Revision e63a3628 libavformat/rmdec.c

View differences:

libavformat/rmdec.c
71 71

  
72 72
    q = buf;
73 73
    for(i=0;i<len;i++) {
74
        r = get_byte(pb);
74
        r = avio_r8(pb);
75 75
        if (i < buf_size - 1)
76 76
            *q++ = r;
77 77
    }
......
80 80

  
81 81
static void get_str8(AVIOContext *pb, char *buf, int buf_size)
82 82
{
83
    get_strl(pb, buf, buf_size, get_byte(pb));
83
    get_strl(pb, buf, buf_size, avio_r8(pb));
84 84
}
85 85

  
86 86
static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size)
......
90 90
    avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
91 91
    if (!avctx->extradata)
92 92
        return AVERROR(ENOMEM);
93
    avctx->extradata_size = get_buffer(pb, avctx->extradata, size);
93
    avctx->extradata_size = avio_read(pb, avctx->extradata, size);
94 94
    memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
95 95
    if (avctx->extradata_size != size)
96 96
        return AVERROR(EIO);
......
102 102
    char buf[1024];
103 103
    int i;
104 104
    for (i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
105
        int len = wide ? get_be16(s->pb) : get_byte(s->pb);
105
        int len = wide ? avio_rb16(s->pb) : avio_r8(s->pb);
106 106
        get_strl(s->pb, buf, sizeof(buf), len);
107 107
        av_metadata_set2(&s->metadata, ff_rm_metadata[i], buf, 0);
108 108
    }
......
128 128
    int ret;
129 129

  
130 130
    /* ra type header */
131
    version = get_be16(pb); /* version */
131
    version = avio_rb16(pb); /* version */
132 132
    if (version == 3) {
133
        int header_size = get_be16(pb);
133
        int header_size = avio_rb16(pb);
134 134
        int64_t startpos = url_ftell(pb);
135 135
        url_fskip(pb, 14);
136 136
        rm_read_metadata(s, 0);
137 137
        if ((startpos + header_size) >= url_ftell(pb) + 2) {
138 138
            // fourcc (should always be "lpcJ")
139
            get_byte(pb);
139
            avio_r8(pb);
140 140
            get_str8(pb, buf, sizeof(buf));
141 141
        }
142 142
        // Skip extra header crap (this should never happen)
......
151 151
        int codecdata_length;
152 152
        /* old version (4) */
153 153
        url_fskip(pb, 2); /* unused */
154
        get_be32(pb); /* .ra4 */
155
        get_be32(pb); /* data size */
156
        get_be16(pb); /* version2 */
157
        get_be32(pb); /* header size */
158
        flavor= get_be16(pb); /* add codec info / flavor */
159
        ast->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */
160
        get_be32(pb); /* ??? */
161
        get_be32(pb); /* ??? */
162
        get_be32(pb); /* ??? */
163
        ast->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */
164
        st->codec->block_align= get_be16(pb); /* frame size */
165
        ast->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */
166
        get_be16(pb); /* ??? */
154
        avio_rb32(pb); /* .ra4 */
155
        avio_rb32(pb); /* data size */
156
        avio_rb16(pb); /* version2 */
157
        avio_rb32(pb); /* header size */
158
        flavor= avio_rb16(pb); /* add codec info / flavor */
159
        ast->coded_framesize = coded_framesize = avio_rb32(pb); /* coded frame size */
160
        avio_rb32(pb); /* ??? */
161
        avio_rb32(pb); /* ??? */
162
        avio_rb32(pb); /* ??? */
163
        ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */
164
        st->codec->block_align= avio_rb16(pb); /* frame size */
165
        ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */
166
        avio_rb16(pb); /* ??? */
167 167
        if (version == 5) {
168
            get_be16(pb); get_be16(pb); get_be16(pb);
168
            avio_rb16(pb); avio_rb16(pb); avio_rb16(pb);
169 169
        }
170
        st->codec->sample_rate = get_be16(pb);
171
        get_be32(pb);
172
        st->codec->channels = get_be16(pb);
170
        st->codec->sample_rate = avio_rb16(pb);
171
        avio_rb32(pb);
172
        st->codec->channels = avio_rb16(pb);
173 173
        if (version == 5) {
174
            get_be32(pb);
175
            get_buffer(pb, buf, 4);
174
            avio_rb32(pb);
175
            avio_read(pb, buf, 4);
176 176
            buf[4] = 0;
177 177
        } else {
178 178
            get_str8(pb, buf, sizeof(buf)); /* desc */
......
201 201
        case CODEC_ID_COOK:
202 202
        case CODEC_ID_ATRAC3:
203 203
        case CODEC_ID_SIPR:
204
            get_be16(pb); get_byte(pb);
204
            avio_rb16(pb); avio_r8(pb);
205 205
            if (version == 5)
206
                get_byte(pb);
207
            codecdata_length = get_be32(pb);
206
                avio_r8(pb);
207
            codecdata_length = avio_rb32(pb);
208 208
            if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
209 209
                av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
210 210
                return -1;
......
236 236
            av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h);
237 237
            break;
238 238
        case CODEC_ID_AAC:
239
            get_be16(pb); get_byte(pb);
239
            avio_rb16(pb); avio_r8(pb);
240 240
            if (version == 5)
241
                get_byte(pb);
242
            codecdata_length = get_be32(pb);
241
                avio_r8(pb);
242
            codecdata_length = avio_rb32(pb);
243 243
            if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
244 244
                av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
245 245
                return -1;
246 246
            }
