Revision c6f05d81 libavformat/swf.c

View differences:

libavformat/swf.c
652 652
    get_le16(pb); /* frame count */
653 653

  
654 654
    swf->samples_per_frame = 0;
655
    s->ctx_flags |= AVFMTCTX_NOHEADER;
656
    return 0;
657
}
658

  
659
static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
660
{
661
    SWFContext *swf = s->priv_data;
662
    ByteIOContext *pb = &s->pb;
663
    AVStream *vst = NULL, *ast = NULL, *st = 0;
664
    int tag, len, i, frame, v;
655 665

  
656 666
    for(;;) {
657
        offset_t tag_offset = url_ftell(pb);
658 667
        tag = get_swf_tag(pb, &len);
659
        if (tag < 0 || tag == TAG_VIDEOFRAME || tag == TAG_STREAMBLOCK) {
660
            url_fseek(pb, frame_offset == -1 ? tag_offset : frame_offset, SEEK_SET);
661
            break;
662
        }
668
        if (tag < 0)
669
            return AVERROR(EIO);
663 670
        if ( tag == TAG_VIDEOSTREAM && !vst) {
664 671
            int ch_id = get_le16(pb);
665 672
            get_le16(pb);
......
670 677
            vst = av_new_stream(s, ch_id);
671 678
            vst->codec->codec_type = CODEC_TYPE_VIDEO;
672 679
            vst->codec->codec_id = codec_get_id(swf_codec_tags, get_byte(pb));
680
            av_set_pts_info(vst, 64, 256, swf->frame_rate);
681
            vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
682
            len -= 10;
673 683
        } else if ( ( tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2 ) && !ast) {
674 684
            /* streaming found */
675 685
            int sample_rate_code;
......
687 697
                return AVERROR(EIO);
688 698
            ast->codec->sample_rate = 11025 << (sample_rate_code-1);
689 699
            av_set_pts_info(ast, 64, 1, ast->codec->sample_rate);
690
            if (len > 4)
691
                url_fskip(pb,len-4);
692

  
693
        } else if (tag == TAG_JPEG2 && !vst) {
694
            vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
695
            vst->codec->codec_type = CODEC_TYPE_VIDEO;
696
            vst->codec->codec_id = CODEC_ID_MJPEG;
697
            url_fskip(pb, len);
698
            frame_offset = tag_offset;
699
        } else {
700
            url_fskip(pb, len);
701
        }
702
    }
703
    if (vst)
704
        av_set_pts_info(vst, 64, 256, swf->frame_rate);
705
    return 0;
706
}
707

  
708
static int swf_read_packet(AVFormatContext *s, AVPacket *pkt)
709
{
710
    SWFContext *swf = s->priv_data;
711
    ByteIOContext *pb = &s->pb;
712
    AVStream *st = 0;
713
    int tag, len, i, frame;
714

  
715
    for(;;) {
716
        tag = get_swf_tag(pb, &len);
717
        if (tag < 0)
718
            return AVERROR(EIO);
700
            len -= 4;
701
        } else
719 702
        if (tag == TAG_VIDEOFRAME) {
720 703
            int ch_id = get_le16(pb);
721 704
            len -= 2;
......
742 725
        } else if (tag == TAG_JPEG2) {
743 726
            for (i=0; i<s->nb_streams; i++) {
744 727
                st = s->streams[i];
745
                if (st->id == -2) {
728
                if (st->id == -2)
729
                    break;
730
            }
731
            if (i == s->nb_streams) {
732
                vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */
733
                vst->codec->codec_type = CODEC_TYPE_VIDEO;
734
                vst->codec->codec_id = CODEC_ID_MJPEG;
735
                av_set_pts_info(vst, 64, 256, swf->frame_rate);
736
                vst->codec->time_base = (AVRational){ 256, swf->frame_rate };
737
                st = vst;
738
            }
746 739
                    get_le16(pb); /* BITMAP_ID */
747 740
                    av_new_packet(pkt, len-2);
748 741
                    get_buffer(pb, pkt->data, 4);
......
755 748
                    }
756 749
                    pkt->stream_index = st->index;
757 750
                    return pkt->size;
758
                }
759
            }
760 751
        }
761 752
        url_fskip(pb, len);
762 753
    }

Also available in: Unified diff