[FFmpeg-devel] [PATCH] avcodec/alsdec: implement floating point decoding

Umair Khan omerjerk at gmail.com
Wed Jul 27 06:35:51 EEST 2016


On Tue, Jul 26, 2016 at 4:52 AM, Michael Niedermayer
<michael at niedermayer.cc> wrote:
> On Mon, Jul 25, 2016 at 10:13:38PM +0530, Umair Khan wrote:
>> On Sun, Jul 24, 2016 at 1:47 AM, Umair Khan <omerjerk at gmail.com> wrote:
>> >
>> > HI,
>> >
>> > On Fri, Jul 22, 2016 at 9:19 PM, Michael Niedermayer
>> > <michael at niedermayer.cc> wrote:
>> > > On Fri, Jul 22, 2016 at 06:22:30PM +0530, Umair Khan wrote:
>> > >> On Thu, Jul 21, 2016 at 6:18 PM, Michael Niedermayer
>> > >> <michael at niedermayer.cc> wrote:
>> > >> > On Sun, Jul 17, 2016 at 12:06:03AM +0530, Umair Khan wrote:
>> > > [...]
>> > >> >> +static int decode_string(MLZDict *dict, unsigned char *buff, int string_code, int *first_char_code, unsigned long bufsize) {
>> > >> >> +    unsigned long count, offset;
>> > >> >> +    int current_code, parent_code, tmp_code;
>> > >> >> +
>> > >> >> +    count            = 0;
>> > >> >> +    current_code     = string_code;
>> > >> >> +    *first_char_code = CODE_UNSET;
>> > >> >> +
>> > >> >> +    while (count < bufsize) {
>> > >> >> +        switch (current_code) {
>> > >> >> +        case CODE_UNSET:
>> > >> >> +            return count;
>> > >> >> +            break;
>> > >> >> +        default:
>> > >> >> +            if (current_code < FIRST_CODE) {
>> > >> >> +                *first_char_code = current_code;
>> > >> >> +                buff[0] = current_code;
>> > >> >> +                count++;
>> > >> >> +                return count;
>> > >> >> +            } else {
>> > >> >> +                offset  = dict[current_code].match_len - 1;
>> > >> >> +                tmp_code = dict[current_code].char_code;
>> > >> >> +                buff[offset] = tmp_code;
>> > >> >> +                count++;
>> > >> >> +            }
>> > >> >> +            current_code = dict[current_code].parent_code;
>> > >> >> +            if ((current_code < 0) || (current_code > (DIC_INDEX_MAX - 1))) {
>> > >> >
>> > >> >> +                av_log(NULL, AV_LOG_ERROR, "MLZ dic index error.\n");
>> > >> >
>> > >> > it would be ideal if all av_log() would have a context instead of NULL
>> > >>
>> > >> How to go ahead with this? Should I create MLZContext or something? If
>> > >> yes, could you please tell how?
>> > >
>> > > possible or you pass a void *context
>> >
>> > Updated patch.
>>
>> Another revision. Fixes some things I had overlooked.
>>
>> - Umair
>
>>  Changelog                     |    3
>>  libavcodec/Makefile           |    2
>>  libavcodec/alsdec.c           |  286 +++++++++++++++++++++++++++++++++++++++++-
>>  libavcodec/mlz.c              |  173 +++++++++++++++++++++++++
>>  libavcodec/mlz.h              |   70 ++++++++++
>>  libavutil/softfloat_ieee754.h |  115 ++++++++++++++++
>>  6 files changed, 646 insertions(+), 3 deletions(-)
>> 66dd916fe5b2e98b30aed21f4cf656b66c51ce1f  0001-avcodec-alsdec-implement-floating-point-decoding.patch
>> From 44567b208cf0b697a4403420bc3f7ba0cebabbc1 Mon Sep 17 00:00:00 2001
>> From: Umair Khan <omerjerk at gmail.com>
>> Date: Sun, 24 Jul 2016 00:28:55 +0530
>> Subject: [PATCH 1/1] avcodec/alsdec: implement floating point decoding
>>
>> It conforms to RM22 version of the reference codec.
>
> gcc generates these warnings:
>
> libavcodec/mlz.c: In function ‘ff_mlz_decompression’:
> libavcodec/mlz.c:152:25: warning: passing argument 1 of ‘decode_string’ from incompatible pointer type [enabled by default]
> libavcodec/mlz.c:61:12: note: expected ‘struct MLZ *’ but argument is of type ‘struct MLZDict *’
> libavcodec/mlz.c:153:25: warning: passing argument 1 of ‘decode_string’ from incompatible pointer type [enabled by default]
> libavcodec/mlz.c:61:12: note: expected ‘struct MLZ *’ but argument is of type ‘struct MLZDict *’
> libavcodec/mlz.c:157:25: warning: passing argument 1 of ‘decode_string’ from incompatible pointer type [enabled by default]

Fixed.

> [...]
>> +
>> +/** Read and decode the floating point sample data
>> + */
>> +static int read_diff_float_data(ALSDecContext *ctx, unsigned int ra_frame) {
>> +    AVCodecContext *avctx   = ctx->avctx;
>> +    GetBitContext *gb       = &ctx->gb;
>> +    SoftFloat_IEEE754 *acf  = ctx->acf;
>> +    int *shift_value        = ctx->shift_value;
>> +    int *last_shift_value   = ctx->last_shift_value;
>> +    int *last_acf_mantissa  = ctx->last_acf_mantissa;
>> +    int **raw_mantissa      = ctx->raw_mantissa;
>> +    int *nbits              = ctx->nbits;
>> +    unsigned char *larray   = ctx->larray;
>> +    int frame_length        = ctx->cur_frame_length;
>> +    SoftFloat_IEEE754 scale = av_int2sf_ieee754(0x1u, 23);
>> +    unsigned int partA_flag;
>> +    unsigned int highest_byte;
>> +    unsigned int shift_amp;
>> +    uint32_t tmp_32;
>> +    int use_acf;
>> +    int nchars;
>> +    int i;
>> +    int c;
>> +    long k;
>> +    long nbits_aligned;
>> +    unsigned long acc;
>> +    unsigned long j;
>> +    uint32_t sign;
>> +    uint32_t e;
>> +    uint32_t mantissa;
>> +
>> +    skip_bits_long(gb, 32); //num_bytes_diff_float
>> +    use_acf = get_bits1(gb);
>> +
>> +    if (ra_frame) {
>
>> +        memset(last_acf_mantissa, 0, sizeof(last_acf_mantissa));
>> +        memset(last_shift_value,  0, sizeof(last_shift_value) );
>
> the sizeof look a bit strange, these are not the allocated array sizes

Taken care of.

> [...]
>> @@ -1678,6 +1931,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
>>  {
>>      unsigned int c;
>>      unsigned int channel_size;
>> +    unsigned int i;
>>      int num_buffers, ret;
>>      ALSDecContext *ctx = avctx->priv_data;
>>      ALSSpecificConfig *sconf = &ctx->sconf;
>> @@ -1803,6 +2057,34 @@ static av_cold int decode_init(AVCodecContext *avctx)
>>      ctx->raw_buffer       = av_mallocz_array(avctx->channels * channel_size, sizeof(*ctx->raw_buffer));
>>      ctx->raw_samples      = av_malloc_array(avctx->channels, sizeof(*ctx->raw_samples));
>>
>> +    if (sconf->floating) {
>> +        ctx->acf               = av_malloc_array(avctx->channels, sizeof(*ctx->acf));
>> +        ctx->shift_value       = av_malloc_array(avctx->channels, sizeof(*ctx->shift_value));
>> +        ctx->last_shift_value  = av_malloc_array(avctx->channels, sizeof(*ctx->last_shift_value));
>> +        ctx->last_acf_mantissa = av_malloc_array(avctx->channels, sizeof(*ctx->last_acf_mantissa));
>> +        ctx->raw_mantissa      = av_malloc_array(avctx->channels, sizeof(*ctx->raw_mantissa));
>> +
>> +        for (c = 0; c < avctx->channels; ++c) {
>> +            ctx->raw_mantissa[c] = av_malloc_array(ctx->cur_frame_length, sizeof(**ctx->raw_mantissa));
>
> using ctx->raw_mantissa without prior malloc failure check

Should I keep this in a separate patch? It is unrelated to my patch.

Updated patch attached.

- Umair
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avcodec-alsdec-implement-floating-point-decoding.patch
Type: application/octet-stream
Size: 28173 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160727/8e4fecf4/attachment.obj>


More information about the ffmpeg-devel mailing list