static int decode_slice(AVCodecContext *c, void *arg)

{

    FFV1Context *fs   = *(void **)arg;

    FFV1Context *f    = fs->avctx->priv_data;

    int width, height, x, y, ret;

    const int ps      = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;

    AVFrame * const p = f->cur;

    int i, si;



    for( si=0; fs != f->slice_context[si]; si ++)

        ;



    if(f->fsrc && !p->key_frame)

        ff_thread_await_progress(&f->last_picture, si, 0);



    if(f->fsrc && !p->key_frame) {

        FFV1Context *fssrc = f->fsrc->slice_context[si];

        FFV1Context *fsdst = f->slice_context[si];

        av_assert1(fsdst->plane_count == fssrc->plane_count);

        av_assert1(fsdst == fs);



        if (!p->key_frame)

            fsdst->slice_damaged |= fssrc->slice_damaged;



        for (i = 0; i < f->plane_count; i++) {

            PlaneContext *psrc = &fssrc->plane[i];

            PlaneContext *pdst = &fsdst->plane[i];



            av_free(pdst->state);

            av_free(pdst->vlc_state);

            memcpy(pdst, psrc, sizeof(*pdst));

            pdst->state = NULL;

            pdst->vlc_state = NULL;



            if (fssrc->ac) {

                pdst->state = av_malloc_array(CONTEXT_SIZE,  psrc->context_count);

                memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);

            } else {

                pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);

                memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);

            }

        }

    }



    fs->slice_rct_by_coef = 1;

    fs->slice_rct_ry_coef = 1;



    if (f->version > 2) {

        if (ff_ffv1_init_slice_state(f, fs) < 0)

            return AVERROR(ENOMEM);

        if (decode_slice_header(f, fs) < 0) {


            fs->slice_damaged = 1;

            return AVERROR_INVALIDDATA;

        }

    }

    if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)

        return ret;

    if (f->cur->key_frame || fs->slice_reset_contexts)

        ff_ffv1_clear_slice_state(f, fs);



    width  = fs->slice_width;

    height = fs->slice_height;

    x      = fs->slice_x;

    y      = fs->slice_y;



    if (!fs->ac) {

        if (f->version == 3 && f->micro_version > 1 || f->version > 3)

            get_rac(&fs->c, (uint8_t[]) { 129 });

        fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;

        init_get_bits(&fs->gb,

                      fs->c.bytestream_start + fs->ac_byte_count,

                      (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);

    }



    av_assert1(width && height);

    if (f->colorspace == 0) {

        const int chroma_width  = FF_CEIL_RSHIFT(width,  f->chroma_h_shift);

        const int chroma_height = FF_CEIL_RSHIFT(height, f->chroma_v_shift);

        const int cx            = x >> f->chroma_h_shift;

        const int cy            = y >> f->chroma_v_shift;

        decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0);



        if (f->chroma_planes) {

            decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);

            decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);

        }

        if (fs->transparency)

            decode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2);

    } else {

        uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],

                               p->data[1] + ps * x + y * p->linesize[1],

                               p->data[2] + ps * x + y * p->linesize[2] };

        decode_rgb_frame(fs, planes, width, height, p->linesize);

    }

    if (fs->ac && f->version > 2) {

        int v;

        get_rac(&fs->c, (uint8_t[]) { 129 });

        v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;

        if (v) {

            av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);

            fs->slice_damaged = 1;

        }

    }



    emms_c();



    ff_thread_report_progress(&f->picture, si, 0);



    return 0;

}
static int decode_slice(AVCodecContext *c, void *arg)

