int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps,

                             int *is_nalff, int *nal_length_size,

                             int err_recognition, void *logctx)

{

    int ret = 0;

    GetByteContext gb;



    bytestream2_init(&gb, data, size);



    if (size > 3 && (data[0] || data[1] || data[2] > 1)) {

        /* It seems the extradata is encoded as hvcC format.

         * Temporarily, we support configurationVersion==0 until 14496-15 3rd

         * is finalized. When finalized, configurationVersion will be 1 and we

         * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */

        int i, j, num_arrays, nal_len_size;



        *is_nalff = 1;



        bytestream2_skip(&gb, 21);

        nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;

        num_arrays   = bytestream2_get_byte(&gb);



        /* nal units in the hvcC always have length coded with 2 bytes,

         * so put a fake nal_length_size = 2 while parsing them */

        *nal_length_size = 2;



        /* Decode nal units from hvcC. */

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

            int type = bytestream2_get_byte(&gb) & 0x3f;

            int cnt  = bytestream2_get_be16(&gb);



            for (j = 0; j < cnt; j++) {

                // +2 for the nal size field

                int nalsize = bytestream2_peek_be16(&gb) + 2;

                if (bytestream2_get_bytes_left(&gb) < nalsize) {

                    av_log(logctx, AV_LOG_ERROR,

                           "Invalid NAL unit size in extradata.\n");

                    return AVERROR_INVALIDDATA;

                }



                ret = hevc_decode_nal_units(gb.buffer, nalsize, ps, *is_nalff, *nal_length_size, logctx);

                if (ret < 0) {

                    av_log(logctx, AV_LOG_ERROR,

                           "Decoding nal unit %d %d from hvcC failed\n",

                           type, i);

                    return ret;

                }

                bytestream2_skip(&gb, nalsize);

            }

        }



        /* Now store right nal length size, that will be used to parse

         * all other nals */

        *nal_length_size = nal_len_size;

    } else {

        *is_nalff = 0;

        ret = hevc_decode_nal_units(data, size, ps, *is_nalff, *nal_length_size, logctx);

        if (ret < 0)

            return ret;

    }



    return ret;

}

int ff_hevc_decode_extradata(const uint8_t *data, int size, HEVCParamSets *ps,

                             int *is_nalff, int *nal_length_size,

                             int err_recognition, void *logctx)

{

    int ret = 0;

    GetByteContext gb;



    bytestream2_init(&gb, data, size);



    if (size > 3 && (data[0] || data[1] || data[2] > 1)) {

        







        int i, j, num_arrays, nal_len_size;



        *is_nalff = 1;



        bytestream2_skip(&gb, 21);

        nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;

        num_arrays   = bytestream2_get_byte(&gb);



        



        *nal_length_size = 2;



        

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

            int type = bytestream2_get_byte(&gb) & 0x3f;

            int cnt  = bytestream2_get_be16(&gb);



            for (j = 0; j < cnt; j++) {

                

                int nalsize = bytestream2_peek_be16(&gb) + 2;

                if (bytestream2_get_bytes_left(&gb) < nalsize) {

                    av_log(logctx, AV_LOG_ERROR,

                           "Invalid NAL unit size in extradata.\n");

                    return AVERROR_INVALIDDATA;

                }



                ret = hevc_decode_nal_units(gb.buffer, nalsize, ps, *is_nalff, *nal_length_size, logctx);

                if (ret < 0) {

                    av_log(logctx, AV_LOG_ERROR,

                           "Decoding nal unit %d %d from hvcC failed\n",

                           type, i);

                    return ret;

                }

                bytestream2_skip(&gb, nalsize);

            }

        }



        



        *nal_length_size = nal_len_size;

    } else {

        *is_nalff = 0;

        ret = hevc_decode_nal_units(data, size, ps, *is_nalff, *nal_length_size, logctx);

        if (ret < 0)

            return ret;

    }



    return ret;

}

    return ret;                 ret = hevc_decode_nal_units(gb.buffer, nalsize, ps, *is_nalff, *nal_length_size, logctx);         ret = hevc_decode_nal_units(data, size, ps, *is_nalff, *nal_length_size, logctx);