247 247
            if (codecdata_length >= 1) {
248
                get_byte(pb);
248
                avio_r8(pb);
249 249
                if ((ret = rm_read_extradata(pb, st->codec, codecdata_length - 1)) < 0)
250 250
                    return ret;
251 251
            }
......
254 254
            av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name));
255 255
        }
256 256
        if (read_all) {
257
            get_byte(pb);
258
            get_byte(pb);
259
            get_byte(pb);
257
            avio_r8(pb);
258
            avio_r8(pb);
259
            avio_r8(pb);
260 260
            rm_read_metadata(s, 0);
261 261
        }
262 262
    }
......
274 274

  
275 275
    av_set_pts_info(st, 64, 1, 1000);
276 276
    codec_pos = url_ftell(pb);
277
    v = get_be32(pb);
277
    v = avio_rb32(pb);
278 278
    if (v == MKTAG(0xfd, 'a', 'r', '.')) {
279 279
        /* ra type header */
280 280
        if (rm_read_audio_stream_info(s, pb, st, rst, 0))
281 281
            return -1;
282 282
    } else {
283 283
        int fps, fps2;
284
        if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
284
        if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) {
285 285
        fail1:
286 286
            av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
287 287
            goto skip;
288 288
        }
289
        st->codec->codec_tag = get_le32(pb);
289
        st->codec->codec_tag = avio_rl32(pb);
290 290
        st->codec->codec_id  = ff_codec_get_id(ff_rm_codec_tags,
291 291
                                               st->codec->codec_tag);
292 292
//        av_log(s, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
293 293
        if (st->codec->codec_id == CODEC_ID_NONE)
294 294
            goto fail1;
295
        st->codec->width = get_be16(pb);
296
        st->codec->height = get_be16(pb);
295
        st->codec->width = avio_rb16(pb);
296
        st->codec->height = avio_rb16(pb);
297 297
        st->codec->time_base.num= 1;
298
        fps= get_be16(pb);
298
        fps= avio_rb16(pb);
299 299
        st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
300
        get_be32(pb);
301
        fps2= get_be16(pb);
302
        get_be16(pb);
300
        avio_rb32(pb);
301
        fps2= avio_rb16(pb);
302
        avio_rb16(pb);
303 303

  
304 304
        if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (url_ftell(pb) - codec_pos))) < 0)
305 305
            return ret;
......
335 335
    AVStream *st;