{

    FFV1Context *fs   = *(void **)arg;

    FFV1Context *f    = fs->avctx->priv_data;

    int width, height, x, y, ret;

    const int ps      = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;

    AVFrame * const p = f->cur;

    int i, si;



    for( si=0; fs != f->slice_context[si]; si ++)

        ;



    if(f->fsrc && !p->key_frame)

        ff_thread_await_progress(&f->last_picture, si, 0);



    if(f->fsrc && !p->key_frame) {

        FFV1Context *fssrc = f->fsrc->slice_context[si];

        FFV1Context *fsdst = f->slice_context[si];

        av_assert1(fsdst->plane_count == fssrc->plane_count);

        av_assert1(fsdst == fs);



        if (!p->key_frame)

            fsdst->slice_damaged |= fssrc->slice_damaged;



        for (i = 0; i < f->plane_count; i++) {

            PlaneContext *psrc = &fssrc->plane[i];

            PlaneContext *pdst = &fsdst->plane[i];



            av_free(pdst->state);

            av_free(pdst->vlc_state);

            memcpy(pdst, psrc, sizeof(*pdst));

            pdst->state = NULL;

            pdst->vlc_state = NULL;



            if (fssrc->ac) {

                pdst->state = av_malloc_array(CONTEXT_SIZE,  psrc->context_count);

                memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);

            } else {

                pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);

                memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);

            }

        }

    }



    fs->slice_rct_by_coef = 1;

    fs->slice_rct_ry_coef = 1;



    if (f->version > 2) {

        if (ff_ffv1_init_slice_state(f, fs) < 0)

            return AVERROR(ENOMEM);

        if (decode_slice_header(f, fs) < 0) {


            fs->slice_damaged = 1;

            return AVERROR_INVALIDDATA;

        }

    }

    if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)

        return ret;

    if (f->cur->key_frame || fs->slice_reset_contexts)

        ff_ffv1_clear_slice_state(f, fs);



    width  = fs->slice_width;

    height = fs->slice_height;

    x      = fs->slice_x;

    y      = fs->slice_y;



    if (!fs->ac) {

        if (f->version == 3 && f->micro_version > 1 || f->version > 3)

            get_rac(&fs->c, (uint8_t[]) { 129 });

        fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0;

        init_get_bits(&fs->gb,

                      fs->c.bytestream_start + fs->ac_byte_count,

                      (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8);

    }



    av_assert1(width && height);

    if (f->colorspace == 0) {

        const int chroma_width  = FF_CEIL_RSHIFT(width,  f->chroma_h_shift);

        const int chroma_height = FF_CEIL_RSHIFT(height, f->chroma_v_shift);

        const int cx            = x >> f->chroma_h_shift;

        const int cy            = y >> f->chroma_v_shift;

        decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0);



        if (f->chroma_planes) {

            decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1);

            decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1);

        }

        if (fs->transparency)

            decode_plane(fs, p->data[3] + ps*x + y*p->linesize[3], width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2);

    } else {

        uint8_t *planes[3] = { p->data[0] + ps * x + y * p->linesize[0],

                               p->data[1] + ps * x + y * p->linesize[1],

                               p->data[2] + ps * x + y * p->linesize[2] };

        decode_rgb_frame(fs, planes, width, height, p->linesize);

    }

    if (fs->ac && f->version > 2) {

        int v;

        get_rac(&fs->c, (uint8_t[]) { 129 });

        v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec;

        if (v) {

            av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);

            fs->slice_damaged = 1;

        }

    }



    emms_c();



    ff_thread_report_progress(&f->picture, si, 0);



    return 0;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)

