Revision e63a3628 libavformat/mov.c

View differences:

libavformat/mov.c
83 83
{
84 84
    char buf[16];
85 85

  
86
    get_be16(pb); // unknown
87
    snprintf(buf, sizeof(buf), "%d", get_be16(pb));
86
    avio_rb16(pb); // unknown
87
    snprintf(buf, sizeof(buf), "%d", avio_rb16(pb));
88 88
    av_metadata_set2(&c->fc->metadata, "track", buf, 0);
89 89

  
90
    get_be16(pb); // total tracks
90
    avio_rb16(pb); // total tracks
91 91

  
92 92
    return 0;
93 93
}
......
119 119
    int i;
120 120

  
121 121
    for (i = 0; i < len; i++) {
122
        uint8_t t, c = get_byte(pb);
122
        uint8_t t, c = avio_r8(pb);
123 123
        if (c < 0x80 && p < end)
124 124
            *p++ = c;
125 125
        else
......
165 165
    }
166 166

  
167 167
    if (c->itunes_metadata && atom.size > 8) {
168
        int data_size = get_be32(pb);
169
        int tag = get_le32(pb);
168
        int data_size = avio_rb32(pb);
169
        int tag = avio_rl32(pb);
170 170
        if (tag == MKTAG('d','a','t','a')) {
171
            data_type = get_be32(pb); // type
172
            get_be32(pb); // unknown
171
            data_type = avio_rb32(pb); // type
172
            avio_rb32(pb); // unknown
173 173
            str_size = data_size - 16;
174 174
            atom.size -= 16;
175 175
        } else return 0;
176 176
    } else if (atom.size > 4 && key && !c->itunes_metadata) {
177
        str_size = get_be16(pb); // string length
178
        langcode = get_be16(pb);
177
        str_size = avio_rb16(pb); // string length
178
        langcode = avio_rb16(pb);
179 179
        ff_mov_lang_to_iso639(langcode, language);
180 180
        atom.size -= 4;
181 181
    } else
......
201 201
        if (data_type == 3 || (data_type == 0 && langcode < 0x800)) { // MAC Encoded
202 202
            mov_read_mac_string(c, pb, str_size, str, sizeof(str));
203 203
        } else {
204
            get_buffer(pb, str, str_size);
204
            avio_read(pb, str, str_size);
205 205
            str[str_size] = 0;
206 206
        }
207 207
        av_metadata_set2(&c->fc->metadata, key, str, 0);
......
228 228
    if ((atom.size -= 5) < 0)
229 229
        return 0;
230 230

  
231
    version = get_byte(pb);
232
    get_be24(pb);
231
    version = avio_r8(pb);
232
    avio_rb24(pb);
233 233
    if (version)
234
        get_be32(pb); // ???
235
    nb_chapters = get_byte(pb);
234
        avio_rb32(pb); // ???
235
    nb_chapters = avio_r8(pb);
236 236

  
237 237
    for (i = 0; i < nb_chapters; i++) {
238 238
        if (atom.size < 9)
239 239
            return 0;
240 240

  
241
        start = get_be64(pb);
242
        str_len = get_byte(pb);
241
        start = avio_rb64(pb);
242
        str_len = avio_r8(pb);
243 243

  
244 244
        if ((atom.size -= 9+str_len) < 0)
245 245
            return 0;
246 246

  
247
        get_buffer(pb, str, str_len);
247
        avio_read(pb, str, str_len);
248 248
        str[str_len] = 0;
249 249
        ff_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str);
250 250
    }
......
264 264
        a.size = atom.size;
265 265
        a.type=0;
266 266
        if(atom.size >= 8) {
267
            a.size = get_be32(pb);
268
            a.type = get_le32(pb);
267
            a.size = avio_rb32(pb);
268
            a.type = avio_rl32(pb);
269 269
        }
270 270
        av_dlog(c->fc, "type: %08x '%.4s' parent:'%.4s' sz: %"PRId64" %"PRId64" %"PRId64"\n",
271 271
                a.type, (char*)&a.type, (char*)&atom.type, a.size, total_size, atom.size);
272 272
        total_size += 8;
273 273
        if (a.size == 1) { /* 64 bit extended size */
274
            a.size = get_be64(pb) - 8;
274
            a.size = avio_rb64(pb) - 8;
275 275
            total_size += 8;
276 276
        }
277 277
        if (a.size == 0) {
......
331 331
    st = c->fc->streams[c->fc->nb_streams-1];
332 332
    sc = st->priv_data;
333 333

  
334
    get_be32(pb); // version + flags
335
    entries = get_be32(pb);
334
    avio_rb32(pb); // version + flags
335
    entries = avio_rb32(pb);
336 336
    if (entries >= UINT_MAX / sizeof(*sc->drefs))
337 337
        return -1;
338 338
    sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));
......
342 342

  
343 343
    for (i = 0; i < sc->drefs_count; i++) {
344 344
        MOVDref *dref = &sc->drefs[i];
345
        uint32_t size = get_be32(pb);
345
        uint32_t size = avio_rb32(pb);
346 346
        int64_t next = url_ftell(pb) + size - 4;
347 347

  
348 348
        if (size < 12)
349 349
            return -1;
350 350

  
351
        dref->type = get_le32(pb);
352
        get_be32(pb); // version + flags
351
        dref->type = avio_rl32(pb);
352
        avio_rb32(pb); // version + flags
353 353
        av_dlog(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);
354 354

  
355 355
        if (dref->type == MKTAG('a','l','i','s') && size > 150) {
......
359 359

  
360 360
            url_fskip(pb, 10);
361 361

  
362
            volume_len = get_byte(pb);
362
            volume_len = avio_r8(pb);
363 363
            volume_len = FFMIN(volume_len, 27);
364
            get_buffer(pb, dref->volume, 27);
364
            avio_read(pb, dref->volume, 27);
365 365
            dref->volume[volume_len] = 0;
366 366
            av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);
367 367

  
368 368
            url_fskip(pb, 12);
369 369

  
370
            len = get_byte(pb);
370
            len = avio_r8(pb);
371 371
            len = FFMIN(len, 63);
372
            get_buffer(pb, dref->filename, 63);
372
            avio_read(pb, dref->filename, 63);
373 373
            dref->filename[len] = 0;
374 374
            av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);
