X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=modules%2Fstream_out%2Frtpfmt.c;h=680f7456b18ea969b119696da27f51aaf161bdbb;hb=2151d6fe01a3b730b6d241b561ce18f5cc424faf;hp=5cb867a26e0fdd812e1c361f1eeec7f1705f62b6;hpb=baf568bd8ef0b334b89bfe8e5249f0ce4d420bb3;p=vlc diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c index 5cb867a26e..680f7456b1 100644 --- a/modules/stream_out/rtpfmt.c +++ b/modules/stream_out/rtpfmt.c @@ -33,11 +33,11 @@ #include "rtp.h" int -rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id, +rtp_packetize_h264_nal( sout_stream_id_t *id, const uint8_t *p_data, int i_data, int64_t i_pts, int64_t i_dts, bool b_last, int64_t i_length ); -int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id, +int rtp_packetize_mpa( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 4; /* payload max in one packet */ @@ -55,11 +55,9 @@ int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id, /* rtp common header */ rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts ); /* mbz set to 0 */ - out->p_buffer[12] = 0; - out->p_buffer[13] = 0; + SetWBE( out->p_buffer + 12, 0 ); /* fragment offset in the current frame */ - out->p_buffer[14] = ( (i*i_max) >> 8 )&0xff; - out->p_buffer[15] = ( (i*i_max) )&0xff; + SetWBE( out->p_buffer + 14, i * i_max ); memcpy( &out->p_buffer[16], p_data, i_payload ); out->i_buffer = 16 + i_payload; @@ -76,8 +74,7 @@ int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id, } /* rfc2250 */ -int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_mpv( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 4; /* payload max in one packet */ int i_count = ( in->i_buffer + i_max - 1 ) / i_max; @@ -146,6 +143,7 @@ int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id, { int i_payload = __MIN( i_max, i_data ); block_t *out = block_Alloc( 16 + i_payload ); + /* MBZ:5 T:1 TR:10 AN:1 N:1 S:1 B:1 E:1 P:3 FBV:1 BFC:3 FFV:1 FFC:3 */ uint32_t h = ( i_temporal_ref << 16 )| ( b_sequence_start << 13 )| ( b_start_slice << 12 )| @@ -157,11 +155,7 @@ int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id, rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts > 0 ? in->i_pts : in->i_dts ); - /* MBZ:5 T:1 TR:10 AN:1 N:1 S:1 B:1 E:1 P:3 FBV:1 BFC:3 FFV:1 FFC:3 */ - out->p_buffer[12] = ( h >> 24 )&0xff; - out->p_buffer[13] = ( h >> 16 )&0xff; - out->p_buffer[14] = ( h >> 8 )&0xff; - out->p_buffer[15] = ( h )&0xff; + SetDWBE( out->p_buffer + 12, h ); memcpy( &out->p_buffer[16], p_data, i_payload ); @@ -178,8 +172,7 @@ int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_ac3( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 2; /* payload max in one packet */ int i_count = ( in->i_buffer + i_max - 1 ) / i_max; @@ -215,8 +208,7 @@ int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_split( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id); /* payload max in one packet */ int i_count = ( in->i_buffer + i_max - 1 ) / i_max; @@ -249,8 +241,7 @@ int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id, } /* rfc3016 */ -int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_mp4a_latm( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 2; /* payload max in one packet */ int latmhdrsize = in->i_buffer / 0xff + 1; @@ -302,8 +293,7 @@ int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_mp4a( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 4; /* payload max in one packet */ int i_count = ( in->i_buffer + i_max - 1 ) / i_max; @@ -325,8 +315,7 @@ int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id, out->p_buffer[12] = 0; out->p_buffer[13] = 2*8; /* for each AU length 13 bits + idx 3bits, */ - out->p_buffer[14] = ( in->i_buffer >> 5 )&0xff; - out->p_buffer[15] = ( (in->i_buffer&0xff)<<3 )|0; + SetWBE( out->p_buffer + 14, (in->i_buffer << 3) | 0 ); memcpy( &out->p_buffer[16], p_data, i_payload ); @@ -347,8 +336,7 @@ int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id, /* rfc2429 */ #define RTP_H263_HEADER_SIZE (2) // plen = 0 #define RTP_H263_PAYLOAD_START (14) // plen = 0 -int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_h263( sout_stream_id_t *id, block_t *in ) { uint8_t *p_data = in->p_buffer; int i_data = in->i_buffer; @@ -390,8 +378,7 @@ int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id, in->i_pts > 0 ? in->i_pts : in->i_dts ); /* h263 header */ - out->p_buffer[12] = ( h >> 8 )&0xff; - out->p_buffer[13] = ( h )&0xff; + SetWBE( out->p_buffer + 12, h ); memcpy( &out->p_buffer[RTP_H263_PAYLOAD_START], p_data, i_payload ); out->i_buffer = RTP_H263_PAYLOAD_START + i_payload; @@ -409,7 +396,7 @@ int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id, /* rfc3984 */ int -rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id, +rtp_packetize_h264_nal( sout_stream_id_t *id, const uint8_t *p_data, int i_data, int64_t i_pts, int64_t i_dts, bool b_last, int64_t i_length ) { @@ -478,8 +465,7 @@ rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_h264( sout_stream_id_t *id, block_t *in ) { const uint8_t *p_buffer = in->p_buffer; int i_buffer = in->i_buffer; @@ -509,7 +495,7 @@ int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id, } } /* TODO add STAP-A to remove a lot of overhead with small slice/sei/... */ - rtp_packetize_h264_nal( p_stream, id, p_buffer, i_size, + rtp_packetize_h264_nal( id, p_buffer, i_size, (in->i_pts > 0 ? in->i_pts : in->i_dts), in->i_dts, (i_size >= i_buffer), in->i_length * i_size / in->i_buffer ); @@ -519,8 +505,7 @@ int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_amr( sout_stream_id_t *id, block_t *in ) { int i_max = rtp_mtu (id) - 2; /* payload max in one packet */ int i_count = ( in->i_buffer + i_max - 1 ) / i_max; @@ -558,8 +543,7 @@ int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id, return VLC_SUCCESS; } -int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_t140( sout_stream_id_t *id, block_t *in ) { const size_t i_max = rtp_mtu (id); const uint8_t *p_data = in->p_buffer; @@ -605,8 +589,7 @@ int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id, } -int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id, - block_t *in ) +int rtp_packetize_spx( sout_stream_id_t *id, block_t *in ) { uint8_t *p_buffer = in->p_buffer; int i_data_size, i_payload_size, i_payload_padding; @@ -615,10 +598,7 @@ int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id, block_t *p_out; if ( in->i_buffer > rtp_mtu (id) ) - { - msg_Warn( p_stream, "Cannot send packet larger than output MTU" ); return VLC_SUCCESS; - } /* RFC for Speex in RTP says that each packet must end on an octet @@ -681,3 +661,55 @@ int rtp_packetize_spx( sout_stream_t *p_stream, sout_stream_id_t *id, rtp_packetize_send( id, p_out ); return VLC_SUCCESS; } + +static int rtp_packetize_g726( sout_stream_id_t *id, block_t *in, int i_pad ) +{ + int i_max = (rtp_mtu( id )- 12 + i_pad - 1) & ~i_pad; + int i_count = ( in->i_buffer + i_max - 1 ) / i_max; + + uint8_t *p_data = in->p_buffer; + int i_data = in->i_buffer; + int i_packet = 0; + + while( i_data > 0 ) + { + int i_payload = __MIN( i_max, i_data ); + block_t *out = block_New( p_stream, 12 + i_payload ); + + /* rtp common header */ + rtp_packetize_common( id, out, 0, + (in->i_pts > 0 ? in->i_pts : in->i_dts) ); + + memcpy( &out->p_buffer[12], p_data, i_payload ); + + out->i_buffer = 12 + i_payload; + out->i_dts = in->i_dts + i_packet++ * in->i_length / i_count; + out->i_length = in->i_length / i_count; + + rtp_packetize_send( id, out ); + + p_data += i_payload; + i_data -= i_payload; + } + return VLC_SUCCESS; +} + +int rtp_packetize_g726_16( sout_stream_id_t *id, block_t *in ) +{ + return rtp_packetize_g726( id, in, 4 ); +} + +int rtp_packetize_g726_24( sout_stream_id_t *id, block_t *in ) +{ + return rtp_packetize_g726( id, in, 8 ); +} + +int rtp_packetize_g726_32( sout_stream_id_t *id, block_t *in ) +{ + return rtp_packetize_g726( id, in, 2 ); +} + +int rtp_packetize_g726_40( sout_stream_id_t *id, block_t *in ) +{ + return rtp_packetize_g726( id, in, 8 ); +}