static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)

{

    HEVCLocalContext *lc = s->HEVClc;

    GetBitContext *gb    = &lc->gb;

    int ctb_addr_ts, ret;



    *gb              = nal->gb;

    s->nal_unit_type = nal->type;

    s->temporal_id   = nal->temporal_id;



    switch (s->nal_unit_type) {

    case HEVC_NAL_VPS:

        ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_SPS:

        ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps,

                                     s->apply_defdispwin);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_PPS:

        ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_SEI_PREFIX:

    case HEVC_NAL_SEI_SUFFIX:

        ret = ff_hevc_decode_nal_sei(s);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_TRAIL_R:

    case HEVC_NAL_TRAIL_N:

    case HEVC_NAL_TSA_N:

    case HEVC_NAL_TSA_R:

    case HEVC_NAL_STSA_N:

    case HEVC_NAL_STSA_R:

    case HEVC_NAL_BLA_W_LP:

    case HEVC_NAL_BLA_W_RADL:

    case HEVC_NAL_BLA_N_LP:

    case HEVC_NAL_IDR_W_RADL:

    case HEVC_NAL_IDR_N_LP:

    case HEVC_NAL_CRA_NUT:

    case HEVC_NAL_RADL_N:

    case HEVC_NAL_RADL_R:

    case HEVC_NAL_RASL_N:

    case HEVC_NAL_RASL_R:

        ret = hls_slice_header(s);

        if (ret < 0)

            return ret;



        if (s->max_ra == INT_MAX) {

            if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {

                s->max_ra = s->poc;

            } else {

                if (IS_IDR(s))

                    s->max_ra = INT_MIN;

            }

        }



        if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&

            s->poc <= s->max_ra) {

            s->is_decoded = 0;

            break;

        } else {

            if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra)

                s->max_ra = INT_MIN;

        }



        if (s->sh.first_slice_in_pic_flag) {

            ret = hevc_frame_start(s);

            if (ret < 0)

                return ret;

        } else if (!s->ref) {

            av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");

            goto fail;

        }



        if (s->nal_unit_type != s->first_nal_type) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Non-matching NAL types of the VCL NALUs: %d %d\n",

                   s->first_nal_type, s->nal_unit_type);

            return AVERROR_INVALIDDATA;

        }



        if (!s->sh.dependent_slice_segment_flag &&

            s->sh.slice_type != HEVC_SLICE_I) {

            ret = ff_hevc_slice_rpl(s);

            if (ret < 0) {

                av_log(s->avctx, AV_LOG_WARNING,

                       "Error constructing the reference lists for the current slice.\n");

                goto fail;

            }

        }



        if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) {

            ret = s->avctx->hwaccel->start_frame(s->avctx, NULL, 0);

            if (ret < 0)

                goto fail;

        }



        if (s->avctx->hwaccel) {

            ret = s->avctx->hwaccel->decode_slice(s->avctx, nal->raw_data, nal->raw_size);

            if (ret < 0)

                goto fail;

        } else {

            if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)

                ctb_addr_ts = hls_slice_data_wpp(s, nal);

            else

                ctb_addr_ts = hls_slice_data(s);

            if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) {

                s->is_decoded = 1;

            }



            if (ctb_addr_ts < 0) {

                ret = ctb_addr_ts;

                goto fail;

            }

        }

        break;

    case HEVC_NAL_EOS_NUT:

    case HEVC_NAL_EOB_NUT:

        s->seq_decode = (s->seq_decode + 1) & 0xff;

        s->max_ra     = INT_MAX;

        break;

    case HEVC_NAL_AUD:

    case HEVC_NAL_FD_NUT:

        break;

    default:

        av_log(s->avctx, AV_LOG_INFO,

               "Skipping NAL unit %d\n", s->nal_unit_type);

    }



    return 0;

fail:

    if (s->avctx->err_recognition & AV_EF_EXPLODE)

        return ret;

    return 0;

}

static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)

