static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,

                     const uint8_t **poutbuf, int *poutbuf_size,

                     const uint8_t *buf, int buf_size)

{

    TAKParseContext *t = s->priv_data;

    ParseContext *pc = &t->pc;

    int next = END_NOT_FOUND;

    GetBitContext gb;

    int consumed = 0;

    int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;



    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        TAKStreamInfo ti;

        init_get_bits(&gb, buf, buf_size);

        if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))

            s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples :

                                                     t->ti.frame_samples;

        *poutbuf      = buf;

        *poutbuf_size = buf_size;

        return buf_size;

    }



    while (buf_size || t->index + needed <= pc->index) {

        if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {

            int tmp_buf_size = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES, buf_size);

            const uint8_t *tmp_buf = buf;



            ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size);

            consumed += tmp_buf_size;

            buf      += tmp_buf_size;

            buf_size -= tmp_buf_size;

        }



        for (; t->index + needed <= pc->index; t->index++) {

            if (pc->buffer[ t->index     ] == 0xFF &&

                pc->buffer[ t->index + 1 ] == 0xA0) {

                TAKStreamInfo ti;



                init_get_bits(&gb, pc->buffer + t->index,

                              8 * (pc->index - t->index));

                if (!ff_tak_decode_frame_header(avctx, &gb,

                        pc->frame_start_found ? &ti : &t->ti, 127) &&

                    !ff_tak_check_crc(pc->buffer + t->index,

                                      get_bits_count(&gb) / 8)) {

                    if (!pc->frame_start_found) {

                        pc->frame_start_found = 1;

                        s->duration = t->ti.last_frame_samples ?

                                      t->ti.last_frame_samples :

                                      t->ti.frame_samples;

                    } else {

                        pc->frame_start_found = 0;

                        next = t->index - pc->index;

                        t->index = 0;

                        goto found;

                    }

                }

            }

        }

    }

found:



    if (consumed && !buf_size && next == END_NOT_FOUND ||

        ff_combine_frame(pc, next, &buf, &buf_size) < 0) {

        *poutbuf      = NULL;

        *poutbuf_size = 0;

        return buf_size + consumed;

    }



    if (next != END_NOT_FOUND) {

        next += consumed;

        pc->overread = FFMAX(0, -next);

    }



    *poutbuf      = buf;

    *poutbuf_size = buf_size;

    return next;

}

static int tak_parse(AVCodecParserContext *s, AVCodecContext *avctx,

                     const uint8_t **poutbuf, int *poutbuf_size,

                     const uint8_t *buf, int buf_size)

{

    TAKParseContext *t = s->priv_data;

    ParseContext *pc = &t->pc;

    int next = END_NOT_FOUND;

    GetBitContext gb;

    int consumed = 0;

    int needed = buf_size ? TAK_MAX_FRAME_HEADER_BYTES : 8;



    if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        TAKStreamInfo ti;

        init_get_bits(&gb, buf, buf_size);

        if (!ff_tak_decode_frame_header(avctx, &gb, &ti, 127))

            s->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples :

                                                     t->ti.frame_samples;

        *poutbuf      = buf;

        *poutbuf_size = buf_size;

        return buf_size;

    }



    while (buf_size || t->index + needed <= pc->index) {

        if (buf_size && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {

            int tmp_buf_size = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES, buf_size);

            const uint8_t *tmp_buf = buf;



            ff_combine_frame(pc, END_NOT_FOUND, &tmp_buf, &tmp_buf_size);

            consumed += tmp_buf_size;

            buf      += tmp_buf_size;

            buf_size -= tmp_buf_size;

        }



        for (; t->index + needed <= pc->index; t->index++) {

            if (pc->buffer[ t->index     ] == 0xFF &&

                pc->buffer[ t->index + 1 ] == 0xA0) {

                TAKStreamInfo ti;



                init_get_bits(&gb, pc->buffer + t->index,

                              8 * (pc->index - t->index));

                if (!ff_tak_decode_frame_header(avctx, &gb,

                        pc->frame_start_found ? &ti : &t->ti, 127) &&

                    !ff_tak_check_crc(pc->buffer + t->index,

                                      get_bits_count(&gb) / 8)) {

                    if (!pc->frame_start_found) {

                        pc->frame_start_found = 1;

                        s->duration = t->ti.last_frame_samples ?

                                      t->ti.last_frame_samples :

                                      t->ti.frame_samples;

                    } else {

                        pc->frame_start_found = 0;

                        next = t->index - pc->index;

                        t->index = 0;

                        goto found;

                    }

                }

            }

        }

    }

found:



    if (consumed && !buf_size && next == END_NOT_FOUND ||

        ff_combine_frame(pc, next, &buf, &buf_size) < 0) {

        *poutbuf      = NULL;

        *poutbuf_size = 0;

        return buf_size + consumed;

    }



    if (next != END_NOT_FOUND) {

        next += consumed;

        pc->overread = FFMAX(0, -next);

    }



    *poutbuf      = buf;

    *poutbuf_size = buf_size;

    return next;

}

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

                     const uint8_t **VAR_2, int *VAR_3,

                     const uint8_t *VAR_4, int VAR_5)

{

    TAKParseContext *t = VAR_0->priv_data;

    ParseContext *pc = &t->pc;

    int VAR_6 = END_NOT_FOUND;

    GetBitContext gb;

    int VAR_7 = 0;

    int VAR_8 = VAR_5 ? TAK_MAX_FRAME_HEADER_BYTES : 8;



    if (VAR_0->flags & PARSER_FLAG_COMPLETE_FRAMES) {

        TAKStreamInfo ti;

        init_get_bits(&gb, VAR_4, VAR_5);

        if (!ff_tak_decode_frame_header(VAR_1, &gb, &ti, 127))

            VAR_0->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples :

                                                     t->ti.frame_samples;

        *VAR_2      = VAR_4;

        *VAR_3 = VAR_5;

        return VAR_5;

    }



    while (VAR_5 || t->index + VAR_8 <= pc->index) {

        if (VAR_5 && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) {

            int VAR_9 = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES, VAR_5);

            const uint8_t *VAR_10 = VAR_4;



            ff_combine_frame(pc, END_NOT_FOUND, &VAR_10, &VAR_9);

            VAR_7 += VAR_9;

            VAR_4      += VAR_9;

            VAR_5 -= VAR_9;

        }



        for (; t->index + VAR_8 <= pc->index; t->index++) {

            if (pc->buffer[ t->index     ] == 0xFF &&

                pc->buffer[ t->index + 1 ] == 0xA0) {

                TAKStreamInfo ti;



                init_get_bits(&gb, pc->buffer + t->index,

                              8 * (pc->index - t->index));

                if (!ff_tak_decode_frame_header(VAR_1, &gb,

                        pc->frame_start_found ? &ti : &t->ti, 127) &&

                    !ff_tak_check_crc(pc->buffer + t->index,

                                      get_bits_count(&gb) / 8)) {

                    if (!pc->frame_start_found) {

                        pc->frame_start_found = 1;

                        VAR_0->duration = t->ti.last_frame_samples ?

                                      t->ti.last_frame_samples :

                                      t->ti.frame_samples;

                    } else {

                        pc->frame_start_found = 0;

                        VAR_6 = t->index - pc->index;

                        t->index = 0;

                        goto found;

                    }

                }

            }

        }

    }

found:



    if (VAR_7 && !VAR_5 && VAR_6 == END_NOT_FOUND ||

        ff_combine_frame(pc, VAR_6, &VAR_4, &VAR_5) < 0) {

        *VAR_2      = NULL;

        *VAR_3 = 0;

        return VAR_5 + VAR_7;

    }



    if (VAR_6 != END_NOT_FOUND) {

        VAR_6 += VAR_7;

        pc->overread = FFMAX(0, -VAR_6);

    }



    *VAR_2      = VAR_4;

    *VAR_3 = VAR_5;

    return VAR_6;

}

static int FUNC_0(AVCodecParserContext *VAR_0, AVCodecContext *VAR_1,
const uint8_t **VAR_2, int *VAR_3,
const uint8_t *VAR_4, int VAR_5)
{ TAKParseContext *t = VAR_0->priv_data; ParseContext *pc = &t->pc; int VAR_6 = END_NOT_FOUND; GetBitContext gb; int VAR_7 = 0; int VAR_8 = VAR_5 ? TAK_MAX_FRAME_HEADER_BYTES : 8; if (VAR_0->flags & PARSER_FLAG_COMPLETE_FRAMES) { TAKStreamInfo ti; init_get_bits(&gb, VAR_4, VAR_5); if (!ff_tak_decode_frame_header(VAR_1, &gb, &ti, 127))
VAR_0->duration = t->ti.last_frame_samples ? t->ti.last_frame_samples :
t->ti.frame_samples; *VAR_2      = VAR_4; *VAR_3 = VAR_5; return VAR_5; } while (VAR_5 || t->index + VAR_8 <= pc->index) { if (VAR_5 && t->index + TAK_MAX_FRAME_HEADER_BYTES > pc->index) { int VAR_9 = FFMIN(2 * TAK_MAX_FRAME_HEADER_BYTES, VAR_5); const uint8_t *VAR_10 = VAR_4; ff_combine_frame(pc, END_NOT_FOUND, &VAR_10, &VAR_9); VAR_7 += VAR_9; VAR_4      += VAR_9; VAR_5 -= VAR_9; } for (; t->index + VAR_8 <= pc->index; t->index++) { if (pc->buffer[ t->index     ] == 0xFF &&
pc->buffer[ t->index + 1 ] == 0xA0) { TAKStreamInfo ti; init_get_bits(&gb, pc->buffer + t->index,
8 * (pc->index - t->index)); if (!ff_tak_decode_frame_header(VAR_1, &gb,
pc->frame_start_found ? &ti : &t->ti, 127) &&
!ff_tak_check_crc(pc->buffer + t->index,
get_bits_count(&gb) / 8)) { if (!pc->frame_start_found) { pc->frame_start_found = 1; VAR_0->duration = t->ti.last_frame_samples ?
t->ti.last_frame_samples :
t->ti.frame_samples; } else { pc->frame_start_found = 0; VAR_6 = t->index - pc->index; t->index = 0; goto found; } } } } } found:
if (VAR_7 && !VAR_5 && VAR_6 == END_NOT_FOUND ||
ff_combine_frame(pc, VAR_6, &VAR_4, &VAR_5) < 0) { *VAR_2      = NULL; *VAR_3 = 0; return VAR_5 + VAR_7; } if (VAR_6 != END_NOT_FOUND) { VAR_6 += VAR_7; pc->overread = FFMAX(0, -VAR_6); } *VAR_2      = VAR_4; *VAR_3 = VAR_5; return VAR_6; }