static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out)

{

    VP9SFSplitContext *s = ctx->priv_data;

    AVPacket *in;

    int i, j, ret, marker;

    int is_superframe = !!s->buffer_pkt;



    if (!s->buffer_pkt) {

        ret = ff_bsf_get_packet(ctx, &s->buffer_pkt);

        if (ret < 0)

            return ret;

        in = s->buffer_pkt;



        marker = in->data[in->size - 1];

        if ((marker & 0xe0) == 0xc0) {

            int length_size = 1 + ((marker >> 3) & 0x3);

            int   nb_frames = 1 + (marker & 0x7);

            int    idx_size = 2 + nb_frames * length_size;



            if (in->size >= idx_size && in->data[in->size - idx_size] == marker) {

                GetByteContext bc;

                int total_size = 0;



                bytestream2_init(&bc, in->data + in->size + 1 - idx_size,

                                 nb_frames * length_size);



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

                    int frame_size = 0;

                    for (j = 0; j < length_size; j++)

                        frame_size |= bytestream2_get_byte(&bc) << (j * 8);



                    total_size += frame_size;

                    if (total_size > in->size - idx_size) {

                        av_log(ctx, AV_LOG_ERROR,

                               "Invalid frame size in a superframe: %d\n", frame_size);

                        ret = AVERROR(EINVAL);

                        goto fail;

                    }

                    s->sizes[i] = frame_size;

                }

                s->nb_frames         = nb_frames;

                s->next_frame        = 0;

                s->next_frame_offset = 0;

                is_superframe        = 1;

            }

        }

    }



    if (is_superframe) {

        GetBitContext gb;

        int profile, invisible = 0;



        ret = av_packet_ref(out, s->buffer_pkt);

        if (ret < 0)

            goto fail;



        out->data += s->next_frame_offset;

        out->size  = s->sizes[s->next_frame];



        s->next_frame_offset += out->size;

        s->next_frame++;



        if (s->next_frame >= s->nb_frames)

            av_packet_free(&s->buffer_pkt);



        ret = init_get_bits8(&gb, out->data, out->size);

        if (ret < 0)

            goto fail;



        get_bits(&gb, 2); // frame_marker

        profile  = get_bits1(&gb);

        profile |= get_bits1(&gb) << 1;

        if (profile == 3)

            get_bits1(&gb);

        if (!get_bits1(&gb)) {

            get_bits1(&gb);

            invisible = !get_bits1(&gb);

        }



        if (invisible)

            out->pts = AV_NOPTS_VALUE;



    } else {

        av_packet_move_ref(out, s->buffer_pkt);

        av_packet_free(&s->buffer_pkt);

    }



    return 0;

fail:

    av_packet_free(&s->buffer_pkt);

    return ret;

}

static int vp9_superframe_split_filter(AVBSFContext *ctx, AVPacket *out)

