]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv/mkv.cpp
Hack to fix Windows build
[vlc] / modules / demux / mkv / mkv.cpp
index 7dec8d7676d93adb7545c5f39216a63ee9642251..8b238b98cf8c0690629e83ddc785da146ffea4a3 100644 (file)
@@ -49,23 +49,23 @@ vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_DEMUX )
 
-    add_bool( "mkv-use-ordered-chapters", true, NULL,
+    add_bool( "mkv-use-ordered-chapters", true,
             N_("Ordered chapters"),
             N_("Play ordered chapters as specified in the segment."), true );
 
-    add_bool( "mkv-use-chapter-codec", true, NULL,
+    add_bool( "mkv-use-chapter-codec", true,
             N_("Chapter codecs"),
             N_("Use chapter codecs found in the segment."), true );
 
-    add_bool( "mkv-preload-local-dir", false, NULL,
+    add_bool( "mkv-preload-local-dir", false,
             N_("Preload Directory"),
             N_("Preload matroska files from the same family in the same directory (not good for broken files)."), true );
 
-    add_bool( "mkv-seek-percent", false, NULL,
+    add_bool( "mkv-seek-percent", false,
             N_("Seek based on percent not time"),
             N_("Seek based on percent not time."), true );
 
-    add_bool( "mkv-use-dummy", false, NULL,
+    add_bool( "mkv-use-dummy", false,
             N_("Dummy Elements"),
             N_("Read and discard unknown EBML elements (not good for broken files)."), true );
 
@@ -76,7 +76,7 @@ class demux_sys_t;
 
 static int  Demux  ( demux_t * );
 static int  Control( demux_t *, int, va_list );
-static void Seek   ( demux_t *, mtime_t i_date, double f_percent, chapter_item_c *psz_chapter );
+static void Seek   ( demux_t *, mtime_t i_date, double f_percent, chapter_item_c *p_chapter );
 
 /*****************************************************************************
  * Open: initializes matroska demux structures
@@ -123,8 +123,8 @@ static int Open( vlc_object_t * p_this )
     }
     p_sys->streams.push_back( p_stream );
 
-    p_stream->p_in = p_io_callback;
-    p_stream->p_es = p_io_stream;
+    p_stream->p_io_callback = p_io_callback;
+    p_stream->p_estream = p_io_stream;
 
     for (size_t i=0; i<p_stream->segments.size(); i++)
     {
@@ -179,13 +179,8 @@ static int Open( vlc_object_t * p_this )
                             continue; // don't reuse the original opened file
                         }
 
-#if defined(__GNUC__) && (__GNUC__ < 3)
-                        if (!s_filename.compare("mkv", s_filename.length() - 3, 3) ||
-                            !s_filename.compare("mka", s_filename.length() - 3, 3))
-#else
                         if (!s_filename.compare(s_filename.length() - 3, 3, "mkv") ||
                             !s_filename.compare(s_filename.length() - 3, 3, "mka"))
-#endif
                         {
                             // test wether this file belongs to our family
                             const uint8_t *p_peek;
@@ -214,8 +209,8 @@ static int Open( vlc_object_t * p_this )
                                 }
                                 else
                                 {
-                                    p_stream->p_in = p_file_io;
-                                    p_stream->p_es = p_estream;
+                                    p_stream->p_io_callback = p_file_io;
+                                    p_stream->p_estream = p_estream;
                                     p_sys->streams.push_back( p_stream );
                                 }
                             }
@@ -245,8 +240,8 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
-    p_sys->StartUiThread();
+    p_sys->InitUi();
+
     return VLC_SUCCESS;
 
 error:
@@ -297,8 +292,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             for( size_t i = 0; i < p_sys->stored_attachments.size(); i++ )
             {
                 attachment_c *a = p_sys->stored_attachments[i];
-                (*ppp_attach)[i] = vlc_input_attachment_New( a->psz_file_name.c_str(), a->psz_mime_type.c_str(), NULL,
-                                                             a->p_data, a->i_size );
+                (*ppp_attach)[i] = vlc_input_attachment_New( a->fileName(), a->mimeType(), NULL,
+                                                             a->p_data, a->size() );
             }
             return VLC_SUCCESS;
 
@@ -375,9 +370,9 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
         case DEMUX_GET_FPS:
             pf = (double *)va_arg( args, double * );
             *pf = 0.0;
-            if( p_sys->p_current_segment && p_sys->p_current_segment->Segment() )
+            if( p_sys->p_current_segment && p_sys->p_current_segment->CurrentSegment() )
             {
-                const matroska_segment_c *p_segment = p_sys->p_current_segment->Segment();
+                const matroska_segment_c *p_segment = p_sys->p_current_segment->CurrentSegment();
                 for( size_t i = 0; i < p_segment->tracks.size(); i++ )
                 {
                     mkv_track_t *tk = p_segment->tracks[i];
@@ -397,11 +392,11 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
 }
 
 /* Seek */
-static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, chapter_item_c *psz_chapter )
+static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, chapter_item_c *p_chapter )
 {
     demux_sys_t        *p_sys = p_demux->p_sys;
     virtual_segment_c  *p_vsegment = p_sys->p_current_segment;
-    matroska_segment_c *p_segment = p_vsegment->Segment();
+    matroska_segment_c *p_segment = p_vsegment->CurrentSegment();
     mtime_t            i_time_offset = 0;
     int64_t            i_global_position = -1;
 
@@ -453,16 +448,17 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, chapter_it
         }
     }
 
-    p_vsegment->Seek( *p_demux, i_date, i_time_offset, psz_chapter, i_global_position );
+    p_vsegment->Seek( *p_demux, i_date, i_time_offset, p_chapter, i_global_position );
 }
 
 /* Utility function for BlockDecode */
-static block_t *MemToBlock( demux_t *p_demux, uint8_t *p_mem, size_t i_mem, size_t offset)
+static block_t *MemToBlock( uint8_t *p_mem, size_t i_mem, size_t offset)
 {
-    block_t *p_block;
-    if( !(p_block = block_New( p_demux, i_mem + offset ) ) ) return NULL;
-    memcpy( p_block->p_buffer + offset, p_mem, i_mem );
-    //p_block->i_rate = p_input->stream.control.i_rate;
+    block_t *p_block = block_New( p_demux, i_mem + offset );
+    if( likely(p_block != NULL) )
+    {
+        memcpy( p_block->p_buffer + offset, p_mem, i_mem );
+    }
     return p_block;
 }
 
@@ -471,7 +467,7 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
                          mtime_t i_pts, mtime_t i_duration, bool f_mandatory )
 {
     demux_sys_t        *p_sys = p_demux->p_sys;
-    matroska_segment_c *p_segment = p_sys->p_current_segment->Segment();
+    matroska_segment_c *p_segment = p_sys->p_current_segment->CurrentSegment();
 
     if( !p_segment ) return;
 
@@ -513,7 +509,7 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
         block_t *p_init;
 
         msg_Dbg( p_demux, "sending header (%d bytes)", tk->i_data_init );
-        p_init = MemToBlock( p_demux, tk->p_data_init, tk->i_data_init, 0 );
+        p_init = MemToBlock( tk->p_data_init, tk->i_data_init, 0 );
         if( p_init ) es_out_Send( p_demux->out, tk->p_es, p_init );
     }
     tk->b_inited = true;
