]> git.sesse.net Git - vlc/blobdiff - modules/stream_out/rtp.c
block_FifoNew: remove un-needed parameter
[vlc] / modules / stream_out / rtp.c
index 193f0221fb0b03177f6ccfb0300ebddaaecea5c4..f0aae26a193f70f6562c0e3f99f166e0a0b2894f 100644 (file)
@@ -64,8 +64,8 @@
  * Module descriptor
  *****************************************************************************/
 
-#define DST_TEXT N_("Destination")
-#define DST_LONGTEXT N_( \
+#define DEST_TEXT N_("Destination")
+#define DEST_LONGTEXT N_( \
     "This is the output URL that will be used." )
 #define SDP_TEXT N_("SDP")
 #define SDP_LONGTEXT N_( \
     "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_( \
@@ -149,47 +151,42 @@ vlc_module_begin();
     set_category( CAT_SOUT );
     set_subcategory( SUBCAT_SOUT_STREAM );
 
-    add_string( SOUT_CFG_PREFIX "dst", "", NULL, DST_TEXT,
-                DST_LONGTEXT, VLC_TRUE );
+    add_string( SOUT_CFG_PREFIX "dst", "", NULL, DEST_TEXT,
+                DEST_LONGTEXT, true );
         change_unsafe();
     add_string( SOUT_CFG_PREFIX "sdp", "", NULL, SDP_TEXT,
-                SDP_LONGTEXT, VLC_TRUE );
+                SDP_LONGTEXT, true );
     add_string( SOUT_CFG_PREFIX "mux", "", NULL, MUX_TEXT,
-                MUX_LONGTEXT, VLC_TRUE );
+                MUX_LONGTEXT, true );
 
     add_string( SOUT_CFG_PREFIX "name", "", NULL, NAME_TEXT,
-                NAME_LONGTEXT, VLC_TRUE );
+                NAME_LONGTEXT, true );
     add_string( SOUT_CFG_PREFIX "description", "", NULL, DESC_TEXT,
-                DESC_LONGTEXT, VLC_TRUE );
+                DESC_LONGTEXT, true );
     add_string( SOUT_CFG_PREFIX "url", "", NULL, URL_TEXT,
-                URL_LONGTEXT, VLC_TRUE );
+                URL_LONGTEXT, true );
     add_string( SOUT_CFG_PREFIX "email", "", NULL, EMAIL_TEXT,
-                EMAIL_LONGTEXT, VLC_TRUE );
+                EMAIL_LONGTEXT, true );
     add_string( SOUT_CFG_PREFIX "phone", "", NULL, PHONE_TEXT,
-                PHONE_LONGTEXT, VLC_TRUE );
-
-    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,
-                 PORT_AUDIO_LONGTEXT, VLC_TRUE );
-    add_integer( SOUT_CFG_PREFIX "port-video", 1232, NULL, PORT_VIDEO_TEXT,
-                 PORT_VIDEO_LONGTEXT, VLC_TRUE );
+                PHONE_LONGTEXT, true );
+
+    add_string( SOUT_CFG_PREFIX "proto", "udp", NULL, PROTO_TEXT,
+                PROTO_LONGTEXT, false );
+        change_string_list( ppsz_protos, ppsz_protocols, NULL );
+    add_integer( SOUT_CFG_PREFIX "port", 50004, NULL, PORT_TEXT,
+                 PORT_LONGTEXT, true );
+    add_integer( SOUT_CFG_PREFIX "port-audio", 50000, NULL, PORT_AUDIO_TEXT,
+                 PORT_AUDIO_LONGTEXT, true );
+    add_integer( SOUT_CFG_PREFIX "port-video", 50002, NULL, PORT_VIDEO_TEXT,
+                 PORT_VIDEO_LONGTEXT, true );
 
     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 );
+                 TTL_LONGTEXT, true );
+    add_bool( SOUT_CFG_PREFIX "rtcp-mux", false, NULL,
+              RTCP_MUX_TEXT, RTCP_MUX_LONGTEXT, false );
 
     add_bool( SOUT_CFG_PREFIX "mp4a-latm", 0, NULL, RFC3016_TEXT,
-                 RFC3016_LONGTEXT, VLC_FALSE );
+                 RFC3016_LONGTEXT, false );
 
     set_callbacks( Open, Close );
 vlc_module_end();
@@ -200,7 +197,7 @@ vlc_module_end();
 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
 };
 
@@ -220,7 +217,7 @@ static void SDPHandleUrl( sout_stream_t *, char * );
 
 static int SapSetup( sout_stream_t *p_stream );
 static int FileSetup( sout_stream_t *p_stream );
-static int HttpSetup( sout_stream_t *p_stream, vlc_url_t * );
+static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t * );
 
 struct sout_stream_sys_t
 {
@@ -229,11 +226,11 @@ struct sout_stream_sys_t
     vlc_mutex_t  lock_sdp;
 
     /* SDP to disk */
-    vlc_bool_t b_export_sdp_file;
+    bool b_export_sdp_file;
     char *psz_sdp_file;
 
     /* SDP via SAP */
-    vlc_bool_t b_export_sap;
+    bool b_export_sap;
     session_descriptor_t *p_session;
 
     /* SDP via HTTP */
@@ -250,8 +247,8 @@ struct sout_stream_sys_t
     uint16_t  i_port;
     uint16_t  i_port_audio;
     uint16_t  i_port_video;
-    vlc_bool_t b_latm;
-    vlc_bool_t rtcp_mux;
+    bool b_latm;
+    bool rtcp_mux;
 
     /* when need to use a private one or when using muxer */
     int i_payload_type;
@@ -310,7 +307,6 @@ struct sout_stream_id_t
     int64_t           i_caching;
 };
 
-
 /*****************************************************************************
  * Open:
  *****************************************************************************/
@@ -321,7 +317,7 @@ static int Open( vlc_object_t *p_this )
     sout_stream_sys_t   *p_sys = NULL;
     config_chain_t      *p_cfg = NULL;
     char                *psz;
-    vlc_bool_t          b_rtsp = VLC_FALSE;
+    bool          b_rtsp = false;
 
     config_ChainParse( p_stream, SOUT_CFG_PREFIX,
                        ppsz_sout_options, p_stream->p_cfg );
@@ -352,7 +348,7 @@ static int Open( vlc_object_t *p_this )
          && ( p_cfg->psz_value != NULL )
          && !strncasecmp( p_cfg->psz_value, "rtsp:", 5 ) )
         {
-            b_rtsp = VLC_TRUE;
+            b_rtsp = true;
             break;
         }
     }
@@ -362,30 +358,47 @@ static int Open( vlc_object_t *p_this )
         if( psz != NULL )
         {
             if( !strncasecmp( psz, "rtsp:", 5 ) )
-                b_rtsp = VLC_TRUE;
+                b_rtsp = true;
             free( psz );
         }
     }
 
     /* 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 */
+        p_sys->rtcp_mux = 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 */
+        p_sys->rtcp_mux = true; /* Force RTP/RTCP mux */
     }
+#endif
+#if 0
     else
+    if (!strcasecmp (psz, "tcp"))
+    {
+        p_sys->proto = IPPROTO_TCP;
+        p_sys->rtcp_mux = 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 )
     {
@@ -412,8 +425,8 @@ static int Open( vlc_object_t *p_this )
     p_sys->rtsp = NULL;
     p_sys->psz_sdp = NULL;
 
-    p_sys->b_export_sap = VLC_FALSE;
-    p_sys->b_export_sdp_file = VLC_FALSE;
+    p_sys->b_export_sap = false;
+    p_sys->b_export_sdp_file = false;
     p_sys->p_session = NULL;
 
     p_sys->p_httpd_host = NULL;
@@ -615,7 +628,7 @@ static void SDPHandleUrl( sout_stream_t *p_stream, char *psz_url )
     else if( ( url.psz_protocol && !strcasecmp( url.psz_protocol, "sap" ) ) ||
              ( url.psz_host && !strcasecmp( url.psz_host, "sap" ) ) )
     {
-        p_sys->b_export_sap = VLC_TRUE;
+        p_sys->b_export_sap = true;
         SapSetup( p_stream );
     }
     else if( url.psz_protocol && !strcasecmp( url.psz_protocol, "file" ) )
@@ -625,7 +638,7 @@ static void SDPHandleUrl( sout_stream_t *p_stream, char *psz_url )
             msg_Err( p_stream, "you can use sdp=file:// only once" );
             goto out;
         }
-        p_sys->b_export_sdp_file = VLC_TRUE;
+        p_sys->b_export_sdp_file = true;
         psz_url = &psz_url[5];
         if( psz_url[0] == '/' && psz_url[1] == '/' )
             psz_url += 2;