375 375

  
376 376
            url_fskip(pb, 16);
377 377

  
378 378
            /* read next level up_from_alias/down_to_target */
379
            dref->nlvl_from = get_be16(pb);
380
            dref->nlvl_to   = get_be16(pb);
379
            dref->nlvl_from = avio_rb16(pb);
380
            dref->nlvl_to   = avio_rb16(pb);
381 381
            av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",
382 382
                   dref->nlvl_from, dref->nlvl_to);
383 383

  
384 384
            url_fskip(pb, 16);
385 385

  
386 386
            for (type = 0; type != -1 && url_ftell(pb) < next; ) {
387
                type = get_be16(pb);
388
                len = get_be16(pb);
387
                type = avio_rb16(pb);
388
                len = avio_rb16(pb);
389 389
                av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);
390 390
                if (len&1)
391 391
                    len += 1;
......
394 394
                    dref->path = av_mallocz(len+1);
395 395
                    if (!dref->path)
396 396
                        return AVERROR(ENOMEM);
397
                    get_buffer(pb, dref->path, len);
397
                    avio_read(pb, dref->path, len);
398 398
                    if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) {
399 399
                        len -= volume_len;
400 400
                        memmove(dref->path, dref->path+volume_len, len);
......
409 409
                    dref->dir = av_malloc(len+1);
410 410
                    if (!dref->dir)
411 411
                        return AVERROR(ENOMEM);
412
                    get_buffer(pb, dref->dir, len);
412
                    avio_read(pb, dref->dir, len);
413 413
                    dref->dir[len] = 0;
414 414
                    for (j = 0; j < len; j++)
415 415
                        if (dref->dir[j] == ':')
......
435 435

  
436 436
    st = c->fc->streams[c->fc->nb_streams-1];
437 437

  
438
    get_byte(pb); /* version */
439
    get_be24(pb); /* flags */
438
    avio_r8(pb); /* version */
439
    avio_rb24(pb); /* flags */
440 440

  
441 441
    /* component type */
442
    ctype = get_le32(pb);
443
    type = get_le32(pb); /* component subtype */
442
    ctype = avio_rl32(pb);
443
    type = avio_rl32(pb); /* component subtype */
444 444

  
445 445
    av_dlog(c->fc, "ctype= %.4s (0x%08x)\n", (char*)&ctype, ctype);
446 446
    av_dlog(c->fc, "stype= %.4s\n", (char*)&type);
......
454 454
    else if(type == MKTAG('s','u','b','p'))
455 455
        st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
456 456

  
457
    get_be32(pb); /* component  manufacture */
458
    get_be32(pb); /* component flags */
459
    get_be32(pb); /* component flags mask */
457
    avio_rb32(pb); /* component  manufacture */
458
    avio_rb32(pb); /* component flags */
459
    avio_rb32(pb); /* component flags mask */
460 460

  
461 461
    return 0;
462 462
}
......
470 470
        return 0;
471 471
    st = fc->streams[fc->nb_streams-1];
472 472

  
473
    get_be32(pb); /* version + flags */
473
    avio_rb32(pb); /* version + flags */
474 474
    len = ff_mp4_read_descr(fc, pb, &tag);
475 475
    if (tag == MP4ESDescrTag) {
476
        get_be16(pb); /* ID */
477
        get_byte(pb); /* priority */
476
        avio_rb16(pb); /* ID */
477
        avio_r8(pb); /* priority */
478 478
    } else
479
        get_be16(pb); /* ID */
479
        avio_rb16(pb); /* ID */
480 480

  
481 481
    len = ff_mp4_read_descr(fc, pb, &tag);
482 482
    if (tag == MP4DecConfigDescrTag)
......
498 498
        return 0;
499 499
    st = c->fc->streams[c->fc->nb_streams-1];
500 500

  
501
    ac3info = get_be24(pb);
501
    ac3info = avio_rb24(pb);
502 502
    acmod = (ac3info >> 11) & 0x7;
503 503
    lfeon = (ac3info >> 10) & 0x1;
504 504
    st->codec->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon;
