Revision 6a2d3fc3

View differences:

libavformat/rmdec.c
704 704
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
705 705
{
706 706
    RMDemuxContext *rm = s->priv_data;
707
    ByteIOContext *pb = s->pb;
708 707
    AVStream *st;
709
    int i, len, res;
708
    int i, len, res, seq = 1;
710 709
    int64_t timestamp, pos;
711 710
    int old_flags, flags;
712 711

  
712
    for (;;) {
713 713
    if (rm->audio_pkt_cnt) {
714 714
        // If there are queued audio packet return them first
715 715
        st = s->streams[rm->audio_stream_num];
716 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 719
        RMStream *ast;
719 720

  
720 721
        st = s->streams[0];
721 722
        ast = st->priv_data;
722
        if (st->codec->codec_id == CODEC_ID_RA_288) {
723
            int x, y;
724

  
725
            for (y = 0; y < ast->sub_packet_h; y++)
726
                for (x = 0; x < ast->sub_packet_h/2; x++)
727
                    if (get_buffer(pb, ast->pkt.data+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0)
728
                        return AVERROR(EIO);
729
            rm->audio_stream_num = 0;
730
            rm->audio_pkt_cnt = ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - 1;
731
            // Release first audio packet
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);
743
            }
744
            pkt->size = len;
745
        }
746
        rm_ac3_swap_bytes(st, pkt);
723
                timestamp = AV_NOPTS_VALUE;
724
                len = !ast->audio_framesize ? RAW_PACKET_SIZE :
725
                    ast->coded_framesize * ast->sub_packet_h / 2;
726
                flags = (seq++ == 1) ? 2 : 0;
747 727
    } else {
748
        int seq=1;
749
resync:
750 728
        len=sync(s, &timestamp, &flags, &i, &pos);
751
        if(len<0)
752
            return AVERROR(EIO);
753 729
        st = s->streams[i];
730
            }
731

  
732
            if(len<0 || url_feof(s->pb))
733
                return AVERROR(EIO);
754 734

  
755 735
        old_flags = flags;
756 736
        res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
757 737
                                  &seq, &flags, &timestamp);
758 738
        if((old_flags&2) && (seq&0x7F) == 1)
759 739
            av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
760
        if (res < 0)
761
            goto resync;
740
            if (res)
741
                continue;
742
        }
762 743

  
763 744
        if(  (st->discard >= AVDISCARD_NONKEY && !(flags&2))
764 745
           || st->discard >= AVDISCARD_ALL){
765 746
            av_free_packet(pkt);
766
            while (rm->audio_pkt_cnt > 0) {
767
                ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
768
                av_free_packet(pkt);
769
            }
770
            goto resync;
771
        }
747
        } else
748
            break;
772 749
    }
773 750

  
774 751
    return 0;

Also available in: Unified diff