From: Arun Raghavan <git@xxxxxxxxxxxxxxxx> module-rtp-send itself doesn't really need to handle this, the implementation can keep track (and make sure sending happens in MTU sized chunks). --- src/modules/rtp/module-rtp-send.c | 7 ++----- src/modules/rtp/rtp.c | 14 +++++++------- src/modules/rtp/rtp.h | 5 +++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index 1c1ebea..c82adc5 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -109,7 +109,6 @@ struct userdata { pa_rtp_context rtp_context; pa_sap_context sap_context; - size_t mtu; pa_time_event *sap_event; @@ -144,7 +143,7 @@ static void source_output_push_cb(pa_source_output *o, const pa_memchunk *chunk) return; } - pa_rtp_send(&u->rtp_context, u->mtu, u->memblockq); + pa_rtp_send(&u->rtp_context, u->memblockq); } static pa_source_output_flags_t get_dont_inhibit_auto_suspend_flag(pa_source *source, @@ -466,8 +465,6 @@ int pa__init(pa_module*m) { 0, NULL); - u->mtu = mtu; - k = sizeof(sa_dst); pa_assert_se((r = getsockname(fd, (struct sockaddr*) &sa_dst, &k)) >= 0); @@ -489,7 +486,7 @@ int pa__init(pa_module*m) { pa_xfree(n); - if (!pa_rtp_context_init_send(&u->rtp_context, fd, payload, pa_frame_size(&ss))) + if (!pa_rtp_context_init_send(&u->rtp_context, fd, payload, mtu, pa_frame_size(&ss))) goto fail; pa_sap_context_init_send(&u->sap_context, sap_fd, p); diff --git a/src/modules/rtp/rtp.c b/src/modules/rtp/rtp.c index a5a5082..8da658a 100644 --- a/src/modules/rtp/rtp.c +++ b/src/modules/rtp/rtp.c @@ -43,7 +43,7 @@ #include "rtp.h" -bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t frame_size) { +bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t mtu, size_t frame_size) { pa_assert(c); pa_assert(fd >= 0); @@ -53,6 +53,7 @@ bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t c->ssrc = (uint32_t) (rand()*rand()); c->payload = (uint8_t) (payload & 127U); c->frame_size = frame_size; + c->mtu = mtu; pa_memchunk_reset(&c->memchunk); @@ -61,17 +62,16 @@ bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t #define MAX_IOVECS 16 -int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { +int pa_rtp_send(pa_rtp_context *c, pa_memblockq *q) { struct iovec iov[MAX_IOVECS]; pa_memblock* mb[MAX_IOVECS]; int iov_idx = 1; size_t n = 0; pa_assert(c); - pa_assert(size > 0); pa_assert(q); - if (pa_memblockq_get_length(q) < size) + if (pa_memblockq_get_length(q) < c->mtu) return 0; for (;;) { @@ -82,7 +82,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { if ((r = pa_memblockq_peek(q, &chunk)) >= 0) { - size_t k = n + chunk.length > size ? size - n : chunk.length; + size_t k = n + chunk.length > c->mtu ? c->mtu - n : chunk.length; pa_assert(chunk.memblock); @@ -97,7 +97,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { pa_assert(n % c->frame_size == 0); - if (r < 0 || n >= size || iov_idx >= MAX_IOVECS) { + if (r < 0 || n >= c->mtu || iov_idx >= MAX_IOVECS) { uint32_t header[3]; struct msghdr m; ssize_t k; @@ -138,7 +138,7 @@ int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q) { return -1; } - if (r < 0 || pa_memblockq_get_length(q) < size) + if (r < 0 || pa_memblockq_get_length(q) < c->mtu) break; n = 0; diff --git a/src/modules/rtp/rtp.h b/src/modules/rtp/rtp.h index 57be3e4..350f968 100644 --- a/src/modules/rtp/rtp.h +++ b/src/modules/rtp/rtp.h @@ -33,15 +33,16 @@ typedef struct pa_rtp_context { uint32_t ssrc; uint8_t payload; size_t frame_size; + size_t mtu; pa_memchunk memchunk; } pa_rtp_context; -bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t frame_size); +bool pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t mtu, size_t frame_size); /* If the memblockq doesn't have a silence memchunk set, then the caller must * guarantee that the current read index doesn't point to a hole. */ -int pa_rtp_send(pa_rtp_context *c, size_t size, pa_memblockq *q); +int pa_rtp_send(pa_rtp_context *c, pa_memblockq *q); pa_rtp_context* pa_rtp_context_init_recv(pa_rtp_context *c, int fd, size_t frame_size); int pa_rtp_recv(pa_rtp_context *c, pa_memchunk *chunk, pa_mempool *pool, struct timeval *tstamp); -- 2.5.0