static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,

                            int parse_extradata)

{

    MpegEncContext *const s     = &h->s;

    AVCodecContext *const avctx = s->avctx;

    H264Context *hx; ///< thread context

    int buf_index;

    int context_count;

    int next_avc;

    int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);

    int nals_needed = 0; ///< number of NALs that need decoding before the next frame thread starts

    int nal_index;

    int idr_cleared=0;

    int first_slice = 0;



    h->nal_unit_type= 0;



    if(!s->slice_context_count)

         s->slice_context_count= 1;

    h->max_contexts = s->slice_context_count;

    if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) {

        h->current_slice = 0;

        if (!s->first_field)

            s->current_picture_ptr = NULL;

        ff_h264_reset_sei(h);

    }



    if (h->nal_length_size == 4) {

        if (buf_size > 8 && AV_RB32(buf) == 1 && AV_RB32(buf+5) > (unsigned)buf_size) {

            h->is_avc = 0;

        }else if(buf_size > 3 && AV_RB32(buf) > 1 && AV_RB32(buf) <= (unsigned)buf_size)

            h->is_avc = 1;

    }



    for (; pass <= 1; pass++) {

        buf_index     = 0;

        context_count = 0;

        next_avc      = h->is_avc ? 0 : buf_size;

        nal_index     = 0;

        for (;;) {

            int consumed;

            int dst_length;

            int bit_length;

            const uint8_t *ptr;

            int i, nalsize = 0;

            int err;



            if (buf_index >= next_avc) {

                if (buf_index >= buf_size - h->nal_length_size)

                    break;

                nalsize = 0;

                for (i = 0; i < h->nal_length_size; i++)

                    nalsize = (nalsize << 8) | buf[buf_index++];

                if (nalsize <= 0 || nalsize > buf_size - buf_index) {

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "AVC: nal size %d\n", nalsize);

                    break;

                }

                next_avc = buf_index + nalsize;

            } else {

                // start code prefix search

                for (; buf_index + 3 < next_avc; buf_index++)

                    // This should always succeed in the first iteration.

                    if (buf[buf_index]     == 0 &&

                        buf[buf_index + 1] == 0 &&

                        buf[buf_index + 2] == 1)

                        break;



                if (buf_index + 3 >= buf_size) {

                    buf_index = buf_size;

                    break;

                }



                buf_index += 3;

                if (buf_index >= next_avc)

                    continue;

            }



            hx = h->thread_context[context_count];



            ptr = ff_h264_decode_nal(hx, buf + buf_index, &dst_length,

                                     &consumed, next_avc - buf_index);

            if (ptr == NULL || dst_length < 0) {

                buf_index = -1;

                goto end;

            }

            i = buf_index + consumed;

            if ((s->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc &&

                buf[i]     == 0x00 && buf[i + 1] == 0x00 &&

                buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)

                s->workaround_bugs |= FF_BUG_TRUNCATED;



            if (!(s->workaround_bugs & FF_BUG_TRUNCATED))

                while(dst_length > 0 && ptr[dst_length - 1] == 0)

                    dst_length--;

            bit_length = !dst_length ? 0

                                     : (8 * dst_length -

                                        decode_rbsp_trailing(h, ptr + dst_length - 1));



            if (s->avctx->debug & FF_DEBUG_STARTCODE)

                av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass);



            if (h->is_avc && (nalsize != consumed) && nalsize)

                av_log(h->s.avctx, AV_LOG_DEBUG,

                       "AVC: Consumed only %d bytes instead of %d\n",

                       consumed, nalsize);



            buf_index += consumed;

            nal_index++;



            if (pass == 0) {

                /* packets can sometimes contain multiple PPS/SPS,

                 * e.g. two PAFF field pictures in one packet, or a demuxer

                 * which splits NALs strangely if so, when frame threading we

                 * can't start the next thread until we've read all of them */

                switch (hx->nal_unit_type) {

                case NAL_SPS:

                case NAL_PPS:

                    nals_needed = nal_index;

                    break;

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    init_get_bits(&hx->s.gb, ptr, bit_length);

                    if (!get_ue_golomb(&hx->s.gb) || !first_slice)

                        nals_needed = nal_index;

                    if (!first_slice)

                        first_slice = hx->nal_unit_type;

                }

                continue;

            }



            if (!first_slice)

                switch (hx->nal_unit_type) {

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    first_slice = hx->nal_unit_type;

                }



            // FIXME do not discard SEI id

            if (avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)

                continue;



again:

            /* Ignore every NAL unit type except PPS and SPS during extradata

             * parsing. Decoding slices is not possible in codec init

             * with frame-mt */

            if (parse_extradata && HAVE_THREADS &&

                (s->avctx->active_thread_type & FF_THREAD_FRAME) &&

                (hx->nal_unit_type != NAL_PPS &&

                 hx->nal_unit_type != NAL_SPS)) {

                av_log(avctx, AV_LOG_INFO, "Ignoring NAL unit %d during "

                       "extradata parsing\n", hx->nal_unit_type);

                hx->nal_unit_type = NAL_FF_IGNORE;

            }

            err = 0;



            if (h->decoding_extradata) {

                switch (hx->nal_unit_type) {

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                case NAL_DPA:

                case NAL_DPB:

                case NAL_DPC:

                case NAL_AUXILIARY_SLICE:

                    av_log(h->s.avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header\n", hx->nal_unit_type);

                    hx->nal_unit_type = NAL_FILLER_DATA;

                }

            }



            switch (hx->nal_unit_type) {

            case NAL_IDR_SLICE:

                if (first_slice != NAL_IDR_SLICE) {

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "Invalid mix of idr and non-idr slices\n");

                    buf_index = -1;

                    goto end;

                }

                if(!idr_cleared)

                    idr(h); // FIXME ensure we don't lose some frames if there is reordering

                idr_cleared = 1;

            case NAL_SLICE:

                init_get_bits(&hx->s.gb, ptr, bit_length);

                hx->intra_gb_ptr        =

                    hx->inter_gb_ptr    = &hx->s.gb;

                hx->s.data_partitioning = 0;



                if ((err = decode_slice_header(hx, h)))

                    break;



                if (h->sei_recovery_frame_cnt >= 0 && (h->frame_num != h->sei_recovery_frame_cnt || hx->slice_type_nos != AV_PICTURE_TYPE_I))

                    h->valid_recovery_point = 1;



                if (   h->sei_recovery_frame_cnt >= 0

                    && (   h->recovery_frame<0

                        || ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt)) {

                    h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %

                                        (1 << h->sps.log2_max_frame_num);



                    if (!h->valid_recovery_point)

                        h->recovery_frame = h->frame_num;

                }



                s->current_picture_ptr->f.key_frame |=

                        (hx->nal_unit_type == NAL_IDR_SLICE);



                if (h->recovery_frame == h->frame_num) {

                    s->current_picture_ptr->sync |= 1;

                    h->recovery_frame = -1;

                }



                h->sync |= !!s->current_picture_ptr->f.key_frame;

                h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL);

                s->current_picture_ptr->sync |= h->sync;



                if (h->current_slice == 1) {

                    if (!(s->flags2 & CODEC_FLAG2_CHUNKS))

                        decode_postinit(h, nal_index >= nals_needed);



                    if (s->avctx->hwaccel &&

                        s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)

                        return -1;

                    if (CONFIG_H264_VDPAU_DECODER &&

                        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)

                        ff_vdpau_h264_picture_start(s);

                }



                if (hx->redundant_pic_count == 0 &&

                    (avctx->skip_frame < AVDISCARD_NONREF ||

                     hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL) {

                    if (avctx->hwaccel) {

                        if (avctx->hwaccel->decode_slice(avctx,

                                                         &buf[buf_index - consumed],

                                                         consumed) < 0)

                            return -1;

                    } else if (CONFIG_H264_VDPAU_DECODER &&

                               s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {

                        static const uint8_t start_code[] = {

                            0x00, 0x00, 0x01 };

                        ff_vdpau_add_data_chunk(s, start_code,

                                                sizeof(start_code));

                        ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed],

                                                consumed);

                    } else

                        context_count++;

                }

                break;

            case NAL_DPA:

                init_get_bits(&hx->s.gb, ptr, bit_length);

                hx->intra_gb_ptr =

                hx->inter_gb_ptr = NULL;



                if ((err = decode_slice_header(hx, h)) < 0)

                    break;



                hx->s.data_partitioning = 1;

                break;

            case NAL_DPB:

                init_get_bits(&hx->intra_gb, ptr, bit_length);

                hx->intra_gb_ptr = &hx->intra_gb;

                break;

            case NAL_DPC:

                init_get_bits(&hx->inter_gb, ptr, bit_length);

                hx->inter_gb_ptr = &hx->inter_gb;



                av_log(h->s.avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n");

                break;



                if (hx->redundant_pic_count == 0 &&

                    hx->intra_gb_ptr &&

                    hx->s.data_partitioning &&

                    s->current_picture_ptr &&

                    s->context_initialized &&

                    (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL)

                    context_count++;

                break;

            case NAL_SEI:

                init_get_bits(&s->gb, ptr, bit_length);

                ff_h264_decode_sei(h);

                break;

            case NAL_SPS:

                init_get_bits(&s->gb, ptr, bit_length);

                if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? (nalsize != consumed) && nalsize : 1)) {

                    av_log(h->s.avctx, AV_LOG_DEBUG,

                           "SPS decoding failure, trying again with the complete NAL\n");

                    if (h->is_avc)

                        av_assert0(next_avc - buf_index + consumed == nalsize);

                    if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)

                        break;

                    init_get_bits(&s->gb, &buf[buf_index + 1 - consumed],

                                  8*(next_avc - buf_index + consumed - 1));

                    ff_h264_decode_seq_parameter_set(h);

                }



                break;

            case NAL_PPS:

                init_get_bits(&s->gb, ptr, bit_length);

                ff_h264_decode_picture_parameter_set(h, bit_length);

                break;

            case NAL_AUD:

            case NAL_END_SEQUENCE:

            case NAL_END_STREAM:

            case NAL_FILLER_DATA:

            case NAL_SPS_EXT:

            case NAL_AUXILIARY_SLICE:

                break;

            case NAL_FF_IGNORE:

                break;

            default:

                av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",

                       hx->nal_unit_type, bit_length);

            }



            if (context_count == h->max_contexts) {

                execute_decode_slices(h, context_count);

                context_count = 0;

            }



            if (err < 0)

                av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");

            else if (err == 1) {

                /* Slice could not be decoded in parallel mode, copy down

                 * NAL unit stuff to context 0 and restart. Note that

                 * rbsp_buffer is not transferred, but since we no longer

                 * run in parallel mode this should not be an issue. */

                h->nal_unit_type = hx->nal_unit_type;

                h->nal_ref_idc   = hx->nal_ref_idc;

                hx               = h;

                goto again;

            }

        }

    }

    if (context_count)

        execute_decode_slices(h, context_count);



