Commit 9dde1a31 authored by aurel's avatar aurel

matroskadec: return pointer instead of index in matroska_find_track_by_num()

git-svn-id: file:///var/local/repositories/ffmpeg/trunk@14556 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent ba05c083
...@@ -721,7 +721,7 @@ matroska_ebmlnum_sint (uint8_t *data, ...@@ -721,7 +721,7 @@ matroska_ebmlnum_sint (uint8_t *data,
} }
static int static MatroskaTrack *
matroska_find_track_by_num (MatroskaDemuxContext *matroska, matroska_find_track_by_num (MatroskaDemuxContext *matroska,
int num) int num)
{ {
...@@ -729,9 +729,10 @@ matroska_find_track_by_num (MatroskaDemuxContext *matroska, ...@@ -729,9 +729,10 @@ matroska_find_track_by_num (MatroskaDemuxContext *matroska,
for (i = 0; i < matroska->num_tracks; i++) for (i = 0; i < matroska->num_tracks; i++)
if (matroska->tracks[i]->num == num) if (matroska->tracks[i]->num == num)
return i; return matroska->tracks[i];
return -1; av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
return NULL;
} }
...@@ -2745,14 +2746,13 @@ matroska_read_header (AVFormatContext *s, ...@@ -2745,14 +2746,13 @@ matroska_read_header (AVFormatContext *s,
} }
if (matroska->index_parsed) { if (matroska->index_parsed) {
int i, track, stream; int i;
for (i=0; i<matroska->num_indexes; i++) { for (i=0; i<matroska->num_indexes; i++) {
MatroskaDemuxIndex *idx = &matroska->index[i]; MatroskaDemuxIndex *idx = &matroska->index[i];
track = matroska_find_track_by_num(matroska, idx->track); MatroskaTrack *track = matroska_find_track_by_num(matroska,
if (track < 0) continue; idx->track);
stream = matroska->tracks[track]->stream->index; if (track && track->stream)
if (stream >= 0 && stream < matroska->ctx->nb_streams) av_add_index_entry(track->stream,
av_add_index_entry(matroska->ctx->streams[stream],
idx->pos, idx->time/AV_TIME_BASE, idx->pos, idx->time/AV_TIME_BASE,
0, 0, AVINDEX_KEYFRAME); 0, 0, AVINDEX_KEYFRAME);
} }
...@@ -2766,8 +2766,8 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, ...@@ -2766,8 +2766,8 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
int64_t pos, uint64_t cluster_time, uint64_t duration, int64_t pos, uint64_t cluster_time, uint64_t duration,
int is_keyframe) int is_keyframe)
{ {
MatroskaTrack *track;
int res = 0; int res = 0;
int track;
AVStream *st; AVStream *st;
AVPacket *pkt; AVPacket *pkt;
uint8_t *origdata = data; uint8_t *origdata = data;
...@@ -2787,19 +2787,19 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, ...@@ -2787,19 +2787,19 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
/* fetch track from num */ /* fetch track from num */
track = matroska_find_track_by_num(matroska, 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, 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); av_free(origdata);
return res; return res;
} }
st = matroska->tracks[track]->stream; st = track->stream;
if (st->discard >= AVDISCARD_ALL) { if (st->discard >= AVDISCARD_ALL) {
av_free(origdata); av_free(origdata);
return res; return res;
} }
if (duration == AV_NOPTS_VALUE) 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 (relative to cluster time) */
block_time = AV_RB16(data); block_time = AV_RB16(data);
...@@ -2904,7 +2904,7 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, ...@@ -2904,7 +2904,7 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
if (st->codec->codec_id == CODEC_ID_RA_288 || if (st->codec->codec_id == CODEC_ID_RA_288 ||
st->codec->codec_id == CODEC_ID_COOK || st->codec->codec_id == CODEC_ID_COOK ||
st->codec->codec_id == CODEC_ID_ATRAC3) { st->codec->codec_id == CODEC_ID_ATRAC3) {
MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track]; MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
int a = st->codec->block_align; int a = st->codec->block_align;
int sps = audiotrack->sub_packet_size; int sps = audiotrack->sub_packet_size;
int cfs = audiotrack->coded_framesize; int cfs = audiotrack->coded_framesize;
...@@ -2940,9 +2940,9 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, ...@@ -2940,9 +2940,9 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
int offset = 0, pkt_size = lace_size[n]; int offset = 0, pkt_size = lace_size[n];
uint8_t *pkt_data = data; 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, offset = matroska_decode_buffer(&pkt_data, &pkt_size,
matroska->tracks[track]); track);
if (offset < 0) if (offset < 0)
continue; continue;
} }
...@@ -2956,7 +2956,7 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, ...@@ -2956,7 +2956,7 @@ matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
break; break;
} }
if (offset) 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); memcpy (pkt->data+offset, pkt_data, pkt_size);
if (pkt_data != data) if (pkt_data != data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment