[FFmpeg-cvslog] mss12: move SliceContexts out of the common context into the codec contexts
Alberto Delmás
git at videolan.org
Tue Sep 4 17:15:01 CEST 2012
ffmpeg | branch: master | Alberto Delmás <adelmas at gmail.com> | Sun Sep 2 12:42:01 2012 +0200| [a97ee41bee60b2075c84e2ce6bb441304698744c] | committer: Kostya Shishkov
mss12: move SliceContexts out of the common context into the codec contexts
Signed-off-by: Kostya Shishkov <kostya.shishkov at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a97ee41bee60b2075c84e2ce6bb441304698744c
---
libavcodec/mss1.c | 9 ++++----
libavcodec/mss12.c | 60 +++++++++++++++++++++++++---------------------------
libavcodec/mss12.h | 9 +++-----
libavcodec/mss2.c | 14 +++++++-----
4 files changed, 46 insertions(+), 46 deletions(-)
diff --git a/libavcodec/mss1.c b/libavcodec/mss1.c
index caf0328..678208b 100644
--- a/libavcodec/mss1.c
+++ b/libavcodec/mss1.c
@@ -30,7 +30,7 @@
typedef struct MSS1Context {
MSS12Context ctx;
AVFrame pic;
- SliceContext sc[2];
+ SliceContext sc;
} MSS1Context;
static void arith_normalise(ArithCoder *c)
@@ -162,7 +162,8 @@ static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
c->pal_stride = -ctx->pic.linesize[0];
c->keyframe = !arith_get_bit(&acoder);
if (c->keyframe) {
- ff_mss12_codec_reset(c);
+ c->corrupted = 0;
+ ff_mss12_slicecontext_reset(&ctx->sc);
pal_changed = decode_pal(c, &acoder);
ctx->pic.key_frame = 1;
ctx->pic.pict_type = AV_PICTURE_TYPE_I;
@@ -172,7 +173,7 @@ static int mss1_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
ctx->pic.key_frame = 0;
ctx->pic.pict_type = AV_PICTURE_TYPE_P;
}
- c->corrupted = ff_mss12_decode_rect(&c->sc[0], &acoder, 0, 0,
+ c->corrupted = ff_mss12_decode_rect(&ctx->sc, &acoder, 0, 0,
avctx->width, avctx->height);
if (c->corrupted)
return AVERROR_INVALIDDATA;
@@ -194,7 +195,7 @@ static av_cold int mss1_decode_init(AVCodecContext *avctx)
c->ctx.avctx = avctx;
avctx->coded_frame = &c->pic;
- ret = ff_mss12_decode_init(&c->ctx, 0);
+ ret = ff_mss12_decode_init(&c->ctx, 0, &c->sc, NULL);
avctx->pix_fmt = PIX_FMT_PAL8;
diff --git a/libavcodec/mss12.c b/libavcodec/mss12.c
index 18f2f28..ea12769 100644
--- a/libavcodec/mss12.c
+++ b/libavcodec/mss12.c
@@ -435,39 +435,30 @@ static int decode_region_masked(MSS12Context const *c, ArithCoder *acoder,
return 0;
}
-static av_cold void codec_init(MSS12Context *c, int version)
+static av_cold void slicecontext_init(SliceContext *sc,
+ int version, int full_model_syms)
{
- int i;
- for (i = 0; i < (c->slice_split ? 2 : 1); i++) {
- c->sc[i].c = c;
- model_init(&c->sc[i].intra_region, 2, THRESH_ADAPTIVE);
- model_init(&c->sc[i].inter_region, 2, THRESH_ADAPTIVE);
- model_init(&c->sc[i].split_mode, 3, THRESH_HIGH);
- model_init(&c->sc[i].edge_mode, 2, THRESH_HIGH);
- model_init(&c->sc[i].pivot, 3, THRESH_LOW);
-
- pixctx_init(&c->sc[i].intra_pix_ctx, 8, c->full_model_syms, 0);
-
- pixctx_init(&c->sc[i].inter_pix_ctx, version ? 3 : 2,
- c->full_model_syms, version ? 1 : 0);
- }
- c->corrupted = 1;
+ model_init(&sc->intra_region, 2, THRESH_ADAPTIVE);
+ model_init(&sc->inter_region, 2, THRESH_ADAPTIVE);
+ model_init(&sc->split_mode, 3, THRESH_HIGH);
+ model_init(&sc->edge_mode, 2, THRESH_HIGH);
+ model_init(&sc->pivot, 3, THRESH_LOW);
+
+ pixctx_init(&sc->intra_pix_ctx, 8, full_model_syms, 0);
+
+ pixctx_init(&sc->inter_pix_ctx, version ? 3 : 2,
+ full_model_syms, version ? 1 : 0);
}
-void ff_mss12_codec_reset(MSS12Context *c)
+void ff_mss12_slicecontext_reset(SliceContext *sc)
{
- int i;
- for (i = 0; i < (c->slice_split ? 2 : 1); i++) {
- model_reset(&c->sc[i].intra_region);
- model_reset(&c->sc[i].inter_region);
- model_reset(&c->sc[i].split_mode);
- model_reset(&c->sc[i].edge_mode);
- model_reset(&c->sc[i].pivot);
- pixctx_reset(&c->sc[i].intra_pix_ctx);
- pixctx_reset(&c->sc[i].inter_pix_ctx);
- }
-
- c->corrupted = 0;
+ model_reset(&sc->intra_region);
+ model_reset(&sc->inter_region);
+ model_reset(&sc->split_mode);
+ model_reset(&sc->edge_mode);
+ model_reset(&sc->pivot);
+ pixctx_reset(&sc->intra_pix_ctx);
+ pixctx_reset(&sc->inter_pix_ctx);
}
static int decode_pivot(SliceContext *sc, ArithCoder *acoder, int base)
@@ -595,7 +586,8 @@ int ff_mss12_decode_rect(SliceContext *sc, ArithCoder *acoder,
return 0;
}
-av_cold int ff_mss12_decode_init(MSS12Context *c, int version)
+av_cold int ff_mss12_decode_init(MSS12Context *c, int version,
+ SliceContext* sc1, SliceContext *sc2)
{
AVCodecContext *avctx = c->avctx;
int i;
@@ -690,7 +682,13 @@ av_cold int ff_mss12_decode_init(MSS12Context *c, int version)
return AVERROR(ENOMEM);
}
- codec_init(c, version);
+ sc1->c = c;
+ slicecontext_init(sc1, version, c->full_model_syms);
+ if (c->slice_split) {
+ sc2->c = c;
+ slicecontext_init(sc2, version, c->full_model_syms);
+ }
+ c->corrupted = 1;
return 0;
}
diff --git a/libavcodec/mss12.h b/libavcodec/mss12.h
index 93d1f61..97cd25f 100644
--- a/libavcodec/mss12.h
+++ b/libavcodec/mss12.h
@@ -86,21 +86,18 @@ typedef struct MSS12Context {
int rgb_stride;
int free_colours;
int keyframe;
- Model intra_region, inter_region;
- Model pivot, edge_mode, split_mode;
- PixContext intra_pix_ctx, inter_pix_ctx;
int mvX, mvY;
int corrupted;
int slice_split;
int full_model_syms;
- SliceContext sc[2];
} MSS12Context;
int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
int x, int y, int width, int height);
void ff_mss12_model_update(Model *m, int val);
-void ff_mss12_codec_reset(MSS12Context *ctx);
-av_cold int ff_mss12_decode_init(MSS12Context *ctx, int version);
+void ff_mss12_slicecontext_reset(SliceContext *sc);
+av_cold int ff_mss12_decode_init(MSS12Context *c, int version,
+ SliceContext* sc1, SliceContext *sc2);
av_cold int ff_mss12_decode_end(MSS12Context *ctx);
#define ARITH_GET_BIT(VERSION) \
diff --git a/libavcodec/mss2.c b/libavcodec/mss2.c
index 2a0bf47..e4c854a 100644
--- a/libavcodec/mss2.c
+++ b/libavcodec/mss2.c
@@ -671,14 +671,18 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
buf += get_bits_count(&gb) >> 3;
buf_size -= get_bits_count(&gb) >> 3;
} else {
- if (keyframe)
- ff_mss12_codec_reset(c);
+ if (keyframe) {
+ c->corrupted = 0;
+ ff_mss12_slicecontext_reset(&ctx->sc[0]);
+ if (c->slice_split)
+ ff_mss12_slicecontext_reset(&ctx->sc[1]);
+ }
else if (c->corrupted)
return AVERROR_INVALIDDATA;
bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
arith2_init(&acoder, &gB);
c->keyframe = keyframe;
- if (c->corrupted = ff_mss12_decode_rect(&c->sc[0], &acoder, 0, 0,
+ if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[0], &acoder, 0, 0,
avctx->width,
ctx->split_position))
return AVERROR_INVALIDDATA;
@@ -690,7 +694,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
return AVERROR_INVALIDDATA;
bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
arith2_init(&acoder, &gB);
- if (c->corrupted = ff_mss12_decode_rect(&c->sc[1], &acoder, 0,
+ if (c->corrupted = ff_mss12_decode_rect(&ctx->sc[1], &acoder, 0,
ctx->split_position,
avctx->width,
avctx->height - ctx->split_position))
@@ -830,7 +834,7 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx)
int ret;
c->avctx = avctx;
avctx->coded_frame = &ctx->pic;
- if (ret = ff_mss12_decode_init(c, 1))
+ if (ret = ff_mss12_decode_init(c, 1, &ctx->sc[0], &ctx->sc[1]))
return ret;
c->pal_stride = c->mask_stride;
c->pal_pic = av_malloc(c->pal_stride * avctx->height);
More information about the ffmpeg-cvslog
mailing list