end:

    /* clean up */

    if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s &&

        !s->droppable) {

        ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,

                                  s->picture_structure == PICT_BOTTOM_FIELD);

    }



    return buf_index;

}

static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,

                            int parse_extradata)

{

    MpegEncContext *const s     = &h->s;

    AVCodecContext *const avctx = s->avctx;

    H264Context *hx; 

    int buf_index;

    int context_count;

    int next_avc;

    int pass = !(avctx->active_thread_type & FF_THREAD_FRAME);

    int nals_needed = 0; 

    int nal_index;

    int idr_cleared=0;

    int first_slice = 0;



    h->nal_unit_type= 0;



    if(!s->slice_context_count)

         s->slice_context_count= 1;

    h->max_contexts = s->slice_context_count;

    if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) {

        h->current_slice = 0;

        if (!s->first_field)

            s->current_picture_ptr = NULL;

        ff_h264_reset_sei(h);

    }



    if (h->nal_length_size == 4) {

        if (buf_size > 8 && AV_RB32(buf) == 1 && AV_RB32(buf+5) > (unsigned)buf_size) {

            h->is_avc = 0;

        }else if(buf_size > 3 && AV_RB32(buf) > 1 && AV_RB32(buf) <= (unsigned)buf_size)

            h->is_avc = 1;

    }



    for (; pass <= 1; pass++) {

        buf_index     = 0;

        context_count = 0;

        next_avc      = h->is_avc ? 0 : buf_size;

        nal_index     = 0;

        for (;;) {

            int consumed;

            int dst_length;

            int bit_length;

            const uint8_t *ptr;

            int i, nalsize = 0;

            int err;



            if (buf_index >= next_avc) {

                if (buf_index >= buf_size - h->nal_length_size)

                    break;

                nalsize = 0;

                for (i = 0; i < h->nal_length_size; i++)

                    nalsize = (nalsize << 8) | buf[buf_index++];

                if (nalsize <= 0 || nalsize > buf_size - buf_index) {

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "AVC: nal size %d\n", nalsize);

                    break;

                }

                next_avc = buf_index + nalsize;

            } else {

                

                for (; buf_index + 3 < next_avc; buf_index++)

                    

                    if (buf[buf_index]     == 0 &&

                        buf[buf_index + 1] == 0 &&

                        buf[buf_index + 2] == 1)

                        break;



                if (buf_index + 3 >= buf_size) {

                    buf_index = buf_size;

                    break;

                }



                buf_index += 3;

                if (buf_index >= next_avc)

                    continue;

            }



            hx = h->thread_context[context_count];



            ptr = ff_h264_decode_nal(hx, buf + buf_index, &dst_length,

                                     &consumed, next_avc - buf_index);

            if (ptr == NULL || dst_length < 0) {

                buf_index = -1;

                goto end;

            }

            i = buf_index + consumed;

            if ((s->workaround_bugs & FF_BUG_AUTODETECT) && i + 3 < next_avc &&

                buf[i]     == 0x00 && buf[i + 1] == 0x00 &&

                buf[i + 2] == 0x01 && buf[i + 3] == 0xE0)

                s->workaround_bugs |= FF_BUG_TRUNCATED;



            if (!(s->workaround_bugs & FF_BUG_TRUNCATED))

                while(dst_length > 0 && ptr[dst_length - 1] == 0)

                    dst_length--;

            bit_length = !dst_length ? 0

                                     : (8 * dst_length -

                                        decode_rbsp_trailing(h, ptr + dst_length - 1));



            if (s->avctx->debug & FF_DEBUG_STARTCODE)

                av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass);



            if (h->is_avc && (nalsize != consumed) && nalsize)

                av_log(h->s.avctx, AV_LOG_DEBUG,

                       "AVC: Consumed only %d bytes instead of %d\n",

                       consumed, nalsize);



            buf_index += consumed;

            nal_index++;



            if (pass == 0) {

                







                switch (hx->nal_unit_type) {

                case NAL_SPS:

                case NAL_PPS:

                    nals_needed = nal_index;

                    break;

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    init_get_bits(&hx->s.gb, ptr, bit_length);

                    if (!get_ue_golomb(&hx->s.gb) || !first_slice)

                        nals_needed = nal_index;

                    if (!first_slice)

                        first_slice = hx->nal_unit_type;

                }

                continue;

            }



            if (!first_slice)

                switch (hx->nal_unit_type) {

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    first_slice = hx->nal_unit_type;

                }



            

            if (avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)

                continue;



again:

            





            if (parse_extradata && HAVE_THREADS &&

                (s->avctx->active_thread_type & FF_THREAD_FRAME) &&

                (hx->nal_unit_type != NAL_PPS &&

                 hx->nal_unit_type != NAL_SPS)) {

                av_log(avctx, AV_LOG_INFO, "Ignoring NAL unit %d during "

                       "extradata parsing\n", hx->nal_unit_type);

                hx->nal_unit_type = NAL_FF_IGNORE;

            }

            err = 0;



            if (h->decoding_extradata) {

                switch (hx->nal_unit_type) {

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                case NAL_DPA:

                case NAL_DPB:

                case NAL_DPC:

                case NAL_AUXILIARY_SLICE:

                    av_log(h->s.avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header\n", hx->nal_unit_type);

                    hx->nal_unit_type = NAL_FILLER_DATA;

                }

            }



            switch (hx->nal_unit_type) {

            case NAL_IDR_SLICE:

                if (first_slice != NAL_IDR_SLICE) {

                    av_log(h->s.avctx, AV_LOG_ERROR,

                           "Invalid mix of idr and non-idr slices\n");

                    buf_index = -1;

                    goto end;

                }

                if(!idr_cleared)

                    idr(h); 

                idr_cleared = 1;

            case NAL_SLICE:

                init_get_bits(&hx->s.gb, ptr, bit_length);

                hx->intra_gb_ptr        =

                    hx->inter_gb_ptr    = &hx->s.gb;

                hx->s.data_partitioning = 0;



                if ((err = decode_slice_header(hx, h)))

                    break;



                if (h->sei_recovery_frame_cnt >= 0 && (h->frame_num != h->sei_recovery_frame_cnt || hx->slice_type_nos != AV_PICTURE_TYPE_I))

                    h->valid_recovery_point = 1;



                if (   h->sei_recovery_frame_cnt >= 0

                    && (   h->recovery_frame<0

                        || ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt)) {

                    h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) %

                                        (1 << h->sps.log2_max_frame_num);



                    if (!h->valid_recovery_point)

                        h->recovery_frame = h->frame_num;

                }



                s->current_picture_ptr->f.key_frame |=

                        (hx->nal_unit_type == NAL_IDR_SLICE);



                if (h->recovery_frame == h->frame_num) {

                    s->current_picture_ptr->sync |= 1;

                    h->recovery_frame = -1;

                }



                h->sync |= !!s->current_picture_ptr->f.key_frame;

                h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL);

                s->current_picture_ptr->sync |= h->sync;



                if (h->current_slice == 1) {

                    if (!(s->flags2 & CODEC_FLAG2_CHUNKS))

                        decode_postinit(h, nal_index >= nals_needed);



                    if (s->avctx->hwaccel &&

                        s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)

                        return -1;

                    if (CONFIG_H264_VDPAU_DECODER &&

                        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)

                        ff_vdpau_h264_picture_start(s);

                }



                if (hx->redundant_pic_count == 0 &&

                    (avctx->skip_frame < AVDISCARD_NONREF ||

                     hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL) {

                    if (avctx->hwaccel) {

                        if (avctx->hwaccel->decode_slice(avctx,

                                                         &buf[buf_index - consumed],

                                                         consumed) < 0)

                            return -1;

                    } else if (CONFIG_H264_VDPAU_DECODER &&

                               s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {

                        static const uint8_t start_code[] = {

                            0x00, 0x00, 0x01 };

                        ff_vdpau_add_data_chunk(s, start_code,

                                                sizeof(start_code));

                        ff_vdpau_add_data_chunk(s, &buf[buf_index - consumed],

                                                consumed);

                    } else

                        context_count++;

                }

                break;

            case NAL_DPA:

                init_get_bits(&hx->s.gb, ptr, bit_length);

                hx->intra_gb_ptr =

                hx->inter_gb_ptr = NULL;



                if ((err = decode_slice_header(hx, h)) < 0)

                    break;



                hx->s.data_partitioning = 1;

                break;

            case NAL_DPB:

                init_get_bits(&hx->intra_gb, ptr, bit_length);

                hx->intra_gb_ptr = &hx->intra_gb;

                break;

            case NAL_DPC:

                init_get_bits(&hx->inter_gb, ptr, bit_length);

                hx->inter_gb_ptr = &hx->inter_gb;



                av_log(h->s.avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n");

                break;



                if (hx->redundant_pic_count == 0 &&

                    hx->intra_gb_ptr &&

                    hx->s.data_partitioning &&

                    s->current_picture_ptr &&

                    s->context_initialized &&

                    (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL)

                    context_count++;

                break;

            case NAL_SEI:

                init_get_bits(&s->gb, ptr, bit_length);

                ff_h264_decode_sei(h);

                break;

            case NAL_SPS:

                init_get_bits(&s->gb, ptr, bit_length);

                if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? (nalsize != consumed) && nalsize : 1)) {

                    av_log(h->s.avctx, AV_LOG_DEBUG,

                           "SPS decoding failure, trying again with the complete NAL\n");

                    if (h->is_avc)

                        av_assert0(next_avc - buf_index + consumed == nalsize);

                    if ((next_avc - buf_index + consumed - 1) >= INT_MAX/8)

                        break;

                    init_get_bits(&s->gb, &buf[buf_index + 1 - consumed],

                                  8*(next_avc - buf_index + consumed - 1));

                    ff_h264_decode_seq_parameter_set(h);

                }



                break;

            case NAL_PPS:

                init_get_bits(&s->gb, ptr, bit_length);

                ff_h264_decode_picture_parameter_set(h, bit_length);

                break;

            case NAL_AUD:

            case NAL_END_SEQUENCE:

            case NAL_END_STREAM:

            case NAL_FILLER_DATA:

            case NAL_SPS_EXT:

            case NAL_AUXILIARY_SLICE:

                break;

            case NAL_FF_IGNORE:

                break;

            default:

                av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",

                       hx->nal_unit_type, bit_length);

            }



            if (context_count == h->max_contexts) {

                execute_decode_slices(h, context_count);

                context_count = 0;

            }



            if (err < 0)

                av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");

            else if (err == 1) {

                







                h->nal_unit_type = hx->nal_unit_type;

                h->nal_ref_idc   = hx->nal_ref_idc;

                hx               = h;

                goto again;

            }

        }

    }

    if (context_count)

        execute_decode_slices(h, context_count);



