static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field)

{

    static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };

    int i, cid;



    if (buf_size < 0x280)

        return -1;



    if (memcmp(buf, header_prefix, 5)) {

        av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");

        return -1;

    }

    if (buf[5] & 2) { /* interlaced */

        ctx->cur_field = buf[5] & 1;

        ctx->picture.interlaced_frame = 1;

        ctx->picture.top_field_first = first_field ^ ctx->cur_field;

        av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field);

    }



    ctx->height = AV_RB16(buf + 0x18);

    ctx->width  = AV_RB16(buf + 0x1a);



    av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height);



    if (buf[0x21] & 0x40) {

        ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P10;

        ctx->avctx->bits_per_raw_sample = 10;

        if (ctx->bit_depth != 10) {

            ff_dsputil_init(&ctx->dsp, ctx->avctx);

            ctx->bit_depth = 10;

            ctx->decode_dct_block = dnxhd_decode_dct_block_10;

        }

    } else {

        ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P;

        ctx->avctx->bits_per_raw_sample = 8;

        if (ctx->bit_depth != 8) {

            ff_dsputil_init(&ctx->dsp, ctx->avctx);

            ctx->bit_depth = 8;

            ctx->decode_dct_block = dnxhd_decode_dct_block_8;

        }

    }



    cid = AV_RB32(buf + 0x28);

    av_dlog(ctx->avctx, "compression id %d\n", cid);



    if (dnxhd_init_vlc(ctx, cid) < 0)

        return -1;



    if (buf_size < ctx->cid_table->coding_unit_size) {

        av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n");

        return -1;

    }



    ctx->mb_width = ctx->width>>4;

    ctx->mb_height = buf[0x16d];



    av_dlog(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);



    if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame)

        ctx->height <<= 1;



    if (ctx->mb_height > 68 ||

        (ctx->mb_height<<ctx->picture.interlaced_frame) > (ctx->height+15)>>4) {

        av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height);

        return -1;

    }



    for (i = 0; i < ctx->mb_height; i++) {

        ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2));

        av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]);

        if (buf_size < ctx->mb_scan_index[i] + 0x280) {

            av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n");

            return -1;

        }

    }



    return 0;

}

static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field)

