diff mbox series

[FFmpeg-devel,04/18] avcodec/hevcdec: Add pointers to logctx and parent ctx to HEVCLocalCtx

Message ID DB6PR0101MB2214341AC45DCBF83D4E056F8FBA9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com
State Accepted
Commit 1837ae9d5f3eb8483c76dc708e68e466f9021cac
Headers show
Series [FFmpeg-devel,v2,01/18] avcodec/pthread_slice: Don't reinitialise initialised mutex | expand


Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt June 30, 2022, 10:29 p.m. UTC
It is safe for a slice thread to read the main context
and therefore it is safe to add a pointer to const HEVCContext
(namely the parent context) to each HEVCLocalContext.
It is also safe (and actually redundant) to add a pointer
to a logcontext to HEVCLocalContext.

Doing so allows to pass the HEVCLocalContext as context in
the parts of the code that is run slice-threaded when slice-threading
is in use (currently these parts of the code use ordinary
HEVCContext*). This way one is not tempted to modify
the main context from the slice contexts.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
One could btw also cache the pointers to the current SPS and PPS;
doing so would make several accesses to the parent context superfluous.

 libavcodec/hevcdec.c | 4 ++++
 libavcodec/hevcdec.h | 3 +++
 2 files changed, 7 insertions(+)
diff mbox series


diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 5ad02742ba..111da42836 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -2661,6 +2661,8 @@  static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal)
             res = AVERROR(ENOMEM);
             goto error;
+        s->HEVClcList[i]->logctx = s->avctx;
+        s->HEVClcList[i]->parent = s->sList[i];
     offset = (lc->gb.index >> 3);
@@ -3646,6 +3648,8 @@  static av_cold int hevc_init_context(AVCodecContext *avctx)
     s->sList = av_mallocz(sizeof(HEVCContext*) * s->threads_number);
     if (!s->HEVClc || !s->HEVClcList || !s->sList)
         return AVERROR(ENOMEM);
+    s->HEVClc->parent = s;
+    s->HEVClc->logctx = avctx;
     s->HEVClcList[0] = s->HEVClc;
     s->sList[0] = s;
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index ff2199aa5a..a4cea2284d 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -428,6 +428,9 @@  typedef struct HEVCLocalContext {
     uint8_t first_qp_group;
+    void *logctx;
+    const struct HEVCContext *parent;
     GetBitContext gb;
     CABACContext cc;