static inline void skip_remaining(BitstreamContext *bc, unsigned n)
{
#ifdef BITSTREAM_READER_LE
    bc->bits >>= n;
#else
    bc->bits <<= n;
#endif
    bc->bits_left -= n;
}
['static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,\n                        AVPacket *avpkt)\n{\n    ALSDecContext *ctx       = avctx->priv_data;\n    AVFrame *frame           = data;\n    ALSSpecificConfig *sconf = &ctx->sconf;\n    const uint8_t *buffer    = avpkt->data;\n    int buffer_size          = avpkt->size;\n    int invalid_frame, ret;\n    unsigned int c, sample, ra_frame, bytes_read, shift;\n    bitstream_init8(&ctx->bc, buffer, buffer_size);\n    ra_frame = sconf->ra_distance && !(ctx->frame_id % sconf->ra_distance);\n    if (sconf->samples != 0xFFFFFFFF)\n        ctx->cur_frame_length = FFMIN(sconf->samples - ctx->frame_id * (uint64_t) sconf->frame_length,\n                                      sconf->frame_length);\n    else\n        ctx->cur_frame_length = sconf->frame_length;\n    if ((invalid_frame = read_frame_data(ctx, ra_frame)) < 0)\n        av_log(ctx->avctx, AV_LOG_WARNING,\n               "Reading frame data failed. Skipping RA unit.\\n");\n    ctx->frame_id++;\n    frame->nb_samples = ctx->cur_frame_length;\n    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {\n        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\\n");\n        return ret;\n    }\n    #define INTERLEAVE_OUTPUT(bps)                                 \\\n    {                                                              \\\n        int##bps##_t *dest = (int##bps##_t*)frame->data[0];        \\\n        shift = bps - ctx->avctx->bits_per_raw_sample;             \\\n        for (sample = 0; sample < ctx->cur_frame_length; sample++) \\\n            for (c = 0; c < avctx->channels; c++)                  \\\n                *dest++ = ctx->raw_samples[c][sample] << shift;    \\\n    }\n    if (ctx->avctx->bits_per_raw_sample <= 16) {\n        INTERLEAVE_OUTPUT(16)\n    } else {\n        INTERLEAVE_OUTPUT(32)\n    }\n    if (sconf->crc_enabled && (avctx->err_recognition & AV_EF_CRCCHECK)) {\n        int swap = HAVE_BIGENDIAN != sconf->msb_first;\n        if (ctx->avctx->bits_per_raw_sample == 24) {\n            int32_t *src = (int32_t *)frame->data[0];\n            for (sample = 0;\n                 sample < ctx->cur_frame_length * avctx->channels;\n                 sample++) {\n                int32_t v;\n                if (swap)\n                    v = av_bswap32(src[sample]);\n                else\n                    v = src[sample];\n                if (!HAVE_BIGENDIAN)\n                    v >>= 8;\n                ctx->crc = av_crc(ctx->crc_table, ctx->crc, (uint8_t*)(&v), 3);\n            }\n        } else {\n            uint8_t *crc_source;\n            if (swap) {\n                if (ctx->avctx->bits_per_raw_sample <= 16) {\n                    int16_t *src  = (int16_t*) frame->data[0];\n                    int16_t *dest = (int16_t*) ctx->crc_buffer;\n                    for (sample = 0;\n                         sample < ctx->cur_frame_length * avctx->channels;\n                         sample++)\n                        *dest++ = av_bswap16(src[sample]);\n                } else {\n                    ctx->bdsp.bswap_buf((uint32_t *) ctx->crc_buffer,\n                                        (uint32_t *) frame->data[0],\n                                        ctx->cur_frame_length * avctx->channels);\n                }\n                crc_source = ctx->crc_buffer;\n            } else {\n                crc_source = frame->data[0];\n            }\n            ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source,\n                              ctx->cur_frame_length * avctx->channels *\n                              av_get_bytes_per_sample(avctx->sample_fmt));\n        }\n        if (ctx->cur_frame_length != sconf->frame_length &&\n            ctx->crc_org != ctx->crc) {\n            av_log(avctx, AV_LOG_ERROR, "CRC error.\\n");\n            if (avctx->err_recognition & AV_EF_EXPLODE)\n                return AVERROR_INVALIDDATA;\n        }\n    }\n    *got_frame_ptr = 1;\n    bytes_read = invalid_frame ? buffer_size :\n                                 (bitstream_tell(&ctx->bc) + 7) >> 3;\n    return bytes_read;\n}', 'static inline int bitstream_init8(BitstreamContext *bc, const uint8_t *buffer,\n                                  unsigned byte_size)\n{\n    if (byte_size > INT_MAX / 8)\n        return AVERROR_INVALIDDATA;\n    return bitstream_init(bc, buffer, byte_size * 8);\n}', 'static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame)\n{\n    ALSSpecificConfig *sconf = &ctx->sconf;\n    AVCodecContext *avctx    = ctx->avctx;\n    BitstreamContext *bc     = &ctx->bc;\n    unsigned int div_blocks[32];\n    unsigned int c;\n    unsigned int js_blocks[2];\n    uint32_t bs_info = 0;\n    int ret;\n    if (sconf->ra_flag == RA_FLAG_FRAMES && ra_frame)\n        bitstream_skip(bc, 32);\n    if (sconf->mc_coding && sconf->joint_stereo) {\n        ctx->js_switch = bitstream_read_bit(bc);\n        bitstream_align(bc);\n    }\n    if (!sconf->mc_coding || ctx->js_switch) {\n        int independent_bs = !sconf->joint_stereo;\n        for (c = 0; c < avctx->channels; c++) {\n            js_blocks[0] = 0;\n            js_blocks[1] = 0;\n            get_block_sizes(ctx, div_blocks, &bs_info);\n            if (sconf->joint_stereo && sconf->block_switching)\n                if (bs_info >> 31)\n                    independent_bs = 2;\n            if (c == avctx->channels - 1)\n                independent_bs = 1;\n            if (independent_bs) {\n                ret = decode_blocks_ind(ctx, ra_frame, c,\n                                        div_blocks, js_blocks);\n                if (ret < 0)\n                    return ret;\n                independent_bs--;\n            } else {\n                ret = decode_blocks(ctx, ra_frame, c, div_blocks, js_blocks);\n                if (ret < 0)\n                    return ret;\n                c++;\n            }\n            memmove(ctx->raw_samples[c] - sconf->max_order,\n                    ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,\n                    sizeof(*ctx->raw_samples[c]) * sconf->max_order);\n        }\n    } else {\n        ALSBlockData   bd = { 0 };\n        int            b, ret;\n        int            *reverted_channels = ctx->reverted_channels;\n        unsigned int   offset             = 0;\n        for (c = 0; c < avctx->channels; c++)\n            if (ctx->chan_data[c] < ctx->chan_data_buffer) {\n                av_log(ctx->avctx, AV_LOG_ERROR, "Invalid channel data!\\n");\n                return AVERROR_INVALIDDATA;\n            }\n        memset(reverted_channels, 0, sizeof(*reverted_channels) * avctx->channels);\n        bd.ra_block         = ra_frame;\n        bd.prev_raw_samples = ctx->prev_raw_samples;\n        get_block_sizes(ctx, div_blocks, &bs_info);\n        for (b = 0; b < ctx->num_blocks; b++) {\n            bd.block_length = div_blocks[b];\n            if (bd.block_length <= 0) {\n                av_log(ctx->avctx, AV_LOG_WARNING,\n                       "Invalid block length %u in channel data!\\n",\n                       bd.block_length);\n                continue;\n            }\n            for (c = 0; c < avctx->channels; c++) {\n                bd.const_block = ctx->const_block + c;\n                bd.shift_lsbs  = ctx->shift_lsbs + c;\n                bd.opt_order   = ctx->opt_order + c;\n                bd.store_prev_samples = ctx->store_prev_samples + c;\n                bd.use_ltp     = ctx->use_ltp + c;\n                bd.ltp_lag     = ctx->ltp_lag + c;\n                bd.ltp_gain    = ctx->ltp_gain[c];\n                bd.lpc_cof     = ctx->lpc_cof[c];\n                bd.quant_cof   = ctx->quant_cof[c];\n                bd.raw_samples = ctx->raw_samples[c] + offset;\n                bd.raw_other   = NULL;\n                if ((ret = read_block(ctx, &bd)) < 0)\n                    return ret;\n                if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0)\n                    return ret;\n            }\n            for (c = 0; c < avctx->channels; c++) {\n                ret = revert_channel_correlation(ctx, &bd, ctx->chan_data,\n                                                 reverted_channels, offset, c);\n                if (ret < 0)\n                    return ret;\n            }\n            for (c = 0; c < avctx->channels; c++) {\n                bd.const_block = ctx->const_block + c;\n                bd.shift_lsbs  = ctx->shift_lsbs + c;\n                bd.opt_order   = ctx->opt_order + c;\n                bd.store_prev_samples = ctx->store_prev_samples + c;\n                bd.use_ltp     = ctx->use_ltp + c;\n                bd.ltp_lag     = ctx->ltp_lag + c;\n                bd.ltp_gain    = ctx->ltp_gain[c];\n                bd.lpc_cof     = ctx->lpc_cof[c];\n                bd.quant_cof   = ctx->quant_cof[c];\n                bd.raw_samples = ctx->raw_samples[c] + offset;\n                if ((ret = decode_block(ctx, &bd)) < 0)\n                    return ret;\n            }\n            memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels));\n            offset      += div_blocks[b];\n            bd.ra_block  = 0;\n        }\n        for (c = 0; c < avctx->channels; c++)\n            memmove(ctx->raw_samples[c] - sconf->max_order,\n                    ctx->raw_samples[c] - sconf->max_order + sconf->frame_length,\n                    sizeof(*ctx->raw_samples[c]) * sconf->max_order);\n    }\n    return 0;\n}', 'static inline void bitstream_skip(BitstreamContext *bc, unsigned n)\n{\n    if (n <= bc->bits_left)\n        skip_remaining(bc, n);\n    else {\n        n -= bc->bits_left;\n        skip_remaining(bc, bc->bits_left);\n        if (n >= 64) {\n            unsigned skip = n / 8;\n            n -= skip * 8;\n            bc->ptr += skip;\n        }\n        refill_64(bc);\n        if (n)\n            skip_remaining(bc, n);\n    }\n}', 'static inline void skip_remaining(BitstreamContext *bc, unsigned n)\n{\n#ifdef BITSTREAM_READER_LE\n    bc->bits >>= n;\n#else\n    bc->bits <<= n;\n#endif\n    bc->bits_left -= n;\n}']