diff options
author | Luca Barbato <lu_zero@gentoo.org> | 2012-10-19 12:14:22 +0200 |
---|---|---|
committer | Luca Barbato <lu_zero@gentoo.org> | 2012-10-20 18:14:52 +0200 |
commit | 0f13cd3187192ba0cc2b043430de6e279e7b97c3 (patch) | |
tree | 604398111a32e7515ffac7284dde79ae2b50b2ed /libavcodec/ffv1.c | |
parent | 4a2a4524a3f50ed302820ba971ddd48e78c7436f (diff) | |
download | ffmpeg-0f13cd3187192ba0cc2b043430de6e279e7b97c3.tar.gz |
ffv1: update to ffv1 version 3
Based on code from Carl Eugen Hoyos, Michael Niedermayer and Paul B Mahol.
Diffstat (limited to 'libavcodec/ffv1.c')
-rw-r--r-- | libavcodec/ffv1.c | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 9dfaecb816..682d111c0c 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -138,12 +138,16 @@ int ffv1_common_init(AVCodecContext *avctx) s->avctx = avctx; s->flags = avctx->flags; + if (!avctx->width || !avctx->height) + return AVERROR_INVALIDDATA; + + avcodec_get_frame_defaults(&s->picture); + ff_dsputil_init(&s->dsp, avctx); s->width = avctx->width; s->height = avctx->height; - assert(s->width && s->height); // defaults s->num_h_slices = 1; s->num_v_slices = 1; @@ -151,35 +155,34 @@ int ffv1_common_init(AVCodecContext *avctx) return 0; } -int ffv1_init_slice_state(FFV1Context *f) +int ffv1_init_slice_state(FFV1Context *f, FFV1Context *fs) { - int i, j; - - for (i = 0; i < f->slice_count; i++) { - FFV1Context *fs = f->slice_context[i]; - for (j = 0; j < f->plane_count; j++) { - PlaneContext *const p = &fs->plane[j]; - - if (fs->ac) { - if (!p->state) - p->state = av_malloc(CONTEXT_SIZE * p->context_count * - sizeof(uint8_t)); - if (!p->state) - return AVERROR(ENOMEM); - } else { - if (!p->vlc_state) - p->vlc_state = av_malloc(p->context_count * sizeof(VlcState)); - if (!p->vlc_state) - return AVERROR(ENOMEM); - } + int j; + + fs->plane_count = f->plane_count; + fs->transparency = f->transparency; + for (j = 0; j < f->plane_count; j++) { + PlaneContext *const p = &fs->plane[j]; + + if (fs->ac) { + if (!p->state) + p->state = av_malloc(CONTEXT_SIZE * p->context_count * + sizeof(uint8_t)); + if (!p->state) + return AVERROR(ENOMEM); + } else { + if (!p->vlc_state) + p->vlc_state = av_malloc(p->context_count * sizeof(VlcState)); + if (!p->vlc_state) + return AVERROR(ENOMEM); } + } - if (fs->ac > 1) { - // FIXME: only redo if state_transition changed - for (j = 1; j < 256; j++) { - fs->c.one_state[j] = fs->state_transition[j]; - fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j]; - } + if (fs->ac > 1) { + //FIXME only redo if state_transition changed + for (j = 1; j < 256; j++) { + fs->c.one_state[j] = f->state_transition[j]; + fs->c.zero_state[256 - j] = 256 - fs->c.one_state[j]; } } @@ -209,7 +212,7 @@ av_cold int ffv1_init_slice_contexts(FFV1Context *f) fs->slice_x = sxs; fs->slice_y = sys; - fs->sample_buffer = av_malloc(9 * (fs->width + 6) * + fs->sample_buffer = av_malloc(3 * MAX_PLANES * (fs->width + 6) * sizeof(*fs->sample_buffer)); if (!fs->sample_buffer) return AVERROR(ENOMEM); @@ -232,31 +235,28 @@ int ffv1_allocate_initial_states(FFV1Context *f) return 0; } -void ffv1_clear_state(FFV1Context *f) +void ffv1_clear_slice_state(FFV1Context *f, FFV1Context *fs) { - int i, si, j; - - for (si = 0; si < f->slice_count; si++) { - FFV1Context *fs = f->slice_context[si]; - for (i = 0; i < f->plane_count; i++) { - PlaneContext *p = &fs->plane[i]; + int i, j; - p->interlace_bit_state[0] = 128; - p->interlace_bit_state[1] = 128; - - if (fs->ac) { - if (f->initial_states[p->quant_table_index]) { - memcpy(p->state, f->initial_states[p->quant_table_index], - CONTEXT_SIZE * p->context_count); - } else - memset(p->state, 128, CONTEXT_SIZE * p->context_count); - } else { - for (j = 0; j < p->context_count; j++) { - p->vlc_state[j].drift = 0; - p->vlc_state[j].error_sum = 4; // FFMAX((RANGE + 32)/64, 2); - p->vlc_state[j].bias = 0; - p->vlc_state[j].count = 1; - } + for (i = 0; i < f->plane_count; i++) { + PlaneContext *p = &fs->plane[i]; + + p->interlace_bit_state[0] = 128; + p->interlace_bit_state[1] = 128; + + if (fs->ac) { + if (f->initial_states[p->quant_table_index]) { + memcpy(p->state, f->initial_states[p->quant_table_index], + CONTEXT_SIZE * p->context_count); + } else + memset(p->state, 128, CONTEXT_SIZE * p->context_count); + } else { + for (j = 0; j < p->context_count; j++) { + p->vlc_state[j].drift = 0; + p->vlc_state[j].error_sum = 4; //FFMAX((RANGE + 32)/64, 2); + p->vlc_state[j].bias = 0; + p->vlc_state[j].count = 1; } } } @@ -269,6 +269,8 @@ av_cold int ffv1_close(AVCodecContext *avctx) if (avctx->codec->decode && s->picture.data[0]) avctx->release_buffer(avctx, &s->picture); + if (avctx->codec->decode && s->last_picture.data[0]) + avctx->release_buffer(avctx, &s->last_picture); for (j = 0; j < s->slice_count; j++) { FFV1Context *fs = s->slice_context[j]; |