{

    static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };

    int i, cid;



    if (buf_size < 0x280)

        return -1;



    if (memcmp(buf, header_prefix, 5)) {

        av_log(ctx->avctx, AV_LOG_ERROR, "error in header\n");

        return -1;

    }

    if (buf[5] & 2) { 

        ctx->cur_field = buf[5] & 1;

        ctx->picture.interlaced_frame = 1;

        ctx->picture.top_field_first = first_field ^ ctx->cur_field;

        av_log(ctx->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", buf[5] & 3, ctx->cur_field);

    }



    ctx->height = AV_RB16(buf + 0x18);

    ctx->width  = AV_RB16(buf + 0x1a);



    av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height);



    if (buf[0x21] & 0x40) {

        ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P10;

        ctx->avctx->bits_per_raw_sample = 10;

        if (ctx->bit_depth != 10) {

            ff_dsputil_init(&ctx->dsp, ctx->avctx);

            ctx->bit_depth = 10;

            ctx->decode_dct_block = dnxhd_decode_dct_block_10;

        }

    } else {

        ctx->avctx->pix_fmt = AV_PIX_FMT_YUV422P;

        ctx->avctx->bits_per_raw_sample = 8;

        if (ctx->bit_depth != 8) {

            ff_dsputil_init(&ctx->dsp, ctx->avctx);

            ctx->bit_depth = 8;

            ctx->decode_dct_block = dnxhd_decode_dct_block_8;

        }

    }



    cid = AV_RB32(buf + 0x28);

    av_dlog(ctx->avctx, "compression id %d\n", cid);



    if (dnxhd_init_vlc(ctx, cid) < 0)

        return -1;



    if (buf_size < ctx->cid_table->coding_unit_size) {

        av_log(ctx->avctx, AV_LOG_ERROR, "incorrect frame size\n");

        return -1;

    }



    ctx->mb_width = ctx->width>>4;

    ctx->mb_height = buf[0x16d];



    av_dlog(ctx->avctx, "mb width %d, mb height %d\n", ctx->mb_width, ctx->mb_height);



    if ((ctx->height+15)>>4 == ctx->mb_height && ctx->picture.interlaced_frame)

        ctx->height <<= 1;



    if (ctx->mb_height > 68 ||

        (ctx->mb_height<<ctx->picture.interlaced_frame) > (ctx->height+15)>>4) {

        av_log(ctx->avctx, AV_LOG_ERROR, "mb height too big: %d\n", ctx->mb_height);

        return -1;

    }



    for (i = 0; i < ctx->mb_height; i++) {

        ctx->mb_scan_index[i] = AV_RB32(buf + 0x170 + (i<<2));

        av_dlog(ctx->avctx, "mb scan index %d\n", ctx->mb_scan_index[i]);

        if (buf_size < ctx->mb_scan_index[i] + 0x280) {

            av_log(ctx->avctx, AV_LOG_ERROR, "invalid mb scan index\n");

            return -1;

        }

    }



    return 0;

}

        if (buf_size < ctx->mb_scan_index[i] + 0x280) {
static int FUNC_0(DNXHDContext *VAR_0, const uint8_t *VAR_1, int VAR_2, int VAR_3)

{

    static const uint8_t VAR_4[] = { 0x00, 0x00, 0x02, 0x80, 0x01 };

    int VAR_5, VAR_6;



    if (VAR_2 < 0x280)

        return -1;



    if (memcmp(VAR_1, VAR_4, 5)) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "error in header\n");

        return -1;

    }

    if (VAR_1[5] & 2) { 

        VAR_0->cur_field = VAR_1[5] & 1;

        VAR_0->picture.interlaced_frame = 1;

        VAR_0->picture.top_field_first = VAR_3 ^ VAR_0->cur_field;

        av_log(VAR_0->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", VAR_1[5] & 3, VAR_0->cur_field);

    }



    VAR_0->height = AV_RB16(VAR_1 + 0x18);

    VAR_0->width  = AV_RB16(VAR_1 + 0x1a);



    av_dlog(VAR_0->avctx, "width %d, height %d\n", VAR_0->width, VAR_0->height);



    if (VAR_1[0x21] & 0x40) {

        VAR_0->avctx->pix_fmt = AV_PIX_FMT_YUV422P10;

        VAR_0->avctx->bits_per_raw_sample = 10;

        if (VAR_0->bit_depth != 10) {

            ff_dsputil_init(&VAR_0->dsp, VAR_0->avctx);

            VAR_0->bit_depth = 10;

            VAR_0->decode_dct_block = dnxhd_decode_dct_block_10;

        }

    } else {

        VAR_0->avctx->pix_fmt = AV_PIX_FMT_YUV422P;

        VAR_0->avctx->bits_per_raw_sample = 8;

        if (VAR_0->bit_depth != 8) {

            ff_dsputil_init(&VAR_0->dsp, VAR_0->avctx);

            VAR_0->bit_depth = 8;

            VAR_0->decode_dct_block = dnxhd_decode_dct_block_8;

        }

    }



    VAR_6 = AV_RB32(VAR_1 + 0x28);

    av_dlog(VAR_0->avctx, "compression id %d\n", VAR_6);



    if (dnxhd_init_vlc(VAR_0, VAR_6) < 0)

        return -1;



    if (VAR_2 < VAR_0->cid_table->coding_unit_size) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "incorrect frame size\n");

        return -1;

    }



    VAR_0->mb_width = VAR_0->width>>4;

    VAR_0->mb_height = VAR_1[0x16d];



    av_dlog(VAR_0->avctx, "mb width %d, mb height %d\n", VAR_0->mb_width, VAR_0->mb_height);



    if ((VAR_0->height+15)>>4 == VAR_0->mb_height && VAR_0->picture.interlaced_frame)

        VAR_0->height <<= 1;



    if (VAR_0->mb_height > 68 ||

        (VAR_0->mb_height<<VAR_0->picture.interlaced_frame) > (VAR_0->height+15)>>4) {

        av_log(VAR_0->avctx, AV_LOG_ERROR, "mb height too big: %d\n", VAR_0->mb_height);

        return -1;

    }



    for (VAR_5 = 0; VAR_5 < VAR_0->mb_height; VAR_5++) {

        VAR_0->mb_scan_index[VAR_5] = AV_RB32(VAR_1 + 0x170 + (VAR_5<<2));

        av_dlog(VAR_0->avctx, "mb scan index %d\n", VAR_0->mb_scan_index[VAR_5]);

        if (VAR_2 < VAR_0->mb_scan_index[VAR_5] + 0x280) {

            av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid mb scan index\n");

            return -1;

        }

    }



    return 0;

}

