static int write_extradata(FFV1Context *f)

{

    RangeCoder *const c = &f->c;

    uint8_t state[CONTEXT_SIZE];

    int i, j, k;

    uint8_t state2[32][CONTEXT_SIZE];

    unsigned v;



    memset(state2, 128, sizeof(state2));

    memset(state, 128, sizeof(state));



    f->avctx->extradata_size = 10000 + 4 +

                                    (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;

    f->avctx->extradata = av_malloc(f->avctx->extradata_size);



    ff_init_range_encoder(c, f->avctx->extradata, f->avctx->extradata_size);

    ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);



    put_symbol(c, state, f->version, 0);

    if (f->version > 2) {

        if (f->version == 3)

            f->minor_version = 4;

        put_symbol(c, state, f->minor_version, 0);

    }



    put_symbol(c, state, f->ac, 0);

    if (f->ac > 1)

        for (i = 1; i < 256; i++)

            put_symbol(c, state, f->state_transition[i] - c->one_state[i], 1);



    put_symbol(c, state, f->colorspace, 0); // YUV cs type

    put_symbol(c, state, f->bits_per_raw_sample, 0);

    put_rac(c, state, f->chroma_planes);

    put_symbol(c, state, f->chroma_h_shift, 0);

    put_symbol(c, state, f->chroma_v_shift, 0);

    put_rac(c, state, f->transparency);

    put_symbol(c, state, f->num_h_slices - 1, 0);

    put_symbol(c, state, f->num_v_slices - 1, 0);



    put_symbol(c, state, f->quant_table_count, 0);

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

        write_quant_tables(c, f->quant_tables[i]);



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

        for (j = 0; j < f->context_count[i] * CONTEXT_SIZE; j++)

            if (f->initial_states[i] && f->initial_states[i][0][j] != 128)

                break;

        if (j < f->context_count[i] * CONTEXT_SIZE) {

            put_rac(c, state, 1);

            for (j = 0; j < f->context_count[i]; j++)

                for (k = 0; k < CONTEXT_SIZE; k++) {

                    int pred = j ? f->initial_states[i][j - 1][k] : 128;

                    put_symbol(c, state2[k],

                               (int8_t)(f->initial_states[i][j][k] - pred), 1);

                }

        } else {

            put_rac(c, state, 0);

        }

    }



    if (f->version > 2) {

        put_symbol(c, state, f->ec, 0);

        put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0);

    }



    f->avctx->extradata_size = ff_rac_terminate(c);

    v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);

    AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);

    f->avctx->extradata_size += 4;



    return 0;

}
static int write_extradata(FFV1Context *f)

{

    RangeCoder *const c = &f->c;

    uint8_t state[CONTEXT_SIZE];

    int i, j, k;

    uint8_t state2[32][CONTEXT_SIZE];

    unsigned v;



    memset(state2, 128, sizeof(state2));

    memset(state, 128, sizeof(state));



    f->avctx->extradata_size = 10000 + 4 +

                                    (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;

    f->avctx->extradata = av_malloc(f->avctx->extradata_size);



    ff_init_range_encoder(c, f->avctx->extradata, f->avctx->extradata_size);

    ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);



    put_symbol(c, state, f->version, 0);

    if (f->version > 2) {

        if (f->version == 3)

            f->minor_version = 4;

        put_symbol(c, state, f->minor_version, 0);

    }



    put_symbol(c, state, f->ac, 0);

    if (f->ac > 1)

        for (i = 1; i < 256; i++)

            put_symbol(c, state, f->state_transition[i] - c->one_state[i], 1);



    put_symbol(c, state, f->colorspace, 0); 

    put_symbol(c, state, f->bits_per_raw_sample, 0);

    put_rac(c, state, f->chroma_planes);

    put_symbol(c, state, f->chroma_h_shift, 0);

    put_symbol(c, state, f->chroma_v_shift, 0);

    put_rac(c, state, f->transparency);

    put_symbol(c, state, f->num_h_slices - 1, 0);

    put_symbol(c, state, f->num_v_slices - 1, 0);



    put_symbol(c, state, f->quant_table_count, 0);

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

        write_quant_tables(c, f->quant_tables[i]);



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

        for (j = 0; j < f->context_count[i] * CONTEXT_SIZE; j++)

            if (f->initial_states[i] && f->initial_states[i][0][j] != 128)

                break;

        if (j < f->context_count[i] * CONTEXT_SIZE) {

            put_rac(c, state, 1);

            for (j = 0; j < f->context_count[i]; j++)

                for (k = 0; k < CONTEXT_SIZE; k++) {

                    int pred = j ? f->initial_states[i][j - 1][k] : 128;

                    put_symbol(c, state2[k],

                               (int8_t)(f->initial_states[i][j][k] - pred), 1);

                }

        } else {

            put_rac(c, state, 0);

        }

    }



    if (f->version > 2) {

        put_symbol(c, state, f->ec, 0);

        put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0);

    }



    f->avctx->extradata_size = ff_rac_terminate(c);

    v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size);

    AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v);

    f->avctx->extradata_size += 4;



    return 0;

}
static int FUNC_0(FFV1Context *VAR_0)

