Revision ae60a857 libavformat/asf.c

View differences:

libavformat/asf.c
530 530
    return 0;
531 531
}
532 532

  
533
/**
534
 *
535
 * @return <0 if error
536
 */
537
static int asf_read_frame_header(AVFormatContext *s){
538
    ASFContext *asf = s->priv_data;
539
    ByteIOContext *pb = &s->pb;
540
    int rsize = 1;
541
    int num = get_byte(pb);
542

  
543
    asf->packet_segments--;
544
    asf->packet_key_frame = num >> 7;
545
    asf->stream_index = asf->asfid2avid[num & 0x7f];
546
    // sequence should be ignored!
547
    DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
548
    DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
549
    DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
550
//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
551
    if (asf->packet_replic_size >= 8) {
552
        asf->packet_obj_size = get_le32(pb);
553
        if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
554
            av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
555
            return -1;
556
        }
557
        asf->packet_frag_timestamp = get_le32(pb); // timestamp
558
        url_fskip(pb, asf->packet_replic_size - 8);
559
        rsize += asf->packet_replic_size; // FIXME - check validity
560
    } else if (asf->packet_replic_size==1){
561
        // multipacket - frag_offset is begining timestamp
562
        asf->packet_time_start = asf->packet_frag_offset;
563
        asf->packet_frag_offset = 0;
564
        asf->packet_frag_timestamp = asf->packet_timestamp;
565

  
566
        asf->packet_time_delta = get_byte(pb);
567
        rsize++;
568
    }else if(asf->packet_replic_size!=0){
569
        av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
570
        return -1;
571
    }
572
    if (asf->packet_flags & 0x01) {
573
        DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
574
        //printf("Fragsize %d\n", asf->packet_frag_size);
575
    } else {
576
        asf->packet_frag_size = asf->packet_size_left - rsize;
577
        //printf("Using rest  %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
578
    }
579
    if (asf->packet_replic_size == 1) {
580
        asf->packet_multi_size = asf->packet_frag_size;
581
        if (asf->packet_multi_size > asf->packet_size_left)
582
            return -1;
583
    }
584
    asf->packet_size_left -= rsize;
585
    //printf("___objsize____  %d   %d    rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
586

  
587
    return 0;
588
}
589

  
533 590
static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
534 591
{
535 592
    ASFContext *asf = s->priv_data;
......
537 594
    ByteIOContext *pb = &s->pb;
538 595
    //static int pc = 0;
539 596
    for (;;) {
540
        int rsize = 0;
541 597
        if (asf->packet_size_left < FRAME_HEADER_SIZE
542 598
            || asf->packet_segments < 1) {
543 599
            //asf->packet_size_left <= asf->packet_padsize) {
......
565 621
            continue;
566 622
        }
567 623
        if (asf->packet_time_start == 0) {
568
            /* read frame header */
569
            int num = get_byte(pb);
570
            asf->packet_segments--;
571
            rsize++;
572
            asf->packet_key_frame = num >> 7;
573
            asf->stream_index = asf->asfid2avid[num & 0x7f];
574
            // sequence should be ignored!
575
            DO_2BITS(asf->packet_property >> 4, asf->packet_seq, 0);
576
            DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0);
577
            DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
578
//printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size);
579
            if (asf->packet_replic_size >= 8) {
580
                asf->packet_obj_size = get_le32(pb);
581
                if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
582
                    av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
583
                    continue;
584
                }
585
                asf->packet_frag_timestamp = get_le32(pb); // timestamp
586
                url_fskip(pb, asf->packet_replic_size - 8);
587
                rsize += asf->packet_replic_size; // FIXME - check validity
588
            } else if (asf->packet_replic_size==1){
589
                // multipacket - frag_offset is begining timestamp
590
                asf->packet_time_start = asf->packet_frag_offset;
591
                asf->packet_frag_offset = 0;
592
                asf->packet_frag_timestamp = asf->packet_timestamp;
593

  
594
                asf->packet_time_delta = get_byte(pb);
595
                rsize++;
596
            }else if(asf->packet_replic_size!=0){
597
                av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
624
            if(asf_read_frame_header(s) < 0){
625
                asf->packet_segments= 0;
598 626
                continue;
599 627
            }
600
            if (asf->packet_flags & 0x01) {
601
                DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal
602
#undef DO_2BITS
603
                //printf("Fragsize %d\n", asf->packet_frag_size);
604
            } else {
605
                asf->packet_frag_size = asf->packet_size_left - rsize;
606
                //printf("Using rest  %d %d %d\n", asf->packet_frag_size, asf->packet_size_left, rsize);
607
            }
608
            if (asf->packet_replic_size == 1) {
609
                asf->packet_multi_size = asf->packet_frag_size;
610
                if (asf->packet_multi_size > asf->packet_size_left) {
611
                    asf->packet_segments = 0;
612
                    continue;
613
                }
614
            }
615
            asf->packet_size_left -= rsize;
616
            //printf("___objsize____  %d   %d    rs:%d\n", asf->packet_obj_size, asf->packet_frag_offset, rsize);
617

  
618 628
            if (asf->stream_index < 0
619 629
                || s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
620 630
                || (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
......
624 634
                url_fskip(pb, asf->packet_frag_size);
625 635
                asf->packet_size_left -= asf->packet_frag_size;
626 636
                if(asf->stream_index < 0)
627
                    av_log(s, AV_LOG_ERROR, "ff asf skip %d  %d\n", asf->packet_frag_size, num & 0x7f);
637
                    av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
628 638
                continue;
629 639
            }
630 640
            asf->asf_st = s->streams[asf->stream_index]->priv_data;

Also available in: Unified diff