static int FUNC_0(DNXHDContext *VAR_0, const uint8_t *VAR_1, int VAR_2, int VAR_3)
{ static const uint8_t VAR_4[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; int VAR_5, VAR_6; if (VAR_2 < 0x280)
return -1; if (memcmp(VAR_1, VAR_4, 5)) { av_log(VAR_0->avctx, AV_LOG_ERROR, "error in header\n"); return -1; } if (VAR_1[5] & 2) { VAR_0->cur_field = VAR_1[5] & 1; VAR_0->picture.interlaced_frame = 1; VAR_0->picture.top_field_first = VAR_3 ^ VAR_0->cur_field; av_log(VAR_0->avctx, AV_LOG_DEBUG, "interlaced %d, cur field %d\n", VAR_1[5] & 3, VAR_0->cur_field); } VAR_0->height = AV_RB16(VAR_1 + 0x18); VAR_0->width  = AV_RB16(VAR_1 + 0x1a); av_dlog(VAR_0->avctx, "width %d, height %d\n", VAR_0->width, VAR_0->height); if (VAR_1[0x21] & 0x40) { VAR_0->avctx->pix_fmt = AV_PIX_FMT_YUV422P10; VAR_0->avctx->bits_per_raw_sample = 10; if (VAR_0->bit_depth != 10) { ff_dsputil_init(&VAR_0->dsp, VAR_0->avctx); VAR_0->bit_depth = 10; VAR_0->decode_dct_block = dnxhd_decode_dct_block_10; } } else { VAR_0->avctx->pix_fmt = AV_PIX_FMT_YUV422P; VAR_0->avctx->bits_per_raw_sample = 8; if (VAR_0->bit_depth != 8) { ff_dsputil_init(&VAR_0->dsp, VAR_0->avctx); VAR_0->bit_depth = 8; VAR_0->decode_dct_block = dnxhd_decode_dct_block_8; } } VAR_6 = AV_RB32(VAR_1 + 0x28); av_dlog(VAR_0->avctx, "compression id %d\n", VAR_6); if (dnxhd_init_vlc(VAR_0, VAR_6) < 0)
return -1; if (VAR_2 < VAR_0->cid_table->coding_unit_size) { av_log(VAR_0->avctx, AV_LOG_ERROR, "incorrect frame size\n"); return -1; } VAR_0->mb_width = VAR_0->width>>4; VAR_0->mb_height = VAR_1[0x16d]; av_dlog(VAR_0->avctx, "mb width %d, mb height %d\n", VAR_0->mb_width, VAR_0->mb_height); if ((VAR_0->height+15)>>4 == VAR_0->mb_height && VAR_0->picture.interlaced_frame)
VAR_0->height <<= 1; if (VAR_0->mb_height > 68 ||
(VAR_0->mb_height<<VAR_0->picture.interlaced_frame) > (VAR_0->height+15)>>4) { av_log(VAR_0->avctx, AV_LOG_ERROR, "mb height too big: %d\n", VAR_0->mb_height); return -1; } for (VAR_5 = 0; VAR_5 < VAR_0->mb_height; VAR_5++) { VAR_0->mb_scan_index[VAR_5] = AV_RB32(VAR_1 + 0x170 + (VAR_5<<2)); av_dlog(VAR_0->avctx, "mb scan index %d\n", VAR_0->mb_scan_index[VAR_5]); if (VAR_2 < VAR_0->mb_scan_index[VAR_5] + 0x280) { av_log(VAR_0->avctx, AV_LOG_ERROR, "invalid mb scan index\n"); return -1; } } return 0; }