......
508 508

  
509 509
static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
510 510
{
511
    const int num = get_be32(pb);
512
    const int den = get_be32(pb);
511
    const int num = avio_rb32(pb);
512
    const int den = avio_rb32(pb);
513 513
    AVStream *st;
514 514

  
515 515
    if (c->fc->nb_streams < 1)
......
547 547
    char* comp_brands_str;
548 548
    uint8_t type[5] = {0};
549 549

  
550
    get_buffer(pb, type, 4);
550
    avio_read(pb, type, 4);
551 551
    if (strcmp(type, "qt  "))
552 552
        c->isom = 1;
553 553
    av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
554 554
    av_metadata_set2(&c->fc->metadata, "major_brand", type, 0);
555
    minor_ver = get_be32(pb); /* minor version */
555
    minor_ver = avio_rb32(pb); /* minor version */
556 556
    snprintf(minor_ver_str, sizeof(minor_ver_str), "%d", minor_ver);
557 557
    av_metadata_set2(&c->fc->metadata, "minor_version", minor_ver_str, 0);
558 558

  
......
562 562
    comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */
563 563
    if (!comp_brands_str)
564 564
        return AVERROR(ENOMEM);
565
    get_buffer(pb, comp_brands_str, comp_brand_size);
565
    avio_read(pb, comp_brands_str, comp_brand_size);
566 566
    comp_brands_str[comp_brand_size] = 0;
567 567
    av_metadata_set2(&c->fc->metadata, "compatible_brands", comp_brands_str, 0);
568 568
    av_freep(&comp_brands_str);
......
615 615
    st = c->fc->streams[c->fc->nb_streams-1];
616 616
    sc = st->priv_data;
617 617

  
618
    version = get_byte(pb);
618
    version = avio_r8(pb);
619 619
    if (version > 1)
620 620
        return -1; /* unsupported */
621 621

  
622
    get_be24(pb); /* flags */
622
    avio_rb24(pb); /* flags */
623 623
    if (version == 1) {
624
        creation_time = get_be64(pb);
625
        get_be64(pb);
624
        creation_time = avio_rb64(pb);
625
        avio_rb64(pb);
626 626
    } else {
627
        creation_time = get_be32(pb);
628
        get_be32(pb); /* modification time */
627
        creation_time = avio_rb32(pb);
628
        avio_rb32(pb); /* modification time */
629 629
    }
630 630
    mov_metadata_creation_time(&st->metadata, creation_time);
631 631

  
632
    sc->time_scale = get_be32(pb);
633
    st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
632
    sc->time_scale = avio_rb32(pb);
633
    st->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */
634 634

  
635
    lang = get_be16(pb); /* language */
635
    lang = avio_rb16(pb); /* language */
636 636
    if (ff_mov_lang_to_iso639(lang, language))
637 637
        av_metadata_set2(&st->metadata, "language", language, 0);
638
    get_be16(pb); /* quality */
638
    avio_rb16(pb); /* quality */
639 639

  
640 640
    return 0;
641 641
}
......
643 643
static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
644 644
{
645 645
    time_t creation_time;
646
    int version = get_byte(pb); /* version */
647
    get_be24(pb); /* flags */
646
    int version = avio_r8(pb); /* version */
647
    avio_rb24(pb); /* flags */
648 648

  
649 649
    if (version == 1) {
650
        creation_time = get_be64(pb);
651
        get_be64(pb);
650
        creation_time = avio_rb64(pb);
651
        avio_rb64(pb);
652 652
    } else {
653
        creation_time = get_be32(pb);
654
        get_be32(pb); /* modification time */
653
        creation_time = avio_rb32(pb);
654
        avio_rb32(pb); /* modification time */
655 655
    }
656 656
    mov_metadata_creation_time(&c->fc->metadata, creation_time);
657
    c->time_scale = get_be32(pb); /* time scale */
657
    c->time_scale = avio_rb32(pb); /* time scale */
658 658

  
659 659
    av_dlog(c->fc, "time scale = %i\n", c->time_scale);
660 660

  
661
    c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */
662
    get_be32(pb); /* preferred scale */
661
    c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */
662
    avio_rb32(pb); /* preferred scale */
663 663

  
664
    get_be16(pb); /* preferred volume */
664
    avio_rb16(pb); /* preferred volume */
665 665

  
666 666
    url_fskip(pb, 10); /* reserved */
667 667

  
668 668
    url_fskip(pb, 36); /* display matrix */
669 669

  
670
    get_be32(pb); /* preview time */
671
    get_be32(pb); /* preview duration */
672
    get_be32(pb); /* poster time */
673
    get_be32(pb); /* selection time */
674
    get_be32(pb); /* selection duration */
675
    get_be32(pb); /* current time */
676
    get_be32(pb); /* next track ID */
670
    avio_rb32(pb); /* preview time */
671
    avio_rb32(pb); /* preview duration */
672
    avio_rb32(pb); /* poster time */
673
    avio_rb32(pb); /* selection time */
674
    avio_rb32(pb); /* selection duration */
675
    avio_rb32(pb); /* current time */
676
    avio_rb32(pb); /* next track ID */
677 677

  
678 678
    return 0;
679 679
}
......
697 697
        return AVERROR(ENOMEM);
698 698
    st->codec->extradata_size = 0x5a + atom.size;
699 699
    memcpy(st->codec->extradata, "SVQ3", 4); // fake
700
    get_buffer(pb, st->codec->extradata + 0x5a, atom.size);
700
    avio_read(pb, st->codec->extradata + 0x5a, atom.size);
701 701
    av_dlog(c->fc, "Reading SMI %"PRId64"  %s\n", atom.size, st->codec->extradata + 0x5a);
702 702
    return 0;
703 703
}
......
711 711
        return 0;
712 712
    st = c->fc->streams[c->fc->nb_streams-1];
713 713

  
714
    little_endian = get_be16(pb);
714
    little_endian = avio_rb16(pb);
715 715
    av_dlog(c->fc, "enda %d\n", little_endian);
716 716
    if (little_endian == 1) {
717 717
        switch (st->codec->codec_id) {
......
755 755
    st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE;
756 756
    AV_WB32(       buf    , atom.size + 8);
757 757
    AV_WL32(       buf + 4, atom.type);
758
    get_buffer(pb, buf + 8, atom.size);
758
    avio_read(pb, buf + 8, atom.size);
759 759
    return 0;
760 760
}
761 761

  
......
777 777
        if (!st->codec->extradata)
778 778
            return AVERROR(ENOMEM);
779 779
        st->codec->extradata_size = atom.size;
780
        get_buffer(pb, st->codec->extradata, atom.size);
780
        avio_read(pb, st->codec->extradata, atom.size);
781 781
    } else if (atom.size > 8) { /* to read frma, esds atoms */
782 782
        if (mov_read_default(c, pb, atom) < 0)
783 783
            return -1;
......
806 806
    if (!st->codec->extradata)
807 807
        return AVERROR(ENOMEM);
808 808
    st->codec->extradata_size = atom.size;
809
    get_buffer(pb, st->codec->extradata, atom.size);
809
    avio_read(pb, st->codec->extradata, atom.size);
810 810
    return 0;
811 811
}
812 812

  
......
834 834
        return AVERROR(ENOMEM);
835 835
    st->codec->extradata_size = atom.size - 40;
836 836
    url_fskip(pb, 40);
837
    get_buffer(pb, st->codec->extradata, atom.size - 40);
837
    avio_read(pb, st->codec->extradata, atom.size - 40);
838 838
    return 0;
839 839
}
840 840

  
......
849 849
    st = c->fc->streams[c->fc->nb_streams-1];
850 850
    sc = st->priv_data;
851 851

  
852
    get_byte(pb); /* version */
853
    get_be24(pb); /* flags */
852
    avio_r8(pb); /* version */
853
    avio_rb24(pb); /* flags */
854 854

  
855
    entries = get_be32(pb);
855
    entries = avio_rb32(pb);
856 856

  
857 857
    if(entries >= UINT_MAX/sizeof(int64_t))
858 858
        return -1;
......
864 864

  
865 865
    if      (atom.type == MKTAG('s','t','c','o'))
866 866
        for(i=0; i<entries; i++)
867
            sc->chunk_offsets[i] = get_be32(pb);
867
            sc->chunk_offsets[i] = avio_rb32(pb);
868 868
    else if (atom.type == MKTAG('c','o','6','4'))
869 869
        for(i=0; i<entries; i++)
870
            sc->chunk_offsets[i] = get_be64(pb);
870
            sc->chunk_offsets[i] = avio_rb64(pb);
871 871
    else
872 872
        return -1;
873 873

  
......
926 926
        int dref_id = 1;
927 927
        MOVAtom a = { AV_RL32("stsd") };
928 928
        int64_t start_pos = url_ftell(pb);
929
        int size = get_be32(pb); /* size */
930
        uint32_t format = get_le32(pb); /* data format */
929
        int size = avio_rb32(pb); /* size */
930
        uint32_t format = avio_rl32(pb); /* data format */
931 931

  
932 932
        if (size >= 16) {
933
            get_be32(pb); /* reserved */
934
            get_be16(pb); /* reserved */
935
            dref_id = get_be16(pb);
933
            avio_rb32(pb); /* reserved */
934
            avio_rb16(pb); /* reserved */
935
            dref_id = avio_rb16(pb);
936 936
        }
937 937

  
938 938
        if (st->codec->codec_tag &&
......
984 984
            int color_greyscale;
985 985

  
986 986
            st->codec->codec_id = id;
987
            get_be16(pb); /* version */
988
            get_be16(pb); /* revision level */
989
            get_be32(pb); /* vendor */
990
            get_be32(pb); /* temporal quality */
991
            get_be32(pb); /* spatial quality */
987
            avio_rb16(pb); /* version */
988
            avio_rb16(pb); /* revision level */
989
            avio_rb32(pb); /* vendor */
990
            avio_rb32(pb); /* temporal quality */
991
            avio_rb32(pb); /* spatial quality */
992 992

  
993
            st->codec->width = get_be16(pb); /* width */
994
            st->codec->height = get_be16(pb); /* height */
993
            st->codec->width = avio_rb16(pb); /* width */
994
            st->codec->height = avio_rb16(pb); /* height */
995 995

  
996
            get_be32(pb); /* horiz resolution */
997
            get_be32(pb); /* vert resolution */
998
            get_be32(pb); /* data size, always 0 */
999
            get_be16(pb); /* frames per samples */
996
            avio_rb32(pb); /* horiz resolution */
997
            avio_rb32(pb); /* vert resolution */
998
            avio_rb32(pb); /* data size, always 0 */
999
            avio_rb16(pb); /* frames per samples */
1000 1000

  
1001
            len = get_byte(pb); /* codec name, pascal string */
1001
            len = avio_r8(pb); /* codec name, pascal string */
1002 1002
            if (len > 31)
1003 1003
                len = 31;
1004 1004
            mov_read_mac_string(c, pb, len, st->codec->codec_name, 32);
......
1008 1008
            if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
1009 1009
                st->codec->codec_tag=MKTAG('I', '4', '2', '0');
1010 1010

  
1011
            st->codec->bits_per_coded_sample = get_be16(pb); /* depth */
1012
            st->codec->color_table_id = get_be16(pb); /* colortable id */
1011
            st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */
1012
            st->codec->color_table_id = avio_rb16(pb); /* colortable id */
1013 1013
            av_dlog(c->fc, "depth %d, ctab id %d\n",
1014 1014
                   st->codec->bits_per_coded_sample, st->codec->color_table_id);
1015 1015
            /* figure out the palette situation */
......
1059 1059
                    }
1060 1060
                } else {
1061 1061
                    /* load the palette from the file */
1062
                    color_start = get_be32(pb);
1063
                    color_count = get_be16(pb);
1064
                    color_end = get_be16(pb);
1062
                    color_start = avio_rb32(pb);
1063
                    color_count = avio_rb16(pb);
1064
                    color_end = avio_rb16(pb);
1065 1065
                    if ((color_start <= 255) &&
1066 1066
                        (color_end <= 255)) {
1067 1067
                        for (j = color_start; j <= color_end; j++) {
1068 1068
                            /* each R, G, or B component is 16 bits;
1069 1069
                             * only use the top 8 bits; skip alpha bytes
1070 1070
                             * up front */
1071
                            get_byte(pb);
1072
                            get_byte(pb);
1073
                            r = get_byte(pb);
1074
                            get_byte(pb);
1075
                            g = get_byte(pb);
1076
                            get_byte(pb);
1077
                            b = get_byte(pb);
1078
                            get_byte(pb);
1071
                            avio_r8(pb);
1072
                            avio_r8(pb);
1073
                            r = avio_r8(pb);
1074
                            avio_r8(pb);
1075
                            g = avio_r8(pb);
1076
                            avio_r8(pb);
1077
                            b = avio_r8(pb);
1078
                            avio_r8(pb);
1079 1079
                            st->codec->palctrl->palette[j] =
1080 1080
                                (r << 16) | (g << 8) | (b);
1081 1081
                        }
......
1085 1085
            }
1086 1086
        } else if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
1087 1087
            int bits_per_sample, flags;
1088
            uint16_t version = get_be16(pb);
1088
            uint16_t version = avio_rb16(pb);
1089 1089

  
1090 1090
            st->codec->codec_id = id;
1091
            get_be16(pb); /* revision level */
1092
            get_be32(pb); /* vendor */
1091
            avio_rb16(pb); /* revision level */
1092
            avio_rb32(pb); /* vendor */
1093 1093

  
1094
            st->codec->channels = get_be16(pb);             /* channel count */
1094
            st->codec->channels = avio_rb16(pb);             /* channel count */
1095 1095
            av_dlog(c->fc, "audio channels %d\n", st->codec->channels);
1096
            st->codec->bits_per_coded_sample = get_be16(pb);      /* sample size */
1096
            st->codec->bits_per_coded_sample = avio_rb16(pb);      /* sample size */
1097 1097

  
1098
            sc->audio_cid = get_be16(pb);
1099
            get_be16(pb); /* packet size = 0 */
1098
            sc->audio_cid = avio_rb16(pb);
1099
            avio_rb16(pb); /* packet size = 0 */
1100 1100

  
1101
            st->codec->sample_rate = ((get_be32(pb) >> 16));
1101
            st->codec->sample_rate = ((avio_rb32(pb) >> 16));
1102 1102

  
1103 1103
            //Read QT version 1 fields. In version 0 these do not exist.
1104 1104
            av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom);
1105 1105
            if(!c->isom) {
1106 1106
                if(version==1) {
1107
                    sc->samples_per_frame = get_be32(pb);
1108
                    get_be32(pb); /* bytes per packet */
1109
                    sc->bytes_per_frame = get_be32(pb);
1110
                    get_be32(pb); /* bytes per sample */
1107
                    sc->samples_per_frame = avio_rb32(pb);
1108
                    avio_rb32(pb); /* bytes per packet */
1109
                    sc->bytes_per_frame = avio_rb32(pb);
1110
                    avio_rb32(pb); /* bytes per sample */
1111 1111
                } else if(version==2) {
1112
                    get_be32(pb); /* sizeof struct only */
1113
                    st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */
1114
                    st->codec->channels = get_be32(pb);
1115
                    get_be32(pb); /* always 0x7F000000 */
1116
                    st->codec->bits_per_coded_sample = get_be32(pb); /* bits per channel if sound is uncompressed */
1117
                    flags = get_be32(pb); /* lpcm format specific flag */
1118
                    sc->bytes_per_frame = get_be32(pb); /* bytes per audio packet if constant */
1119
                    sc->samples_per_frame = get_be32(pb); /* lpcm frames per audio packet if constant */
1112
                    avio_rb32(pb); /* sizeof struct only */
1113
                    st->codec->sample_rate = av_int2dbl(avio_rb64(pb)); /* float 64 */
1114
                    st->codec->channels = avio_rb32(pb);
1115
                    avio_rb32(pb); /* always 0x7F000000 */
1116
                    st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */
1117
                    flags = avio_rb32(pb); /* lpcm format specific flag */
1118
                    sc->bytes_per_frame = avio_rb32(pb); /* bytes per audio packet if constant */
1119
                    sc->samples_per_frame = avio_rb32(pb); /* lpcm frames per audio packet if constant */
1120 1120
                    if (format == MKTAG('l','p','c','m'))
1121 1121
                        st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags);
1122 1122
                }
......
1249 1249
{
1250 1250
    int entries;
1251 1251

  
1252
    get_byte(pb); /* version */
1253
    get_be24(pb); /* flags */
1254
    entries = get_be32(pb);
1252
    avio_r8(pb); /* version */
1253
    avio_rb24(pb); /* flags */
1254
    entries = avio_rb32(pb);
1255 1255

  
1256 1256
    return ff_mov_read_stsd_entries(c, pb, entries);
1257 1257
}
......
1267 1267
    st = c->fc->streams[c->fc->nb_streams-1];
1268 1268
    sc = st->priv_data;
1269 1269

  
1270
    get_byte(pb); /* version */
1271
    get_be24(pb); /* flags */
1270
    avio_r8(pb); /* version */
1271
    avio_rb24(pb); /* flags */
1272 1272

  
1273
    entries = get_be32(pb);
1273
    entries = avio_rb32(pb);
1274 1274

  
1275 1275
    av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
1276 1276

  
......
1282 1282
    sc->stsc_count = entries;
1283 1283

  
1284 1284
    for(i=0; i<entries; i++) {
1285
        sc->stsc_data[i].first = get_be32(pb);
1286
        sc->stsc_data[i].count = get_be32(pb);
1287
        sc->stsc_data[i].id = get_be32(pb);
1285
        sc->stsc_data[i].first = avio_rb32(pb);
1286
        sc->stsc_data[i].count = avio_rb32(pb);
1287
        sc->stsc_data[i].id = avio_rb32(pb);
1288 1288
    }
1289 1289
    return 0;
1290 1290
}
......
1300 1300
    st = c->fc->streams[c->fc->nb_streams-1];
1301 1301
    sc = st->priv_data;
1302 1302

  
1303
    get_be32(pb); // version + flags
1303
    avio_rb32(pb); // version + flags
1304 1304

  
1305
    entries = get_be32(pb);
1305
    entries = avio_rb32(pb);
1306 1306
    if (entries >= UINT_MAX / sizeof(*sc->stps_data))
1307 1307
        return -1;
1308 1308
    sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data));
......
1311 1311
    sc->stps_count = entries;
