]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv/mkv.cpp
MKV: better mnemonics & logs
[vlc] / modules / demux / mkv / mkv.cpp
index 5868ca19bba27f98955f8083faae9823e3e20a74..2d2a12a74ab4d7b09d1244b2e92052b3c87c6784 100644 (file)
 
 #include "stream_io_callback.hpp"
 
+extern "C" {
+#include "../../modules/codec/dts_header.h"
+}
+
 #include <vlc_fs.h>
 #include <vlc_url.h>
 
@@ -541,21 +545,21 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
     else
         block_size = block->GetSize();
  
-    for( unsigned int i = 0;
-         ( block != NULL && i < block->NumberFrames()) || ( simpleblock != NULL && i < simpleblock->NumberFrames() );
-         i++ )
+    const unsigned int i_number_frames = block != NULL ? block->NumberFrames() :
+            ( simpleblock != NULL ? simpleblock->NumberFrames() : 0 );
+    for( unsigned int i_frame = 0; i_frame < i_number_frames; i_frame++ )
     {
         block_t *p_block;
         DataBuffer *data;
         if( simpleblock != NULL )
         {
-            data = &simpleblock->GetBuffer(i);
+            data = &simpleblock->GetBuffer(i_frame);
             // condition when the DTS is correct (keyframe or B frame == NOT P frame)
             f_mandatory = simpleblock->IsDiscardable() || simpleblock->IsKeyframe();
         }
         else
         {
-            data = &block->GetBuffer(i);
+            data = &block->GetBuffer(i_frame);
             // condition when the DTS is correct (keyframe or B frame == NOT P frame)
         }
         frame_size += data->Size();
@@ -606,6 +610,20 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
                 VLC_TS_INVALID;
             continue;
          }
+
+        case VLC_CODEC_DTS:
+            /* Check if packetization is correct and without padding.
+             * example: Test_mkv_div3_DTS_1920x1080_1785Kbps_23,97fps.mkv */
+            if( p_block->i_buffer > 6 )
+            {
+                unsigned int a, b, c, d;
+                bool e;
+                int i_frame_size = GetSyncInfo( p_block->p_buffer, &e, &a, &b, &c, &d );
+                if( i_frame_size > 0 )
+                    p_block->i_buffer = __MIN(p_block->i_buffer, (size_t)i_frame_size);
+            }
+            break;
+
          case VLC_CODEC_OPUS:
             mtime_t i_length = i_duration * tk-> f_timecodescale *
                     (double) p_segment->i_timescale / 1000.0;
@@ -664,18 +682,18 @@ void BlockDecode( demux_t *p_demux, KaxBlock *block, KaxSimpleBlock *simpleblock
         }
 
 #if 0
-msg_Dbg( p_demux, "block i_dts: %"PRId64" / i_pts: %"PRId64, p_block->i_dts, p_block->i_pts);
+msg_Dbg( p_demux, "block (track=%d) i_dts: %"PRId64" / i_pts: %"PRId64, tk->i_number, p_block->i_dts, p_block->i_pts);
 #endif
         if( !tk->b_no_duration )
         {
             p_block->i_length = i_duration * tk-> f_timecodescale *
-                (double) p_segment->i_timescale / 1000.0;
+                (double) p_segment->i_timescale / ( 1000.0 * i_number_frames );
         }
 
         /* FIXME remove when VLC_TS_INVALID work is done */
-        if( i == 0 || p_block->i_dts > VLC_TS_INVALID )
+        if( i_frame == 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 ) )
+        if( !tk->b_dts_only && ( i_frame == 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 );