Commit 5d3891a4 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont Committed by Jean-Baptiste Kempf

rtp: hand-over the data block reference to the packetization function

(cherry picked from commit a1222364b5f81c9f6e819c001394858bc3f4cea4)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 60755cf3
...@@ -1265,14 +1265,13 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id ) ...@@ -1265,14 +1265,13 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_sys_t *id )
static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id, static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
block_t *p_buffer ) block_t *p_buffer )
{ {
block_t *p_next;
assert( p_stream->p_sys->p_mux == NULL ); assert( p_stream->p_sys->p_mux == NULL );
(void)p_stream; (void)p_stream;
while( p_buffer != NULL ) while( p_buffer != NULL )
{ {
p_next = p_buffer->p_next; block_t *p_next = p_buffer->p_next;
p_buffer->p_next = NULL;
/* Send a Vorbis/Theora Packed Configuration packet (RFC 5215 §3.1) /* Send a Vorbis/Theora Packed Configuration packet (RFC 5215 §3.1)
* as the first packet of the stream */ * as the first packet of the stream */
...@@ -1288,7 +1287,6 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id, ...@@ -1288,7 +1287,6 @@ static int Send( sout_stream_t *p_stream, sout_stream_id_sys_t *id,
if( id->rtp_fmt.pf_packetize( id, p_buffer ) ) if( id->rtp_fmt.pf_packetize( id, p_buffer ) )
break; break;
block_Release( p_buffer );
p_buffer = p_next; p_buffer = p_next;
} }
return VLC_SUCCESS; return VLC_SUCCESS;
......
...@@ -681,6 +681,7 @@ static int rtp_packetize_xiph( sout_stream_id_sys_t *id, block_t *in ) ...@@ -681,6 +681,7 @@ static int rtp_packetize_xiph( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -716,6 +717,7 @@ static int rtp_packetize_mpa( sout_stream_id_sys_t *id, block_t *in ) ...@@ -716,6 +717,7 @@ static int rtp_packetize_mpa( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -815,6 +817,7 @@ static int rtp_packetize_mpv( sout_stream_id_sys_t *id, block_t *in ) ...@@ -815,6 +817,7 @@ static int rtp_packetize_mpv( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -851,6 +854,7 @@ static int rtp_packetize_ac3( sout_stream_id_sys_t *id, block_t *in ) ...@@ -851,6 +854,7 @@ static int rtp_packetize_ac3( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -883,6 +887,7 @@ static int rtp_packetize_split( sout_stream_id_sys_t *id, block_t *in ) ...@@ -883,6 +887,7 @@ static int rtp_packetize_split( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -916,6 +921,7 @@ static int rtp_packetize_swab( sout_stream_id_sys_t *id, block_t *in ) ...@@ -916,6 +921,7 @@ static int rtp_packetize_swab( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -969,6 +975,7 @@ static int rtp_packetize_mp4a_latm( sout_stream_id_sys_t *id, block_t *in ) ...@@ -969,6 +975,7 @@ static int rtp_packetize_mp4a_latm( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1008,6 +1015,7 @@ static int rtp_packetize_mp4a( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1008,6 +1015,7 @@ static int rtp_packetize_mp4a( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1030,10 +1038,12 @@ static int rtp_packetize_h263( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1030,10 +1038,12 @@ static int rtp_packetize_h263( sout_stream_id_sys_t *id, block_t *in )
if( i_data < 2 ) if( i_data < 2 )
{ {
block_Release(in);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
if( p_data[0] || p_data[1] ) if( p_data[0] || p_data[1] )
{ {
block_Release(in);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* remove 2 leading 0 bytes */ /* remove 2 leading 0 bytes */
...@@ -1070,6 +1080,7 @@ static int rtp_packetize_h263( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1070,6 +1080,7 @@ static int rtp_packetize_h263( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1182,6 +1193,8 @@ static int rtp_packetize_h264( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1182,6 +1193,8 @@ static int rtp_packetize_h264( sout_stream_id_sys_t *id, block_t *in )
i_buffer -= i_skip; i_buffer -= i_skip;
p_buffer += i_skip; p_buffer += i_skip;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1220,6 +1233,7 @@ static int rtp_packetize_amr( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1220,6 +1233,7 @@ static int rtp_packetize_amr( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1242,15 +1256,20 @@ static int rtp_packetize_t140( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1242,15 +1256,20 @@ static int rtp_packetize_t140( sout_stream_id_sys_t *id, block_t *in )
while( ( p_data[i_payload] & 0xC0 ) == 0x80 ) while( ( p_data[i_payload] & 0xC0 ) == 0x80 )
{ {
if( i_payload == 0 ) if( i_payload == 0 )
{
block_Release(in);
return VLC_SUCCESS; /* fishy input! */ return VLC_SUCCESS; /* fishy input! */
}
i_payload--; i_payload--;
} }
} }
block_t *out = block_Alloc( 12 + i_payload ); block_t *out = block_Alloc( 12 + i_payload );
if( out == NULL ) if( out == NULL )
{
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
}
rtp_packetize_common( id, out, 0, in->i_pts + i_packet ); rtp_packetize_common( id, out, 0, in->i_pts + i_packet );
memcpy( out->p_buffer + 12, p_data, i_payload ); memcpy( out->p_buffer + 12, p_data, i_payload );
...@@ -1265,6 +1284,7 @@ static int rtp_packetize_t140( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1265,6 +1284,7 @@ static int rtp_packetize_t140( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1278,7 +1298,10 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1278,7 +1298,10 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in )
block_t *p_out; block_t *p_out;
if ( in->i_buffer > rtp_mtu (id) ) if ( in->i_buffer > rtp_mtu (id) )
{
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
}
/* /*
RFC for Speex in RTP says that each packet must end on an octet RFC for Speex in RTP says that each packet must end on an octet
...@@ -1337,6 +1360,7 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1337,6 +1360,7 @@ static int rtp_packetize_spx( sout_stream_id_sys_t *id, block_t *in )
p_out->i_buffer = 12 + i_payload_size; p_out->i_buffer = 12 + i_payload_size;
p_out->i_dts = in->i_dts; p_out->i_dts = in->i_dts;
p_out->i_length = in->i_length; p_out->i_length = in->i_length;
block_Release(in);
/* Queue the buffer for actual transmission. */ /* Queue the buffer for actual transmission. */
rtp_packetize_send( id, p_out ); rtp_packetize_send( id, p_out );
...@@ -1372,6 +1396,8 @@ static int rtp_packetize_g726( sout_stream_id_sys_t *id, block_t *in, int i_pad ...@@ -1372,6 +1396,8 @@ static int rtp_packetize_g726( sout_stream_id_sys_t *id, block_t *in, int i_pad
p_data += i_payload; p_data += i_payload;
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1407,14 +1433,20 @@ static int rtp_packetize_vp8( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1407,14 +1433,20 @@ static int rtp_packetize_vp8( sout_stream_id_sys_t *id, block_t *in )
int i_data = in->i_buffer; int i_data = in->i_buffer;
if ( i_max <= 0 ) if ( i_max <= 0 )
{
block_Release(in);
return VLC_EGENERIC; return VLC_EGENERIC;
}
for( int i = 0; i < i_count; i++ ) for( int i = 0; i < i_count; i++ )
{ {
int i_payload = __MIN( i_max, i_data ); int i_payload = __MIN( i_max, i_data );
block_t *out = block_Alloc( RTP_VP8_PAYLOAD_START + i_payload ); block_t *out = block_Alloc( RTP_VP8_PAYLOAD_START + i_payload );
if ( out == NULL ) if ( out == NULL )
{
block_Release(in);
return VLC_ENOMEM; return VLC_ENOMEM;
}
/* VP8 payload header */ /* VP8 payload header */
/* All frames are marked as reference ones */ /* All frames are marked as reference ones */
...@@ -1438,6 +1470,7 @@ static int rtp_packetize_vp8( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1438,6 +1470,7 @@ static int rtp_packetize_vp8( sout_stream_id_sys_t *id, block_t *in )
i_data -= i_payload; i_data -= i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -1463,7 +1496,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1463,7 +1496,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
// Skip SOI // Skip SOI
if (GetWBE(p_data) != 0xffd8) if (GetWBE(p_data) != 0xffd8)
return VLC_EGENERIC; goto error;
p_data += 2; p_data += 2;
i_data -= 2; i_data -= 2;
...@@ -1475,17 +1508,14 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1475,17 +1508,14 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
int section_size = GetWBE(section); int section_size = GetWBE(section);
uint8_t *section_body = p_data + 4; uint8_t *section_body = p_data + 4;
if (section + section_size > bufend) if (section + section_size > bufend)
return VLC_EGENERIC; goto error;
assert((marker & 0xff00) == 0xff00); assert((marker & 0xff00) == 0xff00);
switch (marker) switch (marker)
{ {
case 0xffdb /*DQT*/: case 0xffdb /*DQT*/:
if (section_body[0]) if (section_body[0])
{ goto error; // Only 8-bit precision is supported
// Only 8-bit precision is supported
return VLC_EGENERIC;
}
/* a quantization table is 64 bytes long */ /* a quantization table is 64 bytes long */
nb_qtables = section_size / 65; nb_qtables = section_size / 65;
...@@ -1498,7 +1528,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1498,7 +1528,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
if (width > 2040 || height > 2040) if (width > 2040 || height > 2040)
{ {
// larger than limit supported by RFC 2435 // larger than limit supported by RFC 2435
return VLC_EGENERIC; goto error;
} }
// Round up by 8, divide by 8 // Round up by 8, divide by 8
w = ((width+7)&~7) >> 3; w = ((width+7)&~7) >> 3;
...@@ -1512,7 +1542,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1512,7 +1542,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
// Only 3 components are supported by RFC 2435 // Only 3 components are supported by RFC 2435
if (section_body[5] != 3) // Number of components if (section_body[5] != 3) // Number of components
return VLC_EGENERIC; goto error;
for (int j = 0; j < 3; j++) for (int j = 0; j < 3; j++)
{ {
if (section_body[6 + j * 3] == 1 /* Y */) if (section_body[6 + j * 3] == 1 /* Y */)
...@@ -1522,7 +1552,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1522,7 +1552,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
else if (section_body[6 + j * 3 + 1] != 0x11) else if (section_body[6 + j * 3 + 1] != 0x11)
{ {
// Sampling factor is unsupported by RFC 2435 // Sampling factor is unsupported by RFC 2435
return VLC_EGENERIC; goto error;
} }
} }
break; break;
...@@ -1541,9 +1571,9 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1541,9 +1571,9 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
i_data -= 2 + section_size; i_data -= 2 + section_size;
} }
if (!header_finished) if (!header_finished)
return VLC_EGENERIC; goto error;
if (!w || !h) if (!w || !h)
return VLC_EGENERIC; goto error;
switch (y_sampling_factor) switch (y_sampling_factor)
{ {
...@@ -1554,8 +1584,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1554,8 +1584,7 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
type = 0; type = 0;
break; break;
default: default:
// Sampling format unsupported by RFC 2435 goto error; // Sampling format unsupported by RFC 2435
return VLC_EGENERIC;
} }
if (dri_found) if (dri_found)
...@@ -1628,5 +1657,9 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in ) ...@@ -1628,5 +1657,9 @@ static int rtp_packetize_jpeg( sout_stream_id_sys_t *id, block_t *in )
off += i_payload; off += i_payload;
} }
block_Release(in);
return VLC_SUCCESS; return VLC_SUCCESS;
error:
block_Release(in);
return VLC_EGENERIC;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment