Hi,

2010/6/23 Rémi Denis-Courmont <[email protected]>:
> On Saturday 12 June 2010 08:53:03 Josh Allmann, you wrote:
>> Hello,
>>
>> Here is a first attempt at integrating the RTSP layer from ffmpeg. It
>> does so by adding an access demuxer to the VLC scaffolding for
>> libavformat.
>>
>> All the major transports are working (udp, tcp, rtsp-http). I have not
>> yet looked at features like auth or muxing, but I can do that once I
>> know this patch is on the right track.
>
> @@ -117,10 +119,33 @@ int OpenDemux( vlc_object_t *p_this )
>     unsigned int  i;
>     int64_t       i_start_time = -1;
>     bool          b_can_seek;
> +    char          filename[128] = "", opts[8] = "";
> +    int           filename_len = 0;
>
> I'm afraid an RTSP URL could easily exceed 127 characters. Why don't you use
> asprintf() or similar instead?
>

Well, that's a good function to know. Fixed.

> +    if( var_CreateGetBool( p_demux, "rtsp-tcp" ) )
>
> var_InheritBool.
>

Fixed

> +        strcpy(opts, "?tcp");
>
> If I'm not mistaken, you could simply assign a const char pointer instead of
> using strcpy().

Fixed

>
> +    else if( var_CreateGetBool( p_demux, "rtsp-http" ) )
> +        strcpy(opts, "?http");
> +    else if( var_CreateGetBool( p_demux, "rtsp-udp" ) )
> +        strcpy(opts, "?udp");
>
> Same notes as above.
>

Fixed

> +    /* build the filename string */
> +    if( p_demux->psz_access )
> +    {
> +        filename_len += av_strlcatf( filename + filename_len,
> +                                     sizeof(filename) - filename_len,
> +                                     "%s://", p_demux->psz_access);
> +    }
> +    filename_len += av_strlcpy( filename + filename_len,
> +                                p_demux->psz_path,
> +                                sizeof(filename) - filename_len );
> +    filename_len += av_strlcpy( filename + filename_len,
> +                                opts,
> +                                sizeof(filename) - filename_len );
>
> As noted above, this could probably be corrected and simplified to
> if (psz_access) asprintf(...); else asprintf(...);
> plus error handling.
>

Indeed, simplified considerably.

> --
> Rémi Denis-Courmont
>
From be97c3f9257b1110cc4836b70fda5619a8cc171b Mon Sep 17 00:00:00 2001
From: Josh Allmann <[email protected]>
Date: Fri, 11 Jun 2010 22:17:31 -0700
Subject: [PATCH] Integrate FFmpeg RTSP.

---
 modules/demux/avformat/avformat.c |   29 +++++++++++++++++++++++++++++
 modules/demux/avformat/demux.c    |   37 +++++++++++++++++++++++++++++++++----
 2 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/modules/demux/avformat/avformat.c b/modules/demux/avformat/avformat.c
index b5974a4..6c835a7 100644
--- a/modules/demux/avformat/avformat.c
+++ b/modules/demux/avformat/avformat.c
@@ -22,6 +22,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#define CACHING_TEXT N_("Caching value (ms)")
+#define CACHING_LONGTEXT N_( \
+    "Allows you to modify the default caching value for RTSP streams. This " \
+    "value should be set in millisecond units." )
+
+
 #ifndef MERGE_FFMPEG
 #ifdef HAVE_CONFIG_H
 # include "config.h"
@@ -42,6 +48,29 @@ vlc_module_begin ()
     set_capability( "demux", 2 )
     set_callbacks( OpenDemux, CloseDemux )
 
+    add_submodule()
+        set_description( N_("RTSP/RTP access and demux (FFmpeg)") )
+        add_shortcut( "ffmpeg" )
+        add_shortcut( "rtsp" )
+        add_shortcut( "sdp" )
+        set_capability( "access_demux", 0 )
+        set_callbacks( OpenDemux, CloseDemux )
+        add_integer("rtsp-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
+                    CACHING_TEXT, CACHING_LONGTEXT, true )
+        change_safe()
+        add_bool( "rtsp-tcp", false, NULL,
+                  N_("Use RTP over RTSP (TCP)"),
+                  N_("Use RTP over RTSP (TCP)"), true )
+            change_safe()
+        add_bool( "rtsp-http", false, NULL,
+                  N_("Tunnel RTSP and RTP over HTTP"),
+                  N_("Tunnel RTSP and RTP over HTTP"), true )
+            change_safe()
+        add_bool( "rtsp-udp", false, NULL,
+                  N_("Use RTP and RTSP over UDP (default)"),
+                  N_("Use RTP and RTSP over UDP (default)"), true )
+            change_safe()
+
 #ifdef ENABLE_SOUT
     /* mux submodule */
     add_submodule ()
diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index 3b5454b..2b79346 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -117,10 +117,31 @@ int OpenDemux( vlc_object_t *p_this )
     unsigned int  i;
     int64_t       i_start_time = -1;
     bool          b_can_seek;
+    char          *filename;
+
+    /* build the filename string */
+    if( !p_demux->s ){
+        /* access demuxing */
+        const char *opts;
+
+        if( var_InheritBool( p_demux, "rtsp-tcp" ) )
+            opts = "?tcp";
+        else if( var_InheritBool( p_demux, "rtsp-http" ) )
+            opts = "?http";
+        else if( var_InheritBool( p_demux, "rtsp-udp" ) )
+            opts = "?udp";
+        else
+            opts = "";
+
+       if( asprintf( &filename, "%s://%s%s",
+                     p_demux->psz_access, p_demux->psz_path, opts ) < 0 )
+            return VLC_EGENERIC;
+    }else
+        filename = p_demux->psz_path;
 
     /* Init Probe data */
-    pd.filename = p_demux->psz_path;
-    if( ( pd.buf_size = stream_Peek( p_demux->s, &pd.buf, 2048 + 213 ) ) <= 0 )
+    pd.filename = filename;
+    if( p_demux->s && ( pd.buf_size = stream_Peek( p_demux->s, &pd.buf, 2048 + 213 ) ) <= 0 )
     {
         msg_Warn( p_demux, "cannot peek" );
         return VLC_EGENERIC;
@@ -131,7 +152,7 @@ int OpenDemux( vlc_object_t *p_this )
     vlc_avcodec_unlock();
 
     /* Guess format */
-    if( !( fmt = av_probe_input_format( &pd, 1 ) ) )
+    if( !( fmt = av_probe_input_format( &pd, p_demux->s ? 1 : 0 ) ) )
     {
         msg_Dbg( p_demux, "couldn't guess format" );
         return VLC_EGENERIC;
@@ -171,6 +192,7 @@ int OpenDemux( vlc_object_t *p_this )
     msg_Dbg( p_demux, "detected format: %s", fmt->name );
 
     /* Fill p_demux fields */
+    var_Create( p_demux, "rtsp-caching", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
     p_demux->pf_demux = Demux;
     p_demux->pf_control = Control;
     p_demux->p_sys = p_sys = malloc( sizeof( demux_sys_t ) );
@@ -214,7 +236,7 @@ int OpenDemux( vlc_object_t *p_this )
 
 
     /* Open it */
-    if( av_open_input_stream( &p_sys->ic, &p_sys->io, p_demux->psz_path,
+    if( av_open_input_stream( &p_sys->ic, &p_sys->io, filename,
                               p_sys->fmt, NULL ) )
     {
         msg_Err( p_demux, "av_open_input_stream failed" );
@@ -463,6 +485,9 @@ int OpenDemux( vlc_object_t *p_this )
     }
 #endif
 
+    if( !p_demux->s )
+        free( filename );
+
     return VLC_SUCCESS;
 }
 
@@ -819,6 +844,10 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
         }
 
 
+        case DEMUX_GET_PTS_DELAY:
+            pi64 = (int64_t*)va_arg( args, int64_t * );
+            *pi64 = (int64_t)var_GetInteger( p_demux, "rtsp-caching" ) * 1000;
+            return VLC_SUCCESS;
         default:
             return VLC_EGENERIC;
     }
-- 
1.7.0.4

_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to