diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2007-03-02 00:14:53 +0000 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2007-03-02 00:14:53 +0000 |
commit | 3c58dc0b3c3835ec405645681b7479a09168ea34 (patch) | |
tree | 2a5b630ccf56f08674f8566584bf75495b29e735 | |
parent | 0cc5ea2e9587a987f85e0c7c0314c22e9f5ec91c (diff) | |
download | ffmpeg-3c58dc0b3c3835ec405645681b7479a09168ea34.tar.gz |
don't rely on a specific appearance order for ebml elements at the same level
Originally committed as revision 8181 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavformat/matroska.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/libavformat/matroska.c b/libavformat/matroska.c index 5d5aec325b..094c859feb 100644 --- a/libavformat/matroska.c +++ b/libavformat/matroska.c @@ -289,6 +289,10 @@ typedef struct MatroskaSubtitleTrack { //.. } 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 @@ matroska_add_stream (MatroskaDemuxContext *matroska) 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 @@ matroska_add_stream (MatroskaDemuxContext *matroska) /* 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 @@ matroska_add_stream (MatroskaDemuxContext *matroska) /* 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 @@ matroska_add_stream (MatroskaDemuxContext *matroska) /* 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 @@ matroska_add_stream (MatroskaDemuxContext *matroska) } 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))) { |