static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
{
    DNXHDEncContext *ctx = avctx->priv_data;
    int first_field = 1;
    int offset, i, ret;
    if (buf_size < ctx->cid_table->frame_size) {
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
        return -1;
    }
    dnxhd_load_picture(ctx, data);
 encode_coding_unit:
    for (i = 0; i < 3; i++) {
        ctx->src[i] = ctx->frame.data[i];
        if (ctx->interlaced && ctx->cur_field)
            ctx->src[i] += ctx->frame.linesize[i];
    }
    dnxhd_write_header(avctx, buf);
    if (avctx->mb_decision == FF_MB_DECISION_RD)
        ret = dnxhd_encode_rdo(avctx, ctx);
    else
        ret = dnxhd_encode_fast(avctx, ctx);
    if (ret < 0) {
        av_log(avctx, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n");
        return -1;
    }
    dnxhd_setup_threads_slices(ctx, buf);
    offset = 0;
    for (i = 0; i < ctx->m.mb_height; i++) {
        AV_WB32(ctx->msip + i * 4, offset);
        offset += ctx->slice_size[i];
        assert(!(ctx->slice_size[i] & 3));
    }
    avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
    AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF
    if (ctx->interlaced && first_field) {
        first_field     = 0;
        ctx->cur_field ^= 1;
        buf      += ctx->cid_table->coding_unit_size;
        buf_size -= ctx->cid_table->coding_unit_size;
        goto encode_coding_unit;
    }
    ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
    return ctx->cid_table->frame_size;
}
static int dnxhd_encode_picture(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data)
{
    DNXHDEncContext *ctx = avctx->priv_data;
    int first_field = 1;
    int offset, i, ret;
    if (buf_size < ctx->cid_table->frame_size) {
        av_log(avctx, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
        return -1;
    }
    dnxhd_load_picture(ctx, data);
 encode_coding_unit:
    for (i = 0; i < 3; i++) {
        ctx->src[i] = ctx->frame.data[i];
        if (ctx->interlaced && ctx->cur_field)
            ctx->src[i] += ctx->frame.linesize[i];
    }
    dnxhd_write_header(avctx, buf);
    if (avctx->mb_decision == FF_MB_DECISION_RD)
        ret = dnxhd_encode_rdo(avctx, ctx);
    else
        ret = dnxhd_encode_fast(avctx, ctx);
    if (ret < 0) {
        av_log(avctx, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n");
        return -1;
    }
    dnxhd_setup_threads_slices(ctx, buf);
    offset = 0;
    for (i = 0; i < ctx->m.mb_height; i++) {
        AV_WB32(ctx->msip + i * 4, offset);
        offset += ctx->slice_size[i];
        assert(!(ctx->slice_size[i] & 3));
    }
    avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
    AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); 
    if (ctx->interlaced && first_field) {
        first_field     = 0;
        ctx->cur_field ^= 1;
        buf      += ctx->cid_table->coding_unit_size;
        buf_size -= ctx->cid_table->coding_unit_size;
        goto encode_coding_unit;
    }
    ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
    return ctx->cid_table->frame_size;
}
static int FUNC_0(AVCodecContext *VAR_0, unsigned char *VAR_1, int VAR_2, void *VAR_3)
{
    DNXHDEncContext *ctx = VAR_0->priv_data;
    int VAR_4 = 1;
    int VAR_5, VAR_6, VAR_7;
    if (VAR_2 < ctx->cid_table->frame_size) {
        av_log(VAR_0, AV_LOG_ERROR, "output buffer is too small to compress picture\n");
        return -1;
    }
    dnxhd_load_picture(ctx, VAR_3);
 encode_coding_unit:
    for (VAR_6 = 0; VAR_6 < 3; VAR_6++) {
        ctx->src[VAR_6] = ctx->frame.VAR_3[VAR_6];
        if (ctx->interlaced && ctx->cur_field)
            ctx->src[VAR_6] += ctx->frame.linesize[VAR_6];
    }
    dnxhd_write_header(VAR_0, VAR_1);
    if (VAR_0->mb_decision == FF_MB_DECISION_RD)
        VAR_7 = dnxhd_encode_rdo(VAR_0, ctx);
    else
        VAR_7 = dnxhd_encode_fast(VAR_0, ctx);
    if (VAR_7 < 0) {
        av_log(VAR_0, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n");
        return -1;
    }
    dnxhd_setup_threads_slices(ctx, VAR_1);
    VAR_5 = 0;
    for (VAR_6 = 0; VAR_6 < ctx->m.mb_height; VAR_6++) {
        AV_WB32(ctx->msip + VAR_6 * 4, VAR_5);
        VAR_5 += ctx->slice_size[VAR_6];
        assert(!(ctx->slice_size[VAR_6] & 3));
    }
    VAR_0->execute(VAR_0, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, VAR_0->thread_count, sizeof(void*));
    AV_WB32(VAR_1 + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); 
    if (ctx->interlaced && VAR_4) {
        VAR_4     = 0;
        ctx->cur_field ^= 1;
        VAR_1      += ctx->cid_table->coding_unit_size;
        VAR_2 -= ctx->cid_table->coding_unit_size;
        goto encode_coding_unit;
    }
    ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA;
    return ctx->cid_table->frame_size;
}
static int FUNC_0(AVCodecContext *VAR_0, unsigned char *VAR_1, int VAR_2, void *VAR_3)
{ DNXHDEncContext *ctx = VAR_0->priv_data; int VAR_4 = 1; int VAR_5, VAR_6, VAR_7; if (VAR_2 < ctx->cid_table->frame_size) { av_log(VAR_0, AV_LOG_ERROR, "output buffer is too small to compress picture\n"); return -1; } dnxhd_load_picture(ctx, VAR_3); encode_coding_unit:
for (VAR_6 = 0; VAR_6 < 3; VAR_6++) { ctx->src[VAR_6] = ctx->frame.VAR_3[VAR_6]; if (ctx->interlaced && ctx->cur_field)
ctx->src[VAR_6] += ctx->frame.linesize[VAR_6]; } dnxhd_write_header(VAR_0, VAR_1); if (VAR_0->mb_decision == FF_MB_DECISION_RD)
VAR_7 = dnxhd_encode_rdo(VAR_0, ctx); else
VAR_7 = dnxhd_encode_fast(VAR_0, ctx); if (VAR_7 < 0) { av_log(VAR_0, AV_LOG_ERROR, "picture could not fit ratecontrol constraints\n"); return -1; } dnxhd_setup_threads_slices(ctx, VAR_1); VAR_5 = 0; for (VAR_6 = 0; VAR_6 < ctx->m.mb_height; VAR_6++) { AV_WB32(ctx->msip + VAR_6 * 4, VAR_5); VAR_5 += ctx->slice_size[VAR_6]; assert(!(ctx->slice_size[VAR_6] & 3)); } VAR_0->execute(VAR_0, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, VAR_0->thread_count, sizeof(void*)); AV_WB32(VAR_1 + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); if (ctx->interlaced && VAR_4) { VAR_4     = 0; ctx->cur_field ^= 1; VAR_1      += ctx->cid_table->coding_unit_size; VAR_2 -= ctx->cid_table->coding_unit_size; goto encode_coding_unit; } ctx->frame.quality = ctx->qscale*FF_QP2LAMBDA; return ctx->cid_table->frame_size; }