1312 1312

  
1313 1313
    for (i = 0; i < entries; i++) {
1314
        sc->stps_data[i] = get_be32(pb);
1314
        sc->stps_data[i] = avio_rb32(pb);
1315 1315
        //av_dlog(c->fc, "stps %d\n", sc->stps_data[i]);
1316 1316
    }
1317 1317

  
......
1329 1329
    st = c->fc->streams[c->fc->nb_streams-1];
1330 1330
    sc = st->priv_data;
1331 1331

  
1332
    get_byte(pb); /* version */
1333
    get_be24(pb); /* flags */
1332
    avio_r8(pb); /* version */
1333
    avio_rb24(pb); /* flags */
1334 1334

  
1335
    entries = get_be32(pb);
1335
    entries = avio_rb32(pb);
1336 1336

  
1337 1337
    av_dlog(c->fc, "keyframe_count = %d\n", entries);
1338 1338

  
......
1344 1344
    sc->keyframe_count = entries;
1345 1345

  
1346 1346
    for(i=0; i<entries; i++) {
1347
        sc->keyframes[i] = get_be32(pb);
1347
        sc->keyframes[i] = avio_rb32(pb);
1348 1348
        //av_dlog(c->fc, "keyframes[]=%d\n", sc->keyframes[i]);
1349 1349
    }
1350 1350
    return 0;
......
1363 1363
    st = c->fc->streams[c->fc->nb_streams-1];
1364 1364
    sc = st->priv_data;
1365 1365

  
1366
    get_byte(pb); /* version */
1367
    get_be24(pb); /* flags */
1366
    avio_r8(pb); /* version */
1367
    avio_rb24(pb); /* flags */
1368 1368

  
1369 1369
    if (atom.type == MKTAG('s','t','s','z')) {
1370
        sample_size = get_be32(pb);
1370
        sample_size = avio_rb32(pb);
1371 1371
        if (!sc->sample_size) /* do not overwrite value computed in stsd */
1372 1372
            sc->sample_size = sample_size;
1373 1373
        field_size = 32;
1374 1374
    } else {
1375 1375
        sample_size = 0;
1376
        get_be24(pb); /* reserved */
1377
        field_size = get_byte(pb);
1376
        avio_rb24(pb); /* reserved */
1377
        field_size = avio_r8(pb);
1378 1378
    }
1379
    entries = get_be32(pb);
1379
    entries = avio_rb32(pb);
1380 1380

  
1381 1381
    av_dlog(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries);
1382 1382

  
......
1403 1403
        return AVERROR(ENOMEM);
1404 1404
    }
