int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)

{

    int i;

    uint32_t state = pc->state;



    /* EOF considered as end of frame */

    if (buf_size == 0)

        return 0;



/*

 0  frame start         -> 1/4

 1  first_SEQEXT        -> 0/2

 2  first field start   -> 3/0

 3  second_SEQEXT       -> 2/0

 4  searching end

*/



    for (i = 0; i < buf_size; i++) {

        av_assert1(pc->frame_start_found >= 0 && pc->frame_start_found <= 4);

        if (pc->frame_start_found & 1) {

            if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80)

                pc->frame_start_found--;

            else if (state == EXT_START_CODE + 2) {

                if ((buf[i] & 3) == 3)

                    pc->frame_start_found = 0;

                else

                    pc->frame_start_found = (pc->frame_start_found + 1) & 3;

            }

            state++;

        } else {

            i = avpriv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1;

            if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) {

                i++;

                pc->frame_start_found = 4;

            }

            if (state == SEQ_END_CODE) {

                pc->frame_start_found = 0;

                pc->state=-1;

                return i+1;

            }

            if (pc->frame_start_found == 2 && state == SEQ_START_CODE)

                pc->frame_start_found = 0;

            if (pc->frame_start_found  < 4 && state == EXT_START_CODE)

                pc->frame_start_found++;

            if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) {

                if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) {

                    pc->frame_start_found = 0;

                    pc->state             = -1;

                    return i - 3;

                }

            }

            if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) {

                ff_fetch_timestamp(s, i - 3, 1);

            }

        }

    }

    pc->state = state;

    return END_NOT_FOUND;

}

int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s)

{

    int i;

    uint32_t state = pc->state;



    

    if (buf_size == 0)

        return 0;



















    for (i = 0; i < buf_size; i++) {

        av_assert1(pc->frame_start_found >= 0 && pc->frame_start_found <= 4);

        if (pc->frame_start_found & 1) {

            if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80)

                pc->frame_start_found--;

            else if (state == EXT_START_CODE + 2) {

                if ((buf[i] & 3) == 3)

                    pc->frame_start_found = 0;

                else

                    pc->frame_start_found = (pc->frame_start_found + 1) & 3;

            }

            state++;

        } else {

            i = avpriv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1;

            if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) {

                i++;

                pc->frame_start_found = 4;

            }

            if (state == SEQ_END_CODE) {

                pc->frame_start_found = 0;

                pc->state=-1;

                return i+1;

            }

            if (pc->frame_start_found == 2 && state == SEQ_START_CODE)

                pc->frame_start_found = 0;

            if (pc->frame_start_found  < 4 && state == EXT_START_CODE)

                pc->frame_start_found++;

            if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) {

                if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) {

                    pc->frame_start_found = 0;

                    pc->state             = -1;

                    return i - 3;

                }

            }

            if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) {

                ff_fetch_timestamp(s, i - 3, 1);

            }

        }

    }

    pc->state = state;

    return END_NOT_FOUND;

}

                ff_fetch_timestamp(s, i - 3, 1);
int FUNC_0(ParseContext *VAR_0, const uint8_t *VAR_1, int VAR_2, AVCodecParserContext *VAR_3)

{

    int VAR_4;

    uint32_t state = VAR_0->state;



    

    if (VAR_2 == 0)

        return 0;



















    for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

        av_assert1(VAR_0->frame_start_found >= 0 && VAR_0->frame_start_found <= 4);

        if (VAR_0->frame_start_found & 1) {

            if (state == EXT_START_CODE && (VAR_1[VAR_4] & 0xF0) != 0x80)

                VAR_0->frame_start_found--;

            else if (state == EXT_START_CODE + 2) {

                if ((VAR_1[VAR_4] & 3) == 3)

                    VAR_0->frame_start_found = 0;

                else

                    VAR_0->frame_start_found = (VAR_0->frame_start_found + 1) & 3;

            }

            state++;

        } else {

            VAR_4 = avpriv_find_start_code(VAR_1 + VAR_4, VAR_1 + VAR_2, &state) - VAR_1 - 1;

            if (VAR_0->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) {

                VAR_4++;

                VAR_0->frame_start_found = 4;

            }

            if (state == SEQ_END_CODE) {

                VAR_0->frame_start_found = 0;

                VAR_0->state=-1;

                return VAR_4+1;

            }

            if (VAR_0->frame_start_found == 2 && state == SEQ_START_CODE)

                VAR_0->frame_start_found = 0;

            if (VAR_0->frame_start_found  < 4 && state == EXT_START_CODE)

                VAR_0->frame_start_found++;

            if (VAR_0->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) {

                if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) {

                    VAR_0->frame_start_found = 0;

                    VAR_0->state             = -1;

                    return VAR_4 - 3;

                }

            }

            if (VAR_0->frame_start_found == 0 && VAR_3 && state == PICTURE_START_CODE) {

                ff_fetch_timestamp(VAR_3, VAR_4 - 3, 1);

            }

        }

    }

    VAR_0->state = state;

    return END_NOT_FOUND;

}

int FUNC_0(ParseContext *VAR_0, const uint8_t *VAR_1, int VAR_2, AVCodecParserContext *VAR_3)
{ int VAR_4; uint32_t state = VAR_0->state; if (VAR_2 == 0)
return 0; for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { av_assert1(VAR_0->frame_start_found >= 0 && VAR_0->frame_start_found <= 4); if (VAR_0->frame_start_found & 1) { if (state == EXT_START_CODE && (VAR_1[VAR_4] & 0xF0) != 0x80)
VAR_0->frame_start_found--; else if (state == EXT_START_CODE + 2) { if ((VAR_1[VAR_4] & 3) == 3)
VAR_0->frame_start_found = 0; else
VAR_0->frame_start_found = (VAR_0->frame_start_found + 1) & 3; } state++; } else { VAR_4 = avpriv_find_start_code(VAR_1 + VAR_4, VAR_1 + VAR_2, &state) - VAR_1 - 1; if (VAR_0->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { VAR_4++; VAR_0->frame_start_found = 4; } if (state == SEQ_END_CODE) { VAR_0->frame_start_found = 0; VAR_0->state=-1; return VAR_4+1; } if (VAR_0->frame_start_found == 2 && state == SEQ_START_CODE)
VAR_0->frame_start_found = 0; if (VAR_0->frame_start_found  < 4 && state == EXT_START_CODE)
VAR_0->frame_start_found++; if (VAR_0->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) { if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { VAR_0->frame_start_found = 0; VAR_0->state             = -1; return VAR_4 - 3; } } if (VAR_0->frame_start_found == 0 && VAR_3 && state == PICTURE_START_CODE) { ff_fetch_timestamp(VAR_3, VAR_4 - 3, 1); } } } VAR_0->state = state; return END_NOT_FOUND; }