[FFmpeg-cvslog] lavc/ffv1: change FFV1SliceContext.plane into a RefStruct object

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jul 11 
11:08:55 2024 +0200| [bcf08c11710cab5db8eb3d0774e1a93e322fb821] | committer: 
Anton Khirnov

lavc/ffv1: change FFV1SliceContext.plane into a RefStruct object

Frame threading in the FFV1 decoder works in a very unusual way - the
state that needs to be propagated from the previous frame is not decoded
pixels(¹), but each slice's entropy coder state after decoding the slice.

For that purpose, the decoder's update_thread_context() callback stores
a pointer to the previous frame thread's private data. Then, when
decoding each slice, the frame thread uses the standard progress
mechanism to wait for the corresponding slice in the previous frame to
be completed, then copies the entropy coder state from the
previously-stored pointer.

This approach is highly dubious, as update_thread_context() should be
the only point where frame-thread contexts come into direct contact.
There are no guarantees that the stored pointer will be valid at all, or
will contain any particular data after update_thread_context() finishes.

More specifically, this code can break due to the fact that keyframes
reset entropy coder state and thus do not need to wait for the previous
frame. As an example, consider a decoder process with 2 frame threads -
thread 0 with its context 0, and thread 1 with context 1 - decoding a
previous frame P, current frame F, followed by a keyframe K. Then
consider concurrent execution consistent with the following sequence of
events:
* thread 0 starts decoding P
* thread 0 reads P's slice header, then calls
  ff_thread_finish_setup() allowing next frame thread to start
* main thread calls update_thread_context() to transfer state from
  context 0 to context 1; context 1 stores a pointer to context 0's private
  data
* thread 1 starts decoding F
* thread 1 reads F's slice header, then calls
  ff_thread_finish_setup() allowing the next frame thread to start
  decoding
* thread 0 finishes decoding P
* thread 0 starts decoding K; since K is a keyframe, it does not
  wait for F and reallocates the arrays holding entropy coder state
* thread 0 finishes decoding K
* thread 1 reads entropy coder state from its stored pointer to context
  0, however it finds state from K rather than from P

This execution is currently prevented by special-casing FFV1 in the
generic frame threading code, however that is supremely ugly. It also
involves unnecessary copies of the state arrays, when in fact they can
only be used by one thread at a time.

This commit addresses these deficiencies by changing the array of
PlaneContext (each of which contains the allocated state arrays)
embedded in FFV1SliceContext into a RefStruct object. This object can
then be propagated across frame threads in standard manner. Since the
code structure guarantees only one thread accesses it at a time, no
copies are necessary. It is also re-created for keyframes, solving the
above issue cleanly.

Special-casing of FFV1 in the generic frame threading code will be
removed in a later commit.

(¹) except in the case of a damaged slice, when previous frame's pixels
are used directly

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bcf08c11710cab5db8eb3d0774e1a93e322fb821
---

 libavcodec/ffv1.c| 30 --
 libavcodec/ffv1.h|  4 +++-
 libavcodec/ffv1dec.c | 33 +
 3 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 07cf5564cc..9c219b5ddb 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -31,6 +31,7 @@
 
 #include "avcodec.h"
 #include "ffv1.h"
+#include "refstruct.h"
 
 av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 {
@@ -52,6 +53,24 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 return 0;
 }
 
+static void planes_free(FFRefStructOpaque opaque, void *obj)
+{
+PlaneContext *planes = obj;
+
+for (int i = 0; i < MAX_PLANES; i++) {
+PlaneContext *p = [i];
+
+av_freep(>state);
+av_freep(>vlc_state);
+}
+}
+
+PlaneContext* ff_ffv1_planes_alloc(void)
+{
+return ff_refstruct_alloc_ext(sizeof(PlaneContext) * MAX_PLANES,
+  0, NULL, planes_free);
+}
+
 av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
  FFV1SliceContext *sc)
 {
@@ -132,6 +151,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
   sizeof(*sc->sample_buffer32));
 if (!sc->sample_buffer || !sc->sample_buffer32)
 return AVERROR(ENOMEM);
+
+sc->plane = ff_ffv1_planes_alloc();
+if (!sc->plane)
+return AVERROR(ENOMEM);
 }
 
 return 0;
@@ -188,12 +211,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(>sample_buffer);
 av_freep(>sample_buffer32);
 
-for (i = 0; i &

[FFmpeg-cvslog] lavc/ffv1dec: move slice_damaged to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
17:38:24 2024 +0200| [2b21cdff6ebf8e65b0ff08a6e591a13236c00e37] | committer: 
Anton Khirnov

lavc/ffv1dec: move slice_damaged to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2b21cdff6ebf8e65b0ff08a6e591a13236c00e37
---

 libavcodec/ffv1.h|  2 +-
 libavcodec/ffv1dec.c | 18 --
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index cef61f38ec..c4803654f2 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -91,6 +91,7 @@ typedef struct FFV1SliceContext {
 // decoder-only
 struct {
 int slice_reset_contexts;
+int slice_damaged;
 };
 
 // encoder-only
@@ -131,7 +132,6 @@ typedef struct FFV1Context {
 
 int ec;
 int intra;
-int slice_damaged;
 int key_frame_ok;
 int context_model;
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index ddcbe1583e..3d529ff4e9 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -269,11 +269,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
 ff_progress_frame_await(>last_picture, si);
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
-FFV1Context *fssrc = f->fsrc->slice_context[si];
 const FFV1SliceContext *scsrc = >fsrc->slices[si];
 
 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++) {
 const PlaneContext *psrc = >plane[i];
@@ -303,7 +302,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 return AVERROR(ENOMEM);
 if (decode_slice_header(f, fs, sc, p) < 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;
 }
 }
@@ -311,7 +310,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 return ret;
 if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
-} else if (fs->slice_damaged) {
+} else if (sc->slice_damaged) {
 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;
 if (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 = >slices[j];
 fs->packed_at_lsb = f->packed_at_lsb;
 
-fs->slice_damaged = 0;
+sc->slice_damaged = 0;
 
 if (f->version == 2) {
 int sx = get_symbol(c, state, 0);
@@ -966,7 +965,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 } else {
 av_log(f->avctx, AV_LOG_ERROR, "\n");
 }
-fs->slice_damaged = 1;
+sc->slice_damaged = 1;
 }
 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));
@@ -990,9 +989,8 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
sizeof(void*));
 
 for (int i = f->slice_count - 1; i >= 0; i--) {
-FFV1Context *fs = f->slice_context[i];
 FFV1SliceContext *sc = >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 uint8_t *src[4];
 uint8_t *dst[4];
@@ -1045,7 +1043,6 @@ static void copy_fields(FFV1Context *fsdst, const 
FFV1Context *fssrc,
 
 fsdst->ec  = fsrc->ec;
 fsdst->intra   = fsrc->intra;
-fsdst->slice_damaged   = fssrc->slice_damaged;
 fsdst->key_frame_ok= fsrc->key_frame_ok;
 
 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 = >slices[i];
 
 copy_fields(fsdst, fssrc, fsrc);
+sc->slice_damaged = sc0->slice_damaged;
 
 if (fsrc->version < 3) {
 sc->slice_x = sc0->slice_x;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: inline copy_fields() into update_thread_context()

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
20:18:24 2024 +0200| [c335218a818484071718576722dd654d3f02c558] | committer: 
Anton Khirnov

lavc/ffv1dec: inline copy_fields() into update_thread_context()

It is now only called from a single place, so there is no point in it
being a separate function.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c335218a818484071718576722dd654d3f02c558
---

 libavcodec/ffv1dec.c | 38 --
 1 file changed, 16 insertions(+), 22 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 1933efbfbc..b2c7503ad8 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1022,27 +1022,6 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 }
 
 #if HAVE_THREADS
-static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
-const FFV1Context *fsrc)
-{
-fsdst->version = fsrc->version;
-fsdst->micro_version   = fsrc->micro_version;
-fsdst->chroma_planes   = fsrc->chroma_planes;
-fsdst->chroma_h_shift  = fsrc->chroma_h_shift;
-fsdst->chroma_v_shift  = fsrc->chroma_v_shift;
-fsdst->transparency= fsrc->transparency;
-fsdst->plane_count = fsrc->plane_count;
-fsdst->ac  = fsrc->ac;
-fsdst->colorspace  = fsrc->colorspace;
-
-fsdst->ec  = fsrc->ec;
-fsdst->intra   = fsrc->intra;
-fsdst->key_frame_ok= fsrc->key_frame_ok;
-
-fsdst->packed_at_lsb   = fsrc->packed_at_lsb;
-fsdst->slice_count = fsrc->slice_count;
-}
-
 static int update_thread_context(AVCodecContext *dst, const AVCodecContext 
*src)
 {
 FFV1Context *fsrc = src->priv_data;
@@ -1051,7 +1030,22 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 if (dst == src)
 return 0;
 
-copy_fields(fdst, fsrc, fsrc);
+fdst->version = fsrc->version;
+fdst->micro_version   = fsrc->micro_version;
+fdst->chroma_planes   = fsrc->chroma_planes;
+fdst->chroma_h_shift  = fsrc->chroma_h_shift;
+fdst->chroma_v_shift  = fsrc->chroma_v_shift;
+fdst->transparency= fsrc->transparency;
+fdst->plane_count = fsrc->plane_count;
+fdst->ac  = fsrc->ac;
+fdst->colorspace  = fsrc->colorspace;
+
+fdst->ec  = fsrc->ec;
+fdst->intra   = fsrc->intra;
+fdst->key_frame_ok= fsrc->key_frame_ok;
+
+fdst->packed_at_lsb   = fsrc->packed_at_lsb;
+fdst->slice_count = fsrc->slice_count;
 fdst->use32bit = fsrc->use32bit;
 memcpy(fdst->state_transition, fsrc->state_transition,
sizeof(fdst->state_transition));

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: move slice_reset_contexts to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
17:38:24 2024 +0200| [f2aeba56c45ad83b2a776effccfbb622525a3ca8] | committer: 
Anton Khirnov

lavc/ffv1dec: move slice_reset_contexts to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f2aeba56c45ad83b2a776effccfbb622525a3ca8
---

 libavcodec/ffv1.h| 16 +---
 libavcodec/ffv1dec.c |  4 ++--
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ae81940073..cef61f38ec 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -86,8 +86,19 @@ typedef struct FFV1SliceContext {
 RangeCoder c;
 
 int ac_byte_count;   ///< number of bytes used for AC 
coding
-uint64_t rc_stat[256][2];
-uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
+
+union {
+// decoder-only
+struct {
+int slice_reset_contexts;
+};
+
+// encoder-only
+struct {
+uint64_t rc_stat[256][2];
+uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
+};
+};
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
@@ -135,7 +146,6 @@ typedef struct FFV1Context {
 int max_slice_count;
 int num_v_slices;
 int num_h_slices;
-int slice_reset_contexts;
 
 FFV1SliceContext *slices;
 } FFV1Context;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index d171660c85..ddcbe1583e 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -239,7 +239,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 }
 
 if (fs->version > 3) {
-fs->slice_reset_contexts = get_rac(c, state);
+sc->slice_reset_contexts = get_rac(c, state);
 sc->slice_coding_mode = get_symbol(c, state, 0);
 if (sc->slice_coding_mode != 1) {
 sc->slice_rct_by_coef = get_symbol(c, state, 0);
@@ -309,7 +309,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
 return ret;
-if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
+if ((p->flags & AV_FRAME_FLAG_KEY) || sc->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
 } else if (fs->slice_damaged) {
 return AVERROR_INVALIDDATA;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: stop using per-slice FFV1Context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
17:25:54 2024 +0200| [d44812f7cf8994ccaf7ccf309c958876688dcf79] | committer: 
Anton Khirnov

lavc/ffv1dec: stop using per-slice FFV1Context

All remaining accesses to them are for fields that have the same value
in the main encoder context.

Drop now-unused FFV1Context.slice_contexts.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d44812f7cf8994ccaf7ccf309c958876688dcf79
---

 libavcodec/ffv1.c | 18 ---
 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1dec.c  | 54 ++-
 libavcodec/ffv1dec_template.c | 16 ++---
 4 files changed, 33 insertions(+), 56 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 4ef04f6b9b..07cf5564cc 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -102,7 +102,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 
 av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 {
-int i, max_slice_count = f->num_h_slices * f->num_v_slices;
+int max_slice_count = f->num_h_slices * f->num_v_slices;
 
 av_assert0(max_slice_count > 0);
 
@@ -112,7 +112,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 f->max_slice_count = max_slice_count;
 
-for (i = 0; i < max_slice_count;) {
+for (int i = 0; i < max_slice_count; i++) {
 FFV1SliceContext *sc = >slices[i];
 int sx  = i % f->num_h_slices;
 int sy  = i / f->num_h_slices;
@@ -120,22 +120,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 int sxe = f->avctx->width  * (sx + 1) / f->num_h_slices;
 int sys = f->avctx->height *  sy  / f->num_v_slices;
 int sye = f->avctx->height * (sy + 1) / f->num_v_slices;
-FFV1Context *fs = av_mallocz(sizeof(*fs));
-
-if (!fs)
-return AVERROR(ENOMEM);
-
-f->slice_context[i++] = fs;
-memcpy(fs, f, sizeof(*fs));
 
 sc->slice_width  = sxe - sxs;
 sc->slice_height = sye - sys;
 sc->slice_x  = sxs;
 sc->slice_y  = sys;
 
-sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sc->sample_buffer = av_malloc_array((f->width + 6), 3 * MAX_PLANES *
 sizeof(*sc->sample_buffer));
-sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sc->sample_buffer32 = av_malloc_array((f->width + 6), 3 * MAX_PLANES *
   sizeof(*sc->sample_buffer32));
 if (!sc->sample_buffer || !sc->sample_buffer32)
 return AVERROR(ENOMEM);
@@ -213,9 +206,6 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(>rc_stat2[j]);
 }
 
-for (i = 0; i < s->max_slice_count; i++)
-av_freep(>slice_context[i]);
-
 av_freep(>slices);
 
 return 0;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c4803654f2..9d79219921 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -141,7 +141,6 @@ typedef struct FFV1Context {
 int gob_count;
 int quant_table_count;
 
-struct FFV1Context *slice_context[MAX_SLICES];
 int slice_count;
 int max_slice_count;
 int num_v_slices;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 3d529ff4e9..1933efbfbc 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -116,8 +116,7 @@ static int is_input_end(RangeCoder *c, GetBitContext *gb, 
int ac)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *f,
-FFV1Context *s, FFV1SliceContext *sc,
+static int decode_plane(FFV1Context *f, FFV1SliceContext *sc,
 GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
@@ -141,23 +140,23 @@ static int decode_plane(FFV1Context *f,
 sample[1][-1] = sample[0][0];
 sample[0][w]  = sample[0][w - 1];
 
-if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8, ac);
+if (f->avctx->bits_per_raw_sample <= 8) {
+int ret = decode_line(f, sc, gb, w, sample, plane_index, 8, ac);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample, ac);
+int ret = decode_line(f, sc, gb, w, sample, plane_index, 
f->avctx->bits_per_raw_sample, ac);
 if (ret < 0)
 return ret;
-if (s-&

[FFmpeg-cvslog] lavc/ffv1enc: stop using per-slice FFV1Context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
17:25:54 2024 +0200| [84dda322020584e249840bc815591429c75fe5d0] | committer: 
Anton Khirnov

lavc/ffv1enc: stop using per-slice FFV1Context

All remaining accesses to them are for fields that have the same value
in the main encoder context.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=84dda322020584e249840bc815591429c75fe5d0
---

 libavcodec/ffv1enc.c  | 55 ---
 libavcodec/ffv1enc_template.c | 29 ---
 2 files changed, 41 insertions(+), 43 deletions(-)

diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index b861210462..23d757e5c6 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -269,14 +269,14 @@ static inline void put_vlc_symbol(PutBitContext *pb, 
VlcState *const state,
 #define RENAME(name) name ## 32
 #include "ffv1enc_template.c"
 
-static int encode_plane(FFV1Context *f,
-FFV1Context *s, FFV1SliceContext *sc,
+static int encode_plane(FFV1Context *f, FFV1SliceContext *sc,
 const uint8_t *src, int w, int h,
  int stride, int plane_index, int pixel_stride)
 {
 int x, y, i, ret;
 const int ac = f->ac;
-const int ring_size = s->context_model ? 3 : 2;
+const int pass1 = !!(f->avctx->flags & AV_CODEC_FLAG_PASS1);
+const int ring_size = f->context_model ? 3 : 2;
 int16_t *sample[3];
 sc->run_index = 0;
 
@@ -288,22 +288,22 @@ static int encode_plane(FFV1Context *f,
 
 sample[0][-1]= sample[1][0  ];
 sample[1][ w]= sample[1][w-1];
-if (s->bits_per_raw_sample <= 8) {
+if (f->bits_per_raw_sample <= 8) {
 for (x = 0; x < w; x++)
 sample[0][x] = src[x * pixel_stride + stride * y];
-if((ret = encode_line(f, s, sc, w, sample, plane_index, 8, ac)) < 
0)
+if((ret = encode_line(f, sc, f->avctx, w, sample, plane_index, 8, 
ac, pass1)) < 0)
 return ret;
 } else {
-if (s->packed_at_lsb) {
+if (f->packed_at_lsb) {
 for (x = 0; x < w; x++) {
 sample[0][x] = ((uint16_t*)(src + stride*y))[x];
 }
 } else {
 for (x = 0; x < w; x++) {
-sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - 
s->bits_per_raw_sample);
+sample[0][x] = ((uint16_t*)(src + stride*y))[x] >> (16 - 
f->bits_per_raw_sample);
 }
 }
-if((ret = encode_line(f, s, sc, w, sample, plane_index, 
s->bits_per_raw_sample, ac)) < 0)
+if((ret = encode_line(f, sc, f->avctx, w, sample, plane_index, 
f->bits_per_raw_sample, ac, pass1)) < 0)
 return ret;
 }
 }
@@ -909,8 +909,7 @@ slices_ok:
 return 0;
 }
 
-static void encode_slice_header(FFV1Context *f, FFV1Context *fs,
-FFV1SliceContext *sc)
+static void encode_slice_header(FFV1Context *f, FFV1SliceContext *sc)
 {
 RangeCoder *c = >c;
 uint8_t state[CONTEXT_SIZE];
@@ -943,7 +942,7 @@ static void encode_slice_header(FFV1Context *f, FFV1Context 
*fs,
 }
 }
 
-static void choose_rct_params(FFV1Context *fs, FFV1SliceContext *sc,
+static void choose_rct_params(const FFV1Context *f, FFV1SliceContext *sc,
   const uint8_t *src[3], const int stride[3], int 
w, int h)
 {
 #define NB_Y_COEFF 15
@@ -969,7 +968,7 @@ static void choose_rct_params(FFV1Context *fs, 
FFV1SliceContext *sc,
 int stat[NB_Y_COEFF] = {0};
 int x, y, i, p, best;
 int16_t *sample[3];
-int lbd = fs->bits_per_raw_sample <= 8;
+int lbd = f->bits_per_raw_sample <= 8;
 
 for (y = 0; y < h; y++) {
 int lastr=0, lastg=0, lastb=0;
@@ -1028,10 +1027,8 @@ static void choose_rct_params(FFV1Context *fs, 
FFV1SliceContext *sc,
 
 static int encode_slice(AVCodecContext *c, void *arg)
 {
-FFV1Context *fs  = *(void **)arg;
-FFV1Context *f   = fs->avctx->priv_data;
-const int si = (FFV1Context**)arg - f->slice_context;
-FFV1SliceContext *sc = >slices[si];
+FFV1SliceContext *sc = arg;
+FFV1Context *f   = c->priv_data;
 int width= sc->slice_width;
 int height   = sc->slice_height;
 int x= sc->slice_x;
@@ -1047,7 +1044,7 @@ static int encode_slice(AVCodecContext *c, void *arg)
 
 sc->slice_coding_mode = 0;
 if (f->version > 3) {
-choose_rct_params(fs, sc, planes, p->linesize, width, height);
+choose_rct_params(f, sc, planes, p->linesize, width, height);
 } else {
 sc->slice_rct_by_coef = 1;
 sc->slice_rct_ry_coef = 1;
@@ -1057,7 +1054,7 @@ retry:
 if (f->key_frame)
 ff_ffv1_clear_slice_state(f, sc);

[FFmpeg-cvslog] lavc/ffv1: move ac_byte_count to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
17:20:07 2024 +0200| [96e8af6c4d031313e42a5dfb5caf2bcab48bf976] | committer: 
Anton Khirnov

lavc/ffv1: move ac_byte_count to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=96e8af6c4d031313e42a5dfb5caf2bcab48bf976
---

 libavcodec/ffv1.h| 2 +-
 libavcodec/ffv1dec.c | 6 +++---
 libavcodec/ffv1enc.c | 9 -
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index bee7b75614..ae81940073 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -85,6 +85,7 @@ typedef struct FFV1SliceContext {
 PutBitContext pb;
 RangeCoder c;
 
+int ac_byte_count;   ///< number of bytes used for AC 
coding
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 } FFV1SliceContext;
@@ -109,7 +110,6 @@ typedef struct FFV1Context {
 const AVFrame *cur_enc_frame;
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
-int ac_byte_count;   ///< number of bytes used for AC 
coding
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 187359c9c6..d171660c85 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -323,10 +323,10 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->ac == AC_GOLOMB_RICE) {
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
 get_rac(>c, (uint8_t[]) { 129 });
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
+sc->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
 init_get_bits(,
-  sc->c.bytestream_start + fs->ac_byte_count,
-  (sc->c.bytestream_end - sc->c.bytestream_start - 
fs->ac_byte_count) * 8);
+  sc->c.bytestream_start + sc->ac_byte_count,
+  (sc->c.bytestream_end - sc->c.bytestream_start - 
sc->ac_byte_count) * 8);
 }
 
 av_assert1(width && height);
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index a17fdd35ec..b861210462 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1060,10 +1060,10 @@ retry:
 encode_slice_header(f, fs, sc);
 }
 if (f->ac == AC_GOLOMB_RICE) {
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(>c, f->version > 2) : 0;
+sc->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(>c, f->version > 2) : 0;
 init_put_bits(>pb,
-  sc->c.bytestream_start + fs->ac_byte_count,
-  sc->c.bytestream_end - sc->c.bytestream_start - 
fs->ac_byte_count);
+  sc->c.bytestream_start + sc->ac_byte_count,
+  sc->c.bytestream_end - sc->c.bytestream_start - 
sc->ac_byte_count);
 }
 
 if (f->colorspace == 0 && c->pix_fmt != AV_PIX_FMT_YA8) {
@@ -1212,7 +1212,6 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 
 buf_p = pkt->data;
 for (i = 0; i < f->slice_count; i++) {
-FFV1Context *fs = f->slice_context[i];
 FFV1SliceContext *sc = >slices[i];
 int bytes;
 
@@ -1220,7 +1219,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 bytes = ff_rac_terminate(>c, 1);
 } else {
 flush_put_bits(>pb); // FIXME: nicer padding
-bytes = fs->ac_byte_count + put_bytes_output(>pb);
+bytes = sc->ac_byte_count + put_bytes_output(>pb);
 }
 if (i > 0 || f->version > 2) {
 av_assert0(bytes < pkt->size / f->slice_count);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 10 
16:51:45 2024 +0200| [e7d0f44138a7b7303ccc760d28d608893dbf7641] | committer: 
Anton Khirnov

lavc/ffv1enc: store per-slice rc_stat(2?) in FFV1SliceContext

Instead of the per-slice FFV1Context, which will be removed in future
commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e7d0f44138a7b7303ccc760d28d608893dbf7641
---

 libavcodec/ffv1.c |  6 ++
 libavcodec/ffv1.h |  3 +++
 libavcodec/ffv1enc.c  | 20 ++--
 libavcodec/ffv1enc_template.c |  4 ++--
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 490baac233..4ef04f6b9b 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -127,7 +127,6 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 f->slice_context[i++] = fs;
 memcpy(fs, f, sizeof(*fs));
-memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
 sc->slice_width  = sxe - sxs;
 sc->slice_height = sye - sys;
@@ -208,9 +207,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 for (j = 0; j < s->quant_table_count; j++) {
 av_freep(>initial_states[j]);
 for (i = 0; i < s->max_slice_count; i++) {
-FFV1Context *sf = s->slice_context[i];
-if (sf)
-av_freep(>rc_stat2[j]);
+FFV1SliceContext *sc = >slices[i];
+av_freep(>rc_stat2[j]);
 }
 av_freep(>rc_stat2[j]);
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 01c35dc942..bee7b75614 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -84,6 +84,9 @@ typedef struct FFV1SliceContext {
 PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
 RangeCoder c;
+
+uint64_t rc_stat[256][2];
+uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 6790366149..a17fdd35ec 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -897,11 +897,11 @@ slices_ok:
 return AVERROR(ENOMEM);
 for (i = 0; i < s->quant_table_count; i++)
 for (j = 0; j < s->max_slice_count; j++) {
-FFV1Context *sf = s->slice_context[j];
-av_assert0(!sf->rc_stat2[i]);
-sf->rc_stat2[i] = av_mallocz(s->context_count[i] *
- sizeof(*sf->rc_stat2[i]));
-if (!sf->rc_stat2[i])
+FFV1SliceContext *sc = >slices[j];
+av_assert0(!sc->rc_stat2[i]);
+sc->rc_stat2[i] = av_mallocz(s->context_count[i] *
+ sizeof(*sc->rc_stat2[i]));
+if (!sc->rc_stat2[i])
 return AVERROR(ENOMEM);
 }
 }
@@ -1127,16 +1127,16 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 
 av_assert0(f->slice_count == f->max_slice_count);
 for (j = 0; j < f->slice_count; j++) {
-FFV1Context *fs = f->slice_context[j];
+const FFV1SliceContext *sc = >slices[j];
 for (i = 0; i < 256; i++) {
-f->rc_stat[i][0] += fs->rc_stat[i][0];
-f->rc_stat[i][1] += fs->rc_stat[i][1];
+f->rc_stat[i][0] += sc->rc_stat[i][0];
+f->rc_stat[i][1] += sc->rc_stat[i][1];
 }
 for (i = 0; i < f->quant_table_count; i++) {
 for (k = 0; k < f->context_count[i]; k++)
 for (m = 0; m < 32; m++) {
-f->rc_stat2[i][k][m][0] += 
fs->rc_stat2[i][k][m][0];
-f->rc_stat2[i][k][m][1] += 
fs->rc_stat2[i][k][m][1];
+f->rc_stat2[i][k][m][0] += 
sc->rc_stat2[i][k][m][0];
+f->rc_stat2[i][k][m][1] += 
sc->rc_stat2[i][k][m][1];
 }
 }
 }
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index 1339b2bd4c..24dcf2a68e 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -75,8 +75,8 @@ RENAME(encode_line)(FFV1Context *f,
 
 if (ac != AC_GOLOMB_RICE) {
 if (s->flags & AV_CODEC_FLAG_PASS1) {
-put_symbol_inline(c, p->state[context], diff, 1, s->rc_stat,
-  s->rc_stat2[p->quant_table_index][context]);
+put_symbol_inline(c, p->state[context], diff, 1, sc->rc_stat,
+  sc->rc_stat2[p->quant_table_index][context]);
 } else {
 put_symbol_inline(c, p->state[contex

[FFmpeg-cvslog] lavc/ffv1: move RangeCoder to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jul  9 
08:45:16 2024 +0200| [7b2bfba55db821dcb730624f34e9b62db35000ce] | committer: 
Anton Khirnov

lavc/ffv1: move RangeCoder to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7b2bfba55db821dcb730624f34e9b62db35000ce
---

 libavcodec/ffv1.c |  9 +++--
 libavcodec/ffv1.h |  5 ++-
 libavcodec/ffv1dec.c  | 72 +++--
 libavcodec/ffv1dec_template.c |  2 +-
 libavcodec/ffv1enc.c  | 82 ++-
 libavcodec/ffv1enc_template.c |  2 +-
 6 files changed, 87 insertions(+), 85 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 7bc4f1b135..490baac233 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -53,7 +53,7 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 }
 
 av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
- FFV1Context *fs, FFV1SliceContext *sc)
+ FFV1SliceContext *sc)
 {
 int j, i;
 
@@ -82,8 +82,8 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
 if (f->ac == AC_RANGE_CUSTOM_TAB) {
 //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];
+sc->c. one_state[  j] = f->state_transition[j];
+sc->c.zero_state[256 - j] = 256 - sc->c.one_state[j];
 }
 }
 
@@ -94,8 +94,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 {
 int i, ret;
 for (i = 0; i < f->max_slice_count; i++) {
-FFV1Context *fs = f->slice_context[i];
-if ((ret = ff_ffv1_init_slice_state(f, fs, >slices[i])) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, >slices[i])) < 0)
 return AVERROR(ENOMEM);
 }
 return 0;
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 68e59b300b..01c35dc942 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -83,12 +83,12 @@ typedef struct FFV1SliceContext {
 
 PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
+RangeCoder c;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
-RangeCoder c;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 int version;
@@ -138,8 +138,7 @@ typedef struct FFV1Context {
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
-int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs,
- FFV1SliceContext *sc);
+int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1SliceContext *sc);
 int ff_ffv1_init_slices_state(FFV1Context *f);
 int ff_ffv1_init_slice_contexts(FFV1Context *f);
 int ff_ffv1_allocate_initial_states(FFV1Context *f);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index c46edbf940..187359c9c6 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -168,7 +168,7 @@ static int decode_plane(FFV1Context *f,
 static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
FFV1SliceContext *sc, AVFrame *frame)
 {
-RangeCoder *c = >c;
+RangeCoder *c = >c;
 uint8_t state[CONTEXT_SIZE];
 unsigned ps, context_count;
 int sx, sy, sw, sh;
@@ -299,7 +299,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 sc->slice_rct_ry_coef = 1;
 
 if (f->version > 2) {
-if (ff_ffv1_init_slice_state(f, fs, sc) < 0)
+if (ff_ffv1_init_slice_state(f, sc) < 0)
 return AVERROR(ENOMEM);
 if (decode_slice_header(f, fs, sc, p) < 0) {
 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)
 return AVERROR_INVALIDDATA;
 }
 }
-if ((ret = ff_ffv1_init_slice_state(f, fs, sc)) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, sc)) < 0)
 return ret;
 if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, sc);
@@ -322,11 +322,11 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if (f->ac == AC_GOLOMB_RICE) {
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
-get_rac(>c, (uint8_t[]) { 129 });
-fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
+get_rac(>c, (uint8_t[]) { 129 });
+fs->ac_byte_count = f->version > 2 || (!x && !y) ? sc->c.bytestream - 
sc->c.bytestream_start - 1 : 0;
 init_get_bits(,
-  fs->c.bytestream_sta

[FFmpeg-cvslog] lavc/ffv1: move FFV1Context.plane to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
18:01:13 2024 +0200| [28769f6bc19ba10415405e63a06fe09f18d781b4] | committer: 
Anton Khirnov

lavc/ffv1: move FFV1Context.plane to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=28769f6bc19ba10415405e63a06fe09f18d781b4
---

 libavcodec/ffv1.c | 17 +++--
 libavcodec/ffv1.h |  7 ---
 libavcodec/ffv1dec.c  | 16 
 libavcodec/ffv1dec_template.c |  2 +-
 libavcodec/ffv1enc.c  | 29 -
 libavcodec/ffv1enc_template.c |  2 +-
 6 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 581e775ae2..7bc4f1b135 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -52,12 +52,13 @@ av_cold int ff_ffv1_common_init(AVCodecContext *avctx)
 return 0;
 }
 
-av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs)
+av_cold int ff_ffv1_init_slice_state(const FFV1Context *f,
+ FFV1Context *fs, FFV1SliceContext *sc)
 {
 int j, i;
 
 for (j = 0; j < f->plane_count; j++) {
-PlaneContext *const p = >plane[j];
+PlaneContext *const p = >plane[j];
 
 if (f->ac != AC_GOLOMB_RICE) {
 if (!p->state)
@@ -94,7 +95,7 @@ av_cold int ff_ffv1_init_slices_state(FFV1Context *f)
 int i, ret;
 for (i = 0; i < f->max_slice_count; i++) {
 FFV1Context *fs = f->slice_context[i];
-if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
+if ((ret = ff_ffv1_init_slice_state(f, fs, >slices[i])) < 0)
 return AVERROR(ENOMEM);
 }
 return 0;
@@ -160,12 +161,12 @@ int ff_ffv1_allocate_initial_states(FFV1Context *f)
 return 0;
 }
 
-void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs)
+void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc)
 {
 int i, j;
 
 for (i = 0; i < f->plane_count; i++) {
-PlaneContext *p = >plane[i];
+PlaneContext *p = >plane[i];
 
 if (f->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
@@ -191,17 +192,13 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 int i, j;
 
 for (j = 0; j < s->max_slice_count; j++) {
-FFV1Context *fs = s->slice_context[j];
 FFV1SliceContext *sc = >slices[j];
 
 av_freep(>sample_buffer);
 av_freep(>sample_buffer32);
 
-if (!fs)
-continue;
-
 for (i = 0; i < s->plane_count; i++) {
-PlaneContext *p = >plane[i];
+PlaneContext *p = >plane[i];
 
 av_freep(>state);
 av_freep(>vlc_state);
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index e466aedbbe..68e59b300b 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -81,6 +81,7 @@ typedef struct FFV1SliceContext {
 int slice_rct_by_coef;
 int slice_rct_ry_coef;
 
+PlaneContext plane[MAX_PLANES];
 PutBitContext pb;
 } FFV1SliceContext;
 
@@ -106,7 +107,6 @@ typedef struct FFV1Context {
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
 int ac_byte_count;   ///< number of bytes used for AC 
coding
-PlaneContext plane[MAX_PLANES];
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
@@ -138,11 +138,12 @@ typedef struct FFV1Context {
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
-int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs);
+int ff_ffv1_init_slice_state(const FFV1Context *f, FFV1Context *fs,
+ FFV1SliceContext *sc);
 int ff_ffv1_init_slices_state(FFV1Context *f);
 int ff_ffv1_init_slice_contexts(FFV1Context *f);
 int ff_ffv1_allocate_initial_states(FFV1Context *f);
-void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1Context *fs);
+void ff_ffv1_clear_slice_state(const FFV1Context *f, FFV1SliceContext *sc);
 int ff_ffv1_close(AVCodecContext *avctx);
 
 static av_always_inline int fold(int diff, int bits)
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 992b6596ab..c46edbf940 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -201,7 +201,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 return AVERROR_INVALIDDATA;
 
 for (unsigned i = 0; i < f->plane_count; i++) {
-PlaneContext * const p = >plane[i];
+PlaneContext * const p = >plane[i];
 int idx = get_symbol(c, state, 0);
 if (idx >= (unsigned)f->quant_table_count) {
 av_log(f->avctx, AV_LOG_ERROR, "quant_table_index out of range\n");
@@ -270,13 +270,14 @@ static int decode_slice(AVCodecContext *c, 

[FFmpeg-cvslog] lavc/ffv1: always use the main context values of ac

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
13:11:52 2024 +0200| [9b86ba5a9289160962bca61df5639dae21784fb2] | committer: 
Anton Khirnov

lavc/ffv1: always use the main context values of ac

It cannot change between slices.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9b86ba5a9289160962bca61df5639dae21784fb2
---

 libavcodec/ffv1.c |  6 +++---
 libavcodec/ffv1dec.c  | 19 +--
 libavcodec/ffv1dec_template.c | 14 --
 libavcodec/ffv1enc.c  | 11 ++-
 libavcodec/ffv1enc_template.c | 12 +++-
 5 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 06a77c3a26..581e775ae2 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -59,7 +59,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (j = 0; j < f->plane_count; j++) {
 PlaneContext *const p = >plane[j];
 
-if (fs->ac != AC_GOLOMB_RICE) {
+if (f->ac != AC_GOLOMB_RICE) {
 if (!p->state)
 p->state = av_malloc_array(p->context_count, CONTEXT_SIZE *
  sizeof(uint8_t));
@@ -78,7 +78,7 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 }
 }
 
-if (fs->ac == AC_RANGE_CUSTOM_TAB) {
+if (f->ac == AC_RANGE_CUSTOM_TAB) {
 //FIXME only redo if state_transition changed
 for (j = 1; j < 256; j++) {
 fs->c. one_state[  j] = f->state_transition[j];
@@ -167,7 +167,7 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (i = 0; i < f->plane_count; i++) {
 PlaneContext *p = >plane[i];
 
-if (fs->ac != AC_GOLOMB_RICE) {
+if (f->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
 memcpy(p->state, f->initial_states[p->quant_table_index],
CONTEXT_SIZE * p->context_count);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 8464697fd3..992b6596ab 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -94,10 +94,9 @@ static inline int get_vlc_symbol(GetBitContext *gb, VlcState 
*const state,
 return ret;
 }
 
-static int is_input_end(FFV1Context *s, GetBitContext *gb)
+static int is_input_end(RangeCoder *c, GetBitContext *gb, int ac)
 {
-if (s->ac != AC_GOLOMB_RICE) {
-RangeCoder *const c = >c;
+if (ac != AC_GOLOMB_RICE) {
 if (c->overread > MAX_OVERREAD)
 return AVERROR_INVALIDDATA;
 } else {
@@ -123,6 +122,7 @@ static int decode_plane(FFV1Context *f,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
 {
+const int ac = f->ac;
 int x, y;
 int16_t *sample[2];
 sample[0] = sc->sample_buffer + 3;
@@ -142,13 +142,13 @@ static int decode_plane(FFV1Context *f,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8, ac);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample, ac);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
@@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 av_assert0 (   (unsigned)sc->slice_x + (uint64_t)sc->slice_width  <= 
f->width
 && (unsigned)sc->slice_y + (uint64_t)sc->slice_height <= 
f->height);
 
-if (fs->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
+if (f->ac == AC_GOLOMB_RICE && sc->slice_width >= (1<<23))
 return AVERROR_INVALIDDATA;
 
 for (unsigned i = 0; i < f->plane_count; i++) {
@@ -284,7 +284,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 pdst->state = NULL;
 pdst->vlc_state = NULL;
 
-if (fssrc->ac) {
+if (f->ac) {
 pdst->state = av_malloc_array(CONTEXT_SIZE,  
psrc->context_count);
 memcpy(pdst->state, psrc->state, CONTEXT_SIZE * 
psrc->context_count);
 } else {
@@ -319,7 +319,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 x  = sc->slice_x;
 y  = sc->slice_y;
 
-if (fs->ac == AC_GOLOMB

[FFmpeg-cvslog] lavc/ffv1: move FFV1Context.slice_{coding_mode,rct_.y_coef} to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
16:11:25 2024 +0200| [a57c88d67b921a086d8efc3810e5b749661120d1] | committer: 
Anton Khirnov

lavc/ffv1: move FFV1Context.slice_{coding_mode,rct_.y_coef} to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a57c88d67b921a086d8efc3810e5b749661120d1
---

 libavcodec/ffv1.h |  6 +++---
 libavcodec/ffv1dec.c  | 14 +++---
 libavcodec/ffv1dec_template.c | 10 +-
 libavcodec/ffv1enc.c  | 26 +-
 libavcodec/ffv1enc_template.c | 10 +-
 5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index a3f3b30b49..e466aedbbe 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -77,6 +77,9 @@ typedef struct FFV1SliceContext {
 int slice_y;
 
 int run_index;
+int slice_coding_mode;
+int slice_rct_by_coef;
+int slice_rct_ry_coef;
 
 PutBitContext pb;
 } FFV1SliceContext;
@@ -130,9 +133,6 @@ typedef struct FFV1Context {
 int num_v_slices;
 int num_h_slices;
 int slice_reset_contexts;
-int slice_coding_mode;
-int slice_rct_by_coef;
-int slice_rct_ry_coef;
 
 FFV1SliceContext *slices;
 } FFV1Context;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 6d3db25279..8464697fd3 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -240,11 +240,11 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 
 if (fs->version > 3) {
 fs->slice_reset_contexts = get_rac(c, state);
-fs->slice_coding_mode = get_symbol(c, state, 0);
-if (fs->slice_coding_mode != 1) {
-fs->slice_rct_by_coef = get_symbol(c, state, 0);
-fs->slice_rct_ry_coef = get_symbol(c, state, 0);
-if ((uint64_t)fs->slice_rct_by_coef + 
(uint64_t)fs->slice_rct_ry_coef > 4) {
+sc->slice_coding_mode = get_symbol(c, state, 0);
+if (sc->slice_coding_mode != 1) {
+sc->slice_rct_by_coef = get_symbol(c, state, 0);
+sc->slice_rct_ry_coef = get_symbol(c, state, 0);
+if ((uint64_t)sc->slice_rct_by_coef + 
(uint64_t)sc->slice_rct_ry_coef > 4) {
 av_log(f->avctx, AV_LOG_ERROR, "slice_rct_y_coef out of 
range\n");
 return AVERROR_INVALIDDATA;
 }
@@ -294,8 +294,8 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 }
 
-fs->slice_rct_by_coef = 1;
-fs->slice_rct_ry_coef = 1;
+sc->slice_rct_by_coef = 1;
+sc->slice_rct_ry_coef = 1;
 
 if (f->version > 2) {
 if (ff_ffv1_init_slice_state(f, fs) < 0)
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index 5c472168e2..dbcd4861ac 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -39,7 +39,7 @@ RENAME(decode_line)(FFV1Context *f,
 if (is_input_end(s, gb))
 return AVERROR_INVALIDDATA;
 
-if (s->slice_coding_mode == 1) {
+if (sc->slice_coding_mode == 1) {
 int i;
 for (x = 0; x < w; x++) {
 int v = 0;
@@ -162,10 +162,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 
 sample[p][1][-1]= sample[p][0][0  ];
 sample[p][0][ w]= sample[p][0][w-1];
-if (lbd && s->slice_coding_mode == 0)
+if (lbd && sc->slice_coding_mode == 0)
 ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, 9);
 else
-ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, bits + (s->slice_coding_mode != 1));
+ret = RENAME(decode_line)(f, s, sc, gb, w, sample[p], (p + 
1)/2, bits + (sc->slice_coding_mode != 1));
 if (ret < 0)
 return ret;
 }
@@ -175,10 +175,10 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 int r = sample[2][1][x];
 int a = sample[3][1][x];
 
-if (s->slice_coding_mode != 1) {
+if (sc->slice_coding_mode != 1) {
 b -= offset;
 r -= offset;
-g -= (b * s->slice_rct_by_coef + r * s->slice_rct_ry_coef) >> 
2;
+g -= (b * sc->slice_rct_by_coef + r * sc->slice_rct_ry_coef) 
>> 2;
 b += g;
 r += g;
 }
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index d334220e13..fb373b598b 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -926,13 +926,13 @@ static void encode_slice_header(FFV1Context *f, 
FFV1Context *fs,
 put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.num, 0);
 put_symbol(c, state, f->cur_enc_frame->sample_aspect_ratio.den, 0);
 if (f->version > 3) {
-put_rac(c, state, fs->slice_coding_mode == 1);
-  

[FFmpeg-cvslog] lavc/ffv1: drop redundant PlaneContext.quant_table

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
12:22:57 2024 +0200| [a411fc5a84367b679de38ad07adb0ef351ca35d8] | committer: 
Anton Khirnov

lavc/ffv1: drop redundant PlaneContext.quant_table

It is a copy of FFV1Context.quant_tables[quant_table_index].

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a411fc5a84367b679de38ad07adb0ef351ca35d8
---

 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1_template.c| 22 +++---
 libavcodec/ffv1dec.c  | 28 
 libavcodec/ffv1dec_template.c | 15 ++-
 libavcodec/ffv1enc.c  | 24 
 libavcodec/ffv1enc_template.c | 13 -
 6 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 4d57172d5b..a87c2d2a36 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -59,7 +59,6 @@ typedef struct VlcState {
 } VlcState;
 
 typedef struct PlaneContext {
-int16_t quant_table[MAX_CONTEXT_INPUTS][256];
 int quant_table_index;
 int context_count;
 uint8_t (*state)[CONTEXT_SIZE];
diff --git a/libavcodec/ffv1_template.c b/libavcodec/ffv1_template.c
index c5f61b0182..d15ad11021 100644
--- a/libavcodec/ffv1_template.c
+++ b/libavcodec/ffv1_template.c
@@ -29,25 +29,25 @@ static inline int RENAME(predict)(TYPE *src, TYPE *last)
 return mid_pred(L, L + T - LT, T);
 }
 
-static inline int RENAME(get_context)(PlaneContext *p, TYPE *src,
-  TYPE *last, TYPE *last2)
+static inline int RENAME(get_context)(const int16_t 
quant_table[MAX_CONTEXT_INPUTS][256],
+  TYPE *src, TYPE *last, TYPE *last2)
 {
 const int LT = last[-1];
 const int T  = last[0];
 const int RT = last[1];
 const int L  = src[-1];
 
-if (p->quant_table[3][127] || p->quant_table[4][127]) {
+if (quant_table[3][127] || quant_table[4][127]) {
 const int TT = last2[0];
 const int LL = src[-2];
-return p->quant_table[0][(L - LT) & 0xFF] +
-   p->quant_table[1][(LT - T) & 0xFF] +
-   p->quant_table[2][(T - RT) & 0xFF] +
-   p->quant_table[3][(LL - L) & 0xFF] +
-   p->quant_table[4][(TT - T) & 0xFF];
+return quant_table[0][(L - LT) & 0xFF] +
+   quant_table[1][(LT - T) & 0xFF] +
+   quant_table[2][(T - RT) & 0xFF] +
+   quant_table[3][(LL - L) & 0xFF] +
+   quant_table[4][(TT - T) & 0xFF];
 } else
-return p->quant_table[0][(L - LT) & 0xFF] +
-   p->quant_table[1][(LT - T) & 0xFF] +
-   p->quant_table[2][(T - RT) & 0xFF];
+return quant_table[0][(L - LT) & 0xFF] +
+   quant_table[1][(LT - T) & 0xFF] +
+   quant_table[2][(T - RT) & 0xFF];
 }
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 66d9f63c1a..618020d10f 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -117,7 +117,8 @@ static int is_input_end(FFV1Context *s, GetBitContext *gb)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+static int decode_plane(FFV1Context *f,
+FFV1Context *s, FFV1SliceContext *sc,
 GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
@@ -141,13 +142,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(f, s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
@@ -207,7 +208,6 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 return -1;
 }
 p->quant_table_index = idx;
-memcpy(p->quant_table, f->quant_tables[idx], sizeof(p->quant_table));
 context_count = f->context_count[idx];
 
 if (p->context_count < context_count) {
@@ -335,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg)
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->c

[FFmpeg-cvslog] lavc/ffv1dec: move the bitreader to stack

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
10:09:22 2024 +0200| [889faedd26ed627f0f21e7b6c0ff438edde4f77f] | committer: 
Anton Khirnov

lavc/ffv1dec: move the bitreader to stack

There is no reason to place it in persistent state.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=889faedd26ed627f0f21e7b6c0ff438edde4f77f
---

 libavcodec/ffv1.h |  1 -
 libavcodec/ffv1dec.c  | 28 +++-
 libavcodec/ffv1dec_template.c | 23 ---
 3 files changed, 27 insertions(+), 25 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 68d13a2964..c88aa8c30d 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -85,7 +85,6 @@ typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
 RangeCoder c;
-GetBitContext gb;
 PutBitContext pb;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a2971d7eea..a1f7206871 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -94,14 +94,14 @@ static inline int get_vlc_symbol(GetBitContext *gb, 
VlcState *const state,
 return ret;
 }
 
-static int is_input_end(FFV1Context *s)
+static int is_input_end(FFV1Context *s, GetBitContext *gb)
 {
 if (s->ac != AC_GOLOMB_RICE) {
 RangeCoder *const c = >c;
 if (c->overread > MAX_OVERREAD)
 return AVERROR_INVALIDDATA;
 } else {
-if (get_bits_left(>gb) < 1)
+if (get_bits_left(gb) < 1)
 return AVERROR_INVALIDDATA;
 }
 return 0;
@@ -118,6 +118,7 @@ static int is_input_end(FFV1Context *s)
 #include "ffv1dec_template.c"
 
 static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+GetBitContext *gb,
 uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
 {
@@ -140,13 +141,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, sc, w, sample, plane_index, 8);
+int ret = decode_line(s, sc, gb, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, sc, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(s, sc, gb, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
@@ -262,6 +263,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 AVFrame * const p = f->picture.f;
 const int  si = (FFV1Context**)arg - f->slice_context;
 FFV1SliceContext *sc = >slices[si];
+GetBitContext gb;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
 ff_progress_frame_await(>last_picture, si);
@@ -322,7 +324,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->version == 3 && f->micro_version > 1 || f->version > 3)
 get_rac(>c, (uint8_t[]) { 129 });
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? fs->c.bytestream - 
fs->c.bytestream_start - 1 : 0;
-init_get_bits(>gb,
+init_get_bits(,
   fs->c.bytestream_start + fs->ac_byte_count,
   (fs->c.bytestream_end - fs->c.bytestream_start - 
fs->ac_byte_count) * 8);
 }
@@ -333,29 +335,29 @@ static int decode_slice(AVCodecContext *c, void *arg)
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->chroma_h_shift;
 const int cy= y >> f->chroma_v_shift;
-decode_plane(fs, sc, p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 1);
+decode_plane(fs, sc, , p->data[0] + ps*x + y*p->linesize[0], width, 
height, p->linesize[0], 0, 1);
 
 if (f->chroma_planes) {
-decode_plane(fs, sc, p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
-decode_plane(fs, sc, p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
+decode_plane(fs, sc, , p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
+decode_plane(fs, sc, , p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
 if (fs->transparency)
-decode_plane(fs

[FFmpeg-cvslog] lavc/ffv1: always use the main context values of plane_count/transparency

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
13:11:52 2024 +0200| [39486a2b29dc893b295bc328c63ec138a2df3a91] | committer: 
Anton Khirnov

lavc/ffv1: always use the main context values of plane_count/transparency

They cannot change between slices.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=39486a2b29dc893b295bc328c63ec138a2df3a91
---

 libavcodec/ffv1.c | 2 --
 libavcodec/ffv1dec.c  | 5 ++---
 libavcodec/ffv1dec_template.c | 2 +-
 libavcodec/ffv1enc.c  | 2 +-
 libavcodec/ffv1enc_template.c | 2 +-
 5 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 6a0aca6429..06a77c3a26 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -56,8 +56,6 @@ av_cold int ff_ffv1_init_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 {
 int j, i;
 
-fs->plane_count  = f->plane_count;
-fs->transparency = f->transparency;
 for (j = 0; j < f->plane_count; j++) {
 PlaneContext *const p = >plane[j];
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 618020d10f..6d3db25279 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -270,7 +270,6 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
 FFV1Context *fssrc = f->fsrc->slice_context[si];
-av_assert1(fs->plane_count == fssrc->plane_count);
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
 fs->slice_damaged |= fssrc->slice_damaged;
@@ -330,7 +329,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 
 av_assert1(width && height);
-if (f->colorspace == 0 && (f->chroma_planes || !fs->transparency)) {
+if (f->colorspace == 0 && (f->chroma_planes || !f->transparency)) {
 const int chroma_width  = AV_CEIL_RSHIFT(width,  f->chroma_h_shift);
 const int chroma_height = AV_CEIL_RSHIFT(height, f->chroma_v_shift);
 const int cx= x >> f->chroma_h_shift;
@@ -341,7 +340,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 decode_plane(f, fs, sc, , p->data[1] + ps*cx+cy*p->linesize[1], 
chroma_width, chroma_height, p->linesize[1], 1, 1);
 decode_plane(f, fs, sc, , p->data[2] + ps*cx+cy*p->linesize[2], 
chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
-if (fs->transparency)
+if (f->transparency)
 decode_plane(f, fs, sc, , p->data[3] + ps*x + y*p->linesize[3], 
width, height, p->linesize[3], (f->version >= 4 && !f->chroma_planes) ? 1 : 2, 
1);
 } else if (f->colorspace == 0) {
  decode_plane(f, fs, sc, , p->data[0] + ps*x + y*p->linesize[0]
, width, height, p->linesize[0], 0, 2);
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index d68bbda5be..5c472168e2 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -141,7 +141,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *f,
 int lbd= s->avctx->bits_per_raw_sample <= 8;
 int bits   = s->avctx->bits_per_raw_sample > 0 ? 
s->avctx->bits_per_raw_sample : 8;
 int offset = 1 << bits;
-int transparency = s->transparency;
+int transparency = f->transparency;
 
 for (x = 0; x < 4; x++) {
 sample[x][0] = RENAME(sc->sample_buffer) +  x * 2  * (w + 6) + 3;
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 714e007659..d334220e13 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1072,7 +1072,7 @@ retry:
 ret |= encode_plane(f, fs, sc, p->data[1] + 
ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1, 1);
 ret |= encode_plane(f, fs, sc, p->data[2] + 
ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1, 1);
 }
-if (fs->transparency)
+if (f->transparency)
 ret |= encode_plane(f, fs, sc, p->data[3] + ps*x + 
y*p->linesize[3], width, height, p->linesize[3], 2, 1);
 } else if (c->pix_fmt == AV_PIX_FMT_YA8) {
 ret  = encode_plane(f, fs, sc, p->data[0] + ps*x + 
y*p->linesize[0], width, height, p->linesize[0], 0, 2);
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index 4a5580e1a5..0f47a0b424 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -138,7 +138,7 @@ static int RENAME(encode_rgb_frame)(FFV1Context *f,
 int packed = !src[1];
 int bits   = s->bits_per_raw_sample > 0 ? s->bits_per_raw_sample : 8;
 int offset = 1 << bits;
-int transparency = s->transparency;
+int transparency = f->transparency;
 int packed_size = (3 + transparency)*2;
 
 sc->run_index = 0;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1: drop write-only PlaneContext.interlace_bit_state

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
12:46:29 2024 +0200| [492df6520128f00e341999f454ea9986da2c9a11] | committer: 
Anton Khirnov

lavc/ffv1: drop write-only PlaneContext.interlace_bit_state

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=492df6520128f00e341999f454ea9986da2c9a11
---

 libavcodec/ffv1.c | 3 ---
 libavcodec/ffv1.h | 1 -
 2 files changed, 4 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index a102425596..6a0aca6429 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -169,9 +169,6 @@ void ff_ffv1_clear_slice_state(const FFV1Context *f, 
FFV1Context *fs)
 for (i = 0; i < f->plane_count; i++) {
 PlaneContext *p = >plane[i];
 
-p->interlace_bit_state[0] = 128;
-p->interlace_bit_state[1] = 128;
-
 if (fs->ac != AC_GOLOMB_RICE) {
 if (f->initial_states[p->quant_table_index]) {
 memcpy(p->state, f->initial_states[p->quant_table_index],
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index a87c2d2a36..a3f3b30b49 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -63,7 +63,6 @@ typedef struct PlaneContext {
 int context_count;
 uint8_t (*state)[CONTEXT_SIZE];
 VlcState *vlc_state;
-uint8_t interlace_bit_state[2];
 } PlaneContext;
 
 #define MAX_SLICES 1024

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1: move sample_buffer to the per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jul  7 
19:46:20 2024 +0200| [91d3c1ac47d4a2b1455945b6131a44cdc5e7f425] | committer: 
Anton Khirnov

lavc/ffv1: move sample_buffer to the per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=91d3c1ac47d4a2b1455945b6131a44cdc5e7f425
---

 libavcodec/ffv1.c | 35 ---
 libavcodec/ffv1.h |  5 +++--
 libavcodec/ffv1dec.c  | 27 +--
 libavcodec/ffv1dec_template.c |  9 +
 libavcodec/ffv1enc.c  | 30 --
 libavcodec/ffv1enc_template.c |  9 +
 6 files changed, 62 insertions(+), 53 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 25f28287c0..a102425596 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -112,6 +112,8 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 if (!f->slices)
 return AVERROR(ENOMEM);
 
+f->max_slice_count = max_slice_count;
+
 for (i = 0; i < max_slice_count;) {
 FFV1SliceContext *sc = >slices[i];
 int sx  = i % f->num_h_slices;
@@ -123,7 +125,7 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 FFV1Context *fs = av_mallocz(sizeof(*fs));
 
 if (!fs)
-goto memfail;
+return AVERROR(ENOMEM);
 
 f->slice_context[i++] = fs;
 memcpy(fs, f, sizeof(*fs));
@@ -134,19 +136,15 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 sc->slice_x  = sxs;
 sc->slice_y  = sys;
 
-fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
-  sizeof(*fs->sample_buffer));
-fs->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
-sizeof(*fs->sample_buffer32));
-if (!fs->sample_buffer || !fs->sample_buffer32)
-goto memfail;
+sc->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+sizeof(*sc->sample_buffer));
+sc->sample_buffer32 = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
+  sizeof(*sc->sample_buffer32));
+if (!sc->sample_buffer || !sc->sample_buffer32)
+return AVERROR(ENOMEM);
 }
-f->max_slice_count = max_slice_count;
-return 0;
 
-memfail:
-f->max_slice_count = i;
-return AVERROR(ENOMEM);
+return 0;
 }
 
 int ff_ffv1_allocate_initial_states(FFV1Context *f)
@@ -199,14 +197,20 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 
 for (j = 0; j < s->max_slice_count; j++) {
 FFV1Context *fs = s->slice_context[j];
+FFV1SliceContext *sc = >slices[j];
+
+av_freep(>sample_buffer);
+av_freep(>sample_buffer32);
+
+if (!fs)
+continue;
+
 for (i = 0; i < s->plane_count; i++) {
 PlaneContext *p = >plane[i];
 
 av_freep(>state);
 av_freep(>vlc_state);
 }
-av_freep(>sample_buffer);
-av_freep(>sample_buffer32);
 }
 
 av_freep(>stats_out);
@@ -214,7 +218,8 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 av_freep(>initial_states[j]);
 for (i = 0; i < s->max_slice_count; i++) {
 FFV1Context *sf = s->slice_context[i];
-av_freep(>rc_stat2[j]);
+if (sf)
+av_freep(>rc_stat2[j]);
 }
 av_freep(>rc_stat2[j]);
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index 256904b283..ccb510a483 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -70,6 +70,9 @@ typedef struct PlaneContext {
 #define MAX_SLICES 1024
 
 typedef struct FFV1SliceContext {
+int16_t *sample_buffer;
+int32_t *sample_buffer32;
+
 int slice_width;
 int slice_height;
 int slice_x;
@@ -108,8 +111,6 @@ typedef struct FFV1Context {
 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
 int run_index;
 int colorspace;
-int16_t *sample_buffer;
-int32_t *sample_buffer32;
 
 int use32bit;
 
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 28e4a05b21..fcf8977a36 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -117,18 +117,18 @@ static int is_input_end(FFV1Context *s)
 #define RENAME(name) name ## 32
 #include "ffv1dec_template.c"
 
-static int decode_plane(FFV1Context *s, uint8_t *src,
- int w, int h, int stride, int plane_index,
+static int decode_plane(FFV1Context *s, FFV1SliceContext *sc,
+uint8_t *src, int w, int h, int stride, int 
plane_index,
  int pixel_stride)
 {
 int x, y;
 int16_t *sample[2];
-sample[0] = s->sample_buffer + 3;
-sample[1] = s

[FFmpeg-cvslog] lavc/ffv1enc: move bit writer to per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
10:14:55 2024 +0200| [d2f507233a6c3cbc24d342d3c31db2c3489df96d] | committer: 
Anton Khirnov

lavc/ffv1enc: move bit writer to per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d2f507233a6c3cbc24d342d3c31db2c3489df96d
---

 libavcodec/ffv1.h |  3 ++-
 libavcodec/ffv1enc.c  |  7 ---
 libavcodec/ffv1enc_template.c | 14 +++---
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index c88aa8c30d..dce6e177eb 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -79,13 +79,14 @@ typedef struct FFV1SliceContext {
 int slice_y;
 
 int run_index;
+
+PutBitContext pb;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
 RangeCoder c;
-PutBitContext pb;
 uint64_t rc_stat[256][2];
 uint64_t (*rc_stat2[MAX_QUANT_TABLES])[32][2];
 int version;
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 8bb9174a1d..5692bfa1fc 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -1057,7 +1057,7 @@ retry:
 }
 if (fs->ac == AC_GOLOMB_RICE) {
 fs->ac_byte_count = f->version > 2 || (!x && !y) ? 
ff_rac_terminate(>c, f->version > 2) : 0;
-init_put_bits(>pb,
+init_put_bits(>pb,
   fs->c.bytestream_start + fs->ac_byte_count,
   fs->c.bytestream_end - fs->c.bytestream_start - 
fs->ac_byte_count);
 }
@@ -1209,13 +1209,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket 
*pkt,
 buf_p = pkt->data;
 for (i = 0; i < f->slice_count; i++) {
 FFV1Context *fs = f->slice_context[i];
+FFV1SliceContext *sc = >slices[i];
 int bytes;
 
 if (fs->ac != AC_GOLOMB_RICE) {
 bytes = ff_rac_terminate(>c, 1);
 } else {
-flush_put_bits(>pb); // FIXME: nicer padding
-bytes = fs->ac_byte_count + put_bytes_output(>pb);
+flush_put_bits(>pb); // FIXME: nicer padding
+bytes = fs->ac_byte_count + put_bytes_output(>pb);
 }
 if (i > 0 || f->version > 2) {
 av_assert0(bytes < pkt->size / f->slice_count);
diff --git a/libavcodec/ffv1enc_template.c b/libavcodec/ffv1enc_template.c
index 4dccd531a8..8b9e53fa1b 100644
--- a/libavcodec/ffv1enc_template.c
+++ b/libavcodec/ffv1enc_template.c
@@ -39,7 +39,7 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 return AVERROR_INVALIDDATA;
 }
 } else {
-if (put_bytes_left(>pb, 0) < w * 4) {
+if (put_bytes_left(>pb, 0) < w * 4) {
 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n");
 return AVERROR_INVALIDDATA;
 }
@@ -86,10 +86,10 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 while (run_count >= 1 << ff_log2_run[run_index]) {
 run_count -= 1 << ff_log2_run[run_index];
 run_index++;
-put_bits(>pb, 1, 1);
+put_bits(>pb, 1, 1);
 }
 
-put_bits(>pb, 1 + ff_log2_run[run_index], run_count);
+put_bits(>pb, 1 + ff_log2_run[run_index], run_count);
 if (run_index)
 run_index--;
 run_count = 0;
@@ -103,21 +103,21 @@ RENAME(encode_line)(FFV1Context *s, FFV1SliceContext *sc,
 
 ff_dlog(s->avctx, "count:%d index:%d, mode:%d, x:%d pos:%d\n",
 run_count, run_index, run_mode, x,
-(int)put_bits_count(>pb));
+(int)put_bits_count(>pb));
 
 if (run_mode == 0)
-put_vlc_symbol(>pb, >vlc_state[context], diff, bits);
+put_vlc_symbol(>pb, >vlc_state[context], diff, bits);
 }
 }
 if (run_mode) {
 while (run_count >= 1 << ff_log2_run[run_index]) {
 run_count -= 1 << ff_log2_run[run_index];
 run_index++;
-put_bits(>pb, 1, 1);
+put_bits(>pb, 1, 1);
 }
 
 if (run_count)
-put_bits(>pb, 1, 1);
+put_bits(>pb, 1, 1);
 }
 sc->run_index = run_index;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1: drop redundant FFV1Context.quant_table

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jul  8 
11:36:58 2024 +0200| [4b9f7c7e3a9568a1982a6618c0ab77a3695675c1] | committer: 
Anton Khirnov

lavc/ffv1: drop redundant FFV1Context.quant_table

In all cases except decoding version 1 it's either not used, or contains
a copy of a table from quant_tables, which we can just as well use
directly.

When decoding version 1, we can just as well decode into
quant_tables[0], which would otherwise be unused.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4b9f7c7e3a9568a1982a6618c0ab77a3695675c1
---

 libavcodec/ffv1.h|  1 -
 libavcodec/ffv1dec.c | 10 +++---
 libavcodec/ffv1enc.c |  6 ++
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index dce6e177eb..4d57172d5b 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -106,7 +106,6 @@ typedef struct FFV1Context {
 int ac;  ///< 1=range coder <-> 0=golomb rice
 int ac_byte_count;   ///< number of bytes used for AC 
coding
 PlaneContext plane[MAX_PLANES];
-int16_t quant_table[MAX_CONTEXT_INPUTS][256];
 int16_t quant_tables[MAX_QUANT_TABLES][MAX_CONTEXT_INPUTS][256];
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index a1f7206871..66d9f63c1a 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -764,7 +764,7 @@ static int read_header(FFV1Context *f)
 ff_dlog(f->avctx, "%d %d %d\n",
 f->chroma_h_shift, f->chroma_v_shift, f->avctx->pix_fmt);
 if (f->version < 2) {
-context_count = read_quant_tables(c, f->quant_table);
+context_count = read_quant_tables(c, f->quant_tables[0]);
 if (context_count < 0) {
 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
 return AVERROR_INVALIDDATA;
@@ -834,7 +834,7 @@ static int read_header(FFV1Context *f)
sizeof(p->quant_table));
 context_count = f->context_count[idx];
 } else {
-memcpy(p->quant_table, f->quant_table, sizeof(p->quant_table));
+memcpy(p->quant_table, f->quant_tables[0], 
sizeof(p->quant_table));
 }
 
 if (f->version <= 2) {
@@ -1067,7 +1067,11 @@ static int update_thread_context(AVCodecContext *dst, 
const AVCodecContext *src)
 fdst->use32bit = fsrc->use32bit;
 memcpy(fdst->state_transition, fsrc->state_transition,
sizeof(fdst->state_transition));
-memcpy(fdst->quant_table, fsrc->quant_table, sizeof(fsrc->quant_table));
+
+// in version 1 there is a single per-keyframe quant table, so
+// we need to propagate it between threads
+if (fsrc->version < 2)
+memcpy(fdst->quant_tables[0], fsrc->quant_tables[0], 
sizeof(fsrc->quant_tables[0]));
 
 for (int i = 0; i < fdst->num_h_slices * fdst->num_v_slices; i++) {
 FFV1Context *fssrc = fsrc->slice_context[i];
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index 5692bfa1fc..1d00a46cdd 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -367,7 +367,7 @@ static void write_header(FFV1Context *f)
 put_symbol(c, state, f->chroma_v_shift, 0);
 put_rac(c, state, f->transparency);
 
-write_quant_tables(c, f->quant_table);
+write_quant_tables(c, f->quant_tables[f->context_model]);
 } else if (f->version < 3) {
 put_symbol(c, state, f->slice_count, 0);
 for (i = 0; i < f->slice_count; i++) {
@@ -735,15 +735,13 @@ static av_cold int encode_init(AVCodecContext *avctx)
 }
 s->context_count[0] = (11 * 11 * 11+ 1) / 2;
 s->context_count[1] = (11 * 11 * 5 * 5 * 5 + 1) / 2;
-memcpy(s->quant_table, s->quant_tables[s->context_model],
-   sizeof(s->quant_table));
 
 for (i = 0; i < s->plane_count; i++) {
 PlaneContext *const p = >plane[i];
 
-memcpy(p->quant_table, s->quant_table, sizeof(p->quant_table));
 p->quant_table_index = s->context_model;
 p->context_count = s->context_count[p->quant_table_index];
+memcpy(p->quant_table, s->quant_tables[p->quant_table_index], 
sizeof(p->quant_table));
 }
 
 if ((ret = ff_ffv1_allocate_initial_states(s)) < 0)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1: move run_index to the per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jul  7 
19:46:20 2024 +0200| [19e9f3d5f2457da9b0b9b3d60f2df454580f9f21] | committer: 
Anton Khirnov

lavc/ffv1: move run_index to the per-slice context

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=19e9f3d5f2457da9b0b9b3d60f2df454580f9f21
---

 libavcodec/ffv1.h |  3 ++-
 libavcodec/ffv1dec.c  |  6 +++---
 libavcodec/ffv1dec_template.c | 16 
 libavcodec/ffv1enc.c  |  6 +++---
 libavcodec/ffv1enc_template.c | 16 
 5 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index ccb510a483..68d13a2964 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -77,6 +77,8 @@ typedef struct FFV1SliceContext {
 int slice_height;
 int slice_x;
 int slice_y;
+
+int run_index;
 } FFV1SliceContext;
 
 typedef struct FFV1Context {
@@ -109,7 +111,6 @@ typedef struct FFV1Context {
 int context_count[MAX_QUANT_TABLES];
 uint8_t state_transition[256];
 uint8_t (*initial_states[MAX_QUANT_TABLES])[32];
-int run_index;
 int colorspace;
 
 int use32bit;
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index fcf8977a36..a2971d7eea 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -126,7 +126,7 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0] = sc->sample_buffer + 3;
 sample[1] = sc->sample_buffer + w + 6 + 3;
 
-s->run_index = 0;
+sc->run_index = 0;
 
 memset(sc->sample_buffer, 0, 2 * (w + 6) * sizeof(*sc->sample_buffer));
 
@@ -140,13 +140,13 @@ static int decode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 sample[0][w]  = sample[0][w - 1];
 
 if (s->avctx->bits_per_raw_sample <= 8) {
-int ret = decode_line(s, w, sample, plane_index, 8);
+int ret = decode_line(s, sc, w, sample, plane_index, 8);
 if (ret < 0)
 return ret;
 for (x = 0; x < w; x++)
 src[x*pixel_stride + stride * y] = sample[1][x];
 } else {
-int ret = decode_line(s, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
+int ret = decode_line(s, sc, w, sample, plane_index, 
s->avctx->bits_per_raw_sample);
 if (ret < 0)
 return ret;
 if (s->packed_at_lsb) {
diff --git a/libavcodec/ffv1dec_template.c b/libavcodec/ffv1dec_template.c
index b9316e04ca..8e2e38c0b9 100644
--- a/libavcodec/ffv1dec_template.c
+++ b/libavcodec/ffv1dec_template.c
@@ -22,16 +22,16 @@
 
 #include "ffv1_template.c"
 
-static av_always_inline int RENAME(decode_line)(FFV1Context *s, int w,
- TYPE *sample[2],
- int plane_index, int bits)
+static av_always_inline int
+RENAME(decode_line)(FFV1Context *s, FFV1SliceContext *sc, int w,
+TYPE *sample[2], int plane_index, int bits)
 {
 PlaneContext *const p = >plane[plane_index];
 RangeCoder *const c   = >c;
 int x;
 int run_count = 0;
 int run_mode  = 0;
-int run_index = s->run_index;
+int run_index = sc->run_index;
 
 if (is_input_end(s))
 return AVERROR_INVALIDDATA;
@@ -123,7 +123,7 @@ static av_always_inline int RENAME(decode_line)(FFV1Context 
*s, int w,
 
 sample[1][x] = av_zero_extend(RENAME(predict)(sample[1] + x, sample[0] 
+ x) + (SUINT)diff, bits);
 }
-s->run_index = run_index;
+sc->run_index = run_index;
 return 0;
 }
 
@@ -142,7 +142,7 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, 
FFV1SliceContext *sc,
 sample[x][1] = RENAME(sc->sample_buffer) + (x * 2 + 1) * (w + 6) + 3;
 }
 
-s->run_index = 0;
+sc->run_index = 0;
 
 memset(RENAME(sc->sample_buffer), 0, 8 * (w + 6) * 
sizeof(*RENAME(sc->sample_buffer)));
 
@@ -157,9 +157,9 @@ static int RENAME(decode_rgb_frame)(FFV1Context *s, 
FFV1SliceContext *sc,
 sample[p][1][-1]= sample[p][0][0  ];
 sample[p][0][ w]= sample[p][0][w-1];
 if (lbd && s->slice_coding_mode == 0)
-ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, 9);
+ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, 9);
 else
-ret = RENAME(decode_line)(s, w, sample[p], (p + 1)/2, bits + 
(s->slice_coding_mode != 1));
+ret = RENAME(decode_line)(s, sc, w, sample[p], (p + 1)/2, bits 
+ (s->slice_coding_mode != 1));
 if (ret < 0)
 return ret;
 }
diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
index f6b1919ee4..8bb9174a1d 100644
--- a/libavcodec/ffv1enc.c
+++ b/libavcodec/ffv1enc.c
@@ -276,7 +276,7 @@ static int encode_plane(FFV1Context *s, FFV1SliceContext 
*sc,
 int x, y, i, ret;
 const int ring_size

[FFmpeg-cvslog] lavc/ffv1dec: move copy_fields() under HAVE_THREADS

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul  3 
14:54:51 2024 +0200| [d845ea49c5b6039df18f935103cbef588f223799] | committer: 
Anton Khirnov

lavc/ffv1dec: move copy_fields() under HAVE_THREADS

It is unused otherwise

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d845ea49c5b6039df18f935103cbef588f223799
---

 libavcodec/ffv1dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index dbb7e082a3..6d59355c23 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -1027,6 +1027,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 return buf_size;
 }
 
+#if HAVE_THREADS
 static void copy_fields(FFV1Context *fsdst, const FFV1Context *fssrc,
 const FFV1Context *fsrc)
 {
@@ -1055,7 +1056,6 @@ static void copy_fields(FFV1Context *fsdst, const 
FFV1Context *fssrc,
 }
 }
 
-#if HAVE_THREADS
 static int update_thread_context(AVCodecContext *dst, const AVCodecContext 
*src)
 {
 FFV1Context *fsrc = src->priv_data;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: simplify slice index calculation

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul  3 
13:24:23 2024 +0200| [e1fa107fd1ac22f3f34c2bc5367a7055da784499] | committer: 
Anton Khirnov

lavc/ffv1dec: simplify slice index calculation

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e1fa107fd1ac22f3f34c2bc5367a7055da784499
---

 libavcodec/ffv1dec.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 5c515e97b6..7066146477 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -259,10 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
 AVFrame * const p = f->cur;
-int si;
-
-for( si=0; fs != f->slice_context[si]; si ++)
-;
+const int  si = (FFV1Context**)arg - f->slice_context;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
 ff_progress_frame_await(>last_picture, si);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1: add a per-slice context

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jul  4 
10:22:53 2024 +0200| [54aa33f116b9451a50a39cffd5cec5bfd21a47a8] | committer: 
Anton Khirnov

lavc/ffv1: add a per-slice context

FFV1 decoder and encoder currently use the same struct - FFV1Context -
both as codec private data and per-slice context. For this purpose
FFV1Context contains an array of pointers to per-slice FFV1Context
instances.

This pattern is highly confusing, as it is not clear which fields are
per-slice and which per-codec.

Address this by adding a new struct storing only per-slice data. Start
by moving slice_{x,y,width,height} to it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=54aa33f116b9451a50a39cffd5cec5bfd21a47a8
---

 libavcodec/ffv1.c| 15 ---
 libavcodec/ffv1.h| 13 ++---
 libavcodec/ffv1dec.c | 76 +---
 libavcodec/ffv1enc.c | 25 +
 4 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c
index 6ec24fed4a..25f28287c0 100644
--- a/libavcodec/ffv1.c
+++ b/libavcodec/ffv1.c
@@ -108,7 +108,12 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 
 av_assert0(max_slice_count > 0);
 
+f->slices = av_calloc(max_slice_count, sizeof(*f->slices));
+if (!f->slices)
+return AVERROR(ENOMEM);
+
 for (i = 0; i < max_slice_count;) {
+FFV1SliceContext *sc = >slices[i];
 int sx  = i % f->num_h_slices;
 int sy  = i / f->num_h_slices;
 int sxs = f->avctx->width  *  sx  / f->num_h_slices;
@@ -124,10 +129,10 @@ av_cold int ff_ffv1_init_slice_contexts(FFV1Context *f)
 memcpy(fs, f, sizeof(*fs));
 memset(fs->rc_stat2, 0, sizeof(fs->rc_stat2));
 
-fs->slice_width  = sxe - sxs;
-fs->slice_height = sye - sys;
-fs->slice_x  = sxs;
-fs->slice_y  = sys;
+sc->slice_width  = sxe - sxs;
+sc->slice_height = sye - sys;
+sc->slice_x  = sxs;
+sc->slice_y  = sys;
 
 fs->sample_buffer = av_malloc_array((fs->width + 6), 3 * MAX_PLANES *
   sizeof(*fs->sample_buffer));
@@ -217,5 +222,7 @@ av_cold int ff_ffv1_close(AVCodecContext *avctx)
 for (i = 0; i < s->max_slice_count; i++)
 av_freep(>slice_context[i]);
 
+av_freep(>slices);
+
 return 0;
 }
diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index d99367ce81..256904b283 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -69,6 +69,13 @@ typedef struct PlaneContext {
 
 #define MAX_SLICES 1024
 
+typedef struct FFV1SliceContext {
+int slice_width;
+int slice_height;
+int slice_x;
+int slice_y;
+} FFV1SliceContext;
+
 typedef struct FFV1Context {
 AVClass *class;
 AVCodecContext *avctx;
@@ -123,14 +130,12 @@ typedef struct FFV1Context {
 int max_slice_count;
 int num_v_slices;
 int num_h_slices;
-int slice_width;
-int slice_height;
-int slice_x;
-int slice_y;
 int slice_reset_contexts;
 int slice_coding_mode;
 int slice_rct_by_coef;
 int slice_rct_ry_coef;
+
+FFV1SliceContext *slices;
 } FFV1Context;
 
 int ff_ffv1_common_init(AVCodecContext *avctx);
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 6d59355c23..28e4a05b21 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -164,7 +164,7 @@ static int decode_plane(FFV1Context *s, uint8_t *src,
 }
 
 static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
-   AVFrame *frame)
+   FFV1SliceContext *sc, AVFrame *frame)
 {
 RangeCoder *c = >c;
 uint8_t state[CONTEXT_SIZE];
@@ -185,17 +185,17 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs,
 if (sx > f->num_h_slices - sw || sy > f->num_v_slices - sh)
 return AVERROR_INVALIDDATA;
 
-fs->slice_x  =  sx   * (int64_t)f->width  / f->num_h_slices;
-fs->slice_y  =  sy   * (int64_t)f->height / f->num_v_slices;
-fs->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - 
fs->slice_x;
-fs->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - 
fs->slice_y;
+sc->slice_x  =  sx   * (int64_t)f->width  / f->num_h_slices;
+sc->slice_y  =  sy   * (int64_t)f->height / f->num_v_slices;
+sc->slice_width  = (sx + sw) * (int64_t)f->width  / f->num_h_slices - 
sc->slice_x;
+sc->slice_height = (sy + sh) * (int64_t)f->height / f->num_v_slices - 
sc->slice_y;
 
-av_assert0((unsigned)fs->slice_width  <= f->width &&
-(unsigned)fs->slice_height <= f->height);
-av_assert0 (   (unsigned)fs->slice_x + (uint64_t)fs->slice_wid

[FFmpeg-cvslog] lavc/ffv1dec: drop a pointless variable in decode_slice()

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul  3 
14:40:23 2024 +0200| [3a5c814b19191022affa76e282b69b9aca8883ba] | committer: 
Anton Khirnov

lavc/ffv1dec: drop a pointless variable in decode_slice()

fsdst is by construction always equal to fs, there is even an
av_assert1() checking that. Just use fs directly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3a5c814b19191022affa76e282b69b9aca8883ba
---

 libavcodec/ffv1dec.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 60d04f04b9..dbb7e082a3 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -267,16 +267,14 @@ static int decode_slice(AVCodecContext *c, void *arg)
 
 if(f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY)) {
 FFV1Context *fssrc = f->fsrc->slice_context[si];
-FFV1Context *fsdst = f->slice_context[si];
-av_assert1(fsdst->plane_count == fssrc->plane_count);
-av_assert1(fsdst == fs);
+av_assert1(fs->plane_count == fssrc->plane_count);
 
 if (!(p->flags & AV_FRAME_FLAG_KEY))
-fsdst->slice_damaged |= fssrc->slice_damaged;
+fs->slice_damaged |= fssrc->slice_damaged;
 
 for (int i = 0; i < f->plane_count; i++) {
 PlaneContext *psrc = >plane[i];
-PlaneContext *pdst = >plane[i];
+PlaneContext *pdst = >plane[i];
 
 av_free(pdst->state);
 av_free(pdst->vlc_state);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: drop FFV1Context.cur

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul  3 
14:36:02 2024 +0200| [4da146ba831c51b66a038f6a96c8a6b175e55d35] | committer: 
Anton Khirnov

lavc/ffv1dec: drop FFV1Context.cur

It is merely a pointer to FFV1Context.picture.f, which can just as well
be used directly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4da146ba831c51b66a038f6a96c8a6b175e55d35
---

 libavcodec/ffv1.h|  1 -
 libavcodec/ffv1dec.c | 33 +
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/libavcodec/ffv1.h b/libavcodec/ffv1.h
index acec22e83e..d99367ce81 100644
--- a/libavcodec/ffv1.h
+++ b/libavcodec/ffv1.h
@@ -89,7 +89,6 @@ typedef struct FFV1Context {
 ProgressFrame picture, last_picture;
 struct FFV1Context *fsrc;
 
-AVFrame *cur;
 const AVFrame *cur_enc_frame;
 int plane_count;
 int ac;  ///< 1=range coder <-> 0=golomb rice
diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7066146477..60d04f04b9 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -163,7 +163,8 @@ static int decode_plane(FFV1Context *s, uint8_t *src,
 return 0;
 }
 
-static int decode_slice_header(const FFV1Context *f, FFV1Context *fs)
+static int decode_slice_header(const FFV1Context *f, FFV1Context *fs,
+   AVFrame *frame)
 {
 RangeCoder *c = >c;
 uint8_t state[CONTEXT_SIZE];
@@ -217,23 +218,23 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 
 ps = get_symbol(c, state, 0);
 if (ps == 1) {
-f->cur->flags |= AV_FRAME_FLAG_INTERLACED;
-f->cur->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
+frame->flags |= AV_FRAME_FLAG_INTERLACED;
+frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
 } else if (ps == 2) {
-f->cur->flags |= AV_FRAME_FLAG_INTERLACED;
-f->cur->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
+frame->flags |= AV_FRAME_FLAG_INTERLACED;
+frame->flags &= ~AV_FRAME_FLAG_TOP_FIELD_FIRST;
 } else if (ps == 3) {
-f->cur->flags &= ~AV_FRAME_FLAG_INTERLACED;
+frame->flags &= ~AV_FRAME_FLAG_INTERLACED;
 }
-f->cur->sample_aspect_ratio.num = get_symbol(c, state, 0);
-f->cur->sample_aspect_ratio.den = get_symbol(c, state, 0);
+frame->sample_aspect_ratio.num = get_symbol(c, state, 0);
+frame->sample_aspect_ratio.den = get_symbol(c, state, 0);
 
 if (av_image_check_sar(f->width, f->height,
-   f->cur->sample_aspect_ratio) < 0) {
+   frame->sample_aspect_ratio) < 0) {
 av_log(f->avctx, AV_LOG_WARNING, "ignoring invalid SAR: %u/%u\n",
-   f->cur->sample_aspect_ratio.num,
-   f->cur->sample_aspect_ratio.den);
-f->cur->sample_aspect_ratio = (AVRational){ 0, 1 };
+   frame->sample_aspect_ratio.num,
+   frame->sample_aspect_ratio.den);
+frame->sample_aspect_ratio = (AVRational){ 0, 1 };
 }
 
 if (fs->version > 3) {
@@ -258,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 FFV1Context *f= fs->avctx->priv_data;
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
-AVFrame * const p = f->cur;
+AVFrame * const p = f->picture.f;
 const int  si = (FFV1Context**)arg - f->slice_context;
 
 if (f->fsrc && !(p->flags & AV_FRAME_FLAG_KEY) && f->last_picture.f)
@@ -299,7 +300,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (f->version > 2) {
 if (ff_ffv1_init_slice_state(f, fs) < 0)
 return AVERROR(ENOMEM);
-if (decode_slice_header(f, fs) < 0) {
+if (decode_slice_header(f, fs, p) < 0) {
 fs->slice_x = fs->slice_y = fs->slice_height = fs->slice_width = 0;
 fs->slice_damaged = 1;
 return AVERROR_INVALIDDATA;
@@ -307,7 +308,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 }
 if ((ret = ff_ffv1_init_slice_state(f, fs)) < 0)
 return ret;
-if ((f->cur->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
+if ((p->flags & AV_FRAME_FLAG_KEY) || fs->slice_reset_contexts) {
 ff_ffv1_clear_slice_state(f, fs);
 } else if (fs->slice_damaged) {
 return AVERROR_INVALIDDATA;
@@ -920,7 +921,7 @@ static int decode_frame(AVCodecContext *avctx, AVFrame 
*rframe,
 if (ret < 0)
 return ret;
 
-f->cur = p = f->picture.f;
+p = f->picture.f;
 
 p->pict_type = AV_PICTURE_TYPE_I; //FIXME I vs. P
 p->flags = (p->flags & ~AV_FRAME_FLAG_KEY) | key_frame;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/ffv1dec: declare loop variables in the loop where possible

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul  3 
13:24:23 2024 +0200| [d776fa4e4db4352191f4e6f1fd83c09921e79d25] | committer: 
Anton Khirnov

lavc/ffv1dec: declare loop variables in the loop where possible

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d776fa4e4db4352191f4e6f1fd83c09921e79d25
---

 libavcodec/ffv1dec.c | 45 ++---
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c
index 7a0d1909aa..5c515e97b6 100644
--- a/libavcodec/ffv1dec.c
+++ b/libavcodec/ffv1dec.c
@@ -46,7 +46,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, 
uint8_t *state,
 if (get_rac(c, state + 0))
 return 0;
 else {
-int i, e;
+int e;
 unsigned a;
 e = 0;
 while (get_rac(c, state + 1 + FFMIN(e, 9))) { // 1..10
@@ -56,7 +56,7 @@ static inline av_flatten int get_symbol_inline(RangeCoder *c, 
uint8_t *state,
 }
 
 a = 1;
-for (i = e - 1; i >= 0; i--)
+for (int i = e - 1; i >= 0; i--)
 a += a + get_rac(c, state + 22 + FFMIN(i, 9));  // 22..31
 
 e = -(is_signed && get_rac(c, state + 11 + FFMIN(e, 10))); // 11..21
@@ -167,7 +167,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 {
 RangeCoder *c = >c;
 uint8_t state[CONTEXT_SIZE];
-unsigned ps, i, context_count;
+unsigned ps, context_count;
 int sx, sy, sw, sh;
 
 memset(state, 128, sizeof(state));
@@ -197,7 +197,7 @@ static int decode_slice_header(const FFV1Context *f, 
FFV1Context *fs)
 if (fs->ac == AC_GOLOMB_RICE && fs->slice_width >= (1<<23))
 return AVERROR_INVALIDDATA;
 
-for (i = 0; i < f->plane_count; i++) {
+for (unsigned i = 0; i < f->plane_count; i++) {
 PlaneContext * const p = >plane[i];
 int idx = get_symbol(c, state, 0);
 if (idx >= (unsigned)f->quant_table_count) {
@@ -259,7 +259,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 int width, height, x, y, ret;
 const int ps  = av_pix_fmt_desc_get(c->pix_fmt)->comp[0].step;
 AVFrame * const p = f->cur;
-int i, si;
+int si;
 
 for( si=0; fs != f->slice_context[si]; si ++)
 ;
@@ -276,7 +276,7 @@ static int decode_slice(AVCodecContext *c, void *arg)
 if (!(p->flags & AV_FRAME_FLAG_KEY))
 fsdst->slice_damaged |= fssrc->slice_damaged;
 
-for (i = 0; i < f->plane_count; i++) {
+for (int i = 0; i < f->plane_count; i++) {
 PlaneContext *psrc = >plane[i];
 PlaneContext *pdst = >plane[i];
 
@@ -424,7 +424,7 @@ static int read_extra_header(FFV1Context *f)
 {
 RangeCoder *const c = >c;
 uint8_t state[CONTEXT_SIZE];
-int i, j, k, ret;
+int ret;
 uint8_t state2[32][CONTEXT_SIZE];
 unsigned crc = 0;
 
@@ -453,7 +453,7 @@ static int read_extra_header(FFV1Context *f)
 f->ac = get_symbol(c, state, 0);
 
 if (f->ac == AC_RANGE_CUSTOM_TAB) {
-for (i = 1; i < 256; i++)
+for (int i = 1; i < 256; i++)
 f->state_transition[i] = get_symbol(c, state, 1) + c->one_state[i];
 }
 
@@ -492,7 +492,7 @@ static int read_extra_header(FFV1Context *f)
 return AVERROR_INVALIDDATA;
 }
 
-for (i = 0; i < f->quant_table_count; i++) {
+for (int i = 0; i < f->quant_table_count; i++) {
 f->context_count[i] = read_quant_tables(c, f->quant_tables[i]);
 if (f->context_count[i] < 0) {
 av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n");
@@ -502,10 +502,10 @@ static int read_extra_header(FFV1Context *f)
 if ((ret = ff_ffv1_allocate_initial_states(f)) < 0)
 return ret;
 
-for (i = 0; i < f->quant_table_count; i++)
+for (int i = 0; i < f->quant_table_count; i++)
 if (get_rac(c, state)) {
-for (j = 0; j < f->context_count[i]; j++)
-for (k = 0; k < CONTEXT_SIZE; k++) {
+for (int j = 0; j < f->context_count[i]; j++)
+for (int k = 0; k < CONTEXT_SIZE; k++) {
 int pred = j ? f->initial_states[i][j - 1][k] : 128;
 f->initial_states[i][j][k] =
 (pred + get_symbol(c, state2[k], 1)) & 0xFF;
@@ -550,7 +550,7 @@ static int read_extra_header(FFV1Context *f)
 static int read_header(FFV1Context *f)
 {
 uint8_t state[CONTEXT_SIZE];
-int i, j, context_count = -1; //-1 to avoid warning
+int context_count = -1; //-1 to avoid warning
 RangeCoder *const c = >slice_context[0]->c;
 
 memset(state, 128, sizeof(state));
@@ -566,7 +566,7 @@ static int read_header(FFV1Context *f)
 f->ac = get_symbol(c, state, 0);
 
 if (f->ac 

[FFmpeg-cvslog] tests/fate/vcodec: add vsynth tests for FFV1 version 2

2024-08-01 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jul 16 
13:46:33 2024 +0200| [8e19c24634a0a442586b4c543da33d2843a1baa3] | committer: 
Anton Khirnov

tests/fate/vcodec: add vsynth tests for FFV1 version 2

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8e19c24634a0a442586b4c543da33d2843a1baa3
---

 tests/fate/vcodec.mak| 3 ++-
 tests/ref/vsynth/vsynth1-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth2-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth3-ffv1-v2 | 4 
 tests/ref/vsynth/vsynth_lena-ffv1-v2 | 4 
 5 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/tests/fate/vcodec.mak b/tests/fate/vcodec.mak
index abdc481f8a..b9829be027 100644
--- a/tests/fate/vcodec.mak
+++ b/tests/fate/vcodec.mak
@@ -154,13 +154,14 @@ $(FATE_VCODEC_DV:%=fate-vsynth\%-%): CODEC= dvvideo
 $(FATE_VCODEC_DV:%=fate-vsynth\%-%): FMT  = dv
 $(FATE_VCODEC_DV:%=fate-vsynth\%-%): DECOPTS += $(DEFAULT_SIZE)
 
-FATE_VCODEC-$(call ENCDEC, FFV1, AVI)   += ffv1 ffv1-v0 \
+FATE_VCODEC-$(call ENCDEC, FFV1, AVI)   += ffv1 ffv1-v0 ffv1-v2 \
ffv1-v3-yuv420p \
ffv1-2pass
 FATE_VCODEC_SCALE-$(call ENCDEC, FFV1, AVI) += ffv1-v3-yuv422p10 
ffv1-v3-yuv444p16 \
ffv1-v3-bgr0 ffv1-v3-rgb48
 fate-vsynth%-ffv1:   ENCOPTS = -slices 4
 fate-vsynth%-ffv1-v0:CODEC   = ffv1
+fate-vsynth%-ffv1-v2:ENCOPTS = -level 2 -strict experimental
 fate-vsynth%-ffv1-v3-yuv420p:ENCOPTS = -level 3 -pix_fmt yuv420p
 fate-vsynth%-ffv1-v3-yuv422p10:  ENCOPTS = -level 3 -pix_fmt yuv422p10 \
-sws_flags neighbor+bitexact
diff --git a/tests/ref/vsynth/vsynth1-ffv1-v2 b/tests/ref/vsynth/vsynth1-ffv1-v2
new file mode 100644
index 00..69536fb390
--- /dev/null
+++ b/tests/ref/vsynth/vsynth1-ffv1-v2
@@ -0,0 +1,4 @@
+0f9298229cf53ce257648ccec70c893f *tests/data/fate/vsynth1-ffv1-v2.avi
+2689724 tests/data/fate/vsynth1-ffv1-v2.avi
+c5ccac874dbf808e9088bc3107860042 *tests/data/fate/vsynth1-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth2-ffv1-v2 b/tests/ref/vsynth/vsynth2-ffv1-v2
new file mode 100644
index 00..0b3f288f8f
--- /dev/null
+++ b/tests/ref/vsynth/vsynth2-ffv1-v2
@@ -0,0 +1,4 @@
+3144d06b9af1af98d072ccf05ff116ba *tests/data/fate/vsynth2-ffv1-v2.avi
+3716500 tests/data/fate/vsynth2-ffv1-v2.avi
+36d7ca943916e1743cefa609eba0205c *tests/data/fate/vsynth2-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200
diff --git a/tests/ref/vsynth/vsynth3-ffv1-v2 b/tests/ref/vsynth/vsynth3-ffv1-v2
new file mode 100644
index 00..3b0397ec02
--- /dev/null
+++ b/tests/ref/vsynth/vsynth3-ffv1-v2
@@ -0,0 +1,4 @@
+72f1126e9e270f019d90f74959bcf0cb *tests/data/fate/vsynth3-ffv1-v2.avi
+60648 tests/data/fate/vsynth3-ffv1-v2.avi
+a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:86700/86700
diff --git a/tests/ref/vsynth/vsynth_lena-ffv1-v2 
b/tests/ref/vsynth/vsynth_lena-ffv1-v2
new file mode 100644
index 00..5f180462b5
--- /dev/null
+++ b/tests/ref/vsynth/vsynth_lena-ffv1-v2
@@ -0,0 +1,4 @@
+4a0dbd5b50fa68fc7d5a8d6d64bd695a *tests/data/fate/vsynth_lena-ffv1-v2.avi
+3546264 tests/data/fate/vsynth_lena-ffv1-v2.avi
+dde5895817ad9d219f79a52d0bdfb001 
*tests/data/fate/vsynth_lena-ffv1-v2.out.rawvideo
+stddev:0.00 PSNR:999.99 MAXDIFF:0 bytes:  7603200/  7603200

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavfi/framesync: avoid forcing frame writability unnecessarily

2024-07-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jul 24 
17:10:41 2024 +0200| [43f702a2532c7ddd84160a0a46ed36ad6f4b7c0a] | committer: 
Anton Khirnov

lavfi/framesync: avoid forcing frame writability unnecessarily

Callers of ff_framesync_get_frame() generally do not expect the result
to be writable, those that do (e.g. ff_framesync_dualinput_get_writable())
ensure writability themselves.

Significantly reduces memory consumption in complex graphs with
framesync-based filters (e.g. scale, ssim).

Reported-By: Mark Shwartzman

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=43f702a2532c7ddd84160a0a46ed36ad6f4b7c0a
---

 libavfilter/framesync.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/libavfilter/framesync.c b/libavfilter/framesync.c
index 535fbe9c7c..8e06e0e700 100644
--- a/libavfilter/framesync.c
+++ b/libavfilter/framesync.c
@@ -273,7 +273,6 @@ int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, 
AVFrame **rframe,
 AVFrame *frame;
 unsigned need_copy = 0, i;
 int64_t pts_next;
-int ret;
 
 if (!fs->in[in].frame) {
 *rframe = NULL;
@@ -291,10 +290,6 @@ int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, 
AVFrame **rframe,
 if (need_copy) {
 if (!(frame = av_frame_clone(frame)))
 return AVERROR(ENOMEM);
-if ((ret = ff_inlink_make_frame_writable(fs->parent->inputs[in], 
)) < 0) {
-av_frame_free();
-return ret;
-}
 } else {
 fs->in[in].frame = NULL;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] fftools/ffmpeg: prefer real errors over EOF in err_merge()

2024-07-24 Thread Anton Khirnov
ffmpeg | branch: release/6.1 | Anton Khirnov  | Tue Jul 23 
15:11:08 2024 +0200| [159270e3b2fc51f0d0c65411359a17c15bc520ed] | committer: 
Anton Khirnov

fftools/ffmpeg: prefer real errors over EOF in err_merge()

Fixes an issue in 6.1 when reading a corrupted file with -xerror would
exit with success. This specific issue is not present in master, but
this should generally be a more robust behaviour.

Reported-by: Andrej Peterka
(cherry picked from commit d1fa39d08d3bce9c268cd02cb3c45a76e63b6ff4)
Signed-off-by: Anton Khirnov 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=159270e3b2fc51f0d0c65411359a17c15bc520ed
---

 fftools/ffmpeg.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0983d026cd..25604e05a5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -883,11 +883,12 @@ void update_benchmark(const char *fmt, ...);
 /**
  * Merge two return codes - return one of the error codes if at least one of
  * them was negative, 0 otherwise.
- * Currently just picks the first one, eventually we might want to do something
- * more sophisticated, like sorting them by priority.
  */
 static inline int err_merge(int err0, int err1)
 {
+// prefer "real" errors over EOF
+if ((err0 >= 0 || err0 == AVERROR_EOF) && err1 < 0)
+return err1;
 return (err0 < 0) ? err0 : FFMIN(err1, 0);
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] fftools/ffmpeg: prefer real errors over EOF in err_merge()

2024-07-24 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jul 23 
15:11:08 2024 +0200| [d1fa39d08d3bce9c268cd02cb3c45a76e63b6ff4] | committer: 
Anton Khirnov

fftools/ffmpeg: prefer real errors over EOF in err_merge()

Fixes an issue in 6.1 when reading a corrupted file with -xerror would
exit with success. This specific issue is not present in master, but
this should generally be a more robust behaviour.

Reported-by: Andrej Peterka

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d1fa39d08d3bce9c268cd02cb3c45a76e63b6ff4
---

 fftools/ffmpeg_utils.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fftools/ffmpeg_utils.h b/fftools/ffmpeg_utils.h
index bd225abc38..7939e44cdc 100644
--- a/fftools/ffmpeg_utils.h
+++ b/fftools/ffmpeg_utils.h
@@ -35,11 +35,12 @@ typedef struct Timestamp {
 /**
  * Merge two return codes - return one of the error codes if at least one of
  * them was negative, 0 otherwise.
- * Currently just picks the first one, eventually we might want to do something
- * more sophisticated, like sorting them by priority.
  */
 static inline int err_merge(int err0, int err1)
 {
+// prefer "real" errors over EOF
+if ((err0 >= 0 || err0 == AVERROR_EOF) && err1 < 0)
+return err1;
 return (err0 < 0) ? err0 : FFMIN(err1, 0);
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavf: deprecate avformat_transfer_internal_stream_timing_info()

2024-07-09 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jul  5 
12:40:01 2024 +0200| [9fb8d13d56f20728141fd7070d8a325720727d57] | committer: 
Anton Khirnov

lavf: deprecate avformat_transfer_internal_stream_timing_info()

And av_stream_get_codec_timebase().

They were both added for ffmpeg CLI, which no longer calls either of
them. Furthermore the notion of "internal stream timing info" that needs
to be transferred with a special magic API function is fundamentally
flawed and should be removed.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9fb8d13d56f20728141fd7070d8a325720727d57
---

 doc/APIchanges  |  4 
 libavformat/avformat.c  |  2 ++
 libavformat/avformat.h  | 18 +++---
 libavformat/internal.h  |  2 ++
 libavformat/options.c   |  2 ++
 libavformat/version_major.h |  1 +
 6 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 98bc100662..5751216b24 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2024-03-07
 
 API changes, most recent first:
 
+2024-07-xx - xx - lavf 61 - avformat.h
+  Deprecate avformat_transfer_internal_stream_timing_info()
+  and av_stream_get_codec_timebase() without replacement.
+
 2024-07-08 - xx - lavc 61.10.100 - packet.h
   Add AV_PKT_DATA_FRAME_CROPPING.
 
diff --git a/libavformat/avformat.c b/libavformat/avformat.c
index 140fb5b6aa..b4f20502fb 100644
--- a/libavformat/avformat.c
+++ b/libavformat/avformat.c
@@ -770,6 +770,7 @@ AVRational av_guess_frame_rate(AVFormatContext *format, 
AVStream *st, AVFrame *f
 return fr;
 }
 
+#if FF_API_INTERNAL_TIMING
 int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
   AVStream *ost, const 
AVStream *ist,
   enum AVTimebaseSource 
copy_tb)
@@ -849,6 +850,7 @@ AVRational av_stream_get_codec_timebase(const AVStream *st)
 {
 return cffstream(st)->avctx ? cffstream(st)->avctx->time_base : 
cffstream(st)->transferred_mux_tb;
 }
+#endif
 
 void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits,
  unsigned int pts_num, unsigned int pts_den)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ef912731ac..4a3fb00529 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -3047,6 +3047,7 @@ int avformat_match_stream_specifier(AVFormatContext *s, 
AVStream *st,
 
 int avformat_queue_attached_pictures(AVFormatContext *s);
 
+#if FF_API_INTERNAL_TIMING
 enum AVTimebaseSource {
 AVFMT_TBCF_AUTO = -1,
 AVFMT_TBCF_DECODER,
@@ -3057,25 +3058,20 @@ enum AVTimebaseSource {
 };
 
 /**
- * Transfer internal timing information from one stream to another.
- *
- * This function is useful when doing stream copy.
- *
- * @param ofmt target output format for ost
- * @param ost  output stream which needs timings copy and adjustments
- * @param ist  reference input stream to copy timings from
- * @param copy_tb  define from where the stream codec timebase needs to be 
imported
+ * @deprecated do not call this function
  */
+attribute_deprecated
 int avformat_transfer_internal_stream_timing_info(const AVOutputFormat *ofmt,
   AVStream *ost, const 
AVStream *ist,
   enum AVTimebaseSource 
copy_tb);
 
 /**
- * Get the internal codec timebase from a stream.
- *
- * @param st  input stream to extract the timebase from
+ * @deprecated do not call this function
  */
+attribute_deprecated
 AVRational av_stream_get_codec_timebase(const AVStream *st);
+#endif
+
 
 /**
  * @}
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 6bad4fd119..8e8971bfeb 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -411,7 +411,9 @@ typedef struct FFStream {
 
 const struct AVCodecDescriptor *codec_desc;
 
+#if FF_API_INTERNAL_TIMING
 AVRational transferred_mux_tb;
+#endif
 } FFStream;
 
 static av_always_inline FFStream *ffstream(AVStream *st)
diff --git a/libavformat/options.c b/libavformat/options.c
index ae879b9072..485265df52 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -318,7 +318,9 @@ AVStream *avformat_new_stream(AVFormatContext *s, const 
AVCodec *c)
 sti->pts_buffer[i] = AV_NOPTS_VALUE;
 
 st->sample_aspect_ratio = (AVRational) { 0, 1 };
+#if FF_API_INTERNAL_TIMING
 sti->transferred_mux_tb = (AVRational) { 0, 1 };;
+#endif
 
 #if FF_API_AVSTREAM_SIDE_DATA
 sti->inject_global_side_data = si->inject_global_side_data;
diff --git a/libavformat/version_major.h b/libavformat/version_major.h
index 44ad23c6b6..7a9b06703d 100644
--- a/libavformat/version_major.h
+++ b/libavformat/version_major.h
@@ -47,6 +47,7 @@
 #define FF_API_AVSTREAM_SIDE_DATA   (LIBAVFORMAT_VERSION_MAJOR < 62

[FFmpeg-cvslog] fftools/ffmpeg_dec: improve detection of lavf-guessed durations

2024-07-09 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jul  5 
12:19:35 2024 +0200| [ff55d1cc20780dc90457368cb4ccae2435a878b1] | committer: 
Anton Khirnov

fftools/ffmpeg_dec: improve detection of lavf-guessed durations

Will be useful in following commit.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ff55d1cc20780dc90457368cb4ccae2435a878b1
---

 fftools/ffmpeg_dec.c | 16 
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 70de151301..c2bcf784b0 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -260,6 +260,10 @@ static int64_t video_duration_estimate(const DecoderPriv 
*dp, const AVFrame *fra
 const int  ts_unreliable = dp->flags & DECODER_FLAG_TS_UNRELIABLE;
 const int  fr_forced = dp->flags & DECODER_FLAG_FRAMERATE_FORCED;
 int64_t codec_duration = 0;
+// difference between this and last frame's timestamps
+const int64_t ts_diff =
+(frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE) 
?
+frame->pts - dp->last_frame_pts : -1;
 
 // XXX lavf currently makes up frame durations when they are not provided 
by
 // the container. As there is no way to reliably distinguish real container
@@ -267,8 +271,13 @@ static int64_t video_duration_estimate(const DecoderPriv 
*dp, const AVFrame *fra
 // the container has timestamps. Eventually lavf should stop making up
 // durations, then this should be simplified.
 
+// frame duration is unreliable (typically guessed by lavf) when it is 
equal
+// to 1 and the actual duration of the last frame is more than 2x larger
+const int duration_unreliable = frame->duration == 1 && ts_diff > 2 * 
frame->duration;
+
 // prefer frame duration for containers with timestamps
-if (frame->duration > 0 && (!ts_unreliable || fr_forced))
+if (fr_forced ||
+(frame->duration > 0 && !ts_unreliable && !duration_unreliable))
 return frame->duration;
 
 if (dp->dec_ctx->framerate.den && dp->dec_ctx->framerate.num) {
@@ -285,9 +294,8 @@ static int64_t video_duration_estimate(const DecoderPriv 
*dp, const AVFrame *fra
 
 // when timestamps are available, repeat last frame's actual duration
 // (i.e. pts difference between this and last frame)
-if (frame->pts != AV_NOPTS_VALUE && dp->last_frame_pts != AV_NOPTS_VALUE &&
-frame->pts > dp->last_frame_pts)
-return frame->pts - dp->last_frame_pts;
+if (ts_diff > 0)
+return ts_diff;
 
 // try frame/codec duration
 if (frame->duration > 0)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] fftools/ffmpeg_mux_init: default to input timebase for streamcopy

2024-07-09 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Jul  5 
12:30:04 2024 +0200| [10185e2d4c1e9839bc58a1d6a63c861677b13fd0] | committer: 
Anton Khirnov

fftools/ffmpeg_mux_init: default to input timebase for streamcopy

Stop trying to invent some "framerate-based" timebase when there is no
reason to think the stream is CFR at all.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=10185e2d4c1e9839bc58a1d6a63c861677b13fd0
---

 fftools/ffmpeg_mux_init.c| 7 +--
 tests/fate/ffmpeg.mak| 2 +-
 tests/ref/fate/copy-trac4914-avi | 4 ++--
 3 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 899ee6046f..4a2b5924a4 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -960,17 +960,12 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost, AVDictionary **e
 else
 ost->st->avg_frame_rate = ist->st->avg_frame_rate;
 
-ret = avformat_transfer_internal_stream_timing_info(mux->fc->oformat,
-ost->st, ist->st, 
copy_tb);
-if (ret < 0)
-goto fail;
-
 // copy timebase while removing common factors
 if (ost->st->time_base.num <= 0 || ost->st->time_base.den <= 0) {
 if (fr.num)
 ost->st->time_base = av_inv_q(fr);
 else
-ost->st->time_base = 
av_add_q(av_stream_get_codec_timebase(ost->st), (AVRational){0, 1});
+ost->st->time_base = av_add_q(ist->st->time_base, (AVRational){0, 
1});
 }
 
 if (!ms->copy_prior_start) {
diff --git a/tests/fate/ffmpeg.mak b/tests/fate/ffmpeg.mak
index dc102750a0..9e0c68da20 100644
--- a/tests/fate/ffmpeg.mak
+++ b/tests/fate/ffmpeg.mak
@@ -146,7 +146,7 @@ fate-copy-trac236: CMD = transcode mov 
$(TARGET_SAMPLES)/mov/fcp_export8-236.mov
 
 FATE_STREAMCOPY-$(call TRANSCODE, RAWVIDEO MPEG2VIDEO, MXF, MPEGTS_DEMUXER 
MPEGVIDEO_PARSER MPEGAUDIO_PARSER MP2_DECODER ARESAMPLE_FILTER 
PCM_S16LE_DECODER) += fate-copy-trac4914
 fate-copy-trac4914: CMD = transcode mpegts 
$(TARGET_SAMPLES)/mpeg2/xdcam8mp2-1s_small.ts\
-  mxf "-c:a pcm_s16le -af aresample -c:v copy"
+  mxf "-c:a pcm_s16le -af aresample -c:v copy -time_base 
1001/3"
 
 FATE_STREAMCOPY-$(call TRANSCODE, RAWVIDEO MPEG2VIDEO, AVI, MPEGTS_DEMUXER 
MPEGVIDEO_PARSER MPEGAUDIO_PARSER EXTRACT_EXTRADATA_BSF MP2_DECODER 
ARESAMPLE_FILTER) += fate-copy-trac4914-avi
 fate-copy-trac4914-avi: CMD = transcode mpegts 
$(TARGET_SAMPLES)/mpeg2/xdcam8mp2-1s_small.ts\
diff --git a/tests/ref/fate/copy-trac4914-avi b/tests/ref/fate/copy-trac4914-avi
index 20006ea05c..d598e0aa65 100644
--- a/tests/ref/fate/copy-trac4914-avi
+++ b/tests/ref/fate/copy-trac4914-avi
@@ -1,5 +1,5 @@
-26e4202638bc384b82d2b5eb4d33a5f0 *tests/data/fate/copy-trac4914-avi.avi
-479494 tests/data/fate/copy-trac4914-avi.avi
+3b6f31b806ef421652a066f239536b0d *tests/data/fate/copy-trac4914-avi.avi
+492046 tests/data/fate/copy-trac4914-avi.avi
 #tb 0: 1001/3
 #media_type 0: video
 #codec_id 0: rawvideo

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] tests/fate/mov: add a test for VFR muxing

2024-07-07 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jul  2 
11:34:43 2024 +0200| [24b3bad811f147ebb089048f64fea97a1e627243] | committer: 
Anton Khirnov

tests/fate/mov: add a test for VFR muxing

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=24b3bad811f147ebb089048f64fea97a1e627243
---

 tests/fate/mov.mak | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index b54fe19620..d12980815f 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -218,6 +218,11 @@ fate-mov-pcm-remux: CMD = md5 -i 
$(TARGET_PATH)/tests/data/asynth-44100-1.wav -m
 fate-mov-pcm-remux: CMP = oneline
 fate-mov-pcm-remux: REF = e76115bc392d702da38f523216bba165
 
+FATE_MOV_FFMPEG-$(call TRANSCODE, RAWVIDEO, MOV, TESTSRC_FILTER SETPTS_FILTER) 
+= fate-mov-vfr
+fate-mov-vfr: CMD = md5 -filter_complex testsrc=size=2x2:duration=1,setpts=N*N 
-c rawvideo -fflags +bitexact -f mov
+fate-mov-vfr: CMP = oneline
+fate-mov-vfr: REF = 1558b4a9398d8635783c93f84eb5a60d
+
 FATE_MOV_FFMPEG_FFPROBE-$(call TRANSCODE, FLAC, MOV, WAV_DEMUXER 
PCM_S16LE_DECODER) += fate-mov-mp4-iamf-stereo
 fate-mov-mp4-iamf-stereo: tests/data/asynth-44100-2.wav 
tests/data/streamgroups/audio_element-stereo 
tests/data/streamgroups/mix_presentation-stereo
 fate-mov-mp4-iamf-stereo: SRC = $(TARGET_PATH)/tests/data/asynth-44100-2.wav

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] tests/fate/filter-audio: convert atempo test to oneoff

2024-07-07 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Thu Jul  4 
21:02:25 2024 +0200| [6cde03739e26b65e1ee332f551880ec8851bacb5] | committer: 
Anton Khirnov

tests/fate/filter-audio: convert atempo test to oneoff

Filter output is not bitexact.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6cde03739e26b65e1ee332f551880ec8851bacb5
---

 tests/fate/filter-audio.mak | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tests/fate/filter-audio.mak b/tests/fate/filter-audio.mak
index cf6065b93f..a3f7aaddbf 100644
--- a/tests/fate/filter-audio.mak
+++ b/tests/fate/filter-audio.mak
@@ -414,7 +414,9 @@ fate-filter-hdcd-s32p: REF = 
0c5513e83eedaa10ab6fac9ddc173cf5
 
 FATE_AFILTER_SAMPLES-$(call FILTERDEMDECENCMUX, ATEMPO, WAV, PCM_S16LE, 
PCM_S16LE, WAV) += fate-filter-atempo
 fate-filter-atempo: tests/data/asynth-44100-1.wav
-fate-filter-atempo: CMD = framecrc -i 
$(TARGET_PATH)/tests/data/asynth-44100-1.wav -af "atempo=2.0" -ar 44100
+fate-filter-atempo: CMD = pcm -i $(TARGET_PATH)/tests/data/asynth-44100-1.wav 
-af "atempo=2.0"
+fate-filter-atempo: CMP = oneoff
+fate-filter-atempo: REF = $(SAMPLES)/filter-reference/atempo.pcm
 
 FATE_AFILTER-yes += fate-filter-formats
 fate-filter-formats: libavfilter/tests/formats$(EXESUF)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavf/movenc: mark mov/mp4 as supporting VFR

2024-07-07 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri Mar 29 
09:34:54 2024 +0100| [ef521e7a57fee3ee17f71bb5f9b8d9b0d6bdf3db] | committer: 
Anton Khirnov

lavf/movenc: mark mov/mp4 as supporting VFR

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ef521e7a57fee3ee17f71bb5f9b8d9b0d6bdf3db
---

 libavformat/movenc.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index f8eb6fadf7..3991be0ad4 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -8421,11 +8421,11 @@ const FFOutputFormat ff_mov_muxer = {
 .write_packet  = mov_write_packet,
 .write_trailer = mov_write_trailer,
 .deinit= mov_free,
+.p.flags   = AVFMT_GLOBALHEADER | AVFMT_TS_NEGATIVE | 
AVFMT_VARIABLE_FPS
 #if FF_API_ALLOW_FLUSH
-.p.flags   = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH | 
AVFMT_TS_NEGATIVE,
-#else
-.p.flags   = AVFMT_GLOBALHEADER | AVFMT_TS_NEGATIVE,
+   | AVFMT_ALLOW_FLUSH
 #endif
+ ,
 .p.codec_tag   = (const AVCodecTag* const []){
 ff_codec_movvideo_tags, ff_codec_movaudio_tags, 
ff_codec_movsubtitle_tags, 0
 },
@@ -8473,11 +8473,11 @@ const FFOutputFormat ff_mp4_muxer = {
 .write_packet  = mov_write_packet,
 .write_trailer = mov_write_trailer,
 .deinit= mov_free,
+.p.flags   = AVFMT_GLOBALHEADER | AVFMT_TS_NEGATIVE | 
AVFMT_VARIABLE_FPS
 #if FF_API_ALLOW_FLUSH
-.p.flags   = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH | 
AVFMT_TS_NEGATIVE,
-#else
-.p.flags   = AVFMT_GLOBALHEADER | AVFMT_TS_NEGATIVE,
+   | AVFMT_ALLOW_FLUSH
 #endif
+ ,
 .p.codec_tag   = mp4_codec_tags_list,
 .check_bitstream   = mov_check_bitstream,
 .p.priv_class  = _isobmff_muxer_class,

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] fftools/ffmpeg: rewrite checking whether codec AVOptions have been used

2024-07-03 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Apr  9 
12:56:46 2024 +0200| [f1664aabb18b2d726c3c0c0b7fa8202f3b52b8da] | committer: 
Anton Khirnov

fftools/ffmpeg: rewrite checking whether codec AVOptions have been used

Share the code between encoding and decoding. Instead of checking every
stream's options dictionary (which is also used for other purposes),
track all used options in a dedicated dictionary.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f1664aabb18b2d726c3c0c0b7fa8202f3b52b8da
---

 fftools/cmdutils.c| 17 +-
 fftools/cmdutils.h|  4 +++-
 fftools/ffmpeg.c  | 50 ++
 fftools/ffmpeg.h  |  4 +++-
 fftools/ffmpeg_demux.c| 50 ++
 fftools/ffmpeg_mux.c  |  1 +
 fftools/ffmpeg_mux.h  |  3 +++
 fftools/ffmpeg_mux_init.c | 56 +--
 fftools/ffmpeg_opt.c  | 18 ---
 fftools/ffplay.c  |  2 +-
 fftools/ffprobe.c |  2 +-
 11 files changed, 91 insertions(+), 116 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index a504acb3e4..9b18cf5e4d 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -986,7 +986,7 @@ int check_stream_specifier(AVFormatContext *s, AVStream 
*st, const char *spec)
 
 int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
   AVFormatContext *s, AVStream *st, const AVCodec *codec,
-  AVDictionary **dst)
+  AVDictionary **dst, AVDictionary **opts_used)
 {
 AVDictionary*ret = NULL;
 const AVDictionaryEntry *t = NULL;
@@ -1013,6 +1013,7 @@ int filter_codec_opts(const AVDictionary *opts, enum 
AVCodecID codec_id,
 while (t = av_dict_iterate(opts, t)) {
 const AVClass *priv_class;
 char *p = strchr(t->key, ':');
+int used = 0;
 
 /* check stream specification in opt name */
 if (p) {
@@ -1030,15 +1031,21 @@ int filter_codec_opts(const AVDictionary *opts, enum 
AVCodecID codec_id,
 !codec ||
 ((priv_class = codec->priv_class) &&
  av_opt_find(_class, t->key, NULL, flags,
- AV_OPT_SEARCH_FAKE_OBJ)))
+ AV_OPT_SEARCH_FAKE_OBJ))) {
 av_dict_set(, t->key, t->value, 0);
-else if (t->key[0] == prefix &&
+used = 1;
+} else if (t->key[0] == prefix &&
  av_opt_find(, t->key + 1, NULL, flags,
- AV_OPT_SEARCH_FAKE_OBJ))
+ AV_OPT_SEARCH_FAKE_OBJ)) {
 av_dict_set(, t->key + 1, t->value, 0);
+used = 1;
+}
 
 if (p)
 *p = ':';
+
+if (used && opts_used)
+av_dict_set(opts_used, t->key, "", 0);
 }
 
 *dst = ret;
@@ -1063,7 +1070,7 @@ int setup_find_stream_info_opts(AVFormatContext *s,
 
 for (int i = 0; i < s->nb_streams; i++) {
 ret = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id,
-s, s->streams[i], NULL, [i]);
+s, s->streams[i], NULL, [i], NULL);
 if (ret < 0)
 goto fail;
 }
diff --git a/fftools/cmdutils.h b/fftools/cmdutils.h
index 2125f791d0..14340dff7d 100644
--- a/fftools/cmdutils.h
+++ b/fftools/cmdutils.h
@@ -371,11 +371,13 @@ int check_stream_specifier(AVFormatContext *s, AVStream 
*st, const char *spec);
  * @param codec The particular codec for which the options should be filtered.
  *  If null, the default one is looked up according to the codec 
id.
  * @param dst a pointer to the created dictionary
+ * @param opts_used if non-NULL, every option stored in dst is also stored 
here,
+ *  with specifiers preserved
  * @return a non-negative number on success, a negative error code on failure
  */
 int filter_codec_opts(const AVDictionary *opts, enum AVCodecID codec_id,
   AVFormatContext *s, AVStream *st, const AVCodec *codec,
-  AVDictionary **dst);
+  AVDictionary **dst, AVDictionary **opts_used);
 
 /**
  * Setup AVCodecContext options for avformat_find_stream_info().
diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 8674c4d250..00ab1cce51 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -474,6 +474,56 @@ const FrameData *packet_data_c(AVPacket *pkt)
 return ret < 0 ? NULL : (const FrameData*)pkt->opaque_ref->data;
 }
 
+int check_avoptions_used(const AVDictionary *opts, const AVDictionary 
*opts_used,
+ void *logctx, int decode)
+{
+const AVClass  *class = avcodec_get_class();
+const AVClass *fclass = avformat_get_class();
+
+const int flag = decode ? AV_OPT_FLAG_DECODING_PARAM :
+   

[FFmpeg-cvslog] fftools/ffmpeg_mux_init: make encoder_opts local to ost_add()

2024-07-03 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Apr  9 
14:30:28 2024 +0200| [901f7e3f72fe6005a6fd340882511346e00350b2] | committer: 
Anton Khirnov

fftools/ffmpeg_mux_init: make encoder_opts local to ost_add()

It is no longer needed after this function returns.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=901f7e3f72fe6005a6fd340882511346e00350b2
---

 fftools/ffmpeg.h  |  2 --
 fftools/ffmpeg_mux.c  |  1 -
 fftools/ffmpeg_mux_init.c | 71 ++-
 3 files changed, 40 insertions(+), 34 deletions(-)

diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index e4c8561325..d173475621 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -586,8 +586,6 @@ typedef struct OutputStream {
 FilterGraph  *fg_simple;
 OutputFilter *filter;
 
-AVDictionary *encoder_opts;
-
 char *attachment_filename;
 
 /* stats */
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 80572d7b36..71ff9b45ab 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -812,7 +812,6 @@ static void ost_free(OutputStream **post)
 av_packet_free(>bsf_pkt);
 
 av_packet_free(>pkt);
-av_dict_free(>encoder_opts);
 
 av_freep(>kf.pts);
 av_expr_free(ost->kf.pexpr);
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index cd413e0b7b..899ee6046f 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -905,7 +905,7 @@ static int new_stream_subtitle(Muxer *mux, const 
OptionsContext *o,
 return 0;
 }
 
-static int streamcopy_init(const Muxer *mux, OutputStream *ost)
+static int streamcopy_init(const Muxer *mux, OutputStream *ost, AVDictionary 
**encoder_opts)
 {
 MuxStream   *ms = ms_from_ost(ost);
 
@@ -928,7 +928,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream 
*ost)
 
 ret = avcodec_parameters_to_context(codec_ctx, ist->par);
 if (ret >= 0)
-ret = av_opt_set_dict(codec_ctx, >encoder_opts);
+ret = av_opt_set_dict(codec_ctx, encoder_opts);
 if (ret < 0) {
 av_log(ost, AV_LOG_FATAL,
"Error setting up codec context options.\n");
@@ -1039,6 +1039,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 OutputStream *ost;
 const AVCodec *enc;
 AVStream *st;
+AVDictionary *encoder_opts = NULL;
 int ret = 0, keep_pix_fmt = 0, autoscale = 1;
 int threads_manual = 0;
 AVRational enc_tb = { 0, 0 };
@@ -1160,10 +1161,10 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 const char *enc_time_base = NULL;
 
 ret = filter_codec_opts(o->g->codec_opts, enc->codec_id,
-oc, st, enc->codec, >encoder_opts,
+oc, st, enc->codec, _opts,
 >enc_opts_used);
 if (ret < 0)
-return ret;
+goto fail;
 
 MATCH_PER_STREAM_OPT(presets, str, preset, oc, st);
 
@@ -1187,7 +1188,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 break;
 }
 *arg++ = 0;
-av_dict_set(>encoder_opts, buf, arg, 
AV_DICT_DONT_OVERWRITE);
+av_dict_set(_opts, buf, arg, AV_DICT_DONT_OVERWRITE);
 } while (!s->eof_reached);
 av_bprint_finalize(, NULL);
 avio_closep();
@@ -1195,7 +1196,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 if (ret) {
 av_log(ost, AV_LOG_FATAL,
"Preset %s specified, but could not be opened.\n", preset);
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_stats_pre, str, enc_stats_pre, oc, st);
@@ -1207,7 +1208,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >enc_stats_pre, 1, enc_stats_pre, 
format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_stats_post, str, enc_stats_post, oc, st);
@@ -1219,7 +1220,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >enc_stats_post, 0, enc_stats_post, 
format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(mux_stats, str, mux_stats, oc, st);
@@ -1231,7 +1232,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, 
enum AVMediaType type,
 
 ret = enc_stats_init(ost, >stats, 0, mux_stats, format);
 if (ret < 0)
-return ret;
+goto fail;
 }
 
 MATCH_PER_STREAM_OPT(enc_time_bases, str, enc_time_base, oc, st);
@@ -1253,7 

[FFmpeg-cvslog] fftools/ffmpeg_mux_init: apply encoder options manually

2024-07-03 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Apr  9 
14:11:12 2024 +0200| [9a7686e5458dad8d40b3b3f70f6a19530933468e] | committer: 
Anton Khirnov

fftools/ffmpeg_mux_init: apply encoder options manually

Do not pass an options dictionary to the avcodec_open2() in enc_open().

This is cleaner and more robust, as previously various bits of code
would try to interpret the contents of the options dictionary, with
varying degrees of correctness. Now they can just access the encoder
AVCodecContext directly.

Cf. 372c78dd42f2b1ca743473b9c32fad71c65919e0 - analogous change for
decoding.

A non-progressive field order is now written on the container level in
interlaced ProRes encoding tests.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9a7686e5458dad8d40b3b3f70f6a19530933468e
---

 fftools/ffmpeg_enc.c| 18 ++--
 fftools/ffmpeg_mux_init.c   | 66 +++--
 tests/ref/vsynth/vsynth1-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth1-prores_int |  2 +-
 tests/ref/vsynth/vsynth2-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth2-prores_int |  2 +-
 tests/ref/vsynth/vsynth3-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth3-prores_int |  2 +-
 tests/ref/vsynth/vsynth_lena-prores_444_int |  2 +-
 tests/ref/vsynth/vsynth_lena-prores_int |  2 +-
 10 files changed, 47 insertions(+), 53 deletions(-)

diff --git a/fftools/ffmpeg_enc.c b/fftools/ffmpeg_enc.c
index 928114c20f..c1c8aa0e78 100644
--- a/fftools/ffmpeg_enc.c
+++ b/fftools/ffmpeg_enc.c
@@ -307,16 +307,10 @@ int enc_open(void *opaque, const AVFrame *frame)
 if (ost->bitexact)
 enc_ctx->flags |= AV_CODEC_FLAG_BITEXACT;
 
-if (!av_dict_get(ost->encoder_opts, "threads", NULL, 0))
-av_dict_set(>encoder_opts, "threads", "auto", 0);
+if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE)
+enc_ctx->flags |= AV_CODEC_FLAG_COPY_OPAQUE;
 
-if (enc->capabilities & AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE) {
-ret = av_dict_set(>encoder_opts, "flags", "+copy_opaque", 
AV_DICT_MULTIKEY);
-if (ret < 0)
-return ret;
-}
-
-av_dict_set(>encoder_opts, "flags", "+frame_duration", 
AV_DICT_MULTIKEY);
+enc_ctx->flags |= AV_CODEC_FLAG_FRAME_DURATION;
 
 ret = hw_device_setup_for_encode(ost, frame ? frame->hw_frames_ctx : NULL);
 if (ret < 0) {
@@ -325,7 +319,7 @@ int enc_open(void *opaque, const AVFrame *frame)
 return ret;
 }
 
-if ((ret = avcodec_open2(ost->enc_ctx, enc, >encoder_opts)) < 0) {
+if ((ret = avcodec_open2(ost->enc_ctx, enc, NULL)) < 0) {
 if (ret != AVERROR_EXPERIMENTAL)
 av_log(ost, AV_LOG_ERROR, "Error while opening encoder - maybe "
"incorrect parameters such as bit_rate, rate, width or 
height.\n");
@@ -337,10 +331,6 @@ int enc_open(void *opaque, const AVFrame *frame)
 if (ost->enc_ctx->frame_size)
 frame_samples = ost->enc_ctx->frame_size;
 
-ret = check_avoptions(ost->encoder_opts);
-if (ret < 0)
-return ret;
-
 if (ost->enc_ctx->bit_rate && ost->enc_ctx->bit_rate < 1000 &&
 ost->enc_ctx->codec_id != AV_CODEC_ID_CODEC2 /* don't complain about 
700 bit/s modes */)
 av_log(ost, AV_LOG_WARNING, "The bitrate parameter is set too low."
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index da68d1e5f0..cd413e0b7b 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -711,14 +711,10 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
 /* two pass mode */
 MATCH_PER_STREAM_OPT(pass, i, do_pass, oc, st);
 if (do_pass) {
-if (do_pass & 1) {
+if (do_pass & 1)
 video_enc->flags |= AV_CODEC_FLAG_PASS1;
-av_dict_set(>encoder_opts, "flags", "+pass1", 
AV_DICT_APPEND);
-}
-if (do_pass & 2) {
+if (do_pass & 2)
 video_enc->flags |= AV_CODEC_FLAG_PASS2;
-av_dict_set(>encoder_opts, "flags", "+pass2", 
AV_DICT_APPEND);
-}
 }
 
 MATCH_PER_STREAM_OPT(passlogfiles, str, ost->logfile_prefix, oc, st);
@@ -740,7 +736,10 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
DEFAULT_PASS_LOGFILENAME_PREFIX,
  ost_idx);
 if (!strcmp(ost->enc_ctx->codec->name, "libx264") || 
!strcmp(ost->enc_ctx->codec->name, "libvvenc")) {
-av_dict_set(>encoder_opts, "stats", logfilename, 
AV_DICT_DONT_OVERWRITE);
+  

[FFmpeg-cvslog] lavc/hevcdec: improve check for PPS changing between slices

2024-07-02 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jun 26 
14:41:41 2024 +0200| [e939f02ce67f2af570115214d2d5a6d93501dd80] | committer: 
Anton Khirnov

lavc/hevcdec: improve check for PPS changing between slices

Compare actual PPS objects rather than just PPS ID, as the former might
change while the latter stays the same.

Reported-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e939f02ce67f2af570115214d2d5a6d93501dd80
---

 libavcodec/hevc/hevcdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 01d32086f2..fd143cddab 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -603,7 +603,7 @@ static int hls_slice_header(SliceHeader *sh, const 
HEVCContext *s, GetBitContext
 av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
 return AVERROR_INVALIDDATA;
 }
-if (!sh->first_slice_in_pic_flag && pps_id != sh->pps_id) {
+if (!sh->first_slice_in_pic_flag && s->ps.pps_list[pps_id] != s->pps) {
 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
 return AVERROR_INVALIDDATA;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: do not pass a pixel format to set_sps()

2024-07-02 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jun 12 
10:47:01 2024 +0200| [99b0c3dc7c5380cb3888daca8d7ad0454e789ba8] | committer: 
Anton Khirnov

lavc/hevcdec: do not pass a pixel format to set_sps()

It is merely copied to AVCodecContext.pix_fmt, which serves no useful
purpose. set_sps() is called from two places:
* when a new SPS becomes active - then the pixel format is
  overridden immediately after the set_sps() call by the result from
  ff_get_format();
* when a new SPS is propagated across frame threads - then the
  AVCodecContext value is already set to the same value by the generic
  code.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=99b0c3dc7c5380cb3888daca8d7ad0454e789ba8
---

 libavcodec/hevc/hevcdec.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 4a62170073..5136bb53d9 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -526,8 +526,7 @@ static enum AVPixelFormat get_format(HEVCContext *s, const 
HEVCSPS *sps)
 return ff_get_format(s->avctx, pix_fmts);
 }
 
-static int set_sps(HEVCContext *s, const HEVCSPS *sps,
-   enum AVPixelFormat pix_fmt)
+static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 {
 int ret, i;
 
@@ -544,8 +543,6 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
 
 export_stream_params(s, sps);
 
-s->avctx->pix_fmt = pix_fmt;
-
 ff_hevc_pred_init(>hpc, sps->bit_depth);
 ff_hevc_dsp_init (>hevcdsp, sps->bit_depth);
 ff_videodsp_init (>vdsp,sps->bit_depth);
@@ -2918,7 +2915,7 @@ static int hevc_frame_start(HEVCContext *s)
 
 ff_hevc_clear_refs(s);
 
-ret = set_sps(s, sps, sps->pix_fmt);
+ret = set_sps(s, sps);
 if (ret < 0)
 return ret;
 
@@ -3592,7 +3589,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 ff_refstruct_unref(>pps);
 
 if (s->ps.sps != s0->ps.sps)
-if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0)
+if ((ret = set_sps(s, s0->ps.sps)) < 0)
 return ret;
 
 s->seq_decode = s0->seq_decode;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move export_stream_params() from set_sps() to hevc_frame_start()

2024-07-02 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jun 26 
14:36:31 2024 +0200| [5861576f39c8b40dabaf5d5d7e37b2e8eec51535] | committer: 
Anton Khirnov

lavc/hevcdec: move export_stream_params() from set_sps() to hevc_frame_start()

The only other caller of set_sps() --- hevc_update_thread_context() ---
does not need to call export_stream_params(), since it only updates
AVCodecContext fields that have already been updated by generic code.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5861576f39c8b40dabaf5d5d7e37b2e8eec51535
---

 libavcodec/hevc/hevcdec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5136bb53d9..01d32086f2 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -541,8 +541,6 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps)
 if (ret < 0)
 goto fail;
 
-export_stream_params(s, sps);
-
 ff_hevc_pred_init(>hpc, sps->bit_depth);
 ff_hevc_dsp_init (>hevcdsp, sps->bit_depth);
 ff_videodsp_init (>vdsp,sps->bit_depth);
@@ -2919,6 +2917,8 @@ static int hevc_frame_start(HEVCContext *s)
 if (ret < 0)
 return ret;
 
+export_stream_params(s, sps);
+
 pix_fmt = get_format(s, sps);
 if (pix_fmt < 0)
 return pix_fmt;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: do not call export_stream_params_from_sei() in update_thread_context()

2024-07-02 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jun 25 
16:53:30 2024 +0200| [5295650655ec13efe260a27d7f27572a4f0ab07e] | committer: 
Anton Khirnov

lavc/hevcdec: do not call export_stream_params_from_sei() in 
update_thread_context()

It is redundant, since it only sets AVCodecContext fields that are
already copied by the generic code.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5295650655ec13efe260a27d7f27572a4f0ab07e
---

 libavcodec/hevc/hevcdec.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e80f2f28c7..4a62170073 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3637,10 +3637,6 @@ static int hevc_update_thread_context(AVCodecContext 
*dst,
 s->sei.common.content_light= s0->sei.common.content_light;
 s->sei.common.aom_film_grain   = s0->sei.common.aom_film_grain;
 
-ret = export_stream_params_from_sei(s);
-if (ret < 0)
-return ret;
-
 return 0;
 }
 #endif

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: call export_stream_params_from_sei() before ff_get_buffer()

2024-07-02 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue Jun 25 
16:50:17 2024 +0200| [fd69700e5150d13deabdc3f17ce76032b05fb118] | committer: 
Anton Khirnov

lavc/hevcdec: call export_stream_params_from_sei() before ff_get_buffer()

So that correct values of color_trc are set on the allocated frame.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fd69700e5150d13deabdc3f17ce76032b05fb118
---

 libavcodec/hevc/hevcdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 1d2e53afc3..e80f2f28c7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2964,6 +2964,10 @@ static int hevc_frame_start(HEVCContext *s)
 if (pps->tiles_enabled_flag)
 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << 
sps->log2_ctb_size;
 
+ret = export_stream_params_from_sei(s);
+if (ret < 0)
+return ret;
+
 ret = ff_hevc_set_new_ref(s, s->poc);
 if (ret < 0)
 goto fail;
@@ -2984,10 +2988,6 @@ static int hevc_frame_start(HEVCContext *s)
 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 !s->avctx->hwaccel;
 
-ret = export_stream_params_from_sei(s);
-if (ret < 0)
-return ret;
-
 ret = set_side_data(s);
 if (ret < 0)
 goto fail;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: always call hevc_frame_end() after successfully decoding an AU

2024-06-13 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jun 12 
10:08:02 2024 +0200| [0060a368b175b1cbc01800af2d3d17ca9f88970c] | committer: 
Anton Khirnov

lavc/hevcdec: always call hevc_frame_end() after successfully decoding an AU

Currently it is only done if the final CTB address is at the end of the
frame, however that address is not known with hwaccel decoding. As we
only support exactly one AU per packet, and not partial/multiple AUs, we
can just as well call hevc_frame_end() unconditionally.

Fixes hwaccel decoding after d725c737fe2a19091b481d4d115fd939e0a674b2.

Reported-by: llyyr 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0060a368b175b1cbc01800af2d3d17ca9f88970c
---

 libavcodec/hevc/hevcdec.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 88f2bcecad..4b95358b95 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3192,11 +3192,6 @@ static int decode_slice(HEVCContext *s, const H2645NAL 
*nal, GetBitContext *gb)
 ret = decode_slice_data(s, nal, gb);
 if (ret < 0)
 return ret;
-if (ret >= s->cur_frame->ctb_count) {
-ret = hevc_frame_end(s);
-if (ret < 0)
-return ret;
-}
 
 return 0;
 }
@@ -3370,8 +3365,13 @@ static int decode_nal_units(HEVCContext *s, const 
uint8_t *buf, int length)
 }
 
 fail:
-if (s->cur_frame && s->avctx->active_thread_type == FF_THREAD_FRAME)
-ff_progress_frame_report(>cur_frame->tf, INT_MAX);
+if (s->cur_frame) {
+if (ret >= 0)
+ret = hevc_frame_end(s);
+
+if (s->avctx->active_thread_type == FF_THREAD_FRAME)
+ff_progress_frame_report(>cur_frame->tf, INT_MAX);
+}
 
 return ret;
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: constify source frame in hevc_ref_frame()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Jun  5 
07:09:31 2024 +0200| [08ea7d6b8e1efaa613ec24bbc5310ce912e2490d] | committer: 
Anton Khirnov

lavc/hevcdec: constify source frame in hevc_ref_frame()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=08ea7d6b8e1efaa613ec24bbc5310ce912e2490d
---

 libavcodec/hevc/hevcdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5fc55d5de9..88f2bcecad 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3449,7 +3449,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, 
AVFrame *rframe,
 return avpkt->size;
 }
 
-static int hevc_ref_frame(HEVCFrame *dst, HEVCFrame *src)
+static int hevc_ref_frame(HEVCFrame *dst, const HEVCFrame *src)
 {
 int ret;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: do not unref current frame on frame_end() failure

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
20:26:21 2024 +0200| [ccd391d6a3afaa2e47f01ac51789082f1a39f03e] | committer: 
Anton Khirnov

lavc/hevcdec: do not unref current frame on frame_end() failure

It's a race with frame threading.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ccd391d6a3afaa2e47f01ac51789082f1a39f03e
---

 libavcodec/hevc/hevcdec.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a8c2172674..5fc55d5de9 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3135,17 +3135,14 @@ static int hevc_frame_end(HEVCContext *s)
 if (ret < 0) {
 av_log(s->avctx, AV_LOG_ERROR,
"hardware accelerator failed to decode picture\n");
-ff_hevc_unref_frame(s->cur_frame, ~0);
 return ret;
 }
 } else {
 if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
 s->sei.picture_hash.is_md5) {
 ret = verify_md5(s, s->cur_frame->f);
-if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) {
-ff_hevc_unref_frame(s->cur_frame, ~0);
+if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
 return ret;
-}
 }
 }
 s->sei.picture_hash.is_md5 = 0;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move some frame-end code to hevc_frame_end()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
14:37:25 2024 +0200| [d725c737fe2a19091b481d4d115fd939e0a674b2] | committer: 
Anton Khirnov

lavc/hevcdec: move some frame-end code to hevc_frame_end()

Specifically, calling hwaccel end_frame, verifying frame checksum,
and printing the frame-was-decoded message.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d725c737fe2a19091b481d4d115fd939e0a674b2
---

 libavcodec/hevc/hevcdec.c | 187 ++
 libavcodec/hevc/hevcdec.h |   1 -
 2 files changed, 91 insertions(+), 97 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 7263b80a24..a8c2172674 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2942,7 +2942,6 @@ static int hevc_frame_start(HEVCContext *s)
 ff_hevc_clear_refs(s);
 }
 
-s->is_decoded= 0;
 s->slice_idx = 0;
 s->first_nal_type= s->nal_unit_type;
 s->poc   = s->sh.poc;
@@ -3038,6 +3037,75 @@ fail:
 return ret;
 }
 
+static int verify_md5(HEVCContext *s, AVFrame *frame)
+{
+const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
+char msg_buf[4 * (50 + 2 * 2 * 16 /* MD5-size */)];
+int pixel_shift;
+int err = 0;
+int i, j;
+
+if (!desc)
+return AVERROR(EINVAL);
+
+pixel_shift = desc->comp[0].depth > 8;
+
+/* the checksums are LE, so we have to byteswap for >8bpp formats
+ * on BE arches */
+#if HAVE_BIGENDIAN
+if (pixel_shift && !s->checksum_buf) {
+av_fast_malloc(>checksum_buf, >checksum_buf_size,
+   FFMAX3(frame->linesize[0], frame->linesize[1],
+  frame->linesize[2]));
+if (!s->checksum_buf)
+return AVERROR(ENOMEM);
+}
+#endif
+
+msg_buf[0] = '\0';
+for (i = 0; frame->data[i]; i++) {
+int width  = s->avctx->coded_width;
+int height = s->avctx->coded_height;
+int w = (i == 1 || i == 2) ? (width  >> desc->log2_chroma_w) : width;
+int h = (i == 1 || i == 2) ? (height >> desc->log2_chroma_h) : height;
+uint8_t md5[16];
+
+av_md5_init(s->md5_ctx);
+for (j = 0; j < h; j++) {
+const uint8_t *src = frame->data[i] + j * frame->linesize[i];
+#if HAVE_BIGENDIAN
+if (pixel_shift) {
+s->bdsp.bswap16_buf((uint16_t *) s->checksum_buf,
+(const uint16_t *) src, w);
+src = s->checksum_buf;
+}
+#endif
+av_md5_update(s->md5_ctx, src, w << pixel_shift);
+}
+av_md5_final(s->md5_ctx, md5);
+
+#define MD5_PRI "%016" PRIx64 "%016" PRIx64
+#define MD5_PRI_ARG(buf) AV_RB64(buf), AV_RB64((const uint8_t*)(buf) + 8)
+
+if (!memcmp(md5, s->sei.picture_hash.md5[i], 16)) {
+av_strlcatf(msg_buf, sizeof(msg_buf),
+"plane %d - correct " MD5_PRI "; ",
+i, MD5_PRI_ARG(md5));
+} else {
+av_strlcatf(msg_buf, sizeof(msg_buf),
+   "mismatching checksum of plane %d - " MD5_PRI " != " 
MD5_PRI "; ",
+i, MD5_PRI_ARG(md5), 
MD5_PRI_ARG(s->sei.picture_hash.md5[i]));
+err = AVERROR_INVALIDDATA;
+}
+}
+
+av_log(s->avctx, err < 0 ? AV_LOG_ERROR : AV_LOG_DEBUG,
+   "Verifying checksum for frame with POC %d: %s\n",
+   s->poc, msg_buf);
+
+return err;
+}
+
 static int hevc_frame_end(HEVCContext *s)
 {
 HEVCFrame *out = s->cur_frame;
@@ -3062,6 +3130,28 @@ static int hevc_frame_end(HEVCContext *s)
 av_assert1(ret >= 0);
 }
 
+if (s->avctx->hwaccel) {
+ret = FF_HW_SIMPLE_CALL(s->avctx, end_frame);
+if (ret < 0) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "hardware accelerator failed to decode picture\n");
+ff_hevc_unref_frame(s->cur_frame, ~0);
+return ret;
+}
+} else {
+if (s->avctx->err_recognition & AV_EF_CRCCHECK &&
+s->sei.picture_hash.is_md5) {
+ret = verify_md5(s, s->cur_frame->f);
+if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE) {
+ff_hevc_unref_frame(s->cur_frame, ~0);
+return ret;
+}
+}
+}
+s->sei.picture_hash.is_md5 = 0;
+
+av_log(s->avctx, AV_LOG_DEBUG, "Decoded frame with POC %d.\n", s->poc);
+
 return 0;
 }
 
@@ -3109,7 +3199,6 @@ static int decode_slice(HEVCContext *s, const H2645NAL 
*nal, GetBitContext *gb)
 ret = hevc_frame_end(s);
 

[FFmpeg-cvslog] lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
11:41:23 2024 +0200| [edb6a471c4b3b96845c84772393b74f52e970f45] | committer: 
Anton Khirnov

lavc/hevcdec: factor decoding a slice NALU out of decode_nal_unit()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=edb6a471c4b3b96845c84772393b74f52e970f45
---

 libavcodec/hevc/hevcdec.c | 97 +--
 1 file changed, 52 insertions(+), 45 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index b9aea45edb..7263b80a24 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3065,10 +3065,60 @@ static int hevc_frame_end(HEVCContext *s)
 return 0;
 }
 
+static int decode_slice(HEVCContext *s, const H2645NAL *nal, GetBitContext *gb)
+{
+int ret;
+
+ret = hls_slice_header(>sh, s, gb);
+if (ret < 0)
+return ret;
+
+if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
+(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != 
HEVC_SLICE_I) ||
+(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
+((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == 
HEVC_NAL_RASL_N) &&
+ s->no_rasl_output_flag)) {
+return 0;
+}
+
+if (s->sh.first_slice_in_pic_flag) {
+if (s->cur_frame) {
+av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the 
first in the same frame.\n");
+return AVERROR_INVALIDDATA;
+}
+
+ret = hevc_frame_start(s);
+if (ret < 0)
+return ret;
+} else if (!s->cur_frame) {
+av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame missing.\n");
+return AVERROR_INVALIDDATA;
+}
+
+if (s->nal_unit_type != s->first_nal_type) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "Non-matching NAL types of the VCL NALUs: %d %d\n",
+   s->first_nal_type, s->nal_unit_type);
+return AVERROR_INVALIDDATA;
+}
+
+ret = decode_slice_data(s, nal, gb);
+if (ret < 0)
+return ret;
+if (ret >= s->cur_frame->ctb_count) {
+ret = hevc_frame_end(s);
+if (ret < 0)
+return ret;
+s->is_decoded = 1;
+}
+
+return 0;
+}
+
 static int decode_nal_unit(HEVCContext *s, const H2645NAL *nal)
 {
 GetBitContext gb = nal->gb;
-int ctb_addr_ts, ret;
+int ret;
 
 s->nal_unit_type = nal->type;
 s->temporal_id   = nal->temporal_id;
@@ -3124,52 +3174,9 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 case HEVC_NAL_RADL_R:
 case HEVC_NAL_RASL_N:
 case HEVC_NAL_RASL_R:
-ret = hls_slice_header(>sh, s, );
+ret = decode_slice(s, nal, );
 if (ret < 0)
-return ret;
-
-if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
-(s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != 
HEVC_SLICE_I) ||
-(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
-((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == 
HEVC_NAL_RASL_N) &&
- s->no_rasl_output_flag)) {
-break;
-}
-
-if (s->sh.first_slice_in_pic_flag) {
-if (s->cur_frame) {
-av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the 
first in the same frame.\n");
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
-
-ret = hevc_frame_start(s);
-if (ret < 0)
-return ret;
-} else if (!s->cur_frame) {
-av_log(s->avctx, AV_LOG_ERROR, "First slice in a frame 
missing.\n");
 goto fail;
-}
-
-if (s->nal_unit_type != s->first_nal_type) {
-av_log(s->avctx, AV_LOG_ERROR,
-   "Non-matching NAL types of the VCL NALUs: %d %d\n",
-   s->first_nal_type, s->nal_unit_type);
-return AVERROR_INVALIDDATA;
-}
-
-ctb_addr_ts = decode_slice_data(s, nal, );
-if (ctb_addr_ts >= s->cur_frame->ctb_count) {
-ret = hevc_frame_end(s);
-if (ret < 0)
-goto fail;
-s->is_decoded = 1;
-}
-
-if (ctb_addr_ts < 0) {
-ret = ctb_addr_ts;
-goto fail;
-}
 break;
 case HEVC_NAL_EOS_NUT:
 case HEVC_NAL_EOB_NUT:

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: drop a redundant multiple-frame-per-packet check

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
11:35:39 2024 +0200| [90e75c4ec9b0886a7b96482d2a4dc5e693ca15d1] | committer: 
Anton Khirnov

lavc/hevcdec: drop a redundant multiple-frame-per-packet check

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90e75c4ec9b0886a7b96482d2a4dc5e693ca15d1
---

 libavcodec/hevc/hevcdec.c | 4 
 libavcodec/hevc/hevcdec.h | 1 -
 2 files changed, 5 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a241e25196..b9aea45edb 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3143,7 +3143,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 goto fail;
 }
 
-s->overlap ++;
 ret = hevc_frame_start(s);
 if (ret < 0)
 return ret;
@@ -3204,7 +3203,6 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 s->cur_frame = s->collocated_ref = NULL;
 s->last_eos = s->eos;
 s->eos = 0;
-s->overlap = 0;
 s->slice_initialized = 0;
 
 /* split the input packet into NAL units, so we know the upper bound on the
@@ -3271,8 +3269,6 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 continue;
 
 ret = decode_nal_unit(s, nal);
-if (ret >= 0 && s->overlap > 2)
-ret = AVERROR_INVALIDDATA;
 if (ret < 0) {
 av_log(s->avctx, AV_LOG_WARNING,
"Error parsing NAL unit #%d.\n", i);
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index e47a7107c8..f0443b3ab9 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -487,7 +487,6 @@ typedef struct HEVCContext {
 int last_eos;  ///< last packet contains an EOS/EOB NAL
 int bs_width;
 int bs_height;
-int overlap;
 
 int is_decoded;
 // NoRaslOutputFlag associated with the last IRAP frame

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move the check for multiple frames in a packet

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
11:31:24 2024 +0200| [3cd6492fb5e7bb4b6e0fdada2d2277b405b1236a] | committer: 
Anton Khirnov

lavc/hevcdec: move the check for multiple frames in a packet

Do not do it in hls_slice_header(), which is the wrong place for it.
Avoids special magic return value of 1 in that function. The comment
mentioning potential corrupted state is no longer relevant, as
hls_slice_header() modifies no state beyond SliceHeader, which will only
get used for a valid frame.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3cd6492fb5e7bb4b6e0fdada2d2277b405b1236a
---

 libavcodec/hevc/hevcdec.c | 14 ++
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2809e1e61d..a241e25196 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -598,10 +598,6 @@ static int hls_slice_header(SliceHeader *sh, const 
HEVCContext *s, GetBitContext
 
 // Coded parameters
 sh->first_slice_in_pic_flag = get_bits1(gb);
-if (s->cur_frame && sh->first_slice_in_pic_flag) {
-av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the first 
in the same frame.\n");
-return 1; // This slice will be skipped later, do not corrupt state
-}
 
 sh->no_output_of_prior_pics_flag = 0;
 if (IS_IRAP(s))
@@ -3131,10 +3127,6 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 ret = hls_slice_header(>sh, s, );
 if (ret < 0)
 return ret;
-if (ret == 1) {
-ret = AVERROR_INVALIDDATA;
-goto fail;
-}
 
 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != 
HEVC_SLICE_I) ||
@@ -3145,6 +3137,12 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 }
 
 if (s->sh.first_slice_in_pic_flag) {
+if (s->cur_frame) {
+av_log(s->avctx, AV_LOG_ERROR, "Two slices reporting being the 
first in the same frame.\n");
+ret = AVERROR_INVALIDDATA;
+goto fail;
+}
+
 s->overlap ++;
 ret = hevc_frame_start(s);
 if (ret < 0)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move setting slice_initialized out of hls_slice_header()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
11:09:26 2024 +0200| [a8f9d52c227841929959cd414398cfa426b6024e] | committer: 
Anton Khirnov

lavc/hevcdec: move setting slice_initialized out of hls_slice_header()

hls_slice_header() no longer modifies anything in HEVCContext besides
SliceHeader.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a8f9d52c227841929959cd414398cfa426b6024e
---

 libavcodec/hevc/hevcdec.c | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index b13e3e06a3..2809e1e61d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -589,9 +589,8 @@ fail:
 return ret;
 }
 
-static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
+static int hls_slice_header(SliceHeader *sh, const HEVCContext *s, 
GetBitContext *gb)
 {
-SliceHeader *sh   = >sh;
 const HEVCPPS *pps;
 const HEVCSPS *sps;
 unsigned pps_id;
@@ -647,12 +646,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 }
 } else {
 sh->slice_segment_addr = sh->slice_addr = 0;
-s->slice_initialized   = 0;
 }
 
 if (!sh->dependent_slice_segment_flag) {
-s->slice_initialized = 0;
-
 for (i = 0; i < pps->num_extra_slice_header_bits; i++)
 skip_bits(gb, 1);  // slice_reserved_undetermined_flag[]
 
@@ -991,8 +987,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 return AVERROR_INVALIDDATA;
 }
 
-s->slice_initialized = 1;
-
 return 0;
 }
 
@@ -2798,6 +2792,8 @@ static int decode_slice_data(HEVCContext *s, const 
H2645NAL *nal, GetBitContext
 }
 }
 
+s->slice_initialized = 1;
+
 if (s->avctx->hwaccel)
 return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, 
nal->raw_size);
 
@@ -3042,6 +3038,7 @@ fail:
 if (s->cur_frame)
 ff_hevc_unref_frame(s->cur_frame, ~0);
 s->cur_frame = s->collocated_ref = NULL;
+s->slice_initialized = 0;
 return ret;
 }
 
@@ -3131,7 +3128,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 case HEVC_NAL_RADL_R:
 case HEVC_NAL_RASL_N:
 case HEVC_NAL_RASL_R:
-ret = hls_slice_header(s, );
+ret = hls_slice_header(>sh, s, );
 if (ret < 0)
 return ret;
 if (ret == 1) {
@@ -3139,7 +3136,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 goto fail;
 }
 
-
 if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != 
HEVC_SLICE_I) ||
 (s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
@@ -3211,6 +3207,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t 
*buf, int length)
 s->last_eos = s->eos;
 s->eos = 0;
 s->overlap = 0;
+s->slice_initialized = 0;
 
 /* split the input packet into NAL units, so we know the upper bound on the
  * number of slices in the frame */

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
14:02:52 2024 +0200| [fe171a3b51a1f20ff34159fe75ec44ed0c256348] | committer: 
Anton Khirnov

lavc/hevcdec: move calling hwaccel decode_slice to decode_slice_data()

>From decode_nal_unit(), as that is a more appropriate place for it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fe171a3b51a1f20ff34159fe75ec44ed0c256348
---

 libavcodec/hevc/hevcdec.c | 38 +-
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 0bf68ea45c..c148244361 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2811,6 +2811,15 @@ static int decode_slice_data(HEVCContext *s, const 
H2645NAL *nal, GetBitContext
 }
 }
 
+if (s->avctx->hwaccel)
+return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, 
nal->raw_size);
+
+if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
+av_log(s->avctx, AV_LOG_ERROR,
+   "SCC profile is not yet implemented in hevc native decoder.\n");
+return AVERROR_PATCHWELCOME;
+}
+
 s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
 
 if (!pps->cu_qp_delta_enabled_flag)
@@ -3152,30 +3161,17 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 }
 }
 
-if (s->avctx->hwaccel) {
-ret = FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, 
nal->raw_size);
+ctb_addr_ts = decode_slice_data(s, nal, );
+if (ctb_addr_ts >= s->cur_frame->ctb_count) {
+ret = hevc_frame_end(s);
 if (ret < 0)
 goto fail;
-} else {
-if (s->avctx->profile == AV_PROFILE_HEVC_SCC) {
-av_log(s->avctx, AV_LOG_ERROR,
-   "SCC profile is not yet implemented in hevc native 
decoder.\n");
-ret = AVERROR_PATCHWELCOME;
-goto fail;
-}
-
-ctb_addr_ts = decode_slice_data(s, nal, );
-if (ctb_addr_ts >= s->cur_frame->ctb_count) {
-ret = hevc_frame_end(s);
-if (ret < 0)
-goto fail;
-s->is_decoded = 1;
-}
+s->is_decoded = 1;
+}
 
-if (ctb_addr_ts < 0) {
-ret = ctb_addr_ts;
-goto fail;
-}
+if (ctb_addr_ts < 0) {
+ret = ctb_addr_ts;
+goto fail;
 }
 break;
 case HEVC_NAL_EOS_NUT:

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
10:21:42 2024 +0200| [82ded1ad3a79ad453e82ec317dc58dba91f900a0] | committer: 
Anton Khirnov

lavc/hevcdec: move sequence increment/IDR handling to hevc_frame_start()

>From hls_slice_header(). It is only done once per frame, so that is a
more appropriate place for this code.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=82ded1ad3a79ad453e82ec317dc58dba91f900a0
---

 libavcodec/hevc/hevcdec.c | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 9abae3260d..b13e3e06a3 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -604,11 +604,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 return 1; // This slice will be skipped later, do not corrupt state
 }
 
-if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-if (IS_IDR(s))
-ff_hevc_clear_refs(s);
-}
 sh->no_output_of_prior_pics_flag = 0;
 if (IS_IRAP(s))
 sh->no_output_of_prior_pics_flag = get_bits1(gb);
@@ -2949,6 +2944,12 @@ static int hevc_frame_start(HEVCContext *s)
 memset(s->is_pcm,0, (sps->min_pu_width + 1) * (sps->min_pu_height 
+ 1));
 memset(s->tab_slice_address, -1, pic_size_in_ctb * 
sizeof(*s->tab_slice_address));
 
+if ((IS_IDR(s) || IS_BLA(s))) {
+s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
+if (IS_IDR(s))
+ff_hevc_clear_refs(s);
+}
+
 s->is_decoded= 0;
 s->slice_idx = 0;
 s->first_nal_type= s->nal_unit_type;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
14:02:52 2024 +0200| [6ee550d83d155225c3f57b49b22a992c9d4e59f8] | committer: 
Anton Khirnov

lavc/hevcdec: move calling hwaccel start_frame to hevc_frame_start()

>From decode_nal_unit(), as that is a more appropriate place for it.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6ee550d83d155225c3f57b49b22a992c9d4e59f8
---

 libavcodec/hevc/hevcdec.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index cda52e05ef..0bf68ea45c 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3006,7 +3006,11 @@ static int hevc_frame_start(HEVCContext *s)
 if (ret < 0)
 goto fail;
 
-if (!s->avctx->hwaccel)
+if (s->avctx->hwaccel) {
+ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
+if (ret < 0)
+goto fail;
+} else
 ff_thread_finish_setup(s->avctx);
 
 return 0;
@@ -3148,12 +3152,6 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 }
 }
 
-if (s->sh.first_slice_in_pic_flag && s->avctx->hwaccel) {
-ret = FF_HW_CALL(s->avctx, start_frame, NULL, 0);
-if (ret < 0)
-goto fail;
-}
-
 if (s->avctx->hwaccel) {
 ret = FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, 
nal->raw_size);
 if (ret < 0)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: set active PPS/SPS in hevc_frame_start()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Mon Jun  3 
09:56:09 2024 +0200| [a2e77caf37c90837eb543a268ec5cc3ba5465ca4] | committer: 
Anton Khirnov

lavc/hevcdec: set active PPS/SPS in hevc_frame_start()

Not in hls_slice_header(), as it should only be done once per frame.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a2e77caf37c90837eb543a268ec5cc3ba5465ca4
---

 libavcodec/hevc/hevcdec.c | 52 ---
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 804cceac3e..9abae3260d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -594,6 +594,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 SliceHeader *sh   = >sh;
 const HEVCPPS *pps;
 const HEVCSPS *sps;
+unsigned pps_id;
 int i, ret;
 
 // Coded parameters
@@ -612,40 +613,23 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 if (IS_IRAP(s))
 sh->no_output_of_prior_pics_flag = get_bits1(gb);
 
-sh->pps_id = get_ue_golomb_long(gb);
-if (sh->pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[sh->pps_id]) {
-av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", 
sh->pps_id);
+pps_id = get_ue_golomb_long(gb);
+if (pps_id >= HEVC_MAX_PPS_COUNT || !s->ps.pps_list[pps_id]) {
+av_log(s->avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
 return AVERROR_INVALIDDATA;
 }
-if (!sh->first_slice_in_pic_flag &&
-s->pps != s->ps.pps_list[sh->pps_id]) {
+if (!sh->first_slice_in_pic_flag && pps_id != sh->pps_id) {
 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
 return AVERROR_INVALIDDATA;
 }
-ff_refstruct_replace(>pps, s->ps.pps_list[sh->pps_id]);
-pps = s->pps;
+sh->pps_id = pps_id;
+
+pps = s->ps.pps_list[pps_id];
 sps = pps->sps;
 
 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
 sh->no_output_of_prior_pics_flag = 1;
 
-if (s->ps.sps != sps) {
-enum AVPixelFormat pix_fmt;
-
-ff_hevc_clear_refs(s);
-
-ret = set_sps(s, sps, sps->pix_fmt);
-if (ret < 0)
-return ret;
-
-pix_fmt = get_format(s, sps);
-if (pix_fmt < 0)
-return pix_fmt;
-s->avctx->pix_fmt = pix_fmt;
-
-s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-}
-
 sh->dependent_slice_segment_flag = 0;
 if (!sh->first_slice_in_pic_flag) {
 int slice_address_length;
@@ -2935,12 +2919,30 @@ static int set_side_data(HEVCContext *s)
 
 static int hevc_frame_start(HEVCContext *s)
 {
-const HEVCPPS *const pps = s->pps;
+const HEVCPPS *const pps = s->ps.pps_list[s->sh.pps_id];
 const HEVCSPS *const sps = pps->sps;
 int pic_size_in_ctb  = ((sps->width  >> sps->log2_min_cb_size) + 1) *
((sps->height >> sps->log2_min_cb_size) + 1);
 int ret;
 
+ff_refstruct_replace(>pps, pps);
+if (s->ps.sps != sps) {
+enum AVPixelFormat pix_fmt;
+
+ff_hevc_clear_refs(s);
+
+ret = set_sps(s, sps, sps->pix_fmt);
+if (ret < 0)
+return ret;
+
+pix_fmt = get_format(s, sps);
+if (pix_fmt < 0)
+return pix_fmt;
+s->avctx->pix_fmt = pix_fmt;
+
+s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
+}
+
 memset(s->horizontal_bs, 0, s->bs_width * s->bs_height);
 memset(s->vertical_bs,   0, s->bs_width * s->bs_height);
 memset(s->cbf_luma,  0, sps->min_tb_width * sps->min_tb_height);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move constructing slice RPL to decode_slice_data()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
19:55:01 2024 +0200| [47d34ba7fbb811e23ea4485cf8066e3a045e74f8] | committer: 
Anton Khirnov

lavc/hevcdec: move constructing slice RPL to decode_slice_data()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=47d34ba7fbb811e23ea4485cf8066e3a045e74f8
---

 libavcodec/hevc/hevcdec.c | 25 +
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index c148244361..804cceac3e 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -665,11 +665,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 
 if (!sh->dependent_slice_segment_flag) {
 sh->slice_addr = sh->slice_segment_addr;
-s->slice_idx++;
 }
 } else {
 sh->slice_segment_addr = sh->slice_addr = 0;
-s->slice_idx   = 0;
 s->slice_initialized   = 0;
 }
 
@@ -2801,6 +2799,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, 
GetBitContext *gb)
 {
 const HEVCPPS *pps = s->pps;
+int ret;
 
 if (s->sh.dependent_slice_segment_flag) {
 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
@@ -2811,6 +2810,15 @@ static int decode_slice_data(HEVCContext *s, const 
H2645NAL *nal, GetBitContext
 }
 }
 
+if (!s->sh.dependent_slice_segment_flag && s->sh.slice_type != 
HEVC_SLICE_I) {
+ret = ff_hevc_slice_rpl(s);
+if (ret < 0) {
+av_log(s->avctx, AV_LOG_WARNING,
+   "Error constructing the reference lists for the current 
slice.\n");
+return ret;
+}
+}
+
 if (s->avctx->hwaccel)
 return FF_HW_CALL(s->avctx, decode_slice, nal->raw_data, 
nal->raw_size);
 
@@ -2828,6 +2836,8 @@ static int decode_slice_data(HEVCContext *s, const 
H2645NAL *nal, GetBitContext
 s->local_ctx[0].tu.cu_qp_offset_cb = 0;
 s->local_ctx[0].tu.cu_qp_offset_cr = 0;
 
+s->slice_idx += !s->sh.dependent_slice_segment_flag;
+
 if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
 s->sh.num_entry_point_offsets > 0&&
 pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
@@ -2938,6 +2948,7 @@ static int hevc_frame_start(HEVCContext *s)
 memset(s->tab_slice_address, -1, pic_size_in_ctb * 
sizeof(*s->tab_slice_address));
 
 s->is_decoded= 0;
+s->slice_idx = 0;
 s->first_nal_type= s->nal_unit_type;
 s->poc   = s->sh.poc;
 
@@ -3151,16 +3162,6 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 return AVERROR_INVALIDDATA;
 }
 
-if (!s->sh.dependent_slice_segment_flag &&
-s->sh.slice_type != HEVC_SLICE_I) {
-ret = ff_hevc_slice_rpl(s);
-if (ret < 0) {
-av_log(s->avctx, AV_LOG_WARNING,
-   "Error constructing the reference lists for the current 
slice.\n");
-goto fail;
-}
-}
-
 ctb_addr_ts = decode_slice_data(s, nal, );
 if (ctb_addr_ts >= s->cur_frame->ctb_count) {
 ret = hevc_frame_end(s);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
13:47:13 2024 +0200| [3bbb5d78c74ab24cc5ea30120ebae454a875a454] | committer: 
Anton Khirnov

lavc/hevcdec: move per-slice local_ctx setup out of hls_slice_header()

Into decode_slice_data(). This is a step towards constifying
HEVCContext in hls_slice_header().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3bbb5d78c74ab24cc5ea30120ebae454a875a454
---

 libavcodec/hevc/hevcdec.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index bbcaa350c7..cda52e05ef 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1014,14 +1014,7 @@ static int hls_slice_header(HEVCContext *s, 
GetBitContext *gb)
 return AVERROR_INVALIDDATA;
 }
 
-s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
-
-if (!pps->cu_qp_delta_enabled_flag)
-s->local_ctx[0].qp_y = s->sh.slice_qp;
-
 s->slice_initialized = 1;
-s->local_ctx[0].tu.cu_qp_offset_cb = 0;
-s->local_ctx[0].tu.cu_qp_offset_cr = 0;
 
 return 0;
 }
@@ -2818,6 +2811,14 @@ static int decode_slice_data(HEVCContext *s, const 
H2645NAL *nal, GetBitContext
 }
 }
 
+s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
+
+if (!pps->cu_qp_delta_enabled_flag)
+s->local_ctx[0].qp_y = s->sh.slice_qp;
+
+s->local_ctx[0].tu.cu_qp_offset_cb = 0;
+s->local_ctx[0].tu.cu_qp_offset_cr = 0;
+
 if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
 s->sh.num_entry_point_offsets > 0&&
 pps->num_tile_rows == 1 && pps->num_tile_columns == 1)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move slice decoding dispatch to its own function

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
09:12:06 2024 +0200| [efc827bf6fdcb046e215547e8c3edfee9b22d5db] | committer: 
Anton Khirnov

lavc/hevcdec: move slice decoding dispatch to its own function

Also move there a sanity check from hls_decode_entry() that should also
be performed when WPP is active (note that the check is not moved to
hls_slice_header() because it requires the HEVCContext.tab_slice_address
to be set up).

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=efc827bf6fdcb046e215547e8c3edfee9b22d5db
---

 libavcodec/hevc/hevcdec.c | 36 ++--
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 9c1d879953..bbcaa350c7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2578,14 +2578,6 @@ static int hls_decode_entry(HEVCContext *s, 
GetBitContext *gb)
 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
 int ret;
 
-if (s->sh.dependent_slice_segment_flag) {
-int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
-if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
-av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
-return AVERROR_INVALIDDATA;
-}
-}
-
 while (more_data && ctb_addr_ts < sps->ctb_size) {
 int ctb_addr_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts];
 
@@ -2813,6 +2805,27 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 return res;
 }
 
+static int decode_slice_data(HEVCContext *s, const H2645NAL *nal, 
GetBitContext *gb)
+{
+const HEVCPPS *pps = s->pps;
+
+if (s->sh.dependent_slice_segment_flag) {
+int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
+int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
+if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {
+av_log(s->avctx, AV_LOG_ERROR, "Previous slice segment missing\n");
+return AVERROR_INVALIDDATA;
+}
+}
+
+if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
+s->sh.num_entry_point_offsets > 0&&
+pps->num_tile_rows == 1 && pps->num_tile_columns == 1)
+return hls_slice_data_wpp(s, nal);
+
+return hls_decode_entry(s, gb);
+}
+
 static int set_side_data(HEVCContext *s)
 {
 AVFrame *out = s->cur_frame->f;
@@ -3152,12 +3165,7 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 goto fail;
 }
 
-if (s->avctx->active_thread_type == FF_THREAD_SLICE  &&
-s->sh.num_entry_point_offsets > 0&&
-s->pps->num_tile_rows == 1 && s->pps->num_tile_columns == 1)
-ctb_addr_ts = hls_slice_data_wpp(s, nal);
-else
-ctb_addr_ts = hls_decode_entry(s, );
+ctb_addr_ts = decode_slice_data(s, nal, );
 if (ctb_addr_ts >= s->cur_frame->ctb_count) {
 ret = hevc_frame_end(s);
 if (ret < 0)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move a slice segment sanity check to hls_slice_header()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
09:00:43 2024 +0200| [7cce612a26c3bd750b4a64db6e31ce370b067993] | committer: 
Anton Khirnov

lavc/hevcdec: move a slice segment sanity check to hls_slice_header()

Combine it with an existing similar check.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7cce612a26c3bd750b4a64db6e31ce370b067993
---

 libavcodec/hevc/hevcdec.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index df6d1565bc..9c1d879953 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1002,7 +1002,8 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 
 sh->slice_ctb_addr_rs = sh->slice_segment_addr;
 
-if (!s->sh.slice_ctb_addr_rs && s->sh.dependent_slice_segment_flag) {
+if (sh->dependent_slice_segment_flag &&
+(!sh->slice_ctb_addr_rs || 
!pps->ctb_addr_rs_to_ts[sh->slice_ctb_addr_rs])) {
 av_log(s->avctx, AV_LOG_ERROR, "Impossible slice segment.\n");
 return AVERROR_INVALIDDATA;
 }
@@ -2577,11 +2578,6 @@ static int hls_decode_entry(HEVCContext *s, 
GetBitContext *gb)
 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs];
 int ret;
 
-if (!ctb_addr_ts && s->sh.dependent_slice_segment_flag) {
-av_log(s->avctx, AV_LOG_ERROR, "Impossible initial tile.\n");
-return AVERROR_INVALIDDATA;
-}
-
 if (s->sh.dependent_slice_segment_flag) {
 int prev_rs = pps->ctb_addr_ts_to_rs[ctb_addr_ts - 1];
 if (s->tab_slice_address[prev_rs] != s->sh.slice_addr) {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: store slice header POC in SliceHeader

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
20:29:50 2024 +0200| [d43527a1a0f5760a5c18468cb9f5305d1e6ac93a] | committer: 
Anton Khirnov

lavc/hevcdec: store slice header POC in SliceHeader

Rather than decoding directly into HEVCContext.poc.

This is a step towards constifying HEVCContext in hls_slice_header().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d43527a1a0f5760a5c18468cb9f5305d1e6ac93a
---

 libavcodec/hevc/hevcdec.c | 13 +++--
 libavcodec/hevc/hevcdec.h |  1 +
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index f867fdbea5..df6d1565bc 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -706,14 +706,14 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 
 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
 poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, 
s->nal_unit_type);
-if (!sh->first_slice_in_pic_flag && poc != s->poc) {
+if (!sh->first_slice_in_pic_flag && poc != sh->poc) {
 av_log(s->avctx, AV_LOG_WARNING,
-   "Ignoring POC change between slices: %d -> %d\n", 
s->poc, poc);
+   "Ignoring POC change between slices: %d -> %d\n", poc, 
sh->poc);
 if (s->avctx->err_recognition & AV_EF_EXPLODE)
 return AVERROR_INVALIDDATA;
-poc = s->poc;
+poc = sh->poc;
 }
-s->poc = poc;
+sh->poc = poc;
 
 sh->short_term_ref_pic_set_sps_flag = get_bits1(gb);
 pos = get_bits_left(gb);
@@ -738,7 +738,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
 
 pos = get_bits_left(gb);
-ret = decode_lt_rps(sps, >long_term_rps, gb, s->poc, 
sh->pic_order_cnt_lsb);
+ret = decode_lt_rps(sps, >long_term_rps, gb, sh->poc, 
sh->pic_order_cnt_lsb);
 if (ret < 0) {
 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
 if (s->avctx->err_recognition & AV_EF_EXPLODE)
@@ -751,7 +751,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 else
 sh->slice_temporal_mvp_enabled_flag = 0;
 } else {
-s->poc  = 0;
+sh->poc = 0;
 sh->pic_order_cnt_lsb   = 0;
 sh->short_term_ref_pic_set_sps_flag = 0;
 sh->short_term_ref_pic_set_size = 0;
@@ -2920,6 +2920,7 @@ static int hevc_frame_start(HEVCContext *s)
 
 s->is_decoded= 0;
 s->first_nal_type= s->nal_unit_type;
+s->poc   = s->sh.poc;
 
 if (IS_IRAP(s))
 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 75026a8deb..e47a7107c8 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -209,6 +209,7 @@ typedef struct SliceHeader {
 enum HEVCSliceType slice_type;
 
 int pic_order_cnt_lsb;
+int poc;
 
 uint8_t first_slice_in_pic_flag;
 uint8_t dependent_slice_segment_flag;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: drop redundant HEVCContext.threads_{type,number}

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
20:21:06 2024 +0200| [e4e9e1da15a228688b97489b4e6d89d092a4229b] | committer: 
Anton Khirnov

lavc/hevcdec: drop redundant HEVCContext.threads_{type,number}

They are useless duplicates of corresponding AVCodecContext fields.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e4e9e1da15a228688b97489b4e6d89d092a4229b
---

 libavcodec/hevc/filter.c  |  6 +++---
 libavcodec/hevc/hevcdec.c | 36 +---
 libavcodec/hevc/hevcdec.h |  3 ---
 libavcodec/hevc/mvs.c |  4 ++--
 libavcodec/hevc/refs.c|  2 +-
 5 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c
index 081b3a3898..56e354b486 100644
--- a/libavcodec/hevc/filter.c
+++ b/libavcodec/hevc/filter.c
@@ -892,15 +892,15 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, const 
HEVCPPS *pps,
 sao_filter_CTB(lc, s, pps, sps, x - ctb_size, y);
 if (y && x_end) {
 sao_filter_CTB(lc, s, pps, sps, x, y - ctb_size);
-if (s->threads_type & FF_THREAD_FRAME )
+if (s->avctx->active_thread_type & FF_THREAD_FRAME )
 ff_progress_frame_report(>cur_frame->tf, y);
 }
 if (x_end && y_end) {
 sao_filter_CTB(lc, s, pps, sps, x , y);
-if (s->threads_type & FF_THREAD_FRAME )
+if (s->avctx->active_thread_type & FF_THREAD_FRAME )
 ff_progress_frame_report(>cur_frame->tf, y + ctb_size);
 }
-} else if (s->threads_type & FF_THREAD_FRAME && x_end)
+} else if (s->avctx->active_thread_type & FF_THREAD_FRAME && x_end)
 ff_progress_frame_report(>cur_frame->tf, y + ctb_size - 4);
 }
 
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index e3773a6147..f867fdbea5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -968,8 +968,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 unsigned val = get_bits_long(gb, offset_len);
 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the 
size
 }
-if (s->threads_number > 1 && (pps->num_tile_rows > 1 || 
pps->num_tile_columns > 1))
-s->threads_number = 1;
 }
 }
 
@@ -1870,7 +1868,7 @@ static void chroma_mc_bi(HEVCLocalContext *lc,
 static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref,
 const Mv *mv, int y0, int height)
 {
-if (s->threads_type == FF_THREAD_FRAME ) {
+if (s->avctx->active_thread_type == FF_THREAD_FRAME ) {
 int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9);
 
 ff_progress_frame_await(>tf, y);
@@ -2631,7 +2629,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext 
*gb)
 return ctb_addr_ts;
 }
 
-static int hls_decode_entry_wpp(AVCodecContext *avctxt, void *hevc_lclist,
+static int hls_decode_entry_wpp(AVCodecContext *avctx, void *hevc_lclist,
 int job, int self_id)
 {
 HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id];
@@ -2643,7 +2641,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *hevc_lclist,
 int ctb_row = job;
 int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((sps->width + 
ctb_size - 1) >> sps->log2_ctb_size);
 int ctb_addr_ts = pps->ctb_addr_rs_to_ts[ctb_addr_rs];
-int thread = ctb_row % s->threads_number;
+int thread = ctb_row % avctx->thread_count;
 
 const uint8_t *data  = s->data + s->sh.offset[ctb_row];
 const size_t   data_size = s->sh.size[ctb_row];
@@ -2736,8 +2734,8 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 return AVERROR_INVALIDDATA;
 }
 
-if (s->threads_number > s->nb_local_ctx) {
-HEVCLocalContext *tmp = av_malloc_array(s->threads_number, 
sizeof(*s->local_ctx));
+if (s->avctx->thread_count > s->nb_local_ctx) {
+HEVCLocalContext *tmp = av_malloc_array(s->avctx->thread_count, 
sizeof(*s->local_ctx));
 
 if (!tmp)
 return AVERROR(ENOMEM);
@@ -2746,7 +2744,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 av_free(s->local_ctx);
 s->local_ctx = tmp;
 
-for (unsigned i = s->nb_local_ctx; i < s->threads_number; i++) {
+for (unsigned i = s->nb_local_ctx; i < s->avctx->thread_count; i++) {
 tmp = >local_ctx[i];
 
 memset(tmp, 0, sizeof(*tmp));
@@ -2756,7 +2754,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 tmp->common_cabac_state = >cabac;
 }
 
-s->nb_local_ctx = s->threads_number;
+

[FFmpeg-cvslog] lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
20:05:36 2024 +0200| [b0c29a45dc3c42eb0c32eb78a850b3c3f581459c] | committer: 
Anton Khirnov

lavc/hevc/cabac: do not infer WPP use based on HEVCContext.threads_number

Pass this information explicitly instead.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b0c29a45dc3c42eb0c32eb78a850b3c3f581459c
---

 libavcodec/hevc/cabac.c   | 7 ---
 libavcodec/hevc/hevcdec.c | 4 ++--
 libavcodec/hevc/hevcdec.h | 3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/libavcodec/hevc/cabac.c b/libavcodec/hevc/cabac.c
index 8708efc248..39ca7c0135 100644
--- a/libavcodec/hevc/cabac.c
+++ b/libavcodec/hevc/cabac.c
@@ -452,7 +452,8 @@ static void cabac_init_state(HEVCLocalContext *lc, const 
HEVCContext *s)
 }
 
 int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
-   int ctb_addr_ts, const uint8_t *data, size_t size)
+   int ctb_addr_ts, const uint8_t *data, size_t size,
+   int is_wpp)
 {
 const HEVCContext *const s = lc->parent;
 const HEVCSPS   *const sps = pps->sps;
@@ -479,7 +480,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS 
*pps,
 if (pps->tiles_enabled_flag &&
 pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
 int ret;
-if (s->threads_number == 1)
+if (!is_wpp)
 ret = cabac_reinit(lc);
 else {
 ret = ff_init_cabac_decoder(>cc, data, size);
@@ -492,7 +493,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS 
*pps,
 if (ctb_addr_ts % sps->ctb_width == 0) {
 int ret;
 get_cabac_terminate(>cc);
-if (s->threads_number == 1)
+if (!is_wpp)
 ret = cabac_reinit(lc);
 else {
 ret = ff_init_cabac_decoder(>cc, data, size);
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index a57fa4e539..e3773a6147 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2599,7 +2599,7 @@ static int hls_decode_entry(HEVCContext *s, GetBitContext 
*gb)
 y_ctb = (ctb_addr_rs / ((sps->width + ctb_size - 1) >> 
sps->log2_ctb_size)) << sps->log2_ctb_size;
 hls_decode_neighbour(lc, pps, sps, x_ctb, y_ctb, ctb_addr_ts);
 
-ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size);
+ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, slice_data, slice_size, 
0);
 if (ret < 0) {
 s->tab_slice_address[ctb_addr_rs] = -1;
 return ret;
@@ -2669,7 +2669,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *hevc_lclist,
 return 0;
 }
 
-ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size);
+ret = ff_hevc_cabac_init(lc, pps, ctb_addr_ts, data, data_size, 1);
 if (ret < 0)
 goto error;
 hls_sao_param(lc, pps, sps,
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 04eacca76d..22367602aa 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -579,7 +579,8 @@ int ff_hevc_slice_rpl(HEVCContext *s);
 void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
  int ctb_addr_ts);
 int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
-   int ctb_addr_ts, const uint8_t *data, size_t size);
+   int ctb_addr_ts, const uint8_t *data, size_t size,
+   int is_wpp);
 int ff_hevc_sao_merge_flag_decode(HEVCLocalContext *lc);
 int ff_hevc_sao_type_idx_decode(HEVCLocalContext *lc);
 int ff_hevc_sao_band_position_decode(HEVCLocalContext *lc);

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
18:49:55 2024 +0200| [d86ac94df24dbaacab995442713bfe81253fb004] | committer: 
Anton Khirnov

lavc/hevcdec: output RASL frames based on the value of no_rasl_output_flag

Instead of an ad-hoc scheme. Also, combine skipping RASL frames with
skip_frame handling - current code seems flawed as it only executes for
the first slice of a RASL frame and unnecessarily unsets is_decoded,
which should not be set at this point anyway..

Some RASL frames in fate-hevc-afd-tc-sei that were previously discarded
are now output.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d86ac94df24dbaacab995442713bfe81253fb004
---

 libavcodec/hevc/hevcdec.c  | 33 -
 libavcodec/hevc/hevcdec.h  |  1 -
 tests/ref/fate/hevc-afd-tc-sei | 36 
 3 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d444ea93f7..a57fa4e539 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -605,7 +605,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 
 if ((IS_IDR(s) || IS_BLA(s)) && sh->first_slice_in_pic_flag) {
 s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-s->max_ra = INT_MAX;
 if (IS_IDR(s))
 ff_hevc_clear_refs(s);
 }
@@ -645,7 +644,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 s->avctx->pix_fmt = pix_fmt;
 
 s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-s->max_ra = INT_MAX;
 }
 
 sh->dependent_slice_segment_flag = 0;
@@ -3106,32 +3104,15 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 }
 
 
-if (
-(s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
+if ((s->avctx->skip_frame >= AVDISCARD_BIDIR && s->sh.slice_type == 
HEVC_SLICE_B) ||
 (s->avctx->skip_frame >= AVDISCARD_NONINTRA && s->sh.slice_type != 
HEVC_SLICE_I) ||
-(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s))) {
+(s->avctx->skip_frame >= AVDISCARD_NONKEY && !IS_IRAP(s)) ||
+((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == 
HEVC_NAL_RASL_N) &&
+ s->no_rasl_output_flag)) {
 break;
 }
 
 if (s->sh.first_slice_in_pic_flag) {
-if (s->max_ra == INT_MAX) {
-if (s->nal_unit_type == HEVC_NAL_CRA_NUT || IS_BLA(s)) {
-s->max_ra = s->poc;
-} else {
-if (IS_IDR(s))
-s->max_ra = INT_MIN;
-}
-}
-
-if ((s->nal_unit_type == HEVC_NAL_RASL_R || s->nal_unit_type == 
HEVC_NAL_RASL_N) &&
-s->poc <= s->max_ra) {
-s->is_decoded = 0;
-break;
-} else {
-if (s->nal_unit_type == HEVC_NAL_RASL_R && s->poc > s->max_ra)
-s->max_ra = INT_MIN;
-}
-
 s->overlap ++;
 ret = hevc_frame_start(s);
 if (ret < 0)
@@ -3196,7 +3177,6 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 case HEVC_NAL_EOS_NUT:
 case HEVC_NAL_EOB_NUT:
 s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-s->max_ra = INT_MAX;
 break;
 case HEVC_NAL_AUD:
 case HEVC_NAL_FD_NUT:
@@ -3572,8 +3552,6 @@ static av_cold int hevc_init_context(AVCodecContext 
*avctx)
 return AVERROR(ENOMEM);
 }
 
-s->max_ra = INT_MAX;
-
 s->md5_ctx = av_md5_alloc();
 if (!s->md5_ctx)
 return AVERROR(ENOMEM);
@@ -3626,7 +3604,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 s->seq_decode = s0->seq_decode;
 s->seq_output = s0->seq_output;
 s->poc_tid0   = s0->poc_tid0;
-s->max_ra = s0->max_ra;
 s->eos= s0->eos;
 s->no_rasl_output_flag = s0->no_rasl_output_flag;
 
@@ -3640,7 +3617,6 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 
 if (s0->eos) {
 s->seq_decode = (s->seq_decode + 1) & HEVC_SEQUENCE_COUNTER_MASK;
-s->max_ra = INT_MAX;
 }
 
 ret = ff_h2645_sei_ctx_replace(>sei.common, >sei.common);
@@ -3734,7 +3710,6 @@ static void hevc_decode_flush(AVCodecContext *avctx)
 ff_hevc_reset_sei(>sei);
 ff_dovi_ctx_flush(>dovi_ctx);
 av_buffer_unref(>rpu_buf);
-s->max_ra = INT_MAX;
 s->eos = 1;
 
 if (FF_HW_HAS_CB(avctx, flush))
diff --git a/libavcodec/hevc/hevcdec.h

[FFmpeg-cvslog] lavc/hevcdec: only set no_rasl_output_flag for IRAP frames

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
18:38:57 2024 +0200| [3115c84015d8cc86262844d9a2435d2c5423de0e] | committer: 
Anton Khirnov

lavc/hevcdec: only set no_rasl_output_flag for IRAP frames

Its meaning is only specified for IRAP frames.

As it's currently never used otherwise, this should not change decoder
behaviour, but will be useful in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3115c84015d8cc86262844d9a2435d2c5423de0e
---

 libavcodec/hevc/hevcdec.c | 4 +++-
 libavcodec/hevc/hevcdec.h | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 585a066426..d444ea93f7 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2925,7 +2925,9 @@ static int hevc_frame_start(HEVCContext *s)
 s->is_decoded= 0;
 s->first_nal_type= s->nal_unit_type;
 
-s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == 
HEVC_NAL_CRA_NUT && s->last_eos);
+if (IS_IRAP(s))
+s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) ||
+ (s->nal_unit_type == HEVC_NAL_CRA_NUT && 
s->last_eos);
 
 /* 8.3.1 */
 if (s->temporal_id == 0 &&
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 5eaebd3584..fa7caf9cf7 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -493,6 +493,7 @@ typedef struct HEVCContext {
 int overlap;
 
 int is_decoded;
+// NoRaslOutputFlag associated with the last IRAP frame
 int no_rasl_output_flag;
 
 HEVCPredContext hpc;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
16:36:16 2024 +0200| [381b70e173f9d55a05ef7174f1a3709951dc3ba3] | committer: 
Anton Khirnov

lavc/hevcdec: do not pass HEVCContext to ff_hevc_frame_nb_refs()

Pass the only things required from it - slice header and PPS -
explicitly.

Will be useful in the following commits to avoid mofiying HEVCContext in
hls_slice_header().

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=381b70e173f9d55a05ef7174f1a3709951dc3ba3
---

 libavcodec/hevc/hevcdec.c | 2 +-
 libavcodec/hevc/hevcdec.h | 2 +-
 libavcodec/hevc/refs.c| 8 
 libavcodec/nvdec_hevc.c   | 2 +-
 libavcodec/vdpau_hevc.c   | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index bf6e93ba1b..585a066426 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -795,7 +795,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 
 sh->rpl_modification_flag[0] = 0;
 sh->rpl_modification_flag[1] = 0;
-nb_refs = ff_hevc_frame_nb_refs(s);
+nb_refs = ff_hevc_frame_nb_refs(sh, pps);
 if (!nb_refs) {
 av_log(s->avctx, AV_LOG_ERROR, "Zero refs for a frame with P 
or B slices.\n");
 return AVERROR_INVALIDDATA;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 4b28494366..5eaebd3584 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -614,7 +614,7 @@ int ff_hevc_res_scale_sign_flag(HEVCLocalContext *lc, int 
idx);
 /**
  * Get the number of candidate references for the current frame.
  */
-int ff_hevc_frame_nb_refs(const HEVCContext *s);
+int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps);
 
 int ff_hevc_set_new_ref(HEVCContext *s, int poc);
 
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index 31fcd49d69..5bd5eab9f1 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -526,12 +526,12 @@ fail:
 return ret;
 }
 
-int ff_hevc_frame_nb_refs(const HEVCContext *s)
+int ff_hevc_frame_nb_refs(const SliceHeader *sh, const HEVCPPS *pps)
 {
 int ret = 0;
 int i;
-const ShortTermRPS *rps = s->sh.short_term_rps;
-const LongTermRPS *long_rps = >sh.long_term_rps;
+const ShortTermRPS *rps = sh->short_term_rps;
+const LongTermRPS *long_rps = >long_term_rps;
 
 if (rps) {
 for (i = 0; i < rps->num_negative_pics; i++)
@@ -545,7 +545,7 @@ int ff_hevc_frame_nb_refs(const HEVCContext *s)
 ret += !!long_rps->used[i];
 }
 
-if (s->pps->pps_curr_pic_ref_enabled_flag)
+if (pps->pps_curr_pic_ref_enabled_flag)
 ret++;
 
 return ret;
diff --git a/libavcodec/nvdec_hevc.c b/libavcodec/nvdec_hevc.c
index 0bebca7568..ce66ddcfb7 100644
--- a/libavcodec/nvdec_hevc.c
+++ b/libavcodec/nvdec_hevc.c
@@ -187,7 +187,7 @@ static int nvdec_hevc_start_frame(AVCodecContext *avctx,
 
 .NumBitsForShortTermRPSInSlice= 
s->sh.short_term_rps ? s->sh.short_term_ref_pic_set_size : 0,
 .NumDeltaPocsOfRefRpsIdx  = 
s->sh.short_term_rps ? s->sh.short_term_rps->rps_idx_num_delta_pocs : 0,
-.NumPocTotalCurr  = 
ff_hevc_frame_nb_refs(s),
+.NumPocTotalCurr  = 
ff_hevc_frame_nb_refs(>sh, pps),
 .NumPocStCurrBefore   = 
s->rps[ST_CURR_BEF].nb_refs,
 .NumPocStCurrAfter= 
s->rps[ST_CURR_AFT].nb_refs,
 .NumPocLtCurr = 
s->rps[LT_CURR].nb_refs,
diff --git a/libavcodec/vdpau_hevc.c b/libavcodec/vdpau_hevc.c
index 3db7ec156a..b9e922ecfc 100644
--- a/libavcodec/vdpau_hevc.c
+++ b/libavcodec/vdpau_hevc.c
@@ -205,7 +205,7 @@ static int vdpau_hevc_start_frame(AVCodecContext *avctx,
 }
 }
 /* See section 7.4.7.2 of the specification. */
-info->NumPocTotalCurr = ff_hevc_frame_nb_refs(h);
+info->NumPocTotalCurr = ff_hevc_frame_nb_refs(>sh, pps);
 if (sh->short_term_ref_pic_set_sps_flag == 0 && sh->short_term_rps) {
 /* Corresponds to specification field, NumDeltaPocs[RefRpsIdx].
Only applicable when short_term_ref_pic_set_sps_flag == 0.

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: only call export_stream_params_from_sei() once per frame

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
16:24:00 2024 +0200| [07eb60c0da34d146b72064ec1f316d64a6ac7ebb] | committer: 
Anton Khirnov

lavc/hevcdec: only call export_stream_params_from_sei() once per frame

Not once per each slice header, as it makes no sense and may cause races
with frame threading.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=07eb60c0da34d146b72064ec1f316d64a6ac7ebb
---

 libavcodec/hevc/hevcdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index dd3c188418..bf6e93ba1b 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -648,10 +648,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 s->max_ra = INT_MAX;
 }
 
-ret = export_stream_params_from_sei(s);
-if (ret < 0)
-return ret;
-
 sh->dependent_slice_segment_flag = 0;
 if (!sh->first_slice_in_pic_flag) {
 int slice_address_length;
@@ -2965,6 +2961,10 @@ static int hevc_frame_start(HEVCContext *s)
 !(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) &&
 !s->avctx->hwaccel;
 
+ret = export_stream_params_from_sei(s);
+if (ret < 0)
+return ret;
+
 ret = set_side_data(s);
 if (ret < 0)
 goto fail;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: stop accessing parameter sets through HEVCParamSets

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
13:55:39 2024 +0200| [0f47342c12dc21be2ae64db21eeefefa893641c7] | committer: 
Anton Khirnov

lavc/hevcdec: stop accessing parameter sets through HEVCParamSets

Instead, accept PPS/SPS as function arguments.

Makes the code shorter and significantly reduces diff in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0f47342c12dc21be2ae64db21eeefefa893641c7
---

 libavcodec/hevc/hevcdec.c | 878 +-
 1 file changed, 470 insertions(+), 408 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 5e4e5776e0..14b9a2a844 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -143,7 +143,7 @@ fail:
 return AVERROR(ENOMEM);
 }
 
-static int pred_weight_table(HEVCContext *s, GetBitContext *gb)
+static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext 
*gb)
 {
 int i = 0;
 int j = 0;
@@ -159,7 +159,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext 
*gb)
 return AVERROR_INVALIDDATA;
 }
 s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
-if (s->ps.sps->chroma_format_idc != 0) {
+if (sps->chroma_format_idc != 0) {
 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + 
(int64_t)get_se_golomb(gb);
 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
 av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" 
is invalid\n", chroma_log2_weight_denom);
@@ -175,7 +175,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext 
*gb)
 s->sh.luma_offset_l0[i] = 0;
 }
 }
-if (s->ps.sps->chroma_format_idc != 0) {
+if (sps->chroma_format_idc != 0) {
 for (i = 0; i < s->sh.nb_refs[L0]; i++)
 chroma_weight_l0_flag[i] = get_bits1(gb);
 } else {
@@ -219,7 +219,7 @@ static int pred_weight_table(HEVCContext *s, GetBitContext 
*gb)
 s->sh.luma_offset_l1[i] = 0;
 }
 }
-if (s->ps.sps->chroma_format_idc != 0) {
+if (sps->chroma_format_idc != 0) {
 for (i = 0; i < s->sh.nb_refs[L1]; i++)
 chroma_weight_l1_flag[i] = get_bits1(gb);
 } else {
@@ -259,9 +259,9 @@ static int pred_weight_table(HEVCContext *s, GetBitContext 
*gb)
 return 0;
 }
 
-static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, GetBitContext *gb)
+static int decode_lt_rps(HEVCContext *s, const HEVCSPS *sps, LongTermRPS *rps,
+ GetBitContext *gb)
 {
-const HEVCSPS *sps = s->ps.sps;
 int max_poc_lsb= 1 << sps->log2_max_poc_lsb;
 int prev_delta_msb = 0;
 unsigned int nb_sps = 0, nb_sh;
@@ -591,6 +591,8 @@ fail:
 static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
 {
 SliceHeader *sh   = >sh;
+const HEVCPPS *pps;
+const HEVCSPS *sps;
 int i, ret;
 
 // Coded parameters
@@ -621,11 +623,13 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 return AVERROR_INVALIDDATA;
 }
 s->ps.pps = s->ps.pps_list[sh->pps_id];
+pps = s->ps.pps;
+sps = pps->sps;
+
 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
 sh->no_output_of_prior_pics_flag = 1;
 
-if (s->ps.sps != s->ps.pps->sps) {
-const HEVCSPS *sps = s->ps.pps->sps;
+if (s->ps.sps != sps) {
 enum AVPixelFormat pix_fmt;
 
 ff_hevc_clear_refs(s);
@@ -651,13 +655,13 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 if (!sh->first_slice_in_pic_flag) {
 int slice_address_length;
 
-if (s->ps.pps->dependent_slice_segments_enabled_flag)
+if (pps->dependent_slice_segments_enabled_flag)
 sh->dependent_slice_segment_flag = get_bits1(gb);
 
-slice_address_length = av_ceil_log2(s->ps.sps->ctb_width *
-s->ps.sps->ctb_height);
+slice_address_length = av_ceil_log2(sps->ctb_width *
+sps->ctb_height);
 sh->slice_segment_addr = get_bitsz(gb, slice_address_length);
-if (sh->slice_segment_addr >= s->ps.sps->ctb_width * 
s->ps.sps->ctb_height) {
+if (sh->slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
 av_log(s->avctx, AV_LOG_ERROR,
"Invalid slice segment address: %u.\n",
sh->slice_segment_addr);
@@ -677,7 +681,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 if (!sh->dependent_slice_segment_flag) {
 s->slice_initialized = 0;
 
-for (i = 0; i < s->ps.pps->num_extra_slice_header_bits; i++)
+

[FFmpeg-cvslog] lavc/hevcdec: drop an always-zero variable

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
12:43:42 2024 +0200| [8eb134f4f9449fef6f1a992361e46a7f321f3b1d] | committer: 
Anton Khirnov

lavc/hevcdec: drop an always-zero variable

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8eb134f4f9449fef6f1a992361e46a7f321f3b1d
---

 libavcodec/hevc/hevcdec.c | 9 ++---
 libavcodec/hevc/hevcdec.h | 1 -
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 6dda923df5..d599373c9d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -984,13 +984,9 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 unsigned val = get_bits_long(gb, offset_len);
 sh->entry_point_offset[i] = val + 1; // +1; // +1 to get the 
size
 }
-if (s->threads_number > 1 && (pps->num_tile_rows > 1 || 
pps->num_tile_columns > 1)) {
-s->enable_parallel_tiles = 0; // TODO: you can enable tiles in 
parallel here
+if (s->threads_number > 1 && (pps->num_tile_rows > 1 || 
pps->num_tile_columns > 1))
 s->threads_number = 1;
-} else
-s->enable_parallel_tiles = 0;
-} else
-s->enable_parallel_tiles = 0;
+}
 }
 
 if (pps->slice_header_extension_present_flag) {
@@ -3697,7 +3693,6 @@ static av_cold int hevc_decode_init(AVCodecContext *avctx)
 if (ret < 0)
 return ret;
 
-s->enable_parallel_tiles = 0;
 s->sei.picture_timing.picture_struct = 0;
 s->eos = 1;
 
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 3b7442e5c1..c58ce05639 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -532,7 +532,6 @@ typedef struct HEVCContext {
 /** The target for the common_cabac_state of the local contexts. */
 HEVCCABACState cabac;
 
-int enable_parallel_tiles;
 atomic_int wpp_err;
 
 const uint8_t *data;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move pocTid0 computation to hevc_frame_start()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
16:17:57 2024 +0200| [01b379a93e05d86f7d889a848741f7e235560630] | committer: 
Anton Khirnov

lavc/hevcdec: move pocTid0 computation to hevc_frame_start()

It is only done once per frame. Also, rename the variable to poc_tid0 to
be consistent with our naming conventions.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=01b379a93e05d86f7d889a848741f7e235560630
---

 libavcodec/hevc/hevcdec.c | 26 +-
 libavcodec/hevc/hevcdec.h |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 960a06c773..dd3c188418 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -711,7 +711,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 int poc, pos;
 
 sh->pic_order_cnt_lsb = get_bits(gb, sps->log2_max_poc_lsb);
-poc = ff_hevc_compute_poc(sps, s->pocTid0, sh->pic_order_cnt_lsb, 
s->nal_unit_type);
+poc = ff_hevc_compute_poc(sps, s->poc_tid0, sh->pic_order_cnt_lsb, 
s->nal_unit_type);
 if (!sh->first_slice_in_pic_flag && poc != s->poc) {
 av_log(s->avctx, AV_LOG_WARNING,
"Ignoring POC change between slices: %d -> %d\n", 
s->poc, poc);
@@ -766,17 +766,6 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 sh->slice_temporal_mvp_enabled_flag = 0;
 }
 
-/* 8.3.1 */
-if (sh->first_slice_in_pic_flag && s->temporal_id == 0 &&
-s->nal_unit_type != HEVC_NAL_TRAIL_N &&
-s->nal_unit_type != HEVC_NAL_TSA_N   &&
-s->nal_unit_type != HEVC_NAL_STSA_N  &&
-s->nal_unit_type != HEVC_NAL_RADL_N  &&
-s->nal_unit_type != HEVC_NAL_RADL_R  &&
-s->nal_unit_type != HEVC_NAL_RASL_N  &&
-s->nal_unit_type != HEVC_NAL_RASL_R)
-s->pocTid0 = s->poc;
-
 if (sps->sao_enabled) {
 sh->slice_sample_adaptive_offset_flag[0] = get_bits1(gb);
 if (sps->chroma_format_idc) {
@@ -2942,6 +2931,17 @@ static int hevc_frame_start(HEVCContext *s)
 
 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == 
HEVC_NAL_CRA_NUT && s->last_eos);
 
+/* 8.3.1 */
+if (s->temporal_id == 0 &&
+s->nal_unit_type != HEVC_NAL_TRAIL_N &&
+s->nal_unit_type != HEVC_NAL_TSA_N   &&
+s->nal_unit_type != HEVC_NAL_STSA_N  &&
+s->nal_unit_type != HEVC_NAL_RADL_N  &&
+s->nal_unit_type != HEVC_NAL_RADL_R  &&
+s->nal_unit_type != HEVC_NAL_RASL_N  &&
+s->nal_unit_type != HEVC_NAL_RASL_R)
+s->poc_tid0 = s->poc;
+
 if (pps->tiles_enabled_flag)
 s->local_ctx[0].end_of_tiles_x = pps->column_width[0] << 
sps->log2_ctb_size;
 
@@ -3623,7 +3623,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 
 s->seq_decode = s0->seq_decode;
 s->seq_output = s0->seq_output;
-s->pocTid0= s0->pocTid0;
+s->poc_tid0   = s0->poc_tid0;
 s->max_ra = s0->max_ra;
 s->eos= s0->eos;
 s->no_rasl_output_flag = s0->no_rasl_output_flag;
diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index c58ce05639..4b28494366 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -483,7 +483,7 @@ typedef struct HEVCContext {
 HEVCFrame *collocated_ref;
 HEVCFrame DPB[32];
 int poc;
-int pocTid0;
+int poc_tid0;
 int slice_idx; ///< number of the slice being currently decoded
 int eos;   ///< current packet contains an EOS/EOB NAL
 int last_eos;  ///< last packet contains an EOS/EOB NAL

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
16:04:14 2024 +0200| [0892ec947c7fa488b8806e3711e174969fc77b1b] | committer: 
Anton Khirnov

lavc/hevcdec: pass SliceHeader explicitly to pred_weight_table()

And replace the HEVCContext* parameter by void *logctx.

Makes it clear that only SliceHeader is modified by this function.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0892ec947c7fa488b8806e3711e174969fc77b1b
---

 libavcodec/hevc/hevcdec.c | 75 ---
 1 file changed, 38 insertions(+), 37 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 2c26d397df..6a9de79dcd 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -143,7 +143,8 @@ fail:
 return AVERROR(ENOMEM);
 }
 
-static int pred_weight_table(HEVCContext *s, const HEVCSPS *sps, GetBitContext 
*gb)
+static int pred_weight_table(SliceHeader *sh, void *logctx,
+ const HEVCSPS *sps, GetBitContext *gb)
 {
 int i = 0;
 int j = 0;
@@ -155,40 +156,40 @@ static int pred_weight_table(HEVCContext *s, const 
HEVCSPS *sps, GetBitContext *
 
 luma_log2_weight_denom = get_ue_golomb_long(gb);
 if (luma_log2_weight_denom < 0 || luma_log2_weight_denom > 7) {
-av_log(s->avctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is 
invalid\n", luma_log2_weight_denom);
+av_log(logctx, AV_LOG_ERROR, "luma_log2_weight_denom %d is invalid\n", 
luma_log2_weight_denom);
 return AVERROR_INVALIDDATA;
 }
-s->sh.luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
+sh->luma_log2_weight_denom = av_clip_uintp2(luma_log2_weight_denom, 3);
 if (sps->chroma_format_idc != 0) {
 int64_t chroma_log2_weight_denom = luma_log2_weight_denom + 
(int64_t)get_se_golomb(gb);
 if (chroma_log2_weight_denom < 0 || chroma_log2_weight_denom > 7) {
-av_log(s->avctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" 
is invalid\n", chroma_log2_weight_denom);
+av_log(logctx, AV_LOG_ERROR, "chroma_log2_weight_denom %"PRId64" 
is invalid\n", chroma_log2_weight_denom);
 return AVERROR_INVALIDDATA;
 }
-s->sh.chroma_log2_weight_denom = chroma_log2_weight_denom;
+sh->chroma_log2_weight_denom = chroma_log2_weight_denom;
 }
 
-for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+for (i = 0; i < sh->nb_refs[L0]; i++) {
 luma_weight_l0_flag[i] = get_bits1(gb);
 if (!luma_weight_l0_flag[i]) {
-s->sh.luma_weight_l0[i] = 1 << s->sh.luma_log2_weight_denom;
-s->sh.luma_offset_l0[i] = 0;
+sh->luma_weight_l0[i] = 1 << sh->luma_log2_weight_denom;
+sh->luma_offset_l0[i] = 0;
 }
 }
 if (sps->chroma_format_idc != 0) {
-for (i = 0; i < s->sh.nb_refs[L0]; i++)
+for (i = 0; i < sh->nb_refs[L0]; i++)
 chroma_weight_l0_flag[i] = get_bits1(gb);
 } else {
-for (i = 0; i < s->sh.nb_refs[L0]; i++)
+for (i = 0; i < sh->nb_refs[L0]; i++)
 chroma_weight_l0_flag[i] = 0;
 }
-for (i = 0; i < s->sh.nb_refs[L0]; i++) {
+for (i = 0; i < sh->nb_refs[L0]; i++) {
 if (luma_weight_l0_flag[i]) {
 int delta_luma_weight_l0 = get_se_golomb(gb);
 if ((int8_t)delta_luma_weight_l0 != delta_luma_weight_l0)
 return AVERROR_INVALIDDATA;
-s->sh.luma_weight_l0[i] = (1 << s->sh.luma_log2_weight_denom) + 
delta_luma_weight_l0;
-s->sh.luma_offset_l0[i] = get_se_golomb(gb);
+sh->luma_weight_l0[i] = (1 << sh->luma_log2_weight_denom) + 
delta_luma_weight_l0;
+sh->luma_offset_l0[i] = get_se_golomb(gb);
 }
 if (chroma_weight_l0_flag[i]) {
 for (j = 0; j < 2; j++) {
@@ -200,39 +201,39 @@ static int pred_weight_table(HEVCContext *s, const 
HEVCSPS *sps, GetBitContext *
 return AVERROR_INVALIDDATA;
 }
 
-s->sh.chroma_weight_l0[i][j] = (1 << 
s->sh.chroma_log2_weight_denom) + delta_chroma_weight_l0;
-s->sh.chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 
- ((128 * s->sh.chroma_weight_l0[i][j])
-   
 >> s->sh.chroma_log2_weight_denom) + 128), -128, 127);
+sh->chroma_weight_l0[i][j] = (1 << 
sh->chroma_log2_weight_denom) + delta_chroma_weight_l0;
+sh->chroma_offset_l0[i][j] = av_clip((delta_chroma_offset_l0 - 
((128 * sh->chroma_weight_l0[i][j])
+   
 >> sh->chroma_log2_weight_den

[FFmpeg-cvslog] lavc/hevcdec: do not pass HEVCContext to decode_lt_rps()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
16:04:14 2024 +0200| [5e438511abb28097e73ac8d5c4dd97a8ad6d9908] | committer: 
Anton Khirnov

lavc/hevcdec: do not pass HEVCContext to decode_lt_rps()

Pass the two numbers needed from it explicitly.

Makes it clear that HEVCContext is not modified by this function.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5e438511abb28097e73ac8d5c4dd97a8ad6d9908
---

 libavcodec/hevc/hevcdec.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 6a9de79dcd..960a06c773 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -260,8 +260,8 @@ static int pred_weight_table(SliceHeader *sh, void *logctx,
 return 0;
 }
 
-static int decode_lt_rps(HEVCContext *s, const HEVCSPS *sps, LongTermRPS *rps,
- GetBitContext *gb)
+static int decode_lt_rps(const HEVCSPS *sps, LongTermRPS *rps,
+ GetBitContext *gb, int cur_poc, int poc_lsb)
 {
 int max_poc_lsb= 1 << sps->log2_max_poc_lsb;
 int prev_delta_msb = 0;
@@ -306,7 +306,7 @@ static int decode_lt_rps(HEVCContext *s, const HEVCSPS 
*sps, LongTermRPS *rps,
 if (i && i != nb_sps)
 delta += prev_delta_msb;
 
-poc = rps->poc[i] + s->poc - delta * max_poc_lsb - 
s->sh.pic_order_cnt_lsb;
+poc = rps->poc[i] + cur_poc - delta * max_poc_lsb - poc_lsb;
 if (poc != (int32_t)poc)
 return AVERROR_INVALIDDATA;
 rps->poc[i] = poc;
@@ -744,7 +744,7 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 sh->short_term_ref_pic_set_size = pos - get_bits_left(gb);
 
 pos = get_bits_left(gb);
-ret = decode_lt_rps(s, sps, >long_term_rps, gb);
+ret = decode_lt_rps(sps, >long_term_rps, gb, s->poc, 
sh->pic_order_cnt_lsb);
 if (ret < 0) {
 av_log(s->avctx, AV_LOG_WARNING, "Invalid long term RPS.\n");
 if (s->avctx->err_recognition & AV_EF_EXPLODE)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
13:49:32 2024 +0200| [90fc331b0fc6f7d9c31f9e6d543102ba7fe02daf] | committer: 
Anton Khirnov

lavc/hevcdec: only ignore INVALIDDATA in decode_nal_unit()

All other errors should cause a failure, regardless of the value of
err_recognition. Also, print a warning message when skipping invalid NAL
units.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90fc331b0fc6f7d9c31f9e6d543102ba7fe02daf
---

 libavcodec/hevc/hevcdec.c | 10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d599373c9d..2c26d397df 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3206,9 +3206,13 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 
 return 0;
 fail:
-if (s->avctx->err_recognition & AV_EF_EXPLODE)
-return ret;
-return 0;
+if (ret == AVERROR_INVALIDDATA &&
+!(s->avctx->err_recognition & AV_EF_EXPLODE)) {
+av_log(s->avctx, AV_LOG_WARNING,
+   "Skipping invalid undecodable NALU: %d\n", s->nal_unit_type);
+return 0;
+}
+return ret;
 }
 
 static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
10:36:00 2024 +0200| [8c8072c29c9712615c571a2de733cf49fa5a27ed] | committer: 
Anton Khirnov

lavc/hevcdec: move active PPS from HEVCParamSets to HEVCContext

"Currently active PPS" is a property of the decoding process, not of the
list of available parameter sets.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8c8072c29c9712615c571a2de733cf49fa5a27ed
---

 libavcodec/dxva2_hevc.c   |  8 
 libavcodec/hevc/hevcdec.c | 19 ---
 libavcodec/hevc/hevcdec.h |  1 +
 libavcodec/hevc/ps.c  | 12 ++--
 libavcodec/hevc/ps.h  |  1 -
 libavcodec/hevc/refs.c| 12 ++--
 libavcodec/nvdec_hevc.c   | 10 +-
 libavcodec/vaapi_hevc.c   | 12 ++--
 libavcodec/vdpau_hevc.c   |  4 ++--
 libavcodec/videotoolbox.c |  6 +++---
 libavcodec/vulkan_hevc.c  |  8 
 11 files changed, 45 insertions(+), 48 deletions(-)

diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 2f4073edd6..bd2c6f72a4 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -62,8 +62,8 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 {
 const HEVCContext *h = avctx->priv_data;
 const HEVCFrame *current_picture = h->cur_frame;
-const HEVCSPS *sps = h->ps.sps;
-const HEVCPPS *pps = h->ps.pps;
+const HEVCPPS *pps = h->pps;
+const HEVCSPS *sps = pps->sps;
 int i, j;
 
 memset(pp, 0, sizeof(*pp));
@@ -205,8 +205,8 @@ void ff_dxva2_hevc_fill_scaling_lists(const AVCodecContext 
*avctx, AVDXVAContext
 {
 const HEVCContext *h = avctx->priv_data;
 unsigned i, j, pos;
-const ScalingList *sl = h->ps.pps->scaling_list_data_present_flag ?
->ps.pps->scaling_list : 
>ps.sps->scaling_list;
+const ScalingList *sl = h->pps->scaling_list_data_present_flag ?
+>pps->scaling_list : >pps->sps->scaling_list;
 
 memset(qm, 0, sizeof(*qm));
 for (i = 0; i < 6; i++) {
diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 14b9a2a844..6dda923df5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -618,12 +618,12 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 return AVERROR_INVALIDDATA;
 }
 if (!sh->first_slice_in_pic_flag &&
-s->ps.pps != s->ps.pps_list[sh->pps_id]) {
+s->pps != s->ps.pps_list[sh->pps_id]) {
 av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n");
 return AVERROR_INVALIDDATA;
 }
-s->ps.pps = s->ps.pps_list[sh->pps_id];
-pps = s->ps.pps;
+ff_refstruct_replace(>pps, s->ps.pps_list[sh->pps_id]);
+pps = s->pps;
 sps = pps->sps;
 
 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
@@ -2588,7 +2588,7 @@ static void hls_decode_neighbour(HEVCLocalContext *lc,
 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
 {
 HEVCLocalContext *const lc = >local_ctx[0];
-const HEVCPPS   *const pps = s->ps.pps;
+const HEVCPPS   *const pps = s->pps;
 const HEVCSPS   *const sps = pps->sps;
 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
 const size_t   slice_size = gb->buffer_end - gb->buffer - 
s->sh.data_offset;
@@ -2656,7 +2656,7 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *hevc_lclist,
 {
 HEVCLocalContext *lc = &((HEVCLocalContext*)hevc_lclist)[self_id];
 const HEVCContext *const s = lc->parent;
-const HEVCPPS   *const pps = s->ps.pps;
+const HEVCPPS   *const pps = s->pps;
 const HEVCSPS   *const sps = pps->sps;
 int ctb_size= 1 << sps->log2_ctb_size;
 int more_data   = 1;
@@ -2739,7 +2739,7 @@ error:
 
 static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
 {
-const HEVCPPS *const pps = s->ps.pps;
+const HEVCPPS *const pps = s->pps;
 const HEVCSPS *const sps = pps->sps;
 const uint8_t *data = nal->data;
 int length  = nal->size;
@@ -2928,7 +2928,7 @@ static int set_side_data(HEVCContext *s)
 
 static int hevc_frame_start(HEVCContext *s)
 {
-const HEVCPPS *const pps = s->ps.pps;
+const HEVCPPS *const pps = s->pps;
 const HEVCSPS *const sps = pps->sps;
 int pic_size_in_ctb  = ((sps->width  >> sps->log2_min_cb_size) + 1) *
((sps->height >> sps->log2_min_cb_size) + 1);
@@ -3510,6 +3510,8 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 
 pic_arrays_free(s);
 
+ff_refstruct_unref(>pps);
+
 ff_dovi_ctx_unref(>dovi_ctx);
 av_buffer_unref(>rpu_buf);
 
@@ -3611,6 +3613,9 @@ static int hevc_update_thread_context(AVCodecContext *dst,
 for (int i = 0

[FFmpeg-cvslog] lavc/hevc/filter: stop accessing parameter sets through HEVCParamSets

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
13:55:39 2024 +0200| [b38aecffecea5682d34b1295d1e146f1283160cb] | committer: 
Anton Khirnov

lavc/hevc/filter: stop accessing parameter sets through HEVCParamSets

Instead, accept PPS as a function argument and retrieve SPS through it.

Makes the code shorter and significantly reduces diff in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b38aecffecea5682d34b1295d1e146f1283160cb
---

 libavcodec/hevc/filter.c  | 315 +-
 libavcodec/hevc/hevcdec.c |  20 +--
 libavcodec/hevc/hevcdec.h |  14 ++-
 3 files changed, 188 insertions(+), 161 deletions(-)

diff --git a/libavcodec/hevc/filter.c b/libavcodec/hevc/filter.c
index db7525170d..081b3a3898 100644
--- a/libavcodec/hevc/filter.c
+++ b/libavcodec/hevc/filter.c
@@ -44,7 +44,8 @@ static const uint8_t betatable[52] = {
 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64 
 // QP 38...51
 };
 
-static int chroma_tc(const HEVCContext *s, int qp_y, int c_idx, int tc_offset)
+static int chroma_tc(const HEVCPPS *pps, const HEVCSPS *sps,
+ int qp_y, int c_idx, int tc_offset)
 {
 static const int qp_c[] = {
 29, 30, 31, 32, 33, 33, 34, 34, 35, 35, 36, 36, 37, 37
@@ -53,12 +54,12 @@ static int chroma_tc(const HEVCContext *s, int qp_y, int 
c_idx, int tc_offset)
 
 // slice qp offset is not used for deblocking
 if (c_idx == 1)
-offset = s->ps.pps->cb_qp_offset;
+offset = pps->cb_qp_offset;
 else
-offset = s->ps.pps->cr_qp_offset;
+offset = pps->cr_qp_offset;
 
 qp_i = av_clip(qp_y + offset, 0, 57);
-if (s->ps.sps->chroma_format_idc == 1) {
+if (sps->chroma_format_idc == 1) {
 if (qp_i < 30)
 qp = qp_i;
 else if (qp_i > 43)
@@ -74,16 +75,17 @@ static int chroma_tc(const HEVCContext *s, int qp_y, int 
c_idx, int tc_offset)
 }
 
 static int get_qPy_pred(HEVCLocalContext *lc, const HEVCContext *s,
+const HEVCPPS *pps, const HEVCSPS *sps,
 int xBase, int yBase, int log2_cb_size)
 {
-int ctb_size_mask= (1 << s->ps.sps->log2_ctb_size) - 1;
-int MinCuQpDeltaSizeMask = (1 << (s->ps.sps->log2_ctb_size -
-  s->ps.pps->diff_cu_qp_delta_depth)) - 1;
+int ctb_size_mask= (1 << sps->log2_ctb_size) - 1;
+int MinCuQpDeltaSizeMask = (1 << (sps->log2_ctb_size -
+  pps->diff_cu_qp_delta_depth)) - 1;
 int xQgBase  = xBase - (xBase & MinCuQpDeltaSizeMask);
 int yQgBase  = yBase - (yBase & MinCuQpDeltaSizeMask);
-int min_cb_width = s->ps.sps->min_cb_width;
-int x_cb = xQgBase >> s->ps.sps->log2_min_cb_size;
-int y_cb = yQgBase >> s->ps.sps->log2_min_cb_size;
+int min_cb_width = sps->min_cb_width;
+int x_cb = xQgBase >> sps->log2_min_cb_size;
+int y_cb = yQgBase >> sps->log2_min_cb_size;
 int availableA   = (xBase   & ctb_size_mask) &&
(xQgBase & ctb_size_mask);
 int availableB   = (yBase   & ctb_size_mask) &&
@@ -110,31 +112,33 @@ static int get_qPy_pred(HEVCLocalContext *lc, const 
HEVCContext *s,
 else
 qPy_b = s->qp_y_tab[x_cb + (y_cb - 1) * min_cb_width];
 
-av_assert2(qPy_a >= -s->ps.sps->qp_bd_offset && qPy_a < 52);
-av_assert2(qPy_b >= -s->ps.sps->qp_bd_offset && qPy_b < 52);
+av_assert2(qPy_a >= -sps->qp_bd_offset && qPy_a < 52);
+av_assert2(qPy_b >= -sps->qp_bd_offset && qPy_b < 52);
 
 return (qPy_a + qPy_b + 1) >> 1;
 }
 
-void ff_hevc_set_qPy(HEVCLocalContext *lc, int xBase, int yBase, int 
log2_cb_size)
+void ff_hevc_set_qPy(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int xBase, int yBase, int log2_cb_size)
 {
+const HEVCSPS   *const sps = pps->sps;
 const HEVCContext *const s = lc->parent;
-int qp_y = get_qPy_pred(lc, s, xBase, yBase, log2_cb_size);
+int qp_y = get_qPy_pred(lc, s, pps, sps, xBase, yBase, log2_cb_size);
 
 if (lc->tu.cu_qp_delta != 0) {
-int off = s->ps.sps->qp_bd_offset;
+int off = sps->qp_bd_offset;
 lc->qp_y = FFUMOD(qp_y + lc->tu.cu_qp_delta + 52 + 2 * off,
  52 + off) - off;
 } else
 lc->qp_y = qp_y;
 }
 
-static int get_qPy(const HEVCContext *s, int xC, int yC)
+static int get_qPy(const HEVCSPS *sps, const int8_t *qp_y_tab, int xC, int yC)
 {
-int log2_min_cb_size  = s->ps.sps->log2_min_cb_size;
+int log2_min_cb_size  = sps-&

[FFmpeg-cvslog] lavc/hevc/pred: stop accessing parameter sets through HEVCParamSets

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
13:55:39 2024 +0200| [38b8ae4112684c3415ab2f7d717605759d764d27] | committer: 
Anton Khirnov

lavc/hevc/pred: stop accessing parameter sets through HEVCParamSets

Instead, accept PPS/SPS as function arguments.

Makes the code shorter and significantly reduces diff in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=38b8ae4112684c3415ab2f7d717605759d764d27
---

 libavcodec/hevc/hevcdec.c   |  26 ++--
 libavcodec/hevc/pred.h  |   4 +-
 libavcodec/hevc/pred_template.c |  74 +-
 libavcodec/mips/hevcpred_mips.h |   4 +-
 libavcodec/mips/hevcpred_msa.c  | 291 
 5 files changed, 202 insertions(+), 197 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index cf972ed560..5e4e5776e0 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1160,7 +1160,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 int trafo_size = 1 << log2_trafo_size;
 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, 
s->ps.sps->log2_ctb_size);
 
-s->hpc.intra_pred[log2_trafo_size - 2](lc, x0, y0, 0);
+s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, x0, y0, 0);
 }
 
 if (cbf_luma || cbf_cb[0] || cbf_cr[0] ||
@@ -1247,7 +1247,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << 
log2_trafo_size_c),
 trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
-s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i 
<< log2_trafo_size_c), 1);
+s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, 
x0, y0 + (i << log2_trafo_size_c), 1);
 }
 if (cbf_cb[i])
 ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << 
log2_trafo_size_c),
@@ -1277,7 +1277,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << 
log2_trafo_size_c),
 trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
-s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i 
<< log2_trafo_size_c), 2);
+s->hpc.intra_pred[log2_trafo_size_c - 2](lc, s->ps.pps, 
x0, y0 + (i << log2_trafo_size_c), 2);
 }
 if (cbf_cr[i])
 ff_hevc_hls_residual_coding(lc, s->ps.pps, x0, y0 + (i << 
log2_trafo_size_c),
@@ -1306,7 +1306,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << 
log2_trafo_size),
 trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
-s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + 
(i << log2_trafo_size), 1);
+s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, 
xBase, yBase + (i << log2_trafo_size), 1);
 }
 if (cbf_cb[i])
 ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + 
(i << log2_trafo_size),
@@ -1316,7 +1316,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << 
log2_trafo_size),
 trafo_size_h, trafo_size_v, 
s->ps.sps->log2_ctb_size);
-s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + 
(i << log2_trafo_size), 2);
+s->hpc.intra_pred[log2_trafo_size - 2](lc, s->ps.pps, 
xBase, yBase + (i << log2_trafo_size), 2);
 }
 if (cbf_cr[i])
 ff_hevc_hls_residual_coding(lc, s->ps.pps, xBase, yBase + 
(i << log2_trafo_size),
@@ -1329,26 +1329,26 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
 ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, 
trafo_size_v,
 s->ps.sps->log2_ctb_size);
-s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 1);
-s->hpc.intra_pred[log2_trafo_size_c - 2](

[FFmpeg-cvslog] lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
13:55:39 2024 +0200| [fb873a05b3439c32b362285557a8b1fcb9947dd2] | committer: 
Anton Khirnov

lavc/hevc/mvs: stop accessing parameter sets through HEVCParamSets

Instead, accept PPS as a function argument and retrieve SPS through it.

Makes the code shorter and significantly reduces diff in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fb873a05b3439c32b362285557a8b1fcb9947dd2
---

 libavcodec/hevc/hevcdec.c |  28 ++-
 libavcodec/hevc/hevcdec.h |   8 +--
 libavcodec/hevc/mvs.c | 126 --
 3 files changed, 87 insertions(+), 75 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 16c46997a8..5de229f78d 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -1158,7 +1158,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 
 if (lc->cu.pred_mode == MODE_INTRA) {
 int trafo_size = 1 << log2_trafo_size;
-ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size);
+ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size, trafo_size, 
s->ps.sps->log2_ctb_size);
 
 s->hpc.intra_pred[log2_trafo_size - 2](lc, x0, y0, 0);
 }
@@ -1245,7 +1245,8 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 }
 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
 if (lc->cu.pred_mode == MODE_INTRA) {
-ff_hevc_set_neighbour_available(lc, x0, y0 + (i << 
log2_trafo_size_c), trafo_size_h, trafo_size_v);
+ff_hevc_set_neighbour_available(lc, x0, y0 + (i << 
log2_trafo_size_c),
+trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i 
<< log2_trafo_size_c), 1);
 }
 if (cbf_cb[i])
@@ -1275,7 +1276,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, x0, y0 + (i << 
log2_trafo_size_c),
-trafo_size_h, 
trafo_size_v);
+trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0 + (i 
<< log2_trafo_size_c), 2);
 }
 if (cbf_cr[i])
@@ -1304,7 +1305,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << 
log2_trafo_size),
-trafo_size_h, 
trafo_size_v);
+trafo_size_h, 
trafo_size_v, s->ps.sps->log2_ctb_size);
 s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + 
(i << log2_trafo_size), 1);
 }
 if (cbf_cb[i])
@@ -1314,7 +1315,7 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 for (i = 0; i < (s->ps.sps->chroma_format_idc == 2 ? 2 : 1); i++) {
 if (lc->cu.pred_mode == MODE_INTRA) {
 ff_hevc_set_neighbour_available(lc, xBase, yBase + (i << 
log2_trafo_size),
-trafo_size_h, trafo_size_v);
+trafo_size_h, trafo_size_v, 
s->ps.sps->log2_ctb_size);
 s->hpc.intra_pred[log2_trafo_size - 2](lc, xBase, yBase + 
(i << log2_trafo_size), 2);
 }
 if (cbf_cr[i])
@@ -1326,12 +1327,13 @@ static int hls_transform_unit(HEVCLocalContext *lc, int 
x0, int y0,
 if (log2_trafo_size > 2 || s->ps.sps->chroma_format_idc == 3) {
 int trafo_size_h = 1 << (log2_trafo_size_c + s->ps.sps->hshift[1]);
 int trafo_size_v = 1 << (log2_trafo_size_c + s->ps.sps->vshift[1]);
-ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, 
trafo_size_v);
+ff_hevc_set_neighbour_available(lc, x0, y0, trafo_size_h, 
trafo_size_v,
+s->ps.sps->log2_ctb_size);
 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 1);
 s->hpc.intra_pred[log2_trafo_size_c - 2](lc, x0, y0, 2);
 i

[FFmpeg-cvslog] lavc/hevc/cabac: stop accessing parameter sets through HEVCParamSets

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
13:55:39 2024 +0200| [d0868d70eaa19b6ae118f16a770738e801fa7be7] | committer: 
Anton Khirnov

lavc/hevc/cabac: stop accessing parameter sets through HEVCParamSets

Instead, accept PPS/SPS as function arguments.

Makes the code shorter and significantly reduces diff in future commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d0868d70eaa19b6ae118f16a770738e801fa7be7
---

 libavcodec/hevc/cabac.c   | 145 +++---
 libavcodec/hevc/hevcdec.c |  31 +-
 libavcodec/hevc/hevcdec.h |  22 +++
 3 files changed, 102 insertions(+), 96 deletions(-)

diff --git a/libavcodec/hevc/cabac.c b/libavcodec/hevc/cabac.c
index 37f144758a..8708efc248 100644
--- a/libavcodec/hevc/cabac.c
+++ b/libavcodec/hevc/cabac.c
@@ -399,25 +399,25 @@ static const uint8_t diag_scan8x8_inv[8][8] = {
 { 28, 36, 43, 49, 54, 58, 61, 63, },
 };
 
-void ff_hevc_save_states(HEVCLocalContext *lc, int ctb_addr_ts)
+void ff_hevc_save_states(HEVCLocalContext *lc, const HEVCPPS *pps,
+ int ctb_addr_ts)
 {
-const HEVCContext *const s = lc->parent;
-
-if (s->ps.pps->entropy_coding_sync_enabled_flag &&
-(ctb_addr_ts % s->ps.sps->ctb_width == 2 ||
- (s->ps.sps->ctb_width == 2 &&
-  ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
+const HEVCSPS *const sps = pps->sps;
+if (pps->entropy_coding_sync_enabled_flag &&
+(ctb_addr_ts % sps->ctb_width == 2 ||
+ (sps->ctb_width == 2 &&
+  ctb_addr_ts % sps->ctb_width == 0))) {
 memcpy(lc->common_cabac_state->state, lc->cabac_state, HEVC_CONTEXTS);
-if (s->ps.sps->persistent_rice_adaptation_enabled) {
+if (sps->persistent_rice_adaptation_enabled) {
 memcpy(lc->common_cabac_state->stat_coeff, lc->stat_coeff, 
HEVC_STAT_COEFFS);
 }
 }
 }
 
-static void load_states(HEVCLocalContext *lc, const HEVCContext *s)
+static void load_states(HEVCLocalContext *lc, const HEVCSPS *sps)
 {
 memcpy(lc->cabac_state, lc->common_cabac_state->state, HEVC_CONTEXTS);
-if (s->ps.sps->persistent_rice_adaptation_enabled) {
+if (sps->persistent_rice_adaptation_enabled) {
 memcpy(lc->stat_coeff, lc->common_cabac_state->stat_coeff, 
HEVC_STAT_COEFFS);
 }
 }
@@ -451,32 +451,33 @@ static void cabac_init_state(HEVCLocalContext *lc, const 
HEVCContext *s)
 lc->stat_coeff[i] = 0;
 }
 
-int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
-   const uint8_t *data, size_t size)
+int ff_hevc_cabac_init(HEVCLocalContext *lc, const HEVCPPS *pps,
+   int ctb_addr_ts, const uint8_t *data, size_t size)
 {
 const HEVCContext *const s = lc->parent;
+const HEVCSPS   *const sps = pps->sps;
 
-if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
+if (ctb_addr_ts == pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
 int ret = ff_init_cabac_decoder(>cc, data, size);
 if (ret < 0)
 return ret;
 if (s->sh.dependent_slice_segment_flag == 0 ||
-(s->ps.pps->tiles_enabled_flag &&
- s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts 
- 1]))
+(pps->tiles_enabled_flag &&
+ pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]))
 cabac_init_state(lc, s);
 
 if (!s->sh.first_slice_in_pic_flag &&
-s->ps.pps->entropy_coding_sync_enabled_flag) {
-if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {
-if (s->ps.sps->ctb_width == 1)
+pps->entropy_coding_sync_enabled_flag) {
+if (ctb_addr_ts % sps->ctb_width == 0) {
+if (sps->ctb_width == 1)
 cabac_init_state(lc, s);
 else if (s->sh.dependent_slice_segment_flag == 1)
-load_states(lc, s);
+load_states(lc, sps);
 }
 }
 } else {
-if (s->ps.pps->tiles_enabled_flag &&
-s->ps.pps->tile_id[ctb_addr_ts] != s->ps.pps->tile_id[ctb_addr_ts 
- 1]) {
+if (pps->tiles_enabled_flag &&
+pps->tile_id[ctb_addr_ts] != pps->tile_id[ctb_addr_ts - 1]) {
 int ret;
 if (s->threads_number == 1)
 ret = cabac_reinit(lc);
@@ -487,8 +488,8 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, int 
ctb_addr_ts,
 return ret;
 cabac_init_state(lc, s);
 }
-if (s->ps.pps->entropy_coding_sync_enabled_flag) {
-if (ctb_addr_ts % s->ps.sps->ctb_width == 0) {

[FFmpeg-cvslog] lavc/hevc/parser: stop using HEVCParamSets.[psv]ps

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
10:55:19 2024 +0200| [6ddba110eb1dcb7c05368f85759a70a5645ca4ca] | committer: 
Anton Khirnov

lavc/hevc/parser: stop using HEVCParamSets.[psv]ps

The parser does not need to preserve these between frames.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6ddba110eb1dcb7c05368f85759a70a5645ca4ca
---

 libavcodec/hevc/parser.c | 61 
 1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index 49f7bccdfa..f4e6e3c36d 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -58,6 +58,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 HEVCParamSets *ps = >ps;
 HEVCSEI *sei = >sei;
 GetBitContext *gb = >gb;
+const HEVCPPS *pps;
+const HEVCSPS *sps;
 const HEVCWindow *ow;
 int i, num = 0, den = 0;
 
@@ -78,28 +80,25 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id);
 return AVERROR_INVALIDDATA;
 }
-ps->pps = ps->pps_list[pps_id];
-
-if (ps->sps != ps->pps->sps) {
-ps->sps  = ps->pps->sps;
-ps->vps  = ps->sps->vps;
-}
-ow  = >sps->output_window;
-
-s->coded_width  = ps->sps->width;
-s->coded_height = ps->sps->height;
-s->width= ps->sps->width  - ow->left_offset - ow->right_offset;
-s->height   = ps->sps->height - ow->top_offset  - ow->bottom_offset;
-s->format   = ps->sps->pix_fmt;
-avctx->profile  = ps->sps->ptl.general_ptl.profile_idc;
-avctx->level= ps->sps->ptl.general_ptl.level_idc;
-
-if (ps->vps->vps_timing_info_present_flag) {
-num = ps->vps->vps_num_units_in_tick;
-den = ps->vps->vps_time_scale;
-} else if (ps->sps->vui.vui_timing_info_present_flag) {
-num = ps->sps->vui.vui_num_units_in_tick;
-den = ps->sps->vui.vui_time_scale;
+pps = ps->pps_list[pps_id];
+sps = pps->sps;
+
+ow  = >output_window;
+
+s->coded_width  = sps->width;
+s->coded_height = sps->height;
+s->width= sps->width  - ow->left_offset - ow->right_offset;
+s->height   = sps->height - ow->top_offset  - ow->bottom_offset;
+s->format   = sps->pix_fmt;
+avctx->profile  = sps->ptl.general_ptl.profile_idc;
+avctx->level= sps->ptl.general_ptl.level_idc;
+
+if (sps->vps->vps_timing_info_present_flag) {
+num = sps->vps->vps_num_units_in_tick;
+den = sps->vps->vps_time_scale;
+} else if (sps->vui.vui_timing_info_present_flag) {
+num = sps->vui.vui_num_units_in_tick;
+den = sps->vui.vui_time_scale;
 }
 
 if (num != 0 && den != 0)
@@ -110,15 +109,15 @@ static int hevc_parse_slice_header(AVCodecParserContext 
*s, H2645NAL *nal,
 unsigned int slice_segment_addr;
 int slice_address_length;
 
-if (ps->pps->dependent_slice_segments_enabled_flag)
+if (pps->dependent_slice_segments_enabled_flag)
 dependent_slice_segment_flag = get_bits1(gb);
 else
 dependent_slice_segment_flag = 0;
 
-slice_address_length = av_ceil_log2_c(ps->sps->ctb_width *
-  ps->sps->ctb_height);
+slice_address_length = av_ceil_log2_c(sps->ctb_width *
+  sps->ctb_height);
 slice_segment_addr = get_bitsz(gb, slice_address_length);
-if (slice_segment_addr >= ps->sps->ctb_width * ps->sps->ctb_height) {
+if (slice_segment_addr >= sps->ctb_width * sps->ctb_height) {
 av_log(avctx, AV_LOG_ERROR, "Invalid slice segment address: %u.\n",
slice_segment_addr);
 return AVERROR_INVALIDDATA;
@@ -129,7 +128,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 if (dependent_slice_segment_flag)
 return 0; /* break; */
 
-for (i = 0; i < ps->pps->num_extra_slice_header_bits; i++)
+for (i = 0; i < pps->num_extra_slice_header_bits; i++)
 skip_bits(gb, 1); // slice_reserved_undetermined_flag[]
 
 slice_type = get_ue_golomb_31(gb);
@@ -143,16 +142,16 @@ static int hevc_parse_slice_header(AVCodecParserContext 
*s, H2645NAL *nal,
slice_type == HEVC_SLICE_P ? AV_PICTURE_TYPE_P :
 AV_PICTURE_TYPE_I;
 
-if (ps->pps->output_flag_present_flag)
+if (pps->output_flag_present_flag)
 skip_bits1(gb); // pic_outp

[FFmpeg-cvslog] lavc/hevcdec: drop a redundant assignment in hevc_decode_frame()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
12:19:33 2024 +0200| [e12fd62d1dd4a8f129f33015e22e270e871fc4ce] | committer: 
Anton Khirnov

lavc/hevcdec: drop a redundant assignment in hevc_decode_frame()

The exact same code is executed at the beginning of decode_nal_units()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e12fd62d1dd4a8f129f33015e22e270e871fc4ce
---

 libavcodec/hevc/hevcdec.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 43cbc45062..46db7923fe 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3369,7 +3369,6 @@ static int hevc_decode_frame(AVCodecContext *avctx, 
AVFrame *rframe,
old, s->dovi_ctx.cfg.dv_profile);
 }
 
-s->cur_frame = s->collocated_ref = NULL;
 ret= decode_nal_units(s, avpkt->data, avpkt->size);
 if (ret < 0)
 return ret;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc_ps: make SPS hold a reference to its VPS

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
09:53:28 2024 +0200| [2e46d68f553c36f61e46f1db5c5adce84b60f175] | committer: 
Anton Khirnov

lavc/hevc_ps: make SPS hold a reference to its VPS

SPS and its dependent PPSes depend on, and are parsed for, specific VPS data.

This will be useful in following commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2e46d68f553c36f61e46f1db5c5adce84b60f175
---

 libavcodec/hevc/hevcdec.c |  5 ++---
 libavcodec/hevc/parser.c  |  2 +-
 libavcodec/hevc/ps.c  | 13 +
 libavcodec/hevc/ps.h  |  2 ++
 4 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index ae4a5888e5..16c46997a8 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -319,8 +319,7 @@ static int decode_lt_rps(HEVCContext *s, LongTermRPS *rps, 
GetBitContext *gb)
 static void export_stream_params(HEVCContext *s, const HEVCSPS *sps)
 {
 AVCodecContext *avctx = s->avctx;
-const HEVCParamSets *ps = >ps;
-const HEVCVPS *vps = ps->vps_list[sps->vps_id];
+const HEVCVPS*vps = sps->vps;
 const HEVCWindow *ow = >output_window;
 unsigned int num = 0, den = 0;
 
@@ -575,7 +574,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps,
 }
 
 s->ps.sps = sps;
-s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id];
+s->ps.vps = sps->vps;
 
 return 0;
 
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index d0d5e7fbc2..49f7bccdfa 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -82,7 +82,7 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 
 if (ps->sps != ps->pps->sps) {
 ps->sps  = ps->pps->sps;
-ps->vps  = ps->vps_list[ps->sps->vps_id];
+ps->vps  = ps->sps->vps;
 }
 ow  = >sps->output_window;
 
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 98217e337b..eabed69b94 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -889,10 +889,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, 
unsigned int *sps_id,
 
 sps->vps_id = get_bits(gb, 4);
 
-if (vps_list && !vps_list[sps->vps_id]) {
-av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
-   sps->vps_id);
-return AVERROR_INVALIDDATA;
+if (vps_list) {
+if (!vps_list[sps->vps_id]) {
+av_log(avctx, AV_LOG_ERROR, "VPS %d does not exist\n",
+   sps->vps_id);
+return AVERROR_INVALIDDATA;
+}
+sps->vps = ff_refstruct_ref_c(vps_list[sps->vps_id]);
 }
 
 sps->max_sub_layers = get_bits(gb, 3) + 1;
@@ -1298,6 +1301,8 @@ static void hevc_sps_free(FFRefStructOpaque opaque, void 
*obj)
 {
 HEVCSPS *sps = obj;
 
+ff_refstruct_unref(>vps);
+
 av_freep(>data);
 }
 
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 7c9aacf057..fc10876756 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -302,6 +302,8 @@ typedef struct HEVCSPS {
 
 uint8_t *data;
 int data_size;
+
+const HEVCVPS *vps; ///< RefStruct reference
 } HEVCSPS;
 
 typedef struct HEVCPPS {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc_ps: make PPS hold a reference to its SPS

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Fri May 31 
09:53:28 2024 +0200| [c879165b393dee62ecd7c3b51d0e15964425bf5d] | committer: 
Anton Khirnov

lavc/hevc_ps: make PPS hold a reference to its SPS

PPS depends on, and is parsed for, specific SPS data.

This will be useful in following commits.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c879165b393dee62ecd7c3b51d0e15964425bf5d
---

 libavcodec/hevc/hevcdec.c | 4 ++--
 libavcodec/hevc/parser.c  | 8 ++--
 libavcodec/hevc/ps.c  | 4 
 libavcodec/hevc/ps.h  | 2 ++
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 46db7923fe..ae4a5888e5 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -625,8 +625,8 @@ static int hls_slice_header(HEVCContext *s, GetBitContext 
*gb)
 if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1)
 sh->no_output_of_prior_pics_flag = 1;
 
-if (s->ps.sps != s->ps.sps_list[s->ps.pps->sps_id]) {
-const HEVCSPS *sps = s->ps.sps_list[s->ps.pps->sps_id];
+if (s->ps.sps != s->ps.pps->sps) {
+const HEVCSPS *sps = s->ps.pps->sps;
 enum AVPixelFormat pix_fmt;
 
 ff_hevc_clear_refs(s);
diff --git a/libavcodec/hevc/parser.c b/libavcodec/hevc/parser.c
index 056e1b4aa4..d0d5e7fbc2 100644
--- a/libavcodec/hevc/parser.c
+++ b/libavcodec/hevc/parser.c
@@ -80,12 +80,8 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, 
H2645NAL *nal,
 }
 ps->pps = ps->pps_list[pps_id];
 
-if (ps->pps->sps_id >= HEVC_MAX_SPS_COUNT || 
!ps->sps_list[ps->pps->sps_id]) {
-av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", 
ps->pps->sps_id);
-return AVERROR_INVALIDDATA;
-}
-if (ps->sps != ps->sps_list[ps->pps->sps_id]) {
-ps->sps  = ps->sps_list[ps->pps->sps_id];
+if (ps->sps != ps->pps->sps) {
+ps->sps  = ps->pps->sps;
 ps->vps  = ps->vps_list[ps->sps->vps_id];
 }
 ow  = >sps->output_window;
diff --git a/libavcodec/hevc/ps.c b/libavcodec/hevc/ps.c
index 2dd4f834a4..98217e337b 100644
--- a/libavcodec/hevc/ps.c
+++ b/libavcodec/hevc/ps.c
@@ -1363,6 +1363,8 @@ static void hevc_pps_free(FFRefStructOpaque unused, void 
*obj)
 {
 HEVCPPS *pps = obj;
 
+ff_refstruct_unref(>sps);
+
 av_freep(>column_width);
 av_freep(>row_height);
 av_freep(>col_bd);
@@ -1828,6 +1830,8 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, 
AVCodecContext *avctx,
 sps = ps->sps_list[pps->sps_id];
 vps = ps->vps_list[sps->vps_id];
 
+pps->sps = ff_refstruct_ref_c(sps);
+
 pps->dependent_slice_segments_enabled_flag = get_bits1(gb);
 pps->output_flag_present_flag  = get_bits1(gb);
 pps->num_extra_slice_header_bits   = get_bits(gb, 3);
diff --git a/libavcodec/hevc/ps.h b/libavcodec/hevc/ps.h
index 99d70cefd2..7c9aacf057 100644
--- a/libavcodec/hevc/ps.h
+++ b/libavcodec/hevc/ps.h
@@ -437,6 +437,8 @@ typedef struct HEVCPPS {
 
 uint8_t *data;
 int data_size;
+
+const HEVCSPS *sps; ///< RefStruct reference
 } HEVCPPS;
 
 typedef struct HEVCParamSets {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: simplify condition

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sat Jun  1 
10:04:44 2024 +0200| [a82f2b092430db8284bf91147f718d09f3ee592c] | committer: 
Anton Khirnov

lavc/hevcdec: simplify condition

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a82f2b092430db8284bf91147f718d09f3ee592c
---

 libavcodec/hevc/hevcdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index d317c1471a..43cbc45062 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3115,7 +3115,7 @@ static int decode_nal_unit(HEVCContext *s, const H2645NAL 
*nal)
 ctb_addr_ts = hls_slice_data_wpp(s, nal);
 else
 ctb_addr_ts = hls_decode_entry(s, );
-if (ctb_addr_ts >= (s->ps.sps->ctb_width * s->ps.sps->ctb_height)) 
{
+if (ctb_addr_ts >= s->cur_frame->ctb_count) {
 ret = hevc_frame_end(s);
 if (ret < 0)
 goto fail;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free()

2024-06-11 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Sun Jun  2 
20:23:07 2024 +0200| [04075567163290eb8b85d106b3e53bdc13d8515b] | committer: 
Anton Khirnov

lavc/hevcdec: do not free SliceHeader arrays in pic_arrays_free()

SliceHeader.{entry_point_offset,size,offset} are not derived from frame
size and do not need to be freed here.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=04075567163290eb8b85d106b3e53bdc13d8515b
---

 libavcodec/hevc/hevcdec.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 4e0df4d033..d317c1471a 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -84,10 +84,6 @@ static void pic_arrays_free(HEVCContext *s)
 av_freep(>horizontal_bs);
 av_freep(>vertical_bs);
 
-av_freep(>sh.entry_point_offset);
-av_freep(>sh.size);
-av_freep(>sh.offset);
-
 ff_refstruct_pool_uninit(>tab_mvf_pool);
 ff_refstruct_pool_uninit(>rpl_tab_pool);
 }

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: drop unused HEVCContext.width/height

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
17:03:28 2024 +0200| [9576a005271e5a20572b5c581dbf15ad77b373bb] | committer: 
Anton Khirnov

lavc/hevcdec: drop unused HEVCContext.width/height

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9576a005271e5a20572b5c581dbf15ad77b373bb
---

 libavcodec/hevc/hevcdec.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.h b/libavcodec/hevc/hevcdec.h
index 8208268460..33ad4ac0aa 100644
--- a/libavcodec/hevc/hevcdec.h
+++ b/libavcodec/hevc/hevcdec.h
@@ -456,9 +456,6 @@ typedef struct HEVCContext {
 uint8_t threads_type;
 uint8_t threads_number;
 
-int width;
-int height;
-
 /** 1 if the independent slice segment header was successfully parsed */
 uint8_t slice_initialized;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: rename HEVCContext.ref to cur_frame

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
08:38:27 2024 +0200| [9226514cededdfe0244fbe8fe5c8fcfa3a9c75cb] | committer: 
Anton Khirnov

lavc/hevcdec: rename HEVCContext.ref to cur_frame

Since it stores a pointer to the current frame.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9226514cededdfe0244fbe8fe5c8fcfa3a9c75cb
---

 libavcodec/d3d12va_hevc.c  | 10 +++
 libavcodec/dxva2_hevc.c| 12 
 libavcodec/hevc_filter.c   | 34 ++---
 libavcodec/hevc_mvs.c  | 20 ++---
 libavcodec/hevc_refs.c | 18 +--
 libavcodec/hevcdec.c   | 68 +-
 libavcodec/hevcdec.h   |  2 +-
 libavcodec/hevcpred_template.c |  2 +-
 libavcodec/mips/hevcpred_msa.c | 68 +-
 libavcodec/nvdec_hevc.c|  6 ++--
 libavcodec/vaapi_hevc.c| 18 +--
 libavcodec/vdpau_hevc.c| 10 +++
 libavcodec/videotoolbox.c  |  2 +-
 libavcodec/vulkan_hevc.c   |  6 ++--
 14 files changed, 138 insertions(+), 138 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index a4964a05c6..323ade7d83 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -53,7 +53,7 @@ static int d3d12va_hevc_start_frame(AVCodecContext *avctx, 
av_unused const uint8
 {
 const HEVCContext*h   = avctx->priv_data;
 D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx);
-HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+HEVCDecodePictureContext *ctx_pic = h->cur_frame->hwaccel_picture_private;
 
 if (!ctx)
 return -1;
@@ -76,7 +76,7 @@ static int d3d12va_hevc_start_frame(AVCodecContext *avctx, 
av_unused const uint8
 static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, const uint8_t 
*buffer, uint32_t size)
 {
 const HEVCContext*h   = avctx->priv_data;
-const HEVCFrame  *current_picture = h->ref;
+const HEVCFrame  *current_picture = h->cur_frame;
 HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
 unsigned position;
 
@@ -99,7 +99,7 @@ static int d3d12va_hevc_decode_slice(AVCodecContext *avctx, 
const uint8_t *buffe
 static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPUT_STREAM_ARGUMENTS *input_args, ID3D12Resource *buffer)
 {
 const HEVCContext*h   = avctx->priv_data;
-const HEVCFrame  *current_picture = h->ref;
+const HEVCFrame  *current_picture = h->cur_frame;
 HEVCDecodePictureContext *ctx_pic = 
current_picture->hwaccel_picture_private;
 
 int i;
@@ -149,14 +149,14 @@ static int update_input_arguments(AVCodecContext *avctx, 
D3D12_VIDEO_DECODE_INPU
 static int d3d12va_hevc_end_frame(AVCodecContext *avctx)
 {
 HEVCContext  *h   = avctx->priv_data;
-HEVCDecodePictureContext *ctx_pic = h->ref->hwaccel_picture_private;
+HEVCDecodePictureContext *ctx_pic = h->cur_frame->hwaccel_picture_private;
 
 int scale = ctx_pic->pp.dwCodingParamToolFlags & 1;
 
 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 return -1;
 
-return ff_d3d12va_common_end_frame(avctx, h->ref->frame, _pic->pp, 
sizeof(ctx_pic->pp),
+return ff_d3d12va_common_end_frame(avctx, h->cur_frame->frame, 
_pic->pp, sizeof(ctx_pic->pp),
scale ? _pic->qm : NULL, scale ? sizeof(ctx_pic->qm) : 0, 
update_input_arguments);
 }
 
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index b500d7917a..2d6c2f812f 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -61,7 +61,7 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 DXVA_PicParams_HEVC *pp)
 {
 const HEVCContext *h = avctx->priv_data;
-const HEVCFrame *current_picture = h->ref;
+const HEVCFrame *current_picture = h->cur_frame;
 const HEVCSPS *sps = h->ps.sps;
 const HEVCPPS *pps = h->ps.pps;
 int i, j;
@@ -245,7 +245,7 @@ static int commit_bitstream_and_slice_buffer(AVCodecContext 
*avctx,
 {
 const HEVCContext *h = avctx->priv_data;
 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
-const HEVCFrame *current_picture = h->ref;
+const HEVCFrame *current_picture = h->cur_frame;
 struct hevc_dxva2_picture_context *ctx_pic = 
current_picture->hwaccel_picture_private;
 DXVA_Slice_HEVC_Short *slice = NULL;
 void *dxva_data_ptr;
@@ -364,7 +364,7 @@ static int dxva2_hevc_start_frame(AVCodecContext *avctx,
 {
 const HEVCContext *h = avctx->priv_data;
 AVDXVAContext *ctx = DXVA_CONTEXT(avctx);
-struct hevc_dxva2_picture_context *ctx_pic = 
h->ref->hwaccel_pictur

[FFmpeg-cvslog] lavc/hevcdec: drop HEVCContext.HEVClc

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
08:23:54 2024 +0200| [7ad9400952c0e2827def7a461ff7a8f7b911945b] | committer: 
Anton Khirnov

lavc/hevcdec: drop HEVCContext.HEVClc

It is merely a pointer to local_ctx[0], which we can just as well use
directly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7ad9400952c0e2827def7a461ff7a8f7b911945b
---

 libavcodec/hevcdec.c | 24 ++--
 libavcodec/hevcdec.h |  2 --
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 0a9443505a..75d0ed613a 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -1036,14 +1036,14 @@ static int hls_slice_header(HEVCContext *s, 
GetBitContext *gb)
 return AVERROR_INVALIDDATA;
 }
 
-s->HEVClc->first_qp_group = !s->sh.dependent_slice_segment_flag;
+s->local_ctx[0].first_qp_group = !s->sh.dependent_slice_segment_flag;
 
 if (!s->ps.pps->cu_qp_delta_enabled_flag)
-s->HEVClc->qp_y = s->sh.slice_qp;
+s->local_ctx[0].qp_y = s->sh.slice_qp;
 
 s->slice_initialized = 1;
-s->HEVClc->tu.cu_qp_offset_cb = 0;
-s->HEVClc->tu.cu_qp_offset_cr = 0;
+s->local_ctx[0].tu.cu_qp_offset_cb = 0;
+s->local_ctx[0].tu.cu_qp_offset_cr = 0;
 
 return 0;
 }
@@ -2534,7 +2534,7 @@ static void hls_decode_neighbour(HEVCLocalContext *lc, 
int x_ctb, int y_ctb,
 
 static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
 {
-HEVCLocalContext *const lc = s->HEVClc;
+HEVCLocalContext *const lc = >local_ctx[0];
 const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
 const size_t   slice_size = gb->buffer_end - gb->buffer - 
s->sh.data_offset;
 int ctb_size= 1 << s->ps.sps->log2_ctb_size;
@@ -2704,7 +2704,6 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 memcpy(tmp, s->local_ctx, sizeof(*s->local_ctx) * s->nb_local_ctx);
 av_free(s->local_ctx);
 s->local_ctx = tmp;
-s->HEVClc= >local_ctx[0];
 
 for (unsigned i = s->nb_local_ctx; i < s->threads_number; i++) {
 tmp = >local_ctx[i];
@@ -2757,7 +2756,7 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 
 for (i = 1; i < s->threads_number; i++) {
 s->local_ctx[i].first_qp_group = 1;
-s->local_ctx[i].qp_y = s->HEVClc->qp_y;
+s->local_ctx[i].qp_y = s->local_ctx[0].qp_y;
 }
 
 atomic_store(>wpp_err, 0);
@@ -2868,7 +2867,6 @@ static int set_side_data(HEVCContext *s)
 
 static int hevc_frame_start(HEVCContext *s)
 {
-HEVCLocalContext *lc = s->HEVClc;
 int pic_size_in_ctb  = ((s->ps.sps->width  >> s->ps.sps->log2_min_cb_size) 
+ 1) *
((s->ps.sps->height >> s->ps.sps->log2_min_cb_size) 
+ 1);
 int ret;
@@ -2885,7 +2883,7 @@ static int hevc_frame_start(HEVCContext *s)
 s->no_rasl_output_flag = IS_IDR(s) || IS_BLA(s) || (s->nal_unit_type == 
HEVC_NAL_CRA_NUT && s->last_eos);
 
 if (s->ps.pps->tiles_enabled_flag)
-lc->end_of_tiles_x = s->ps.pps->column_width[0] << 
s->ps.sps->log2_ctb_size;
+s->local_ctx[0].end_of_tiles_x = s->ps.pps->column_width[0] << 
s->ps.sps->log2_ctb_size;
 
 ret = ff_hevc_set_new_ref(s, >frame, s->poc);
 if (ret < 0)
@@ -3505,11 +3503,9 @@ static av_cold int hevc_init_context(AVCodecContext 
*avctx)
 return AVERROR(ENOMEM);
 s->nb_local_ctx = 1;
 
-s->HEVClc = >local_ctx[0];
-
-s->HEVClc->parent = s;
-s->HEVClc->logctx = avctx;
-s->HEVClc->common_cabac_state = >cabac;
+s->local_ctx[0].parent = s;
+s->local_ctx[0].logctx = avctx;
+s->local_ctx[0].common_cabac_state = >cabac;
 
 s->output_frame = av_frame_alloc();
 if (!s->output_frame)
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 0ed51a5392..6957cd1091 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -452,8 +452,6 @@ typedef struct HEVCContext {
 HEVCLocalContext *local_ctx;
 unsigned   nb_local_ctx;
 
-HEVCLocalContext*HEVClc;
-
 uint8_t threads_type;
 uint8_t threads_number;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: drop HEVCContext.frame

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
09:00:19 2024 +0200| [ba56a300a94bdf5520ac1324a8e7fbaeea430904] | committer: 
Anton Khirnov

lavc/hevcdec: drop HEVCContext.frame

It is merely a redundant pointer to cur_frame->f

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ba56a300a94bdf5520ac1324a8e7fbaeea430904
---

 libavcodec/hevc_cabac.c|  4 ++--
 libavcodec/hevc_filter.c   | 39 ++-
 libavcodec/hevc_refs.c |  3 +--
 libavcodec/hevcdec.c   | 53 +-
 libavcodec/hevcdec.h   |  3 +--
 libavcodec/hevcpred_template.c |  4 ++--
 6 files changed, 50 insertions(+), 56 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 71bd678972..c9da4d7fc1 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -1002,10 +1002,10 @@ void ff_hevc_hls_residual_coding(HEVCLocalContext *lc, 
int x0, int y0,
 
 const uint8_t *scan_x_cg, *scan_y_cg, *scan_x_off, *scan_y_off;
 
-ptrdiff_t stride = s->frame->linesize[c_idx];
+ptrdiff_t stride = s->cur_frame->f->linesize[c_idx];
 int hshift = s->ps.sps->hshift[c_idx];
 int vshift = s->ps.sps->vshift[c_idx];
-uint8_t *dst = >frame->data[c_idx][(y0 >> vshift) * stride +
+uint8_t *dst = >cur_frame->f->data[c_idx][(y0 >> vshift) * stride +
   ((x0 >> hshift) << 
s->ps.sps->pixel_shift)];
 int16_t *coeffs = (int16_t*)(c_idx ? lc->edge_emu_buffer2 : 
lc->edge_emu_buffer);
 uint8_t significant_coeff_group_flag[8][8] = {{0}};
diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c
index 0ba419a7b8..db7525170d 100644
--- a/libavcodec/hevc_filter.c
+++ b/libavcodec/hevc_filter.c
@@ -315,13 +315,13 @@ static void sao_filter_CTB(HEVCLocalContext *lc, const 
HEVCContext *s, int x, in
 for (c_idx = 0; c_idx < (s->ps.sps->chroma_format_idc ? 3 : 1); c_idx++) {
 int x0   = x >> s->ps.sps->hshift[c_idx];
 int y0   = y >> s->ps.sps->vshift[c_idx];
-ptrdiff_t stride_src = s->frame->linesize[c_idx];
+ptrdiff_t stride_src = s->cur_frame->f->linesize[c_idx];
 int ctb_size_h = (1 << (s->ps.sps->log2_ctb_size)) >> 
s->ps.sps->hshift[c_idx];
 int ctb_size_v = (1 << (s->ps.sps->log2_ctb_size)) >> 
s->ps.sps->vshift[c_idx];
 int width= FFMIN(ctb_size_h, (s->ps.sps->width  >> 
s->ps.sps->hshift[c_idx]) - x0);
 int height   = FFMIN(ctb_size_v, (s->ps.sps->height >> 
s->ps.sps->vshift[c_idx]) - y0);
 int tab  = sao_tab[(FFALIGN(width, 8) >> 3) - 1];
-uint8_t *src = >frame->data[c_idx][y0 * stride_src + (x0 << 
s->ps.sps->pixel_shift)];
+uint8_t *src = >cur_frame->f->data[c_idx][y0 * stride_src + (x0 << 
s->ps.sps->pixel_shift)];
 ptrdiff_t stride_dst;
 uint8_t *dst;
 
@@ -484,6 +484,9 @@ static int get_pcm(const HEVCContext *s, int x, int y)
 
 static void deblocking_filter_CTB(const HEVCContext *s, int x0, int y0)
 {
+uint8_t **data = s->cur_frame->f->data;
+int  *linesize = s->cur_frame->f->linesize;
+
 uint8_t *src;
 int x, y;
 int chroma, beta;
@@ -537,18 +540,16 @@ static void deblocking_filter_CTB(const HEVCContext *s, 
int x0, int y0)
 
 tc[0]   = bs0 ? TC_CALC(qp, bs0) : 0;
 tc[1]   = bs1 ? TC_CALC(qp, bs1) : 0;
-src = >frame->data[LUMA][y * s->frame->linesize[LUMA] + 
(x << s->ps.sps->pixel_shift)];
+src = [LUMA][y * linesize[LUMA] + (x << 
s->ps.sps->pixel_shift)];
 if (pcmf) {
 no_p[0] = get_pcm(s, x - 1, y);
 no_p[1] = get_pcm(s, x - 1, y + 4);
 no_q[0] = get_pcm(s, x, y);
 no_q[1] = get_pcm(s, x, y + 4);
-s->hevcdsp.hevc_v_loop_filter_luma_c(src,
- 
s->frame->linesize[LUMA],
+s->hevcdsp.hevc_v_loop_filter_luma_c(src, linesize[LUMA],
  beta, tc, no_p, no_q);
 } else
-s->hevcdsp.hevc_v_loop_filter_luma(src,
-   
s->frame->linesize[LUMA],
+s->hevcdsp.hevc_v_loop_filter_luma(src, linesize[LUMA],
beta, tc, no_p, no_q);
 }
 }
@@ -569,18 +570,16 @@ static void deblocking_filter_CTB(const HEVCContext *s, 
int x0, int y0)
 beta = betatable[av_c

[FFmpeg-cvslog] lavc/hevcdec: rename HEVCFrame.frame to just f

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
08:38:27 2024 +0200| [db84c1c6eff955150ec2a1a5211c15c9101fcbf1] | committer: 
Anton Khirnov

lavc/hevcdec: rename HEVCFrame.frame to just f

This is shorter, loses no information, and is consistent with other
similar structs.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db84c1c6eff955150ec2a1a5211c15c9101fcbf1
---

 libavcodec/d3d12va_hevc.c |  2 +-
 libavcodec/dxva2_hevc.c   |  8 
 libavcodec/hevc_refs.c| 34 
 libavcodec/hevcdec.c  | 50 +++
 libavcodec/hevcdec.h  |  2 +-
 libavcodec/nvdec_hevc.c   |  6 +++---
 libavcodec/vaapi_hevc.c   | 18 -
 libavcodec/vdpau_hevc.c   | 10 +-
 libavcodec/videotoolbox.c |  2 +-
 libavcodec/vulkan_hevc.c  | 10 +-
 10 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/libavcodec/d3d12va_hevc.c b/libavcodec/d3d12va_hevc.c
index 323ade7d83..3a886f3bc1 100644
--- a/libavcodec/d3d12va_hevc.c
+++ b/libavcodec/d3d12va_hevc.c
@@ -156,7 +156,7 @@ static int d3d12va_hevc_end_frame(AVCodecContext *avctx)
 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 return -1;
 
-return ff_d3d12va_common_end_frame(avctx, h->cur_frame->frame, 
_pic->pp, sizeof(ctx_pic->pp),
+return ff_d3d12va_common_end_frame(avctx, h->cur_frame->f, _pic->pp, 
sizeof(ctx_pic->pp),
scale ? _pic->qm : NULL, scale ? sizeof(ctx_pic->qm) : 0, 
update_input_arguments);
 }
 
diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 2d6c2f812f..08b3b1e785 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -170,7 +170,7 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 }
 
 if (frame) {
-fill_picture_entry(>RefPicList[i], 
ff_dxva2_get_surface_index(avctx, ctx, frame->frame, 0), !!(frame->flags & 
HEVC_FRAME_FLAG_LONG_REF));
+fill_picture_entry(>RefPicList[i], 
ff_dxva2_get_surface_index(avctx, ctx, frame->f, 0), !!(frame->flags & 
HEVC_FRAME_FLAG_LONG_REF));
 pp->PicOrderCntValList[i] = frame->poc;
 } else {
 pp->RefPicList[i].bPicEntry = 0xff;
@@ -178,7 +178,7 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 }
 }
 
-fill_picture_entry(>CurrPic, ff_dxva2_get_surface_index(avctx, ctx, 
current_picture->frame, 1), 0);
+fill_picture_entry(>CurrPic, ff_dxva2_get_surface_index(avctx, ctx, 
current_picture->f, 1), 0);
 
 #define DO_REF_LIST(ref_idx, ref_list) { \
 const RefPicList *rpl = >rps[ref_idx]; \
@@ -187,7 +187,7 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 while (!frame && j < rpl->nb_refs) \
 frame = rpl->ref[j++]; \
 if (frame && frame->flags & (HEVC_FRAME_FLAG_LONG_REF | 
HEVC_FRAME_FLAG_SHORT_REF)) \
-pp->ref_list[i] = get_refpic_index(pp, 
ff_dxva2_get_surface_index(avctx, ctx, frame->frame, 0)); \
+pp->ref_list[i] = get_refpic_index(pp, 
ff_dxva2_get_surface_index(avctx, ctx, frame->f, 0)); \
 else \
 pp->ref_list[i] = 0xff; \
 } \
@@ -415,7 +415,7 @@ static int dxva2_hevc_end_frame(AVCodecContext *avctx)
 if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0)
 return -1;
 
-ret = ff_dxva2_common_end_frame(avctx, h->cur_frame->frame,
+ret = ff_dxva2_common_end_frame(avctx, h->cur_frame->f,
 _pic->pp, sizeof(ctx_pic->pp),
 scale ? _pic->qm : NULL, scale ? 
sizeof(ctx_pic->qm) : 0,
 commit_bitstream_and_slice_buffer);
diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c
index ca4b2b8bfd..6019818cf0 100644
--- a/libavcodec/hevc_refs.c
+++ b/libavcodec/hevc_refs.c
@@ -79,7 +79,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
 int i, j, ret;
 for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) {
 HEVCFrame *frame = >DPB[i];
-if (frame->frame)
+if (frame->f)
 continue;
 
 ret = ff_progress_frame_get_buffer(s->avctx, >tf,
@@ -104,10 +104,10 @@ static HEVCFrame *alloc_frame(HEVCContext *s)
 frame->rpl_tab[j] = frame->rpl;
 
 if (s->sei.picture_timing.picture_struct == 
AV_PICTURE_STRUCTURE_TOP_FIELD)
-frame->frame->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
+frame->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST;
 if ((s->sei.picture_timing.picture_struct == 
AV_PICTURE_STRUCTURE_TOP_FIELD) ||
 (s->sei.picture_timing.picture_struct == 
AV_PICTURE

[FFmpeg-cvslog] lavc/hevcdec: deduplicate calling hwaccel decode_params()

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
13:44:04 2024 +0200| [a13b892080811345c9b5ae74ed1a9dbbccd5af52] | committer: 
Anton Khirnov

lavc/hevcdec: deduplicate calling hwaccel decode_params()

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a13b892080811345c9b5ae74ed1a9dbbccd5af52
---

 libavcodec/hevc/hevcdec.c | 36 
 1 file changed, 12 insertions(+), 24 deletions(-)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 4a07fa6612..4e0df4d033 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -2985,49 +2985,37 @@ static int decode_nal_unit(HEVCContext *s, const 
H2645NAL *nal)
 s->nal_unit_type = nal->type;
 s->temporal_id   = nal->temporal_id;
 
+if (FF_HW_HAS_CB(s->avctx, decode_params) &&
+(s->nal_unit_type == HEVC_NAL_VPS ||
+ s->nal_unit_type == HEVC_NAL_SPS ||
+ s->nal_unit_type == HEVC_NAL_PPS ||
+ s->nal_unit_type == HEVC_NAL_SEI_PREFIX ||
+ s->nal_unit_type == HEVC_NAL_SEI_SUFFIX)) {
+ret = FF_HW_CALL(s->avctx, decode_params,
+ nal->type, nal->raw_data, nal->raw_size);
+if (ret < 0)
+goto fail;
+}
+
 switch (s->nal_unit_type) {
 case HEVC_NAL_VPS:
-if (FF_HW_HAS_CB(s->avctx, decode_params)) {
-ret = FF_HW_CALL(s->avctx, decode_params,
- nal->type, nal->raw_data, nal->raw_size);
-if (ret < 0)
-goto fail;
-}
 ret = ff_hevc_decode_nal_vps(, s->avctx, >ps);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_SPS:
-if (FF_HW_HAS_CB(s->avctx, decode_params)) {
-ret = FF_HW_CALL(s->avctx, decode_params,
- nal->type, nal->raw_data, nal->raw_size);
-if (ret < 0)
-goto fail;
-}
 ret = ff_hevc_decode_nal_sps(, s->avctx, >ps,
  s->apply_defdispwin);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_PPS:
-if (FF_HW_HAS_CB(s->avctx, decode_params)) {
-ret = FF_HW_CALL(s->avctx, decode_params,
- nal->type, nal->raw_data, nal->raw_size);
-if (ret < 0)
-goto fail;
-}
 ret = ff_hevc_decode_nal_pps(, s->avctx, >ps);
 if (ret < 0)
 goto fail;
 break;
 case HEVC_NAL_SEI_PREFIX:
 case HEVC_NAL_SEI_SUFFIX:
-if (FF_HW_HAS_CB(s->avctx, decode_params)) {
-ret = FF_HW_CALL(s->avctx, decode_params,
- nal->type, nal->raw_data, nal->raw_size);
-if (ret < 0)
-goto fail;
-}
 ret = ff_hevc_decode_nal_sei(, s->avctx, >sei, >ps, 
s->nal_unit_type);
 if (ret < 0)
 goto fail;

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc*: move to hevc/ subdir

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed May 29 
09:50:48 2024 +0200| [e4601cc3390eec6ccbfc1139bdd102b4e801ae80] | committer: 
Anton Khirnov

lavc/hevc*: move to hevc/ subdir

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e4601cc3390eec6ccbfc1139bdd102b4e801ae80
---

 libavcodec/Makefile| 12 ++--
 libavcodec/aarch64/hevcdsp_init_aarch64.c  |  2 +-
 libavcodec/arm/hevcdsp_arm.h   |  2 +-
 libavcodec/arm/hevcdsp_init_arm.c  |  2 +-
 libavcodec/arm/hevcdsp_init_neon.c |  2 +-
 libavcodec/bsf/extract_extradata.c |  3 +-
 libavcodec/bsf/h265_metadata.c |  3 +-
 libavcodec/bsf/hevc_mp4toannexb.c  |  3 +-
 libavcodec/bsf/remove_extradata.c  |  3 +-
 libavcodec/cbs_h2645.c |  2 +-
 libavcodec/cbs_h265.h  |  3 +-
 libavcodec/d3d12va_hevc.c  |  4 +--
 libavcodec/dxva2_hevc.c|  4 +--
 libavcodec/h2645_parse.c   |  3 +-
 libavcodec/hevc/Makefile   | 36 ++
 libavcodec/{hevc_cabac.c => hevc/cabac.c}  |  2 +-
 libavcodec/{hevc_data.c => hevc/data.c}|  2 +-
 libavcodec/{hevc_data.h => hevc/data.h}|  0
 libavcodec/{hevcdsp.c => hevc/dsp.c}   | 10 +++---
 libavcodec/{hevcdsp.h => hevc/dsp.h}   |  8 ++---
 .../{hevcdsp_template.c => hevc/dsp_template.c}|  2 +-
 libavcodec/{hevc_filter.c => hevc/filter.c}|  0
 libavcodec/{ => hevc}/hevc.h   |  6 ++--
 libavcodec/{ => hevc}/hevcdec.c|  2 +-
 libavcodec/{ => hevc}/hevcdec.h| 33 ++--
 libavcodec/{hevc_mvs.c => hevc/mvs.c}  |  0
 libavcodec/{hevc_parse.c => hevc/parse.c}  |  2 +-
 libavcodec/{hevc_parse.h => hevc/parse.h}  |  4 +--
 libavcodec/{hevc_parser.c => hevc/parser.c}|  6 ++--
 libavcodec/{hevcpred.c => hevc/pred.c} | 10 +++---
 libavcodec/{hevcpred.h => hevc/pred.h} |  6 ++--
 .../{hevcpred_template.c => hevc/pred_template.c}  |  2 +-
 libavcodec/{hevc_ps.c => hevc/ps.c}|  4 +--
 libavcodec/{hevc_ps.h => hevc/ps.h}|  7 +++--
 libavcodec/{hevc_ps_enc.c => hevc/ps_enc.c}|  2 +-
 libavcodec/{hevc_refs.c => hevc/refs.c}|  0
 libavcodec/{hevc_sei.c => hevc/sei.c}  |  4 +--
 libavcodec/{hevc_sei.h => hevc/sei.h}  |  7 +++--
 libavcodec/loongarch/hevcdsp_lasx.h|  2 +-
 libavcodec/loongarch/hevcdsp_lsx.h |  2 +-
 libavcodec/mediacodecdec.c |  2 +-
 libavcodec/mips/hevcdsp_mips.h |  2 +-
 libavcodec/mips/hevcdsp_mmi.c  |  2 +-
 libavcodec/mips/hevcpred_mips.h|  2 +-
 libavcodec/mips/hevcpred_msa.c |  2 +-
 libavcodec/nvdec_hevc.c|  4 +--
 libavcodec/nvenc.c |  2 +-
 libavcodec/ppc/hevcdsp.c   |  2 +-
 libavcodec/qsvenc_hevc.c   |  5 +--
 libavcodec/vaapi_encode_h265.c |  3 +-
 libavcodec/vaapi_hevc.c|  3 +-
 libavcodec/vdpau_hevc.c|  4 +--
 libavcodec/videotoolbox.c  |  2 +-
 libavcodec/vulkan_hevc.c   |  6 ++--
 libavcodec/x86/hevcdsp_init.c  |  2 +-
 libavformat/hevc.c |  2 +-
 libavformat/hevcdec.c  |  2 +-
 libavformat/mov.c  |  2 +-
 libavformat/mpegtsenc.c|  2 +-
 tests/checkasm/hevc_add_res.c  |  2 +-
 tests/checkasm/hevc_deblock.c  |  2 +-
 tests/checkasm/hevc_idct.c |  2 +-
 tests/checkasm/hevc_pel.c  |  2 +-
 tests/checkasm/hevc_sao.c  |  2 +-
 64 files changed, 154 insertions(+), 114 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2443d2c6fd..8ab4398b6c 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -65,6 +65,7 @@ OBJS = ac3_parser.o   
  \
 
 # subsystems
 include $(SRC_PATH)/libavcodec/aac/Makefile
+include $(SRC_PATH)/libavcodec/hevc/Makefile
 include $(SRC_PATH)/libavcodec/vvc/Makefile
 -include $(SRC_PATH)/libavcodec/$(ARCH)/vvc/Makefile
 OBJS-$(CONFIG_AANDCTTABLES)+= aandcttab.o
@@ -105,10 +106,6 @@ OBJS-$(CONFIG_H264PARSE)   += h264_parse.o 
h264_ps.o h264data.o \
 OBJS-$(CONFIG_H264PRED)+= h264pred.o
 OBJS

[FFmpeg-cvslog] lavc/hevcdec: drop HEVCLocalContext.gb

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue May 28 
18:43:13 2024 +0200| [67ca18dd56956892a097388a160bb70f10539d77] | committer: 
Anton Khirnov

lavc/hevcdec: drop HEVCLocalContext.gb

In all HEVCLocalContext instances except the first one, the bitreader is
never used for actually reading bits, but merely for passing the buffer
to ff_init_cabac_decoder(), which is better done directly.

The instance that actually is used for bitreading gets moved to stack in
decode_nal_unit(), which makes its lifetime clearer.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=67ca18dd56956892a097388a160bb70f10539d77
---

 libavcodec/hevc_cabac.c | 17 +
 libavcodec/hevcdec.c| 43 ---
 libavcodec/hevcdec.h|  4 ++--
 3 files changed, 27 insertions(+), 37 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 3f95c9ca05..71bd678972 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -427,14 +427,6 @@ static int cabac_reinit(HEVCLocalContext *lc)
 return skip_bytes(>cc, 0) == NULL ? AVERROR_INVALIDDATA : 0;
 }
 
-static int cabac_init_decoder(HEVCLocalContext *lc)
-{
-GetBitContext *gb = >gb;
-return ff_init_cabac_decoder(>cc,
-  gb->buffer + get_bits_count(gb) / 8,
-  (get_bits_left(gb) + 7) / 8);
-}
-
 static void cabac_init_state(HEVCLocalContext *lc, const HEVCContext *s)
 {
 int init_type = 2 - s->sh.slice_type;
@@ -459,12 +451,13 @@ static void cabac_init_state(HEVCLocalContext *lc, const 
HEVCContext *s)
 lc->stat_coeff[i] = 0;
 }
 
-int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts)
+int ff_hevc_cabac_init(HEVCLocalContext *lc, int ctb_addr_ts,
+   const uint8_t *data, size_t size)
 {
 const HEVCContext *const s = lc->parent;
 
 if (ctb_addr_ts == s->ps.pps->ctb_addr_rs_to_ts[s->sh.slice_ctb_addr_rs]) {
-int ret = cabac_init_decoder(lc);
+int ret = ff_init_cabac_decoder(>cc, data, size);
 if (ret < 0)
 return ret;
 if (s->sh.dependent_slice_segment_flag == 0 ||
@@ -488,7 +481,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, int 
ctb_addr_ts)
 if (s->threads_number == 1)
 ret = cabac_reinit(lc);
 else {
-ret = cabac_init_decoder(lc);
+ret = ff_init_cabac_decoder(>cc, data, size);
 }
 if (ret < 0)
 return ret;
@@ -501,7 +494,7 @@ int ff_hevc_cabac_init(HEVCLocalContext *lc, int 
ctb_addr_ts)
 if (s->threads_number == 1)
 ret = cabac_reinit(lc);
 else {
-ret = cabac_init_decoder(lc);
+ret = ff_init_cabac_decoder(>cc, data, size);
 }
 if (ret < 0)
 return ret;
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 42fd33961b..0a9443505a 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -593,9 +593,8 @@ fail:
 return ret;
 }
 
-static int hls_slice_header(HEVCContext *s)
+static int hls_slice_header(HEVCContext *s, GetBitContext *gb)
 {
-GetBitContext *gb = >HEVClc->gb;
 SliceHeader *sh   = >sh;
 int i, ret;
 
@@ -2533,9 +2532,11 @@ static void hls_decode_neighbour(HEVCLocalContext *lc, 
int x_ctb, int y_ctb,
 lc->ctb_up_left_flag = ((x_ctb > 0) && (y_ctb > 0)  && 
(ctb_addr_in_slice-1 >= s->ps.sps->ctb_width) && 
(s->ps.pps->tile_id[ctb_addr_ts] == 
s->ps.pps->tile_id[s->ps.pps->ctb_addr_rs_to_ts[ctb_addr_rs-1 - 
s->ps.sps->ctb_width]]));
 }
 
-static int hls_decode_entry(HEVCContext *s)
+static int hls_decode_entry(HEVCContext *s, GetBitContext *gb)
 {
 HEVCLocalContext *const lc = s->HEVClc;
+const uint8_t *slice_data = gb->buffer + s->sh.data_offset;
+const size_t   slice_size = gb->buffer_end - gb->buffer - 
s->sh.data_offset;
 int ctb_size= 1 << s->ps.sps->log2_ctb_size;
 int more_data   = 1;
 int x_ctb   = 0;
@@ -2563,7 +2564,7 @@ static int hls_decode_entry(HEVCContext *s)
 y_ctb = (ctb_addr_rs / ((s->ps.sps->width + ctb_size - 1) >> 
s->ps.sps->log2_ctb_size)) << s->ps.sps->log2_ctb_size;
 hls_decode_neighbour(lc, x_ctb, y_ctb, ctb_addr_ts);
 
-ret = ff_hevc_cabac_init(lc, ctb_addr_ts);
+ret = ff_hevc_cabac_init(lc, ctb_addr_ts, slice_data, slice_size);
 if (ret < 0) {
 s->tab_slice_address[ctb_addr_rs] = -1;
 return ret;
@@ -2605,14 +2606,14 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *hevc_lclist,
 int ctb_addr_rs = s->sh.slice_ctb_addr_rs + ctb_row * ((s->ps.sps->width + 
ctb_size - 1) >> s->ps.sps->log2_ct

[FFmpeg-cvslog] lavc/hevcdec: include first row in SliceHeader.offset/size

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue May 28 
18:40:22 2024 +0200| [ac69e6caf6d9b74a215c7fc170574e7bcc4f9fda] | committer: 
Anton Khirnov

lavc/hevcdec: include first row in SliceHeader.offset/size

Will be useful in the following commit.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ac69e6caf6d9b74a215c7fc170574e7bcc4f9fda
---

 libavcodec/hevcdec.c | 19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index d3715f9de7..42fd33961b 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -975,8 +975,8 @@ static int hls_slice_header(HEVCContext *s)
 av_freep(>offset);
 av_freep(>size);
 sh->entry_point_offset = 
av_malloc_array(sh->num_entry_point_offsets, sizeof(unsigned));
-sh->offset = av_malloc_array(sh->num_entry_point_offsets, 
sizeof(int));
-sh->size = av_malloc_array(sh->num_entry_point_offsets, 
sizeof(int));
+sh->offset = 
av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
+sh->size   = 
av_malloc_array(sh->num_entry_point_offsets + 1, sizeof(int));
 if (!sh->entry_point_offset || !sh->offset || !sh->size) {
 sh->num_entry_point_offsets = 0;
 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate memory\n");
@@ -2608,10 +2608,10 @@ static int hls_decode_entry_wpp(AVCodecContext *avctxt, 
void *hevc_lclist,
 int ret;
 
 if(ctb_row) {
-ret = init_get_bits8(>gb, s->data + s->sh.offset[ctb_row - 1], 
s->sh.size[ctb_row - 1]);
+ret = init_get_bits8(>gb, s->data + s->sh.offset[ctb_row], 
s->sh.size[ctb_row]);
 if (ret < 0)
 goto error;
-ff_init_cabac_decoder(>cc, s->data + s->sh.offset[(ctb_row)-1], 
s->sh.size[ctb_row - 1]);
+ff_init_cabac_decoder(>cc, s->data + s->sh.offset[ctb_row], 
s->sh.size[ctb_row]);
 }
 
 while(more_data && ctb_addr_ts < s->ps.sps->ctb_size) {
@@ -2738,8 +2738,8 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 cmpt++;
 }
 }
-s->sh.size[i - 1] = s->sh.entry_point_offset[i] - cmpt;
-s->sh.offset[i - 1] = offset;
+s->sh.size[i]   = s->sh.entry_point_offset[i] - cmpt;
+s->sh.offset[i] = offset;
 
 }
 
@@ -2748,8 +2748,11 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is 
corrupted\n");
 return AVERROR_INVALIDDATA;
 }
-s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
-s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
+s->sh.size  [s->sh.num_entry_point_offsets] = length - offset;
+s->sh.offset[s->sh.num_entry_point_offsets] = offset;
+
+s->sh.offset[0] = s->sh.data_offset;
+s->sh.size[0]   = s->sh.offset[1] - s->sh.offset[0];
 
 s->data = data;
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: drop a useless condition

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue May 28 
18:33:54 2024 +0200| [79c0310acaf3b638cea2258b5b18b575668f250c] | committer: 
Anton Khirnov

lavc/hevcdec: drop a useless condition

hls_slice_data_wpp() is only called when num_entry_point_offsets>0

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=79c0310acaf3b638cea2258b5b18b575668f250c
---

 libavcodec/hevcdec.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index ad2cbd7ece..d3715f9de7 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2742,16 +2742,15 @@ static int hls_slice_data_wpp(HEVCContext *s, const 
H2645NAL *nal)
 s->sh.offset[i - 1] = offset;
 
 }
-if (s->sh.num_entry_point_offsets != 0) {
-offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] 
- cmpt;
-if (length < offset) {
-av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is 
corrupted\n");
-return AVERROR_INVALIDDATA;
-}
-s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
-s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
 
+offset += s->sh.entry_point_offset[s->sh.num_entry_point_offsets - 1] - 
cmpt;
+if (length < offset) {
+av_log(s->avctx, AV_LOG_ERROR, "entry_point_offset table is 
corrupted\n");
+return AVERROR_INVALIDDATA;
 }
+s->sh.size[s->sh.num_entry_point_offsets - 1] = length - offset;
+s->sh.offset[s->sh.num_entry_point_offsets - 1] = offset;
+
 s->data = data;
 
 for (i = 1; i < s->threads_number; i++) {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevcdec: move handling of byte alignment at the end of slice header

2024-06-04 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Tue May 28 
16:59:23 2024 +0200| [74159cbfc30a0202b3c3d6f770143d0e1c30fa5a] | committer: 
Anton Khirnov

lavc/hevcdec: move handling of byte alignment at the end of slice header

Do it in hls_slice_header() rather than cabac_init_decoder() - the
former is a more logical place as according the spec the byte alignment
is a part of the slice header, not slice data. Avoids a second instance
of alignment handling in vaapi_hevc.

Also, check that alignment_bit_equal_to_one is, in fact, equal to one.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=74159cbfc30a0202b3c3d6f770143d0e1c30fa5a
---

 libavcodec/hevc_cabac.c | 2 --
 libavcodec/hevcdec.c| 7 +++
 libavcodec/hevcdec.h| 1 +
 libavcodec/vaapi_hevc.c | 4 +---
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
index 2e639a7e41..3f95c9ca05 100644
--- a/libavcodec/hevc_cabac.c
+++ b/libavcodec/hevc_cabac.c
@@ -430,8 +430,6 @@ static int cabac_reinit(HEVCLocalContext *lc)
 static int cabac_init_decoder(HEVCLocalContext *lc)
 {
 GetBitContext *gb = >gb;
-skip_bits(gb, 1);
-align_get_bits(gb);
 return ff_init_cabac_decoder(>cc,
   gb->buffer + get_bits_count(gb) / 8,
   (get_bits_left(gb) + 7) / 8);
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index ff9a418926..ad2cbd7ece 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -1005,6 +1005,13 @@ static int hls_slice_header(HEVCContext *s)
 skip_bits(gb, 8);  // slice_header_extension_data_byte
 }
 
+ret = get_bits1(gb);
+if (!ret) {
+av_log(s->avctx, AV_LOG_ERROR, "alignment_bit_equal_to_one=0\n");
+return AVERROR_INVALIDDATA;
+}
+sh->data_offset = align_get_bits(gb) - gb->buffer;
+
 // Inferred parameters
 sh->slice_qp = 26U + s->ps.pps->pic_init_qp_minus26 + sh->slice_qp_delta;
 if (sh->slice_qp > 51 ||
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index 5aa3d40450..3824bf621b 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -277,6 +277,7 @@ typedef struct SliceHeader {
 int16_t chroma_offset_l1[16][2];
 
 int slice_ctb_addr_rs;
+unsigned data_offset;
 } SliceHeader;
 
 typedef struct CodingUnit {
diff --git a/libavcodec/vaapi_hevc.c b/libavcodec/vaapi_hevc.c
index 0f5dd50351..f0a0f295d9 100644
--- a/libavcodec/vaapi_hevc.c
+++ b/libavcodec/vaapi_hevc.c
@@ -485,9 +485,7 @@ static int vaapi_hevc_decode_slice(AVCodecContext *avctx,
 .slice_data_size   = size,
 .slice_data_offset = 0,
 .slice_data_flag   = VA_SLICE_DATA_FLAG_ALL,
-/* Add 1 to the bits count here to account for the byte_alignment bit, 
which
- * always is at least one bit and not accounted for otherwise. */
-.slice_data_byte_offset= (get_bits_count(>HEVClc->gb) + 1 + 
7) / 8,
+.slice_data_byte_offset= sh->data_offset,
 .slice_segment_address = sh->slice_segment_addr,
 .slice_qp_delta= sh->slice_qp_delta,
 .slice_cb_qp_offset= sh->slice_cb_qp_offset,

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc_ps: fix variable signedness in ff_hevc_decode_short_term_rps()

2024-05-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Apr 10 
13:36:50 2024 +0200| [4264e4056c41e0dfc01a27d95f600ac91fb5a04f] | committer: 
Anton Khirnov

lavc/hevc_ps: fix variable signedness in ff_hevc_decode_short_term_rps()

It is actually supposed to go negative in the loop over num_negative
pics, but underflow does not break anything as the result is then
assigned to a signed int.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4264e4056c41e0dfc01a27d95f600ac91fb5a04f
---

 libavcodec/hevc_ps.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 1af691414e..d90f172c46 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -197,7 +197,8 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 }
 } else {
-unsigned int prev, nb_positive_pics;
+unsigned int nb_positive_pics;
+
 rps->num_negative_pics = get_ue_golomb_long(gb);
 nb_positive_pics   = get_ue_golomb_long(gb);
 
@@ -209,7 +210,8 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 
 rps->num_delta_pocs = rps->num_negative_pics + nb_positive_pics;
 if (rps->num_delta_pocs) {
-prev = 0;
+int prev = 0;
+
 for (i = 0; i < rps->num_negative_pics; i++) {
 delta_poc = rps->delta_poc_s0[i] = get_ue_golomb_long(gb) + 1;
 if (delta_poc < 1 || delta_poc > 32768) {

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc_ps: reduce the size of ShortTermRPS.used

2024-05-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Apr 10 
11:27:51 2024 +0200| [9127819d514a3a82031f7448b40714f2880d7804] | committer: 
Anton Khirnov

lavc/hevc_ps: reduce the size of ShortTermRPS.used

It is currently an array of 32 uint8_t, each storing a single flag. A
single uint32_t is sufficient.

Reduces sizeof(HEVCSPS) by 1792 bytes.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9127819d514a3a82031f7448b40714f2880d7804
---

 libavcodec/hevc_ps.c | 33 +++--
 libavcodec/hevc_ps.h |  2 +-
 libavcodec/hevc_refs.c   |  6 +++---
 libavcodec/vulkan_hevc.c | 13 +
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index a6b0021bc3..76fe507e7b 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -107,6 +107,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 int k  = 0;
 int i;
 
+rps->used= 0;
 rps->rps_predict = 0;
 
 if (rps != sps->st_rps && sps->nb_st_rps)
@@ -114,6 +115,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 
 if (rps->rps_predict) {
 const ShortTermRPS *rps_ridx;
+uint8_t used[32] = { 0 };
 int delta_rps;
 
 if (is_slice_header) {
@@ -139,13 +141,13 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 delta_rps  = (1 - (rps->delta_rps_sign << 1)) * rps->abs_delta_rps;
 for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
-int used = rps->used[k] = get_bits1(gb);
+used[k] = get_bits1(gb);
 
 rps->use_delta_flag = 0;
-if (!used)
+if (!used[k])
 rps->use_delta_flag = get_bits1(gb);
 
-if (used || rps->use_delta_flag) {
+if (used[k] || rps->use_delta_flag) {
 if (i < rps_ridx->num_delta_pocs)
 delta_poc = delta_rps + rps_ridx->delta_poc[i];
 else
@@ -157,7 +159,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 }
 
-if (k >= FF_ARRAY_ELEMS(rps->used)) {
+if (k >= FF_ARRAY_ELEMS(used)) {
 av_log(avctx, AV_LOG_ERROR,
"Invalid num_delta_pocs: %d\n", k);
 return AVERROR_INVALIDDATA;
@@ -167,35 +169,38 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 rps->num_negative_pics = k0;
 // sort in increasing order (smallest first)
 if (rps->num_delta_pocs != 0) {
-int used, tmp;
+int u, tmp;
 for (i = 1; i < rps->num_delta_pocs; i++) {
 delta_poc = rps->delta_poc[i];
-used  = rps->used[i];
+u = used[i];
 for (k = i - 1; k >= 0; k--) {
 tmp = rps->delta_poc[k];
 if (delta_poc < tmp) {
 rps->delta_poc[k + 1] = tmp;
-rps->used[k + 1]  = rps->used[k];
+used[k + 1]   = used[k];
 rps->delta_poc[k] = delta_poc;
-rps->used[k]  = used;
+used[k]   = u;
 }
 }
 }
 }
 if ((rps->num_negative_pics >> 1) != 0) {
-int used;
+int u;
 k = rps->num_negative_pics - 1;
 // flip the negative values to largest first
 for (i = 0; i < rps->num_negative_pics >> 1; i++) {
 delta_poc = rps->delta_poc[i];
-used  = rps->used[i];
+u = used[i];
 rps->delta_poc[i] = rps->delta_poc[k];
-rps->used[i]  = rps->used[k];
+used[i]   = used[k];
 rps->delta_poc[k] = delta_poc;
-rps->used[k]  = used;
+used[k]   = u;
 k--;
 }
 }
+
+for (unsigned i = 0; i < FF_ARRAY_ELEMS(used); i++)
+rps->used |= used[i] * (1 << i);
 } else {
 unsigned int nb_positive_pics;
 
@@ -222,7 +227,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 prev -= delta_poc;
 rps->delta_poc[i] = prev;
-rps->used[i]  = get_bits1(gb);
+rps->used|= get_bits1(gb) * (1 << i);
 }
 prev = 0;
 for (i = 0; i < nb_positive_pics; i++) {
@@ -235,7 +240,7 @@ int ff_hevc_decode_shor

[FFmpeg-cvslog] lavc/hevc_ps/HEVCSPS: change flags into uint8_t

2024-05-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Apr 10 
12:28:09 2024 +0200| [6fed1841a1f5dd3cdcf343f77925af0781ebe83a] | committer: 
Anton Khirnov

lavc/hevc_ps/HEVCSPS: change flags into uint8_t

Reduces sizeof(HEVCSPS) by 64 bytes.

Also improve flag names: drop redundant suffixes and prefixes, and
consistently use disabled/enabled.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=6fed1841a1f5dd3cdcf343f77925af0781ebe83a
---

 libavcodec/dxva2_hevc.c| 24 +--
 libavcodec/hevc_cabac.c| 36 
 libavcodec/hevc_filter.c   |  8 ++--
 libavcodec/hevc_parser.c   |  2 +-
 libavcodec/hevc_ps.c   | 95 +-
 libavcodec/hevc_ps.h   | 66 ++---
 libavcodec/hevcdec.c   | 10 ++---
 libavcodec/hevcpred_template.c |  4 +-
 libavcodec/mips/hevcpred_msa.c |  6 +--
 libavcodec/nvdec_hevc.c| 42 +--
 libavcodec/qsvenc_hevc.c   |  2 +-
 libavcodec/vaapi_hevc.c| 42 +--
 libavcodec/vdpau_hevc.c| 36 
 libavcodec/vulkan_hevc.c   | 56 -
 14 files changed, 214 insertions(+), 215 deletions(-)

diff --git a/libavcodec/dxva2_hevc.c b/libavcodec/dxva2_hevc.c
index 31d74a7164..b500d7917a 100644
--- a/libavcodec/dxva2_hevc.c
+++ b/libavcodec/dxva2_hevc.c
@@ -72,7 +72,7 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 pp->PicHeightInMinCbsY = sps->min_cb_height;
 
 pp->wFormatAndSequenceInfoFlags = (sps->chroma_format_idc <<  
0) |
-  (sps->separate_colour_plane_flag<<  
2) |
+  (sps->separate_colour_plane <<  
2) |
   ((sps->bit_depth - 8)   <<  
3) |
   ((sps->bit_depth - 8)   <<  
6) |
   ((sps->log2_max_poc_lsb - 4)<<  
9) |
@@ -99,18 +99,18 @@ void ff_dxva2_hevc_fill_picture_parameters(const 
AVCodecContext *avctx, AVDXVACo
 pp->wNumBitsForShortTermRPSInSlice   = 
h->sh.short_term_ref_pic_set_size;
 }
 
-pp->dwCodingParamToolFlags = (sps->scaling_list_enable_flag
  <<  0) |
- (sps->amp_enabled_flag
  <<  1) |
+pp->dwCodingParamToolFlags = (sps->scaling_list_enabled
  <<  0) |
+ (sps->amp_enabled 
  <<  1) |
  (sps->sao_enabled 
  <<  2) |
- (sps->pcm_enabled_flag
  <<  3) |
- ((sps->pcm_enabled_flag ? (sps->pcm.bit_depth 
- 1) : 0)<<  4) |
- ((sps->pcm_enabled_flag ? 
(sps->pcm.bit_depth_chroma - 1) : 0) <<  8) |
- ((sps->pcm_enabled_flag ? 
(sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
- ((sps->pcm_enabled_flag ? 
(sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
- (sps->pcm.loop_filter_disable_flag
  << 16) |
- (sps->long_term_ref_pics_present_flag 
  << 17) |
- (sps->sps_temporal_mvp_enabled_flag   
  << 18) |
- (sps->sps_strong_intra_smoothing_enable_flag  
  << 19) |
+ (sps->pcm_enabled 
  <<  3) |
+ ((sps->pcm_enabled  ? (sps->pcm.bit_depth 
- 1) : 0)<<  4) |
+ ((sps->pcm_enabled  ? 
(sps->pcm.bit_depth_chroma - 1) : 0) <<  8) |
+ ((sps->pcm_enabled  ? 
(sps->pcm.log2_min_pcm_cb_size - 3) : 0) << 12) |
+ ((sps->pcm_enabled  ? 
(sps->pcm.log2_max_pcm_cb_size - sps->pcm.log2_min_pcm_cb_size) : 0) << 14) |
+ (sps->pcm_loop_filter_disabled
  << 16) |
+ (sps->long_term_ref_pics_present  
  << 17) |
+ (sps->temporal_mvp_enabled
  << 18) |
+ (sps->strong_intra_smoothing_enabled  
  << 19) |
  (pps->dependent_slice_segments_enabled_flag   
  << 20) |
 

[FFmpeg-cvslog] lavc/hevc_ps: do not store delta_poc_s[01] in ShortTermRPS

2024-05-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Apr 10 
13:46:20 2024 +0200| [d8936678673d05410b3462c41dba190cc5e23705] | committer: 
Anton Khirnov

lavc/hevc_ps: do not store delta_poc_s[01] in ShortTermRPS

They are only used in vulkan_hevc and are not actually needed, as they
can be computed from delta_poc.

Reduces sizeof(HEVCSPS) by 16kB.

Also, fix a typo (s0->s1) in the code being touched.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d8936678673d05410b3462c41dba190cc5e23705
---

 libavcodec/hevc_ps.c | 4 ++--
 libavcodec/hevc_ps.h | 2 --
 libavcodec/vulkan_hevc.c | 9 ++---
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index d90f172c46..a6b0021bc3 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -213,7 +213,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 int prev = 0;
 
 for (i = 0; i < rps->num_negative_pics; i++) {
-delta_poc = rps->delta_poc_s0[i] = get_ue_golomb_long(gb) + 1;
+delta_poc = get_ue_golomb_long(gb) + 1;
 if (delta_poc < 1 || delta_poc > 32768) {
 av_log(avctx, AV_LOG_ERROR,
 "Invalid value of delta_poc: %d\n",
@@ -226,7 +226,7 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 }
 prev = 0;
 for (i = 0; i < nb_positive_pics; i++) {
-delta_poc = rps->delta_poc_s1[i] = get_ue_golomb_long(gb) + 1;
+delta_poc = get_ue_golomb_long(gb) + 1;
 if (delta_poc < 1 || delta_poc > 32768) {
 av_log(avctx, AV_LOG_ERROR,
 "Invalid value of delta_poc: %d\n",
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index 3cd2eac923..1d3bdca4c6 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -78,8 +78,6 @@ typedef struct ShortTermRPS {
 unsigned int num_negative_pics;
 int num_delta_pocs;
 int rps_idx_num_delta_pocs;
-int32_t delta_poc_s0[32];
-int32_t delta_poc_s1[32];
 int32_t delta_poc[32];
 uint8_t used[32];
 } ShortTermRPS;
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index df86049d22..21cf49c0ec 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -351,6 +351,8 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
 pal->PredictorPaletteEntries[i][j] = 
sps->sps_palette_predictor_initializer[i][j];
 
 for (int i = 0; i < sps->nb_st_rps; i++) {
+const ShortTermRPS *st_rps = >st_rps[i];
+
 str[i] = (StdVideoH265ShortTermRefPicSet) {
 .flags = (StdVideoH265ShortTermRefPicSetFlags) {
 .inter_ref_pic_set_prediction_flag = 
sps->st_rps[i].rps_predict,
@@ -375,13 +377,14 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
 str[i].used_by_curr_pic_flag |= sps->st_rps[i].used[j] << j;
 
 for (int j = 0; j < str[i].num_negative_pics; j++) {
-str[i].delta_poc_s0_minus1[j] = sps->st_rps[i].delta_poc_s0[j] - 1;
+str[i].delta_poc_s0_minus1[j] = st_rps->delta_poc[j] - (j ? 
st_rps->delta_poc[j - 1] : 0) - 1;
 str[i].used_by_curr_pic_s0_flag |= sps->st_rps[i].used[j] << j;
 }
 
 for (int j = 0; j < str[i].num_positive_pics; j++) {
-str[i].delta_poc_s1_minus1[j] = sps->st_rps[i].delta_poc_s1[j] - 1;
-str[i].used_by_curr_pic_s0_flag |= 
sps->st_rps[i].used[str[i].num_negative_pics + j] << j;
+str[i].delta_poc_s1_minus1[j] = 
st_rps->delta_poc[st_rps->num_negative_pics + j] -
+(j ? 
st_rps->delta_poc[st_rps->num_negative_pics + j - 1] : 0) - 1;
+str[i].used_by_curr_pic_s1_flag |= 
sps->st_rps[i].used[str[i].num_negative_pics + j] << j;
 }
 }
 

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-cvslog] lavc/hevc_ps: compactify ShortTermRPS

2024-05-31 Thread Anton Khirnov
ffmpeg | branch: master | Anton Khirnov  | Wed Apr 10 
14:42:37 2024 +0200| [63a96dbcced2a67e96ee7306874dd2574e2d7d74] | committer: 
Anton Khirnov

lavc/hevc_ps: compactify ShortTermRPS

Do not use larger fields than needed, use size-1 bitfields for flags.

Reduces sizeof(HEVCSPS) by 1280 bytes.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=63a96dbcced2a67e96ee7306874dd2574e2d7d74
---

 libavcodec/hevc_ps.c |  6 +++---
 libavcodec/hevc_ps.h | 19 +++
 libavcodec/vulkan_hevc.c |  2 +-
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c
index 76fe507e7b..7b486ce0af 100644
--- a/libavcodec/hevc_ps.c
+++ b/libavcodec/hevc_ps.c
@@ -143,11 +143,11 @@ int ff_hevc_decode_short_term_rps(GetBitContext *gb, 
AVCodecContext *avctx,
 for (i = 0; i <= rps_ridx->num_delta_pocs; i++) {
 used[k] = get_bits1(gb);
 
-rps->use_delta_flag = 0;
+rps->use_delta = 0;
 if (!used[k])
-rps->use_delta_flag = get_bits1(gb);
+rps->use_delta = get_bits1(gb);
 
-if (used[k] || rps->use_delta_flag) {
+if (used[k] || rps->use_delta) {
 if (i < rps_ridx->num_delta_pocs)
 delta_poc = delta_rps + rps_ridx->delta_poc[i];
 else
diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h
index ed6372c747..d06d7cf1d4 100644
--- a/libavcodec/hevc_ps.h
+++ b/libavcodec/hevc_ps.h
@@ -70,16 +70,19 @@ typedef struct HEVCHdrParams {
 } HEVCHdrParams;
 
 typedef struct ShortTermRPS {
-uint8_t rps_predict;
-unsigned int delta_idx;
-uint8_t use_delta_flag;
-uint8_t delta_rps_sign;
-unsigned int abs_delta_rps;
-unsigned int num_negative_pics;
-int num_delta_pocs;
-int rps_idx_num_delta_pocs;
 int32_t delta_poc[32];
 uint32_t used;
+
+uint8_t delta_idx;
+uint8_t num_negative_pics;
+uint8_t num_delta_pocs;
+uint8_t rps_idx_num_delta_pocs;
+
+uint16_t abs_delta_rps;
+unsigned delta_rps_sign:1;
+
+unsigned rps_predict:1;
+unsigned use_delta:1;
 } ShortTermRPS;
 
 typedef struct HEVCWindow {
diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c
index a35f3d992d..5583f56285 100644
--- a/libavcodec/vulkan_hevc.c
+++ b/libavcodec/vulkan_hevc.c
@@ -359,7 +359,7 @@ static void set_sps(const HEVCSPS *sps, int sps_idx,
 .delta_rps_sign = sps->st_rps[i].delta_rps_sign,
 },
 .delta_idx_minus1 = sps->st_rps[i].delta_idx - 1,
-.use_delta_flag = sps->st_rps[i].use_delta_flag,
+.use_delta_flag = sps->st_rps[i].use_delta,
 .abs_delta_rps_minus1 = sps->st_rps[i].abs_delta_rps - 1,
 .used_by_curr_pic_flag= 0x0,
 .used_by_curr_pic_s0_flag = 0x0,

___
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".


  1   2   3   4   5   6   7   8   9   10   >