changeset 1832:1e51dfa8ef85 libavformat

don't rely on a specific appearance order for ebml elements at the same level
author aurel
date Fri, 02 Mar 2007 00:14:53 +0000
parents bdca904db5e5
children 09a67819763e
files matroska.c
diffstat 1 files changed, 14 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/matroska.c	Fri Mar 02 00:06:03 2007 +0000
+++ b/matroska.c	Fri Mar 02 00:14:53 2007 +0000
@@ -289,6 +289,10 @@
     //..
 } MatroskaSubtitleTrack;
 
+#define MAX_TRACK_SIZE (FFMAX(FFMAX(sizeof(MatroskaVideoTrack), \
+                                    sizeof(MatroskaAudioTrack)), \
+                                    sizeof(MatroskaSubtitleTrack)))
+
 typedef struct MatroskaLevel {
     uint64_t start, length;
 } MatroskaLevel;
@@ -1165,7 +1169,7 @@
     av_log(matroska->ctx, AV_LOG_DEBUG, "parsing track, adding stream..,\n");
 
     /* Allocate a generic track. As soon as we know its type we'll realloc. */
-    track = av_mallocz(sizeof(MatroskaTrack));
+    track = av_mallocz(MAX_TRACK_SIZE);
     matroska->num_tracks++;
 
     /* start with the master */
@@ -1204,30 +1208,19 @@
             /* track type (video, audio, combined, subtitle, etc.) */
             case MATROSKA_ID_TRACKTYPE: {
                 uint64_t num;
-                if (track->type != 0) {
+                if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
+                    break;
+                if (track->type && track->type != num) {
                     av_log(matroska->ctx, AV_LOG_INFO,
                            "More than one tracktype in an entry - skip\n");
                     break;
                 }
-                if ((res = ebml_read_uint(matroska, &id, &num)) < 0)
-                    break;
                 track->type = num;
 
-                /* ok, so we're actually going to reallocate this thing */
                 switch (track->type) {
                     case MATROSKA_TRACK_TYPE_VIDEO:
-                        track = (MatroskaTrack *)
-                            av_realloc(track, sizeof(MatroskaVideoTrack));
-                        break;
                     case MATROSKA_TRACK_TYPE_AUDIO:
-                        track = (MatroskaTrack *)
-                            av_realloc(track, sizeof(MatroskaAudioTrack));
-                        ((MatroskaAudioTrack *)track)->channels = 1;
-                        ((MatroskaAudioTrack *)track)->samplerate = 8000;
-                        break;
                     case MATROSKA_TRACK_TYPE_SUBTITLE:
-                        track = (MatroskaTrack *)
-                            av_realloc(track, sizeof(MatroskaSubtitleTrack));
                         break;
                     case MATROSKA_TRACK_TYPE_COMPLEX:
                     case MATROSKA_TRACK_TYPE_LOGO:
@@ -1246,6 +1239,8 @@
             /* tracktype specific stuff for video */
             case MATROSKA_ID_TRACKVIDEO: {
                 MatroskaVideoTrack *videotrack;
+                if (!track->type)
+                    track->type = MATROSKA_TRACK_TYPE_VIDEO;
                 if (track->type != MATROSKA_TRACK_TYPE_VIDEO) {
                     av_log(matroska->ctx, AV_LOG_INFO,
                            "video data in non-video track - ignoring\n");
@@ -1413,6 +1408,8 @@
             /* tracktype specific stuff for audio */
             case MATROSKA_ID_TRACKAUDIO: {
                 MatroskaAudioTrack *audiotrack;
+                if (!track->type)
+                    track->type = MATROSKA_TRACK_TYPE_AUDIO;
                 if (track->type != MATROSKA_TRACK_TYPE_AUDIO) {
                     av_log(matroska->ctx, AV_LOG_INFO,
                            "audio data in non-audio track - ignoring\n");
@@ -1421,6 +1418,8 @@
                 } else if ((res = ebml_read_master(matroska, &id)) < 0)
                     break;
                 audiotrack = (MatroskaAudioTrack *)track;
+                audiotrack->channels = 1;
+                audiotrack->samplerate = 8000;
 
                 while (res == 0) {
                     if (!(id = ebml_peek_id(matroska, &matroska->level_up))) {