int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,

                                  ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)

{

    uint8_t rps_predict = 0;

    int delta_poc;

    int k0 = 0;

    int k1 = 0;

    int k  = 0;

    int i;



    if (rps != sps->st_rps && sps->nb_st_rps)

        rps_predict = get_bits1(gb);



    if (rps_predict) {

        const ShortTermRPS *rps_ridx;

        int delta_rps;

        unsigned abs_delta_rps;

        uint8_t use_delta_flag = 0;

        uint8_t delta_rps_sign;



        if (is_slice_header) {

            unsigned int delta_idx = get_ue_golomb_long(gb) + 1;

            if (delta_idx > sps->nb_st_rps) {


                       "Invalid value of delta_idx in slice header RPS: %d > %d.\n",

                       delta_idx, sps->nb_st_rps);



            rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx];

            rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs;

        } else

            rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];



        delta_rps_sign = get_bits1(gb);

        abs_delta_rps  = get_ue_golomb_long(gb) + 1;

        if (abs_delta_rps < 1 || abs_delta_rps > 32768) {


                   "Invalid value of abs_delta_rps: %d\n",

                   abs_delta_rps);



        delta_rps      = (1 - (delta_rps_sign << 1)) * abs_delta_rps;

        for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {

            int used = rps->used[k] = get_bits1(gb);



            if (!used)

                use_delta_flag = get_bits1(gb);



            if (used || use_delta_flag) {

                if (i < rps_ridx->num_delta_pocs)

                    delta_poc = delta_rps + rps_ridx->delta_poc[i];

                else

                    delta_poc = delta_rps;

                rps->delta_poc[k] = delta_poc;

                if (delta_poc < 0)

                    k0++;

                else

                    k1++;

                k++;





        if (k >= FF_ARRAY_ELEMS(rps->used)) {


                   "Invalid num_delta_pocs: %d\n", k);





        rps->num_delta_pocs    = k;

        rps->num_negative_pics = k0;

        // sort in increasing order (smallest first)

        if (rps->num_delta_pocs != 0) {

            int used, tmp;

            for (i = 1; i < rps->num_delta_pocs; i++) {

                delta_poc = rps->delta_poc[i];

                used      = rps->used[i];

                for (k = i - 1; k >= 0; k--) {

                    tmp = rps->delta_poc[k];

                    if (delta_poc < tmp) {

                        rps->delta_poc[k + 1] = tmp;

                        rps->used[k + 1]      = rps->used[k];

                        rps->delta_poc[k]     = delta_poc;

                        rps->used[k]          = used;





        if ((rps->num_negative_pics >> 1) != 0) {

            int used;

            k = rps->num_negative_pics - 1;

            // flip the negative values to largest first

            for (i = 0; i < rps->num_negative_pics >> 1; i++) {

                delta_poc         = rps->delta_poc[i];

                used              = rps->used[i];

                rps->delta_poc[i] = rps->delta_poc[k];

                rps->used[i]      = rps->used[k];

                rps->delta_poc[k] = delta_poc;

                rps->used[k]      = used;

                k--;



    } else {

        unsigned int prev, nb_positive_pics;

        rps->num_negative_pics = get_ue_golomb_long(gb);

        nb_positive_pics       = get_ue_golomb_long(gb);



        if (rps->num_negative_pics >= HEVC_MAX_REFS ||

            nb_positive_pics >= HEVC_MAX_REFS) {

            av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");





        rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;

        if (rps->num_delta_pocs) {

            prev = 0;

            for (i = 0; i < rps->num_negative_pics; i++) {

                delta_poc = get_ue_golomb_long(gb) + 1;







                prev -= delta_poc;

                rps->delta_poc[i] = prev;

                rps->used[i]      = get_bits1(gb);


            prev = 0;

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

                delta_poc = get_ue_golomb_long(gb) + 1;







                prev += delta_poc;

                rps->delta_poc[rps->num_negative_pics + i] = prev;

                rps->used[rps->num_negative_pics + i]      = get_bits1(gb);




    return 0;

int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx,

                                  ShortTermRPS *rps, const HEVCSPS *sps, int is_slice_header)

{

    uint8_t rps_predict = 0;

    int delta_poc;

    int k0 = 0;

    int k1 = 0;

    int k  = 0;

    int i;



    if (rps != sps->st_rps && sps->nb_st_rps)

        rps_predict = get_bits1(gb);



    if (rps_predict) {

        const ShortTermRPS *rps_ridx;

        int delta_rps;

        unsigned abs_delta_rps;

        uint8_t use_delta_flag = 0;

        uint8_t delta_rps_sign;



        if (is_slice_header) {

            unsigned int delta_idx = get_ue_golomb_long(gb) + 1;

            if (delta_idx > sps->nb_st_rps) {


                       "Invalid value of delta_idx in slice header RPS: %d > %d.\n",

                       delta_idx, sps->nb_st_rps);



            rps_ridx = &sps->st_rps[sps->nb_st_rps - delta_idx];

            rps->rps_idx_num_delta_pocs = rps_ridx->num_delta_pocs;

        } else

            rps_ridx = &sps->st_rps[rps - sps->st_rps - 1];



        delta_rps_sign = get_bits1(gb);

        abs_delta_rps  = get_ue_golomb_long(gb) + 1;

        if (abs_delta_rps < 1 || abs_delta_rps > 32768) {


                   "Invalid value of abs_delta_rps: %d\n",

                   abs_delta_rps);



        delta_rps      = (1 - (delta_rps_sign << 1)) * abs_delta_rps;

        for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {

            int used = rps->used[k] = get_bits1(gb);



            if (!used)

                use_delta_flag = get_bits1(gb);



            if (used || use_delta_flag) {

                if (i < rps_ridx->num_delta_pocs)

                    delta_poc = delta_rps + rps_ridx->delta_poc[i];

                else

                    delta_poc = delta_rps;

                rps->delta_poc[k] = delta_poc;

                if (delta_poc < 0)

                    k0++;

                else

                    k1++;

                k++;





        if (k >= FF_ARRAY_ELEMS(rps->used)) {


                   "Invalid num_delta_pocs: %d\n", k);





        rps->num_delta_pocs    = k;

        rps->num_negative_pics = k0;

        

        if (rps->num_delta_pocs != 0) {

            int used, tmp;

            for (i = 1; i < rps->num_delta_pocs; i++) {

                delta_poc = rps->delta_poc[i];

                used      = rps->used[i];

                for (k = i - 1; k >= 0; k--) {

                    tmp = rps->delta_poc[k];

                    if (delta_poc < tmp) {

                        rps->delta_poc[k + 1] = tmp;

                        rps->used[k + 1]      = rps->used[k];

                        rps->delta_poc[k]     = delta_poc;

                        rps->used[k]          = used;





        if ((rps->num_negative_pics >> 1) != 0) {

            int used;

            k = rps->num_negative_pics - 1;

            

            for (i = 0; i < rps->num_negative_pics >> 1; i++) {

                delta_poc         = rps->delta_poc[i];

                used              = rps->used[i];

                rps->delta_poc[i] = rps->delta_poc[k];

                rps->used[i]      = rps->used[k];

                rps->delta_poc[k] = delta_poc;

                rps->used[k]      = used;

                k--;



    } else {

        unsigned int prev, nb_positive_pics;

        rps->num_negative_pics = get_ue_golomb_long(gb);

        nb_positive_pics       = get_ue_golomb_long(gb);



        if (rps->num_negative_pics >= HEVC_MAX_REFS ||

            nb_positive_pics >= HEVC_MAX_REFS) {

            av_log(avctx, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");





        rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;

        if (rps->num_delta_pocs) {

            prev = 0;

            for (i = 0; i < rps->num_negative_pics; i++) {

                delta_poc = get_ue_golomb_long(gb) + 1;







                prev -= delta_poc;

                rps->delta_poc[i] = prev;

                rps->used[i]      = get_bits1(gb);


            prev = 0;

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

                delta_poc = get_ue_golomb_long(gb) + 1;







                prev += delta_poc;

                rps->delta_poc[rps->num_negative_pics + i] = prev;

                rps->used[rps->num_negative_pics + i]      = get_bits1(gb);




    return 0;

int FUNC_0(GetBitContext *VAR_0, AVCodecContext *VAR_1,

                                  ShortTermRPS *VAR_2, const HEVCSPS *VAR_3, int VAR_4)

{

    uint8_t rps_predict = 0;

    int VAR_5;

    int VAR_6 = 0;

    int VAR_7 = 0;

    int VAR_8  = 0;

    int VAR_9;



    if (VAR_2 != VAR_3->st_rps && VAR_3->nb_st_rps)

        rps_predict = get_bits1(VAR_0);



    if (rps_predict) {

        const ShortTermRPS *VAR_10;

        int VAR_11;

        unsigned VAR_12;

        uint8_t use_delta_flag = 0;

        uint8_t delta_rps_sign;



        if (VAR_4) {

            unsigned int VAR_13 = get_ue_golomb_long(VAR_0) + 1;

            if (VAR_13 > VAR_3->nb_st_rps) {


                       "Invalid value of VAR_13 in slice header RPS: %d > %d.\n",

                       VAR_13, VAR_3->nb_st_rps);



            VAR_10 = &VAR_3->st_rps[VAR_3->nb_st_rps - VAR_13];

            VAR_2->rps_idx_num_delta_pocs = VAR_10->num_delta_pocs;

        } else

            VAR_10 = &VAR_3->st_rps[VAR_2 - VAR_3->st_rps - 1];



        delta_rps_sign = get_bits1(VAR_0);

        VAR_12  = get_ue_golomb_long(VAR_0) + 1;

        if (VAR_12 < 1 || VAR_12 > 32768) {


                   "Invalid value of VAR_12: %d\n",

                   VAR_12);



        VAR_11      = (1 - (delta_rps_sign << 1)) * VAR_12;

        for (VAR_9 = 0; VAR_9 <= VAR_10->num_delta_pocs; VAR_9++) {

            int used = VAR_2->used[VAR_8] = get_bits1(VAR_0);



            if (!used)

                use_delta_flag = get_bits1(VAR_0);



            if (used || use_delta_flag) {

                if (VAR_9 < VAR_10->num_delta_pocs)

                    VAR_5 = VAR_11 + VAR_10->VAR_5[VAR_9];

                else

                    VAR_5 = VAR_11;

                VAR_2->VAR_5[VAR_8] = VAR_5;

                if (VAR_5 < 0)

                    VAR_6++;

                else

                    VAR_7++;

                VAR_8++;





        if (VAR_8 >= FF_ARRAY_ELEMS(VAR_2->used)) {


                   "Invalid num_delta_pocs: %d\n", VAR_8);





        VAR_2->num_delta_pocs    = VAR_8;

        VAR_2->num_negative_pics = VAR_6;

        

        if (VAR_2->num_delta_pocs != 0) {

            int used, tmp;

            for (VAR_9 = 1; VAR_9 < VAR_2->num_delta_pocs; VAR_9++) {

                VAR_5 = VAR_2->VAR_5[VAR_9];

                used      = VAR_2->used[VAR_9];

                for (VAR_8 = VAR_9 - 1; VAR_8 >= 0; VAR_8--) {

                    tmp = VAR_2->VAR_5[VAR_8];

                    if (VAR_5 < tmp) {

                        VAR_2->VAR_5[VAR_8 + 1] = tmp;

                        VAR_2->used[VAR_8 + 1]      = VAR_2->used[VAR_8];

                        VAR_2->VAR_5[VAR_8]     = VAR_5;

                        VAR_2->used[VAR_8]          = used;





        if ((VAR_2->num_negative_pics >> 1) != 0) {

            int used;

            VAR_8 = VAR_2->num_negative_pics - 1;

            

            for (VAR_9 = 0; VAR_9 < VAR_2->num_negative_pics >> 1; VAR_9++) {

                VAR_5         = VAR_2->VAR_5[VAR_9];

                used              = VAR_2->used[VAR_9];

                VAR_2->VAR_5[VAR_9] = VAR_2->VAR_5[VAR_8];

                VAR_2->used[VAR_9]      = VAR_2->used[VAR_8];

                VAR_2->VAR_5[VAR_8] = VAR_5;

                VAR_2->used[VAR_8]      = used;

                VAR_8--;



    } else {

        unsigned int prev, nb_positive_pics;

        VAR_2->num_negative_pics = get_ue_golomb_long(VAR_0);

        nb_positive_pics       = get_ue_golomb_long(VAR_0);



        if (VAR_2->num_negative_pics >= HEVC_MAX_REFS ||

            nb_positive_pics >= HEVC_MAX_REFS) {

            av_log(VAR_1, AV_LOG_ERROR, "Too many refs in a short term RPS.\n");





        VAR_2->num_delta_pocs = VAR_2->num_negative_pics + nb_positive_pics;

        if (VAR_2->num_delta_pocs) {

            prev = 0;

            for (VAR_9 = 0; VAR_9 < VAR_2->num_negative_pics; VAR_9++) {

                VAR_5 = get_ue_golomb_long(VAR_0) + 1;







                prev -= VAR_5;

                VAR_2->VAR_5[VAR_9] = prev;

                VAR_2->used[VAR_9]      = get_bits1(VAR_0);


            prev = 0;

            for (VAR_9 = 0; VAR_9 < nb_positive_pics; VAR_9++) {

                VAR_5 = get_ue_golomb_long(VAR_0) + 1;







                prev += VAR_5;

                VAR_2->VAR_5[VAR_2->num_negative_pics + VAR_9] = prev;

                VAR_2->used[VAR_2->num_negative_pics + VAR_9]      = get_bits1(VAR_0);




    return 0;

int FUNC_0(GetBitContext *VAR_0, AVCodecContext *VAR_1,
ShortTermRPS *VAR_2, const HEVCSPS *VAR_3, int VAR_4)
{ uint8_t rps_predict = 0; int VAR_5; int VAR_6 = 0; int VAR_7 = 0; int VAR_8  = 0; int VAR_9; if (VAR_2 != VAR_3->st_rps && VAR_3->nb_st_rps)
rps_predict = get_bits1(VAR_0); if (rps_predict) { const ShortTermRPS *VAR_10; int VAR_11; unsigned VAR_12; uint8_t use_delta_flag = 0; uint8_t delta_rps_sign; if (VAR_4) { unsigned int VAR_13 = get_ue_golomb_long(VAR_0) + 1; if (VAR_13 > VAR_3->nb_st_rps) { "Invalid value of VAR_13 in slice header RPS: %d > %d.\n",
VAR_13, VAR_3->nb_st_rps); VAR_10 = &VAR_3->st_rps[VAR_3->nb_st_rps - VAR_13]; VAR_2->rps_idx_num_delta_pocs = VAR_10->num_delta_pocs; } else VAR_10 = &VAR_3->st_rps[VAR_2 - VAR_3->st_rps - 1]; delta_rps_sign = get_bits1(VAR_0); VAR_12  = get_ue_golomb_long(VAR_0) + 1; if (VAR_12 < 1 || VAR_12 > 32768) { "Invalid value of VAR_12: %d\n",
VAR_12); VAR_11      = (1 - (delta_rps_sign << 1)) * VAR_12; for (VAR_9 = 0; VAR_9 <= VAR_10->num_delta_pocs; VAR_9++) { int used = VAR_2->used[VAR_8] = get_bits1(VAR_0); if (!used)
use_delta_flag = get_bits1(VAR_0); if (used || use_delta_flag) { if (VAR_9 < VAR_10->num_delta_pocs)
VAR_5 = VAR_11 + VAR_10->VAR_5[VAR_9]; else
VAR_5 = VAR_11; VAR_2->VAR_5[VAR_8] = VAR_5; if (VAR_5 < 0)
VAR_6++; else
VAR_7++; VAR_8++; if (VAR_8 >= FF_ARRAY_ELEMS(VAR_2->used)) { "Invalid num_delta_pocs: %d\n", VAR_8); VAR_2->num_delta_pocs    = VAR_8; VAR_2->num_negative_pics = VAR_6; if (VAR_2->num_delta_pocs != 0) { int used, tmp; for (VAR_9 = 1; VAR_9 < VAR_2->num_delta_pocs; VAR_9++) { VAR_5 = VAR_2->VAR_5[VAR_9]; used      = VAR_2->used[VAR_9]; for (VAR_8 = VAR_9 - 1; VAR_8 >= 0; VAR_8--) { tmp = VAR_2->VAR_5[VAR_8]; if (VAR_5 < tmp) { VAR_2->VAR_5[VAR_8 + 1] = tmp; VAR_2->used[VAR_8 + 1]      = VAR_2->used[VAR_8]; VAR_2->VAR_5[VAR_8]     = VAR_5; VAR_2->used[VAR_8]          = used; if ((VAR_2->num_negative_pics >> 1) != 0) { int used; VAR_8 = VAR_2->num_negative_pics - 1; for (VAR_9 = 0; VAR_9 < VAR_2->num_negative_pics >> 1; VAR_9++) { VAR_5         = VAR_2->VAR_5[VAR_9]; used              = VAR_2->used[VAR_9]; VAR_2->VAR_5[VAR_9] = VAR_2->VAR_5[VAR_8]; VAR_2->used[VAR_9]      = VAR_2->used[VAR_8]; VAR_2->VAR_5[VAR_8] = VAR_5; VAR_2->used[VAR_8]      = used; VAR_8--; } else { unsigned int prev, nb_positive_pics; VAR_2->num_negative_pics = get_ue_golomb_long(VAR_0); nb_positive_pics       = get_ue_golomb_long(VAR_0); if (VAR_2->num_negative_pics >= HEVC_MAX_REFS ||
nb_positive_pics >= HEVC_MAX_REFS) { av_log(VAR_1, AV_LOG_ERROR, "Too many refs in a short term RPS.\n"); VAR_2->num_delta_pocs = VAR_2->num_negative_pics + nb_positive_pics; if (VAR_2->num_delta_pocs) { prev = 0; for (VAR_9 = 0; VAR_9 < VAR_2->num_negative_pics; VAR_9++) { VAR_5 = get_ue_golomb_long(VAR_0) + 1; prev -= VAR_5; VAR_2->VAR_5[VAR_9] = prev; VAR_2->used[VAR_9]      = get_bits1(VAR_0); prev = 0; for (VAR_9 = 0; VAR_9 < nb_positive_pics; VAR_9++) { VAR_5 = get_ue_golomb_long(VAR_0) + 1; prev += VAR_5; VAR_2->VAR_5[VAR_2->num_negative_pics + VAR_9] = prev; VAR_2->used[VAR_2->num_negative_pics + VAR_9]      = get_bits1(VAR_0); return 0;