Revision fce48f5b libavformat/rmdec.c

View differences:

libavformat/rmdec.c
24 24
#include "rm.h"
25 25

  
26 26
struct RMStream {
27
    uint8_t *videobuf; ///< place to store merged video frame
27
    uint8_t *buf; ///< place to store merged video frame / reordered audio data
28 28
    int videobufsize;  ///< current assembled frame size
29 29
    int videobufpos;   ///< position for the next slice in the video buffer
30 30
    int curpic_num;    ///< picture number of current frame
31 31
    int cur_slice, slices;
32 32
    int64_t pktpos;    ///< first slice position in file
33 33
    /// Audio descrambling matrix parameters
34
    uint8_t *audiobuf; ///< place to store reordered audio data
35 34
    int64_t audiotimestamp; ///< Audio packet timestamp
36 35
    int sub_packet_cnt; // Subpacket counter, used while reading
37 36
    int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
......
81 80

  
82 81
void ff_rm_free_rmstream (RMStream *rms)
83 82
{
84
    av_freep(&rms->videobuf);
85
    av_freep(&rms->audiobuf);
83
    av_freep(&rms->buf);
86 84
}
87 85

  
88 86
static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb,
......
157 155
                return -1;
158 156
            }
159 157

  
160
            ast->audiobuf = av_malloc(ast->audio_framesize * sub_packet_h);
158
            ast->buf = av_malloc(ast->audio_framesize * sub_packet_h);
161 159
        } else if ((!strcmp(buf, "cook")) || (!strcmp(buf, "atrc")) || (!strcmp(buf, "sipr"))) {
162 160
            int codecdata_length;
163 161
            get_be16(pb); get_byte(pb);
......
188 186
                return -1;
189 187
            }
190 188

  
191
            ast->audiobuf = av_malloc(ast->audio_framesize * sub_packet_h);
189
            ast->buf = av_malloc(ast->audio_framesize * sub_packet_h);
192 190
        } else if (!strcmp(buf, "raac") || !strcmp(buf, "racp")) {
193 191
            int codecdata_length;
194 192
            get_be16(pb); get_byte(pb);
......
523 521
    if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
524 522
        vst->slices = ((hdr & 0x3F) << 1) + 1;
525 523
        vst->videobufsize = len2 + 8*vst->slices + 1;
526
        av_free(vst->videobuf);
527
        if(!(vst->videobuf = av_malloc(vst->videobufsize)))
524
        av_free(vst->buf);
525
        if(!(vst->buf = av_malloc(vst->videobufsize)))
528 526
            return AVERROR(ENOMEM);
529 527
        vst->videobufpos = 8*vst->slices + 1;
530 528
        vst->cur_slice = 0;
......
536 534

  
537 535
    if(++vst->cur_slice > vst->slices)
538 536
        return 1;
539
    AV_WL32(vst->videobuf - 7 + 8*vst->cur_slice, 1);
540
    AV_WL32(vst->videobuf - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);
537
    AV_WL32(vst->buf - 7 + 8*vst->cur_slice, 1);
538
    AV_WL32(vst->buf - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);
541 539
    if(vst->videobufpos + len > vst->videobufsize)
542 540
        return 1;
543
    if (get_buffer(pb, vst->videobuf + vst->videobufpos, len) != len)
541
    if (get_buffer(pb, vst->buf + vst->videobufpos, len) != len)
544 542
        return AVERROR(EIO);
545 543
    vst->videobufpos += len;
546 544
    rm->remaining_len-= len;
547 545

  
548 546
    if(type == 2 || (vst->videobufpos) == vst->videobufsize){
549
         vst->videobuf[0] = vst->cur_slice-1;
547
         vst->buf[0] = vst->cur_slice-1;
550 548
         if(av_new_packet(pkt, vst->videobufpos - 8*(vst->slices - vst->cur_slice)) < 0)
551 549
             return AVERROR(ENOMEM);
552
         memcpy(pkt->data, vst->videobuf, 1 + 8*vst->cur_slice);
553
         memcpy(pkt->data + 1 + 8*vst->cur_slice, vst->videobuf + 1 + 8*vst->slices,
550
         memcpy(pkt->data, vst->buf, 1 + 8*vst->cur_slice);
551
         memcpy(pkt->data + 1 + 8*vst->cur_slice, vst->buf + 1 + 8*vst->slices,
554 552
                vst->videobufpos - 1 - 8*vst->slices);
555 553
         pkt->pts = AV_NOPTS_VALUE;
556 554
         pkt->pos = vst->pktpos;
......
606 604
            switch(st->codec->codec_id) {
607 605
                case CODEC_ID_RA_288:
608 606
                    for (x = 0; x < h/2; x++)
609
                        get_buffer(pb, ast->audiobuf+x*2*w+y*cfs, cfs);
607
                        get_buffer(pb, ast->buf+x*2*w+y*cfs, cfs);
610 608
                    break;
611 609
                case CODEC_ID_ATRAC3:
612 610
                case CODEC_ID_COOK:
613 611
                    for (x = 0; x < w/sps; x++)
614
                        get_buffer(pb, ast->audiobuf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
612
                        get_buffer(pb, ast->buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
615 613
                    break;
616 614
            }
617 615

  
......
623 621
                rm->audio_pkt_cnt = h * w / st->codec->block_align - 1;
624 622
                // Release first audio packet
625 623
                av_new_packet(pkt, st->codec->block_align);
626
                memcpy(pkt->data, ast->audiobuf, st->codec->block_align);
624
                memcpy(pkt->data, ast->buf, st->codec->block_align);
627 625
                *timestamp = ast->audiotimestamp;
628 626
                *flags = 2; // Mark first packet as keyframe
629 627
            }
......
686 684
        av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);
687 685
    else {
688 686
        av_new_packet(pkt, st->codec->block_align);
689
        memcpy(pkt->data, ast->audiobuf + st->codec->block_align *
687
        memcpy(pkt->data, ast->buf + st->codec->block_align *
690 688
               (ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
691 689
               st->codec->block_align);
692 690
    }
......
720 718

  
721 719
            for (y = 0; y < ast->sub_packet_h; y++)
722 720
                for (x = 0; x < ast->sub_packet_h/2; x++)
723
                    if (get_buffer(pb, ast->audiobuf+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0)
721
                    if (get_buffer(pb, ast->buf+x*2*ast->audio_framesize+y*ast->coded_framesize, ast->coded_framesize) <= 0)
724 722
                        return AVERROR(EIO);
725 723
            rm->audio_stream_num = 0;
726 724
            rm->audio_pkt_cnt = ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - 1;
727 725
            // Release first audio packet
728 726
            av_new_packet(pkt, st->codec->block_align);
729
            memcpy(pkt->data, ast->audiobuf, st->codec->block_align);
727
            memcpy(pkt->data, ast->buf, st->codec->block_align);
730 728
            pkt->flags |= PKT_FLAG_KEY; // Mark first packet as keyframe
731 729
            pkt->stream_index = 0;
732 730
        } else {

Also available in: Unified diff