{

    VP9SFSplitContext *s = ctx->priv_data;

    AVPacket *in;

    int i, j, ret, marker;

    int is_superframe = !!s->buffer_pkt;



    if (!s->buffer_pkt) {

        ret = ff_bsf_get_packet(ctx, &s->buffer_pkt);

        if (ret < 0)

            return ret;

        in = s->buffer_pkt;



        marker = in->data[in->size - 1];

        if ((marker & 0xe0) == 0xc0) {

            int length_size = 1 + ((marker >> 3) & 0x3);

            int   nb_frames = 1 + (marker & 0x7);

            int    idx_size = 2 + nb_frames * length_size;



            if (in->size >= idx_size && in->data[in->size - idx_size] == marker) {

                GetByteContext bc;

                int total_size = 0;



                bytestream2_init(&bc, in->data + in->size + 1 - idx_size,

                                 nb_frames * length_size);



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

                    int frame_size = 0;

                    for (j = 0; j < length_size; j++)

                        frame_size |= bytestream2_get_byte(&bc) << (j * 8);



                    total_size += frame_size;

                    if (total_size > in->size - idx_size) {

                        av_log(ctx, AV_LOG_ERROR,

                               "Invalid frame size in a superframe: %d\n", frame_size);

                        ret = AVERROR(EINVAL);

                        goto fail;

                    }

                    s->sizes[i] = frame_size;

                }

                s->nb_frames         = nb_frames;

                s->next_frame        = 0;

                s->next_frame_offset = 0;

                is_superframe        = 1;

            }

        }

    }



    if (is_superframe) {

        GetBitContext gb;

        int profile, invisible = 0;



        ret = av_packet_ref(out, s->buffer_pkt);

        if (ret < 0)

            goto fail;



        out->data += s->next_frame_offset;

        out->size  = s->sizes[s->next_frame];



        s->next_frame_offset += out->size;

        s->next_frame++;



        if (s->next_frame >= s->nb_frames)

            av_packet_free(&s->buffer_pkt);



        ret = init_get_bits8(&gb, out->data, out->size);

        if (ret < 0)

            goto fail;



        get_bits(&gb, 2); 

        profile  = get_bits1(&gb);

        profile |= get_bits1(&gb) << 1;

        if (profile == 3)

            get_bits1(&gb);

        if (!get_bits1(&gb)) {

            get_bits1(&gb);

            invisible = !get_bits1(&gb);

        }



        if (invisible)

            out->pts = AV_NOPTS_VALUE;



    } else {

        av_packet_move_ref(out, s->buffer_pkt);

        av_packet_free(&s->buffer_pkt);

    }



    return 0;

fail:

    av_packet_free(&s->buffer_pkt);

    return ret;

}

                int total_size = 0;                     if (total_size > in->size - idx_size) {
static int FUNC_0(AVBSFContext *VAR_0, AVPacket *VAR_1)

{

    VP9SFSplitContext *s = VAR_0->priv_data;

    AVPacket *in;

    int VAR_2, VAR_3, VAR_4, VAR_5;

    int VAR_6 = !!s->buffer_pkt;



    if (!s->buffer_pkt) {

        VAR_4 = ff_bsf_get_packet(VAR_0, &s->buffer_pkt);

        if (VAR_4 < 0)

            return VAR_4;

        in = s->buffer_pkt;



        VAR_5 = in->data[in->size - 1];

        if ((VAR_5 & 0xe0) == 0xc0) {

            int VAR_7 = 1 + ((VAR_5 >> 3) & 0x3);

            int   VAR_8 = 1 + (VAR_5 & 0x7);

            int    VAR_9 = 2 + VAR_8 * VAR_7;



            if (in->size >= VAR_9 && in->data[in->size - VAR_9] == VAR_5) {

                GetByteContext bc;

                int VAR_10 = 0;



                bytestream2_init(&bc, in->data + in->size + 1 - VAR_9,

                                 VAR_8 * VAR_7);



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

                    int VAR_11 = 0;

                    for (VAR_3 = 0; VAR_3 < VAR_7; VAR_3++)

                        VAR_11 |= bytestream2_get_byte(&bc) << (VAR_3 * 8);



                    VAR_10 += VAR_11;

                    if (VAR_10 > in->size - VAR_9) {

                        av_log(VAR_0, AV_LOG_ERROR,

                               "Invalid frame size in a superframe: %d\n", VAR_11);

                        VAR_4 = AVERROR(EINVAL);

                        goto fail;

                    }

                    s->sizes[VAR_2] = VAR_11;

                }

                s->VAR_8         = VAR_8;

                s->next_frame        = 0;

                s->next_frame_offset = 0;

                VAR_6        = 1;

            }

        }

    }



    if (VAR_6) {

        GetBitContext gb;

        int VAR_12, VAR_13 = 0;



        VAR_4 = av_packet_ref(VAR_1, s->buffer_pkt);

        if (VAR_4 < 0)

            goto fail;



        VAR_1->data += s->next_frame_offset;

        VAR_1->size  = s->sizes[s->next_frame];



        s->next_frame_offset += VAR_1->size;

        s->next_frame++;



        if (s->next_frame >= s->VAR_8)

            av_packet_free(&s->buffer_pkt);



        VAR_4 = init_get_bits8(&gb, VAR_1->data, VAR_1->size);

        if (VAR_4 < 0)

            goto fail;



        get_bits(&gb, 2); 

        VAR_12  = get_bits1(&gb);

        VAR_12 |= get_bits1(&gb) << 1;

        if (VAR_12 == 3)

            get_bits1(&gb);

        if (!get_bits1(&gb)) {

            get_bits1(&gb);

            VAR_13 = !get_bits1(&gb);

        }



        if (VAR_13)

            VAR_1->pts = AV_NOPTS_VALUE;



    } else {

        av_packet_move_ref(VAR_1, s->buffer_pkt);

        av_packet_free(&s->buffer_pkt);

    }



    return 0;

fail:

    av_packet_free(&s->buffer_pkt);

    return VAR_4;

}

