fix filename self-references
[vlc.git] / modules / demux / mkv / matroska_segment_parse.cpp
index ad31e0b..1a5ec21 100644 (file)
@@ -1,5 +1,5 @@
 /*****************************************************************************
- * mkv.cpp : matroska demuxer
+ * matroska_segment_parse.cpp : matroska demuxer
  *****************************************************************************
  * Copyright (C) 2003-2010 the VideoLAN team
  * $Id$
@@ -28,6 +28,8 @@
 
 #include "demux.hpp"
 
+#include "Ebml_parser.hpp"
+
 /*****************************************************************************
  * Some functions to manipulate memory
  *****************************************************************************/
@@ -855,6 +857,22 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
 
             msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterFlagHidden: %s", chapters.b_display_seekpoint ? "no":"yes" );
         }
+        else if( MKV_IS_ID( l, KaxChapterSegmentUID ) )
+        {
+            chapters.p_segment_uid = new KaxChapterSegmentUID( *static_cast<KaxChapterSegmentUID*>(l) );
+            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentUID= %u", *(uint32*)chapters.p_segment_uid->GetBuffer() );
+        }
+        else if( MKV_IS_ID( l, KaxChapterSegmentEditionUID ) )
+        {
+            chapters.p_segment_edition_uid = new KaxChapterSegmentEditionUID( *static_cast<KaxChapterSegmentEditionUID*>(l) );
+            msg_Dbg( &sys.demuxer, "|   |   |   |   + ChapterSegmentEditionUID= %u",
+#if LIBMATROSKA_VERSION < 0x010300
+            *(uint32*)chapters.p_segment_edition_uid->GetBuffer()
+#else
+            *(uint32*)chapters.p_segment_edition_uid
+#endif
+            );
+        }
         else if( MKV_IS_ID( l, KaxChapterTimeStart ) )
         {
             KaxChapterTimeStart &start =*(KaxChapterTimeStart*)l;
@@ -952,7 +970,7 @@ void matroska_segment_c::ParseChapterAtom( int i_level, KaxChapterAtom *ca, chap
         {
             chapter_item_c *new_sub_chapter = new chapter_item_c();
             ParseChapterAtom( i_level+1, static_cast<KaxChapterAtom *>(l), *new_sub_chapter );
-            new_sub_chapter->psz_parent = &chapters;
+            new_sub_chapter->p_parent = &chapters;
             chapters.sub_chapters.push_back( new_sub_chapter );
         }
     }
@@ -972,28 +990,21 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
 
     while( attachedFile && ( attachedFile->GetSize() > 0 ) )
     {
-        std::string psz_mime_type  = GetChild<KaxMimeType>( *attachedFile );
-        KaxFileName  &file_name    = GetChild<KaxFileName>( *attachedFile );
         KaxFileData  &img_data     = GetChild<KaxFileData>( *attachedFile );
+        attachment_c *new_attachment = new attachment_c( ToUTF8( UTFstring( GetChild<KaxFileName>( *attachedFile ) ) ),
+                                                        GetChild<KaxMimeType>( *attachedFile ),
+                                                        img_data.GetSize() );
 
-        attachment_c *new_attachment = new attachment_c();
+        msg_Dbg( &sys.demuxer, "|   |   - %s (%s)", new_attachment->fileName(), new_attachment->mimeType() );
 
-        if( new_attachment )
+        if( new_attachment->init() )
         {
-            new_attachment->psz_file_name  = ToUTF8( UTFstring( file_name ) );
-            new_attachment->psz_mime_type  = psz_mime_type;
-            new_attachment->i_size         = img_data.GetSize();
-            new_attachment->p_data         = malloc( img_data.GetSize() );
-
-            if( new_attachment->p_data )
-            {
-                memcpy( new_attachment->p_data, img_data.GetBuffer(), img_data.GetSize() );
-                sys.stored_attachments.push_back( new_attachment );
-            }
-            else
-            {
-                delete new_attachment;
-            }
+             memcpy( new_attachment->p_data, img_data.GetBuffer(), img_data.GetSize() );
+             sys.stored_attachments.push_back( new_attachment );
+        }
+        else
+        {
+            delete new_attachment;
         }
 
         attachedFile = &GetNextChild<KaxAttached>( *attachments, *attachedFile );
@@ -1007,7 +1018,6 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters )
 {
     EbmlElement *el;
     int i_upper_level = 0;
-    mtime_t i_dur;
 
     /* Master elements */
     chapters->Read( es, EBML_CONTEXT(chapters), i_upper_level, el, true );
@@ -1061,19 +1071,6 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters )
             msg_Dbg( &sys.demuxer, "|   |   + Unknown (%s)", typeid(*l).name() );
         }
     }
-
-    for( size_t i = 0; i < stored_editions.size(); i++ )
-    {
-        stored_editions[i]->RefreshChapters( );
-    }
-
-    if ( stored_editions.size() != 0 && stored_editions[i_default_edition]->b_ordered )
-    {
-        /* update the duration of the segment according to the sum of all sub chapters */
-        i_dur = stored_editions[i_default_edition]->Duration() / INT64_C(1000);
-        if (i_dur > 0)
-            i_duration = i_dur;
-    }
 }
 
 void matroska_segment_c::ParseCluster( )