{

    HEVCLocalContext *lc = s->HEVClc;

    GetBitContext *gb    = &lc->gb;

    int ctb_addr_ts, ret;



    *gb              = nal->gb;

    s->nal_unit_type = nal->type;

    s->temporal_id   = nal->temporal_id;



    switch (s->nal_unit_type) {

    case HEVC_NAL_VPS:

        ret = ff_hevc_decode_nal_vps(gb, s->avctx, &s->ps);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_SPS:

        ret = ff_hevc_decode_nal_sps(gb, s->avctx, &s->ps,

                                     s->apply_defdispwin);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_PPS:

        ret = ff_hevc_decode_nal_pps(gb, s->avctx, &s->ps);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_SEI_PREFIX:

    case HEVC_NAL_SEI_SUFFIX:

        ret = ff_hevc_decode_nal_sei(s);

        if (ret < 0)

            goto fail;

        break;

    case HEVC_NAL_TRAIL_R:

    case HEVC_NAL_TRAIL_N:

    case HEVC_NAL_TSA_N:

    case HEVC_NAL_TSA_R:

    case HEVC_NAL_STSA_N:

    case HEVC_NAL_STSA_R:

    case HEVC_NAL_BLA_W_LP:

    case HEVC_NAL_BLA_W_RADL:

    case HEVC_NAL_BLA_N_LP:

    case HEVC_NAL_IDR_W_RADL:

    case HEVC_NAL_IDR_N_LP:

    case HEVC_NAL_CRA_NUT:

    case HEVC_NAL_RADL_N:

    case HEVC_NAL_RADL_R:

    case HEVC_NAL_RASL_N:

    case HEVC_NAL_RASL_R:

        ret = hls_slice_header(s);

        if (ret < 0)

            return ret;



        if (s->max_ra == INT_MAX) {

            if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {

                s->max_ra = s->poc;

            } else {

                if (IS_IDR(s))

                    s->max_ra = INT_MIN;

            }

        }



        if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&

            s->poc <= s->max_ra) {

            s->is_decoded = 0;

            break;

        } else {

            if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra)

                s->max_ra = INT_MIN;

        }



        if (s->sh.first_slice_in_pic_flag) {

            ret = hevc_frame_start(s);

            if (ret < 0)

                return ret;

        } else if (!s->ref) {

            av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");

            goto fail;

        }



        if (s->nal_unit_type != s->first_nal_type) {

            av_log(s->avctx, AV_LOG_ERROR,

                   "Non-matching NAL types of the VCL NALUs: %d %d\n",

                   s->first_nal_type, s->nal_unit_type);

            return AVERROR_INVALIDDATA;

        }



        if (!s->sh.dependent_slice_segment_flag &&

            s->sh.slice_type != HEVC_SLICE_I) {

            ret = ff_hevc_slice_rpl(s);

            if (ret < 0) {

                av_log(s->avctx, AV_LOG_WARNING,

                       "Error constructing the reference lists for the current slice.\n");

                goto fail;

            }

        }



        if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) {

            ret = s->avctx->hwaccel->start_frame(s->avctx, NULL, 0);

            if (ret < 0)

                goto fail;

        }



        if (s->avctx->hwaccel) {

            ret = s->avctx->hwaccel->decode_slice(s->avctx, nal->raw_data, nal->raw_size);

            if (ret < 0)

                goto fail;

        } else {

            if (s->threads_number > 1 && s->sh.num_entry_point_offsets > 0)

                ctb_addr_ts = hls_slice_data_wpp(s, nal);

            else

                ctb_addr_ts = hls_slice_data(s);

            if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) {

                s->is_decoded = 1;

            }



            if (ctb_addr_ts < 0) {

                ret = ctb_addr_ts;

                goto fail;

            }

        }

        break;

    case HEVC_NAL_EOS_NUT:

    case HEVC_NAL_EOB_NUT:

        s->seq_decode = (s->seq_decode + 1) & 0xff;

        s->max_ra     = INT_MAX;

        break;

    case HEVC_NAL_AUD:

    case HEVC_NAL_FD_NUT:

        break;

    default:

        av_log(s->avctx, AV_LOG_INFO,

               "Skipping NAL unit %d\n", s->nal_unit_type);

    }



    return 0;

