lavc/ffv1dec: move slice_damaged to per-slice context

release/7.1
Anton Khirnov 6 months ago
parent f2aeba56c4
commit 2b21cdff6e
  1. 2
      libavcodec/ffv1.h
  2. 18
      libavcodec/ffv1dec.c

@ -91,6 +91,7 @@ typedef struct FFV1SliceContext {
// decoder-only // decoder-only
struct { struct {
int slice_reset_contexts; int slice_reset_contexts;
int slice_damaged;
}; };
// encoder-only // encoder-only
@ -131,7 +132,6 @@ typedef struct FFV1Context {
int ec; int ec;
int intra; int intra;
int slice_damaged;
int key_frame_ok; int key_frame_ok;
int context_model; int context_model;

@ -269,11 +269,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
ff_progress_frame_await(&f->last_picture, si); ff_progress_frame_await(&f->last_picture, si);
if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) { if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
FFV1Context *fssrc = f->fsrc->slice_context[si];
const FFV1SliceContext *scsrc = &f->fsrc->slices[si]; const FFV1SliceContext *scsrc = &f->fsrc->slices[si];
if (!(p->flags & AV_FRAME_FLAG_KEY)) if (!(p->flags & AV_FRAME_FLAG_KEY))
fs->slice_damaged |= fssrc->slice_damaged; sc->slice_damaged |= scsrc->slice_damaged;
for (int i = 0; i < f->plane_count; i++) { for (int i = 0; i < f->plane_count; i++) {
const PlaneContext *psrc = &scsrc->plane[i]; const PlaneContext *psrc = &scsrc->plane[i];
@ -303,7 +302,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
if (decode_slice_header(f, fs, sc, p) < 0) { if (decode_slice_header(f, fs, sc, p) < 0) {
sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0; sc->slice_x = sc->slice_y = sc->slice_height = sc->slice_width = 0;
fs->slice_damaged = 1; sc->slice_damaged = 1;
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
} }
@ -311,7 +310,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
return ret; return ret;
if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) { if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
ff_ffv1_clear_slice_state(f, sc); ff_ffv1_clear_slice_state(f, sc);
} else if (fs->slice_damaged) { } else if (sc->slice_damaged) {
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
@ -365,7 +364,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec; v = sc->c.bytestream_end - sc->c.bytestream - 2 - 5*f->ec;
if (v) { if (v) {
av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v); av_log(f->avctx, AV_LOG_ERROR, "bytestream end mismatching by %d\n", v);
fs->slice_damaged = 1; sc->slice_damaged = 1;
} }
} }
@ -794,7 +793,7 @@ static int read_header(FFV1Context *f)
FFV1SliceContext *sc = &f->slices[j]; FFV1SliceContext *sc = &f->slices[j];
fs->packed_at_lsb = f->packed_at_lsb; fs->packed_at_lsb = f->packed_at_lsb;
fs->slice_damaged = 0; sc->slice_damaged = 0;
if (f->version == 2) { if (f->version == 2) {
int sx = get_symbol(c, state, 0); int sx = get_symbol(c, state, 0);
@ -966,7 +965,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
} else { } else {
av_log(f->avctx, AV_LOG_ERROR, "\n"); av_log(f->avctx, AV_LOG_ERROR, "\n");
} }
fs->slice_damaged = 1; sc->slice_damaged = 1;
} }
if (avctx->debug & FF_DEBUG_PICT_INFO) { if (avctx->debug & FF_DEBUG_PICT_INFO) {
av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4)); av_log(avctx, AV_LOG_DEBUG, "slice %d, CRC: 0x%08"PRIX32"\n", i, AV_RB32(buf_p + v - 4));
@ -990,9 +989,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame *rframe,
sizeof(void*)); sizeof(void*));
for (int i = f->slice_count - 1; i >= 0; i--) { for (int i = f->slice_count - 1; i >= 0; i--) {
FFV1Context *fs = f->slice_context[i];
FFV1SliceContext *sc = &f->slices[i]; FFV1SliceContext *sc = &f->slices[i];
if (fs->slice_damaged && f->last_picture.f) { if (sc->slice_damaged && f->last_picture.f) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt); const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(avctx->pix_fmt);
const uint8_t *src[4]; const uint8_t *src[4];
uint8_t *dst[4]; uint8_t *dst[4];
@ -1045,7 +1043,6 @@ static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
fsdst->ec = fsrc->ec; fsdst->ec = fsrc->ec;
fsdst->intra = fsrc->intra; fsdst->intra = fsrc->intra;
fsdst->slice_damaged = fssrc->slice_damaged;
fsdst->key_frame_ok = fsrc->key_frame_ok; fsdst->key_frame_ok = fsrc->key_frame_ok;
fsdst->packed_at_lsb = fsrc->packed_at_lsb; fsdst->packed_at_lsb = fsrc->packed_at_lsb;
@ -1078,6 +1075,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
const FFV1SliceContext *sc0 = &fsrc->slices[i]; const FFV1SliceContext *sc0 = &fsrc->slices[i];
copy_fields(fsdst, fssrc, fsrc); copy_fields(fsdst, fssrc, fsrc);
sc->slice_damaged = sc0->slice_damaged;
if (fsrc->version < 3) { if (fsrc->version < 3) {
sc->slice_x = sc0->slice_x; sc->slice_x = sc0->slice_x;

Loading…
Cancel
Save