Revision e63a3628 libavformat/asfdec.c

View differences:

libavformat/asfdec.c
135 135
void ff_get_guid(AVIOContext *s, ff_asf_guid *g)
136 136
{
137 137
    assert(sizeof(*g) == 16);
138
    get_buffer(s, *g, sizeof(*g));
138
    avio_read(s, *g, sizeof(*g));
139 139
}
140 140

  
141 141
static int asf_probe(AVProbeData *pd)
......
149 149

  
150 150
static int get_value(AVIOContext *pb, int type){
151 151
    switch(type){
152
        case 2: return get_le32(pb);
153
        case 3: return get_le32(pb);
154
        case 4: return get_le64(pb);
155
        case 5: return get_le16(pb);
152
        case 2: return avio_rl32(pb);
153
        case 3: return avio_rl32(pb);
154
        case 4: return avio_rl64(pb);
155
        case 5: return avio_rl16(pb);
156 156
        default:return INT_MIN;
157 157
    }
158 158
}
......
190 190
    AVIOContext *pb = s->pb;
191 191

  
192 192
    ff_get_guid(pb, &asf->hdr.guid);
193
    asf->hdr.file_size          = get_le64(pb);
194
    asf->hdr.create_time        = get_le64(pb);
195
    get_le64(pb);                               /* number of packets */
196
    asf->hdr.play_time          = get_le64(pb);
197
    asf->hdr.send_time          = get_le64(pb);
198
    asf->hdr.preroll            = get_le32(pb);
199
    asf->hdr.ignore             = get_le32(pb);
200
    asf->hdr.flags              = get_le32(pb);
201
    asf->hdr.min_pktsize        = get_le32(pb);
202
    asf->hdr.max_pktsize        = get_le32(pb);
203
    asf->hdr.max_bitrate        = get_le32(pb);
193
    asf->hdr.file_size          = avio_rl64(pb);
194
    asf->hdr.create_time        = avio_rl64(pb);
195
    avio_rl64(pb);                               /* number of packets */
196
    asf->hdr.play_time          = avio_rl64(pb);
197
    asf->hdr.send_time          = avio_rl64(pb);
198
    asf->hdr.preroll            = avio_rl32(pb);
199
    asf->hdr.ignore             = avio_rl32(pb);
200
    asf->hdr.flags              = avio_rl32(pb);
201
    asf->hdr.min_pktsize        = avio_rl32(pb);
202
    asf->hdr.max_pktsize        = avio_rl32(pb);
203
    asf->hdr.max_bitrate        = avio_rl32(pb);
204 204
    s->packet_size = asf->hdr.max_pktsize;
205 205

  
206 206
    return 0;
......
262 262
        return -1;
263 263
    }
264 264
    ff_get_guid(pb, &g);
265
    total_size = get_le64(pb);
266
    type_specific_size = get_le32(pb);
267
    get_le32(pb);
268
    st->id = get_le16(pb) & 0x7f; /* stream id */
265
    total_size = avio_rl64(pb);
266
    type_specific_size = avio_rl32(pb);
267
    avio_rl32(pb);
268
    st->id = avio_rl16(pb) & 0x7f; /* stream id */
269 269
    // mapping of asf ID to AV stream ID;
270 270
    asf->asfid2avid[st->id] = s->nb_streams - 1;
271 271

  
272
    get_le32(pb);
272
    avio_rl32(pb);
273 273

  
274 274
    if (test_for_ext_stream_audio) {
275 275
        ff_get_guid(pb, &g);
......
277 277
            type = AVMEDIA_TYPE_AUDIO;
278 278
            is_dvr_ms_audio=1;
279 279
            ff_get_guid(pb, &g);
280
            get_le32(pb);
281
            get_le32(pb);
282
            get_le32(pb);
280
            avio_rl32(pb);
281
            avio_rl32(pb);
282
            avio_rl32(pb);
283 283
            ff_get_guid(pb, &g);
284
            get_le32(pb);
284
            avio_rl32(pb);
285 285
        }
286 286
    }
287 287

  
......
302 302
        /* We have to init the frame size at some point .... */
303 303
        pos2 = url_ftell(pb);
304 304
        if (size >= (pos2 + 8 - pos1 + 24)) {
305
            asf_st->ds_span = get_byte(pb);
306
            asf_st->ds_packet_size = get_le16(pb);
307
            asf_st->ds_chunk_size = get_le16(pb);
308
            get_le16(pb); //ds_data_size
309
            get_byte(pb); //ds_silence_data
305
            asf_st->ds_span = avio_r8(pb);
306
            asf_st->ds_packet_size = avio_rl16(pb);
307
            asf_st->ds_chunk_size = avio_rl16(pb);
308
            avio_rl16(pb); //ds_data_size
309
            avio_r8(pb);   //ds_silence_data
310 310
        }
311 311
        //printf("Descrambling: ps:%d cs:%d ds:%d s:%d  sd:%d\n",
312 312
        //       asf_st->ds_packet_size, asf_st->ds_chunk_size,
......
338 338
        }
339 339
    } else if (type == AVMEDIA_TYPE_VIDEO &&
340 340
            size - (url_ftell(pb) - pos1 + 24) >= 51) {
341
        get_le32(pb);
342
        get_le32(pb);
343
        get_byte(pb);
344
        get_le16(pb);        /* size */
345
        sizeX= get_le32(pb); /* size */
346
        st->codec->width = get_le32(pb);
347
        st->codec->height = get_le32(pb);
341
        avio_rl32(pb);
342
        avio_rl32(pb);
343
        avio_r8(pb);
344
        avio_rl16(pb);        /* size */
345
        sizeX= avio_rl32(pb); /* size */
346
        st->codec->width = avio_rl32(pb);
347
        st->codec->height = avio_rl32(pb);
348 348
        /* not available for asf */
349
        get_le16(pb); /* panes */
350
        st->codec->bits_per_coded_sample = get_le16(pb); /* depth */
351
        tag1 = get_le32(pb);
349
        avio_rl16(pb); /* panes */
350
        st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */
351
        tag1 = avio_rl32(pb);
352 352
        url_fskip(pb, 20);
353 353
        //                av_log(s, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX);
354 354
        if (sizeX > 40) {
355 355
            st->codec->extradata_size = sizeX - 40;
356 356
            st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
357
            get_buffer(pb, st->codec->extradata, st->codec->extradata_size);
357
            avio_read(pb, st->codec->extradata, st->codec->extradata_size);
358 358
        }
359 359

  
360 360
        /* Extract palette from extradata if bpp <= 8 */
......
401 401
    uint32_t ext_d, leak_rate, stream_num;
402 402
    unsigned int stream_languageid_index;
403 403

  
404
    get_le64(pb); // starttime
405
    get_le64(pb); // endtime
406
    leak_rate = get_le32(pb); // leak-datarate
407
    get_le32(pb); // bucket-datasize
408
    get_le32(pb); // init-bucket-fullness
409
    get_le32(pb); // alt-leak-datarate
410
    get_le32(pb); // alt-bucket-datasize
411
    get_le32(pb); // alt-init-bucket-fullness
412
    get_le32(pb); // max-object-size
413
    get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
414
    stream_num = get_le16(pb); // stream-num
415

  
416
    stream_languageid_index = get_le16(pb); // stream-language-id-index
404
    avio_rl64(pb); // starttime
405
    avio_rl64(pb); // endtime
406
    leak_rate = avio_rl32(pb); // leak-datarate
407
    avio_rl32(pb); // bucket-datasize
408
    avio_rl32(pb); // init-bucket-fullness
409
    avio_rl32(pb); // alt-leak-datarate
410
    avio_rl32(pb); // alt-bucket-datasize
411
    avio_rl32(pb); // alt-init-bucket-fullness
412
    avio_rl32(pb); // max-object-size
413
    avio_rl32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved)
414
    stream_num = avio_rl16(pb); // stream-num
415

  
416
    stream_languageid_index = avio_rl16(pb); // stream-language-id-index
417 417
    if (stream_num < 128)
418 418
        asf->streams[stream_num].stream_language_index = stream_languageid_index;
419 419

  
420
    get_le64(pb); // avg frametime in 100ns units
421
    stream_ct = get_le16(pb); //stream-name-count
422
    payload_ext_ct = get_le16(pb); //payload-extension-system-count
420
    avio_rl64(pb); // avg frametime in 100ns units
421
    stream_ct = avio_rl16(pb); //stream-name-count
422
    payload_ext_ct = avio_rl16(pb); //payload-extension-system-count
423 423

  
424 424
    if (stream_num < 128)
425 425
        asf->stream_bitrates[stream_num] = leak_rate;
426 426

  
427 427
    for (i=0; i<stream_ct; i++){
428
        get_le16(pb);
429
        ext_len = get_le16(pb);
428
        avio_rl16(pb);
429
        ext_len = avio_rl16(pb);
430 430
        url_fseek(pb, ext_len, SEEK_CUR);
431 431
    }
432 432

  
433 433
    for (i=0; i<payload_ext_ct; i++){
434 434
        ff_get_guid(pb, &g);
435
        ext_d=get_le16(pb);
436
        ext_len=get_le32(pb);
435
        ext_d=avio_rl16(pb);
436
        ext_len=avio_rl32(pb);
437 437
        url_fseek(pb, ext_len, SEEK_CUR);
438 438
    }
439 439

  
......
445 445
    AVIOContext *pb = s->pb;
446 446
    int len1, len2, len3, len4, len5;
447 447

  
448
    len1 = get_le16(pb);
449
    len2 = get_le16(pb);
450
    len3 = get_le16(pb);
451
    len4 = get_le16(pb);
452
    len5 = get_le16(pb);
448
    len1 = avio_rl16(pb);
449
    len2 = avio_rl16(pb);
450
    len3 = avio_rl16(pb);
451
    len4 = avio_rl16(pb);
452
    len5 = avio_rl16(pb);
453 453
    get_tag(s, "title"    , 0, len1);
454 454
    get_tag(s, "author"   , 0, len2);
455 455
    get_tag(s, "copyright", 0, len3);
......
465 465
    ASFContext *asf = s->priv_data;
466 466
    int desc_count, i, ret;
467 467

  
468
    desc_count = get_le16(pb);
468
    desc_count = avio_rl16(pb);
469 469
    for(i=0;i<desc_count;i++) {
470 470
        int name_len,value_type,value_len;
471 471
        char name[1024];
472 472

  
473
        name_len = get_le16(pb);
473
        name_len = avio_rl16(pb);
474 474
        if (name_len%2)     // must be even, broken lavf versions wrote len-1
475 475
            name_len += 1;
476 476
        if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
477 477
            url_fskip(pb, name_len - ret);
478
        value_type = get_le16(pb);
479
        value_len  = get_le16(pb);
478
        value_type = avio_rl16(pb);
479
        value_len  = avio_rl16(pb);
480 480
        if (!value_type && value_len%2)
481 481
            value_len += 1;
482 482
        /**
......
499 499
    AVIOContext *pb = s->pb;
500 500
    ASFContext *asf = s->priv_data;
501 501
    int j, ret;
502
    int stream_count = get_le16(pb);
502
    int stream_count = avio_rl16(pb);
503 503
    for(j = 0; j < stream_count; j++) {
504 504
        char lang[6];
505
        unsigned int lang_len = get_byte(pb);
505
        unsigned int lang_len = avio_r8(pb);
506 506
        if ((ret = avio_get_str16le(pb, lang_len, lang, sizeof(lang))) < lang_len)
507 507
            url_fskip(pb, lang_len - ret);
508 508
        if (j < 128)
......
518 518
    ASFContext *asf = s->priv_data;
519 519
    int n, stream_num, name_len, value_len, value_type, value_num;
520 520
    int ret, i;
521
    n = get_le16(pb);
521
    n = avio_rl16(pb);
522 522

  
523 523
    for(i=0;i<n;i++) {
524 524
        char name[1024];
525 525

  
526
        get_le16(pb); //lang_list_index
527
        stream_num= get_le16(pb);
528
        name_len=   get_le16(pb);
529
        value_type= get_le16(pb);
530
        value_len=  get_le32(pb);
526
        avio_rl16(pb); //lang_list_index
527
        stream_num= avio_rl16(pb);
528
        name_len=   avio_rl16(pb);
529
        value_type= avio_rl16(pb);
530
        value_len=  avio_rl32(pb);
531 531

  
532 532
        if ((ret = avio_get_str16le(pb, name_len, name, sizeof(name))) < name_len)
533 533
            url_fskip(pb, name_len - ret);
534 534
        //av_log(s, AV_LOG_ERROR, "%d %d %d %d %d <%s>\n", i, stream_num, name_len, value_type, value_len, name);
535
        value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
535
        value_num= avio_rl16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere
536 536
        url_fskip(pb, value_len - 2);
537 537

  
538 538
        if(stream_num<128){
......
550 550
    int i, count, name_len, ret;
551 551
    char name[1024];
552 552

  
553
    get_le64(pb);            // reserved 16 bytes
554
    get_le64(pb);            // ...
555
    count = get_le32(pb);    // markers count
556
    get_le16(pb);            // reserved 2 bytes
557
    name_len = get_le16(pb); // name length
553
    avio_rl64(pb);            // reserved 16 bytes
554
    avio_rl64(pb);            // ...
555
    count = avio_rl32(pb);    // markers count
556
    avio_rl16(pb);            // reserved 2 bytes
557
    name_len = avio_rl16(pb); // name length
558 558
    for(i=0;i<name_len;i++){
559
        get_byte(pb); // skip the name
559
        avio_r8(pb); // skip the name
560 560
    }
561 561

  
562 562
    for(i=0;i<count;i++){
563 563
        int64_t pres_time;
564 564
        int name_len;
565 565

  
566
        get_le64(pb);             // offset, 8 bytes
567
        pres_time = get_le64(pb); // presentation time
568
        get_le16(pb);             // entry length
569
        get_le32(pb);             // send time
570
        get_le32(pb);             // flags
571
        name_len = get_le32(pb);  // name length
566
        avio_rl64(pb);             // offset, 8 bytes
567
        pres_time = avio_rl64(pb); // presentation time
568
        avio_rl16(pb);             // entry length
569
        avio_rl32(pb);             // send time
570
        avio_rl32(pb);             // flags
571
        name_len = avio_rl32(pb);  // name length
572 572
        if ((ret = avio_get_str16le(pb, name_len * 2, name, sizeof(name))) < name_len)
573 573
            url_fskip(pb, name_len - ret);
574 574
        ff_new_chapter(s, i, (AVRational){1, 10000000}, pres_time, AV_NOPTS_VALUE, name );
......
588 588
    ff_get_guid(pb, &g);
589 589
    if (ff_guidcmp(&g, &ff_asf_header))
590 590
        return -1;
591
    get_le64(pb);
592
    get_le32(pb);
593
    get_byte(pb);
594
    get_byte(pb);
591
    avio_rl64(pb);
592
    avio_rl32(pb);
593
    avio_r8(pb);
594
    avio_r8(pb);
595 595
    memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid));
596 596
    for(;;) {
597 597
        uint64_t gpos= url_ftell(pb);
598 598
        ff_get_guid(pb, &g);
599
        gsize = get_le64(pb);
599
        gsize = avio_rl64(pb);
600 600
        av_dlog(s, "%08"PRIx64": ", gpos);
601 601
        print_guid(&g);
602 602
        av_dlog(s, "  size=0x%"PRIx64"\n", gsize);
......
633 633
        } else if (!ff_guidcmp(&g, &ff_asf_head1_guid)) {
634 634
            int v1, v2;
635 635
            ff_get_guid(pb, &g);
636
            v1 = get_le32(pb);
637
            v2 = get_le16(pb);
636
            v1 = avio_rl32(pb);
637
            v2 = avio_rl16(pb);
638 638
            continue;
639 639
        } else if (!ff_guidcmp(&g, &ff_asf_marker_header)) {
640 640
            asf_read_marker(s, gsize);
......
656 656
        url_fseek(pb, gpos + gsize, SEEK_SET);
657 657
    }
658 658
    ff_get_guid(pb, &g);
659
    get_le64(pb);
660
    get_byte(pb);
661
    get_byte(pb);
659
    avio_rl64(pb);
660
    avio_r8(pb);
661
    avio_r8(pb);
662 662
    if (url_feof(pb))
663 663
        return -1;
664 664
    asf->data_offset = url_ftell(pb);
......
703 703
#define DO_2BITS(bits, var, defval) \
704 704
    switch (bits & 3) \
705 705
    { \
706
    case 3: var = get_le32(pb); rsize += 4; break; \
707
    case 2: var = get_le16(pb); rsize += 2; break; \
708
    case 1: var = get_byte(pb); rsize++; break; \
706
    case 3: var = avio_rl32(pb); rsize += 4; break; \
707
    case 2: var = avio_rl16(pb); rsize += 2; break; \
708
    case 1: var = avio_r8(pb);   rsize++; break; \
709 709
    default: var = defval; break; \
710 710
    }
711 711

  
......
730 730
    c=d=e=-1;
731 731
    while(off-- > 0){
732 732
        c=d; d=e;
733
        e= get_byte(pb);
733
        e= avio_r8(pb);
734 734
        if(c == 0x82 && !d && !e)
735 735
            break;
736 736
    }
......
753 753
                av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
754 754
            return -1;
755 755
        }
756
        c= get_byte(pb);
757
        d= get_byte(pb);
756
        c= avio_r8(pb);
757
        d= avio_r8(pb);
758 758
        rsize+=3;
759 759
    }else{
760 760
        url_fseek(pb, -1, SEEK_CUR); //FIXME
......
777 777
        return -1;
778 778
    }
779 779

  
780
    asf->packet_timestamp = get_le32(pb);
781
    get_le16(pb); /* duration */
780
    asf->packet_timestamp = avio_rl32(pb);
781
    avio_rl16(pb); /* duration */
782 782
    // rsize has at least 11 bytes which have to be present
783 783

  
784 784
    if (asf->packet_flags & 0x01) {
785
        asf->packet_segsizetype = get_byte(pb); rsize++;
785
        asf->packet_segsizetype = avio_r8(pb); rsize++;
786 786
        asf->packet_segments = asf->packet_segsizetype & 0x3f;
787 787
    } else {
788 788
        asf->packet_segments = 1;
......
803 803
static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){
804 804
    ASFContext *asf = s->priv_data;
805 805
    int rsize = 1;
806
    int num = get_byte(pb);
806
    int num = avio_r8(pb);
807 807
    int64_t ts0, ts1;
808 808

  
809 809
    asf->packet_segments--;
......
815 815
    DO_2BITS(asf->packet_property, asf->packet_replic_size, 0);
816 816
//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);
817 817
    if (asf->packet_replic_size >= 8) {
818
        asf->packet_obj_size = get_le32(pb);
818
        asf->packet_obj_size = avio_rl32(pb);
819 819
        if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){
820 820
            av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n");
821 821
            return -1;
822 822
        }
823
        asf->packet_frag_timestamp = get_le32(pb); // timestamp
823
        asf->packet_frag_timestamp = avio_rl32(pb); // timestamp
824 824
        if(asf->packet_replic_size >= 8+38+4){
825 825
//            for(i=0; i<asf->packet_replic_size-8; i++)
826
//                av_log(s, AV_LOG_DEBUG, "%02X ",get_byte(pb));
826
//                av_log(s, AV_LOG_DEBUG, "%02X ",avio_r8(pb));
827 827
//            av_log(s, AV_LOG_DEBUG, "\n");
828 828
            url_fskip(pb, 10);
829
            ts0= get_le64(pb);
830
            ts1= get_le64(pb);
829
            ts0= avio_rl64(pb);
830
            ts1= avio_rl64(pb);
831 831
            url_fskip(pb, 12);
832
            get_le32(pb);
832
            avio_rl32(pb);
833 833
            url_fskip(pb, asf->packet_replic_size - 8 - 38 - 4);
834 834
            if(ts0!= -1) asf->packet_frag_timestamp= ts0/10000;
835 835
            else         asf->packet_frag_timestamp= AV_NOPTS_VALUE;
......
842 842
        asf->packet_frag_offset = 0;
843 843
        asf->packet_frag_timestamp = asf->packet_timestamp;
844 844

  
845
        asf->packet_time_delta = get_byte(pb);
845
        asf->packet_time_delta = avio_r8(pb);
846 846
        rsize++;
847 847
    }else if(asf->packet_replic_size!=0){
848 848
        av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size);
......
927 927
            // frag_offset is here used as the beginning timestamp
928 928
            asf->packet_frag_timestamp = asf->packet_time_start;
929 929
            asf->packet_time_start += asf->packet_time_delta;
930
            asf->packet_obj_size = asf->packet_frag_size = get_byte(pb);
930
            asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
931 931
            asf->packet_size_left--;
932 932
            asf->packet_multi_size--;
933 933
            if (asf->packet_multi_size < asf->packet_obj_size)
......
987 987
            continue;
988 988
        }
989 989

  
990
        ret = get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset,
990
        ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
991 991
                         asf->packet_frag_size);
992 992
        if (ret != asf->packet_frag_size) {
993 993
            if (ret < 0 || asf->packet_frag_offset + ret == 0)
......
1193 1193
    /* the data object can be followed by other top-level objects,
1194 1194
       skip them until the simple index object is reached */
1195 1195
    while (ff_guidcmp(&g, &index_guid)) {
1196
        int64_t gsize= get_le64(s->pb);
1196
        int64_t gsize= avio_rl64(s->pb);
1197 1197
        if (gsize < 24 || url_feof(s->pb)) {
1198 1198
            url_fseek(s->pb, current_pos, SEEK_SET);
1199 1199
            return;
......
1205 1205
    {
1206 1206
        int64_t itime, last_pos=-1;
1207 1207
        int pct, ict;
1208
        int64_t av_unused gsize= get_le64(s->pb);
1208
        int64_t av_unused gsize= avio_rl64(s->pb);
1209 1209
        ff_get_guid(s->pb, &g);
1210
        itime=get_le64(s->pb);
1211
        pct=get_le32(s->pb);
1212
        ict=get_le32(s->pb);
1210
        itime=avio_rl64(s->pb);
1211
        pct=avio_rl32(s->pb);
1212
        ict=avio_rl32(s->pb);
1213 1213
        av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict);
1214 1214

  
1215 1215
        for (i=0;i<ict;i++){
1216
            int pktnum=get_le32(s->pb);
1217
            int pktct =get_le16(s->pb);
1216
            int pktnum=avio_rl32(s->pb);
1217
            int pktct =avio_rl16(s->pb);
1218 1218
            int64_t pos      = s->data_offset + s->packet_size*(int64_t)pktnum;
1219 1219
            int64_t index_pts= av_rescale(itime, i, 10000);
1220 1220

  

Also available in: Unified diff