fail:

    if (s->avctx->err_recognition & AV_EF_EXPLODE)

        return ret;

    return 0;

}

        if (s->max_ra == INT_MAX) {             if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {                 s->max_ra = s->poc;                 if (IS_IDR(s))         if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == HEVC_NAL_RASL_N) &&             s->poc <= s->max_ra) {             s->is_decoded = 0;             break;         } else {             if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra)                 s->max_ra = INT_MIN;         if (s->sh.first_slice_in_pic_flag) {
static int FUNC_0(HEVCContext *VAR_0, const H2645NAL *VAR_1)

{

    HEVCLocalContext *lc = VAR_0->HEVClc;

    GetBitContext *gb    = &lc->gb;

    int VAR_2, VAR_3;



    *gb              = VAR_1->gb;

    VAR_0->nal_unit_type = VAR_1->type;

    VAR_0->temporal_id   = VAR_1->temporal_id;



    switch (VAR_0->nal_unit_type) {

    case HEVC_NAL_VPS:

        VAR_3 = ff_hevc_decode_nal_vps(gb, VAR_0->avctx, &VAR_0->ps);

        if (VAR_3 < 0)

            goto fail;

        break;

    case HEVC_NAL_SPS:

        VAR_3 = ff_hevc_decode_nal_sps(gb, VAR_0->avctx, &VAR_0->ps,

                                     VAR_0->apply_defdispwin);

        if (VAR_3 < 0)

            goto fail;

        break;

    case HEVC_NAL_PPS:

        VAR_3 = ff_hevc_decode_nal_pps(gb, VAR_0->avctx, &VAR_0->ps);

        if (VAR_3 < 0)

            goto fail;

        break;

    case HEVC_NAL_SEI_PREFIX:

    case HEVC_NAL_SEI_SUFFIX:

        VAR_3 = ff_hevc_decode_nal_sei(VAR_0);

        if (VAR_3 < 0)

            goto fail;

        break;

    case HEVC_NAL_TRAIL_R:

    case HEVC_NAL_TRAIL_N:

    case HEVC_NAL_TSA_N:

    case HEVC_NAL_TSA_R:

    case HEVC_NAL_STSA_N:

    case HEVC_NAL_STSA_R:

    case HEVC_NAL_BLA_W_LP:

    case HEVC_NAL_BLA_W_RADL:

    case HEVC_NAL_BLA_N_LP:

    case HEVC_NAL_IDR_W_RADL:

    case HEVC_NAL_IDR_N_LP:

    case HEVC_NAL_CRA_NUT:

    case HEVC_NAL_RADL_N:

    case HEVC_NAL_RADL_R:

    case HEVC_NAL_RASL_N:

    case HEVC_NAL_RASL_R:

        VAR_3 = hls_slice_header(VAR_0);

        if (VAR_3 < 0)

            return VAR_3;



        if (VAR_0->max_ra == INT_MAX) {

            if (VAR_0->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(VAR_0)) {

                VAR_0->max_ra = VAR_0->poc;

            } else {

                if (IS_IDR(VAR_0))

                    VAR_0->max_ra = INT_MIN;

            }

        }



        if ((VAR_0->nal_unit_type == HEVC_NAL_RASL_R || VAR_0->nal_unit_type == HEVC_NAL_RASL_N) &&

            VAR_0->poc <= VAR_0->max_ra) {

            VAR_0->is_decoded = 0;

            break;

        } else {

            if (VAR_0->nal_unit_type == HEVC_NAL_RASL_R && VAR_0->poc > VAR_0->max_ra)

                VAR_0->max_ra = INT_MIN;

        }



        if (VAR_0->sh.first_slice_in_pic_flag) {

            VAR_3 = hevc_frame_start(VAR_0);

            if (VAR_3 < 0)

                return VAR_3;

        } else if (!VAR_0->ref) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");

            goto fail;

        }



        if (VAR_0->nal_unit_type != VAR_0->first_nal_type) {

            av_log(VAR_0->avctx, AV_LOG_ERROR,

                   "Non-matching NAL types of the VCL NALUs: %d %d\n",

                   VAR_0->first_nal_type, VAR_0->nal_unit_type);

            return AVERROR_INVALIDDATA;

        }



        if (!VAR_0->sh.dependent_slice_segment_flag &&

            VAR_0->sh.slice_type != HEVC_SLICE_I) {

            VAR_3 = ff_hevc_slice_rpl(VAR_0);

            if (VAR_3 < 0) {

                av_log(VAR_0->avctx, AV_LOG_WARNING,

                       "Error constructing the reference lists for the current slice.\n");

                goto fail;

            }

        }



        if (VAR_0->sh.first_slice_in_pic_flag && VAR_0->avctx->hwaccel) {

            VAR_3 = VAR_0->avctx->hwaccel->start_frame(VAR_0->avctx, NULL, 0);

            if (VAR_3 < 0)

                goto fail;

        }



        if (VAR_0->avctx->hwaccel) {

            VAR_3 = VAR_0->avctx->hwaccel->decode_slice(VAR_0->avctx, VAR_1->raw_data, VAR_1->raw_size);

            if (VAR_3 < 0)

                goto fail;

        } else {

            if (VAR_0->threads_number > 1 && VAR_0->sh.num_entry_point_offsets > 0)

                VAR_2 = hls_slice_data_wpp(VAR_0, VAR_1);

            else

                VAR_2 = hls_slice_data(VAR_0);

            if (VAR_2 >= (VAR_0->ps.sps->ctb_width * VAR_0->ps.sps->ctb_height)) {

                VAR_0->is_decoded = 1;

            }



            if (VAR_2 < 0) {

                VAR_3 = VAR_2;

                goto fail;

            }

        }

        break;

    case HEVC_NAL_EOS_NUT:

    case HEVC_NAL_EOB_NUT:

        VAR_0->seq_decode = (VAR_0->seq_decode + 1) & 0xff;

        VAR_0->max_ra     = INT_MAX;

        break;

    case HEVC_NAL_AUD:

    case HEVC_NAL_FD_NUT:

        break;

    default:

        av_log(VAR_0->avctx, AV_LOG_INFO,

               "Skipping NAL unit %d\n", VAR_0->nal_unit_type);

    }



    return 0;

fail:

    if (VAR_0->avctx->err_recognition & AV_EF_EXPLODE)

        return VAR_3;

    return 0;

}

