mss12: move SliceContexts out of the common context into the codec contexts
Signed-off-by: Kostya Shishkov <kostya.shishkov@gmail.com>
This commit is contained in:
		
							parent
							
								
									eb239a577f
								
							
						
					
					
						commit
						a97ee41bee
					
				@ -30,7 +30,7 @@
 | 
				
			|||||||
typedef struct MSS1Context {
 | 
					typedef struct MSS1Context {
 | 
				
			||||||
    MSS12Context   ctx;
 | 
					    MSS12Context   ctx;
 | 
				
			||||||
    AVFrame        pic;
 | 
					    AVFrame        pic;
 | 
				
			||||||
    SliceContext   sc[2];
 | 
					    SliceContext   sc;
 | 
				
			||||||
} MSS1Context;
 | 
					} MSS1Context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void arith_normalise(ArithCoder *c)
 | 
					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->pal_stride = -ctx->pic.linesize[0];
 | 
				
			||||||
    c->keyframe   = !arith_get_bit(&acoder);
 | 
					    c->keyframe   = !arith_get_bit(&acoder);
 | 
				
			||||||
    if (c->keyframe) {
 | 
					    if (c->keyframe) {
 | 
				
			||||||
        ff_mss12_codec_reset(c);
 | 
					        c->corrupted = 0;
 | 
				
			||||||
 | 
					        ff_mss12_slicecontext_reset(&ctx->sc);
 | 
				
			||||||
        pal_changed        = decode_pal(c, &acoder);
 | 
					        pal_changed        = decode_pal(c, &acoder);
 | 
				
			||||||
        ctx->pic.key_frame = 1;
 | 
					        ctx->pic.key_frame = 1;
 | 
				
			||||||
        ctx->pic.pict_type = AV_PICTURE_TYPE_I;
 | 
					        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.key_frame = 0;
 | 
				
			||||||
        ctx->pic.pict_type = AV_PICTURE_TYPE_P;
 | 
					        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);
 | 
					                                        avctx->width, avctx->height);
 | 
				
			||||||
    if (c->corrupted)
 | 
					    if (c->corrupted)
 | 
				
			||||||
        return AVERROR_INVALIDDATA;
 | 
					        return AVERROR_INVALIDDATA;
 | 
				
			||||||