336 336

  
337 337
    do {
338
        if (get_le32(pb) != MKTAG('I','N','D','X'))
338
        if (avio_rl32(pb) != MKTAG('I','N','D','X'))
339 339
            return -1;
340
        size     = get_be32(pb);
340
        size     = avio_rb32(pb);
341 341
        if (size < 20)
342 342
            return -1;
343 343
        url_fskip(pb, 2);
344
        n_pkts   = get_be32(pb);
345
        str_id   = get_be16(pb);
346
        next_off = get_be32(pb);
344
        n_pkts   = avio_rb32(pb);
345
        str_id   = avio_rb16(pb);
346
        next_off = avio_rb32(pb);
347 347
        for (n = 0; n < s->nb_streams; n++)
348 348
            if (s->streams[n]->id == str_id) {
349 349
                st = s->streams[n];
......
354 354

  
355 355
        for (n = 0; n < n_pkts; n++) {
356 356
            url_fskip(pb, 2);
357
            pts = get_be32(pb);
358
            pos = get_be32(pb);
357
            pts = avio_rb32(pb);
358
            pos = avio_rb32(pb);
359 359
            url_fskip(pb, 4); /* packet no. */
360 360

  
361 361
            av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);
......
395 395
    char buf[128];
396 396
    int flags = 0;
397 397

  
398
    tag = get_le32(pb);
398
    tag = avio_rl32(pb);
399 399
    if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
400 400
        /* very old .ra format */
401 401
        return rm_read_header_old(s, ap);
......
403 403
        return AVERROR(EIO);
404 404
    }
405 405

  
406
    get_be32(pb); /* header size */
407
    get_be16(pb);
408
    get_be32(pb);
409
    get_be32(pb); /* number of headers */
406
    avio_rb32(pb); /* header size */
407
    avio_rb16(pb);
408
    avio_rb32(pb);
409
    avio_rb32(pb); /* number of headers */
410 410

  
411 411
    for(;;) {
412 412
        if (url_feof(pb))
413 413
            return -1;
414
        tag = get_le32(pb);
415
        tag_size = get_be32(pb);
416
        get_be16(pb);
414
        tag = avio_rl32(pb);
415
        tag_size = avio_rb32(pb);
416
        avio_rb16(pb);
417 417
#if 0
418 418
        printf("tag=%c%c%c%c (%08x) size=%d\n",
419 419
               (tag) & 0xff,
......
428 428
        switch(tag) {
429 429
        case MKTAG('P', 'R', 'O', 'P'):
430 430
            /* file header */
431
            get_be32(pb); /* max bit rate */
432
            get_be32(pb); /* avg bit rate */
433
            get_be32(pb); /* max packet size */
434
            get_be32(pb); /* avg packet size */
435
            get_be32(pb); /* nb packets */
436
            get_be32(pb); /* duration */
437
            get_be32(pb); /* preroll */
438
            indx_off = get_be32(pb); /* index offset */
439
            data_off = get_be32(pb); /* data offset */
440
            get_be16(pb); /* nb streams */
441
            flags = get_be16(pb); /* flags */
431
            avio_rb32(pb); /* max bit rate */
432
            avio_rb32(pb); /* avg bit rate */
433
            avio_rb32(pb); /* max packet size */
434
            avio_rb32(pb); /* avg packet size */
435
            avio_rb32(pb); /* nb packets */
436
            avio_rb32(pb); /* duration */
437
            avio_rb32(pb); /* preroll */
438
            indx_off = avio_rb32(pb); /* index offset */
439
            data_off = avio_rb32(pb); /* data offset */
440
            avio_rb16(pb); /* nb streams */
441
            flags = avio_rb16(pb); /* flags */
442 442
            break;
443 443
        case MKTAG('C', 'O', 'N', 'T'):
444 444
            rm_read_metadata(s, 1);
......
447 447
            st = av_new_stream(s, 0);
448 448
            if (!st)
449 449
                return AVERROR(ENOMEM);
450
            st->id = get_be16(pb);
451
            get_be32(pb); /* max bit rate */
452
            st->codec->bit_rate = get_be32(pb); /* bit rate */
453
            get_be32(pb); /* max packet size */
454
            get_be32(pb); /* avg packet size */
455
            start_time = get_be32(pb); /* start time */
456
            get_be32(pb); /* preroll */
457
            duration = get_be32(pb); /* duration */
450
            st->id = avio_rb16(pb);
451
            avio_rb32(pb); /* max bit rate */
452
            st->codec->bit_rate = avio_rb32(pb); /* bit rate */
453
            avio_rb32(pb); /* max packet size */
454
            avio_rb32(pb); /* avg packet size */
455
            start_time = avio_rb32(pb); /* start time */
456
            avio_rb32(pb); /* preroll */
457
            duration = avio_rb32(pb); /* duration */
458 458
            st->start_time = start_time;
459 459
            st->duration = duration;
460 460
            get_str8(pb, buf, sizeof(buf)); /* desc */
......
462 462
            st->codec->codec_type = AVMEDIA_TYPE_DATA;
463 463
            st->priv_data = ff_rm_alloc_rmstream();
464 464
            if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
465
                                          get_be32(pb)) < 0)
465
                                          avio_rb32(pb)) < 0)
466 466
                return -1;
467 467
            break;
468 468
        case MKTAG('D', 'A', 'T', 'A'):
......
474 474
        }
475 475
    }
476 476
 header_end:
477
    rm->nb_packets = get_be32(pb); /* number of packets */
477
    rm->nb_packets = avio_rb32(pb); /* number of packets */
478 478
    if (!rm->nb_packets && (flags & 4))
479 479
        rm->nb_packets = 3600 * 25;
480
    get_be32(pb); /* next data header */
480
    avio_rb32(pb); /* next data header */
481 481

  
482 482
    if (!data_off)
483 483
        data_off = url_ftell(pb) - 18;