@@ -539,9 +535,9 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
             break;
 
         if( tk->i_compression_type == MATROSKA_COMPRESSION_HEADER && tk->p_compression_data != NULL )
-            p_block = MemToBlock( p_demux, data->Buffer(), data->Size(), tk->p_compression_data->GetSize() );
+            p_block = MemToBlock( data->Buffer(), data->Size(), tk->p_compression_data->GetSize() );
         else
-            p_block = MemToBlock( p_demux, data->Buffer(), data->Size(), 0 );
+            p_block = MemToBlock( data->Buffer(), data->Size(), 0 );
 
         if( p_block == NULL )
         {
@@ -565,15 +561,8 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
         if ( tk->fmt.i_cat == NAV_ES )
         {
             // TODO handle the start/stop times of this packet
-            if ( p_sys->b_ui_hooked )
-            {
-                vlc_mutex_lock( &p_sys->p_ev->lock );
-                memcpy( &p_sys->pci_packet, &p_block->p_buffer[1], sizeof(pci_t) );
-                p_sys->SwapButtons();
-                p_sys->b_pci_packet_set = true;
-                vlc_mutex_unlock( &p_sys->p_ev->lock );
-                block_Release( p_block );
-            }
+            p_sys->p_ev->SetPci( (const pci_t *)&p_block->p_buffer[1]);
+            block_Release( p_block );
             return;
         }
         // correct timestamping when B frames are used
@@ -637,7 +626,7 @@ static int Demux( demux_t *p_demux)
     vlc_mutex_lock( &p_sys->lock_demuxer );
 
     virtual_segment_c  *p_vsegment = p_sys->p_current_segment;
-    matroska_segment_c *p_segment = p_vsegment->Segment();
+    matroska_segment_c *p_segment = p_vsegment->CurrentSegment();
     if ( p_segment == NULL ) return 0;
     int                i_block_count = 0;
     int                i_return = 0;
@@ -653,18 +642,18 @@ static int Demux( demux_t *p_demux)
                 i_return = 1;
                 break;
             }
