Revision eabb8ba4 libavformat/matroskadec.c

View differences:

libavformat/matroskadec.c
79 79
        bitdepth,
80 80
        internal_samplerate,
81 81
        samplerate;
82
    int block_align;
83

  
84
    /* real audio header */
85
    int coded_framesize;
86
    int sub_packet_h;
87
    int frame_size;
88
    int sub_packet_size;
89
    int sub_packet_cnt;
90
    int pkt_cnt;
91
    uint8_t *buf;
82 92
    //..
83 93
} MatroskaAudioTrack;
84 94

  
......
2103 2113
                track->flags |= MATROSKA_TRACK_REAL_V;
2104 2114
            }
2105 2115

  
2116
            else if (codec_id == CODEC_ID_RA_144) {
2117
                MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
2118
                audiotrack->samplerate = 8000;
2119
                audiotrack->channels = 1;
2120
            }
2121

  
2122
            else if (codec_id == CODEC_ID_RA_288 ||
2123
                     codec_id == CODEC_ID_COOK ||
2124
                     codec_id == CODEC_ID_ATRAC3) {
2125
                MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
2126
                ByteIOContext b;
2127

  
2128
                init_put_byte(&b, track->codec_priv, track->codec_priv_size, 0,
2129
                              NULL, NULL, NULL, NULL);
2130
                url_fskip(&b, 24);
2131
                audiotrack->coded_framesize = get_be32(&b);
2132
                url_fskip(&b, 12);
2133
                audiotrack->sub_packet_h    = get_be16(&b);
2134
                audiotrack->frame_size      = get_be16(&b);
2135
                audiotrack->sub_packet_size = get_be16(&b);
2136
                audiotrack->buf = av_malloc(audiotrack->frame_size * audiotrack->sub_packet_h);
2137
                if (codec_id == CODEC_ID_RA_288) {
2138
                    audiotrack->block_align = audiotrack->coded_framesize;
2139
                    track->codec_priv_size = 0;
2140
                } else {
2141
                    audiotrack->block_align = audiotrack->sub_packet_size;
2142
                    extradata_offset = 78;
2143
                    track->codec_priv_size -= extradata_offset;
2144
                }
2145
            }
2146

  
2106 2147
            if (codec_id == CODEC_ID_NONE) {
2107 2148
                av_log(matroska->ctx, AV_LOG_INFO,
2108 2149
                       "Unknown/unsupported CodecID %s.\n",
......
2159 2200
                st->codec->codec_type = CODEC_TYPE_AUDIO;
2160 2201
                st->codec->sample_rate = audiotrack->samplerate;
2161 2202
                st->codec->channels = audiotrack->channels;
2203
                st->codec->block_align = audiotrack->block_align;
2162 2204
            } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) {
2163 2205
                st->codec->codec_type = CODEC_TYPE_SUBTITLE;
2164 2206
            }
......
2347 2389
                    slice_size = lace_size[n] - slice_offset;
2348 2390
                else
2349 2391
                    slice_size = rv_offset(data, slice+1, slices) - slice_offset;
2392

  
2393
                if (st->codec->codec_id == CODEC_ID_RA_288 ||
2394
                    st->codec->codec_id == CODEC_ID_COOK ||
2395
                    st->codec->codec_id == CODEC_ID_ATRAC3) {
2396
                    MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)matroska->tracks[track];
2397
                    int a = st->codec->block_align;
2398
                    int sps = audiotrack->sub_packet_size;
2399
                    int cfs = audiotrack->coded_framesize;
2400
                    int h = audiotrack->sub_packet_h;
2401
                    int y = audiotrack->sub_packet_cnt;
2402
                    int w = audiotrack->frame_size;
2403
                    int x;
2404

  
2405
                    if (!audiotrack->pkt_cnt) {
2406
                        if (st->codec->codec_id == CODEC_ID_RA_288)
2407
                            for (x=0; x<h/2; x++)
2408
                                memcpy(audiotrack->buf+x*2*w+y*cfs,
2409
                                       data+x*cfs, cfs);
2410
                        else
2411
                            for (x=0; x<w/sps; x++)
2412
                                memcpy(audiotrack->buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps);
2413

  
2414
                        if (++audiotrack->sub_packet_cnt >= h) {
2415
                            audiotrack->sub_packet_cnt = 0;
2416
                            audiotrack->pkt_cnt = h*w / a;
2417
                        }
2418
                    }
2419
                    while (audiotrack->pkt_cnt) {
2420
                        pkt = av_mallocz(sizeof(AVPacket));
2421
                        av_new_packet(pkt, a);
2422
                        memcpy(pkt->data, audiotrack->buf
2423
                               + a * (h*w / a - audiotrack->pkt_cnt--), a);
2424
                        pkt->pos = pos;
2425
                        pkt->stream_index = matroska->tracks[track]->stream_index;
2426
                        matroska_queue_packet(matroska, pkt);
2427
                    }
2428
                } else {
2350 2429
                pkt = av_mallocz(sizeof(AVPacket));
2351 2430
                /* XXX: prevent data copy... */
2352 2431
                if (av_new_packet(pkt, slice_size) < 0) {
......
2365 2444
                pkt->duration = duration;
2366 2445

  
2367 2446
                matroska_queue_packet(matroska, pkt);
2447
                }
2368 2448

  
2369 2449
                if (timecode != AV_NOPTS_VALUE)
2370 2450
                    timecode = duration ? timecode + duration : AV_NOPTS_VALUE;
......
2625 2705
        av_free(track->name);
2626 2706
        av_free(track->language);
2627 2707

  
2708
        if (track->type == MATROSKA_TRACK_TYPE_AUDIO) {
2709
            MatroskaAudioTrack *audiotrack = (MatroskaAudioTrack *)track;
2710
            av_free(audiotrack->buf);
2711
        }
2712

  
2628 2713
        av_free(track);
2629 2714
    }
2630 2715

  

Also available in: Unified diff