mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	packet: Introduce pa_packet_new_data() to copy data into a newly created packet
v2: (thanks Alexander Patrakov) * turn check in pa_packet_new() into assert() Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
This commit is contained in:
		
							parent
							
								
									c1a7f0e326
								
							
						
					
					
						commit
						f92300cc92
					
				
					 3 changed files with 16 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -60,6 +60,17 @@ pa_packet* pa_packet_new(size_t length) {
 | 
			
		|||
    return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pa_packet* pa_packet_new_data(const void* data, size_t length) {
 | 
			
		||||
    pa_packet *p = pa_packet_new(length);
 | 
			
		||||
 | 
			
		||||
    pa_assert(data);
 | 
			
		||||
    pa_assert(length > 0);
 | 
			
		||||
 | 
			
		||||
    memcpy(p->data, data, length);
 | 
			
		||||
 | 
			
		||||
    return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pa_packet* pa_packet_new_dynamic(void* data, size_t length) {
 | 
			
		||||
    pa_packet *p;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,10 @@ typedef struct pa_packet pa_packet;
 | 
			
		|||
 * on length) */
 | 
			
		||||
pa_packet* pa_packet_new(size_t length);
 | 
			
		||||
 | 
			
		||||
/* create packet (either of type appended or dynamic depending on length)
 | 
			
		||||
 * and copy data */
 | 
			
		||||
pa_packet* pa_packet_new_data(const void* data, size_t length);
 | 
			
		||||
 | 
			
		||||
/* data must have been malloc()ed; the packet takes ownership of the memory,
 | 
			
		||||
 * i.e. memory is free()d with the packet */
 | 
			
		||||
pa_packet* pa_packet_new_dynamic(void* data, size_t length);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,7 @@ static void pa_pstream_send_tagstruct_with_ancil_data(pa_pstream *p, pa_tagstruc
 | 
			
		|||
    pa_assert(t);
 | 
			
		||||
 | 
			
		||||
    pa_assert_se(data = pa_tagstruct_data(t, &length));
 | 
			
		||||
    pa_assert_se(packet = pa_packet_new_dynamic(pa_xmemdup(data, length), length));
 | 
			
		||||
    pa_assert_se(packet = pa_packet_new_data(data, length));
 | 
			
		||||
    pa_tagstruct_free(t);
 | 
			
		||||
 | 
			
		||||
    pa_pstream_send_packet(p, packet, ancil_data);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue