]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv/mkv.cpp
VLCKit: Use name instead of $1 and $2 in Pre-Compile script.
[vlc] / modules / demux / mkv / mkv.cpp
index fa25d28e855f7f9d1e72791821da1fc57fa1f95b..68fbc44161ef65c639bc4440db97a70a40f221f1 100644 (file)
@@ -33,6 +33,8 @@
 
 #include "stream_io_callback.hpp"
 
+#include <vlc_fs.h>
+
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -47,23 +49,23 @@ vlc_module_begin ()
     set_category( CAT_INPUT )
     set_subcategory( SUBCAT_INPUT_DEMUX )
 
-    add_bool( "mkv-use-ordered-chapters", 1, NULL,
+    add_bool( "mkv-use-ordered-chapters", true, NULL,
             N_("Ordered chapters"),
             N_("Play ordered chapters as specified in the segment."), true );
 
-    add_bool( "mkv-use-chapter-codec", 1, NULL,
+    add_bool( "mkv-use-chapter-codec", true, NULL,
             N_("Chapter codecs"),
             N_("Use chapter codecs found in the segment."), true );
 
-    add_bool( "mkv-preload-local-dir", 0, NULL,
+    add_bool( "mkv-preload-local-dir", false, NULL,
             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", 0, NULL,
+    add_bool( "mkv-seek-percent", false, NULL,
             N_("Seek based on percent not time"),
             N_("Seek based on percent not time."), true );
 
-    add_bool( "mkv-use-dummy", 0, NULL,
+    add_bool( "mkv-use-dummy", false, NULL,
             N_("Dummy Elements"),
             N_("Read and discard unknown EBML elements (not good for broken files)."), true );
 
@@ -137,7 +139,7 @@ static int Open( vlc_object_t * p_this )
         goto error;
     }
 
-    if (config_GetInt( p_demux, "mkv-preload-local-dir" ))
+    if (var_InheritInteger( p_demux, "mkv-preload-local-dir" ))
     {
         /* get the files from the same dir from the same family (based on p_demux->psz_path) */
         if (p_demux->psz_path[0] != '\0' && !strcmp(p_demux->psz_access, ""))
@@ -157,12 +159,12 @@ static int Open( vlc_object_t * p_this )
                 }
             }
 
-            DIR *p_src_dir = utf8_opendir(s_path.c_str());
+            DIR *p_src_dir = vlc_opendir(s_path.c_str());
 
             if (p_src_dir != NULL)
             {
                 char *psz_file;
-                while ((psz_file = utf8_readdir(p_src_dir)) != NULL)
+                while ((psz_file = vlc_readdir(p_src_dir)) != NULL)
                 {
                     if (strlen(psz_file) > 4)
                     {
@@ -419,7 +421,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, chapter_it
     }
 
     /* seek without index or without date */
-    if( f_percent >= 0 && (config_GetInt( p_demux, "mkv-seek-percent" ) || !p_segment->b_cues || i_date < 0 ))
+    if( f_percent >= 0 && (var_InheritInteger( p_demux, "mkv-seek-percent" ) || !p_segment->b_cues || i_date < 0 ))
     {
         if( p_sys->f_duration >= 0 && p_segment->b_cues )
         {
@@ -456,7 +458,7 @@ static void Seek( demux_t *p_demux, mtime_t i_date, double f_percent, chapter_it
 }
 
 /* Utility function for BlockDecode */
-static block_t *MemToBlock( demux_t *p_demux, uint8_t *p_mem, int i_mem, size_t offset)
+static block_t *MemToBlock( demux_t *p_demux, 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;
@@ -534,6 +536,8 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
         {
             data = &block->GetBuffer(i);
         }
+        if( !data->Buffer() || data->Size() > SIZE_MAX )
+            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() );
@@ -549,6 +553,8 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
         if( tk->i_compression_type == MATROSKA_COMPRESSION_ZLIB )
         {
             p_block = block_zlib_decompress( VLC_OBJECT(p_demux), p_block );
+            if( p_block == NULL )
+                break;
         }
         else
 #endif
@@ -580,7 +586,7 @@ static void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simp
         {
             if( tk->b_dts_only )
             {
-                p_block->i_pts = 0;
+                p_block->i_pts = VLC_TS_INVALID;
                 p_block->i_dts = i_pts;
             }
             else
@@ -603,10 +609,16 @@ msg_Dbg( p_demux, "block i_dts: %"PRId64" / i_pts: %"PRId64, p_block->i_dts, p_b
             p_block->i_length = i_duration * 1000;
         }
 
+        /* FIXME remove when VLC_TS_INVALID work is done */
+        if( i == 0 || p_block->i_dts > VLC_TS_INVALID )
+            p_block->i_dts += VLC_TS_0;
+        if( !tk->b_dts_only && ( i == 0 || p_block->i_pts > VLC_TS_INVALID ) )
+            p_block->i_pts += VLC_TS_0;
+
         es_out_Send( p_demux->out, tk->p_es, p_block );
 
         /* use time stamp only for first block */
-        i_pts = 0;
+        i_pts = VLC_TS_INVALID;
     }
 }
 
@@ -859,7 +871,8 @@ 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, p_sys->i_pts );
+        /* */
+        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  )
         {