......
494 494
{
495 495
    int n, n1;
496 496

  
497
    n = get_be16(pb);
497
    n = avio_rb16(pb);
498 498
    (*len)-=2;
499 499
    n &= 0x7FFF;
500 500
    if (n >= 0x4000) {
501 501
        return n - 0x4000;
502 502
    } else {
503
        n1 = get_be16(pb);
503
        n1 = avio_rb16(pb);
504 504
        (*len)-=2;
505 505
        return (n << 16) | n1;
506 506
    }
......
524 524
            *timestamp = AV_NOPTS_VALUE;
525 525
            *flags= 0;
526 526
        }else{
527
            state= (state<<8) + get_byte(pb);
527
            state= (state<<8) + avio_r8(pb);
528 528

  
529 529
            if(state == MKBETAG('I', 'N', 'D', 'X')){
530 530
                int n_pkts, expected_len;
531
                len = get_be32(pb);
531
                len = avio_rb32(pb);
532 532
                url_fskip(pb, 2);
533
                n_pkts = get_be32(pb);
533
                n_pkts = avio_rb32(pb);
534 534
                expected_len = 20 + n_pkts * 14;
535 535
                if (len == 20)
536 536
                    /* some files don't add index entries to chunk size... */
......
553 553
            len=state - 12;
554 554
            state= 0xFFFFFFFF;
555 555

  
556
            num = get_be16(pb);
557
            *timestamp = get_be32(pb);
558
            get_byte(pb); /* reserved */
559
            *flags = get_byte(pb); /* flags */
556
            num = avio_rb16(pb);
557
            *timestamp = avio_rb32(pb);
558
            avio_r8(pb); /* reserved */
559
            *flags = avio_r8(pb); /* flags */
560 560
        }
561 561
        for(i=0;i<s->nb_streams;i++) {
562 562
            st = s->streams[i];
......
584 584
    int hdr, seq, pic_num, len2, pos;
585 585
    int type;
586 586

  
587
    hdr = get_byte(pb); len--;
587
    hdr = avio_r8(pb); len--;
588 588
    type = hdr >> 6;
589 589

  
590 590
    if(type != 3){  // not frame as a part of packet
591
        seq = get_byte(pb); len--;
591
        seq = avio_r8(pb); len--;
592 592
    }
593 593
    if(type != 1){  // not whole frame
594 594
        len2 = get_num(pb, &len);
595 595
        pos  = get_num(pb, &len);
596
        pic_num = get_byte(pb); len--;
596
        pic_num = avio_r8(pb); len--;
597 597
    }
598 598
    if(len<0)
599 599
        return -1;
......
609 609
        pkt->data[0] = 0;
610 610
        AV_WL32(pkt->data + 1, 1);
611 611
        AV_WL32(pkt->data + 5, 0);
612
        get_buffer(pb, pkt->data + 9, len);
612
        avio_read(pb, pkt->data + 9, len);
613 613
        return 0;
614 614
    }
615 615
    //now we have to deal with single slice
......
635 635
    AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);
636 636
    if(vst->videobufpos + len > vst->videobufsize)
637 637
        return 1;
638
    if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len)
638
    if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len)
639 639
        return AVERROR(EIO);
640 640
    vst->videobufpos += len;
641 641
    rm->remaining_len-= len;
......
730 730
            switch(st->codec->codec_id) {
731 731
                case CODEC_ID_RA_288:
732 732
                    for (x = 0; x < h/2; x++)
733
                        get_buffer(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
733
                        avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs);
734 734
                    break;
735 735
                case CODEC_ID_ATRAC3:
736 736
                case CODEC_ID_COOK:
737 737
                    for (x = 0; x < w/sps; x++)
738
                        get_buffer(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
738
                        avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
739 739
                    break;
740 740
                case CODEC_ID_SIPR:
741
                    get_buffer(pb, ast->pkt.data + y * w, w);
741
                    avio_read(pb, ast->pkt.data + y * w, w);
742 742
                    break;
743 743
            }
744 744

  
......
753 753
        } else if (st->codec->codec_id == CODEC_ID_AAC) {
754 754
            int x;
755 755
            rm->audio_stream_num = st->index;
756
            ast->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4;
756
            ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;
757 757
            if (ast->sub_packet_cnt) {
758 758
                for (x = 0; x < ast->sub_packet_cnt; x++)
759
                    ast->sub_packet_lengths[x] = get_be16(pb);
759
                    ast->sub_packet_lengths[x] = avio_rb16(pb);
760 760
                rm->audio_pkt_cnt = ast->sub_packet_cnt;
761 761
                ast->audiotimestamp = timestamp;
762 762
            } else
......
916 916

  
917 917
        st = s->streams[stream_index2];
918 918
        if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
919
            h= get_byte(s->pb); len--;
919
            h= avio_r8(s->pb); len--;
920 920
            if(!(h & 0x40)){
921
                seq = get_byte(s->pb); len--;
921
                seq = avio_r8(s->pb); len--;
922 922
            }
923 923
        }
924 924

  

Also available in: Unified diff