{

    FFV1Context *fs   = *(void **)VAR_1;

    FFV1Context *f    = fs->avctx->priv_data;

    int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6;

    const int VAR_7      = av_pix_fmt_desc_get(VAR_0->pix_fmt)->comp[0].step;

    AVFrame * const p = f->cur;

    int VAR_8, VAR_9;



    for( VAR_9=0; fs != f->slice_context[VAR_9]; VAR_9 ++)

        ;



    if(f->fsrc && !p->key_frame)

        ff_thread_await_progress(&f->last_picture, VAR_9, 0);



    if(f->fsrc && !p->key_frame) {

        FFV1Context *fssrc = f->fsrc->slice_context[VAR_9];

        FFV1Context *fsdst = f->slice_context[VAR_9];

        av_assert1(fsdst->plane_count == fssrc->plane_count);

        av_assert1(fsdst == fs);



        if (!p->key_frame)

            fsdst->slice_damaged |= fssrc->slice_damaged;



        for (VAR_8 = 0; VAR_8 < f->plane_count; VAR_8++) {

            PlaneContext *psrc = &fssrc->plane[VAR_8];

            PlaneContext *pdst = &fsdst->plane[VAR_8];



            av_free(pdst->state);

            av_free(pdst->vlc_state);

            memcpy(pdst, psrc, sizeof(*pdst));

            pdst->state = NULL;

            pdst->vlc_state = NULL;



            if (fssrc->ac) {

                pdst->state = av_malloc_array(CONTEXT_SIZE,  psrc->context_count);

                memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count);

            } else {

                pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count);

                memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count);

            }

        }

    }



    fs->slice_rct_by_coef = 1;

    fs->slice_rct_ry_coef = 1;



    if (f->version > 2) {

        if (ff_ffv1_init_slice_state(f, fs) < 0)

            return AVERROR(ENOMEM);

        if (decode_slice_header(f, fs) < 0) {


            fs->slice_damaged = 1;

            return AVERROR_INVALIDDATA;

        }

    }

    if ((VAR_6 = ff_ffv1_init_slice_state(f, fs)) < 0)

        return VAR_6;

    if (f->cur->key_frame || fs->slice_reset_contexts)

        ff_ffv1_clear_slice_state(f, fs);



    VAR_2  = fs->slice_width;

    VAR_3 = fs->slice_height;

    VAR_4      = fs->slice_x;

    VAR_5      = fs->slice_y;



    if (!fs->ac) {

        if (f->version == 3 && f->micro_version > 1 || f->version > 3)

            get_rac(&fs->VAR_0, (uint8_t[]) { 129 });

        fs->ac_byte_count = f->version > 2 || (!VAR_4 && !VAR_5) ? fs->VAR_0.bytestream - fs->VAR_0.bytestream_start - 1 : 0;

        init_get_bits(&fs->gb,

                      fs->VAR_0.bytestream_start + fs->ac_byte_count,

                      (fs->VAR_0.bytestream_end - fs->VAR_0.bytestream_start - fs->ac_byte_count) * 8);

    }



    av_assert1(VAR_2 && VAR_3);

    if (f->colorspace == 0) {

        const int VAR_10  = FF_CEIL_RSHIFT(VAR_2,  f->chroma_h_shift);

        const int VAR_11 = FF_CEIL_RSHIFT(VAR_3, f->chroma_v_shift);

        const int VAR_12            = VAR_4 >> f->chroma_h_shift;

        const int VAR_13            = VAR_5 >> f->chroma_v_shift;

        decode_plane(fs, p->data[0] + VAR_7*VAR_4 + VAR_5*p->linesize[0], VAR_2, VAR_3, p->linesize[0], 0);



        if (f->chroma_planes) {

            decode_plane(fs, p->data[1] + VAR_7*VAR_12+VAR_13*p->linesize[1], VAR_10, VAR_11, p->linesize[1], 1);

            decode_plane(fs, p->data[2] + VAR_7*VAR_12+VAR_13*p->linesize[2], VAR_10, VAR_11, p->linesize[2], 1);

        }

        if (fs->transparency)

            decode_plane(fs, p->data[3] + VAR_7*VAR_4 + VAR_5*p->linesize[3], VAR_2, VAR_3, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2);

    } else {

        uint8_t *planes[3] = { p->data[0] + VAR_7 * VAR_4 + VAR_5 * p->linesize[0],

                               p->data[1] + VAR_7 * VAR_4 + VAR_5 * p->linesize[1],

                               p->data[2] + VAR_7 * VAR_4 + VAR_5 * p->linesize[2] };

        decode_rgb_frame(fs, planes, VAR_2, VAR_3, p->linesize);

    }

    if (fs->ac && f->version > 2) {

        int VAR_14;

        get_rac(&fs->VAR_0, (uint8_t[]) { 129 });

        VAR_14 = fs->VAR_0.bytestream_end - fs->VAR_0.bytestream - 2 - 5*f->ec;

        if (VAR_14) {

            av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", VAR_14);

            fs->slice_damaged = 1;

        }

    }



    emms_c();



    ff_thread_report_progress(&f->picture, VAR_9, 0);



    return 0;

}
static int FUNC_0(AVCodecContext *VAR_0, void *VAR_1)
{ FFV1Context *fs   = *(void **)VAR_1; FFV1Context *f    = fs->avctx->priv_data; int VAR_2, VAR_3, VAR_4, VAR_5, VAR_6; const int VAR_7      = av_pix_fmt_desc_get(VAR_0->pix_fmt)->comp[0].step; AVFrame * const p = f->cur; int VAR_8, VAR_9; for( VAR_9=0; fs != f->slice_context[VAR_9]; VAR_9 ++) ; if(f->fsrc && !p->key_frame)
ff_thread_await_progress(&f->last_picture, VAR_9, 0); if(f->fsrc && !p->key_frame) { FFV1Context *fssrc = f->fsrc->slice_context[VAR_9]; FFV1Context *fsdst = f->slice_context[VAR_9]; av_assert1(fsdst->plane_count == fssrc->plane_count); av_assert1(fsdst == fs); if (!p->key_frame)
fsdst->slice_damaged |= fssrc->slice_damaged; for (VAR_8 = 0; VAR_8 < f->plane_count; VAR_8++) { PlaneContext *psrc = &fssrc->plane[VAR_8]; PlaneContext *pdst = &fsdst->plane[VAR_8]; av_free(pdst->state); av_free(pdst->vlc_state); memcpy(pdst, psrc, sizeof(*pdst)); pdst->state = NULL; pdst->vlc_state = NULL; if (fssrc->ac) { pdst->state = av_malloc_array(CONTEXT_SIZE,  psrc->context_count); memcpy(pdst->state, psrc->state, CONTEXT_SIZE * psrc->context_count); } else { pdst->vlc_state = av_malloc_array(sizeof(*pdst->vlc_state), psrc->context_count); memcpy(pdst->vlc_state, psrc->vlc_state, sizeof(*pdst->vlc_state) * psrc->context_count); } } } fs->slice_rct_by_coef = 1; fs->slice_rct_ry_coef = 1; if (f->version > 2) { if (ff_ffv1_init_slice_state(f, fs) < 0)
return AVERROR(ENOMEM); if (decode_slice_header(f, fs) < 0) { fs->slice_damaged = 1; return AVERROR_INVALIDDATA; } } if ((VAR_6 = ff_ffv1_init_slice_state(f, fs)) < 0)
return VAR_6; if (f->cur->key_frame || fs->slice_reset_contexts)
ff_ffv1_clear_slice_state(f, fs); VAR_2  = fs->slice_width; VAR_3 = fs->slice_height; VAR_4      = fs->slice_x; VAR_5      = fs->slice_y; if (!fs->ac) { if (f->version == 3 && f->micro_version > 1 || f->version > 3)
get_rac(&fs->VAR_0, (uint8_t[]) { 129 }); fs->ac_byte_count = f->version > 2 || (!VAR_4 && !VAR_5) ? fs->VAR_0.bytestream - fs->VAR_0.bytestream_start - 1 : 0; init_get_bits(&fs->gb,
fs->VAR_0.bytestream_start + fs->ac_byte_count,
(fs->VAR_0.bytestream_end - fs->VAR_0.bytestream_start - fs->ac_byte_count) * 8); } av_assert1(VAR_2 && VAR_3); if (f->colorspace == 0) { const int VAR_10  = FF_CEIL_RSHIFT(VAR_2,  f->chroma_h_shift); const int VAR_11 = FF_CEIL_RSHIFT(VAR_3, f->chroma_v_shift); const int VAR_12            = VAR_4 >> f->chroma_h_shift; const int VAR_13            = VAR_5 >> f->chroma_v_shift; decode_plane(fs, p->data[0] + VAR_7*VAR_4 + VAR_5*p->linesize[0], VAR_2, VAR_3, p->linesize[0], 0); if (f->chroma_planes) { decode_plane(fs, p->data[1] + VAR_7*VAR_12+VAR_13*p->linesize[1], VAR_10, VAR_11, p->linesize[1], 1); decode_plane(fs, p->data[2] + VAR_7*VAR_12+VAR_13*p->linesize[2], VAR_10, VAR_11, p->linesize[2], 1); } if (fs->transparency)
decode_plane(fs, p->data[3] + VAR_7*VAR_4 + VAR_5*p->linesize[3], VAR_2, VAR_3, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2); } else { uint8_t *planes[3] = { p->data[0] + VAR_7 * VAR_4 + VAR_5 * p->linesize[0], p->data[1] + VAR_7 * VAR_4 + VAR_5 * p->linesize[1],
p->data[2] + VAR_7 * VAR_4 + VAR_5 * p->linesize[2] }; decode_rgb_frame(fs, planes, VAR_2, VAR_3, p->linesize); } if (fs->ac && f->version > 2) { int VAR_14; get_rac(&fs->VAR_0, (uint8_t[]) { 129 }); VAR_14 = fs->VAR_0.bytestream_end - fs->VAR_0.bytestream - 2 - 5*f->ec; if (VAR_14) { av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", VAR_14); fs->slice_damaged = 1; } } emms_c(); ff_thread_report_progress(&f->picture, VAR_9, 0); return 0; }