Commit 8da8aa98 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Factorize rtpmap formatting

parent 5d33b82e
...@@ -219,7 +219,7 @@ VLC_EXPORT(void, sout_MethodRelease, (announce_method_t *) ); ...@@ -219,7 +219,7 @@ VLC_EXPORT(void, sout_MethodRelease, (announce_method_t *) );
/** SDP */ /** SDP */
VLC_EXPORT( char *, vlc_sdp_Start, ( vlc_object_t *obj, const char *cfgpref, const struct sockaddr *src, size_t srclen, const struct sockaddr *addr, size_t addrlen ) ); VLC_EXPORT( char *, vlc_sdp_Start, ( vlc_object_t *obj, const char *cfgpref, const struct sockaddr *src, size_t srclen, const struct sockaddr *addr, size_t addrlen ) );
VLC_EXPORT( char *, sdp_AddMedia, (char **sdp, const char *type, const char *protocol, int dport, unsigned pt, vlc_bool_t bw_indep, unsigned bw, const char *rtpmap, const char *fmtp) ); VLC_EXPORT( char *, sdp_AddMedia, (char **sdp, const char *type, const char *protocol, int dport, unsigned pt, vlc_bool_t bw_indep, unsigned bw, const char *ptname, unsigned clockrate, unsigned channels, const char *fmtp) );
VLC_EXPORT( char *, sdp_AddAttribute, (char **sdp, const char *name, const char *fmt, ...) ATTRIBUTE_FORMAT( 3, 4 ) ); VLC_EXPORT( char *, sdp_AddAttribute, (char **sdp, const char *name, const char *fmt, ...) ATTRIBUTE_FORMAT( 3, 4 ) );
......
...@@ -282,7 +282,7 @@ struct sout_stream_id_t ...@@ -282,7 +282,7 @@ struct sout_stream_id_t
uint8_t ssrc[4]; uint8_t ssrc[4];
/* for sdp */ /* for sdp */
char *psz_rtpmap; const char *psz_enc;
char *psz_fmtp; char *psz_fmtp;
int i_clock_rate; int i_clock_rate;
int i_port; int i_port;
...@@ -743,7 +743,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url ) ...@@ -743,7 +743,8 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
sdp_AddMedia( &psz_sdp, mime_major, proto, inclport * id->i_port, sdp_AddMedia( &psz_sdp, mime_major, proto, inclport * id->i_port,
id->i_payload_type, VLC_FALSE, id->i_bitrate, id->i_payload_type, VLC_FALSE, id->i_bitrate,
id->psz_rtpmap, id->psz_fmtp); id->psz_enc, id->i_clock_rate, id->i_channels,
id->psz_fmtp);
if( rtsp_url != NULL ) if( rtsp_url != NULL )
{ {
...@@ -852,7 +853,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -852,7 +853,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
id->ssrc[2] = rand()&0xff; id->ssrc[2] = rand()&0xff;
id->ssrc[3] = rand()&0xff; id->ssrc[3] = rand()&0xff;
id->psz_rtpmap = NULL; id->psz_enc = NULL;
id->psz_fmtp = NULL; id->psz_fmtp = NULL;
id->i_clock_rate = 90000; /* most common case for video */ id->i_clock_rate = 90000; /* most common case for video */
id->i_channels = 0; id->i_channels = 0;
...@@ -929,11 +930,11 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -929,11 +930,11 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
if( strncmp( psz, "ts", 2 ) == 0 ) if( strncmp( psz, "ts", 2 ) == 0 )
{ {
id->i_payload_type = 33; id->i_payload_type = 33;
id->psz_rtpmap = strdup( "MP2T/90000" ); id->psz_enc = "MP2T";
} }
else else
{ {
id->psz_rtpmap = strdup( "MP2P/90000" ); id->psz_enc = "MP2P";
} }
} }
else else
...@@ -942,17 +943,13 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -942,17 +943,13 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
case VLC_FOURCC( 'u', 'l', 'a', 'w' ): case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 ) if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 )
id->i_payload_type = 0; id->i_payload_type = 0;
if( asprintf( &id->psz_rtpmap, "PCMU/%d/%d", p_fmt->audio.i_rate, id->psz_enc = "PCMU";
p_fmt->audio.i_channels ) == -1 )
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_l8; id->pf_packetize = rtp_packetize_l8;
break; break;
case VLC_FOURCC( 'a', 'l', 'a', 'w' ): case VLC_FOURCC( 'a', 'l', 'a', 'w' ):
if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 ) if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 )
id->i_payload_type = 8; id->i_payload_type = 8;
if( asprintf( &id->psz_rtpmap, "PCMA/%d/%d", p_fmt->audio.i_rate, id->psz_enc = "PCMA";
p_fmt->audio.i_channels ) == -1 )
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_l8; id->pf_packetize = rtp_packetize_l8;
break; break;
case VLC_FOURCC( 's', '1', '6', 'b' ): case VLC_FOURCC( 's', '1', '6', 'b' ):
...@@ -965,37 +962,33 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -965,37 +962,33 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
{ {
id->i_payload_type = 10; id->i_payload_type = 10;
} }
if( asprintf( &id->psz_rtpmap, "L16/%d/%d", p_fmt->audio.i_rate, id->psz_enc = "L16";
p_fmt->audio.i_channels ) == -1 )
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_l16; id->pf_packetize = rtp_packetize_l16;
break; break;
case VLC_FOURCC( 'u', '8', ' ', ' ' ): case VLC_FOURCC( 'u', '8', ' ', ' ' ):
if( asprintf( &id->psz_rtpmap, "L8/%d/%d", p_fmt->audio.i_rate, id->psz_enc = "L8";
p_fmt->audio.i_channels ) == -1 )
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_l8; id->pf_packetize = rtp_packetize_l8;
break; break;
case VLC_FOURCC( 'm', 'p', 'g', 'a' ): case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
id->i_payload_type = 14; id->i_payload_type = 14;
id->psz_rtpmap = strdup( "MPA/90000" ); id->psz_enc = "MPA";
id->pf_packetize = rtp_packetize_mpa; id->pf_packetize = rtp_packetize_mpa;
break; break;
case VLC_FOURCC( 'm', 'p', 'g', 'v' ): case VLC_FOURCC( 'm', 'p', 'g', 'v' ):
id->i_payload_type = 32; id->i_payload_type = 32;
id->psz_rtpmap = strdup( "MPV/90000" ); id->psz_enc = "MPV";
id->pf_packetize = rtp_packetize_mpv; id->pf_packetize = rtp_packetize_mpv;
break; break;
case VLC_FOURCC( 'a', '5', '2', ' ' ): case VLC_FOURCC( 'a', '5', '2', ' ' ):
id->psz_rtpmap = strdup( "ac3/90000" ); id->psz_enc = "ac3";
id->pf_packetize = rtp_packetize_ac3; id->pf_packetize = rtp_packetize_ac3;
break; break;
case VLC_FOURCC( 'H', '2', '6', '3' ): case VLC_FOURCC( 'H', '2', '6', '3' ):
id->psz_rtpmap = strdup( "H263-1998/90000" ); id->psz_enc = "H263-1998";
id->pf_packetize = rtp_packetize_h263; id->pf_packetize = rtp_packetize_h263;
break; break;
case VLC_FOURCC( 'h', '2', '6', '4' ): case VLC_FOURCC( 'h', '2', '6', '4' ):
id->psz_rtpmap = strdup( "H264/90000" ); id->psz_enc = "H264";
id->pf_packetize = rtp_packetize_h264; id->pf_packetize = rtp_packetize_h264;
id->psz_fmtp = NULL; id->psz_fmtp = NULL;
...@@ -1057,7 +1050,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1057,7 +1050,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
{ {
char hexa[2*p_fmt->i_extra +1]; char hexa[2*p_fmt->i_extra +1];
id->psz_rtpmap = strdup( "MP4V-ES/90000" ); id->psz_enc = "MP4V-ES";
id->pf_packetize = rtp_packetize_split; id->pf_packetize = rtp_packetize_split;
if( p_fmt->i_extra > 0 ) if( p_fmt->i_extra > 0 )
{ {
...@@ -1074,9 +1067,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1074,9 +1067,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
{ {
char hexa[2*p_fmt->i_extra +1]; char hexa[2*p_fmt->i_extra +1];
if( asprintf( &id->psz_rtpmap, "mpeg4-generic/%d", id->psz_enc = "mpeg4-generic";
p_fmt->audio.i_rate ) == -1 )
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_mp4a; id->pf_packetize = rtp_packetize_mp4a;
sprintf_hexa( hexa, p_fmt->p_extra, p_fmt->i_extra ); sprintf_hexa( hexa, p_fmt->p_extra, p_fmt->i_extra );
if( asprintf( &id->psz_fmtp, if( asprintf( &id->psz_fmtp,
...@@ -1106,10 +1097,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1106,10 +1097,7 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
config[4]=0x3f; config[4]=0x3f;
config[5]=0xc0; config[5]=0xc0;
if( asprintf( &id->psz_rtpmap, "MP4A-LATM/%d/%d", id->psz_enc = "MP4A-LATM";
p_fmt->audio.i_rate,
p_fmt->audio.i_channels ) == -1)
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_mp4a_latm; id->pf_packetize = rtp_packetize_mp4a_latm;
sprintf_hexa( hexa, config, 6 ); sprintf_hexa( hexa, config, 6 );
if( asprintf( &id->psz_fmtp, "profile-level-id=15; " if( asprintf( &id->psz_fmtp, "profile-level-id=15; "
...@@ -1119,26 +1107,22 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt ) ...@@ -1119,26 +1107,22 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
break; break;
} }
case VLC_FOURCC( 's', 'a', 'm', 'r' ): case VLC_FOURCC( 's', 'a', 'm', 'r' ):
id->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ? id->psz_enc = "AMR";
"AMR/8000/2" : "AMR/8000" );
id->psz_fmtp = strdup( "octet-align=1" ); id->psz_fmtp = strdup( "octet-align=1" );
id->pf_packetize = rtp_packetize_amr; id->pf_packetize = rtp_packetize_amr;
break; break;
case VLC_FOURCC( 's', 'a', 'w', 'b' ): case VLC_FOURCC( 's', 'a', 'w', 'b' ):
id->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ? id->psz_enc = "AMR-WB";
"AMR-WB/16000/2" : "AMR-WB/16000" );
id->psz_fmtp = strdup( "octet-align=1" ); id->psz_fmtp = strdup( "octet-align=1" );
id->pf_packetize = rtp_packetize_amr; id->pf_packetize = rtp_packetize_amr;
break; break;
case VLC_FOURCC( 's', 'p', 'x', ' ' ): case VLC_FOURCC( 's', 'p', 'x', ' ' ):
id->i_payload_type = p_sys->i_payload_type++; id->i_payload_type = p_sys->i_payload_type++;
if( asprintf( &id->psz_rtpmap, "SPEEX/%d", id->psz_enc = "SPEEX";
p_fmt->audio.i_rate ) == -1)
id->psz_rtpmap = NULL;
id->pf_packetize = rtp_packetize_spx; id->pf_packetize = rtp_packetize_spx;
break; break;
case VLC_FOURCC( 't', '1', '4', '0' ): case VLC_FOURCC( 't', '1', '4', '0' ):
id->psz_rtpmap = strdup( "t140/1000" ); id->psz_enc = "t140" ;
id->i_clock_rate = 1000; id->i_clock_rate = 1000;
id->pf_packetize = rtp_packetize_t140; id->pf_packetize = rtp_packetize_t140;
break; break;
...@@ -1218,7 +1202,6 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) ...@@ -1218,7 +1202,6 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
p_sys->i_port_video = id->i_port; p_sys->i_port_video = id->i_port;
} }
free( id->psz_rtpmap );
free( id->psz_fmtp ); free( id->psz_fmtp );
if( id->rtsp_id ) if( id->rtsp_id )
......
...@@ -205,7 +205,8 @@ char *sdp_AddAttribute (char **sdp, const char *name, const char *fmt, ...) ...@@ -205,7 +205,8 @@ char *sdp_AddAttribute (char **sdp, const char *name, const char *fmt, ...)
char *sdp_AddMedia (char **sdp, char *sdp_AddMedia (char **sdp,
const char *type, const char *protocol, int dport, const char *type, const char *protocol, int dport,
unsigned pt, vlc_bool_t bw_indep, unsigned bw, unsigned pt, vlc_bool_t bw_indep, unsigned bw,
const char *rtpmap, const char *fmtp) const char *ptname, unsigned clock, unsigned chans,
const char *fmtp)
{ {
char *newsdp, *ptr; char *newsdp, *ptr;
size_t inlen = strlen (*sdp), outlen = inlen; size_t inlen = strlen (*sdp), outlen = inlen;
...@@ -237,8 +238,14 @@ char *sdp_AddMedia (char **sdp, ...@@ -237,8 +238,14 @@ char *sdp_AddMedia (char **sdp,
ptr += sprintf (ptr, "b=RR:0\r\n"); ptr += sprintf (ptr, "b=RR:0\r\n");
/* RTP payload type map */ /* RTP payload type map */
if (rtpmap != NULL) if (ptname != NULL)
sdp_AddAttribute (sdp, "rtpmap", "%u %s", pt, rtpmap); {
if ((strcmp (type, "audio") == 0) && (chans != 1))
sdp_AddAttribute (sdp, "rtpmap", "%u %s/%u/%u", pt, ptname, clock,
chans);
else
sdp_AddAttribute (sdp, "rtpmap", "%u %s/%u", pt, ptname, clock);
}
/* Format parameters */ /* Format parameters */
if (fmtp != NULL) if (fmtp != NULL)
sdp_AddAttribute (sdp, "fmtp", "%u %s", pt, fmtp); sdp_AddAttribute (sdp, "fmtp", "%u %s", pt, fmtp);
......
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