static int set_sps(HEVCContext *s, const HEVCSPS *sps)

{

    int ret;

    int num = 0, den = 0;



    pic_arrays_free(s);

    ret = pic_arrays_init(s, sps);

    if (ret < 0)

        goto fail;



    s->avctx->coded_width         = sps->width;

    s->avctx->coded_height        = sps->height;

    s->avctx->width               = sps->output_width;

    s->avctx->height              = sps->output_height;

    s->avctx->pix_fmt             = sps->pix_fmt;

    s->avctx->sample_aspect_ratio = sps->vui.sar;

    s->avctx->has_b_frames        = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;



    if (sps->vui.video_signal_type_present_flag)

        s->avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG

                                                               : AVCOL_RANGE_MPEG;

    else

        s->avctx->color_range = AVCOL_RANGE_MPEG;



    if (sps->vui.colour_description_present_flag) {

        s->avctx->color_primaries = sps->vui.colour_primaries;

        s->avctx->color_trc       = sps->vui.transfer_characteristic;

        s->avctx->colorspace      = sps->vui.matrix_coeffs;

    } else {

        s->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;

        s->avctx->color_trc       = AVCOL_TRC_UNSPECIFIED;

        s->avctx->colorspace      = AVCOL_SPC_UNSPECIFIED;

    }



    ff_hevc_pred_init(&s->hpc,     sps->bit_depth);

    ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);

    ff_videodsp_init (&s->vdsp,    sps->bit_depth);



    if (sps->sao_enabled) {

        av_frame_unref(s->tmp_frame);

        ret = ff_get_buffer(s->avctx, s->tmp_frame, AV_GET_BUFFER_FLAG_REF);

        if (ret < 0)

            goto fail;

        s->frame = s->tmp_frame;

    }



    s->sps = sps;

    s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data;



    if (s->vps->vps_timing_info_present_flag) {

        num = s->vps->vps_num_units_in_tick;

        den = s->vps->vps_time_scale;

    } else if (sps->vui.vui_timing_info_present_flag) {

        num = sps->vui.vui_num_units_in_tick;

        den = sps->vui.vui_time_scale;

    }



    if (num != 0 && den != 0)

        av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,

                  num, den, 1 << 30);



    return 0;



fail:

    pic_arrays_free(s);

    s->sps = NULL;

    return ret;

}

static int set_sps(HEVCContext *s, const HEVCSPS *sps)

{

    int ret;

    int num = 0, den = 0;



    pic_arrays_free(s);

    ret = pic_arrays_init(s, sps);

    if (ret < 0)

        goto fail;



    s->avctx->coded_width         = sps->width;

    s->avctx->coded_height        = sps->height;

    s->avctx->width               = sps->output_width;

    s->avctx->height              = sps->output_height;

    s->avctx->pix_fmt             = sps->pix_fmt;

    s->avctx->sample_aspect_ratio = sps->vui.sar;

    s->avctx->has_b_frames        = sps->temporal_layer[sps->max_sub_layers - 1].num_reorder_pics;



    if (sps->vui.video_signal_type_present_flag)

        s->avctx->color_range = sps->vui.video_full_range_flag ? AVCOL_RANGE_JPEG

                                                               : AVCOL_RANGE_MPEG;

    else

        s->avctx->color_range = AVCOL_RANGE_MPEG;



    if (sps->vui.colour_description_present_flag) {

        s->avctx->color_primaries = sps->vui.colour_primaries;

        s->avctx->color_trc       = sps->vui.transfer_characteristic;

        s->avctx->colorspace      = sps->vui.matrix_coeffs;

    } else {

        s->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;

        s->avctx->color_trc       = AVCOL_TRC_UNSPECIFIED;

        s->avctx->colorspace      = AVCOL_SPC_UNSPECIFIED;

    }



    ff_hevc_pred_init(&s->hpc,     sps->bit_depth);

    ff_hevc_dsp_init (&s->hevcdsp, sps->bit_depth);

    ff_videodsp_init (&s->vdsp,    sps->bit_depth);



    if (sps->sao_enabled) {

        av_frame_unref(s->tmp_frame);

        ret = ff_get_buffer(s->avctx, s->tmp_frame, AV_GET_BUFFER_FLAG_REF);

        if (ret < 0)

            goto fail;

        s->frame = s->tmp_frame;

    }



    s->sps = sps;

    s->vps = (HEVCVPS*) s->vps_list[s->sps->vps_id]->data;



    if (s->vps->vps_timing_info_present_flag) {

        num = s->vps->vps_num_units_in_tick;

        den = s->vps->vps_time_scale;

    } else if (sps->vui.vui_timing_info_present_flag) {

        num = sps->vui.vui_num_units_in_tick;

        den = sps->vui.vui_time_scale;

    }



    if (num != 0 && den != 0)

        av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den,

                  num, den, 1 << 30);



    return 0;



