Revision b7effd4e libavformat/mxfdec.c

View differences:

libavformat/mxfdec.c
163 163

  
164 164
static int64_t klv_decode_ber_length(AVIOContext *pb)
165 165
{
166
    uint64_t size = get_byte(pb);
166
    uint64_t size = avio_r8(pb);
167 167
    if (size & 0x80) { /* long form */
168 168
        int bytes_num = size & 0x7f;
169 169
        /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */
......
171 171
            return -1;
172 172
        size = 0;
173 173
        while (bytes_num--)
174
            size = size << 8 | get_byte(pb);
174
            size = size << 8 | avio_r8(pb);
175 175
    }
176 176
    return size;
177 177
}
......
180 180
{
181 181
    int i, b;
182 182
    for (i = 0; i < size && !url_feof(pb); i++) {
183
        b = get_byte(pb);
183
        b = avio_r8(pb);
184 184
        if (b == key[0])
185 185
            i = 0;
186 186
        else if (b != key[i])
......
195 195
        return -1;
196 196
    klv->offset = url_ftell(pb) - 4;
197 197
    memcpy(klv->key, mxf_klv_key, 4);
198
    get_buffer(pb, klv->key + 4, 12);
198
    avio_read(pb, klv->key + 4, 12);
199 199
    klv->length = klv_decode_ber_length(pb);
200 200
    return klv->length == -1 ? -1 : 0;
201 201
}
......
224 224
    if (length > 61444) /* worst case PAL 1920 samples 8 channels */
225 225
        return -1;
226 226
    av_new_packet(pkt, length);
227
    get_buffer(pb, pkt->data, length);
227
    avio_read(pb, pkt->data, length);
228 228
    data_ptr = pkt->data;
229 229
    end_ptr = pkt->data + length;
230 230
    buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */
......
265 265
    url_fskip(pb, klv_decode_ber_length(pb));
266 266
    // plaintext offset
267 267
    klv_decode_ber_length(pb);
268
    plaintext_size = get_be64(pb);
268
    plaintext_size = avio_rb64(pb);
269 269
    // source klv key
270 270
    klv_decode_ber_length(pb);
271
    get_buffer(pb, klv->key, 16);
271
    avio_read(pb, klv->key, 16);
272 272
    if (!IS_KLV_KEY(klv, mxf_essence_element_key))
273 273
        return -1;
274 274
    index = mxf_get_stream_index(s, klv);
......
276 276
        return -1;
277 277
    // source size
278 278
    klv_decode_ber_length(pb);
279
    orig_size = get_be64(pb);
279
    orig_size = avio_rb64(pb);
280 280
    if (orig_size < plaintext_size)
281 281
        return -1;
282 282
    // enc. code
283 283
    size = klv_decode_ber_length(pb);
284 284
    if (size < 32 || size - 32 < orig_size)
285 285
        return -1;
286
    get_buffer(pb, ivec, 16);
287
    get_buffer(pb, tmpbuf, 16);
286
    avio_read(pb, ivec, 16);
287
    avio_read(pb, tmpbuf, 16);
288 288
    if (mxf->aesc)
289 289
        av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1);
290 290
    if (memcmp(tmpbuf, checkv, 16))
......
347 347
static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid)
348 348
{
349 349
    MXFContext *mxf = arg;
350
    int item_num = get_be32(pb);
351
    int item_len = get_be32(pb);
350
    int item_num = avio_rb32(pb);
351
    int item_len = avio_rb32(pb);
352 352

  
353 353
    if (item_len != 18) {
354 354
        av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n");
......
360 360
    mxf->local_tags = av_malloc(item_num*item_len);
361 361
    if (!mxf->local_tags)
362 362
        return -1;
363
    get_buffer(pb, mxf->local_tags, item_num*item_len);
363
    avio_read(pb, mxf->local_tags, item_num*item_len);
364 364
    return 0;
365 365
}
366 366

  
......
382 382
    if (size != 16)
383 383
        return -1;
384 384
    if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul))
385
        get_buffer(pb, cryptocontext->source_container_ul, 16);
385
        avio_read(pb, cryptocontext->source_container_ul, 16);
386 386
    return 0;
387 387
}
388 388

  
......
391 391
    MXFContext *mxf = arg;
392 392
    switch (tag) {
393 393
    case 0x1901:
394
        mxf->packages_count = get_be32(pb);
394
        mxf->packages_count = avio_rb32(pb);
395 395
        if (mxf->packages_count >= UINT_MAX / sizeof(UID))
396 396
            return -1;
397 397
        mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID));
398 398
        if (!mxf->packages_refs)
399 399
            return -1;
400 400
        url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
401
        get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
401
        avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID));
402 402
        break;
403 403
    }
404 404
    return 0;
......
409 409
    MXFStructuralComponent *source_clip = arg;
