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
a53bc035c0
commit
44340fde05
3 changed files with 23 additions and 5 deletions
|
|
@ -162,6 +162,9 @@ struct impl {
|
||||||
socklen_t src_len;
|
socklen_t src_len;
|
||||||
struct spa_source *source;
|
struct spa_source *source;
|
||||||
|
|
||||||
|
uint8_t *buffer;
|
||||||
|
size_t buffer_size;
|
||||||
|
|
||||||
unsigned receiving:1;
|
unsigned receiving:1;
|
||||||
unsigned last_receiving:1;
|
unsigned last_receiving:1;
|
||||||
};
|
};
|
||||||
|
|
@ -171,17 +174,16 @@ on_rtp_io(void *data, int fd, uint32_t mask)
|
||||||
{
|
{
|
||||||
struct impl *impl = data;
|
struct impl *impl = data;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
uint8_t buffer[2048];
|
|
||||||
|
|
||||||
if (mask & SPA_IO_IN) {
|
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;
|
goto receive_error;
|
||||||
|
|
||||||
if (len < 12)
|
if (len < 12)
|
||||||
goto short_packet;
|
goto short_packet;
|
||||||
|
|
||||||
if (SPA_LIKELY(impl->stream)) {
|
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;
|
goto receive_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -193,7 +195,7 @@ receive_error:
|
||||||
pw_log_warn("recv error: %m");
|
pw_log_warn("recv error: %m");
|
||||||
return;
|
return;
|
||||||
short_packet:
|
short_packet:
|
||||||
pw_log_warn("short packet received");
|
pw_log_warn("short packet of len %zd received", len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -477,6 +479,7 @@ static void impl_destroy(struct impl *impl)
|
||||||
pw_properties_free(impl->stream_props);
|
pw_properties_free(impl->stream_props);
|
||||||
pw_properties_free(impl->props);
|
pw_properties_free(impl->props);
|
||||||
|
|
||||||
|
free(impl->buffer);
|
||||||
free(impl->ifname);
|
free(impl->ifname);
|
||||||
free(impl);
|
free(impl);
|
||||||
}
|
}
|
||||||
|
|
@ -663,6 +666,14 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
|
||||||
goto out;
|
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_add_listener(module, &impl->module_listener, &module_events, impl);
|
||||||
|
|
||||||
pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_info));
|
pw_impl_module_update_properties(module, &SPA_DICT_INIT_ARRAY(module_info));
|
||||||
|
|
|
||||||
|
|
@ -665,10 +665,15 @@ uint64_t rtp_stream_get_time(struct rtp_stream *s, uint32_t *rate)
|
||||||
uint16_t rtp_stream_get_seq(struct rtp_stream *s)
|
uint16_t rtp_stream_get_seq(struct rtp_stream *s)
|
||||||
{
|
{
|
||||||
struct impl *impl = (struct impl*)s;
|
struct impl *impl = (struct impl*)s;
|
||||||
|
|
||||||
return impl->seq;
|
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)
|
void rtp_stream_set_first(struct rtp_stream *s)
|
||||||
{
|
{
|
||||||
struct impl *impl = (struct impl*)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);
|
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_first(struct rtp_stream *s);
|
||||||
|
|
||||||
void rtp_stream_set_error(struct rtp_stream *s, int res, const char *error);
|
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