int FUNC_0(const uint8_t *VAR_0, int VAR_1, HEVCParamSets *VAR_2,

                             int *VAR_3, int *VAR_4,

                             int VAR_5, void *VAR_6)

{

    int VAR_7 = 0;

    GetByteContext gb;



    bytestream2_init(&gb, VAR_0, VAR_1);



    if (VAR_1 > 3 && (VAR_0[0] || VAR_0[1] || VAR_0[2] > 1)) {

        







        int VAR_8, VAR_9, VAR_10, VAR_11;



        *VAR_3 = 1;



        bytestream2_skip(&gb, 21);

        VAR_11 = (bytestream2_get_byte(&gb) & 3) + 1;

        VAR_10   = bytestream2_get_byte(&gb);



        



        *VAR_4 = 2;



        

        for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8++) {

            int VAR_12 = bytestream2_get_byte(&gb) & 0x3f;

            int VAR_13  = bytestream2_get_be16(&gb);



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

                

                int VAR_14 = bytestream2_peek_be16(&gb) + 2;

                if (bytestream2_get_bytes_left(&gb) < VAR_14) {

                    av_log(VAR_6, AV_LOG_ERROR,

                           "Invalid NAL unit VAR_1 in extradata.\n");

                    return AVERROR_INVALIDDATA;

                }



                VAR_7 = hevc_decode_nal_units(gb.buffer, VAR_14, VAR_2, *VAR_3, *VAR_4, VAR_6);

                if (VAR_7 < 0) {

                    av_log(VAR_6, AV_LOG_ERROR,

                           "Decoding nal unit %d %d from hvcC failed\n",

                           VAR_12, VAR_8);

                    return VAR_7;

                }

                bytestream2_skip(&gb, VAR_14);

            }

        }



        



        *VAR_4 = VAR_11;

    } else {

        *VAR_3 = 0;

        VAR_7 = hevc_decode_nal_units(VAR_0, VAR_1, VAR_2, *VAR_3, *VAR_4, VAR_6);

        if (VAR_7 < 0)

            return VAR_7;

    }



    return VAR_7;

}

int FUNC_0(const uint8_t *VAR_0, int VAR_1, HEVCParamSets *VAR_2,
int *VAR_3, int *VAR_4,
int VAR_5, void *VAR_6)
{ int VAR_7 = 0; GetByteContext gb; bytestream2_init(&gb, VAR_0, VAR_1); if (VAR_1 > 3 && (VAR_0[0] || VAR_0[1] || VAR_0[2] > 1)) { int VAR_8, VAR_9, VAR_10, VAR_11; *VAR_3 = 1; bytestream2_skip(&gb, 21); VAR_11 = (bytestream2_get_byte(&gb) & 3) + 1; VAR_10   = bytestream2_get_byte(&gb); *VAR_4 = 2; for (VAR_8 = 0; VAR_8 < VAR_10; VAR_8++) { int VAR_12 = bytestream2_get_byte(&gb) & 0x3f; int VAR_13  = bytestream2_get_be16(&gb); for (VAR_9 = 0; VAR_9 < VAR_13; VAR_9++) { int VAR_14 = bytestream2_peek_be16(&gb) + 2; if (bytestream2_get_bytes_left(&gb) < VAR_14) { av_log(VAR_6, AV_LOG_ERROR,
"Invalid NAL unit VAR_1 in extradata.\n"); return AVERROR_INVALIDDATA; } VAR_7 = hevc_decode_nal_units(gb.buffer, VAR_14, VAR_2, *VAR_3, *VAR_4, VAR_6); if (VAR_7 < 0) { av_log(VAR_6, AV_LOG_ERROR,
"Decoding nal unit %d %d from hvcC failed\n",
VAR_12, VAR_8); return VAR_7; } bytestream2_skip(&gb, VAR_14); } } *VAR_4 = VAR_11; } else { *VAR_3 = 0; VAR_7 = hevc_decode_nal_units(VAR_0, VAR_1, VAR_2, *VAR_3, *VAR_4, VAR_6); if (VAR_7 < 0)
return VAR_7; } return VAR_7; }