@ -194,7 +195,7 @@ static av_cold int mss1_decode_init(AVCodecContext *avctx)
 | 
				
			|||||||
    c->ctx.avctx       = avctx;
 | 
					    c->ctx.avctx       = avctx;
 | 
				
			||||||
    avctx->coded_frame = &c->pic;
 | 
					    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;
 | 
					    avctx->pix_fmt = PIX_FMT_PAL8;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -435,39 +435,30 @@ static int decode_region_masked(MSS12Context const *c, ArithCoder *acoder,
 | 
				
			|||||||
    return 0;
 | 
					    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;
 | 
					    model_init(&sc->intra_region, 2, THRESH_ADAPTIVE);
 | 
				
			||||||
    for (i = 0; i < (c->slice_split ? 2 : 1); i++) {
 | 
					    model_init(&sc->inter_region, 2, THRESH_ADAPTIVE);
 | 
				
			||||||
        c->sc[i].c = c;
 | 
					    model_init(&sc->split_mode,   3, THRESH_HIGH);
 | 
				
			||||||
        model_init(&c->sc[i].intra_region, 2, THRESH_ADAPTIVE);
 | 
					    model_init(&sc->edge_mode,    2, THRESH_HIGH);
 | 
				
			||||||
        model_init(&c->sc[i].inter_region, 2, THRESH_ADAPTIVE);
 | 
					    model_init(&sc->pivot,        3, THRESH_LOW);
 | 
				
			||||||
        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(&sc->intra_pix_ctx, 8, full_model_syms, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        pixctx_init(&c->sc[i].inter_pix_ctx, version ? 3 : 2,
 | 
					    pixctx_init(&sc->inter_pix_ctx, version ? 3 : 2,
 | 
				
			||||||
                    c->full_model_syms, version ? 1 : 0);
 | 
					                full_model_syms, version ? 1 : 0);
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    c->corrupted = 1;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void ff_mss12_codec_reset(MSS12Context *c)
 | 
					void ff_mss12_slicecontext_reset(SliceContext *sc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int i;
 | 
					    model_reset(&sc->intra_region);
 | 
				
			||||||
    for (i = 0; i < (c->slice_split ? 2 : 1); i++) {
 | 
					    model_reset(&sc->inter_region);
 | 
				
			||||||
        model_reset(&c->sc[i].intra_region);
 | 
					    model_reset(&sc->split_mode);
 | 
				
			||||||
        model_reset(&c->sc[i].inter_region);
 | 
					    model_reset(&sc->edge_mode);
 | 
				
			||||||
        model_reset(&c->sc[i].split_mode);
 | 
					    model_reset(&sc->pivot);
 | 
				
			||||||
        model_reset(&c->sc[i].edge_mode);
 | 
					    pixctx_reset(&sc->intra_pix_ctx);
 | 
				
			||||||
        model_reset(&c->sc[i].pivot);
 | 
					    pixctx_reset(&sc->inter_pix_ctx);
 | 
				
			||||||
        pixctx_reset(&c->sc[i].intra_pix_ctx);
 | 
					 | 
				
			||||||
        pixctx_reset(&c->sc[i].inter_pix_ctx);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    c->corrupted = 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int decode_pivot(SliceContext *sc, ArithCoder *acoder, int base)
 | 
					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;
 | 
					    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;
 | 
					    AVCodecContext *avctx = c->avctx;
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
@ -690,7 +682,13 @@ av_cold int ff_mss12_decode_init(MSS12Context *c, int version)
 | 
				
			|||||||
        return AVERROR(ENOMEM);
 | 
					        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;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -86,21 +86,18 @@ typedef struct MSS12Context {
 | 
				
			|||||||
    int            rgb_stride;
 | 
					    int            rgb_stride;
 | 
				
			||||||
    int            free_colours;
 | 
					    int            free_colours;
 | 
				
			||||||
    int            keyframe;
 | 
					    int            keyframe;
 | 
				
			||||||
    Model          intra_region, inter_region;
 | 
					 | 
				
			||||||
    Model          pivot, edge_mode, split_mode;
 | 
					 | 
				
			||||||
    PixContext     intra_pix_ctx, inter_pix_ctx;
 | 
					 | 
				
			||||||
    int            mvX, mvY;
 | 
					    int            mvX, mvY;
 | 
				
			||||||
    int            corrupted;
 | 
					    int            corrupted;
 | 
				
			||||||
    int            slice_split;
 | 
					    int            slice_split;
 | 
				
			||||||
    int            full_model_syms;
 | 
					    int            full_model_syms;
 | 
				
			||||||
    SliceContext   sc[2];
 | 
					 | 
				
			||||||
} MSS12Context;
 | 
					} MSS12Context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
 | 
					int ff_mss12_decode_rect(SliceContext *ctx, ArithCoder *acoder,
 | 
				
			||||||
                         int x, int y, int width, int height);
 | 
					                         int x, int y, int width, int height);
 | 
				
			||||||
void ff_mss12_model_update(Model *m, int val);
 | 
					void ff_mss12_model_update(Model *m, int val);
 | 
				
			||||||
void ff_mss12_codec_reset(MSS12Context *ctx);
 | 
					void ff_mss12_slicecontext_reset(SliceContext *sc);
 | 
				
			||||||
av_cold int ff_mss12_decode_init(MSS12Context *ctx, int version);
 | 
					av_cold int ff_mss12_decode_init(MSS12Context *c, int version,
 | 
				
			||||||
 | 
					                                 SliceContext* sc1, SliceContext *sc2);
 | 
				
			||||||
av_cold int ff_mss12_decode_end(MSS12Context *ctx);
 | 
					av_cold int ff_mss12_decode_end(MSS12Context *ctx);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ARITH_GET_BIT(VERSION)                                          \
 | 
					#define ARITH_GET_BIT(VERSION)                                          \
 | 
				
			||||||
 | 
				
			|||||||
@ -671,14 +671,18 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 | 
				
			|||||||
        buf      += get_bits_count(&gb) >> 3;
 | 
					        buf      += get_bits_count(&gb) >> 3;
 | 
				
			||||||
        buf_size -= get_bits_count(&gb) >> 3;
 | 
					        buf_size -= get_bits_count(&gb) >> 3;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        if (keyframe)
 | 
					        if (keyframe) {
 | 
				
			||||||
            ff_mss12_codec_reset(c);
 | 
					            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)
 | 
					        else if (c->corrupted)
 | 
				
			||||||
            return AVERROR_INVALIDDATA;
 | 
					            return AVERROR_INVALIDDATA;
 | 
				
			||||||
        bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
 | 
					        bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
 | 
				
			||||||
        arith2_init(&acoder, &gB);
 | 
					        arith2_init(&acoder, &gB);
 | 
				
			||||||
        c->keyframe = keyframe;
 | 
					        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,
 | 
					                                                avctx->width,
 | 
				
			||||||
                                                ctx->split_position))
 | 
					                                                ctx->split_position))
 | 
				
			||||||
            return AVERROR_INVALIDDATA;
 | 
					            return AVERROR_INVALIDDATA;
 | 
				
			||||||
@ -690,7 +694,7 @@ static int mss2_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
 | 
				
			|||||||
                return AVERROR_INVALIDDATA;
 | 
					                return AVERROR_INVALIDDATA;
 | 
				
			||||||
            bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
 | 
					            bytestream2_init(&gB, buf, buf_size + ARITH2_PADDING);
 | 
				
			||||||
            arith2_init(&acoder, &gB);
 | 
					            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,
 | 
					                                                    ctx->split_position,
 | 
				
			||||||
                                                    avctx->width,
 | 
					                                                    avctx->width,
 | 
				
			||||||
                                                    avctx->height - ctx->split_position))
 | 
					                                                    avctx->height - ctx->split_position))
 | 
				
			||||||
@ -830,7 +834,7 @@ static av_cold int mss2_decode_init(AVCodecContext *avctx)
 | 
				
			|||||||
    int ret;
 | 
					    int ret;
 | 
				
			||||||
    c->avctx = avctx;
 | 
					    c->avctx = avctx;
 | 
				
			||||||
    avctx->coded_frame = &ctx->pic;
 | 
					    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;
 | 
					        return ret;
 | 
				
			||||||
    c->pal_stride   = c->mask_stride;
 | 
					    c->pal_stride   = c->mask_stride;
 | 
				
			||||||
    c->pal_pic      = av_malloc(c->pal_stride * avctx->height);
 | 
					    c->pal_pic      = av_malloc(c->pal_stride * avctx->height);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user