]> git.sesse.net Git - vlc/blobdiff - modules/demux/mkv.cpp
Add secstotimestr and msecstotimestr to convert (milli)seconds to a
[vlc] / modules / demux / mkv.cpp
index f4934100aa49c420688dffa7ae81f28f9f4243a8..211903273803a7b441b9960f6a5ae4b0c55fbc04 100644 (file)
@@ -2,7 +2,7 @@
  * mkv.cpp : matroska demuxer
  *****************************************************************************
  * Copyright (C) 2001 VideoLAN
- * $Id: mkv.cpp,v 1.42 2003/11/20 22:10:55 fenrir Exp $
+ * $Id: mkv.cpp,v 1.48 2003/12/02 01:54:30 rocky Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
@@ -197,7 +197,6 @@ typedef struct
     vlc_bool_t      b_search_keyframe;
 
     /* informative */
-    char         *psz_name;
     char         *psz_codec_name;
     char         *psz_codec_settings;
     char         *psz_codec_info_url;
@@ -475,6 +474,7 @@ static int Open( vlc_object_t * p_this )
 
                     es_format_Init( &tk.fmt, UNKNOWN_ES, 0 );
                     tk.fmt.psz_language = strdup("English");
+                    tk.fmt.psz_description = NULL;
 
                     tk.b_default = VLC_TRUE;
                     tk.b_enabled = VLC_TRUE;
@@ -489,7 +489,6 @@ static int Open( vlc_object_t * p_this )
                     tk.i_data_init = 0;
                     tk.p_data_init = NULL;
 
-                    tk.psz_name = NULL;
                     tk.psz_codec_name = NULL;
                     tk.psz_codec_settings = NULL;
                     tk.psz_codec_info_url = NULL;
@@ -607,9 +606,9 @@ static int Open( vlc_object_t * p_this )
                             KaxTrackName &tname = *(KaxTrackName*)el3;
                             tname.ReadData( p_sys->es->I_O() );
 
-                            tk.psz_name = UTF8ToStr( UTFstring( tname ) );
+                            tk.fmt.psz_description = UTF8ToStr( UTFstring( tname ) );
                             msg_Dbg( p_input, "|   |   |   + Track Name=%s",
-                                     tk.psz_name );
+                                     tk.fmt.psz_description );
                         }
                         else  if( EbmlId( *el3 ) == KaxTrackLanguage::ClassInfos.GlobalId )
                         {
@@ -1104,7 +1103,7 @@ static int Open( vlc_object_t * p_this )
                  !strncmp( tk.psz_codec, "A_AAC/MPEG4/", strlen( "A_AAC/MPEG4/" ) ) )
         {
             int i_profile, i_srate;
-            static int i_sample_rates[] =
+            static unsigned int i_sample_rates[] =
             {
                     96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
                         16000, 12000, 11025, 8000,  7350,  0,     0,     0
@@ -1213,6 +1212,10 @@ static void Close( vlc_object_t *p_this )
     for( i_track = 0; i_track < p_sys->i_track; i_track++ )
     {
 #define tk  p_sys->track[i_track]
+        if( tk.fmt.psz_description )
+        {
+            free( tk.fmt.psz_language );
+        }
         if( tk.psz_codec )
         {
             free( tk.psz_codec );
@@ -1369,27 +1372,13 @@ static int BlockGet( input_thread_t *p_input, KaxBlock **pp_block, int64_t *pi_r
     }
 }
 
-static pes_packet_t *MemToPES( input_thread_t *p_input, uint8_t *p_mem, int i_mem )
+static block_t *MemToBlock( input_thread_t *p_input, uint8_t *p_mem, int i_mem)
 {
-    pes_packet_t *p_pes;
-    data_packet_t *p_data;
-
-    if( ( p_pes = input_NewPES( p_input->p_method_data ) ) == NULL )
-    {
-        return NULL;
-    }
-
-    p_data = input_NewPacket( p_input->p_method_data, i_mem);
-
-    memcpy( p_data->p_payload_start, p_mem, i_mem );
-    p_data->p_payload_end = p_data->p_payload_start + i_mem;
-
-    p_pes->p_first = p_pes->p_last = p_data;
-    p_pes->i_nb_data = 1;
-    p_pes->i_pes_size = i_mem;
-    p_pes->i_rate = p_input->stream.control.i_rate;
-    
-    return p_pes;
+    block_t *p_block;
+    if( !(p_block = block_New( p_input, i_mem ) ) ) return NULL;
+    memcpy( p_block->p_buffer, p_mem, i_mem );
+    //p_block->i_rate = p_input->stream.control.i_rate;
+    return p_block;
 }
 
 static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts, mtime_t i_duration )
@@ -1415,7 +1404,7 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
         return;
     }
 
-    es_out_Control( p_input->p_es_out, ES_OUT_GET_SELECT, tk.p_es, &b );
+    es_out_Control( p_input->p_es_out, ES_OUT_GET_ES_STATE, tk.p_es, &b );
     if( !b )
     {
         tk.b_inited = VLC_FALSE;
@@ -1430,7 +1419,7 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
     /* First send init data */
     if( !tk.b_inited && tk.i_data_init > 0 )
     {
-        pes_packet_t *p_init;
+        block_t *p_init;
 
         msg_Dbg( p_input, "sending header (%d bytes)", tk.i_data_init );
 
@@ -1462,17 +1451,17 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
             i_size[1] = __MIN( i_size[1], tk.i_data_init - i_offset - i_size[0] );
             i_size[2] = tk.i_data_init - i_offset - i_size[0] - i_size[1];
 
-            p_init = MemToPES( p_input, &tk.p_data_init[i_offset], i_size[0] );
+            p_init = MemToBlock( p_input, &tk.p_data_init[i_offset], i_size[0] );
             if( p_init )
             {
                 es_out_Send( p_input->p_es_out, tk.p_es, p_init );
             }
-            p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]], i_size[1] );
+            p_init = MemToBlock( p_input, &tk.p_data_init[i_offset+i_size[0]], i_size[1] );
             if( p_init )
             {
                 es_out_Send( p_input->p_es_out, tk.p_es, p_init );
             }