1405 1405

  
1406
    if (get_buffer(pb, buf, num_bytes) < num_bytes) {
1406
    if (avio_read(pb, buf, num_bytes) < num_bytes) {
1407 1407
        av_freep(&sc->sample_sizes);
1408 1408
        av_free(buf);
1409 1409
        return -1;
......
1431 1431
    st = c->fc->streams[c->fc->nb_streams-1];
1432 1432
    sc = st->priv_data;
1433 1433

  
1434
    get_byte(pb); /* version */
1435
    get_be24(pb); /* flags */
1436
    entries = get_be32(pb);
1434
    avio_r8(pb); /* version */
1435
    avio_rb24(pb); /* flags */
1436
    entries = avio_rb32(pb);
1437 1437

  
1438 1438
    av_dlog(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
1439 1439

  
......
1448 1448
        int sample_duration;
1449 1449
        int sample_count;
1450 1450

  
1451
        sample_count=get_be32(pb);
1452
        sample_duration = get_be32(pb);
1451
        sample_count=avio_rb32(pb);
1452
        sample_duration = avio_rb32(pb);
1453 1453
        sc->stts_data[i].count= sample_count;
1454 1454
        sc->stts_data[i].duration= sample_duration;
1455 1455

  
......
1476 1476
    st = c->fc->streams[c->fc->nb_streams-1];
1477 1477
    sc = st->priv_data;
1478 1478

  
1479
    get_byte(pb); /* version */
1480
    get_be24(pb); /* flags */
1481
    entries = get_be32(pb);
1479
    avio_r8(pb); /* version */
1480
    avio_rb24(pb); /* flags */
1481
    entries = avio_rb32(pb);
1482 1482

  
1483 1483
    av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
1484 1484

  
......
1490 1490
    sc->ctts_count = entries;
1491 1491

  
1492 1492
    for(i=0; i<entries; i++) {
1493
        int count    =get_be32(pb);
1494
        int duration =get_be32(pb);
1493
        int count    =avio_rb32(pb);
1494
        int duration =avio_rb32(pb);
1495 1495

  
1496 1496
        sc->ctts_data[i].count   = count;
1497 1497
        sc->ctts_data[i].duration= duration;
......
1837 1837
static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
1838 1838
{
1839 1839
    while (atom.size > 8) {
1840
        uint32_t tag = get_le32(pb);
1840
        uint32_t tag = avio_rl32(pb);
1841 1841
        atom.size -= 4;
1842 1842
        if (tag == MKTAG('h','d','l','r')) {
1843 1843
            url_fseek(pb, -8, SEEK_CUR);
......
1864 1864
    st = c->fc->streams[c->fc->nb_streams-1];
1865 1865
    sc = st->priv_data;
1866 1866

  
1867
    version = get_byte(pb);
1868
    get_be24(pb); /* flags */
1867
    version = avio_r8(pb);
1868
    avio_rb24(pb); /* flags */
1869 1869
    /*
1870 1870
    MOV_TRACK_ENABLED 0x0001
1871 1871
    MOV_TRACK_IN_MOVIE 0x0002
......
1874 1874
    */
1875 1875

  
1876 1876
    if (version == 1) {
1877
        get_be64(pb);
1878
        get_be64(pb);
1877
        avio_rb64(pb);
1878
        avio_rb64(pb);
1879 1879
    } else {
1880
        get_be32(pb); /* creation time */
1881
        get_be32(pb); /* modification time */
1880
        avio_rb32(pb); /* creation time */
1881
        avio_rb32(pb); /* modification time */
1882 1882
    }
1883
    st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
1884
    get_be32(pb); /* reserved */
1883
    st->id = (int)avio_rb32(pb); /* track id (NOT 0 !)*/
1884
    avio_rb32(pb); /* reserved */
1885 1885

  
1886 1886
    /* highlevel (considering edits) duration in movie timebase */
1887
    (version == 1) ? get_be64(pb) : get_be32(pb);
1888
    get_be32(pb); /* reserved */
1889
    get_be32(pb); /* reserved */
1887
    (version == 1) ? avio_rb64(pb) : avio_rb32(pb);
1888
    avio_rb32(pb); /* reserved */
1889
    avio_rb32(pb); /* reserved */
1890 1890

  
1891
    get_be16(pb); /* layer */
1892
    get_be16(pb); /* alternate group */
1893
    get_be16(pb); /* volume */
1894
    get_be16(pb); /* reserved */
1891
    avio_rb16(pb); /* layer */
1892
    avio_rb16(pb); /* alternate group */
1893
    avio_rb16(pb); /* volume */
1894
    avio_rb16(pb); /* reserved */
1895 1895

  
1896 1896
    //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2)
1897 1897
    // they're kept in fixed point format through all calculations
1898 1898
    // ignore u,v,z b/c we don't need the scale factor to calc aspect ratio
1899 1899
    for (i = 0; i < 3; i++) {
1900
        display_matrix[i][0] = get_be32(pb);   // 16.16 fixed point
1901
        display_matrix[i][1] = get_be32(pb);   // 16.16 fixed point
1902
        get_be32(pb);           // 2.30 fixed point (not used)
1900
        display_matrix[i][0] = avio_rb32(pb);   // 16.16 fixed point
1901
        display_matrix[i][1] = avio_rb32(pb);   // 16.16 fixed point
1902
        avio_rb32(pb);           // 2.30 fixed point (not used)
1903 1903
    }
1904 1904

  
1905
    width = get_be32(pb);       // 16.16 fixed point track width
1906
    height = get_be32(pb);      // 16.16 fixed point track height
1905
    width = avio_rb32(pb);       // 16.16 fixed point track width
1906
    height = avio_rb32(pb);      // 16.16 fixed point track height
1907 1907
    sc->width = width >> 16;
1908 1908
    sc->height = height >> 16;
1909 1909

  
......
1937 1937
    MOVTrackExt *trex = NULL;
1938 1938
    int flags, track_id, i;
1939 1939

  
1940
    get_byte(pb); /* version */
1941
    flags = get_be24(pb);
1940
    avio_r8(pb); /* version */
1941
    flags = avio_rb24(pb);
1942 1942

  
1943
    track_id = get_be32(pb);
1943
    track_id = avio_rb32(pb);
1944 1944
    if (!track_id)
1945 1945
        return -1;
1946 1946
    frag->track_id = track_id;
......
1954 1954
        return -1;
1955 1955
    }
1956 1956

  
1957
    if (flags & 0x01) frag->base_data_offset = get_be64(pb);
1957
    if (flags & 0x01) frag->base_data_offset = avio_rb64(pb);
1958 1958
    else              frag->base_data_offset = frag->moof_offset;
1959
    if (flags & 0x02) frag->stsd_id          = get_be32(pb);
1959
    if (flags & 0x02) frag->stsd_id          = avio_rb32(pb);
1960 1960
    else              frag->stsd_id          = trex->stsd_id;
1961 1961

  
1962
    frag->duration = flags & 0x08 ? get_be32(pb) : trex->duration;
1963
    frag->size     = flags & 0x10 ? get_be32(pb) : trex->size;
1964
    frag->flags    = flags & 0x20 ? get_be32(pb) : trex->flags;
1962
    frag->duration = flags & 0x08 ? avio_rb32(pb) : trex->duration;
1963
    frag->size     = flags & 0x10 ? avio_rb32(pb) : trex->size;
1964
    frag->flags    = flags & 0x20 ? avio_rb32(pb) : trex->flags;
1965 1965
    av_dlog(c->fc, "frag flags 0x%x\n", frag->flags);
1966 1966
    return 0;
1967 1967
}
1968 1968

  
1969 1969
static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
1970 1970
{
1971
    c->chapter_track = get_be32(pb);
1971
    c->chapter_track = avio_rb32(pb);
1972 1972
    return 0;
1973 1973
}
1974 1974

  
......
1983 1983
        return AVERROR(ENOMEM);
1984 1984
    c->trex_data = trex;
1985 1985
    trex = &c->trex_data[c->trex_count++];
1986
    get_byte(pb); /* version */
1987
    get_be24(pb); /* flags */
1988
    trex->track_id = get_be32(pb);
1989
    trex->stsd_id  = get_be32(pb);
1990
    trex->duration = get_be32(pb);
1991
    trex->size     = get_be32(pb);
1992
    trex->flags    = get_be32(pb);
1986
    avio_r8(pb); /* version */
1987
    avio_rb24(pb); /* flags */
1988
    trex->track_id = avio_rb32(pb);
1989
    trex->stsd_id  = avio_rb32(pb);
1990
    trex->duration = avio_rb32(pb);
1991
    trex->size     = avio_rb32(pb);
1992
    trex->flags    = avio_rb32(pb);
1993 1993
    return 0;
1994 1994
}
1995 1995

  
......
2017 2017
    sc = st->priv_data;
2018 2018
    if (sc->pseudo_stream_id+1 != frag->stsd_id)
2019 2019
        return 0;
2020
    get_byte(pb); /* version */
2021
    flags = get_be24(pb);
2022
    entries = get_be32(pb);
2020
    avio_r8(pb); /* version */
2021
    flags = avio_rb24(pb);
2022
    entries = avio_rb32(pb);
2023 2023
    av_dlog(c->fc, "flags 0x%x entries %d\n", flags, entries);
2024
    if (flags & 0x001) data_offset        = get_be32(pb);
2025
    if (flags & 0x004) first_sample_flags = get_be32(pb);
2024
    if (flags & 0x001) data_offset        = avio_rb32(pb);
2025
    if (flags & 0x004) first_sample_flags = avio_rb32(pb);
2026 2026
    if (flags & 0x800) {
2027 2027
        MOVStts *ctts_data;
2028 2028
        if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
......
2043 2043
        unsigned sample_duration = frag->duration;
2044 2044
        int keyframe;
2045 2045

  
2046
        if (flags & 0x100) sample_duration = get_be32(pb);
2047
        if (flags & 0x200) sample_size     = get_be32(pb);
2048
        if (flags & 0x400) sample_flags    = get_be32(pb);
2046
        if (flags & 0x100) sample_duration = avio_rb32(pb);
2047
        if (flags & 0x200) sample_size     = avio_rb32(pb);
2048
        if (flags & 0x400) sample_flags    = avio_rb32(pb);
2049 2049
        if (flags & 0x800) {
2050 2050
            sc->ctts_data[sc->ctts_count].count = 1;
2051
            sc->ctts_data[sc->ctts_count].duration = get_be32(pb);
2051
            sc->ctts_data[sc->ctts_count].duration = avio_rb32(pb);
2052 2052
            sc->ctts_count++;
2053 2053
        }
2054 2054
        if ((keyframe = st->codec->codec_type == AVMEDIA_TYPE_AUDIO ||
......
2077 2077

  
2078 2078
    if (atom.size < 8)
2079 2079
        return 0; /* continue */
2080
    if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
2080
    if (avio_rb32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
2081 2081
        url_fskip(pb, atom.size - 4);
2082 2082
        return 0;
2083 2083
    }
2084
    atom.type = get_le32(pb);
2084
    atom.type = avio_rl32(pb);
2085 2085
    atom.size -= 8;
2086 2086
    if (atom.type != MKTAG('m','d','a','t')) {
2087 2087
        url_fskip(pb, atom.size);
......
2100 2100
    long cmov_len, moov_len;
2101 2101
    int ret = -1;
2102 2102

  
2103
    get_be32(pb); /* dcom atom */
2104
    if (get_le32(pb) != MKTAG('d','c','o','m'))
2103
    avio_rb32(pb); /* dcom atom */
2104
    if (avio_rl32(pb) != MKTAG('d','c','o','m'))
2105 2105
        return -1;
2106
    if (get_le32(pb) != MKTAG('z','l','i','b')) {
2106
    if (avio_rl32(pb) != MKTAG('z','l','i','b')) {
2107 2107
        av_log(c->fc, AV_LOG_ERROR, "unknown compression for cmov atom !");
2108 2108
        return -1;
2109 2109
    }
2110
    get_be32(pb); /* cmvd atom */
2111
    if (get_le32(pb) != MKTAG('c','m','v','d'))
2110
    avio_rb32(pb); /* cmvd atom */
2111
    if (avio_rl32(pb) != MKTAG('c','m','v','d'))
2112 2112
        return -1;
2113
    moov_len = get_be32(pb); /* uncompressed size */
2113
    moov_len = avio_rb32(pb); /* uncompressed size */
2114 2114
    cmov_len = atom.size - 6 * 4;
2115 2115

  
2116 2116
    cmov_data = av_malloc(cmov_len);
......
2121 2121
        av_free(cmov_data);
2122 2122
        return AVERROR(ENOMEM);
2123 2123
    }
2124
    get_buffer(pb, cmov_data, cmov_len);
2124
    avio_read(pb, cmov_data, cmov_len);
2125 2125
    if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
2126 2126
        goto free_and_return;
2127 2127
    if(ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
......
2152 2152
        return 0;
2153 2153
    sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
2154 2154

  
2155
    get_byte(pb); /* version */
2156
    get_be24(pb); /* flags */
2157
    edit_count = get_be32(pb); /* entries */
2155
    avio_r8(pb); /* version */
2156
    avio_rb24(pb); /* flags */
2157
    edit_count = avio_rb32(pb); /* entries */
2158 2158

  
2159 2159
    if((uint64_t)edit_count*12+8 > atom.size)
2160 2160
        return -1;
2161 2161

  
2162 2162
    for(i=0; i<edit_count; i++){
2163 2163
        int time;
2164
        int duration = get_be32(pb); /* Track duration */
2165
        time = get_be32(pb); /* Media time */
2166
        get_be32(pb); /* Media rate */
2164
        int duration = avio_rb32(pb); /* Track duration */
2165
        time = avio_rb32(pb); /* Media time */
2166
        avio_rb32(pb); /* Media rate */
2167 2167
        if (i == 0 && time >= -1) {
2168 2168
            sc->time_offset = time != -1 ? time : -duration;
2169 2169
        }
......
2314 2314
        }
2315 2315

  
2316 2316
        // the first two bytes are the length of the title
2317
        len = get_be16(sc->pb);
2317
        len = avio_rb16(sc->pb);
2318 2318
        if (len > sample->size-2)
2319 2319
            continue;
2320 2320
        title_len = 2*len + 1;
......
2324 2324
        // The samples could theoretically be in any encoding if there's an encd
2325 2325
        // atom following, but in practice are only utf-8 or utf-16, distinguished
2326 2326
        // instead by the presence of a BOM
2327
        ch = get_be16(sc->pb);
2327
        ch = avio_rb16(sc->pb);
2328 2328
        if (ch == 0xfeff)
2329 2329
            avio_get_str16be(sc->pb, len, title, title_len);
2330 2330
        else if (ch == 0xfffe)

Also available in: Unified diff