On Tue, Mar 24, 2015 at 7:35 AM, Anton Khirnov <[email protected]> wrote:
> Quoting Hendrik Leppkes (2015-03-23 12:45:19)
>> diff --git a/libavcodec/libdcadec.c b/libavcodec/libdcadec.c
>> new file mode 100644
>> index 0000000..7ca8942
>> --- /dev/null
>> +++ b/libavcodec/libdcadec.c
>> @@ -0,0 +1,197 @@
>> +/*
>> + * libdcadec decoder wrapper
>> + * Copyright (C) 2015 Hendrik Leppkes
>> + *
>> + * This file is part of FFmpeg.
>> + *
>> + * FFmpeg is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU Lesser General Public
>> + * License as published by the Free Software Foundation; either
>> + * version 2.1 of the License, or (at your option) any later version.
>> + *
>> + * FFmpeg is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
>> + * Lesser General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU Lesser General Public
>> + * License along with FFmpeg; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
>> USA
>> + */
>> +
>> +#include <libdcadec/dca_context.h>
>> +
>> +#include "libavutil/avassert.h"
>> +#include "libavutil/channel_layout.h"
>> +#include "libavutil/common.h"
>> +#include "libavutil/opt.h"
>> +#include "avcodec.h"
>> +#include "dca.h"
>> +#include "dca_syncwords.h"
>> +#include "internal.h"
>> +
>> +typedef struct DCADecContext {
>> +    struct dcadec_context *ctx;
>> +    uint8_t *buffer;
>> +    int buffer_size;
>> +} DCADecContext;
>> +
>> +static int dcadec_decode_frame(AVCodecContext *avctx, void *data,
>> +                               int *got_frame_ptr, AVPacket *avpkt)
>> +{
>> +    DCADecContext *s = avctx->priv_data;
>> +    AVFrame *frame = data;
>> +    int ret, i, k;
>> +    int **samples, nsamples, channel_mask, sample_rate, bits_per_sample, 
>> profile;
>> +    uint32_t mrk;
>> +    uint8_t *input = avpkt->data;
>> +    int input_size = avpkt->size;
>> +
>> +    /* convert bytestream syntax to RAW BE format if required */
>> +    mrk = AV_RB32(input);
>
> This read should be checked. The packet size can be anything positive.

As far as I know, decoders can rely on input packets being padded to
at least FF_INPUT_BUFFER_PADDING_SIZE, so this read is safe.
Other decoders do the same thing, ie. the native dca decoder. :p

>> +    } else
>> +        avctx->bit_rate = 0;
>> +
>> +    frame->nb_samples = nsamples;
>> +    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
>> +        return ret;
>> +
>> +    for (i = 0; i < avctx->channels; i++) {
>> +        if (frame->format == AV_SAMPLE_FMT_S16P) {
>> +            int16_t *plane = (int16_t *)frame->extended_data[i];
>> +            for (k = 0; k < nsamples; k++)
>> +                plane[k] = samples[i][k];
>> +        } else {
>> +            int32_t *plane = (int32_t *)frame->extended_data[i];
>> +            int shift = 32 - bits_per_sample;
>> +            for (k = 0; k < nsamples; k++)
>> +                plane[k] = samples[i][k] << shift;
>> +        }
>> +    }
>
> This looks awfully inefficient, but I guess nobody cares.
>

There doesn't seem to be a DSP function that does such a conversion,
so generic C it was.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to