-        if ( p_vsegment->Edition() && p_vsegment->Edition()->b_ordered && p_vsegment->CurrentChapter() == NULL )
+
+        if ( p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered && p_vsegment->CurrentChapter() == NULL )
         {
             /* nothing left to read in this ordered edition */
             if ( !p_vsegment->SelectNext() )
                 break;
             p_segment->UnSelect( );
+
             es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
 
             /* switch to the next segment */
-            p_segment = p_vsegment->Segment();
+            p_segment = p_vsegment->CurrentSegment();
             if ( !p_segment->Select( 0 ) )
             {
                 msg_Err( p_demux, "Failed to select new segment" );
@@ -680,7 +669,7 @@ static int Demux( demux_t *p_demux)
         bool b_discardable_picture;
         if( p_segment->BlockGet( block, simpleblock, &b_key_picture, &b_discardable_picture, &i_block_duration ) )
         {
-            if ( p_vsegment->Edition() && p_vsegment->Edition()->b_ordered )
+            if ( p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered )
             {
                 const chapter_item_c *p_chap = p_vsegment->CurrentChapter();
                 // check if there are more chapters to read
@@ -702,14 +691,14 @@ static int Demux( demux_t *p_demux)
             {
                 msg_Warn( p_demux, "cannot get block EOF?" );
                 p_segment->UnSelect( );
+
                 es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
 
                 /* switch to the next segment */
                 if ( !p_vsegment->SelectNext() )
                     // no more segments in this stream
                     break;
-                p_segment = p_vsegment->Segment();
+                p_segment = p_vsegment->CurrentSegment();
                 if ( !p_segment->Select( 0 ) )
                 {
                     msg_Err( p_demux, "Failed to select new segment" );
@@ -725,20 +714,21 @@ static int Demux( demux_t *p_demux)
         else
             p_sys->i_pts = (p_sys->i_chapter_time + block->GlobalTimecode()) / (mtime_t) 1000;
 
-        /* */
-        es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pts );
+        /* The blocks are in coding order so we can safely consider that only references are in chronological order */
+        if( b_key_picture )
+            es_out_Control( p_demux->out, ES_OUT_SET_PCR, VLC_TS_0 + p_sys->i_pts );
 
         if( p_sys->i_pts >= p_sys->i_start_pts  )
         {
-            if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) )
+            if ( p_vsegment->UpdateCurrentToChapter( *p_demux ) && p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered )
             {
                 i_return = 1;
                 delete block;
                 break;
             }
         }
-        if ( p_vsegment->Edition() && p_vsegment->Edition()->b_ordered && p_vsegment->CurrentChapter() == NULL )
+
+        if ( p_vsegment->CurrentEdition() && p_vsegment->CurrentEdition()->b_ordered && p_vsegment->CurrentChapter() == NULL )
         {
             /* nothing left to read in this ordered edition */
             if ( !p_vsegment->SelectNext() )
@@ -747,11 +737,11 @@ static int Demux( demux_t *p_demux)
                 break;
             }
             p_segment->UnSelect( );
+
             es_out_Control( p_demux->out, ES_OUT_RESET_PCR );
 
             /* switch to the next segment */
-            p_segment = p_vsegment->Segment();
+            p_segment = p_vsegment->CurrentSegment();
             if ( !p_segment->Select( 0 ) )
             {
                 msg_Err( p_demux, "Failed to select new segment" );