* Preamble
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
#include <vlc_sout.h>
#include <vlc_block.h>
#define NAME_LONGTEXT N_( \
"This is the name of the session that will be announced in the SDP " \
"(Session Descriptor)." )
-#define DESC_TEXT N_("Session descriptipn")
+#define DESC_TEXT N_("Session description")
#define DESC_LONGTEXT N_( \
"This allows you to give a short description with details about the stream, " \
"that will be announced in the SDP (Session Descriptor)." )
"This sends and receives RTCP packet multiplexed over the same port " \
"as RTP packets." )
-#define DCCP_TEXT N_("DCCP transport")
-#define DCCP_LONGTEXT N_( \
- "This enables DCCP instead of UDP as a transport for RTP." )
-#define TCP_TEXT N_("TCP transport")
-#define TCP_LONGTEXT N_( \
- "This enables TCP instead of UDP as a transport for RTP." )
-#define UDP_LITE_TEXT N_("UDP-Lite transport")
-#define UDP_LITE_LONGTEXT N_( \
- "This enables UDP-Lite instead of UDP as a transport for RTP." )
+#define PROTO_TEXT N_("Transport protocol")
+#define PROTO_LONGTEXT N_( \
+ "This selects which transport protocol to use for RTP." )
+
+static const char *const ppsz_protos[] = {
+ "dccp", "sctp", "tcp", "udp", "udplite",
+};
+
+static const char *const ppsz_protocols[] = {
+ "DCCP", "SCTP", "TCP", "UDP", "UDP-Lite",
+};
#define RFC3016_TEXT N_("MP4A LATM")
#define RFC3016_LONGTEXT N_( \
add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
DST_LONGTEXT, VLC_TRUE );
+ change_unsafe();
add_string( SOUT_CFG_PREFIX "sdp", "", NULL, SDP_TEXT,
SDP_LONGTEXT, VLC_TRUE );
add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
add_string( SOUT_CFG_PREFIX "phone", "", NULL, PHONE_TEXT,
PHONE_LONGTEXT, VLC_TRUE );
+ add_string( SOUT_CFG_PREFIX "proto", "udp", NULL, PROTO_TEXT,
+ PROTO_LONGTEXT, VLC_FALSE );
+ change_string_list( ppsz_protos, ppsz_protocols, NULL );
add_integer( SOUT_CFG_PREFIX "port", 1234, NULL, PORT_TEXT,
PORT_LONGTEXT, VLC_TRUE );
add_integer( SOUT_CFG_PREFIX "port-audio", 1230, NULL, PORT_AUDIO_TEXT,
add_integer( SOUT_CFG_PREFIX "ttl", 0, NULL, TTL_TEXT,
TTL_LONGTEXT, VLC_TRUE );
-
add_bool( SOUT_CFG_PREFIX "rtcp-mux", VLC_FALSE, NULL,
RTCP_MUX_TEXT, RTCP_MUX_LONGTEXT, VLC_FALSE );
- add_bool( SOUT_CFG_PREFIX "dccp", VLC_FALSE, NULL,
- DCCP_TEXT, DCCP_LONGTEXT, VLC_FALSE );
- add_bool( SOUT_CFG_PREFIX "tcp", VLC_FALSE, NULL,
- TCP_TEXT, TCP_LONGTEXT, VLC_FALSE );
- add_bool( SOUT_CFG_PREFIX "udplite", VLC_FALSE, NULL,
- UDP_LITE_TEXT, UDP_LITE_LONGTEXT, VLC_FALSE );
-
add_bool( SOUT_CFG_PREFIX "mp4a-latm", 0, NULL, RFC3016_TEXT,
RFC3016_LONGTEXT, VLC_FALSE );
static const char *ppsz_sout_options[] = {
"dst", "name", "port", "port-audio", "port-video", "*sdp", "ttl", "mux",
"description", "url", "email", "phone",
- "rtcp-mux", "dccp", "tcp", "udplite",
+ "proto", "rtcp-mux",
"mp4a-latm", NULL
};
uint8_t ssrc[4];
/* for sdp */
- char *psz_rtpmap;
+ const char *psz_enc;
char *psz_fmtp;
int i_clock_rate;
int i_port;
int i_cat;
+ int i_channels;
int i_bitrate;
/* Packetizer specific fields */
int64_t i_caching;
};
-
/*****************************************************************************
* Open:
*****************************************************************************/
/* Transport protocol */
p_sys->proto = IPPROTO_UDP;
+ psz = var_GetNonEmptyString (p_stream, SOUT_CFG_PREFIX"proto");
- if( var_GetBool( p_stream, SOUT_CFG_PREFIX "dccp" ) )
+ if ((psz == NULL) || !strcasecmp (psz, "udp"))
+ (void)0; /* default */
+ else
+ if (!strcasecmp (psz, "dccp"))
{
p_sys->proto = IPPROTO_DCCP;
p_sys->rtcp_mux = VLC_TRUE; /* Force RTP/RTCP mux */
}
#if 0
else
- if( var_GetBool( p_stream, SOUT_CFG_PREFIX "tcp" ) )
+ if (!strcasecmp (psz, "sctp"))
{
p_sys->proto = IPPROTO_TCP;
p_sys->rtcp_mux = VLC_TRUE; /* Force RTP/RTCP mux */
}
+#endif
+#if 0
else
+ if (!strcasecmp (psz, "tcp"))
+ {
+ p_sys->proto = IPPROTO_TCP;
+ p_sys->rtcp_mux = VLC_TRUE; /* Force RTP/RTCP mux */
+ }
#endif
- if( var_GetBool( p_stream, SOUT_CFG_PREFIX "udplite" ) )
+ else
+ if (!strcasecmp (psz, "udplite") || !strcasecmp (psz, "udp-lite"))
p_sys->proto = IPPROTO_UDPLITE;
+ else
+ msg_Warn (p_this, "unknown or unsupported transport protocol \"%s\"",
+ psz);
+ free (psz);
+ var_Create (p_this, "dccp-service", VLC_VAR_STRING);
if( ( p_sys->psz_destination == NULL ) && !b_rtsp )
{
sdp_AddMedia( &psz_sdp, mime_major, proto, inclport * id->i_port,
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( id->listen_fd != NULL )
sdp_AddAttribute( &psz_sdp, "setup", "passive" );
-#if 0
if( p_sys->proto == IPPROTO_DCCP )
sdp_AddAttribute( &psz_sdp, "dccp-service-code",
"SC:RTP%c", toupper( mime_major[0] ) );
-#endif
}
}
/*****************************************************************************
* RTP mux
*****************************************************************************/
-static int rtp_packetize_l16 ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_l8 ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_mpa ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_mpv ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_ac3 ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_split( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_mp4a ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_mp4a_latm ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_h263 ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_h264 ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_amr ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_spx ( sout_stream_t *, sout_stream_id_t *, block_t * );
-static int rtp_packetize_t140 ( sout_stream_t *, sout_stream_id_t *, block_t * );
static void sprintf_hexa( char *s, uint8_t *p_data, int i_data )
{
id->ssrc[2] = rand()&0xff;
id->ssrc[3] = rand()&0xff;
- id->psz_rtpmap = NULL;
+ id->psz_enc = NULL;
id->psz_fmtp = NULL;
- id->i_clock_rate = 90000; /* most common case */
+ id->i_clock_rate = 90000; /* most common case for video */
+ id->i_channels = 0;
id->i_port = i_port;
if( p_fmt != NULL )
{
id->i_cat = p_fmt->i_cat;
+ if( p_fmt->i_cat == AUDIO_ES )
+ {
+ id->i_clock_rate = p_fmt->audio.i_rate;
+ id->i_channels = p_fmt->audio.i_channels;
+ }
id->i_bitrate = p_fmt->i_bitrate/1000; /* Stream bitrate in kbps */
}
else
if( p_sys->psz_destination != NULL )
switch( p_sys->proto )
{
- case IPPROTO_TCP:
case IPPROTO_DCCP:
+ {
+ const char *code;
+ switch (id->i_cat)
+ {
+ case VIDEO_ES: code = "RTPV"; break;
+ case AUDIO_ES: code = "RTPARTPV"; break;
+ case SPU_ES: code = "RTPTRPTV"; break;
+ default: code = "RTPORTPV"; break;
+ }
+ var_SetString (p_stream, "dccp-service", code);
+ } /* fall through */
+ case IPPROTO_TCP:
id->listen_fd = net_Listen( VLC_OBJECT(p_stream),
p_sys->psz_destination, i_port,
p_sys->proto );
if( strncmp( psz, "ts", 2 ) == 0 )
{
id->i_payload_type = 33;
- id->psz_rtpmap = strdup( "MP2T/90000" );
+ id->psz_enc = "MP2T";
}
else
{
- id->psz_rtpmap = strdup( "MP2P/90000" );
+ id->psz_enc = "MP2P";
}
}
else
case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 )
id->i_payload_type = 0;
- id->i_clock_rate = p_fmt->audio.i_rate;
- if( asprintf( &id->psz_rtpmap, "PCMU/%d/%d", p_fmt->audio.i_rate,
- p_fmt->audio.i_channels ) == -1 )
- id->psz_rtpmap = NULL;
- id->i_clock_rate = p_fmt->audio.i_rate;
+ id->psz_enc = "PCMU";
id->pf_packetize = rtp_packetize_l8;
break;
case VLC_FOURCC( 'a', 'l', 'a', 'w' ):
if( p_fmt->audio.i_channels == 1 && p_fmt->audio.i_rate == 8000 )
id->i_payload_type = 8;
- id->i_clock_rate = p_fmt->audio.i_rate;
- if( asprintf( &id->psz_rtpmap, "PCMA/%d/%d", p_fmt->audio.i_rate,
- p_fmt->audio.i_channels ) == -1 )
- id->psz_rtpmap = NULL;
- id->i_clock_rate = p_fmt->audio.i_rate;
+ id->psz_enc = "PCMA";
id->pf_packetize = rtp_packetize_l8;
break;
case VLC_FOURCC( 's', '1', '6', 'b' ):
{
id->i_payload_type = 10;
}
- if( asprintf( &id->psz_rtpmap, "L16/%d/%d", p_fmt->audio.i_rate,
- p_fmt->audio.i_channels ) == -1 )
- id->psz_rtpmap = NULL;
- id->i_clock_rate = p_fmt->audio.i_rate;
+ id->psz_enc = "L16";
id->pf_packetize = rtp_packetize_l16;
break;
case VLC_FOURCC( 'u', '8', ' ', ' ' ):
- if( asprintf( &id->psz_rtpmap, "L8/%d/%d", p_fmt->audio.i_rate,
- p_fmt->audio.i_channels ) == -1 )
- id->psz_rtpmap = NULL;
- id->i_clock_rate = p_fmt->audio.i_rate;
+ id->psz_enc = "L8";
id->pf_packetize = rtp_packetize_l8;
break;
case VLC_FOURCC( 'm', 'p', 'g', 'a' ):
+ case VLC_FOURCC( 'm', 'p', '3', ' ' ):
id->i_payload_type = 14;
- id->psz_rtpmap = strdup( "MPA/90000" );
+ id->psz_enc = "MPA";
id->pf_packetize = rtp_packetize_mpa;
break;
case VLC_FOURCC( 'm', 'p', 'g', 'v' ):
id->i_payload_type = 32;
- id->psz_rtpmap = strdup( "MPV/90000" );
+ id->psz_enc = "MPV";
id->pf_packetize = rtp_packetize_mpv;
break;
case VLC_FOURCC( 'a', '5', '2', ' ' ):
- id->psz_rtpmap = strdup( "ac3/90000" );
+ id->psz_enc = "ac3";
id->pf_packetize = rtp_packetize_ac3;
break;
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;
break;
case VLC_FOURCC( 'h', '2', '6', '4' ):
- id->psz_rtpmap = strdup( "H264/90000" );
+ id->psz_enc = "H264";
id->pf_packetize = rtp_packetize_h264;
id->psz_fmtp = NULL;
{
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;
if( p_fmt->i_extra > 0 )
{
}
case VLC_FOURCC( 'm', 'p', '4', 'a' ):
{
- id->i_clock_rate = p_fmt->audio.i_rate;
-
if(!p_sys->b_latm)
{
char hexa[2*p_fmt->i_extra +1];
- if( asprintf( &id->psz_rtpmap, "mpeg4-generic/%d",
- p_fmt->audio.i_rate ) == -1 )
- id->psz_rtpmap = NULL;
+ id->psz_enc = "mpeg4-generic";
id->pf_packetize = rtp_packetize_mp4a;
sprintf_hexa( hexa, p_fmt->p_extra, p_fmt->i_extra );
if( asprintf( &id->psz_fmtp,
config[4]=0x3f;
config[5]=0xc0;
- if( asprintf( &id->psz_rtpmap, "MP4A-LATM/%d/%d",
- p_fmt->audio.i_rate,
- p_fmt->audio.i_channels ) == -1)
- id->psz_rtpmap = NULL;
+ id->psz_enc = "MP4A-LATM";
id->pf_packetize = rtp_packetize_mp4a_latm;
sprintf_hexa( hexa, config, 6 );
if( asprintf( &id->psz_fmtp, "profile-level-id=15; "
break;
}
case VLC_FOURCC( 's', 'a', 'm', 'r' ):
- id->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ?
- "AMR/8000/2" : "AMR/8000" );
+ id->psz_enc = "AMR";
id->psz_fmtp = strdup( "octet-align=1" );
- id->i_clock_rate = p_fmt->audio.i_rate;
id->pf_packetize = rtp_packetize_amr;
break;
case VLC_FOURCC( 's', 'a', 'w', 'b' ):
- id->psz_rtpmap = strdup( p_fmt->audio.i_channels == 2 ?
- "AMR-WB/16000/2" : "AMR-WB/16000" );
+ id->psz_enc = "AMR-WB";
id->psz_fmtp = strdup( "octet-align=1" );
- id->i_clock_rate = p_fmt->audio.i_rate;
id->pf_packetize = rtp_packetize_amr;
break;
case VLC_FOURCC( 's', 'p', 'x', ' ' ):
id->i_payload_type = p_sys->i_payload_type++;
- if( asprintf( &id->psz_rtpmap, "SPEEX/%d",
- p_fmt->audio.i_rate ) == -1)
- id->psz_rtpmap = NULL;
- id->i_clock_rate = p_fmt->audio.i_rate;
+ id->psz_enc = "SPEEX";
id->pf_packetize = rtp_packetize_spx;
break;
case VLC_FOURCC( 't', '1', '4', '0' ):
- id->psz_rtpmap = strdup( "t140/1000" );
+ id->psz_enc = "t140" ;
id->i_clock_rate = 1000;
id->pf_packetize = rtp_packetize_t140;
break;
p_sys->i_port_video = id->i_port;
}
- free( id->psz_rtpmap );
free( id->psz_fmtp );
if( id->rtsp_id )
if( p_sys->b_export_sdp_file ) FileSetup( p_stream );
vlc_object_detach( id );
- vlc_object_destroy( id );
+ vlc_object_release( id );
return VLC_SUCCESS;
}
if( ( p_sys->i_es > 0 || p_sys->p_mux ) && p_sys->psz_sdp && *p_sys->psz_sdp )
{
announce_method_t *p_method = sout_SAPMethod();
- p_sys->p_session = sout_AnnounceRegisterSDP( p_sout, SOUT_CFG_PREFIX,
+ p_sys->p_session = sout_AnnounceRegisterSDP( p_sout,
p_sys->psz_sdp,
p_sys->psz_destination,
p_method );
httpd_file_t *f, uint8_t *p_request,
uint8_t **pp_data, int *pi_data )
{
+ VLC_UNUSED(f); VLC_UNUSED(p_request);
sout_stream_sys_t *p_sys = (sout_stream_sys_t*)p_args;
vlc_mutex_lock( &p_sys->lock_sdp );
#endif
}
-static inline void rtp_packetize_send( sout_stream_id_t *id, block_t *out )
-{
- block_FifoPut( id->p_fifo, out );
-}
-
int rtp_add_sink( sout_stream_id_t *id, int fd, vlc_bool_t rtcp_mux )
{
rtp_sink_t sink = { fd, NULL };
}
-/****************************************************************************
- * rtp_packetize_*:
- ****************************************************************************/
-static void rtp_packetize_common( sout_stream_id_t *id, block_t *out,
- int b_marker, int64_t i_pts )
+void rtp_packetize_common( sout_stream_id_t *id, block_t *out,
+ int b_marker, int64_t i_pts )
{
uint32_t i_timestamp = i_pts * (int64_t)id->i_clock_rate / I64C(1000000);
id->i_sequence++;
}
-static int rtp_packetize_mpa( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
+void rtp_packetize_send( sout_stream_id_t *id, block_t *out )
{
- int i_max = id->i_mtu - 12 - 4; /* payload max in one packet */
- 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;
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream, 16 + i_payload );
-
- /* 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;
- /* fragment offset in the current frame */
- out->p_buffer[14] = ( (i*i_max) >> 8 )&0xff;
- out->p_buffer[15] = ( (i*i_max) )&0xff;
- memcpy( &out->p_buffer[16], p_data, i_payload );
-
- out->i_buffer = 16 + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-/* rfc2250 */
-static int rtp_packetize_mpv( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 12 - 4; /* payload max in one packet */
- 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;
- int b_sequence_start = 0;
- int i_temporal_ref = 0;
- int i_picture_coding_type = 0;
- int i_fbv = 0, i_bfc = 0, i_ffv = 0, i_ffc = 0;
- int b_start_slice = 0;
-
- /* preparse this packet to get some info */
- if( in->i_buffer > 4 )
- {
- uint8_t *p = p_data;
- int i_rest = in->i_buffer;
-
- for( ;; )
- {
- while( i_rest > 4 &&
- ( p[0] != 0x00 || p[1] != 0x00 || p[2] != 0x01 ) )
- {
- p++;
- i_rest--;
- }
- if( i_rest <= 4 )
- {
- break;
- }
- p += 3;
- i_rest -= 4;
-
- if( *p == 0xb3 )
- {
- /* sequence start code */
- b_sequence_start = 1;
- }
- else if( *p == 0x00 && i_rest >= 4 )
- {
- /* picture */
- i_temporal_ref = ( p[1] << 2) |((p[2]>>6)&0x03);
- i_picture_coding_type = (p[2] >> 3)&0x07;
-
- if( i_rest >= 4 && ( i_picture_coding_type == 2 ||
- i_picture_coding_type == 3 ) )
- {
- i_ffv = (p[3] >> 2)&0x01;
- i_ffc = ((p[3]&0x03) << 1)|((p[4]>>7)&0x01);
- if( i_rest > 4 && i_picture_coding_type == 3 )
- {
- i_fbv = (p[4]>>6)&0x01;
- i_bfc = (p[4]>>3)&0x07;
- }
- }
- }
- else if( *p <= 0xaf )
- {
- b_start_slice = 1;
- }
- }
- }
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream,
- 16 + i_payload );
- uint32_t h = ( i_temporal_ref << 16 )|
- ( b_sequence_start << 13 )|
- ( b_start_slice << 12 )|
- ( i == i_count - 1 ? 1 << 11 : 0 )|
- ( i_picture_coding_type << 8 )|
- ( i_fbv << 7 )|( i_bfc << 4 )|( i_ffv << 3 )|i_ffc;
-
- /* rtp common header */
- 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;
-
- memcpy( &out->p_buffer[16], p_data, i_payload );
-
- out->i_buffer = 16 + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-static int rtp_packetize_ac3( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 12 - 2; /* payload max in one packet */
- 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;
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream, 14 + i_payload );
-
- /* rtp common header */
- rtp_packetize_common( id, out, (i == i_count - 1)?1:0, in->i_pts );
- /* unit count */
- out->p_buffer[12] = 1;
- /* unit header */
- out->p_buffer[13] = 0x00;
- /* data */
- memcpy( &out->p_buffer[14], p_data, i_payload );
-
- out->i_buffer = 14 + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-static int rtp_packetize_split( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 12; /* payload max in one packet */
- 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;
-
- for( i = 0; i < i_count; i++ )
- {
- 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, ((i == i_count - 1)?1: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 * 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;
-}
-
-/* rfc3016 */
-static int rtp_packetize_mp4a_latm( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 14; /* payload max in one packet */
- int latmhdrsize = in->i_buffer / 0xff + 1;
- int i_count = ( in->i_buffer + i_max - 1 ) / i_max;
-
- uint8_t *p_data = in->p_buffer, *p_header = NULL;
- int i_data = in->i_buffer;
- int i;
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out;
-
- if( i != 0 )
- latmhdrsize = 0;
- out = block_New( p_stream, 12 + latmhdrsize + i_payload );
-
- /* rtp common header */
- rtp_packetize_common( id, out, ((i == i_count - 1) ? 1 : 0),
- (in->i_pts > 0 ? in->i_pts : in->i_dts) );
-
- if( i == 0 )
- {
- int tmp = in->i_buffer;
-
- p_header=out->p_buffer+12;
- while( tmp > 0xfe )
- {
- *p_header = 0xff;
- p_header++;
- tmp -= 0xff;
- }
- *p_header = tmp;
- }
-
- memcpy( &out->p_buffer[12+latmhdrsize], p_data, i_payload );
-
- out->i_buffer = 12 + latmhdrsize + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-static int rtp_packetize_l16( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 12; /* payload max in one packet */
- 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 )/4)*4;
- 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;
- i_packet++;
- }
-
- return VLC_SUCCESS;
-}
-
-static int rtp_packetize_l8( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 12; /* payload max in one packet */
- 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 )/2)*2;
- 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;
- i_packet++;
- }
-
- return VLC_SUCCESS;
-}
-
-static int rtp_packetize_mp4a( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- int i_max = id->i_mtu - 16; /* payload max in one packet */
- 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;
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream, 16 + i_payload );
-
- /* rtp common header */
- rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
- (in->i_pts > 0 ? in->i_pts : in->i_dts) );
- /* AU headers */
- /* AU headers length (bits) */
- 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;
-
- memcpy( &out->p_buffer[16], p_data, i_payload );
-
- out->i_buffer = 16 + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-
-/* rfc2429 */
-#define RTP_H263_HEADER_SIZE (2) // plen = 0
-#define RTP_H263_PAYLOAD_START (14) // plen = 0
-static int rtp_packetize_h263( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- uint8_t *p_data = in->p_buffer;
- int i_data = in->i_buffer;
- int i;
- int i_max = id->i_mtu - 12 - RTP_H263_HEADER_SIZE; /* payload max in one packet */
- int i_count;
- int b_p_bit;
- int b_v_bit = 0; // no pesky error resilience
- int i_plen = 0; // normally plen=0 for PSC packet
- int i_pebit = 0; // because plen=0
- uint16_t h;
-
- if( i_data < 2 )
- {
- return VLC_EGENERIC;
- }
- if( p_data[0] || p_data[1] )
- {
- return VLC_EGENERIC;
- }
- /* remove 2 leading 0 bytes */
- p_data += 2;
- i_data -= 2;
- i_count = ( i_data + i_max - 1 ) / i_max;
-
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream,
- RTP_H263_PAYLOAD_START + i_payload );
- b_p_bit = (i == 0) ? 1 : 0;
- h = ( b_p_bit << 10 )|
- ( b_v_bit << 9 )|
- ( i_plen << 3 )|
- i_pebit;
-
- /* rtp common header */
- //b_m_bit = 1; // always contains end of frame
- rtp_packetize_common( id, out, (i == i_count - 1)?1:0,
- 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;
- memcpy( &out->p_buffer[RTP_H263_PAYLOAD_START], p_data, i_payload );
-
- out->i_buffer = RTP_H263_PAYLOAD_START + i_payload;
- out->i_dts = in->i_dts + i * 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;
-}
-
-/* rfc3984 */
-static int
-rtp_packetize_h264_nal( sout_stream_t *p_stream, sout_stream_id_t *id,
- const uint8_t *p_data, int i_data, int64_t i_pts,
- int64_t i_dts, vlc_bool_t b_last, int64_t i_length )
-{
- const int i_max = id->i_mtu - 12; /* payload max in one packet */
- int i_nal_hdr;
- int i_nal_type;
-
- if( i_data < 5 )
- return VLC_SUCCESS;
-
- i_nal_hdr = p_data[3];
- i_nal_type = i_nal_hdr&0x1f;
-
- /* Skip start code */
- p_data += 3;
- i_data -= 3;
-
- /* */
- if( i_data <= i_max )
- {
- /* Single NAL unit packet */
- block_t *out = block_New( p_stream, 12 + i_data );
- out->i_dts = i_dts;
- out->i_length = i_length;
-
- /* */
- rtp_packetize_common( id, out, b_last, i_pts );
- out->i_buffer = 12 + i_data;
-
- memcpy( &out->p_buffer[12], p_data, i_data );
-
- rtp_packetize_send( id, out );
- }
- else
- {
- /* FU-A Fragmentation Unit without interleaving */
- const int i_count = ( i_data-1 + i_max-2 - 1 ) / (i_max-2);
- int i;
-
- p_data++;
- i_data--;
-
- for( i = 0; i < i_count; i++ )
- {
- const int i_payload = __MIN( i_data, i_max-2 );
- block_t *out = block_New( p_stream, 12 + 2 + i_payload );
- out->i_dts = i_dts + i * i_length / i_count;
- out->i_length = i_length / i_count;
-
- /* */
- rtp_packetize_common( id, out, (b_last && i_payload == i_data), i_pts );
- out->i_buffer = 14 + i_payload;
-
- /* FU indicator */
- out->p_buffer[12] = 0x00 | (i_nal_hdr & 0x60) | 28;
- /* FU header */
- out->p_buffer[13] = ( i == 0 ? 0x80 : 0x00 ) | ( (i == i_count-1) ? 0x40 : 0x00 ) | i_nal_type;
- memcpy( &out->p_buffer[14], p_data, i_payload );
-
- rtp_packetize_send( id, out );
-
- i_data -= i_payload;
- p_data += i_payload;
- }
- }
- return VLC_SUCCESS;
+ block_FifoPut( id->p_fifo, out );
}
-static int rtp_packetize_h264( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
+/**
+ * @return configured max RTP payload size (including payload type-specific
+ * headers, excluding RTP and transport headers)
+ */
+size_t rtp_mtu (const sout_stream_id_t *id)
{
- const uint8_t *p_buffer = in->p_buffer;
- int i_buffer = in->i_buffer;
-
- while( i_buffer > 4 && ( p_buffer[0] != 0 || p_buffer[1] != 0 || p_buffer[2] != 1 ) )
- {
- i_buffer--;
- p_buffer++;
- }
-
- /* Split nal units */
- while( i_buffer > 4 )
- {
- int i_offset;
- int i_size = i_buffer;
- int i_skip = i_buffer;
-
- /* search nal end */
- for( i_offset = 4; i_offset+2 < i_buffer ; i_offset++)
- {
- if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 && p_buffer[i_offset+2] == 1 )
- {
- /* we found another startcode */
- i_size = i_offset - ( p_buffer[i_offset-1] == 0 ? 1 : 0);
- i_skip = i_offset;
- break;
- }
- }
- /* 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,
- (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 );
-
- i_buffer -= i_skip;
- p_buffer += i_skip;
- }
- return VLC_SUCCESS;
+ return id->i_mtu - 12;
}
-static int rtp_packetize_amr( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
+/**
+ * @return number of audio samples to include for a given packetization time
+ * (this really only makes sense for audio formats).
+ */
+size_t rtp_plen (const sout_stream_id_t * id, unsigned ptime_ms)
{
- int i_max = id->i_mtu - 14; /* payload max in one packet */
- 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;
-
- /* Only supports octet-aligned mode */
- for( i = 0; i < i_count; i++ )
- {
- int i_payload = __MIN( i_max, i_data );
- block_t *out = block_New( p_stream, 14 + i_payload );
-
- /* rtp common header */
- rtp_packetize_common( id, out, ((i == i_count - 1)?1:0),
- (in->i_pts > 0 ? in->i_pts : in->i_dts) );
- /* Payload header */
- out->p_buffer[12] = 0xF0; /* CMR */
- out->p_buffer[13] = p_data[0]&0x7C; /* ToC */ /* FIXME: frame type */
-
- /* FIXME: are we fed multiple frames ? */
- memcpy( &out->p_buffer[14], p_data+1, i_payload-1 );
-
- out->i_buffer = 14 + i_payload-1;
- out->i_dts = in->i_dts + i * 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;
+ return id->i_channels * (((id->i_clock_rate - 1) * ptime_ms / 1000) + 1);
}
-static int rtp_packetize_t140( sout_stream_t *p_stream, sout_stream_id_t *id,
- block_t *in )
-{
- const size_t i_max = id->i_mtu - 12;
- const uint8_t *p_data = in->p_buffer;
- size_t i_data = in->i_buffer;
-
- for( unsigned i_packet = 0; i_data > 0; i_packet++ )
- {
- size_t i_payload = i_data;
-
- /* Make sure we stop on an UTF-8 character boundary
- * (assuming the input is valid UTF-8) */
- if( i_data > i_max )
- {
- i_payload = i_max;
-
- while( ( p_data[i_payload] & 0xC0 ) == 0x80 )
- {
- if( i_payload == 0 )
- return VLC_SUCCESS; /* fishy input! */
-
- i_payload--;
- }
- }
-
- block_t *out = block_New( p_stream, 12 + i_payload );
- if( out == NULL )
- return VLC_SUCCESS;
-
- rtp_packetize_common( id, out, 0, in->i_pts + i_packet );
- memcpy( out->p_buffer + 12, p_data, i_payload );
-
- out->i_buffer = 12 + i_payload;
- out->i_dts = out->i_pts;
- out->i_length = 0;
-
- rtp_packetize_send( id, out );
-
- p_data += i_payload;
- i_data -= i_payload;
- }
-
- return VLC_SUCCESS;
-}
/*****************************************************************************
* Non-RTP mux
p_grab->p_sys = (sout_access_out_sys_t *)p_stream;
p_grab->pf_seek = NULL;
p_grab->pf_write = AccessOutGrabberWrite;
+ vlc_object_attach( p_grab, p_stream );
return p_grab;
}
-
-static int rtp_packetize_spx( sout_stream_t *p_stream, 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;
- i_data_size = i_payload_size = in->i_buffer;
- i_payload_padding = 0;
- block_t *p_out;
-
- if ( in->i_buffer + 12 > id->i_mtu )
- {
- 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
- boundary. So, we check to see if the number of bytes % 4 is zero.
- If not, we have to add some padding.
-
- This MAY be overkill since packetization is handled elsewhere and
- appears to ensure the octet boundary. However, better safe than
- sorry.
- */
- if ( i_payload_size % 4 )
- {
- i_payload_padding = 4 - ( i_payload_size % 4 );
- i_payload_size += i_payload_padding;
- }
-
- /*
- Allocate a new RTP p_output block of the appropriate size.
- Allow for 12 extra bytes of RTP header.
- */
- p_out = block_New( p_stream, 12 + i_payload_size );
-
- if ( i_payload_padding )
- {
- /*
- The padding is required to be a zero followed by all 1s.
- */
- char c_first_pad, c_remaining_pad;
- c_first_pad = 0x7F;
- c_remaining_pad = 0xFF;
-
- /*
- Allow for 12 bytes before the i_data_size because
- of the expected RTP header added during
- rtp_packetize_common.
- */
- p_out->p_buffer[12 + i_data_size] = c_first_pad;
- switch (i_payload_padding)
- {
- case 2:
- p_out->p_buffer[12 + i_data_size + 1] = c_remaining_pad;
- break;
- case 3:
- p_out->p_buffer[12 + i_data_size + 1] = c_remaining_pad;
- p_out->p_buffer[12 + i_data_size + 2] = c_remaining_pad;
- break;
- }
- }
-
- /* Add the RTP header to our p_output buffer. */
- rtp_packetize_common( id, p_out, 0, (in->i_pts > 0 ? in->i_pts : in->i_dts) );
- /* Copy the Speex payload to the p_output buffer */
- memcpy( &p_out->p_buffer[12], p_buffer, i_data_size );
-
- p_out->i_buffer = 12 + i_payload_size;
- p_out->i_dts = in->i_dts;
- p_out->i_length = in->i_length;
-
- /* Queue the buffer for actual transmission. */
- rtp_packetize_send( id, p_out );
- return VLC_SUCCESS;
-}