-            p_init = MemToPES( p_input, &tk.p_data_init[i_offset+i_size[0]+i_size[1]], i_size[2] );
+            p_init = MemToBlock( p_input, &tk.p_data_init[i_offset+i_size[0]+i_size[1]], i_size[2] );
             if( p_init )
             {
                 es_out_Send( p_input->p_es_out, tk.p_es, p_init );
@@ -1480,7 +1469,7 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
         }
         else
         {
-            p_init = MemToPES( p_input, tk.p_data_init, tk.i_data_init );
+            p_init = MemToBlock( p_input, tk.p_data_init, tk.i_data_init );
             if( p_init )
             {
                 es_out_Send( p_input->p_es_out, tk.p_es, p_init );
@@ -1492,35 +1481,35 @@ static void BlockDecode( input_thread_t *p_input, KaxBlock *block, mtime_t i_pts
 
     for( i = 0; i < block->NumberFrames(); i++ )
     {
-        pes_packet_t *p_pes;
+        block_t *p_block;
         DataBuffer &data = block->GetBuffer(i);
 
-        p_pes = MemToPES( p_input, data.Buffer(), data.Size() );
-        if( p_pes == NULL )
+        p_block = MemToBlock( p_input, data.Buffer(), data.Size() );
+        if( p_block == NULL )
         {
             break;
         }
 
-        p_pes->i_pts = i_pts;
-        p_pes->i_dts = i_pts;
+        if( tk.fmt.i_cat != VIDEO_ES )
+            p_block->i_dts = p_block->i_pts = i_pts;
+        else
+        {
+            p_block->i_dts = i_pts;
+            p_block->i_pts = 0;
+        }
 
         if( tk.fmt.i_cat == SPU_ES && strcmp( tk.psz_codec, "S_VOBSUB" ) )
         {
             if( i_duration > 0 )
             {
-                p_pes->i_dts += i_duration * 1000;
+                p_block->i_dts += i_duration * 1000;
             }
             else
             {
-                p_pes->i_dts = 0;
-            }
-
-            if( p_pes->p_first && p_pes->i_pes_size > 0 )
-            {
-                p_pes->p_first->p_payload_end[0] = '\0';
+                p_block->i_dts = 0;
             }
         }
-        es_out_Send( p_input->p_es_out, tk.p_es, p_pes );
+        es_out_Send( p_input->p_es_out, tk.p_es, p_block );
 
         /* use time stamp only for first block */
         i_pts = 0;
@@ -2182,14 +2171,9 @@ static void InformationsCreate( input_thread_t *p_input )
     p_cat = input_InfoCategory( p_input, "Matroska" );
     if( p_sys->f_duration > 1000.1 )
     {
-        int64_t i_sec = (int64_t)p_sys->f_duration / 1000;
-        int h,m,s;
-
-        h = i_sec / 3600;
-        m = ( i_sec / 60 ) % 60;
-        s = i_sec % 60;
-
-        input_AddInfo( p_cat, _("Duration"), "%d:%2.2d:%2.2d" , h, m, s );
+       char psz_buffer[MSTRTIME_MAX_SIZE];
+        input_AddInfo( p_cat, _("Duration"), 
+                      msecstotimestr( psz_buffer, p_sys->f_duration ) );
     }
 
     if( p_sys->psz_title )
@@ -2221,9 +2205,13 @@ static void InformationsCreate( input_thread_t *p_input )
 
         sprintf( psz_cat, "Stream %d", i_track );
         p_cat = input_InfoCategory( p_input, psz_cat);
-        if( tk.psz_name )
+        if( tk.fmt.psz_description )
+        {
+            input_AddInfo( p_cat, _("Name"), "%s", tk.fmt.psz_description );
+        }
+        if( tk.fmt.psz_language )
         {
-            input_AddInfo( p_cat, _("Name"), "%s", tk.psz_name );
+            input_AddInfo( p_cat, _("Language"), "%s", tk.fmt.psz_language );
         }
         if( tk.psz_codec_name )
         {