fail:

    pic_arrays_free(s);

    s->sps = NULL;

    return ret;

}

static int FUNC_0(HEVCContext *VAR_0, const HEVCSPS *VAR_1)

{

    int VAR_2;

    int VAR_3 = 0, VAR_4 = 0;



    pic_arrays_free(VAR_0);

    VAR_2 = pic_arrays_init(VAR_0, VAR_1);

    if (VAR_2 < 0)

        goto fail;



    VAR_0->avctx->coded_width         = VAR_1->width;

    VAR_0->avctx->coded_height        = VAR_1->height;

    VAR_0->avctx->width               = VAR_1->output_width;

    VAR_0->avctx->height              = VAR_1->output_height;

    VAR_0->avctx->pix_fmt             = VAR_1->pix_fmt;

    VAR_0->avctx->sample_aspect_ratio = VAR_1->vui.sar;

    VAR_0->avctx->has_b_frames        = VAR_1->temporal_layer[VAR_1->max_sub_layers - 1].num_reorder_pics;



    if (VAR_1->vui.video_signal_type_present_flag)

        VAR_0->avctx->color_range = VAR_1->vui.video_full_range_flag ? AVCOL_RANGE_JPEG

                                                               : AVCOL_RANGE_MPEG;

    else

        VAR_0->avctx->color_range = AVCOL_RANGE_MPEG;



    if (VAR_1->vui.colour_description_present_flag) {

        VAR_0->avctx->color_primaries = VAR_1->vui.colour_primaries;

        VAR_0->avctx->color_trc       = VAR_1->vui.transfer_characteristic;

        VAR_0->avctx->colorspace      = VAR_1->vui.matrix_coeffs;

    } else {

        VAR_0->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED;

        VAR_0->avctx->color_trc       = AVCOL_TRC_UNSPECIFIED;

        VAR_0->avctx->colorspace      = AVCOL_SPC_UNSPECIFIED;

    }



    ff_hevc_pred_init(&VAR_0->hpc,     VAR_1->bit_depth);

    ff_hevc_dsp_init (&VAR_0->hevcdsp, VAR_1->bit_depth);

    ff_videodsp_init (&VAR_0->vdsp,    VAR_1->bit_depth);



    if (VAR_1->sao_enabled) {

        av_frame_unref(VAR_0->tmp_frame);

        VAR_2 = ff_get_buffer(VAR_0->avctx, VAR_0->tmp_frame, AV_GET_BUFFER_FLAG_REF);

        if (VAR_2 < 0)

            goto fail;

        VAR_0->frame = VAR_0->tmp_frame;

    }



    VAR_0->VAR_1 = VAR_1;

    VAR_0->vps = (HEVCVPS*) VAR_0->vps_list[VAR_0->VAR_1->vps_id]->data;



    if (VAR_0->vps->vps_timing_info_present_flag) {

        VAR_3 = VAR_0->vps->vps_num_units_in_tick;

        VAR_4 = VAR_0->vps->vps_time_scale;

    } else if (VAR_1->vui.vui_timing_info_present_flag) {

        VAR_3 = VAR_1->vui.vui_num_units_in_tick;

        VAR_4 = VAR_1->vui.vui_time_scale;

    }



    if (VAR_3 != 0 && VAR_4 != 0)

        av_reduce(&VAR_0->avctx->time_base.VAR_3, &VAR_0->avctx->time_base.VAR_4,

                  VAR_3, VAR_4, 1 << 30);



    return 0;



fail:

    pic_arrays_free(VAR_0);

    VAR_0->VAR_1 = NULL;

    return VAR_2;

}

