Showing the changes to libavcodec (6 of 6 files). Show all
Unified · Split
| @@ -53,7 +53,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx) · 52 unmodified lines | |||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, | 55 | av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, |
| 56 | FFV1Context *fs, FFV1SliceContext *sc) | 56 | FFV1SliceContext *sc) |
| 57 | { | 57 | { |
| 58 | int j, i; | 58 | int j, i; |
| 59 | 59 | ||
| @@ -82,8 +82,8 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, · 22 unmodified lines | |||
| 82 | if (f->ac == AC_RANGE_CUSTOM_TAB) { | 82 | if (f->ac == AC_RANGE_CUSTOM_TAB) { |
| 83 | //FIXME only redo if state_transition changed | 83 | //FIXME only redo if state_transition changed |
| 84 | for (j = 1; j < 256; j++) { | 84 | for (j = 1; j < 256; j++) { |
| 85 | fs->c. one_state[ j] = f->state_transition[j]; | 85 | sc->c. one_state[ j] = f->state_transition[j]; |
| 86 | fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j]; | 86 | sc->c.zero_state[256 - j] = 256 - sc->c.one_state[j]; |
| 87 | } | 87 | } |
| 88 | } | 88 | } |
| 89 | 89 | ||
| @@ -94,8 +94,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f) · 4 unmodified lines | |||
| 94 | { | 94 | { |
| 95 | int i, ret; | 95 | int i, ret; |
| 96 | for (i = 0; i < f->max_slice_count; i++) { | 96 | for (i = 0; i < f->max_slice_count; i++) { |
| 97 | FFV1Context *fs = f->slice_context[i]; | 97 | if ((ret = ff_ffv1_init_slice_state(f, &f->slices[i])) < 0) |
| 98 | if ((ret = ff_ffv1_init_slice_state(f, fs, &f->slices[i])) < 0) | ||
| 99 | return AVERROR(ENOMEM); | 98 | return AVERROR(ENOMEM); |
| 100 | } | 99 | } |
| 101 | return 0; | 100 | return 0; |
| @@ -83,12 +83,12 @@ typedef struct FFV1SliceContext { · 82 unmodified lines | |||
| 83 | 83 | ||
| 84 | PlaneContext plane[MAX_PLANES]; | 84 | PlaneContext plane[MAX_PLANES]; |
| 85 | PutBitContext pb; | 85 | PutBitContext pb; |
| 86 | RangeCoder c; | ||
| 86 | } FFV1SliceContext; | 87 | } FFV1SliceContext; |
| 87 | 88 | ||
| 88 | typedef struct FFV1Context { | 89 | typedef struct FFV1Context { |
| 89 | AVClass *class; | 90 | AVClass *class; |
| 90 | AVCodecContext *avctx; | 91 | AVCodecContext *avctx; |
| 91 | RangeCoder c; | ||
| 92 | uint64_t rc_stat[256][2]; | 92 | uint64_t rc_stat[256][2]; |
| 93 | uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; | 93 | uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2]; |
| 94 | int version; | 94 | int version; |
| @@ -138,8 +138,7 @@ typedef struct FFV1Context { · 43 unmodified lines | |||
| 138 | } FFV1Context; | 138 | } FFV1Context; |
| 139 | 139 | ||
| 140 | int ff_ffv1_common_init(AVCodecContext *avctx); | 140 | int ff_ffv1_common_init(AVCodecContext *avctx); |
| 141 | int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs, | 141 | int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc); |
| 142 | FFV1SliceContext *sc); | ||
| 143 | int ff_ffv1_init_slices_state(FFV1Context *f); | 142 | int ff_ffv1_init_slices_state(FFV1Context *f); |
| 144 | int ff_ffv1_init_slice_contexts(FFV1Context *f); | 143 | int ff_ffv1_init_slice_contexts(FFV1Context *f); |
| 145 | int ff_ffv1_allocate_initial_states(FFV1Context *f); | 144 | int ff_ffv1_allocate_initial_states(FFV1Context *f); |
| @@ -168,7 +168,7 @@ static int decode_plane(FFV1Context *f, · 167 unmodified lines | |||
| 168 | static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, | 168 | static int decode_slice_header(const FFV1Context *f, FFV1Context *fs, |
| 169 | FFV1SliceContext *sc, AVFrame *frame) | 169 | FFV1SliceContext *sc, AVFrame *frame) |
| 170 | { | 170 | { |
| 171 | RangeCoder *c = &fs->c; | 171 | RangeCoder *c = &sc->c; |
| 172 | uint8_t state[CONTEXT_SIZE]; | 172 | uint8_t state[CONTEXT_SIZE]; |
| 173 | unsigned ps, context_count; | 173 | unsigned ps, context_count; |
| 174 | int sx, sy, sw, sh; | 174 | int sx, sy, sw, sh; |
| @@ -299,7 +299,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 124 unmodified lines | |||
| 299 | sc->slice_rct_ry_coef = 1; | 299 | sc->slice_rct_ry_coef = 1; |
| 300 | 300 | ||
| 301 | if (f->version > 2) { | 301 | if (f->version > 2) { |
| 302 | if (ff_ffv1_init_slice_state(f, fs, sc) < 0) | 302 | if (ff_ffv1_init_slice_state(f, sc) < 0) |
| 303 | return AVERROR(ENOMEM); | 303 | return AVERROR(ENOMEM); |
| 304 | if (decode_slice_header(f, fs, sc, p) < 0) { | 304 | if (decode_slice_header(f, fs, sc, p) < 0) { |
| 305 | sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; | 305 | sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; |
| @@ -307,7 +307,7 @@ static int decode_slice(AVCodecContext *c, void *arg) · 1 unmodified line | |||
| 307 | return AVERROR_INVALIDDATA; | 307 | return AVERROR_INVALIDDATA; |
| 308 | } | 308 | } |
| 309 | } | 309 | } |
| 310 | if ((ret = ff_ffv1_init_slice_state(f, fs, sc)) < 0) | 310 | if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0) |
| 311 | return ret; | 311 | return ret; |
| 312 | if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { | 312 | if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) { |
| 313 | ff_ffv1_clear_slice_state(f, sc); | 313 | ff_ffv1_clear_slice_state(f, sc); |
| @@ -322,11 +322,11 @@ static int decode_slice(AVCodecContext *c, void *arg) · 8 unmodified lines | |||
| 322 | 322 | ||
| 323 | if (f->ac == AC_GOLOMB_RICE) { | 323 | if (f->ac == AC_GOLOMB_RICE) { |
| 324 | if (f->version == 3 && f->micro_version > 1 || f->version > 3) | 324 | if (f->version == 3 && f->micro_version > 1 || f->version > 3) |
| 325 | get_rac(&fs->c, (uint8_t[]) { 129 }); | 325 | get_rac(&sc->c, (uint8_t[]) { 129 }); |
| 326 | fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - fs->c.bytestream_start - 1 : 0; | 326 | fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - sc->c.bytestream_start - 1 : 0; |
| 327 | init_get_bits(&gb, | 327 | init_get_bits(&gb, |
| 328 | fs->c.bytestream_start + fs->ac_byte_count, | 328 | sc->c.bytestream_start + fs->ac_byte_count, |
| 329 | (fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count) * 8); | 329 | (sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count) * 8); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | av_assert1(width && height); | 332 | av_assert1(width && height); |
| @@ -361,8 +361,8 @@ static int decode_slice(AVCodecContext *c, void *arg) · 28 unmodified lines | |||
| 361 | } | 361 | } |
| 362 | if (f->ac != AC_GOLOMB_RICE && f->version > 2) { | 362 | if (f->ac != AC_GOLOMB_RICE && f->version > 2) { |
| 363 | int v; | 363 | int v; |
| 364 | get_rac(&fs->c, (uint8_t[]) { 129 }); | 364 | get_rac(&sc->c, (uint8_t[]) { 129 }); |
| 365 | v = fs->c.bytestream_end - fs->c.bytestream - 2 - 5*f->ec; | 365 | v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec; |
| 366 | if (v) { | 366 | if (v) { |
| 367 | av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); | 367 | av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); |
| 368 | fs->slice_damaged = 1; | 368 | fs->slice_damaged = 1; |
| @@ -421,7 +421,7 @@ static int read_quant_tables(RangeCoder *c, · 52 unmodified lines | |||
| 421 | 421 | ||
| 422 | static int read_extra_header(FFV1Context *f) | 422 | static int read_extra_header(FFV1Context *f) |
| 423 | { | 423 | { |
| 424 | RangeCoder *const c = &f->c; | 424 | RangeCoder c; |
| 425 | uint8_t state[CONTEXT_SIZE]; | 425 | uint8_t state[CONTEXT_SIZE]; |
| 426 | int ret; | 426 | int ret; |
| 427 | uint8_t state2[32][CONTEXT_SIZE]; | 427 | uint8_t state2[32][CONTEXT_SIZE]; |
| @@ -430,10 +430,10 @@ static int read_extra_header(FFV1Context *f) · 2 unmodified lines | |||
| 430 | memset(state2, 128, sizeof(state2)); | 430 | memset(state2, 128, sizeof(state2)); |
| 431 | memset(state, 128, sizeof(state)); | 431 | memset(state, 128, sizeof(state)); |
| 432 | 432 | ||
| 433 | ff_init_range_decoder(c, f->avctx->extradata, f->avctx->extradata_size); | 433 | ff_init_range_decoder(&c, f->avctx->extradata, f->avctx->extradata_size); |
| 434 | ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); | 434 | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); |
| 435 | 435 | ||
| 436 | f->version = get_symbol(c, state, 0); | 436 | f->version = get_symbol(&c, state, 0); |
| 437 | if (f->version < 2) { | 437 | if (f->version < 2) { |
| 438 | av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); | 438 | av_log(f->avctx, AV_LOG_ERROR, "Invalid version in global header\n"); |
| 439 | return AVERROR_INVALIDDATA; | 439 | return AVERROR_INVALIDDATA; |
| @@ -444,27 +444,27 @@ static int read_extra_header(FFV1Context *f) · 4 unmodified lines | |||
| 444 | return AVERROR_PATCHWELCOME; | 444 | return AVERROR_PATCHWELCOME; |
| 445 | } | 445 | } |
| 446 | if (f->version > 2) { | 446 | if (f->version > 2) { |
| 447 | c->bytestream_end -= 4; | 447 | c.bytestream_end -= 4; |
| 448 | f->micro_version = get_symbol(c, state, 0); | 448 | f->micro_version = get_symbol(&c, state, 0); |
| 449 | if (f->micro_version < 0) | 449 | if (f->micro_version < 0) |
| 450 | return AVERROR_INVALIDDATA; | 450 | return AVERROR_INVALIDDATA; |
| 451 | } | 451 | } |
| 452 | f->ac = get_symbol(c, state, 0); | 452 | f->ac = get_symbol(&c, state, 0); |
| 453 | 453 | ||
| 454 | if (f->ac == AC_RANGE_CUSTOM_TAB) { | 454 | if (f->ac == AC_RANGE_CUSTOM_TAB) { |
| 455 | for (int i = 1; i < 256; i++) | 455 | for (int i = 1; i < 256; i++) |
| 456 | f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i]; | 456 | f->state_transition[i] = get_symbol(&c, state, 1) + c.one_state[i]; |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | f->colorspace = get_symbol(c, state, 0); //YUV cs type | 459 | f->colorspace = get_symbol(&c, state, 0); //YUV cs type |
| 460 | f->avctx->bits_per_raw_sample = get_symbol(c, state, 0); | 460 | f->avctx->bits_per_raw_sample = get_symbol(&c, state, 0); |
| 461 | f->chroma_planes = get_rac(c, state); | 461 | f->chroma_planes = get_rac(&c, state); |
| 462 | f->chroma_h_shift = get_symbol(c, state, 0); | 462 | f->chroma_h_shift = get_symbol(&c, state, 0); |
| 463 | f->chroma_v_shift = get_symbol(c, state, 0); | 463 | f->chroma_v_shift = get_symbol(&c, state, 0); |
| 464 | f->transparency = get_rac(c, state); | 464 | f->transparency = get_rac(&c, state); |
| 465 | f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; | 465 | f->plane_count = 1 + (f->chroma_planes || f->version<4) + f->transparency; |
| 466 | f->num_h_slices = 1 + get_symbol(c, state, 0); | 466 | f->num_h_slices = 1 + get_symbol(&c, state, 0); |
| 467 | f->num_v_slices = 1 + get_symbol(c, state, 0); | 467 | f->num_v_slices = 1 + get_symbol(&c, state, 0); |
| 468 | 468 | ||
| 469 | if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { | 469 | if (f->chroma_h_shift > 4U || f->chroma_v_shift > 4U) { |
| 470 | av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", | 470 | av_log(f->avctx, AV_LOG_ERROR, "chroma shift parameters %d %d are invalid\n", |
| @@ -484,7 +484,7 @@ static int read_extra_header(FFV1Context *f) · 13 unmodified lines | |||
| 484 | return AVERROR_PATCHWELCOME; | 484 | return AVERROR_PATCHWELCOME; |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | f->quant_table_count = get_symbol(c, state, 0); | 487 | f->quant_table_count = get_symbol(&c, state, 0); |
| 488 | if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) { | 488 | if (f->quant_table_count > (unsigned)MAX_QUANT_TABLES || !f->quant_table_count) { |
| 489 | av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count); | 489 | av_log(f->avctx, AV_LOG_ERROR, "quant table count %d is invalid\n", f->quant_table_count); |
| 490 | f->quant_table_count = 0; | 490 | f->quant_table_count = 0; |
| @@ -492,7 +492,7 @@ static int read_extra_header(FFV1Context *f) · 1 unmodified line | |||
| 492 | } | 492 | } |
| 493 | 493 | ||
| 494 | for (int i = 0; i < f->quant_table_count; i++) { | 494 | for (int i = 0; i < f->quant_table_count; i++) { |
| 495 | f->context_count[i] = read_quant_tables(c, f->quant_tables[i]); | 495 | f->context_count[i] = read_quant_tables(&c, f->quant_tables[i]); |
| 496 | if (f->context_count[i] < 0) { | 496 | if (f->context_count[i] < 0) { |
| 497 | av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); | 497 | av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); |
| 498 | return AVERROR_INVALIDDATA; | 498 | return AVERROR_INVALIDDATA; |
| @@ -502,19 +502,19 @@ static int read_extra_header(FFV1Context *f) · 3 unmodified lines | |||
| 502 | return ret; | 502 | return ret; |
| 503 | 503 | ||
| 504 | for (int i = 0; i < f->quant_table_count; i++) | 504 | for (int i = 0; i < f->quant_table_count; i++) |
| 505 | if (get_rac(c, state)) { | 505 | if (get_rac(&c, state)) { |
| 506 | for (int j = 0; j < f->context_count[i]; j++) | 506 | for (int j = 0; j < f->context_count[i]; j++) |
| 507 | for (int k = 0; k < CONTEXT_SIZE; k++) { | 507 | for (int k = 0; k < CONTEXT_SIZE; k++) { |
| 508 | int pred = j ? f->initial_states[i][j - 1][k] : 128; | 508 | int pred = j ? f->initial_states[i][j - 1][k] : 128; |
| 509 | f->initial_states[i][j][k] = | 509 | f->initial_states[i][j][k] = |
| 510 | (pred + get_symbol(c, state2[k], 1)) & 0xFF; | 510 | (pred + get_symbol(&c, state2[k], 1)) & 0xFF; |
| 511 | } | 511 | } |
| 512 | } | 512 | } |
| 513 | 513 | ||
| 514 | if (f->version > 2) { | 514 | if (f->version > 2) { |
| 515 | f->ec = get_symbol(c, state, 0); | 515 | f->ec = get_symbol(&c, state, 0); |
| 516 | if (f->micro_version > 2) | 516 | if (f->micro_version > 2) |
| 517 | f->intra = get_symbol(c, state, 0); | 517 | f->intra = get_symbol(&c, state, 0); |
| 518 | } | 518 | } |
| 519 | 519 | ||
| 520 | if (f->version > 2) { | 520 | if (f->version > 2) { |
| @@ -550,7 +550,7 @@ static int read_header(FFV1Context *f) · 29 unmodified lines | |||
| 550 | { | 550 | { |
| 551 | uint8_t state[CONTEXT_SIZE]; | 551 | uint8_t state[CONTEXT_SIZE]; |
| 552 | int context_count = -1; //-1 to avoid warning | 552 | int context_count = -1; //-1 to avoid warning |
| 553 | RangeCoder *const c = &f->slice_context[0]->c; | 553 | RangeCoder *const c = &f->slices[0].c; |
| 554 | 554 | ||
| 555 | memset(state, 128, sizeof(state)); | 555 | memset(state, 128, sizeof(state)); |
| 556 | 556 | ||
| @@ -868,7 +868,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 311 unmodified lines | |||
| 868 | uint8_t *buf = avpkt->data; | 868 | uint8_t *buf = avpkt->data; |
| 869 | int buf_size = avpkt->size; | 869 | int buf_size = avpkt->size; |
| 870 | FFV1Context *f = avctx->priv_data; | 870 | FFV1Context *f = avctx->priv_data; |
| 871 | RangeCoder *const c = &f->slice_context[0]->c; | 871 | RangeCoder *const c = &f->slices[0].c; |
| 872 | int ret, key_frame; | 872 | int ret, key_frame; |
| 873 | uint8_t keystate = 128; | 873 | uint8_t keystate = 128; |
| 874 | uint8_t *buf_p; | 874 | uint8_t *buf_p; |
| @@ -939,6 +939,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 64 unmodified lines | |||
| 939 | buf_p = buf + buf_size; | 939 | buf_p = buf + buf_size; |
| 940 | for (int i = f->slice_count - 1; i >= 0; i--) { | 940 | for (int i = f->slice_count - 1; i >= 0; i--) { |
| 941 | FFV1Context *fs = f->slice_context[i]; | 941 | FFV1Context *fs = f->slice_context[i]; |
| 942 | FFV1SliceContext *sc = &f->slices[i]; | ||
| 942 | int trailer = 3 + 5*!!f->ec; | 943 | int trailer = 3 + 5*!!f->ec; |
| 943 | int v; | 944 | int v; |
| 944 | 945 | ||
| @@ -973,9 +974,10 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe, · 28 unmodified lines | |||
| 973 | } | 974 | } |
| 974 | 975 | ||
| 975 | if (i) { | 976 | if (i) { |
| 976 | ff_init_range_decoder(&fs->c, buf_p, v); | 977 | ff_init_range_decoder(&sc->c, buf_p, v); |
| 978 | ff_build_rac_states(&sc->c, 0.05 * (1LL << 32), 256 - 8); | ||
| 977 | } else | 979 | } else |
| 978 | fs->c.bytestream_end = buf_p + v; | 980 | sc->c.bytestream_end = buf_p + v; |
| 979 | 981 | ||
| 980 | fs->avctx = avctx; | 982 | fs->avctx = avctx; |
| 981 | } | 983 | } |
| @@ -30,7 +30,7 @@ RENAME(decode_line)(FFV1Context *f, · 29 unmodified lines | |||
| 30 | int ac) | 30 | int ac) |
| 31 | { | 31 | { |
| 32 | PlaneContext *const p = &sc->plane[plane_index]; | 32 | PlaneContext *const p = &sc->plane[plane_index]; |
| 33 | RangeCoder *const c = &s->c; | 33 | RangeCoder *const c = &sc->c; |
| 34 | const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index]; | 34 | const int16_t (*quant_table)[256] = f->quant_tables[p->quant_table_index]; |
| 35 | int x; | 35 | int x; |
| 36 | int run_count = 0; | 36 | int run_count = 0; |
| @@ -349,7 +349,7 @@ static void write_header(FFV1Context *f) · 348 unmodified lines | |||
| 349 | { | 349 | { |
| 350 | uint8_t state[CONTEXT_SIZE]; | 350 | uint8_t state[CONTEXT_SIZE]; |
| 351 | int i, j; | 351 | int i, j; |
| 352 | RangeCoder *const c = &f->slice_context[0]->c; | 352 | RangeCoder *const c = &f->slices[0].c; |
| 353 | 353 | ||
| 354 | memset(state, 128, sizeof(state)); | 354 | memset(state, 128, sizeof(state)); |
| 355 | 355 | ||
| @@ -394,7 +394,7 @@ static void write_header(FFV1Context *f) · 38 unmodified lines | |||
| 394 | 394 | ||
| 395 | static int write_extradata(FFV1Context *f) | 395 | static int write_extradata(FFV1Context *f) |
| 396 | { | 396 | { |
| 397 | RangeCoder *const c = &f->c; | 397 | RangeCoder c; |
| 398 | uint8_t state[CONTEXT_SIZE]; | 398 | uint8_t state[CONTEXT_SIZE]; |
| 399 | int i, j, k; | 399 | int i, j, k; |
| 400 | uint8_t state2[32][CONTEXT_SIZE]; | 400 | uint8_t state2[32][CONTEXT_SIZE]; |
| @@ -408,56 +408,56 @@ static int write_extradata(FFV1Context *f) · 7 unmodified lines | |||
| 408 | f->avctx->extradata = av_malloc(f->avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); | 408 | f->avctx->extradata = av_malloc(f->avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); |
| 409 | if (!f->avctx->extradata) | 409 | if (!f->avctx->extradata) |
| 410 | return AVERROR(ENOMEM); | 410 | return AVERROR(ENOMEM); |
| 411 | ff_init_range_encoder(c, f->avctx->extradata, f->avctx->extradata_size); | 411 | ff_init_range_encoder(&c, f->avctx->extradata, f->avctx->extradata_size); |
| 412 | ff_build_rac_states(c, 0.05 * (1LL << 32), 256 - 8); | 412 | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); |
| 413 | 413 | ||
| 414 | put_symbol(c, state, f->version, 0); | 414 | put_symbol(&c, state, f->version, 0); |
| 415 | if (f->version > 2) { | 415 | if (f->version > 2) { |
| 416 | if (f->version == 3) { | 416 | if (f->version == 3) { |
| 417 | f->micro_version = 4; | 417 | f->micro_version = 4; |
| 418 | } else if (f->version == 4) | 418 | } else if (f->version == 4) |
| 419 | f->micro_version = 2; | 419 | f->micro_version = 2; |
| 420 | put_symbol(c, state, f->micro_version, 0); | 420 | put_symbol(&c, state, f->micro_version, 0); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | put_symbol(c, state, f->ac, 0); | 423 | put_symbol(&c, state, f->ac, 0); |
| 424 | if (f->ac == AC_RANGE_CUSTOM_TAB) | 424 | if (f->ac == AC_RANGE_CUSTOM_TAB) |
| 425 | for (i = 1; i < 256; i++) | 425 | for (i = 1; i < 256; i++) |
| 426 | put_symbol(c, state, f->state_transition[i] - c->one_state[i], 1); | 426 | put_symbol(&c, state, f->state_transition[i] - c.one_state[i], 1); |
| 427 | 427 | ||
| 428 | put_symbol(c, state, f->colorspace, 0); // YUV cs type | 428 | put_symbol(&c, state, f->colorspace, 0); // YUV cs type |
| 429 | put_symbol(c, state, f->bits_per_raw_sample, 0); | 429 | put_symbol(&c, state, f->bits_per_raw_sample, 0); |
| 430 | put_rac(c, state, f->chroma_planes); | 430 | put_rac(&c, state, f->chroma_planes); |
| 431 | put_symbol(c, state, f->chroma_h_shift, 0); | 431 | put_symbol(&c, state, f->chroma_h_shift, 0); |
| 432 | put_symbol(c, state, f->chroma_v_shift, 0); | 432 | put_symbol(&c, state, f->chroma_v_shift, 0); |
| 433 | put_rac(c, state, f->transparency); | 433 | put_rac(&c, state, f->transparency); |
| 434 | put_symbol(c, state, f->num_h_slices - 1, 0); | 434 | put_symbol(&c, state, f->num_h_slices - 1, 0); |
| 435 | put_symbol(c, state, f->num_v_slices - 1, 0); | 435 | put_symbol(&c, state, f->num_v_slices - 1, 0); |
| 436 | 436 | ||
| 437 | put_symbol(c, state, f->quant_table_count, 0); | 437 | put_symbol(&c, state, f->quant_table_count, 0); |
| 438 | for (i = 0; i < f->quant_table_count; i++) | 438 | for (i = 0; i < f->quant_table_count; i++) |
| 439 | write_quant_tables(c, f->quant_tables[i]); | 439 | write_quant_tables(&c, f->quant_tables[i]); |
| 440 | 440 | ||
| 441 | for (i = 0; i < f->quant_table_count; i++) { | 441 | for (i = 0; i < f->quant_table_count; i++) { |
| 442 | if (contains_non_128(f->initial_states[i], f->context_count[i])) { | 442 | if (contains_non_128(f->initial_states[i], f->context_count[i])) { |
| 443 | put_rac(c, state, 1); | 443 | put_rac(&c, state, 1); |
| 444 | for (j = 0; j < f->context_count[i]; j++) | 444 | for (j = 0; j < f->context_count[i]; j++) |
| 445 | for (k = 0; k < CONTEXT_SIZE; k++) { | 445 | for (k = 0; k < CONTEXT_SIZE; k++) { |
| 446 | int pred = j ? f->initial_states[i][j - 1][k] : 128; | 446 | int pred = j ? f->initial_states[i][j - 1][k] : 128; |
| 447 | put_symbol(c, state2[k], | 447 | put_symbol(&c, state2[k], |
| 448 | (int8_t)(f->initial_states[i][j][k] - pred), 1); | 448 | (int8_t)(f->initial_states[i][j][k] - pred), 1); |
| 449 | } | 449 | } |
| 450 | } else { | 450 | } else { |
| 451 | put_rac(c, state, 0); | 451 | put_rac(&c, state, 0); |
| 452 | } | 452 | } |
| 453 | } | 453 | } |
| 454 | 454 | ||
| 455 | if (f->version > 2) { | 455 | if (f->version > 2) { |
| 456 | put_symbol(c, state, f->ec, 0); | 456 | put_symbol(&c, state, f->ec, 0); |
| 457 | put_symbol(c, state, f->intra = (f->avctx->gop_size < 2), 0); | 457 | put_symbol(&c, state, f->intra = (f->avctx->gop_size < 2), 0); |
| 458 | } | 458 | } |
| 459 | 459 | ||
| 460 | f->avctx->extradata_size = ff_rac_terminate(c, 0); | 460 | f->avctx->extradata_size = ff_rac_terminate(&c, 0); |
| 461 | v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); | 461 | v = av_crc(av_crc_get_table(AV_CRC_32_IEEE), 0, f->avctx->extradata, f->avctx->extradata_size); |
| 462 | AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v); | 462 | AV_WL32(f->avctx->extradata + f->avctx->extradata_size, v); |
| 463 | f->avctx->extradata_size += 4; | 463 | f->avctx->extradata_size += 4; |
| @@ -883,6 +883,8 @@ slices_ok: · 419 unmodified lines | |||
| 883 | p->quant_table_index = s->context_model; | 883 | p->quant_table_index = s->context_model; |
| 884 | p->context_count = s->context_count[p->quant_table_index]; | 884 | p->context_count = s->context_count[p->quant_table_index]; |
| 885 | } | 885 | } |
| 886 | |||
| 887 | ff_build_rac_states(&s->slices[j].c, 0.05 * (1LL << 32), 256 - 8); | ||
| 886 | } | 888 | } |
| 887 | 889 | ||
| 888 | if ((ret = ff_ffv1_init_slices_state(s)) < 0) | 890 | if ((ret = ff_ffv1_init_slices_state(s)) < 0) |
| @@ -910,7 +912,7 @@ slices_ok: · 21 unmodified lines | |||
| 910 | static void encode_slice_header(FFV1Context *f, FFV1Context *fs, | 912 | static void encode_slice_header(FFV1Context *f, FFV1Context *fs, |
| 911 | FFV1SliceContext *sc) | 913 | FFV1SliceContext *sc) |
| 912 | { | 914 | { |
| 913 | RangeCoder *c = &fs->c; | 915 | RangeCoder *c = &sc->c; |
| 914 | uint8_t state[CONTEXT_SIZE]; | 916 | uint8_t state[CONTEXT_SIZE]; |
| 915 | int j; | 917 | int j; |
| 916 | memset(state, 128, sizeof(state)); | 918 | memset(state, 128, sizeof(state)); |
| @@ -1037,7 +1039,7 @@ static int encode_slice(AVCodecContext *c, void *arg) · 120 unmodified lines | |||
| 1037 | const AVFrame *const p = f->cur_enc_frame; | 1039 | const AVFrame *const p = f->cur_enc_frame; |
| 1038 | const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; | 1040 | const int ps = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step; |
| 1039 | int ret; | 1041 | int ret; |
| 1040 | RangeCoder c_bak = fs->c; | 1042 | RangeCoder c_bak = sc->c; |
| 1041 | const uint8_t *planes[4] = {p->data[0] + ps*x + y*p->linesize[0], | 1043 | const uint8_t *planes[4] = {p->data[0] + ps*x + y*p->linesize[0], |
| 1042 | p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] : NULL, | 1044 | p->data[1] ? p->data[1] + ps*x + y*p->linesize[1] : NULL, |
| 1043 | p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] : NULL, | 1045 | p->data[2] ? p->data[2] + ps*x + y*p->linesize[2] : NULL, |
| @@ -1058,10 +1060,10 @@ retry: · 14 unmodified lines | |||
| 1058 | encode_slice_header(f, fs, sc); | 1060 | encode_slice_header(f, fs, sc); |
| 1059 | } | 1061 | } |
| 1060 | if (f->ac == AC_GOLOMB_RICE) { | 1062 | if (f->ac == AC_GOLOMB_RICE) { |
| 1061 | fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&fs->c, f->version > 2) : 0; | 1063 | fs->ac_byte_count = f->version > 2 || (!x && !y) ? ff_rac_terminate(&sc->c, f->version > 2) : 0; |
| 1062 | init_put_bits(&sc->pb, | 1064 | init_put_bits(&sc->pb, |
| 1063 | fs->c.bytestream_start + fs->ac_byte_count, | 1065 | sc->c.bytestream_start + fs->ac_byte_count, |
| 1064 | fs->c.bytestream_end - fs->c.bytestream_start - fs->ac_byte_count); | 1066 | sc->c.bytestream_end - sc->c.bytestream_start - fs->ac_byte_count); |
| 1065 | } | 1067 | } |
| 1066 | 1068 | ||
| 1067 | if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) { | 1069 | if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) { |
| @@ -1095,7 +1097,7 @@ retry: · 27 unmodified lines | |||
| 1095 | } | 1097 | } |
| 1096 | av_log(c, AV_LOG_DEBUG, "Coding slice as PCM\n"); | 1098 | av_log(c, AV_LOG_DEBUG, "Coding slice as PCM\n"); |
| 1097 | sc->slice_coding_mode = 1; | 1099 | sc->slice_coding_mode = 1; |
| 1098 | fs->c = c_bak; | 1100 | sc->c = c_bak; |
| 1099 | goto retry; | 1101 | goto retry; |
| 1100 | } | 1102 | } |
| 1101 | 1103 | ||
| @@ -1106,7 +1108,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 4 unmodified lines | |||
| 1106 | const AVFrame *pict, int *got_packet) | 1108 | const AVFrame *pict, int *got_packet) |
| 1107 | { | 1109 | { |
| 1108 | FFV1Context *f = avctx->priv_data; | 1110 | FFV1Context *f = avctx->priv_data; |
| 1109 | RangeCoder *const c = &f->slice_context[0]->c; | 1111 | RangeCoder *const c = &f->slices[0].c; |
| 1110 | uint8_t keystate = 128; | 1112 | uint8_t keystate = 128; |
| 1111 | uint8_t *buf_p; | 1113 | uint8_t *buf_p; |
| 1112 | int i, ret; | 1114 | int i, ret; |
| @@ -1194,15 +1196,15 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 81 unmodified lines | |||
| 1194 | } | 1196 | } |
| 1195 | 1197 | ||
| 1196 | for (i = 0; i < f->slice_count; i++) { | 1198 | for (i = 0; i < f->slice_count; i++) { |
| 1197 | FFV1Context *fs = f->slice_context[i]; | 1199 | FFV1SliceContext *sc = &f->slices[i]; |
| 1198 | uint8_t *start = pkt->data + pkt->size * (int64_t)i / f->slice_count; | 1200 | uint8_t *start = pkt->data + pkt->size * (int64_t)i / f->slice_count; |
| 1199 | int len = pkt->size / f->slice_count; | 1201 | int len = pkt->size / f->slice_count; |
| 1200 | if (i) { | 1202 | if (i) { |
| 1201 | ff_init_range_encoder(&fs->c, start, len); | 1203 | ff_init_range_encoder(&sc->c, start, len); |
| 1202 | } else { | 1204 | } else { |
| 1203 | av_assert0(fs->c.bytestream_end >= fs->c.bytestream_start + len); | 1205 | av_assert0(sc->c.bytestream_end >= sc->c.bytestream_start + len); |
| 1204 | av_assert0(fs->c.bytestream < fs->c.bytestream_start + len); | 1206 | av_assert0(sc->c.bytestream < sc->c.bytestream_start + len); |
| 1205 | fs->c.bytestream_end = fs->c.bytestream_start + len; | 1207 | sc->c.bytestream_end = sc->c.bytestream_start + len; |
| 1206 | } | 1208 | } |
| 1207 | } | 1209 | } |
| 1208 | avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, | 1210 | avctx->execute(avctx, encode_slice, &f->slice_context[0], NULL, |
| @@ -1215,14 +1217,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 6 unmodified lines | |||
| 1215 | int bytes; | 1217 | int bytes; |
| 1216 | 1218 | ||
| 1217 | if (f->ac != AC_GOLOMB_RICE) { | 1219 | if (f->ac != AC_GOLOMB_RICE) { |
| 1218 | bytes = ff_rac_terminate(&fs->c, 1); | 1220 | bytes = ff_rac_terminate(&sc->c, 1); |
| 1219 | } else { | 1221 | } else { |
| 1220 | flush_put_bits(&sc->pb); // FIXME: nicer padding | 1222 | flush_put_bits(&sc->pb); // FIXME: nicer padding |
| 1221 | bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); | 1223 | bytes = fs->ac_byte_count + put_bytes_output(&sc->pb); |
| 1222 | } | 1224 | } |
| 1223 | if (i > 0 || f->version > 2) { | 1225 | if (i > 0 || f->version > 2) { |
| 1224 | av_assert0(bytes < pkt->size / f->slice_count); | 1226 | av_assert0(bytes < pkt->size / f->slice_count); |
| 1225 | memmove(buf_p, fs->c.bytestream_start, bytes); | 1227 | memmove(buf_p, sc->c.bytestream_start, bytes); |
| 1226 | av_assert0(bytes < (1 << 24)); | 1228 | av_assert0(bytes < (1 << 24)); |
| 1227 | AV_WB24(buf_p + bytes, bytes); | 1229 | AV_WB24(buf_p + bytes, bytes); |
| 1228 | bytes += 3; | 1230 | bytes += 3; |
| @@ -29,7 +29,7 @@ RENAME(encode_line)(FFV1Context *f, · 28 unmodified lines | |||
| 29 | int ac) | 29 | int ac) |
| 30 | { | 30 | { |
| 31 | PlaneContext *const p = &sc->plane[plane_index]; | 31 | PlaneContext *const p = &sc->plane[plane_index]; |
| 32 | RangeCoder *const c = &s->c; | 32 | RangeCoder *const c = &sc->c; |
| 33 | int x; | 33 | int x; |
| 34 | int run_index = sc->run_index; | 34 | int run_index = sc->run_index; |
| 35 | int run_count = 0; | 35 | int run_count = 0; |