[vlc-commits] avformat demux: update to new AVIO apis

Rafaël Carré git at videolan.org
Sun Jan 29 07:19:00 CET 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Sun Jan 29 01:12:18 2012 -0500| [deb3faef4cd61081372a5e2b693497880113d20d] | committer: Rafaël Carré

avformat demux: update to new AVIO apis

also use avformat_open_input() and print its errors

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=deb3faef4cd61081372a5e2b693497880113d20d
---

 modules/demux/avformat/demux.c |   41 +++++++++++++++++++--------------------
 1 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/modules/demux/avformat/demux.c b/modules/demux/avformat/demux.c
index f427744..902f578 100644
--- a/modules/demux/avformat/demux.c
+++ b/modules/demux/avformat/demux.c
@@ -67,7 +67,12 @@
  *****************************************************************************/
 struct demux_sys_t
 {
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(105<<8)+0)
+    AVIOContext     *io;
+#else
     ByteIOContext   io;
+#endif
+
     int             io_buffer_size;
     uint8_t        *io_buffer;
 
@@ -132,6 +137,7 @@ int OpenDemux( vlc_object_t *p_this )
         msg_Warn( p_demux, "cannot peek" );
         return VLC_EGENERIC;
     }
+    stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek );
 
     vlc_avcodec_lock();
     av_register_all(); /* Can be called several times */
@@ -212,35 +218,28 @@ int OpenDemux( vlc_object_t *p_this )
     /* Create I/O wrapper */
     p_sys->io_buffer_size = 32768;  /* FIXME */
     p_sys->io_buffer = malloc( p_sys->io_buffer_size );
-    init_put_byte( &p_sys->io, p_sys->io_buffer, p_sys->io_buffer_size,
-                   0, p_demux, IORead, NULL, IOSeek );
 
-    stream_Control( p_demux->s, STREAM_CAN_SEEK, &b_can_seek );
-    if( !b_can_seek )
-    {
-       /* Tell avformat that input is stream, so it doesn't get stuck
-       when trying av_find_stream_info() trying to seek all the wrong places
-       init_put_byte defaults io.is_streamed=0, so thats why we set them after it
-       */
-       p_sys->io.is_streamed = 1;
-#if defined(AVIO_SEEKABLE_NORMAL)
-       p_sys->io.seekable = 0;
+#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(105<<8)+0)
+    p_sys->io = avio_alloc_context( p_sys->io_buffer, p_sys->io_buffer_size, 0,
+        p_demux, IORead, NULL, IOSeek );
+    p_sys->io->seekable = b_can_seek ? AVIO_SEEKABLE_NORMAL : 0;
+    error = avformat_open_input(&p_sys->ic, psz_url, p_sys->fmt, NULL);
+#else
+    init_put_byte( &p_sys->io, p_sys->io_buffer, p_sys->io_buffer_size, 0,
+        p_demux, IORead, NULL, IOSeek );
+    p_sys->io.is_streamed = !b_can_seek;
+    error = av_open_input_stream(&p_sys->ic, &p_sys->io, psz_url, p_sys->fmt, NULL);
 #endif
-    }
-
 
-    /* Open it */
-    if( av_open_input_stream( &p_sys->ic, &p_sys->io, psz_url,
-                              p_sys->fmt, NULL ) )
+    free( psz_url );
+    if( error < 0 )
     {
-        msg_Err( p_demux, "av_open_input_stream failed" );
+        errno = AVUNERROR(error);
+        msg_Err( p_demux, "Could not open %s: %m", psz_url );
         p_sys->ic = NULL;
-        free( psz_url );
         CloseDemux( p_this );
         return VLC_EGENERIC;
     }
-    free( psz_url );
-    psz_url = NULL;
 
     vlc_avcodec_lock(); /* avformat calls avcodec behind our back!!! */
 #if LIBAVFORMAT_VERSION_INT >= ((53<<16)+(17<<8)+0)



More information about the vlc-commits mailing list