Revision 725d86bf libavcodec/pcm.c

View differences:

libavcodec/pcm.c
28 28
#include "bitstream.h" // for ff_reverse
29 29
#include "bytestream.h"
30 30

  
31
#define MAX_CHANNELS 64
32

  
31 33
/* from g711.c by SUN microsystems (unrestricted use) */
32 34

  
33 35
#define         SIGN_BIT        (0x80)      /* Sign bit for a A-law byte. */
......
374 376
                            uint8_t *buf, int buf_size)
375 377
{
376 378
    PCMDecode *s = avctx->priv_data;
377
    int n;
379
    int c, n;
378 380
    short *samples;
379
    uint8_t *src;
381
    uint8_t *src, *src2[MAX_CHANNELS];
380 382

  
381 383
    samples = data;
382 384
    src = buf;
383 385

  
384 386
    n= av_get_bits_per_sample(avctx->codec_id)/8;
385
    if(n && buf_size % n){
387
    if((n && buf_size % n) || avctx->channels > MAX_CHANNELS){
386 388
        av_log(avctx, AV_LOG_ERROR, "invalid PCM packet\n");
387 389
        return -1;
388 390
    }
......
390 392
    buf_size= FFMIN(buf_size, *data_size/2);
391 393
    *data_size=0;
392 394

  
395
    n = buf_size/avctx->channels;
396
    for(c=0;c<avctx->channels;c++)
397
        src2[c] = &src[c*n];
398

  
393 399
    switch(avctx->codec->id) {
394 400
    case CODEC_ID_PCM_S32LE:
395 401
        decode_to16(4, 1, 0, &src, &samples, buf_size);
......
430 436
            *samples++ = bytestream_get_le16(&src);
431 437
        }
432 438
        break;
439
    case CODEC_ID_PCM_S16LE_PLANAR:
440
        for(n>>=1;n>0;n--)
441
            for(c=0;c<avctx->channels;c++)
442
                *samples++ = bytestream_get_le16(&src2[c]);
443
        src = src2[avctx->channels-1];
444
        break;
433 445
    case CODEC_ID_PCM_S16BE:
434 446
        n = buf_size >> 1;
435 447
        for(;n>0;n--) {
......
528 540
PCM_CODEC(CODEC_ID_PCM_U24BE, pcm_u24be);
529 541
PCM_CODEC(CODEC_ID_PCM_S24DAUD, pcm_s24daud);
530 542
PCM_CODEC(CODEC_ID_PCM_S16LE, pcm_s16le);
543
PCM_DECODER(CODEC_ID_PCM_S16LE_PLANAR, pcm_s16le_planar);
531 544
PCM_CODEC(CODEC_ID_PCM_S16BE, pcm_s16be);
532 545
PCM_CODEC(CODEC_ID_PCM_U16LE, pcm_u16le);
533 546
PCM_CODEC(CODEC_ID_PCM_U16BE, pcm_u16be);

Also available in: Unified diff