LCOV - code coverage report
Current view: top level - libavcodec - interplayacm.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 336 0.0 %
Date: 2017-12-13 10:57:33 Functions: 0 21 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Interplay ACM decoder
       3             :  *
       4             :  * Copyright (c) 2004-2008 Marko Kreen
       5             :  * Copyright (c) 2008 Adam Gashlin
       6             :  * Copyright (c) 2015 Paul B Mahol
       7             :  *
       8             :  * Permission to use, copy, modify, and distribute this software for any
       9             :  * purpose with or without fee is hereby granted, provided that the above
      10             :  * copyright notice and this permission notice appear in all copies.
      11             :  *
      12             :  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      13             :  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
      14             :  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
      15             :  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
      16             :  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
      17             :  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
      18             :  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
      19             :  */
      20             : 
      21             : #include "libavutil/intreadwrite.h"
      22             : 
      23             : #define BITSTREAM_READER_LE
      24             : #include "avcodec.h"
      25             : #include "get_bits.h"
      26             : #include "internal.h"
      27             : 
      28             : static const int8_t map_1bit[]      = { -1, +1 };
      29             : static const int8_t map_2bit_near[] = { -2, -1, +1, +2 };
      30             : static const int8_t map_2bit_far[]  = { -3, -2, +2, +3 };
      31             : static const int8_t map_3bit[]      = { -4, -3, -2, -1, +1, +2, +3, +4 };
      32             : 
      33             : static int mul_3x3 [3 * 3 * 3];
      34             : static int mul_3x5 [5 * 5 * 5];
      35             : static int mul_2x11[11  *  11];
      36             : 
      37             : typedef struct InterplayACMContext {
      38             :     GetBitContext gb;
      39             :     uint8_t *bitstream;
      40             :     int max_framesize;
      41             :     int bitstream_size;
      42             :     int bitstream_index;
      43             : 
      44             :     int level;
      45             :     int rows;
      46             :     int cols;
      47             :     int wrapbuf_len;
      48             :     int block_len;
      49             :     int skip;
      50             : 
      51             :     int *block;
      52             :     int *wrapbuf;
      53             :     int *ampbuf;
      54             :     int *midbuf;
      55             : } InterplayACMContext;
      56             : 
      57           0 : static av_cold int decode_init(AVCodecContext *avctx)
      58             : {
      59           0 :     InterplayACMContext *s = avctx->priv_data;
      60             :     int x1, x2, x3;
      61             : 
      62           0 :     if (avctx->extradata_size < 14)
      63           0 :         return AVERROR_INVALIDDATA;
      64             : 
      65           0 :     if (avctx->channels <= 0) {
      66           0 :         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels: %d\n", avctx->channels);
      67           0 :         return AVERROR_INVALIDDATA;
      68             :     }
      69             : 
      70           0 :     s->level = AV_RL16(avctx->extradata + 12) & 0xf;
      71           0 :     s->rows  = AV_RL16(avctx->extradata + 12) >>  4;
      72           0 :     s->cols  = 1 << s->level;
      73           0 :     s->wrapbuf_len = 2 * s->cols - 2;
      74           0 :     s->block_len = s->rows * s->cols;
      75           0 :     s->max_framesize = s->block_len;
      76             : 
      77           0 :     s->block   = av_calloc(s->block_len, sizeof(int));
      78           0 :     s->wrapbuf = av_calloc(s->wrapbuf_len, sizeof(int));
      79           0 :     s->ampbuf  = av_calloc(0x10000, sizeof(int));
      80           0 :     s->bitstream = av_calloc(s->max_framesize + AV_INPUT_BUFFER_PADDING_SIZE / sizeof(*s->bitstream) + 1, sizeof(*s->bitstream));
      81           0 :     if (!s->block || !s->wrapbuf || !s->ampbuf || !s->bitstream)
      82           0 :         return AVERROR(ENOMEM);
      83             : 
      84           0 :     s->midbuf  = s->ampbuf + 0x8000;
      85           0 :     avctx->sample_fmt = AV_SAMPLE_FMT_S16;
      86             : 
      87           0 :     for (x3 = 0; x3 < 3; x3++)
      88           0 :         for (x2 = 0; x2 < 3; x2++)
      89           0 :             for (x1 = 0; x1 < 3; x1++)
      90           0 :                 mul_3x3[x1 + x2 * 3 + x3* 3 * 3] = x1 + (x2 << 4) + (x3 << 8);
      91           0 :     for (x3 = 0; x3 < 5; x3++)
      92           0 :         for (x2 = 0; x2 < 5; x2++)
      93           0 :             for (x1 = 0; x1 < 5; x1++)
      94           0 :                 mul_3x5[x1 + x2 * 5 + x3 * 5 * 5] = x1 + (x2 << 4) + (x3 << 8);
      95           0 :     for (x2 = 0; x2 < 11; x2++)
      96           0 :         for (x1 = 0; x1 < 11; x1++)
      97           0 :             mul_2x11[x1 + x2 * 11] = x1 + (x2 << 4);
      98             : 
      99           0 :     return 0;
     100             : }
     101             : 
     102             : #define set_pos(s, r, c, idx) do {               \
     103             :         unsigned pos = ((r) << s->level) + (c);  \
     104             :         s->block[pos] = s->midbuf[(idx)];        \
     105             :     } while (0)
     106             : 
     107           0 : static int zero(InterplayACMContext *s, unsigned ind, unsigned col)
     108             : {
     109             :     unsigned i;
     110             : 
     111           0 :     for (i = 0; i < s->rows; i++)
     112           0 :         set_pos(s, i, col, 0);
     113           0 :     return 0;
     114             : }
     115             : 
     116           0 : static int bad(InterplayACMContext *s, unsigned ind, unsigned col)
     117             : {
     118           0 :     return AVERROR_INVALIDDATA;
     119             : }
     120             : 
     121           0 : static int linear(InterplayACMContext *s, unsigned ind, unsigned col)
     122             : {
     123           0 :     GetBitContext *gb = &s->gb;
     124             :     unsigned int i;
     125           0 :     int b, middle = 1 << (ind - 1);
     126             : 
     127           0 :     for (i = 0; i < s->rows; i++) {
     128           0 :         b = get_bits(gb, ind);
     129           0 :         set_pos(s, i, col, b - middle);
     130             :     }
     131           0 :     return 0;
     132             : }
     133             : 
     134           0 : static int k13(InterplayACMContext *s, unsigned ind, unsigned col)
     135             : {
     136           0 :     GetBitContext *gb = &s->gb;
     137             :     unsigned i, b;
     138             : 
     139           0 :     for (i = 0; i < s->rows; i++) {
     140           0 :         b = get_bits1(gb);
     141           0 :         if (b == 0) {
     142           0 :             set_pos(s, i++, col, 0);
     143           0 :             if (i >= s->rows)
     144           0 :                 break;
     145           0 :             set_pos(s, i, col, 0);
     146           0 :             continue;
     147             :         }
     148           0 :         b = get_bits1(gb);
     149           0 :         if (b == 0) {
     150           0 :             set_pos(s, i, col, 0);
     151           0 :             continue;
     152             :         }
     153           0 :         b = get_bits1(gb);
     154           0 :         set_pos(s, i, col, map_1bit[b]);
     155             :     }
     156           0 :     return 0;
     157             : }
     158             : 
     159           0 : static int k12(InterplayACMContext *s, unsigned ind, unsigned col)
     160             : {
     161           0 :     GetBitContext *gb = &s->gb;
     162             :     unsigned i, b;
     163             : 
     164           0 :     for (i = 0; i < s->rows; i++) {
     165           0 :         b = get_bits1(gb);
     166           0 :         if (b == 0) {
     167           0 :             set_pos(s, i, col, 0);
     168           0 :             continue;
     169             :         }
     170             : 
     171           0 :         b = get_bits1(gb);
     172           0 :         set_pos(s, i, col, map_1bit[b]);
     173             :     }
     174           0 :     return 0;
     175             : }
     176             : 
     177           0 : static int k24(InterplayACMContext *s, unsigned ind, unsigned col)
     178             : {
     179           0 :     GetBitContext *gb = &s->gb;
     180             :     unsigned i, b;
     181             : 
     182           0 :     for (i = 0; i < s->rows; i++) {
     183           0 :         b = get_bits1(gb);
     184           0 :         if (b == 0) {
     185           0 :             set_pos(s, i++, col, 0);
     186           0 :             if (i >= s->rows) break;
     187           0 :             set_pos(s, i, col, 0);
     188           0 :             continue;
     189             :         }
     190             : 
     191           0 :         b = get_bits1(gb);
     192           0 :         if (b == 0) {
     193           0 :             set_pos(s, i, col, 0);
     194           0 :             continue;
     195             :         }
     196             : 
     197           0 :         b = get_bits(gb, 2);
     198           0 :         set_pos(s, i, col, map_2bit_near[b]);
     199             :     }
     200           0 :     return 0;
     201             : }
     202             : 
     203           0 : static int k23(InterplayACMContext *s, unsigned ind, unsigned col)
     204             : {
     205           0 :     GetBitContext *gb = &s->gb;
     206             :     unsigned i, b;
     207             : 
     208           0 :     for (i = 0; i < s->rows; i++) {
     209           0 :         b = get_bits1(gb);
     210           0 :         if (b == 0) {
     211           0 :             set_pos(s, i, col, 0);
     212           0 :             continue;
     213             :         }
     214             : 
     215           0 :         b = get_bits(gb, 2);
     216           0 :         set_pos(s, i, col, map_2bit_near[b]);
     217             :     }
     218           0 :     return 0;
     219             : }
     220             : 
     221           0 : static int k35(InterplayACMContext *s, unsigned ind, unsigned col)
     222             : {
     223           0 :     GetBitContext *gb = &s->gb;
     224             :     unsigned i, b;
     225             : 
     226           0 :     for (i = 0; i < s->rows; i++) {
     227           0 :         b = get_bits1(gb);
     228           0 :         if (b == 0) {
     229           0 :             set_pos(s, i++, col, 0);
     230           0 :             if (i >= s->rows)
     231           0 :                 break;
     232           0 :             set_pos(s, i, col, 0);
     233           0 :             continue;
     234             :         }
     235             : 
     236           0 :         b = get_bits1(gb);
     237           0 :         if (b == 0) {
     238           0 :             set_pos(s, i, col, 0);
     239           0 :             continue;
     240             :         }
     241             : 
     242           0 :         b = get_bits1(gb);
     243           0 :         if (b == 0) {
     244           0 :             b = get_bits1(gb);
     245           0 :             set_pos(s, i, col, map_1bit[b]);
     246           0 :             continue;
     247             :         }
     248             : 
     249           0 :         b = get_bits(gb, 2);
     250           0 :         set_pos(s, i, col, map_2bit_far[b]);
     251             :     }
     252           0 :     return 0;
     253             : }
     254             : 
     255           0 : static int k34(InterplayACMContext *s, unsigned ind, unsigned col)
     256             : {
     257           0 :     GetBitContext *gb = &s->gb;
     258             :     unsigned i, b;
     259             : 
     260           0 :     for (i = 0; i < s->rows; i++) {
     261           0 :         b = get_bits1(gb);
     262           0 :         if (b == 0) {
     263           0 :             set_pos(s, i, col, 0);
     264           0 :             continue;
     265             :         }
     266             : 
     267           0 :         b = get_bits1(gb);
     268           0 :         if (b == 0) {
     269           0 :             b = get_bits1(gb);
     270           0 :             set_pos(s, i, col, map_1bit[b]);
     271           0 :             continue;
     272             :         }
     273             : 
     274           0 :         b = get_bits(gb, 2);
     275           0 :         set_pos(s, i, col, map_2bit_far[b]);
     276             :     }
     277           0 :     return 0;
     278             : }
     279             : 
     280           0 : static int k45(InterplayACMContext *s, unsigned ind, unsigned col)
     281             : {
     282           0 :     GetBitContext *gb = &s->gb;
     283             :     unsigned i, b;
     284             : 
     285           0 :     for (i = 0; i < s->rows; i++) {
     286           0 :         b = get_bits1(gb);
     287           0 :         if (b == 0) {
     288           0 :             set_pos(s, i, col, 0); i++;
     289           0 :             if (i >= s->rows)
     290           0 :                 break;
     291           0 :             set_pos(s, i, col, 0);
     292           0 :             continue;
     293             :         }
     294             : 
     295           0 :         b = get_bits1(gb);
     296           0 :         if (b == 0) {
     297           0 :             set_pos(s, i, col, 0);
     298           0 :             continue;
     299             :         }
     300             : 
     301           0 :         b = get_bits(gb, 3);
     302           0 :         set_pos(s, i, col, map_3bit[b]);
     303             :     }
     304           0 :     return 0;
     305             : }
     306             : 
     307           0 : static int k44(InterplayACMContext *s, unsigned ind, unsigned col)
     308             : {
     309           0 :     GetBitContext *gb = &s->gb;
     310             :     unsigned i, b;
     311             : 
     312           0 :     for (i = 0; i < s->rows; i++) {
     313           0 :         b = get_bits1(gb);
     314           0 :         if (b == 0) {
     315           0 :             set_pos(s, i, col, 0);
     316           0 :             continue;
     317             :         }
     318             : 
     319           0 :         b = get_bits(gb, 3);
     320           0 :         set_pos(s, i, col, map_3bit[b]);
     321             :     }
     322           0 :     return 0;
     323             : }
     324             : 
     325           0 : static int t15(InterplayACMContext *s, unsigned ind, unsigned col)
     326             : {
     327           0 :     GetBitContext *gb = &s->gb;
     328             :     unsigned i, b;
     329             :     int n1, n2, n3;
     330             : 
     331           0 :     for (i = 0; i < s->rows; i++) {
     332             :         /* b = (x1) + (x2 * 3) + (x3 * 9) */
     333           0 :         b = get_bits(gb, 5);
     334           0 :         if (b > 26) {
     335           0 :             av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 26\n", b);
     336           0 :             return AVERROR_INVALIDDATA;
     337             :         }
     338             : 
     339           0 :         n1 =  (mul_3x3[b] & 0x0F) - 1;
     340           0 :         n2 = ((mul_3x3[b] >> 4) & 0x0F) - 1;
     341           0 :         n3 = ((mul_3x3[b] >> 8) & 0x0F) - 1;
     342             : 
     343           0 :         set_pos(s, i++, col, n1);
     344           0 :         if (i >= s->rows)
     345           0 :             break;
     346           0 :         set_pos(s, i++, col, n2);
     347           0 :         if (i >= s->rows)
     348           0 :             break;
     349           0 :         set_pos(s, i, col, n3);
     350             :     }
     351           0 :     return 0;
     352             : }
     353             : 
     354           0 : static int t27(InterplayACMContext *s, unsigned ind, unsigned col)
     355             : {
     356           0 :     GetBitContext *gb = &s->gb;
     357             :     unsigned i, b;
     358             :     int n1, n2, n3;
     359             : 
     360           0 :     for (i = 0; i < s->rows; i++) {
     361             :         /* b = (x1) + (x2 * 5) + (x3 * 25) */
     362           0 :         b = get_bits(gb, 7);
     363           0 :         if (b > 124) {
     364           0 :             av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 124\n", b);
     365           0 :             return AVERROR_INVALIDDATA;
     366             :         }
     367             : 
     368           0 :         n1 =  (mul_3x5[b] & 0x0F) - 2;
     369           0 :         n2 = ((mul_3x5[b] >> 4) & 0x0F) - 2;
     370           0 :         n3 = ((mul_3x5[b] >> 8) & 0x0F) - 2;
     371             : 
     372           0 :         set_pos(s, i++, col, n1);
     373           0 :         if (i >= s->rows)
     374           0 :             break;
     375           0 :         set_pos(s, i++, col, n2);
     376           0 :         if (i >= s->rows)
     377           0 :             break;
     378           0 :         set_pos(s, i, col, n3);
     379             :     }
     380           0 :     return 0;
     381             : }
     382             : 
     383           0 : static int t37(InterplayACMContext *s, unsigned ind, unsigned col)
     384             : {
     385           0 :     GetBitContext *gb = &s->gb;
     386             :     unsigned i, b;
     387             :     int n1, n2;
     388           0 :     for (i = 0; i < s->rows; i++) {
     389             :         /* b = (x1) + (x2 * 11) */
     390           0 :         b = get_bits(gb, 7);
     391           0 :         if (b > 120) {
     392           0 :             av_log(NULL, AV_LOG_ERROR, "Too large b = %d > 120\n", b);
     393           0 :             return AVERROR_INVALIDDATA;
     394             :         }
     395             : 
     396           0 :         n1 =  (mul_2x11[b] & 0x0F) - 5;
     397           0 :         n2 = ((mul_2x11[b] >> 4) & 0x0F) - 5;
     398             : 
     399           0 :         set_pos(s, i++, col, n1);
     400           0 :         if (i >= s->rows)
     401           0 :             break;
     402           0 :         set_pos(s, i, col, n2);
     403             :     }
     404           0 :     return 0;
     405             : }
     406             : 
     407             : typedef int (*filler)(InterplayACMContext *s, unsigned ind, unsigned col);
     408             : 
     409             : static const filler filler_list[] = {
     410             :     zero,   bad,    bad,    linear,
     411             :     linear, linear, linear, linear,
     412             :     linear, linear, linear, linear,
     413             :     linear, linear, linear, linear,
     414             :     linear, k13,    k12,    t15,
     415             :     k24,    k23,    t27,    k35,
     416             :     k34,    bad,    k45,    k44,
     417             :     bad,    t37,    bad,    bad,
     418             : };
     419             : 
     420           0 : static int fill_block(InterplayACMContext *s)
     421             : {
     422           0 :     GetBitContext *gb = &s->gb;
     423             :     unsigned i, ind;
     424             :     int ret;
     425             : 
     426           0 :     for (i = 0; i < s->cols; i++) {
     427           0 :         ind = get_bits(gb, 5);
     428           0 :         ret = filler_list[ind](s, ind, i);
     429           0 :         if (ret < 0)
     430           0 :             return ret;
     431             :     }
     432           0 :     return 0;
     433             : }
     434             : 
     435           0 : static void juggle(int *wrap_p, int *block_p, unsigned sub_len, unsigned sub_count)
     436             : {
     437             :     unsigned i, j;
     438             :     int *p, r0, r1, r2, r3;
     439             : 
     440           0 :     for (i = 0; i < sub_len; i++) {
     441           0 :         p = block_p;
     442           0 :         r0 = wrap_p[0];
     443           0 :         r1 = wrap_p[1];
     444           0 :         for (j = 0; j < sub_count/2; j++) {
     445           0 :             r2 = *p;
     446           0 :             *p = r1 * 2 + (r0 + r2);
     447           0 :             p += sub_len;
     448           0 :             r3 = *p;
     449           0 :             *p = r2 * 2 - (r1 + r3);
     450           0 :             p += sub_len;
     451           0 :             r0 = r2;
     452           0 :             r1 = r3;
     453             :         }
     454             : 
     455           0 :         *wrap_p++ = r0;
     456           0 :         *wrap_p++ = r1;
     457           0 :         block_p++;
     458             :     }
     459           0 : }
     460             : 
     461           0 : static void juggle_block(InterplayACMContext *s)
     462             : {
     463             :     unsigned sub_count, sub_len, todo_count, step_subcount, i;
     464             :     int *wrap_p, *block_p, *p;
     465             : 
     466             :     /* juggle only if subblock_len > 1 */
     467           0 :     if (s->level == 0)
     468           0 :         return;
     469             : 
     470             :     /* 2048 / subblock_len */
     471           0 :     if (s->level > 9)
     472           0 :         step_subcount = 1;
     473             :     else
     474           0 :         step_subcount = (2048 >> s->level) - 2;
     475             : 
     476             :     /* Apply juggle()  (rows)x(cols)
     477             :      * from (step_subcount * 2)            x (subblock_len/2)
     478             :      * to   (step_subcount * subblock_len) x (1)
     479             :      */
     480           0 :     todo_count = s->rows;
     481           0 :     block_p = s->block;
     482             :     while (1) {
     483           0 :         wrap_p = s->wrapbuf;
     484           0 :         sub_count = step_subcount;
     485           0 :         if (sub_count > todo_count)
     486           0 :             sub_count = todo_count;
     487             : 
     488           0 :         sub_len = s->cols / 2;
     489           0 :         sub_count *= 2;
     490             : 
     491           0 :         juggle(wrap_p, block_p, sub_len, sub_count);
     492           0 :         wrap_p += sub_len * 2;
     493             : 
     494           0 :         for (i = 0, p = block_p; i < sub_count; i++) {
     495           0 :             p[0]++;
     496           0 :             p += sub_len;
     497             :         }
     498             : 
     499           0 :         while (sub_len > 1) {
     500           0 :             sub_len /= 2;
     501           0 :             sub_count *= 2;
     502           0 :             juggle(wrap_p, block_p, sub_len, sub_count);
     503           0 :             wrap_p += sub_len * 2;
     504             :         }
     505             : 
     506           0 :         if (todo_count <= step_subcount)
     507           0 :             break;
     508             : 
     509           0 :         todo_count -= step_subcount;
     510           0 :         block_p += step_subcount << s->level;
     511             :     }
     512             : }
     513             : 
     514           0 : static int decode_block(InterplayACMContext *s)
     515             : {
     516           0 :     GetBitContext *gb = &s->gb;
     517             :     int pwr, count, val, i, x, ret;
     518             : 
     519           0 :     pwr = get_bits(gb, 4);
     520           0 :     val = get_bits(gb, 16);
     521             : 
     522           0 :     count = 1 << pwr;
     523             : 
     524           0 :     for (i = 0, x = 0; i < count; i++) {
     525           0 :         s->midbuf[i] = x;
     526           0 :         x += val;
     527             :     }
     528             : 
     529           0 :     for (i = 1, x = -val; i <= count; i++) {
     530           0 :         s->midbuf[-i] = x;
     531           0 :         x -= val;
     532             :     }
     533             : 
     534           0 :     ret = fill_block(s);
     535           0 :     if (ret < 0)
     536           0 :         return ret;
     537             : 
     538           0 :     juggle_block(s);
     539             : 
     540           0 :     return 0;
     541             : }
     542             : 
     543           0 : static int decode_frame(AVCodecContext *avctx, void *data,
     544             :                         int *got_frame_ptr, AVPacket *pkt)
     545             : {
     546           0 :     InterplayACMContext *s = avctx->priv_data;
     547           0 :     GetBitContext *gb = &s->gb;
     548           0 :     AVFrame *frame = data;
     549             :     const uint8_t *buf;
     550             :     int16_t *samples;
     551             :     int ret, n, buf_size, input_buf_size;
     552             : 
     553           0 :     if (!pkt->size && !s->bitstream_size) {
     554           0 :         *got_frame_ptr = 0;
     555           0 :         return 0;
     556             :     }
     557             : 
     558           0 :     buf_size = FFMIN(pkt->size, s->max_framesize - s->bitstream_size);
     559           0 :     input_buf_size = buf_size;
     560           0 :     if (s->bitstream_index + s->bitstream_size + buf_size > s->max_framesize) {
     561           0 :         memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
     562           0 :         s->bitstream_index = 0;
     563             :     }
     564           0 :     if (pkt->data)
     565           0 :         memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], pkt->data, buf_size);
     566           0 :     buf                = &s->bitstream[s->bitstream_index];
     567           0 :     buf_size          += s->bitstream_size;
     568           0 :     s->bitstream_size  = buf_size;
     569           0 :     if (buf_size < s->max_framesize && pkt->data) {
     570           0 :         *got_frame_ptr = 0;
     571           0 :         return input_buf_size;
     572             :     }
     573             : 
     574           0 :     if ((ret = init_get_bits8(gb, buf, buf_size)) < 0)
     575           0 :         return ret;
     576             : 
     577           0 :     frame->nb_samples = s->block_len / avctx->channels;
     578           0 :     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
     579           0 :         return ret;
     580             : 
     581           0 :     skip_bits(gb, s->skip);
     582           0 :     ret = decode_block(s);
     583           0 :     if (ret < 0)
     584           0 :         return ret;
     585             : 
     586           0 :     samples = (int16_t *)frame->data[0];
     587           0 :     for (n = 0; n < frame->nb_samples * avctx->channels; n++) {
     588           0 :         int val = s->block[n] >> s->level;
     589           0 :         *samples++ = val;
     590             :     }
     591             : 
     592           0 :     *got_frame_ptr = 1;
     593           0 :     s->skip = get_bits_count(gb) - 8 * (get_bits_count(gb) / 8);
     594           0 :     n = get_bits_count(gb) / 8;
     595             : 
     596           0 :     if (n > buf_size && pkt->data) {
     597           0 :         s->bitstream_size = 0;
     598           0 :         s->bitstream_index = 0;
     599           0 :         return AVERROR_INVALIDDATA;
     600             :     }
     601             : 
     602           0 :     if (s->bitstream_size) {
     603           0 :         s->bitstream_index += n;
     604           0 :         s->bitstream_size  -= n;
     605           0 :         return input_buf_size;
     606             :     }
     607           0 :     return n;
     608             : }
     609             : 
     610           0 : static av_cold int decode_close(AVCodecContext *avctx)
     611             : {
     612           0 :     InterplayACMContext *s = avctx->priv_data;
     613             : 
     614           0 :     av_freep(&s->block);
     615           0 :     av_freep(&s->wrapbuf);
     616           0 :     av_freep(&s->ampbuf);
     617           0 :     av_freep(&s->bitstream);
     618           0 :     s->bitstream_size = 0;
     619             : 
     620           0 :     return 0;
     621             : }
     622             : 
     623             : AVCodec ff_interplay_acm_decoder = {
     624             :     .name           = "interplayacm",
     625             :     .long_name      = NULL_IF_CONFIG_SMALL("Interplay ACM"),
     626             :     .type           = AVMEDIA_TYPE_AUDIO,
     627             :     .id             = AV_CODEC_ID_INTERPLAY_ACM,
     628             :     .init           = decode_init,
     629             :     .close          = decode_close,
     630             :     .decode         = decode_frame,
     631             :     .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
     632             :     .priv_data_size = sizeof(InterplayACMContext),
     633             : };

Generated by: LCOV version 1.13