]> git.sesse.net Git - vlc/blobdiff - modules/demux/ogg.c
* ALL: changed the prototype of input_AddES() to include enough information so we...
[vlc] / modules / demux / ogg.c
index 3bc0a72475872d9c96067aa167f3160c717b2581..e5a78aa074a6fcbc7021fcc2109893c6d7d2ff87 100644 (file)
@@ -2,7 +2,7 @@
  * ogg.c : ogg stream input module for vlc
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: ogg.c,v 1.16 2002/12/19 23:23:24 sigmunau Exp $
+ * $Id: ogg.c,v 1.25 2003/05/05 22:23:34 gbazin Exp $
  *
  * Authors: Gildas Bazin <gbazin@netcourrier.com>
  * 
@@ -94,8 +94,8 @@ struct demux_sys_t
     /* program clock reference (in units of 90kHz) derived from the pcr of
      * the sub-streams */
     mtime_t i_pcr;
+    mtime_t i_old_pcr;
 
-    mtime_t i_length;
     int     b_seekable;
     int     b_reinit;
 };
@@ -184,7 +184,7 @@ static int  Ogg_FindLogicalStreams( input_thread_t *p_input,
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_description( _("ogg stream demux" ) );
+    set_description( _("ogg stream demuxer" ) );
     set_capability( "demux", 50 );
     set_callbacks( Activate, Deactivate );
     add_shortcut( "ogg" );
@@ -416,6 +416,7 @@ static void Ogg_DecodePacket( input_thread_t *p_input,
         input_DeletePES( p_input->p_method_data, p_pes );
         return;
     }
+    p_data->p_payload_end = p_data->p_payload_start + p_oggpacket->bytes;
 
     /* Convert the pcr into a pts */
     if( p_stream->i_cat != SPU_ES )
@@ -443,8 +444,7 @@ static void Ogg_DecodePacket( input_thread_t *p_input,
 
     if( p_stream->i_fourcc != VLC_FOURCC( 'v','o','r','b' ) &&
         p_stream->i_fourcc != VLC_FOURCC( 't','a','r','k' ) &&
-        p_stream->i_fourcc != VLC_FOURCC( 't','h','e','o' ) &&
-        p_stream->i_fourcc != VLC_FOURCC( 'o','f','l','c') )
+        p_stream->i_fourcc != VLC_FOURCC( 't','h','e','o' ) )
     {
         /* Remove the header from the packet */
         i_header_len = (*p_oggpacket->packet & PACKET_LEN_BITS01) >> 6;
@@ -525,33 +525,8 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                 /* FIXME: check return value */
                 ogg_stream_packetpeek( &p_stream->os, &oggpacket );
 
-                msg_Dbg( p_input, "found string: %s", strndup( &oggpacket.packet[0], 6 ) );
-                msg_Dbg( p_input, "oggpacket.bytes is %d", oggpacket.bytes );
-                if( oggpacket.bytes >= 4 &&
-                    ! strncmp( &oggpacket.packet[0], "fLaC", 4 ) )
-                {
-                    oggpack_buffer opb;
-
-                    msg_Dbg( p_input, "found flac header" );
-                    p_stream->i_cat = AUDIO_ES;
-                    p_stream->i_fourcc = VLC_FOURCC( 'o','f','l','c' );
-#if 0
-                    /* Signal that we want to keep a backup of the vorbis
-                     * stream headers. They will be used when switching between
-                     * audio streams. */
-                    p_stream->b_force_backup = 1;
-
-                    /* Cheat and get additionnal info ;) */
-                    oggpack_readinit( &opb, oggpacket.packet, oggpacket.bytes);
-                    oggpack_adv( &opb, 96 );
-                    p_stream->f_rate = oggpack_read( &opb, 32 );
-                    oggpack_adv( &opb, 32 );
-                    p_stream->i_bitrate = oggpack_read( &opb, 32 );
-#endif
-                }
-
                 /* Check for Vorbis header */
-                else if( oggpacket.bytes >= 7 &&
+                if( oggpacket.bytes >= 7 &&
                     ! strncmp( &oggpacket.packet[1], "vorbis", 6 ) )
                 {
                     oggpack_buffer opb;
@@ -576,11 +551,11 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                         input_info_category_t *p_cat;
                         sprintf( title, "Stream %d", p_ogg->i_streams );
                         p_cat = input_InfoCategory( p_input, title );
-                        input_AddInfo( p_cat, "Type", "Audio" );
-                        input_AddInfo( p_cat, "Codec", "vorbis" );
-                        input_AddInfo( p_cat, "Sample Rate", "%f",
+                        input_AddInfo( p_cat, _("Type"), _("Audio") );
+                        input_AddInfo( p_cat, _("Codec"), _("Vorbis") );
+                        input_AddInfo( p_cat, _("Sample Rate"), "%f",
                                        p_stream->f_rate );
-                        input_AddInfo( p_cat, "Bit Rate", "%d",
+                        input_AddInfo( p_cat, _("Bit Rate"), "%d",
                                        p_stream->i_bitrate );
                     }
                 }
@@ -635,11 +610,11 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                         input_info_category_t *p_cat;
                         sprintf( title, "Stream %d", p_ogg->i_streams );
                         p_cat = input_InfoCategory( p_input, title );
-                        input_AddInfo( p_cat, "Type", "Video" );
-                        input_AddInfo( p_cat, "Codec", "theora" );
-                        input_AddInfo( p_cat, "Frame Rate", "%f",
+                        input_AddInfo( p_cat, _("Type"), _("Video") );
+                        input_AddInfo( p_cat, _("Codec"), _("Theora") );
+                        input_AddInfo( p_cat, _("Frame Rate"), "%f",
                                        p_stream->f_rate );
-                        input_AddInfo( p_cat, "Bit Rate", "%d",
+                        input_AddInfo( p_cat, _("Bit Rate"), "%d",
                                        p_stream->i_bitrate );
                     }
 #else /* HAVE_OGGPACKB */
@@ -675,11 +650,11 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                         input_info_category_t *p_cat;
                         sprintf( title, "Stream %d", p_ogg->i_streams );
                         p_cat = input_InfoCategory( p_input, title );
-                        input_AddInfo( p_cat, "Type", "Video" );
-                        input_AddInfo( p_cat, "Codec", "tarkin" );
-                        input_AddInfo( p_cat, "Sample Rate", "%f",
+                        input_AddInfo( p_cat, _("Type"), _("Video") );
+                        input_AddInfo( p_cat, _("Codec"), _("tarkin") );
+                        input_AddInfo( p_cat, _("Sample Rate"), "%f",
                                        p_stream->f_rate );
-                        input_AddInfo( p_cat, "Bit Rate", "%d",
+                        input_AddInfo( p_cat, _("Bit Rate"), "%d",
                                        p_stream->i_bitrate );
                     }
 
@@ -740,16 +715,16 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                             input_info_category_t *p_cat;
                             sprintf( title, "Stream %d", p_ogg->i_streams );
                             p_cat = input_InfoCategory( p_input, title );
-                            input_AddInfo( p_cat, "Type", "Video" );
-                            input_AddInfo( p_cat, "Codec", "%.4s",
+                            input_AddInfo( p_cat, _("Type"), _("Video") );
+                            input_AddInfo( p_cat, _("Codec"), "%.4s",
                                            (char *)&p_stream->i_fourcc );
-                            input_AddInfo( p_cat, "Frame Rate", "%f",
+                            input_AddInfo( p_cat, _("Frame Rate"), "%f",
                                            p_stream->f_rate );
-                            input_AddInfo( p_cat, "Bit Count", "%d",
+                            input_AddInfo( p_cat, _("Bit Count"), "%d",
                                            p_stream->p_bih->biBitCount );
-                            input_AddInfo( p_cat, "Width", "%d",
+                            input_AddInfo( p_cat, _("Width"), "%d",
                                            p_stream->p_bih->biWidth );
-                            input_AddInfo( p_cat, "Height", "%d",
+                            input_AddInfo( p_cat, _("Height"), "%d",
                                            p_stream->p_bih->biHeight );
                         }
                         p_stream->i_bitrate = 0;
@@ -835,17 +810,17 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                             input_info_category_t *p_cat;
                             sprintf( title, "Stream %d", p_ogg->i_streams );
                             p_cat = input_InfoCategory( p_input, title );
-                            input_AddInfo( p_cat, "Type", "Audio" );
-                            input_AddInfo( p_cat, "Codec", "%.4s", 
+                            input_AddInfo( p_cat, _("Type"), _("Audio") );
+                            input_AddInfo( p_cat, _("Codec"), "%.4s", 
                                            (char *)&p_stream->i_fourcc );
-                            input_AddInfo( p_cat, "Sample Rate", "%d",
+                            input_AddInfo( p_cat, _("Sample Rate"), "%d",
                                            p_stream->p_wf->nSamplesPerSec );
-                            input_AddInfo( p_cat, "Bit Rate", "%d",
+                            input_AddInfo( p_cat, _("Bit Rate"), "%d",
                                            p_stream->p_wf->nAvgBytesPerSec * 8
                                               / 1024 );
-                            input_AddInfo( p_cat, "Channels", "%d",
+                            input_AddInfo( p_cat, _("Channels"), "%d",
                                            p_stream->p_wf->nChannels );
-                            input_AddInfo( p_cat, "Bits per Sample", "%d",
+                            input_AddInfo( p_cat, _("Bits per Sample"), "%d",
                                            p_stream->p_wf->wBitsPerSample );
                         }
 
@@ -915,16 +890,16 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                             input_info_category_t *p_cat;
                             sprintf( title, "Stream %d", p_ogg->i_streams );
                             p_cat = input_InfoCategory( p_input, title );
-                            input_AddInfo( p_cat, "Type", "Video" );
-                            input_AddInfo( p_cat, "Codec", "%.4s",
+                            input_AddInfo( p_cat, _("Type"), _("Video") );
+                            input_AddInfo( p_cat, _("Codec"), "%.4s",
                                            (char *)&p_stream->i_fourcc );
-                            input_AddInfo( p_cat, "Frame Rate", "%f",
+                            input_AddInfo( p_cat, _("Frame Rate"), "%f",
                                            p_stream->f_rate );
-                            input_AddInfo( p_cat, "Bit Count", "%d",
+                            input_AddInfo( p_cat, _("Bit Count"), "%d",
                                            p_stream->p_bih->biBitCount );
-                            input_AddInfo( p_cat, "Width", "%d",
+                            input_AddInfo( p_cat, _("Width"), "%d",
                                            p_stream->p_bih->biWidth );
-                            input_AddInfo( p_cat, "Height", "%d",
+                            input_AddInfo( p_cat, _("Height"), "%d",
                                            p_stream->p_bih->biHeight );
                         }
                         p_stream->i_bitrate = 0;
@@ -1008,17 +983,17 @@ static int Ogg_FindLogicalStreams( input_thread_t *p_input, demux_sys_t *p_ogg)
                             input_info_category_t *p_cat;
                             sprintf( title, "Stream %d", p_ogg->i_streams );
                             p_cat = input_InfoCategory( p_input, title );
-                            input_AddInfo( p_cat, "Type", "Audio" );
-                            input_AddInfo( p_cat, "Codec", "%.4s", 
+                            input_AddInfo( p_cat, _("Type"), _("Audio") );
+                            input_AddInfo( p_cat, _("Codec"), "%.4s", 
                                            (char *)&p_stream->i_fourcc );
-                            input_AddInfo( p_cat, "Sample Rate", "%d",
+                            input_AddInfo( p_cat, _("Sample Rate"), "%d",
                                            p_stream->p_wf->nSamplesPerSec );
-                            input_AddInfo( p_cat, "Bit Rate", "%d",
+                            input_AddInfo( p_cat, _("Bit Rate"), "%d",
                                            p_stream->p_wf->nAvgBytesPerSec * 8
                                               / 1024 );
-                            input_AddInfo( p_cat, "Channels", "%d",
+                            input_AddInfo( p_cat, _("Channels"), "%d",
                                            p_stream->p_wf->nChannels );
-                            input_AddInfo( p_cat, "Bits per Sample", "%d",
+                            input_AddInfo( p_cat, _("Bits per Sample"), "%d",
                                            p_stream->p_wf->wBitsPerSample );
                         }
                     }
@@ -1148,14 +1123,14 @@ static int Activate( vlc_object_t * p_this )
         vlc_mutex_lock( &p_input->stream.stream_lock );
         p_stream->p_es = input_AddES( p_input,
                                       p_input->stream.p_selected_program,
-                                      p_ogg->i_streams + 1, 0 );
+                                      i_stream,
+                                      p_stream->i_cat, NULL, 0 );
         p_input->stream.i_mux_rate += (p_stream->i_bitrate / ( 8 * 50 ));
         vlc_mutex_unlock( &p_input->stream.stream_lock );
-        p_stream->p_es->i_stream_id = p_stream->p_es->i_id = i_stream;
+        p_stream->p_es->i_stream_id = i_stream;
         p_stream->p_es->i_fourcc = p_stream->i_fourcc;
-        p_stream->p_es->i_cat = p_stream->i_cat;
-        p_stream->p_es->p_demux_data = p_stream->p_bih ?
-            (void *)p_stream->p_bih : (void *)p_stream->p_wf;
+        p_stream->p_es->p_waveformatex      = (void*)p_stream->p_wf;
+        p_stream->p_es->p_bitmapinfoheader  = (void*)p_stream->p_bih;
 #undef p_stream
     }
 
@@ -1412,17 +1387,23 @@ static int Demux( input_thread_t * p_input )
     }
 
     i_stream = 0;
+    p_ogg->i_old_pcr = p_ogg->i_pcr;
     p_ogg->i_pcr = p_stream->i_interpolated_pcr;
     for( ; i_stream < p_ogg->i_streams; i_stream++ )
     {
         if( p_stream->i_cat == SPU_ES )
             continue;
 
-        if( p_stream->i_interpolated_pcr < p_ogg->i_pcr )
+        if( p_stream->i_interpolated_pcr > 0
+            && p_stream->i_interpolated_pcr < p_ogg->i_pcr )
             p_ogg->i_pcr = p_stream->i_interpolated_pcr;
     }
 #undef p_stream
 
+    /* Sanity check for streams where the granulepos of the header packets
+     * don't match these of the data packets (eg. ogg web radios). */
+    if( p_ogg->i_old_pcr == 0 && p_ogg->i_pcr > 1000000 )
+        p_input->stream.p_selected_program->i_synchro_state = SYNCHRO_REINIT;
 
     /* Call the pace control */
     input_ClockManageRef( p_input, p_input->stream.p_selected_program,