end:

    

    if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s &&

        !s->droppable) {

        ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,

                                  s->picture_structure == PICT_BOTTOM_FIELD);

    }



    return buf_index;

}

static int FUNC_0(H264Context *VAR_0, const uint8_t *VAR_1, int VAR_2,

                            int VAR_3)

{

    MpegEncContext *const s     = &VAR_0->s;

    AVCodecContext *const avctx = s->avctx;

    H264Context *hx; 

    int VAR_4;

    int VAR_5;

    int VAR_6;

    int VAR_7 = !(avctx->active_thread_type & FF_THREAD_FRAME);

    int VAR_8 = 0; 

    int VAR_9;

    int VAR_10=0;

    int VAR_11 = 0;



    VAR_0->nal_unit_type= 0;



    if(!s->slice_context_count)

         s->slice_context_count= 1;

    VAR_0->max_contexts = s->slice_context_count;

    if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) {

        VAR_0->current_slice = 0;

        if (!s->first_field)

            s->current_picture_ptr = NULL;

        ff_h264_reset_sei(VAR_0);

    }



    if (VAR_0->nal_length_size == 4) {

        if (VAR_2 > 8 && AV_RB32(VAR_1) == 1 && AV_RB32(VAR_1+5) > (unsigned)VAR_2) {

            VAR_0->is_avc = 0;

        }else if(VAR_2 > 3 && AV_RB32(VAR_1) > 1 && AV_RB32(VAR_1) <= (unsigned)VAR_2)

            VAR_0->is_avc = 1;

    }



    for (; VAR_7 <= 1; VAR_7++) {

        VAR_4     = 0;

        VAR_5 = 0;

        VAR_6      = VAR_0->is_avc ? 0 : VAR_2;

        VAR_9     = 0;

        for (;;) {

            int VAR_12;

            int VAR_13;

            int VAR_14;

            const uint8_t *VAR_15;

            int VAR_16, VAR_17 = 0;

            int VAR_18;



            if (VAR_4 >= VAR_6) {

                if (VAR_4 >= VAR_2 - VAR_0->nal_length_size)

                    break;

                VAR_17 = 0;

                for (VAR_16 = 0; VAR_16 < VAR_0->nal_length_size; VAR_16++)

                    VAR_17 = (VAR_17 << 8) | VAR_1[VAR_4++];

                if (VAR_17 <= 0 || VAR_17 > VAR_2 - VAR_4) {

                    av_log(VAR_0->s.avctx, AV_LOG_ERROR,

                           "AVC: nal size %d\n", VAR_17);

                    break;

                }

                VAR_6 = VAR_4 + VAR_17;

            } else {

                

                for (; VAR_4 + 3 < VAR_6; VAR_4++)

                    

                    if (VAR_1[VAR_4]     == 0 &&

                        VAR_1[VAR_4 + 1] == 0 &&

                        VAR_1[VAR_4 + 2] == 1)

                        break;



                if (VAR_4 + 3 >= VAR_2) {

                    VAR_4 = VAR_2;

                    break;

                }



                VAR_4 += 3;

                if (VAR_4 >= VAR_6)

                    continue;

            }



            hx = VAR_0->thread_context[VAR_5];



            VAR_15 = ff_h264_decode_nal(hx, VAR_1 + VAR_4, &VAR_13,

                                     &VAR_12, VAR_6 - VAR_4);

            if (VAR_15 == NULL || VAR_13 < 0) {

                VAR_4 = -1;

                goto end;

            }

            VAR_16 = VAR_4 + VAR_12;

            if ((s->workaround_bugs & FF_BUG_AUTODETECT) && VAR_16 + 3 < VAR_6 &&

                VAR_1[VAR_16]     == 0x00 && VAR_1[VAR_16 + 1] == 0x00 &&

                VAR_1[VAR_16 + 2] == 0x01 && VAR_1[VAR_16 + 3] == 0xE0)

                s->workaround_bugs |= FF_BUG_TRUNCATED;



            if (!(s->workaround_bugs & FF_BUG_TRUNCATED))

                while(VAR_13 > 0 && VAR_15[VAR_13 - 1] == 0)

                    VAR_13--;

            VAR_14 = !VAR_13 ? 0

                                     : (8 * VAR_13 -

                                        decode_rbsp_trailing(VAR_0, VAR_15 + VAR_13 - 1));



            if (s->avctx->debug & FF_DEBUG_STARTCODE)

                av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d VAR_7 %d\n", hx->nal_unit_type, hx->nal_ref_idc, VAR_4, VAR_2, VAR_13, VAR_7);



            if (VAR_0->is_avc && (VAR_17 != VAR_12) && VAR_17)

                av_log(VAR_0->s.avctx, AV_LOG_DEBUG,

                       "AVC: Consumed only %d bytes instead of %d\n",

                       VAR_12, VAR_17);



            VAR_4 += VAR_12;

            VAR_9++;



            if (VAR_7 == 0) {

                







                switch (hx->nal_unit_type) {

                case NAL_SPS:

                case NAL_PPS:

                    VAR_8 = VAR_9;

                    break;

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    init_get_bits(&hx->s.gb, VAR_15, VAR_14);

                    if (!get_ue_golomb(&hx->s.gb) || !VAR_11)

                        VAR_8 = VAR_9;

                    if (!VAR_11)

                        VAR_11 = hx->nal_unit_type;

                }

                continue;

            }



            if (!VAR_11)

                switch (hx->nal_unit_type) {

                case NAL_DPA:

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                    VAR_11 = hx->nal_unit_type;

                }



            

            if (avctx->skip_frame >= AVDISCARD_NONREF && VAR_0->nal_ref_idc == 0)

                continue;



again:

            





            if (VAR_3 && HAVE_THREADS &&

                (s->avctx->active_thread_type & FF_THREAD_FRAME) &&

                (hx->nal_unit_type != NAL_PPS &&

                 hx->nal_unit_type != NAL_SPS)) {

                av_log(avctx, AV_LOG_INFO, "Ignoring NAL unit %d during "

                       "extradata parsing\n", hx->nal_unit_type);

                hx->nal_unit_type = NAL_FF_IGNORE;

            }

            VAR_18 = 0;



            if (VAR_0->decoding_extradata) {

                switch (hx->nal_unit_type) {

                case NAL_IDR_SLICE:

                case NAL_SLICE:

                case NAL_DPA:

                case NAL_DPB:

                case NAL_DPC:

                case NAL_AUXILIARY_SLICE:

                    av_log(VAR_0->s.avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header\n", hx->nal_unit_type);

                    hx->nal_unit_type = NAL_FILLER_DATA;

                }

            }



            switch (hx->nal_unit_type) {

            case NAL_IDR_SLICE:

                if (VAR_11 != NAL_IDR_SLICE) {

                    av_log(VAR_0->s.avctx, AV_LOG_ERROR,

                           "Invalid mix of idr and non-idr slices\n");

                    VAR_4 = -1;

                    goto end;

                }

                if(!VAR_10)

                    idr(VAR_0); 

                VAR_10 = 1;

            case NAL_SLICE:

                init_get_bits(&hx->s.gb, VAR_15, VAR_14);

                hx->intra_gb_ptr        =

                    hx->inter_gb_ptr    = &hx->s.gb;

                hx->s.data_partitioning = 0;



                if ((VAR_18 = decode_slice_header(hx, VAR_0)))

                    break;



                if (VAR_0->sei_recovery_frame_cnt >= 0 && (VAR_0->frame_num != VAR_0->sei_recovery_frame_cnt || hx->slice_type_nos != AV_PICTURE_TYPE_I))

                    VAR_0->valid_recovery_point = 1;



                if (   VAR_0->sei_recovery_frame_cnt >= 0

                    && (   VAR_0->recovery_frame<0

                        || ((VAR_0->recovery_frame - VAR_0->frame_num) & ((1 << VAR_0->sps.log2_max_frame_num)-1)) > VAR_0->sei_recovery_frame_cnt)) {

                    VAR_0->recovery_frame = (VAR_0->frame_num + VAR_0->sei_recovery_frame_cnt) %

                                        (1 << VAR_0->sps.log2_max_frame_num);



                    if (!VAR_0->valid_recovery_point)

                        VAR_0->recovery_frame = VAR_0->frame_num;

                }



                s->current_picture_ptr->f.key_frame |=

                        (hx->nal_unit_type == NAL_IDR_SLICE);



                if (VAR_0->recovery_frame == VAR_0->frame_num) {

                    s->current_picture_ptr->sync |= 1;

                    VAR_0->recovery_frame = -1;

                }



                VAR_0->sync |= !!s->current_picture_ptr->f.key_frame;

                VAR_0->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL);

                s->current_picture_ptr->sync |= VAR_0->sync;



                if (VAR_0->current_slice == 1) {

                    if (!(s->flags2 & CODEC_FLAG2_CHUNKS))

                        decode_postinit(VAR_0, VAR_9 >= VAR_8);



                    if (s->avctx->hwaccel &&

                        s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)

                        return -1;

                    if (CONFIG_H264_VDPAU_DECODER &&

                        s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)

                        ff_vdpau_h264_picture_start(s);

                }



                if (hx->redundant_pic_count == 0 &&

                    (avctx->skip_frame < AVDISCARD_NONREF ||

                     hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL) {

                    if (avctx->hwaccel) {

                        if (avctx->hwaccel->decode_slice(avctx,

                                                         &VAR_1[VAR_4 - VAR_12],

                                                         VAR_12) < 0)

                            return -1;

                    } else if (CONFIG_H264_VDPAU_DECODER &&

                               s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {

                        static const uint8_t VAR_19[] = {

                            0x00, 0x00, 0x01 };

                        ff_vdpau_add_data_chunk(s, VAR_19,

                                                sizeof(VAR_19));

                        ff_vdpau_add_data_chunk(s, &VAR_1[VAR_4 - VAR_12],

                                                VAR_12);

                    } else

                        VAR_5++;

                }

                break;

            case NAL_DPA:

                init_get_bits(&hx->s.gb, VAR_15, VAR_14);

                hx->intra_gb_ptr =

                hx->inter_gb_ptr = NULL;



                if ((VAR_18 = decode_slice_header(hx, VAR_0)) < 0)

                    break;



                hx->s.data_partitioning = 1;

                break;

            case NAL_DPB:

                init_get_bits(&hx->intra_gb, VAR_15, VAR_14);

                hx->intra_gb_ptr = &hx->intra_gb;

                break;

            case NAL_DPC:

                init_get_bits(&hx->inter_gb, VAR_15, VAR_14);

                hx->inter_gb_ptr = &hx->inter_gb;



                av_log(VAR_0->s.avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n");

                break;



                if (hx->redundant_pic_count == 0 &&

                    hx->intra_gb_ptr &&

                    hx->s.data_partitioning &&

                    s->current_picture_ptr &&

                    s->context_initialized &&

                    (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&

                    (avctx->skip_frame < AVDISCARD_BIDIR  ||

                     hx->slice_type_nos != AV_PICTURE_TYPE_B) &&

                    (avctx->skip_frame < AVDISCARD_NONKEY ||

                     hx->slice_type_nos == AV_PICTURE_TYPE_I) &&

                    avctx->skip_frame < AVDISCARD_ALL)

                    VAR_5++;

                break;

            case NAL_SEI:

                init_get_bits(&s->gb, VAR_15, VAR_14);

                ff_h264_decode_sei(VAR_0);

                break;

            case NAL_SPS:

                init_get_bits(&s->gb, VAR_15, VAR_14);

                if (ff_h264_decode_seq_parameter_set(VAR_0) < 0 && (VAR_0->is_avc ? (VAR_17 != VAR_12) && VAR_17 : 1)) {

                    av_log(VAR_0->s.avctx, AV_LOG_DEBUG,

                           "SPS decoding failure, trying again with the complete NAL\n");

                    if (VAR_0->is_avc)

                        av_assert0(VAR_6 - VAR_4 + VAR_12 == VAR_17);

                    if ((VAR_6 - VAR_4 + VAR_12 - 1) >= INT_MAX/8)

                        break;

                    init_get_bits(&s->gb, &VAR_1[VAR_4 + 1 - VAR_12],

                                  8*(VAR_6 - VAR_4 + VAR_12 - 1));

                    ff_h264_decode_seq_parameter_set(VAR_0);

                }



                break;

            case NAL_PPS:

                init_get_bits(&s->gb, VAR_15, VAR_14);

                ff_h264_decode_picture_parameter_set(VAR_0, VAR_14);

                break;

            case NAL_AUD:

            case NAL_END_SEQUENCE:

            case NAL_END_STREAM:

            case NAL_FILLER_DATA:

            case NAL_SPS_EXT:

            case NAL_AUXILIARY_SLICE:

                break;

            case NAL_FF_IGNORE:

                break;

            default:

                av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",

                       hx->nal_unit_type, VAR_14);

            }



            if (VAR_5 == VAR_0->max_contexts) {

                execute_decode_slices(VAR_0, VAR_5);

                VAR_5 = 0;

            }



            if (VAR_18 < 0)

                av_log(VAR_0->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");

            else if (VAR_18 == 1) {

                







                VAR_0->nal_unit_type = hx->nal_unit_type;

                VAR_0->nal_ref_idc   = hx->nal_ref_idc;

                hx               = VAR_0;

                goto again;

            }

        }

    }

    if (VAR_5)

        execute_decode_slices(VAR_0, VAR_5);



end:

    

    if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s &&

        !s->droppable) {

        ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,

                                  s->picture_structure == PICT_BOTTOM_FIELD);

    }



    return VAR_4;

}

static int FUNC_0(H264Context *VAR_0, const uint8_t *VAR_1, int VAR_2,
int VAR_3)
{ MpegEncContext *const s     = &VAR_0->s; AVCodecContext *const avctx = s->avctx; H264Context *hx; int VAR_4; int VAR_5; int VAR_6; int VAR_7 = !(avctx->active_thread_type & FF_THREAD_FRAME); int VAR_8 = 0; int VAR_9; int VAR_10=0; int VAR_11 = 0; VAR_0->nal_unit_type= 0; if(!s->slice_context_count)
s->slice_context_count= 1; VAR_0->max_contexts = s->slice_context_count; if (!(s->flags2 & CODEC_FLAG2_CHUNKS)) { VAR_0->current_slice = 0; if (!s->first_field)
s->current_picture_ptr = NULL; ff_h264_reset_sei(VAR_0); } if (VAR_0->nal_length_size == 4) { if (VAR_2 > 8 && AV_RB32(VAR_1) == 1 && AV_RB32(VAR_1+5) > (unsigned)VAR_2) { VAR_0->is_avc = 0; }else if(VAR_2 > 3 && AV_RB32(VAR_1) > 1 && AV_RB32(VAR_1) <= (unsigned)VAR_2) VAR_0->is_avc = 1; } for (; VAR_7 <= 1; VAR_7++) { VAR_4     = 0; VAR_5 = 0; VAR_6      = VAR_0->is_avc ? 0 : VAR_2; VAR_9     = 0; for (;;) { int VAR_12; int VAR_13; int VAR_14; const uint8_t *VAR_15; int VAR_16, VAR_17 = 0; int VAR_18; if (VAR_4 >= VAR_6) { if (VAR_4 >= VAR_2 - VAR_0->nal_length_size)
break; VAR_17 = 0; for (VAR_16 = 0; VAR_16 < VAR_0->nal_length_size; VAR_16++) VAR_17 = (VAR_17 << 8) | VAR_1[VAR_4++]; if (VAR_17 <= 0 || VAR_17 > VAR_2 - VAR_4) { av_log(VAR_0->s.avctx, AV_LOG_ERROR,
"AVC: nal size %d\n", VAR_17); break; } VAR_6 = VAR_4 + VAR_17; } else { for (; VAR_4 + 3 < VAR_6; VAR_4++) if (VAR_1[VAR_4]     == 0 &&
VAR_1[VAR_4 + 1] == 0 &&
VAR_1[VAR_4 + 2] == 1)
break; if (VAR_4 + 3 >= VAR_2) { VAR_4 = VAR_2; break; } VAR_4 += 3; if (VAR_4 >= VAR_6)
continue; } hx = VAR_0->thread_context[VAR_5]; VAR_15 = ff_h264_decode_nal(hx, VAR_1 + VAR_4, &VAR_13,
&VAR_12, VAR_6 - VAR_4); if (VAR_15 == NULL || VAR_13 < 0) { VAR_4 = -1; goto end; } VAR_16 = VAR_4 + VAR_12; if ((s->workaround_bugs & FF_BUG_AUTODETECT) && VAR_16 + 3 < VAR_6 &&
VAR_1[VAR_16]     == 0x00 && VAR_1[VAR_16 + 1] == 0x00 &&
VAR_1[VAR_16 + 2] == 0x01 && VAR_1[VAR_16 + 3] == 0xE0)
s->workaround_bugs |= FF_BUG_TRUNCATED; if (!(s->workaround_bugs & FF_BUG_TRUNCATED))
while(VAR_13 > 0 && VAR_15[VAR_13 - 1] == 0)
VAR_13--; VAR_14 = !VAR_13 ? 0
: (8 * VAR_13 -
decode_rbsp_trailing(VAR_0, VAR_15 + VAR_13 - 1)); if (s->avctx->debug & FF_DEBUG_STARTCODE)
av_log(VAR_0->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d VAR_7 %d\n", hx->nal_unit_type, hx->nal_ref_idc, VAR_4, VAR_2, VAR_13, VAR_7); if (VAR_0->is_avc && (VAR_17 != VAR_12) && VAR_17)
av_log(VAR_0->s.avctx, AV_LOG_DEBUG,
"AVC: Consumed only %d bytes instead of %d\n",
VAR_12, VAR_17); VAR_4 += VAR_12; VAR_9++; if (VAR_7 == 0) { switch (hx->nal_unit_type) { case NAL_SPS:
case NAL_PPS:
VAR_8 = VAR_9; break; case NAL_DPA:
case NAL_IDR_SLICE:
case NAL_SLICE:
init_get_bits(&hx->s.gb, VAR_15, VAR_14); if (!get_ue_golomb(&hx->s.gb) || !VAR_11)
VAR_8 = VAR_9; if (!VAR_11)
VAR_11 = hx->nal_unit_type; } continue; } if (!VAR_11)
switch (hx->nal_unit_type) { case NAL_DPA:
case NAL_IDR_SLICE:
case NAL_SLICE:
VAR_11 = hx->nal_unit_type; } if (avctx->skip_frame >= AVDISCARD_NONREF && VAR_0->nal_ref_idc == 0)
continue; again:
if (VAR_3 && HAVE_THREADS &&
(s->avctx->active_thread_type & FF_THREAD_FRAME) &&
(hx->nal_unit_type != NAL_PPS &&
hx->nal_unit_type != NAL_SPS)) { av_log(avctx, AV_LOG_INFO, "Ignoring NAL unit %d during "
"extradata parsing\n", hx->nal_unit_type); hx->nal_unit_type = NAL_FF_IGNORE; } VAR_18 = 0; if (VAR_0->decoding_extradata) { switch (hx->nal_unit_type) { case NAL_IDR_SLICE:
case NAL_SLICE:
case NAL_DPA:
case NAL_DPB:
case NAL_DPC:
case NAL_AUXILIARY_SLICE:
av_log(VAR_0->s.avctx, AV_LOG_WARNING, "Ignoring NAL %d in global header\n", hx->nal_unit_type); hx->nal_unit_type = NAL_FILLER_DATA; } } switch (hx->nal_unit_type) { case NAL_IDR_SLICE:
if (VAR_11 != NAL_IDR_SLICE) { av_log(VAR_0->s.avctx, AV_LOG_ERROR,
"Invalid mix of idr and non-idr slices\n"); VAR_4 = -1; goto end; } if(!VAR_10)
idr(VAR_0); VAR_10 = 1; case NAL_SLICE:
init_get_bits(&hx->s.gb, VAR_15, VAR_14); hx->intra_gb_ptr        =
hx->inter_gb_ptr    = &hx->s.gb; hx->s.data_partitioning = 0; if ((VAR_18 = decode_slice_header(hx, VAR_0)))
break; if (VAR_0->sei_recovery_frame_cnt >= 0 && (VAR_0->frame_num != VAR_0->sei_recovery_frame_cnt || hx->slice_type_nos != AV_PICTURE_TYPE_I))
VAR_0->valid_recovery_point = 1; if (   VAR_0->sei_recovery_frame_cnt >= 0
&& (   VAR_0->recovery_frame<0
|| ((VAR_0->recovery_frame - VAR_0->frame_num) & ((1 << VAR_0->sps.log2_max_frame_num)-1)) > VAR_0->sei_recovery_frame_cnt)) { VAR_0->recovery_frame = (VAR_0->frame_num + VAR_0->sei_recovery_frame_cnt) %
(1 << VAR_0->sps.log2_max_frame_num); if (!VAR_0->valid_recovery_point)
VAR_0->recovery_frame = VAR_0->frame_num; } s->current_picture_ptr->f.key_frame |=
(hx->nal_unit_type == NAL_IDR_SLICE); if (VAR_0->recovery_frame == VAR_0->frame_num) { s->current_picture_ptr->sync |= 1; VAR_0->recovery_frame = -1; } VAR_0->sync |= !!s->current_picture_ptr->f.key_frame; VAR_0->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL); s->current_picture_ptr->sync |= VAR_0->sync; if (VAR_0->current_slice == 1) { if (!(s->flags2 & CODEC_FLAG2_CHUNKS))
decode_postinit(VAR_0, VAR_9 >= VAR_8); if (s->avctx->hwaccel &&
s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0)
return -1; if (CONFIG_H264_VDPAU_DECODER &&
s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
ff_vdpau_h264_picture_start(s); } if (hx->redundant_pic_count == 0 &&
(avctx->skip_frame < AVDISCARD_NONREF ||
hx->nal_ref_idc) &&
(avctx->skip_frame < AVDISCARD_BIDIR  ||
hx->slice_type_nos != AV_PICTURE_TYPE_B) &&
(avctx->skip_frame < AVDISCARD_NONKEY ||
hx->slice_type_nos == AV_PICTURE_TYPE_I) &&
avctx->skip_frame < AVDISCARD_ALL) { if (avctx->hwaccel) { if (avctx->hwaccel->decode_slice(avctx,
&VAR_1[VAR_4 - VAR_12],
VAR_12) < 0)
return -1; } else if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) { static const uint8_t VAR_19[] = { 0x00, 0x00, 0x01 }; ff_vdpau_add_data_chunk(s, VAR_19,
sizeof(VAR_19)); ff_vdpau_add_data_chunk(s, &VAR_1[VAR_4 - VAR_12],
VAR_12); } else VAR_5++; } break; case NAL_DPA:
init_get_bits(&hx->s.gb, VAR_15, VAR_14); hx->intra_gb_ptr =
hx->inter_gb_ptr = NULL; if ((VAR_18 = decode_slice_header(hx, VAR_0)) < 0)
break; hx->s.data_partitioning = 1; break; case NAL_DPB:
init_get_bits(&hx->intra_gb, VAR_15, VAR_14); hx->intra_gb_ptr = &hx->intra_gb; break; case NAL_DPC:
init_get_bits(&hx->inter_gb, VAR_15, VAR_14); hx->inter_gb_ptr = &hx->inter_gb; av_log(VAR_0->s.avctx, AV_LOG_ERROR, "Partitioned H.264 support is incomplete\n"); break; if (hx->redundant_pic_count == 0 &&
hx->intra_gb_ptr &&
hx->s.data_partitioning &&
s->current_picture_ptr &&
s->context_initialized &&
(avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) &&
(avctx->skip_frame < AVDISCARD_BIDIR  ||
hx->slice_type_nos != AV_PICTURE_TYPE_B) &&
(avctx->skip_frame < AVDISCARD_NONKEY ||
hx->slice_type_nos == AV_PICTURE_TYPE_I) &&
avctx->skip_frame < AVDISCARD_ALL)
VAR_5++; break; case NAL_SEI:
init_get_bits(&s->gb, VAR_15, VAR_14); ff_h264_decode_sei(VAR_0); break; case NAL_SPS:
init_get_bits(&s->gb, VAR_15, VAR_14); if (ff_h264_decode_seq_parameter_set(VAR_0) < 0 && (VAR_0->is_avc ? (VAR_17 != VAR_12) && VAR_17 : 1)) { av_log(VAR_0->s.avctx, AV_LOG_DEBUG,
"SPS decoding failure, trying again with the complete NAL\n"); if (VAR_0->is_avc)
av_assert0(VAR_6 - VAR_4 + VAR_12 == VAR_17); if ((VAR_6 - VAR_4 + VAR_12 - 1) >= INT_MAX/8)
break; init_get_bits(&s->gb, &VAR_1[VAR_4 + 1 - VAR_12],
8*(VAR_6 - VAR_4 + VAR_12 - 1)); ff_h264_decode_seq_parameter_set(VAR_0); } break; case NAL_PPS:
init_get_bits(&s->gb, VAR_15, VAR_14); ff_h264_decode_picture_parameter_set(VAR_0, VAR_14); break; case NAL_AUD:
case NAL_END_SEQUENCE:
case NAL_END_STREAM:
case NAL_FILLER_DATA:
case NAL_SPS_EXT:
case NAL_AUXILIARY_SLICE:
break; case NAL_FF_IGNORE:
break; default:
av_log(avctx, AV_LOG_DEBUG, "Unknown NAL code: %d (%d bits)\n",
hx->nal_unit_type, VAR_14); } if (VAR_5 == VAR_0->max_contexts) { execute_decode_slices(VAR_0, VAR_5); VAR_5 = 0; } if (VAR_18 < 0)
av_log(VAR_0->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); else if (VAR_18 == 1) { VAR_0->nal_unit_type = hx->nal_unit_type; VAR_0->nal_ref_idc   = hx->nal_ref_idc; hx               = VAR_0; goto again; } } } if (VAR_5)
execute_decode_slices(VAR_0, VAR_5); end:
if (s->current_picture_ptr && s->current_picture_ptr->owner2 == s &&
!s->droppable) { ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX,
s->picture_structure == PICT_BOTTOM_FIELD); } return VAR_4; }