410 410
    switch(tag) {
411 411
    case 0x0202:
412
        source_clip->duration = get_be64(pb);
412
        source_clip->duration = avio_rb64(pb);
413 413
        break;
414 414
    case 0x1201:
415
        source_clip->start_position = get_be64(pb);
415
        source_clip->start_position = avio_rb64(pb);
416 416
        break;
417 417
    case 0x1101:
418 418
        /* UMID, only get last 16 bytes */
419 419
        url_fskip(pb, 16);
420
        get_buffer(pb, source_clip->source_package_uid, 16);
420
        avio_read(pb, source_clip->source_package_uid, 16);
421 421
        break;
422 422
    case 0x1102:
423
        source_clip->source_track_id = get_be32(pb);
423
        source_clip->source_track_id = avio_rb32(pb);
424 424
        break;
425 425
    }
426 426
    return 0;
......
431 431
    MXFPackage *package = arg;
432 432
    switch(tag) {
433 433
    case 0x4403:
434
        package->tracks_count = get_be32(pb);
434
        package->tracks_count = avio_rb32(pb);
435 435
        if (package->tracks_count >= UINT_MAX / sizeof(UID))
436 436
            return -1;
437 437
        package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
438 438
        if (!package->tracks_refs)
439 439
            return -1;
440 440
        url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
441
        get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
441
        avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
442 442
        break;
443 443
    }
444 444
    return 0;
......
449 449
    MXFTrack *track = arg;
450 450
    switch(tag) {
451 451
    case 0x4801:
452
        track->track_id = get_be32(pb);
452
        track->track_id = avio_rb32(pb);
453 453
        break;
454 454
    case 0x4804:
455
        get_buffer(pb, track->track_number, 4);
455
        avio_read(pb, track->track_number, 4);
456 456
        break;
457 457
    case 0x4B01:
458
        track->edit_rate.den = get_be32(pb);
459
        track->edit_rate.num = get_be32(pb);
458
        track->edit_rate.den = avio_rb32(pb);
459
        track->edit_rate.num = avio_rb32(pb);
460 460
        break;
461 461
    case 0x4803:
462
        get_buffer(pb, track->sequence_ref, 16);
462
        avio_read(pb, track->sequence_ref, 16);
463 463
        break;
464 464
    }
465 465
    return 0;
......
470 470
    MXFSequence *sequence = arg;
471 471
    switch(tag) {
472 472
    case 0x0202:
473
        sequence->duration = get_be64(pb);
473
        sequence->duration = avio_rb64(pb);
474 474
        break;
475 475
    case 0x0201:
476
        get_buffer(pb, sequence->data_definition_ul, 16);
476
        avio_read(pb, sequence->data_definition_ul, 16);
477 477
        break;
478 478
    case 0x1001:
479
        sequence->structural_components_count = get_be32(pb);
479
        sequence->structural_components_count = avio_rb32(pb);
480 480
        if (sequence->structural_components_count >= UINT_MAX / sizeof(UID))
481 481
            return -1;
482 482
        sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID));
483 483
        if (!sequence->structural_components_refs)
484 484
            return -1;
485 485
        url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
486
        get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
486
        avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID));
487 487
        break;
488 488
    }
489 489
    return 0;
......
494 494
    MXFPackage *package = arg;
495 495
    switch(tag) {
496 496
    case 0x4403:
497
        package->tracks_count = get_be32(pb);
497
        package->tracks_count = avio_rb32(pb);
498 498
        if (package->tracks_count >= UINT_MAX / sizeof(UID))
499 499
            return -1;
500 500
        package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID));
501 501
        if (!package->tracks_refs)
502 502
            return -1;
503 503
        url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
504
        get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
504
        avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID));
505 505
        break;
506 506
    case 0x4401:
507 507
        /* UMID, only get last 16 bytes */
508 508
        url_fskip(pb, 16);
509
        get_buffer(pb, package->package_uid, 16);
509
        avio_read(pb, package->package_uid, 16);
510 510
        break;
511 511
    case 0x4701:
512
        get_buffer(pb, package->descriptor_ref, 16);
512
        avio_read(pb, package->descriptor_ref, 16);
513 513
        break;
514 514
    }
515 515
    return 0;
......
518 518
static int mxf_read_index_table_segment(void *arg, AVIOContext *pb, int tag, int size, UID uid)
519 519
{
520 520
    switch(tag) {
521
    case 0x3F05: av_dlog(NULL, "EditUnitByteCount %d\n", get_be32(pb)); break;
522
    case 0x3F06: av_dlog(NULL, "IndexSID %d\n", get_be32(pb)); break;
523
    case 0x3F07: av_dlog(NULL, "BodySID %d\n", get_be32(pb)); break;
524
    case 0x3F0B: av_dlog(NULL, "IndexEditRate %d/%d\n", get_be32(pb), get_be32(pb)); break;
525
    case 0x3F0C: av_dlog(NULL, "IndexStartPosition %lld\n", get_be64(pb)); break;
526
    case 0x3F0D: av_dlog(NULL, "IndexDuration %lld\n", get_be64(pb)); break;
521
    case 0x3F05: av_dlog(NULL, "EditUnitByteCount %d\n", avio_rb32(pb)); break;
522
    case 0x3F06: av_dlog(NULL, "IndexSID %d\n", avio_rb32(pb)); break;
523
    case 0x3F07: av_dlog(NULL, "BodySID %d\n", avio_rb32(pb)); break;
524
    case 0x3F0B: av_dlog(NULL, "IndexEditRate %d/%d\n", avio_rb32(pb), avio_rb32(pb)); break;
525
    case 0x3F0C: av_dlog(NULL, "IndexStartPosition %lld\n", avio_rb64(pb)); break;
526
    case 0x3F0D: av_dlog(NULL, "IndexDuration %lld\n", avio_rb64(pb)); break;
527 527
    }
528 528
    return 0;
529 529
}
......
534 534
    char layout[16] = {0};