static int FUNC_0(HEVCContext *VAR_0, const HEVCSPS *VAR_1)
{ int VAR_2; int VAR_3 = 0, VAR_4 = 0; pic_arrays_free(VAR_0); VAR_2 = pic_arrays_init(VAR_0, VAR_1); if (VAR_2 < 0)
goto fail; VAR_0->avctx->coded_width         = VAR_1->width; VAR_0->avctx->coded_height        = VAR_1->height; VAR_0->avctx->width               = VAR_1->output_width; VAR_0->avctx->height              = VAR_1->output_height; VAR_0->avctx->pix_fmt             = VAR_1->pix_fmt; VAR_0->avctx->sample_aspect_ratio = VAR_1->vui.sar; VAR_0->avctx->has_b_frames        = VAR_1->temporal_layer[VAR_1->max_sub_layers - 1].num_reorder_pics; if (VAR_1->vui.video_signal_type_present_flag)
VAR_0->avctx->color_range = VAR_1->vui.video_full_range_flag ? AVCOL_RANGE_JPEG
: AVCOL_RANGE_MPEG; else
VAR_0->avctx->color_range = AVCOL_RANGE_MPEG; if (VAR_1->vui.colour_description_present_flag) { VAR_0->avctx->color_primaries = VAR_1->vui.colour_primaries; VAR_0->avctx->color_trc       = VAR_1->vui.transfer_characteristic; VAR_0->avctx->colorspace      = VAR_1->vui.matrix_coeffs; } else { VAR_0->avctx->color_primaries = AVCOL_PRI_UNSPECIFIED; VAR_0->avctx->color_trc       = AVCOL_TRC_UNSPECIFIED; VAR_0->avctx->colorspace      = AVCOL_SPC_UNSPECIFIED; } ff_hevc_pred_init(&VAR_0->hpc,     VAR_1->bit_depth); ff_hevc_dsp_init (&VAR_0->hevcdsp, VAR_1->bit_depth); ff_videodsp_init (&VAR_0->vdsp,    VAR_1->bit_depth); if (VAR_1->sao_enabled) { av_frame_unref(VAR_0->tmp_frame); VAR_2 = ff_get_buffer(VAR_0->avctx, VAR_0->tmp_frame, AV_GET_BUFFER_FLAG_REF); if (VAR_2 < 0)
goto fail; VAR_0->frame = VAR_0->tmp_frame; } VAR_0->VAR_1 = VAR_1; VAR_0->vps = (HEVCVPS*) VAR_0->vps_list[VAR_0->VAR_1->vps_id]->data; if (VAR_0->vps->vps_timing_info_present_flag) { VAR_3 = VAR_0->vps->vps_num_units_in_tick; VAR_4 = VAR_0->vps->vps_time_scale; } else if (VAR_1->vui.vui_timing_info_present_flag) { VAR_3 = VAR_1->vui.vui_num_units_in_tick; VAR_4 = VAR_1->vui.vui_time_scale; } if (VAR_3 != 0 && VAR_4 != 0)
av_reduce(&VAR_0->avctx->time_base.VAR_3, &VAR_0->avctx->time_base.VAR_4,
VAR_3, VAR_4, 1 << 30); return 0; fail:
pic_arrays_free(VAR_0); VAR_0->VAR_1 = NULL; return VAR_2; }