@@ -747,14 +760,14 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
         }
 
         sdp_AddMedia( &psz_sdp, mime_major, proto, inclport * id->i_port,
-                      id->i_payload_type, VLC_FALSE, id->i_bitrate,
+                      id->i_payload_type, false, id->i_bitrate,
                       id->psz_enc, id->i_clock_rate, id->i_channels,
                       id->psz_fmtp);
 
         if( rtsp_url != NULL )
         {
             assert( strlen( rtsp_url ) > 0 );
-            vlc_bool_t addslash = ( rtsp_url[strlen( rtsp_url ) - 1] != '/' );
+            bool addslash = ( rtsp_url[strlen( rtsp_url ) - 1] != '/' );
             sdp_AddAttribute ( &psz_sdp, "control",
                                addslash ? "%s/trackID=%u" : "%strackID=%u",
                                rtsp_url, i );
@@ -763,11 +776,9 @@ char *SDPGenerate( const sout_stream_t *p_stream, const char *rtsp_url )
         {
             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
         }
     }
 
@@ -886,8 +897,19 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
     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 );
@@ -1140,9 +1162,9 @@ static sout_stream_id_t *Add( sout_stream_t *p_stream, es_format_t *p_fmt )
                                  p_sys->psz_destination,
                                  p_sys->i_ttl, id->i_port, id->i_port + 1 );
 
-    id->p_fifo = block_FifoNew( p_stream );
+    id->p_fifo = block_FifoNew();
     if( vlc_thread_create( id, "RTP send thread", ThreadSend,
-                           VLC_THREAD_PRIORITY_HIGHEST, VLC_FALSE ) )
+                           VLC_THREAD_PRIORITY_HIGHEST, false ) )
         goto error;
 
     /* Update p_sys context */
@@ -1187,13 +1209,10 @@ static int Del( sout_stream_t *p_stream, sout_stream_id_t *id )
     vlc_mutex_unlock( &p_sys->lock_es );
 
     /* Release port */
-    if( id->i_port > 0 )
-    {
-        if( id->i_cat == AUDIO_ES && p_sys->i_port_audio == 0 )
-            p_sys->i_port_audio = id->i_port;
-        else if( id->i_cat == VIDEO_ES && p_sys->i_port_video == 0 )
-            p_sys->i_port_video = id->i_port;
-    }
+    if( id->i_port == var_GetInteger( p_stream, "port-audio" ) )
+        p_sys->i_port_audio = id->i_port;
+    if( id->i_port == var_GetInteger( p_stream, "port-video" ) )
+        p_sys->i_port_video = id->i_port;
 
     free( id->psz_fmtp );
 
@@ -1290,7 +1309,7 @@ static int  HttpCallback( httpd_file_sys_t *p_args,
                           httpd_file_t *, uint8_t *p_request,
                           uint8_t **pp_data, int *pi_data );
 
-static int HttpSetup( sout_stream_t *p_stream, vlc_url_t *url)
+static int HttpSetup( sout_stream_t *p_stream, const vlc_url_t *url)
 {
     sout_stream_sys_t *p_sys = p_stream->p_sys;
 
@@ -1419,7 +1438,7 @@ static void ThreadSend( vlc_object_t *p_this )
             if( fd == -1 )
                 break;
             msg_Dbg( id, "adding socket %d", fd );
-            rtp_add_sink( id, fd, VLC_TRUE );
+            rtp_add_sink( id, fd, true );
         }
     }
 
@@ -1429,7 +1448,7 @@ static void ThreadSend( vlc_object_t *p_this )
 #endif
 }
 
-int rtp_add_sink( sout_stream_id_t *id, int fd, vlc_bool_t rtcp_mux )
+int rtp_add_sink( sout_stream_id_t *id, int fd, bool rtcp_mux )
 {
     rtp_sink_t sink = { fd, NULL };
     sink.rtcp = OpenRTCP( VLC_OBJECT( id->p_stream ), fd, IPPROTO_UDP,
@@ -1493,7 +1512,7 @@ unsigned rtp_get_num( const sout_stream_id_t *id )
 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);
+    uint32_t i_timestamp = i_pts * (int64_t)id->i_clock_rate / INT64_C(1000000);
 
     out->p_buffer[0] = 0x80;
     out->p_buffer[1] = (b_marker?0x80:0x00)|id->i_payload_type;
@@ -1665,5 +1684,6 @@ static sout_access_out_t *GrabberCreate( sout_stream_t *p_stream )
     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;
 }