mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	rtp: Move MTU handling to the RTP implementation
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). Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
This commit is contained in:
		
							parent
							
								
									02fa9d5fc6
								
							
						
					
					
						commit
						0548cdc6d6
					
				
					 3 changed files with 12 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -491,7 +488,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)) < 0)
 | 
			
		||||
    if (pa_rtp_context_init_send(&u->rtp_context, fd, payload, mtu, pa_frame_size(&ss)) < 0)
 | 
			
		||||
        goto fail;
 | 
			
		||||
    pa_sap_context_init_send(&u->sap_context, sap_fd, p);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -43,7 +43,7 @@
 | 
			
		|||
 | 
			
		||||
#include "rtp.h"
 | 
			
		||||
 | 
			
		||||
int pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t frame_size) {
 | 
			
		||||
int 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 @@ int 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;
 | 
			
		||||
 | 
			
		||||
    c->recv_buf = NULL;
 | 
			
		||||
    c->recv_buf_size = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -63,17 +64,16 @@ int 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 (;;) {
 | 
			
		||||
| 
						 | 
				
			
			@ -84,7 +84,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);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -99,7 +99,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;
 | 
			
		||||
| 
						 | 
				
			
			@ -140,7 +140,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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,17 +33,18 @@ typedef struct pa_rtp_context {
 | 
			
		|||
    uint32_t ssrc;
 | 
			
		||||
    uint8_t payload;
 | 
			
		||||
    size_t frame_size;
 | 
			
		||||
    size_t mtu;
 | 
			
		||||
 | 
			
		||||
    uint8_t *recv_buf;
 | 
			
		||||
    size_t recv_buf_size;
 | 
			
		||||
    pa_memchunk memchunk;
 | 
			
		||||
} pa_rtp_context;
 | 
			
		||||
 | 
			
		||||
int pa_rtp_context_init_send(pa_rtp_context *c, int fd, uint8_t payload, size_t frame_size);
 | 
			
		||||
int 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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue