comparison matroskadec.c @ 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
comparison
equal deleted inserted replaced
3635:318d5e2f9aed 3636:1f8f906eb49e
719 719
720 return res; 720 return res;
721 } 721 }
722 722
723 723
724 static int 724 static MatroskaTrack *
725 matroska_find_track_by_num (MatroskaDemuxContext *matroska, 725 matroska_find_track_by_num (MatroskaDemuxContext *matroska,
726 int num) 726 int num)
727 { 727 {
728 int i; 728 int i;
729 729
730 for (i = 0; i < matroska->num_tracks; i++) 730 for (i = 0; i < matroska->num_tracks; i++)
731 if (matroska->tracks[i]->num == num) 731 if (matroska->tracks[i]->num == num)
732 return i; 732 return matroska->tracks[i];
733 733
734 return -1; 734 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num);
735 return NULL;
735 } 736 }
736 737
737 738
738 /* 739 /*
739 * Put one packet in an application-supplied AVPacket struct. 740 * Put one packet in an application-supplied AVPacket struct.
2743 } 2744 }
2744 res = 0; 2745 res = 0;
2745 } 2746 }
2746 2747
2747 if (matroska->index_parsed) { 2748 if (matroska->index_parsed) {
2748 int i, track, stream; 2749 int i;
2749 for (i=0; i<matroska->num_indexes; i++) { 2750 for (i=0; i<matroska->num_indexes; i++) {
2750 MatroskaDemuxIndex *idx = &matroska->index[i]; 2751 MatroskaDemuxIndex *idx = &matroska->index[i];
2751 track = matroska_find_track_by_num(matroska, idx->track); 2752 MatroskaTrack *track = matroska_find_track_by_num(matroska,
2752 if (track < 0) continue; 2753 idx->track);
2753 stream = matroska->tracks[track]->stream->index; 2754 if (track && track->stream)
2754 if (stream >= 0 && stream < matroska->ctx->nb_streams) 2755 av_add_index_entry(track->stream,
2755 av_add_index_entry(matroska->ctx->streams[stream],
2756 idx->pos, idx->time/AV_TIME_BASE, 2756 idx->pos, idx->time/AV_TIME_BASE,
2757 0, 0, AVINDEX_KEYFRAME); 2757 0, 0, AVINDEX_KEYFRAME);
2758 } 2758 }
2759 } 2759 }
2760 2760
2764 static int 2764 static int
2765 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, 2765 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size,
2766 int64_t pos, uint64_t cluster_time, uint64_t duration, 2766 int64_t pos, uint64_t cluster_time, uint64_t duration,
2767 int is_keyframe) 2767 int is_keyframe)
2768 { 2768 {
2769 MatroskaTrack *track;
2769 int res = 0; 2770 int res = 0;
2770 int track;
2771 AVStream *st; 2771 AVStream *st;
2772 AVPacket *pkt; 2772 AVPacket *pkt;
2773 uint8_t *origdata = data; 2773 uint8_t *origdata = data;
2774 int16_t block_time; 2774 int16_t block_time;
2775 uint32_t *lace_size = NULL; 2775 uint32_t *lace_size = NULL;
2785 data += n; 2785 data += n;
2786 size -= n; 2786 size -= n;
2787 2787
2788 /* fetch track from num */ 2788 /* fetch track from num */
2789 track = matroska_find_track_by_num(matroska, num); 2789 track = matroska_find_track_by_num(matroska, num);
2790 if (size <= 3 || track < 0 || track >= matroska->num_tracks) { 2790 if (size <= 3 || !track || !track->stream) {
2791 av_log(matroska->ctx, AV_LOG_INFO, 2791 av_log(matroska->ctx, AV_LOG_INFO,
2792 "Invalid stream %d or size %u\n", track, size); 2792 "Invalid stream %"PRIu64" or size %u\n", num, size);
2793 av_free(origdata); 2793 av_free(origdata);
2794 return res; 2794 return res;
2795 } 2795 }
2796 st = matroska->tracks[track]->stream; 2796 st = track->stream;
2797 if (st->discard >= AVDISCARD_ALL) { 2797 if (st->discard >= AVDISCARD_ALL) {
2798 av_free(origdata); 2798 av_free(origdata);
2799 return res; 2799 return res;
2800 } 2800 }
2801 if (duration == AV_NOPTS_VALUE) 2801 if (duration == AV_NOPTS_VALUE)
2802 duration = matroska->tracks[track]->default_duration / matroska->time_scale; 2802 duration = track->default_duration / matroska->time_scale;
2803 2803
2804 /* block_time (relative to cluster time) */ 2804 /* block_time (relative to cluster time) */
2805 block_time = AV_RB16(data); 2805 block_time = AV_RB16(data);
2806 data += 2; 2806 data += 2;
2807 flags = *data++; 2807 flags = *data++;
2902 2902
2903 for (n = 0; n < laces; n++) { 2903 for (n = 0; n < laces; n++) {
2904 if (st->codec->codec_id == CODEC_ID_RA_288 || 2904 if (st->codec->codec_id == CODEC_ID_RA_288 ||
2905 st->codec->codec_id == CODEC_ID_COOK || 2905 st->codec->codec_id == CODEC_ID_COOK ||
2906 st->codec->codec_id == CODEC_ID_ATRAC3) { 2906 st->codec->codec_id == CODEC_ID_ATRAC3) {
2907 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track]; 2907 MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
2908 int a = st->codec->block_align; 2908 int a = st->codec->block_align;
2909 int sps = audiotrack->sub_packet_size; 2909 int sps = audiotrack->sub_packet_size;
2910 int cfs = audiotrack->coded_framesize; 2910 int cfs = audiotrack->coded_framesize;
2911 int h = audiotrack->sub_packet_h; 2911 int h = audiotrack->sub_packet_h;
2912 int y = audiotrack->sub_packet_cnt; 2912 int y = audiotrack->sub_packet_cnt;
2938 } 2938 }
2939 } else { 2939 } else {
2940 int offset = 0, pkt_size = lace_size[n]; 2940 int offset = 0, pkt_size = lace_size[n];
2941 uint8_t *pkt_data = data; 2941 uint8_t *pkt_data = data;
2942 2942
2943 if (matroska->tracks[track]->encoding_scope & 1) { 2943 if (track->encoding_scope & 1) {
2944 offset = matroska_decode_buffer(&pkt_data, &pkt_size, 2944 offset = matroska_decode_buffer(&pkt_data, &pkt_size,
2945 matroska->tracks[track]); 2945 track);
2946 if (offset < 0) 2946 if (offset < 0)
2947 continue; 2947 continue;
2948 } 2948 }
2949 2949
2950 pkt = av_mallocz(sizeof(AVPacket)); 2950 pkt = av_mallocz(sizeof(AVPacket));
2954 res = AVERROR(ENOMEM); 2954 res = AVERROR(ENOMEM);
2955 n = laces-1; 2955 n = laces-1;
2956 break; 2956 break;
2957 } 2957 }
2958 if (offset) 2958 if (offset)
2959 memcpy (pkt->data, matroska->tracks[track]->encoding_settings, offset); 2959 memcpy (pkt->data, track->encoding_settings, offset);
2960 memcpy (pkt->data+offset, pkt_data, pkt_size); 2960 memcpy (pkt->data+offset, pkt_data, pkt_size);
2961 2961
2962 if (pkt_data != data) 2962 if (pkt_data != data)
2963 av_free(pkt_data); 2963 av_free(pkt_data);
2964 2964