static int FUNC_0(HEVCContext *VAR_0, const H2645NAL *VAR_1)
{ HEVCLocalContext *lc = VAR_0->HEVClc; GetBitContext *gb    = &lc->gb; int VAR_2, VAR_3; *gb              = VAR_1->gb; VAR_0->nal_unit_type = VAR_1->type; VAR_0->temporal_id   = VAR_1->temporal_id; switch (VAR_0->nal_unit_type) { case HEVC_NAL_VPS:
VAR_3 = ff_hevc_decode_nal_vps(gb, VAR_0->avctx, &VAR_0->ps); if (VAR_3 < 0)
goto fail; break; case HEVC_NAL_SPS:
VAR_3 = ff_hevc_decode_nal_sps(gb, VAR_0->avctx, &VAR_0->ps,
VAR_0->apply_defdispwin); if (VAR_3 < 0)
goto fail; break; case HEVC_NAL_PPS:
VAR_3 = ff_hevc_decode_nal_pps(gb, VAR_0->avctx, &VAR_0->ps); if (VAR_3 < 0)
goto fail; break; case HEVC_NAL_SEI_PREFIX:
case HEVC_NAL_SEI_SUFFIX:
VAR_3 = ff_hevc_decode_nal_sei(VAR_0); if (VAR_3 < 0)
goto fail; break; case HEVC_NAL_TRAIL_R:
case HEVC_NAL_TRAIL_N:
case HEVC_NAL_TSA_N:
case HEVC_NAL_TSA_R:
case HEVC_NAL_STSA_N:
case HEVC_NAL_STSA_R:
case HEVC_NAL_BLA_W_LP:
case HEVC_NAL_BLA_W_RADL:
case HEVC_NAL_BLA_N_LP:
case HEVC_NAL_IDR_W_RADL:
case HEVC_NAL_IDR_N_LP:
case HEVC_NAL_CRA_NUT:
case HEVC_NAL_RADL_N:
case HEVC_NAL_RADL_R:
case HEVC_NAL_RASL_N:
case HEVC_NAL_RASL_R:
VAR_3 = hls_slice_header(VAR_0); if (VAR_3 < 0)
return VAR_3; if (VAR_0->max_ra == INT_MAX) { if (VAR_0->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(VAR_0)) { VAR_0->max_ra = VAR_0->poc; } else { if (IS_IDR(VAR_0))
VAR_0->max_ra = INT_MIN; } } if ((VAR_0->nal_unit_type == HEVC_NAL_RASL_R || VAR_0->nal_unit_type == HEVC_NAL_RASL_N) &&
VAR_0->poc <= VAR_0->max_ra) { VAR_0->is_decoded = 0; break; } else { if (VAR_0->nal_unit_type == HEVC_NAL_RASL_R && VAR_0->poc > VAR_0->max_ra)
VAR_0->max_ra = INT_MIN; } if (VAR_0->sh.first_slice_in_pic_flag) { VAR_3 = hevc_frame_start(VAR_0); if (VAR_3 < 0)
return VAR_3; } else if (!VAR_0->ref) { av_log(VAR_0->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n"); goto fail; } if (VAR_0->nal_unit_type != VAR_0->first_nal_type) { av_log(VAR_0->avctx, AV_LOG_ERROR,
"Non-matching NAL types of the VCL NALUs: %d %d\n",
VAR_0->first_nal_type, VAR_0->nal_unit_type); return AVERROR_INVALIDDATA; } if (!VAR_0->sh.dependent_slice_segment_flag &&
VAR_0->sh.slice_type != HEVC_SLICE_I) { VAR_3 = ff_hevc_slice_rpl(VAR_0); if (VAR_3 < 0) { av_log(VAR_0->avctx, AV_LOG_WARNING,
"Error constructing the reference lists for the current slice.\n"); goto fail; } } if (VAR_0->sh.first_slice_in_pic_flag && VAR_0->avctx->hwaccel) { VAR_3 = VAR_0->avctx->hwaccel->start_frame(VAR_0->avctx, NULL, 0); if (VAR_3 < 0)
goto fail; } if (VAR_0->avctx->hwaccel) { VAR_3 = VAR_0->avctx->hwaccel->decode_slice(VAR_0->avctx, VAR_1->raw_data, VAR_1->raw_size); if (VAR_3 < 0)
goto fail; } else { if (VAR_0->threads_number > 1 && VAR_0->sh.num_entry_point_offsets > 0)
VAR_2 = hls_slice_data_wpp(VAR_0, VAR_1); else
VAR_2 = hls_slice_data(VAR_0); if (VAR_2 >= (VAR_0->ps.sps->ctb_width * VAR_0->ps.sps->ctb_height)) { VAR_0->is_decoded = 1; } if (VAR_2 < 0) { VAR_3 = VAR_2; goto fail; } } break; case HEVC_NAL_EOS_NUT:
case HEVC_NAL_EOB_NUT:
VAR_0->seq_decode = (VAR_0->seq_decode + 1) & 0xff; VAR_0->max_ra     = INT_MAX; break; case HEVC_NAL_AUD:
case HEVC_NAL_FD_NUT:
break; default:
av_log(VAR_0->avctx, AV_LOG_INFO,
"Skipping NAL unit %d\n", VAR_0->nal_unit_type); } return 0; fail:
if (VAR_0->avctx->err_recognition & AV_EF_EXPLODE)
return VAR_3; return 0; }