static int alac_decode_frame(AVCodecContext *avctx, void *data,

                             int *got_frame_ptr, AVPacket *avpkt)

{

    ALACContext *alac = avctx->priv_data;

    enum RawDataBlockType element;

    int channels;

    int ch, ret, got_end;



    init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8);



    got_end = 0;

    alac->nb_samples = 0;

    ch = 0;

    while (get_bits_left(&alac->gb) >= 3) {

        element = get_bits(&alac->gb, 3);

        if (element == TYPE_END) {

            got_end = 1;

            break;

        }

        if (element > TYPE_CPE && element != TYPE_LFE) {

            av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d\n", element);

            return AVERROR_PATCHWELCOME;

        }



        channels = (element == TYPE_CPE) ? 2 : 1;

        if (ch + channels > alac->channels) {

            av_log(avctx, AV_LOG_ERROR, "invalid element channel count\n");

            return AVERROR_INVALIDDATA;

        }



        ret = decode_element(avctx, data,

                             alac_channel_layout_offsets[alac->channels - 1][ch],

                             channels);

        if (ret < 0 && get_bits_left(&alac->gb))

            return ret;



        ch += channels;

    }

    if (!got_end) {

        av_log(avctx, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");

        return AVERROR_INVALIDDATA;

    }



    if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {

        av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",

               avpkt->size * 8 - get_bits_count(&alac->gb));

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = alac->frame;



    return avpkt->size;

}

static int alac_decode_frame(AVCodecContext *avctx, void *data,

                             int *got_frame_ptr, AVPacket *avpkt)

{

    ALACContext *alac = avctx->priv_data;

    enum RawDataBlockType element;

    int channels;

    int ch, ret, got_end;



    init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8);



    got_end = 0;

    alac->nb_samples = 0;

    ch = 0;

    while (get_bits_left(&alac->gb) >= 3) {

        element = get_bits(&alac->gb, 3);

        if (element == TYPE_END) {

            got_end = 1;

            break;

        }

        if (element > TYPE_CPE && element != TYPE_LFE) {

            av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d\n", element);

            return AVERROR_PATCHWELCOME;

        }



        channels = (element == TYPE_CPE) ? 2 : 1;

        if (ch + channels > alac->channels) {

            av_log(avctx, AV_LOG_ERROR, "invalid element channel count\n");

            return AVERROR_INVALIDDATA;

        }



        ret = decode_element(avctx, data,

                             alac_channel_layout_offsets[alac->channels - 1][ch],

                             channels);

        if (ret < 0 && get_bits_left(&alac->gb))

            return ret;



        ch += channels;

    }

    if (!got_end) {

        av_log(avctx, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");

        return AVERROR_INVALIDDATA;

    }



    if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {

        av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",

               avpkt->size * 8 - get_bits_count(&alac->gb));

    }



    *got_frame_ptr   = 1;

    *(AVFrame *)data = alac->frame;



    return avpkt->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,

                             int *VAR_2, AVPacket *VAR_3)

{

    ALACContext *alac = VAR_0->priv_data;

    enum RawDataBlockType VAR_4;

    int VAR_5;

    int VAR_6, VAR_7, VAR_8;



    init_get_bits(&alac->gb, VAR_3->VAR_1, VAR_3->size * 8);



    VAR_8 = 0;

    alac->nb_samples = 0;

    VAR_6 = 0;

    while (get_bits_left(&alac->gb) >= 3) {

        VAR_4 = get_bits(&alac->gb, 3);

        if (VAR_4 == TYPE_END) {

            VAR_8 = 1;

            break;

        }

        if (VAR_4 > TYPE_CPE && VAR_4 != TYPE_LFE) {

            av_log(VAR_0, AV_LOG_ERROR, "syntax VAR_4 unsupported: %d\n", VAR_4);

            return AVERROR_PATCHWELCOME;

        }



        VAR_5 = (VAR_4 == TYPE_CPE) ? 2 : 1;

        if (VAR_6 + VAR_5 > alac->VAR_5) {

            av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_4 channel count\n");

            return AVERROR_INVALIDDATA;

        }



        VAR_7 = decode_element(VAR_0, VAR_1,

                             alac_channel_layout_offsets[alac->VAR_5 - 1][VAR_6],

                             VAR_5);

        if (VAR_7 < 0 && get_bits_left(&alac->gb))

            return VAR_7;



        VAR_6 += VAR_5;

    }

    if (!VAR_8) {

        av_log(VAR_0, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");

        return AVERROR_INVALIDDATA;

    }



    if (VAR_3->size * 8 - get_bits_count(&alac->gb) > 8) {

        av_log(VAR_0, AV_LOG_ERROR, "Error : %d bits left\n",

               VAR_3->size * 8 - get_bits_count(&alac->gb));

    }



    *VAR_2   = 1;

    *(AVFrame *)VAR_1 = alac->frame;



    return VAR_3->size;

}

static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1,
int *VAR_2, AVPacket *VAR_3)
{ ALACContext *alac = VAR_0->priv_data; enum RawDataBlockType VAR_4; int VAR_5; int VAR_6, VAR_7, VAR_8; init_get_bits(&alac->gb, VAR_3->VAR_1, VAR_3->size * 8); VAR_8 = 0; alac->nb_samples = 0; VAR_6 = 0; while (get_bits_left(&alac->gb) >= 3) { VAR_4 = get_bits(&alac->gb, 3); if (VAR_4 == TYPE_END) { VAR_8 = 1; break; } if (VAR_4 > TYPE_CPE && VAR_4 != TYPE_LFE) { av_log(VAR_0, AV_LOG_ERROR, "syntax VAR_4 unsupported: %d\n", VAR_4); return AVERROR_PATCHWELCOME; } VAR_5 = (VAR_4 == TYPE_CPE) ? 2 : 1; if (VAR_6 + VAR_5 > alac->VAR_5) { av_log(VAR_0, AV_LOG_ERROR, "invalid VAR_4 channel count\n"); return AVERROR_INVALIDDATA; } VAR_7 = decode_element(VAR_0, VAR_1,
alac_channel_layout_offsets[alac->VAR_5 - 1][VAR_6],
VAR_5); if (VAR_7 < 0 && get_bits_left(&alac->gb))
return VAR_7; VAR_6 += VAR_5; } if (!VAR_8) { av_log(VAR_0, AV_LOG_ERROR, "no end tag found. incomplete packet.\n"); return AVERROR_INVALIDDATA; } if (VAR_3->size * 8 - get_bits_count(&alac->gb) > 8) { av_log(VAR_0, AV_LOG_ERROR, "Error : %d bits left\n",
VAR_3->size * 8 - get_bits_count(&alac->gb)); } *VAR_2   = 1; *(AVFrame *)VAR_1 = alac->frame; return VAR_3->size; }