535 535

  
536 536
    do {
537
        code = get_byte(pb);
538
        value = get_byte(pb);
537
        code = avio_r8(pb);
538
        value = avio_r8(pb);
539 539
        av_dlog(NULL, "pixel layout: code %#x\n", code);
540 540

  
541 541
        if (ofs < 16) {
......
552 552
    MXFDescriptor *descriptor = arg;
553 553
    switch(tag) {
554 554
    case 0x3F01:
555
        descriptor->sub_descriptors_count = get_be32(pb);
555
        descriptor->sub_descriptors_count = avio_rb32(pb);
556 556
        if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID))
557 557
            return -1;
558 558
        descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID));
559 559
        if (!descriptor->sub_descriptors_refs)
560 560
            return -1;
561 561
        url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */
562
        get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
562
        avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID));
563 563
        break;
564 564
    case 0x3004:
565
        get_buffer(pb, descriptor->essence_container_ul, 16);
565
        avio_read(pb, descriptor->essence_container_ul, 16);
566 566
        break;
567 567
    case 0x3006:
568
        descriptor->linked_track_id = get_be32(pb);
568
        descriptor->linked_track_id = avio_rb32(pb);
569 569
        break;
570 570
    case 0x3201: /* PictureEssenceCoding */
571
        get_buffer(pb, descriptor->essence_codec_ul, 16);
571
        avio_read(pb, descriptor->essence_codec_ul, 16);
572 572
        break;
573 573
    case 0x3203:
574
        descriptor->width = get_be32(pb);
574
        descriptor->width = avio_rb32(pb);
575 575
        break;
576 576
    case 0x3202:
577
        descriptor->height = get_be32(pb);
577
        descriptor->height = avio_rb32(pb);
578 578
        break;
579 579
    case 0x320E:
580
        descriptor->aspect_ratio.num = get_be32(pb);
581
        descriptor->aspect_ratio.den = get_be32(pb);
580
        descriptor->aspect_ratio.num = avio_rb32(pb);
581
        descriptor->aspect_ratio.den = avio_rb32(pb);
582 582
        break;
583 583
    case 0x3D03:
584
        descriptor->sample_rate.num = get_be32(pb);
585
        descriptor->sample_rate.den = get_be32(pb);
584
        descriptor->sample_rate.num = avio_rb32(pb);
585
        descriptor->sample_rate.den = avio_rb32(pb);
586 586
        break;
587 587
    case 0x3D06: /* SoundEssenceCompression */
588
        get_buffer(pb, descriptor->essence_codec_ul, 16);
588
        avio_read(pb, descriptor->essence_codec_ul, 16);
589 589
        break;
590 590
    case 0x3D07:
591
        descriptor->channels = get_be32(pb);
591
        descriptor->channels = avio_rb32(pb);
592 592
        break;
593 593
    case 0x3D01:
594
        descriptor->bits_per_sample = get_be32(pb);
594
        descriptor->bits_per_sample = avio_rb32(pb);
595 595
        break;
596 596
    case 0x3401:
597 597
        mxf_read_pixel_layout(pb, descriptor);
......
603 603
            if (!descriptor->extradata)
604 604
                return -1;
605 605
            descriptor->extradata_size = size;
606
            get_buffer(pb, descriptor->extradata, size);
606
            avio_read(pb, descriptor->extradata, size);
607 607
        }
608 608
        break;
609 609
    }
......
871 871
    if (!ctx)
872 872
        return -1;
873 873
    while (url_ftell(pb) + 4 < klv_end) {
874
        int tag = get_be16(pb);
875
        int size = get_be16(pb); /* KLV specified by 0x53 */
874
        int tag = avio_rb16(pb);
875
        int size = avio_rb16(pb); /* KLV specified by 0x53 */
876 876
        uint64_t next = url_ftell(pb) + size;
877 877
        UID uid = {0};
878 878

  
......
893 893
            }
894 894
        }
895 895
        if (ctx_size && tag == 0x3C0A)
896
            get_buffer(pb, ctx->uid, 16);
896
            avio_read(pb, ctx->uid, 16);
897 897
        else if (read_child(ctx, pb, tag, size, uid) < 0)
898 898
            return -1;
899 899

  

Also available in: Unified diff