static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,

                               int buf_size)

{

    int i;

    uint32_t state;

    ParseContext *pc = &p->pc;

//    mb_addr= pc->mb_addr - 1;

    state = pc->state;

    if (state > 13)

        state = 7;



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

        if (state == 7) {

            i += p->h264dsp.startcode_find_candidate(buf + i, buf_size - i);

            if (i < buf_size)

                state = 2;

        } else if (state <= 2) {

            if (buf[i] == 1)

                state ^= 5;            // 2->7, 1->4, 0->5

            else if (buf[i])

                state = 7;

            else

                state >>= 1;           // 2->1, 1->0, 0->0

        } else if (state <= 5) {

            int nalu_type = buf[i] & 0x1F;

            if (nalu_type == NAL_SEI || nalu_type == NAL_SPS ||

                nalu_type == NAL_PPS || nalu_type == NAL_AUD) {

                if (pc->frame_start_found) {

                    i++;

                    goto found;

                }

            } else if (nalu_type == NAL_SLICE || nalu_type == NAL_DPA ||

                       nalu_type == NAL_IDR_SLICE) {

                if (pc->frame_start_found) {

                    state += 8;

                    continue;

                } else

                    pc->frame_start_found = 1;

            }

            state = 7;

        } else {

            // first_mb_in_slice is 0, probably the first nal of a new slice

            if (buf[i] & 0x80)

                goto found;

            state = 7;

        }

    }

    pc->state = state;

    return END_NOT_FOUND;



found:

    pc->state             = 7;

    pc->frame_start_found = 0;

    return i - (state & 5);

}

static int h264_find_frame_end(H264ParseContext *p, const uint8_t *buf,

                               int buf_size)

{

    int i;

    uint32_t state;

    ParseContext *pc = &p->pc;



    state = pc->state;

    if (state > 13)

        state = 7;



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

        if (state == 7) {

            i += p->h264dsp.startcode_find_candidate(buf + i, buf_size - i);

            if (i < buf_size)

                state = 2;

        } else if (state <= 2) {

            if (buf[i] == 1)

                state ^= 5;            

            else if (buf[i])

                state = 7;

            else

                state >>= 1;           

        } else if (state <= 5) {

            int nalu_type = buf[i] & 0x1F;

            if (nalu_type == NAL_SEI || nalu_type == NAL_SPS ||

                nalu_type == NAL_PPS || nalu_type == NAL_AUD) {

                if (pc->frame_start_found) {

                    i++;

                    goto found;

                }

            } else if (nalu_type == NAL_SLICE || nalu_type == NAL_DPA ||

                       nalu_type == NAL_IDR_SLICE) {

                if (pc->frame_start_found) {

                    state += 8;

                    continue;

                } else

                    pc->frame_start_found = 1;

            }

            state = 7;

        } else {

            

            if (buf[i] & 0x80)

                goto found;

            state = 7;

        }

    }

    pc->state = state;

    return END_NOT_FOUND;



found:

    pc->state             = 7;

    pc->frame_start_found = 0;

    return i - (state & 5);

}

static int FUNC_0(H264ParseContext *VAR_0, const uint8_t *VAR_1,

                               int VAR_2)

{

    int VAR_3;

    uint32_t state;

    ParseContext *pc = &VAR_0->pc;



    state = pc->state;

    if (state > 13)

        state = 7;



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

        if (state == 7) {

            VAR_3 += VAR_0->h264dsp.startcode_find_candidate(VAR_1 + VAR_3, VAR_2 - VAR_3);

            if (VAR_3 < VAR_2)

                state = 2;

        } else if (state <= 2) {

            if (VAR_1[VAR_3] == 1)

                state ^= 5;            

            else if (VAR_1[VAR_3])

                state = 7;

            else

                state >>= 1;           

        } else if (state <= 5) {

            int VAR_4 = VAR_1[VAR_3] & 0x1F;

            if (VAR_4 == NAL_SEI || VAR_4 == NAL_SPS ||

                VAR_4 == NAL_PPS || VAR_4 == NAL_AUD) {

                if (pc->frame_start_found) {

                    VAR_3++;

                    goto found;

                }

            } else if (VAR_4 == NAL_SLICE || VAR_4 == NAL_DPA ||

                       VAR_4 == NAL_IDR_SLICE) {

                if (pc->frame_start_found) {

                    state += 8;

                    continue;

                } else

                    pc->frame_start_found = 1;

            }

            state = 7;

        } else {

            

            if (VAR_1[VAR_3] & 0x80)

                goto found;

            state = 7;

        }

    }

    pc->state = state;

    return END_NOT_FOUND;



found:

    pc->state             = 7;

    pc->frame_start_found = 0;

    return VAR_3 - (state & 5);

}

static int FUNC_0(H264ParseContext *VAR_0, const uint8_t *VAR_1,
int VAR_2)
{ int VAR_3; uint32_t state; ParseContext *pc = &VAR_0->pc; state = pc->state; if (state > 13)
state = 7; for (VAR_3 = 0; VAR_3 < VAR_2; VAR_3++) { if (state == 7) { VAR_3 += VAR_0->h264dsp.startcode_find_candidate(VAR_1 + VAR_3, VAR_2 - VAR_3); if (VAR_3 < VAR_2)
state = 2; } else if (state <= 2) { if (VAR_1[VAR_3] == 1)
state ^= 5; else if (VAR_1[VAR_3])
state = 7; else
state >>= 1; } else if (state <= 5) { int VAR_4 = VAR_1[VAR_3] & 0x1F; if (VAR_4 == NAL_SEI || VAR_4 == NAL_SPS ||
VAR_4 == NAL_PPS || VAR_4 == NAL_AUD) { if (pc->frame_start_found) { VAR_3++; goto found; } } else if (VAR_4 == NAL_SLICE || VAR_4 == NAL_DPA || VAR_4 == NAL_IDR_SLICE) { if (pc->frame_start_found) { state += 8; continue; } else pc->frame_start_found = 1; } state = 7; } else { if (VAR_1[VAR_3] & 0x80)
goto found; state = 7; } } pc->state = state; return END_NOT_FOUND; found:
pc->state             = 7; pc->frame_start_found = 0; return VAR_3 - (state & 5); }