changeset 3636:1f8f906eb49e libavformat

matroskadec: return pointer instead of index in matroska_find_track_by_num()
author aurel
date Tue, 05 Aug 2008 00:40:12 +0000
parents 318d5e2f9aed
children c2d2760cfba0
files matroskadec.c
diffstat 1 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/matroskadec.c	Tue Aug 05 00:40:09 2008 +0000
+++ b/matroskadec.c	Tue Aug 05 00:40:12 2008 +0000
@@ -721,7 +721,7 @@
 }
 
 
-static int
+static MatroskaTrack *
 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
                             int                   num)
 {
@@ -729,9 +729,10 @@
 
     for (i = 0; i < matroska->num_tracks; i++)
         if (matroska->tracks[i]->num == num)
-            return i;
-
-    return -1;
+            return matroska->tracks[i];
+
+    av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
+    return NULL;
 }
 
 
@@ -2745,14 +2746,13 @@
     }
 
     if (matroska->index_parsed) {
-        int i, track, stream;
+        int i;
         for (i=0; i<matroska->num_indexes; i++) {
             MatroskaDemuxIndex *idx = &matroska->index[i];
-            track = matroska_find_track_by_num(matroska, idx->track);
-            if (track < 0)  continue;
-            stream = matroska->tracks[track]->stream->index;
-            if (stream >= 0 && stream < matroska->ctx->nb_streams)
-                av_add_index_entry(matroska->ctx->streams[stream],
+            MatroskaTrack *track = matroska_find_track_by_num(matroska,
+                                                              idx->track);
+            if (track && track->stream)
+                av_add_index_entry(track->stream,
                                    idx->pos, idx->time/AV_TIME_BASE,
                                    0, 0, AVINDEX_KEYFRAME);
         }
@@ -2766,8 +2766,8 @@
                      int64_t pos, uint64_t cluster_time, uint64_t duration,
                      int is_keyframe)
 {
+    MatroskaTrack *track;
     int res = 0;
-    int track;
     AVStream *st;
     AVPacket *pkt;
     uint8_t *origdata = data;
@@ -2787,19 +2787,19 @@
 
     /* fetch track from num */
     track = matroska_find_track_by_num(matroska, num);
-    if (size <= 3 || track < 0 || track >= matroska->num_tracks) {
+    if (size <= 3 || !track || !track->stream) {
         av_log(matroska->ctx, AV_LOG_INFO,
-               "Invalid stream %d or size %u\n", track, size);
+               "Invalid stream %"PRIu64" or size %u\n", num, size);
         av_free(origdata);
         return res;
     }
-    st = matroska->tracks[track]->stream;
+    st = track->stream;
     if (st->discard >= AVDISCARD_ALL) {
         av_free(origdata);
         return res;
     }
     if (duration == AV_NOPTS_VALUE)
-        duration = matroska->tracks[track]->default_duration / matroska->time_scale;
+        duration = track->default_duration / matroska->time_scale;
 
     /* block_time (relative to cluster time) */
     block_time = AV_RB16(data);
@@ -2904,7 +2904,7 @@
             if (st->codec->codec_id == CODEC_ID_RA_288 ||
                 st->codec->codec_id == CODEC_ID_COOK ||
                 st->codec->codec_id == CODEC_ID_ATRAC3) {
-                MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track];
+                MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
                 int a = st->codec->block_align;
                 int sps = audiotrack->sub_packet_size;
                 int cfs = audiotrack->coded_framesize;
@@ -2940,9 +2940,9 @@
                 int offset = 0, pkt_size = lace_size[n];
                 uint8_t *pkt_data = data;
 
-                if (matroska->tracks[track]->encoding_scope & 1) {
+                if (track->encoding_scope & 1) {
                     offset = matroska_decode_buffer(&pkt_data, &pkt_size,
-                                                    matroska->tracks[track]);
+                                                    track);
                     if (offset < 0)
                         continue;
                 }
@@ -2956,7 +2956,7 @@
                     break;
                 }
                 if (offset)
-                    memcpy (pkt->data, matroska->tracks[track]->encoding_settings, offset);
+                    memcpy (pkt->data, track->encoding_settings, offset);
                 memcpy (pkt->data+offset, pkt_data, pkt_size);
 
                 if (pkt_data != data)