{

    RangeCoder *const c = &VAR_0->c;

    uint8_t state[CONTEXT_SIZE];

    int VAR_1, VAR_2, VAR_3;

    uint8_t state2[32][CONTEXT_SIZE];

    unsigned VAR_4;



    memset(state2, 128, sizeof(state2));

    memset(state, 128, sizeof(state));



    VAR_0->avctx->extradata_size = 10000 + 4 +

                                    (11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32;

    VAR_0->avctx->extradata = av_malloc(VAR_0->avctx->extradata_size);



    ff_init_range_encoder(c, VAR_0->avctx->extradata, VAR_0->avctx->extradata_size);

    ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8);



    put_symbol(c, state, VAR_0->version, 0);

    if (VAR_0->version > 2) {

        if (VAR_0->version == 3)

            VAR_0->minor_version = 4;

        put_symbol(c, state, VAR_0->minor_version, 0);

    }



    put_symbol(c, state, VAR_0->ac, 0);

    if (VAR_0->ac > 1)

        for (VAR_1 = 1; VAR_1 < 256; VAR_1++)

            put_symbol(c, state, VAR_0->state_transition[VAR_1] - c->one_state[VAR_1], 1);



    put_symbol(c, state, VAR_0->colorspace, 0); 

    put_symbol(c, state, VAR_0->bits_per_raw_sample, 0);

    put_rac(c, state, VAR_0->chroma_planes);

    put_symbol(c, state, VAR_0->chroma_h_shift, 0);

    put_symbol(c, state, VAR_0->chroma_v_shift, 0);

    put_rac(c, state, VAR_0->transparency);

    put_symbol(c, state, VAR_0->num_h_slices - 1, 0);

    put_symbol(c, state, VAR_0->num_v_slices - 1, 0);



    put_symbol(c, state, VAR_0->quant_table_count, 0);

    for (VAR_1 = 0; VAR_1 < VAR_0->quant_table_count; VAR_1++)

        write_quant_tables(c, VAR_0->quant_tables[VAR_1]);



    for (VAR_1 = 0; VAR_1 < VAR_0->quant_table_count; VAR_1++) {

        for (VAR_2 = 0; VAR_2 < VAR_0->context_count[VAR_1] * CONTEXT_SIZE; VAR_2++)

            if (VAR_0->initial_states[VAR_1] && VAR_0->initial_states[VAR_1][0][VAR_2] != 128)

                break;

        if (VAR_2 < VAR_0->context_count[VAR_1] * CONTEXT_SIZE) {

            put_rac(c, state, 1);

            for (VAR_2 = 0; VAR_2 < VAR_0->context_count[VAR_1]; VAR_2++)

                for (VAR_3 = 0; VAR_3 < CONTEXT_SIZE; VAR_3++) {

                    int pred = VAR_2 ? VAR_0->initial_states[VAR_1][VAR_2 - 1][VAR_3] : 128;

                    put_symbol(c, state2[VAR_3],

                               (int8_t)(VAR_0->initial_states[VAR_1][VAR_2][VAR_3] - pred), 1);

                }

        } else {

            put_rac(c, state, 0);

        }

    }



    if (VAR_0->version > 2) {

        put_symbol(c, state, VAR_0->ec, 0);

        put_symbol(c, state, VAR_0->intra = (VAR_0->avctx->gop_size < 2), 0);

    }



    VAR_0->avctx->extradata_size = ff_rac_terminate(c);

    VAR_4 = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, VAR_0->avctx->extradata, VAR_0->avctx->extradata_size);

    AV_WL32(VAR_0->avctx->extradata + VAR_0->avctx->extradata_size, VAR_4);

    VAR_0->avctx->extradata_size += 4;



    return 0;

}
static int FUNC_0(FFV1Context *VAR_0)
{ RangeCoder *const c = &VAR_0->c; uint8_t state[CONTEXT_SIZE]; int VAR_1, VAR_2, VAR_3; uint8_t state2[32][CONTEXT_SIZE]; unsigned VAR_4; memset(state2, 128, sizeof(state2)); memset(state, 128, sizeof(state)); VAR_0->avctx->extradata_size = 10000 + 4 +
(11 * 11 * 5 * 5 * 5 + 11 * 11 * 11) * 32; VAR_0->avctx->extradata = av_malloc(VAR_0->avctx->extradata_size); ff_init_range_encoder(c, VAR_0->avctx->extradata, VAR_0->avctx->extradata_size); ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); put_symbol(c, state, VAR_0->version, 0); if (VAR_0->version > 2) { if (VAR_0->version == 3)
VAR_0->minor_version = 4; put_symbol(c, state, VAR_0->minor_version, 0); } put_symbol(c, state, VAR_0->ac, 0); if (VAR_0->ac > 1)
for (VAR_1 = 1; VAR_1 < 256; VAR_1++) put_symbol(c, state, VAR_0->state_transition[VAR_1] - c->one_state[VAR_1], 1); put_symbol(c, state, VAR_0->colorspace, 0); put_symbol(c, state, VAR_0->bits_per_raw_sample, 0); put_rac(c, state, VAR_0->chroma_planes); put_symbol(c, state, VAR_0->chroma_h_shift, 0); put_symbol(c, state, VAR_0->chroma_v_shift, 0); put_rac(c, state, VAR_0->transparency); put_symbol(c, state, VAR_0->num_h_slices - 1, 0); put_symbol(c, state, VAR_0->num_v_slices - 1, 0); put_symbol(c, state, VAR_0->quant_table_count, 0); for (VAR_1 = 0; VAR_1 < VAR_0->quant_table_count; VAR_1++) write_quant_tables(c, VAR_0->quant_tables[VAR_1]); for (VAR_1 = 0; VAR_1 < VAR_0->quant_table_count; VAR_1++) { for (VAR_2 = 0; VAR_2 < VAR_0->context_count[VAR_1] * CONTEXT_SIZE; VAR_2++) if (VAR_0->initial_states[VAR_1] && VAR_0->initial_states[VAR_1][0][VAR_2] != 128)
break; if (VAR_2 < VAR_0->context_count[VAR_1] * CONTEXT_SIZE) { put_rac(c, state, 1); for (VAR_2 = 0; VAR_2 < VAR_0->context_count[VAR_1]; VAR_2++) for (VAR_3 = 0; VAR_3 < CONTEXT_SIZE; VAR_3++) { int pred = VAR_2 ? VAR_0->initial_states[VAR_1][VAR_2 - 1][VAR_3] : 128; put_symbol(c, state2[VAR_3],
(int8_t)(VAR_0->initial_states[VAR_1][VAR_2][VAR_3] - pred), 1); } } else { put_rac(c, state, 0); } } if (VAR_0->version > 2) { put_symbol(c, state, VAR_0->ec, 0); put_symbol(c, state, VAR_0->intra = (VAR_0->avctx->gop_size < 2), 0); } VAR_0->avctx->extradata_size = ff_rac_terminate(c); VAR_4 = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, VAR_0->avctx->extradata, VAR_0->avctx->extradata_size); AV_WL32(VAR_0->avctx->extradata + VAR_0->avctx->extradata_size, VAR_4); VAR_0->avctx->extradata_size += 4; return 0; }