comparison rmdec.c @ 4732:0d7a569678a4 libavformat

Merge code for packet reading in "old" (.ra, audio-only) Realmedia files and the newer (.rm, audio/video) files. See "[PATCH] rmdec.c: merge old/new packet reading code" thread on mailinglist.
author rbultje
date Mon, 16 Mar 2009 12:47:34 +0000
parents a2390c6a35e6
children 7fbb4c4b3e3f
comparison
equal deleted inserted replaced
4731:18bcd89f5809 4732:0d7a569678a4
702 } 702 }
703 703
704 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt) 704 static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
705 { 705 {
706 RMDemuxContext *rm = s->priv_data; 706 RMDemuxContext *rm = s->priv_data;
707 ByteIOContext *pb = s->pb;
708 AVStream *st; 707 AVStream *st;
709 int i, len, res; 708 int i, len, res, seq = 1;
710 int64_t timestamp, pos; 709 int64_t timestamp, pos;
711 int old_flags, flags; 710 int old_flags, flags;
712 711
712 for (;;) {
713 if (rm->audio_pkt_cnt) { 713 if (rm->audio_pkt_cnt) {
714 // If there are queued audio packet return them first 714 // If there are queued audio packet return them first
715 st = s->streams[rm->audio_stream_num]; 715 st = s->streams[rm->audio_stream_num];
716 ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt); 716 ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
717 } else if (rm->old_format) { 717 } else {
718 if (rm->old_format) {
718 RMStream *ast; 719 RMStream *ast;
719 720
720 st = s->streams[0]; 721 st = s->streams[0];
721 ast = st->priv_data; 722 ast = st->priv_data;
722 if (st->codec->codec_id == CODEC_ID_RA_288) { 723 timestamp = AV_NOPTS_VALUE;
723 int x, y; 724 len = !ast->audio_framesize ? RAW_PACKET_SIZE :
724 725 ast->coded_framesize * ast->sub_packet_h / 2;
725 for (y = 0; y < ast->sub_packet_h; y++) 726 flags = (seq++ == 1) ? 2 : 0;
726 for (x = 0; x < ast->sub_packet_h/2; x++) 727 } else {
727 if (get_buffer(pb, ast->pkt.data+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0) 728 len=sync(s, &timestamp, &flags, &i, &pos);
728 return AVERROR(EIO); 729 st = s->streams[i];
729 rm->audio_stream_num = 0; 730 }
730 rm->audio_pkt_cnt = ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - 1; 731
731 // Release first audio packet 732 if(len<0 || url_feof(s->pb))
732 av_new_packet(pkt, st->codec->block_align);
733 memcpy(pkt->data, ast->pkt.data, st->codec->block_align); //FIXME avoid this
734 pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
735 pkt->stream_index = 0;
736 } else {
737 /* just read raw bytes */
738 len = RAW_PACKET_SIZE;
739 len= av_get_packet(pb, pkt, len);
740 pkt->stream_index = 0;
741 if (len <= 0) {
742 return AVERROR(EIO); 733 return AVERROR(EIO);
743 }
744 pkt->size = len;
745 }
746 rm_ac3_swap_bytes(st, pkt);
747 } else {
748 int seq=1;
749 resync:
750 len=sync(s, &timestamp, &flags, &i, &pos);
751 if(len<0)
752 return AVERROR(EIO);
753 st = s->streams[i];
754 734
755 old_flags = flags; 735 old_flags = flags;
756 res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt, 736 res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
757 &seq, &flags, &timestamp); 737 &seq, &flags, &timestamp);
758 if((old_flags&2) && (seq&0x7F) == 1) 738 if((old_flags&2) && (seq&0x7F) == 1)
759 av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME); 739 av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
760 if (res < 0) 740 if (res)
761 goto resync; 741 continue;
742 }
762 743
763 if( (st->discard >= AVDISCARD_NONKEY && !(flags&2)) 744 if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
764 || st->discard >= AVDISCARD_ALL){ 745 || st->discard >= AVDISCARD_ALL){
765 av_free_packet(pkt); 746 av_free_packet(pkt);
766 while (rm->audio_pkt_cnt > 0) { 747 } else
767 ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt); 748 break;
768 av_free_packet(pkt);
769 }
770 goto resync;
771 }
772 } 749 }
773 750
774 return 0; 751 return 0;
775 } 752 }
776 753