mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
module-rtp: allocate receive buffer based on MTU
Use the MTU to allocate the receive buffer instead of using a hardcoded size. Fixes #4394
This commit is contained in:
parent
ba7a8664a1
commit
d2857c2129
3 changed files with 23 additions and 5 deletions
|
|
@ -162,6 +162,9 @@ struct impl {
|
|||
socklen_t src_len;
|
||||
struct spa_source *source;
|
||||
|
||||
uint8_t *buffer;
|
||||
size_t buffer_size;
|
||||
|
||||
unsigned receiving:1;
|
||||
unsigned last_receiving:1;
|
||||
};
|
||||
|
|
@ -171,17 +174,16 @@ on_rtp_io(void *data, int fd, uint32_t mask)
|
|||
{
|
||||
struct impl *impl = data;
|
||||
ssize_t len;
|
||||
uint8_t buffer[2048];
|
||||
|
||||
if (mask & SPA_IO_IN) {
|
||||
if ((len = recv(fd, buffer, sizeof(buffer), 0)) < 0)
|
||||
if ((len = recv(fd, impl->buffer, impl->buffer_size, 0)) < 0)
|
||||
goto receive_error;
|
||||
|
||||
if (len < 12)
|
||||
goto short_packet;
|
||||
|
||||
if (SPA_LIKELY(impl->stream)) {
|
||||
if (rtp_stream_receive_packet(impl->stream, buffer, len) < 0)
|
||||
if (rtp_stream_receive_packet(impl->stream, impl->buffer, len) < 0)
|
||||
goto receive_error;
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +195,7 @@ receive_error:
|
|||
pw_log_warn("recv error: %m");
|
||||
return;
|
||||
short_packet:
|
||||
pw_log_warn("short packet received");
|
||||
pw_log_warn("short packet of len %zd received", len);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -477,6 +479,7 @@ static void impl_destroy(struct impl *impl)
|
|||
pw_properties_free(impl->stream_props);
|
||||
pw_properties_free(impl->props);
|
||||
|
||||
free(impl->buffer);
|
||||
free(impl->ifname);
|
||||
free(impl);
|
||||
}
|
||||
|
|
@ -663,6 +666,14 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
|||
goto out;
|
||||
}
|
||||
|
||||
impl->buffer_size = rtp_stream_get_mtu(impl->stream);
|
||||
impl->buffer = calloc(1, impl->buffer_size);
|
||||
if (impl->buffer == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("can't create packet buffer of size %zd: %m", impl->buffer_size);
|
||||
goto out;
|
||||
}
|
||||
|
||||
pw_impl_module_add_listener(module, &impl->module_listener, &module_events, impl);
|
||||
|
||||
pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_info));
|
||||
|
|
|
|||
|
|
@ -657,10 +657,15 @@ uint64_t rtp_stream_get_time(struct rtp_stream *s, uint32_t *rate)
|
|||
uint16_t rtp_stream_get_seq(struct rtp_stream *s)
|
||||
{
|
||||
struct impl *impl = (struct impl*)s;
|
||||
|
||||
return impl->seq;
|
||||
}
|
||||
|
||||
size_t rtp_stream_get_mtu(struct rtp_stream *s)
|
||||
{
|
||||
struct impl *impl = (struct impl*)s;
|
||||
return impl->mtu;
|
||||
}
|
||||
|
||||
void rtp_stream_set_first(struct rtp_stream *s)
|
||||
{
|
||||
struct impl *impl = (struct impl*)s;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ uint64_t rtp_stream_get_time(struct rtp_stream *s, uint32_t *rate);
|
|||
|
||||
uint16_t rtp_stream_get_seq(struct rtp_stream *s);
|
||||
|
||||
size_t rtp_stream_get_mtu(struct rtp_stream *s);
|
||||
|
||||
void rtp_stream_set_first(struct rtp_stream *s);
|
||||
|
||||
void rtp_stream_set_error(struct rtp_stream *s, int res, const char *error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue