Revision b7effd4e 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
}
......
191 191
    AVIOContext *pb = s->pb;
192 192

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

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

  
273
    get_le32(pb);
273
    avio_rl32(pb);
274 274

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  

Also available in: Unified diff