comparison rmdec.c @ 4036:1349c277efbd libavformat

Add ByteIOContext argument to public ff_rm_* functions so that we can specify the data source as function argument instead of in s->pb before calling the function. Discussed in ML thread "[PATCH] fix small memleak in rdt.c".
author rbultje
date Mon, 17 Nov 2008 14:20:00 +0000
parents 2e7994e45100
children 56204ba7a2c5
comparison
equal deleted inserted replaced
4035:8c161751e4c7 4036:1349c277efbd
45 static void get_str8(ByteIOContext *pb, char *buf, int buf_size) 45 static void get_str8(ByteIOContext *pb, char *buf, int buf_size)
46 { 46 {
47 get_strl(pb, buf, buf_size, get_byte(pb)); 47 get_strl(pb, buf, buf_size, get_byte(pb));
48 } 48 }
49 49
50 static int rm_read_audio_stream_info(AVFormatContext *s, AVStream *st, 50 static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb,
51 int read_all) 51 AVStream *st, int read_all)
52 { 52 {
53 RMContext *rm = s->priv_data; 53 RMContext *rm = s->priv_data;
54 ByteIOContext *pb = s->pb;
55 char buf[256]; 54 char buf[256];
56 uint32_t version; 55 uint32_t version;
57 int i; 56 int i;
58 57
59 /* ra type header */ 58 /* ra type header */
194 } 193 }
195 return 0; 194 return 0;
196 } 195 }
197 196
198 int 197 int
199 ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVStream *st, int codec_data_size) 198 ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb,
200 { 199 AVStream *st, int codec_data_size)
201 ByteIOContext *pb = s->pb; 200 {
202 unsigned int v; 201 unsigned int v;
203 int size; 202 int size;
204 int64_t codec_pos; 203 int64_t codec_pos;
205 204
206 av_set_pts_info(st, 64, 1, 1000); 205 av_set_pts_info(st, 64, 1, 1000);
207 codec_pos = url_ftell(pb); 206 codec_pos = url_ftell(pb);
208 v = get_be32(pb); 207 v = get_be32(pb);
209 if (v == MKTAG(0xfd, 'a', 'r', '.')) { 208 if (v == MKTAG(0xfd, 'a', 'r', '.')) {
210 /* ra type header */ 209 /* ra type header */
211 if (rm_read_audio_stream_info(s, st, 0)) 210 if (rm_read_audio_stream_info(s, pb, st, 0))
212 return -1; 211 return -1;
213 } else { 212 } else {
214 int fps, fps2; 213 int fps, fps2;
215 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { 214 if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
216 fail1: 215 fail1:
273 272
274 rm->old_format = 1; 273 rm->old_format = 1;
275 st = av_new_stream(s, 0); 274 st = av_new_stream(s, 0);
276 if (!st) 275 if (!st)
277 return -1; 276 return -1;
278 return rm_read_audio_stream_info(s, st, 1); 277 return rm_read_audio_stream_info(s, s->pb, st, 1);
279 } 278 }
280 279
281 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) 280 static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
282 { 281 {
283 RMContext *rm = s->priv_data; 282 RMContext *rm = s->priv_data;
355 st->start_time = start_time; 354 st->start_time = start_time;
356 st->duration = duration; 355 st->duration = duration;
357 get_str8(pb, buf, sizeof(buf)); /* desc */ 356 get_str8(pb, buf, sizeof(buf)); /* desc */
358 get_str8(pb, buf, sizeof(buf)); /* mimetype */ 357 get_str8(pb, buf, sizeof(buf)); /* mimetype */
359 st->codec->codec_type = CODEC_TYPE_DATA; 358 st->codec->codec_type = CODEC_TYPE_DATA;
360 if (ff_rm_read_mdpr_codecdata(s, st, get_be32(pb)) < 0) 359 if (ff_rm_read_mdpr_codecdata(s, s->pb, st, get_be32(pb)) < 0)
361 return -1; 360 return -1;
362 break; 361 break;
363 case MKTAG('D', 'A', 'T', 'A'): 362 case MKTAG('D', 'A', 'T', 'A'):
364 goto header_end; 363 goto header_end;
365 default: 364 default:
450 return len; 449 return len;
451 } 450 }
452 return -1; 451 return -1;
453 } 452 }
454 453
455 static int rm_assemble_video_frame(AVFormatContext *s, RMContext *rm, AVPacket *pkt, int len) 454 static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb,
456 { 455 RMContext *rm, AVPacket *pkt, int len)
457 ByteIOContext *pb = s->pb; 456 {
458 int hdr, seq, pic_num, len2, pos; 457 int hdr, seq, pic_num, len2, pos;
459 int type; 458 int type;
460 459
461 hdr = get_byte(pb); len--; 460 hdr = get_byte(pb); len--;
462 type = hdr >> 6; 461 type = hdr >> 6;
548 } 547 }
549 } 548 }
550 } 549 }
551 550
552 int 551 int
553 ff_rm_parse_packet (AVFormatContext *s, AVStream *st, int len, AVPacket *pkt, 552 ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb,
553 AVStream *st, int len, AVPacket *pkt,
554 int *seq, int *flags, int64_t *timestamp) 554 int *seq, int *flags, int64_t *timestamp)
555 { 555 {
556 ByteIOContext *pb = s->pb;
557 RMContext *rm = s->priv_data; 556 RMContext *rm = s->priv_data;
558 557
559 if (st->codec->codec_type == CODEC_TYPE_VIDEO) { 558 if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
560 rm->current_stream= st->id; 559 rm->current_stream= st->id;
561 if(rm_assemble_video_frame(s, rm, pkt, len) == 1) 560 if(rm_assemble_video_frame(s, pb, rm, pkt, len) == 1)
562 return -1; //got partial frame 561 return -1; //got partial frame
563 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) { 562 } else if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
564 if ((st->codec->codec_id == CODEC_ID_RA_288) || 563 if ((st->codec->codec_id == CODEC_ID_RA_288) ||
565 (st->codec->codec_id == CODEC_ID_COOK) || 564 (st->codec->codec_id == CODEC_ID_COOK) ||
566 (st->codec->codec_id == CODEC_ID_ATRAC3) || 565 (st->codec->codec_id == CODEC_ID_ATRAC3) ||
647 646
648 return 0; 647 return 0;
649 } 648 }
650 649
651 void 650 void
652 ff_rm_retrieve_cache (AVFormatContext *s, AVStream *st, AVPacket *pkt) 651 ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb,
653 { 652 AVStream *st, AVPacket *pkt)
654 ByteIOContext *pb = s->pb; 653 {
655 RMContext *rm = s->priv_data; 654 RMContext *rm = s->priv_data;
656 655
657 assert (rm->audio_pkt_cnt > 0); 656 assert (rm->audio_pkt_cnt > 0);
658 657
659 if (st->codec->codec_id == CODEC_ID_AAC) 658 if (st->codec->codec_id == CODEC_ID_AAC)
679 int flags; 678 int flags;
680 679
681 if (rm->audio_pkt_cnt) { 680 if (rm->audio_pkt_cnt) {
682 // If there are queued audio packet return them first 681 // If there are queued audio packet return them first
683 st = s->streams[rm->audio_stream_num]; 682 st = s->streams[rm->audio_stream_num];
684 ff_rm_retrieve_cache(s, st, pkt); 683 ff_rm_retrieve_cache(s, s->pb, st, pkt);
685 } else if (rm->old_format) { 684 } else if (rm->old_format) {
686 st = s->streams[0]; 685 st = s->streams[0];
687 if (st->codec->codec_id == CODEC_ID_RA_288) { 686 if (st->codec->codec_id == CODEC_ID_RA_288) {
688 int x, y; 687 int x, y;
689 688
715 len=sync(s, &timestamp, &flags, &i, &pos); 714 len=sync(s, &timestamp, &flags, &i, &pos);
716 if(len<0) 715 if(len<0)
717 return AVERROR(EIO); 716 return AVERROR(EIO);
718 st = s->streams[i]; 717 st = s->streams[i];
719 718
720 if (ff_rm_parse_packet (s, st, len, pkt, &seq, &flags, &timestamp) < 0) 719 if (ff_rm_parse_packet (s, s->pb, st, len, pkt, &seq, &flags, &timestamp) < 0)
721 goto resync; 720 goto resync;
722 721
723 if((flags&2) && (seq&0x7F) == 1) 722 if((flags&2) && (seq&0x7F) == 1)
724 av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); 723 av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
725 } 724 }