]> git.sesse.net Git - vlc/blobdiff - modules/demux/flac.c
Better packetizer helpers
[vlc] / modules / demux / flac.c
index 71aecf90294e263962e8d9a323f2ae94ba22b21a..ef8907475e00df08e692439e4de0860002bb667e 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * flac.c : FLAC demux module for vlc
  *****************************************************************************
- * Copyright (C) 2001-2003 VideoLAN
+ * Copyright (C) 2001-2003 the VideoLAN team
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
@@ -18,7 +18,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
@@ -56,6 +56,7 @@ struct demux_sys_t
 
     /* Packetizer */
     decoder_t *p_packetizer;
+    vlc_meta_t *p_meta;
 };
 
 #define STREAMINFO_SIZE 38
@@ -67,6 +68,7 @@ struct demux_sys_t
 static int Open( vlc_object_t * p_this )
 {
     demux_t     *p_demux = (demux_t*)p_this;
+    module_t    *p_id3;
     demux_sys_t *p_sys;
     int          i_peek;
     byte_t      *p_peek;
@@ -77,10 +79,8 @@ static int Open( vlc_object_t * p_this )
 
     if( p_peek[0]!='f' || p_peek[1]!='L' || p_peek[2]!='a' || p_peek[3]!='C' )
     {
-        if( strncmp( p_demux->psz_demux, "flac", 4 ) )
-        {
-            return VLC_EGENERIC;
-        }
+        if( !p_demux->b_force ) return VLC_EGENERIC;
+
         /* User forced */
         msg_Err( p_demux, "this doesn't look like a flac stream, "
                  "continuing anyway" );
@@ -91,6 +91,7 @@ static int Open( vlc_object_t * p_this )
     p_demux->p_sys      = p_sys = malloc( sizeof( demux_sys_t ) );
     es_format_Init( &fmt, AUDIO_ES, VLC_FOURCC( 'f', 'l', 'a', 'c' ) );
     p_sys->b_start = VLC_TRUE;
+    p_sys->p_meta = NULL;
 
     /* We need to read and store the STREAMINFO metadata */
     i_peek = stream_Peek( p_demux->s, &p_peek, 8 );
@@ -106,18 +107,8 @@ static int Open( vlc_object_t * p_this )
         return VLC_EGENERIC;
     }
 
-    /*
-     * Load the FLAC packetizer
-     */
-    p_sys->p_packetizer = vlc_object_create( p_demux, VLC_OBJECT_DECODER );
-    p_sys->p_packetizer->pf_decode_audio = 0;
-    p_sys->p_packetizer->pf_decode_video = 0;
-    p_sys->p_packetizer->pf_decode_sub = 0;
-    p_sys->p_packetizer->pf_packetize = 0;
-
-    /* Initialization of decoder structure */
-    es_format_Init( &p_sys->p_packetizer->fmt_in, AUDIO_ES,
-                    VLC_FOURCC( 'f', 'l', 'a', 'c' ) );
+    /* Load the FLAC packetizer */
+    INIT_APACKETIZER( p_sys->p_packetizer, 'f', 'l', 'a', 'c' );
 
     /* Store STREAMINFO for the decoder and packetizer */
     p_sys->p_packetizer->fmt_in.i_extra = fmt.i_extra = STREAMINFO_SIZE + 4;
@@ -137,14 +128,22 @@ static int Open( vlc_object_t * p_this )
     {
         if( p_sys->p_packetizer->fmt_in.p_extra )
             free( p_sys->p_packetizer->fmt_in.p_extra );
-
         vlc_object_destroy( p_sys->p_packetizer );
+
         msg_Err( p_demux, "cannot find flac packetizer" );
         return VLC_EGENERIC;
     }
 
     p_sys->p_es = es_out_Add( p_demux->out, &fmt );
 
+    /* Parse possible id3 header */
+    if( ( p_id3 = module_Need( p_demux, "id3", NULL, 0 ) ) )
+    {
+        p_sys->p_meta = (vlc_meta_t *)p_demux->p_private;
+        p_demux->p_private = NULL;
+        module_Unneed( p_demux, p_id3 );
+    }
+
     return VLC_SUCCESS;
 }
 
@@ -164,7 +163,7 @@ static void Close( vlc_object_t * p_this )
 
     /* Delete the decoder */
     vlc_object_destroy( p_sys->p_packetizer );
-
+    if( p_sys->p_meta ) vlc_meta_Delete( p_sys->p_meta );
     free( p_sys );
 }
 
@@ -219,11 +218,15 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 {
     /* demux_sys_t *p_sys  = p_demux->p_sys; */
     /* FIXME bitrate */
-    if( i_query == DEMUX_SET_TIME )
-        return VLC_EGENERIC;
-    else
-        return demux2_vaControlHelper( p_demux->s,
-                                       0, -1,
-                                       8*0, 1, i_query, args );
+    if( i_query == DEMUX_SET_TIME ) return VLC_EGENERIC;
+    else if( i_query == DEMUX_GET_META )
+    {
+        vlc_meta_t *p_meta = (vlc_meta_t *)va_arg( args, vlc_meta_t* );
+        if( p_demux->p_sys->p_meta )
+            vlc_meta_Merge( p_meta, p_demux->p_sys->p_meta );
+        return VLC_SUCCESS;
+    }
+    else return demux2_vaControlHelper( p_demux->s, 0, -1,
+                                        8*0, 1, i_query, args );
 }