static int FUNC_0(AVBSFContext *VAR_0, AVPacket *VAR_1)
{ VP9SFSplitContext *s = VAR_0->priv_data; AVPacket *in; int VAR_2, VAR_3, VAR_4, VAR_5; int VAR_6 = !!s->buffer_pkt; if (!s->buffer_pkt) { VAR_4 = ff_bsf_get_packet(VAR_0, &s->buffer_pkt); if (VAR_4 < 0)
return VAR_4; in = s->buffer_pkt; VAR_5 = in->data[in->size - 1]; if ((VAR_5 & 0xe0) == 0xc0) { int VAR_7 = 1 + ((VAR_5 >> 3) & 0x3); int   VAR_8 = 1 + (VAR_5 & 0x7); int    VAR_9 = 2 + VAR_8 * VAR_7; if (in->size >= VAR_9 && in->data[in->size - VAR_9] == VAR_5) { GetByteContext bc; int VAR_10 = 0; bytestream2_init(&bc, in->data + in->size + 1 - VAR_9,
VAR_8 * VAR_7); for (VAR_2 = 0; VAR_2 < VAR_8; VAR_2++) { int VAR_11 = 0; for (VAR_3 = 0; VAR_3 < VAR_7; VAR_3++) VAR_11 |= bytestream2_get_byte(&bc) << (VAR_3 * 8); VAR_10 += VAR_11; if (VAR_10 > in->size - VAR_9) { av_log(VAR_0, AV_LOG_ERROR,
"Invalid frame size in a superframe: %d\n", VAR_11); VAR_4 = AVERROR(EINVAL); goto fail; } s->sizes[VAR_2] = VAR_11; } s->VAR_8         = VAR_8; s->next_frame        = 0; s->next_frame_offset = 0; VAR_6        = 1; } } } if (VAR_6) { GetBitContext gb; int VAR_12, VAR_13 = 0; VAR_4 = av_packet_ref(VAR_1, s->buffer_pkt); if (VAR_4 < 0)
goto fail; VAR_1->data += s->next_frame_offset; VAR_1->size  = s->sizes[s->next_frame]; s->next_frame_offset += VAR_1->size; s->next_frame++; if (s->next_frame >= s->VAR_8)
av_packet_free(&s->buffer_pkt); VAR_4 = init_get_bits8(&gb, VAR_1->data, VAR_1->size); if (VAR_4 < 0)
goto fail; get_bits(&gb, 2); VAR_12  = get_bits1(&gb); VAR_12 |= get_bits1(&gb) << 1; if (VAR_12 == 3)
get_bits1(&gb); if (!get_bits1(&gb)) { get_bits1(&gb); VAR_13 = !get_bits1(&gb); } if (VAR_13)
VAR_1->pts = AV_NOPTS_VALUE; } else { av_packet_move_ref(VAR_1, s->buffer_pkt); av_packet_free(&s->buffer_pkt); } return 0; fail:
av_packet_free(&s->buffer_pkt); return VAR_4; }