mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	split user supplied data in multiple memory blocks if necessary to fit in one mempool tile. If the caller supplied a free_cb and we use shm it's better to copy the data immediately to the shm region instead of keeping it around as user memblock
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2278 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									ed36f3129c
								
							
						
					
					
						commit
						33cb5897e1
					
				
					 1 changed files with 38 additions and 13 deletions
				
			
		| 
						 | 
					@ -896,6 +896,10 @@ int pa_stream_write(
 | 
				
			||||||
        pa_seek_mode_t seek) {
 | 
					        pa_seek_mode_t seek) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_memchunk chunk;
 | 
					    pa_memchunk chunk;
 | 
				
			||||||
 | 
					    pa_seek_mode_t t_seek;
 | 
				
			||||||
 | 
					    int64_t t_offset;
 | 
				
			||||||
 | 
					    size_t t_length;
 | 
				
			||||||
 | 
					    const void *t_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pa_assert(s);
 | 
					    pa_assert(s);
 | 
				
			||||||
    pa_assert(PA_REFCNT_VALUE(s) >= 1);
 | 
					    pa_assert(PA_REFCNT_VALUE(s) >= 1);
 | 
				
			||||||
| 
						 | 
					@ -909,21 +913,42 @@ int pa_stream_write(
 | 
				
			||||||
    if (length <= 0)
 | 
					    if (length <= 0)
 | 
				
			||||||
        return 0;
 | 
					        return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (free_cb)
 | 
					    t_seek = seek;
 | 
				
			||||||
        chunk.memblock = pa_memblock_new_user(s->context->mempool, (void*) data, length, free_cb, 1);
 | 
					    t_offset = offset;
 | 
				
			||||||
    else {
 | 
					    t_length = length;
 | 
				
			||||||
        void *tdata;
 | 
					    t_data = data;
 | 
				
			||||||
        chunk.memblock = pa_memblock_new(s->context->mempool, length);
 | 
					
 | 
				
			||||||
        tdata = pa_memblock_acquire(chunk.memblock);
 | 
					    while (t_length > 0) {
 | 
				
			||||||
        memcpy(tdata, data, length);
 | 
					
 | 
				
			||||||
        pa_memblock_release(chunk.memblock);
 | 
					        chunk.index = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (free_cb && !pa_pstream_get_shm(s->context->pstream)) {
 | 
				
			||||||
 | 
					            chunk.memblock = pa_memblock_new_user(s->context->mempool, (void*) t_data, t_length, free_cb, 1);
 | 
				
			||||||
 | 
					            chunk.length = t_length;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            void *d;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            chunk.length = PA_MIN(t_length, pa_mempool_block_size_max(s->context->mempool));
 | 
				
			||||||
 | 
					            chunk.memblock = pa_memblock_new(s->context->mempool, chunk.length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            d = pa_memblock_acquire(chunk.memblock);
 | 
				
			||||||
 | 
					            memcpy(d, t_data, chunk.length);
 | 
				
			||||||
 | 
					            pa_memblock_release(chunk.memblock);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pa_pstream_send_memblock(s->context->pstream, s->channel, t_offset, t_seek, &chunk);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        t_offset = 0;
 | 
				
			||||||
 | 
					        t_seek = PA_SEEK_RELATIVE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        t_data = (const uint8_t*) t_data + chunk.length;
 | 
				
			||||||
 | 
					        t_length -= chunk.length;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        pa_memblock_unref(chunk.memblock);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    chunk.index = 0;
 | 
					    if (free_cb && pa_pstream_get_shm(s->context->pstream))
 | 
				
			||||||
    chunk.length = length;
 | 
					        free_cb((void*) data);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    pa_pstream_send_memblock(s->context->pstream, s->channel, offset, seek, &chunk);
 | 
					 | 
				
			||||||
    pa_memblock_unref(chunk.memblock);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (length < s->requested_bytes)
 | 
					    if (length < s->requested_bytes)
 | 
				
			||||||
        s->requested_bytes -= length;
 | 
					        s->requested_bytes -= length;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue