From: Anton Khirnov <anton@khirnov.net>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: Re: [FFmpeg-devel] [PATCH 09/18] avcodec/hevcdec: Add stat_coeffs to HEVCABACState
Date: Sat, 02 Jul 2022 10:34:49 +0200
Message-ID: <165675088963.31466.628326916294051579@lain.khirnov.net> (raw)
In-Reply-To: =?utf-8?q?=3CDB6PR0101MB22142A7A49F01D9EB61518608FBA9=40DB6PR01?= =?utf-8?q?01MB2214=2Eeurprd01=2Eprod=2Eexchangelabs=2Ecom=3E?=
Quoting Andreas Rheinhardt (2022-07-01 00:29:40)
> The HEVC decoder has both HEVCContext and HEVCLocalContext
> structures. The latter is supposed to be the structure
> containing the per-slicethread state.
>
> Yet that is not how it is handled in practice: Each HEVCLocalContext
> has a unique HEVCContext allocated for it and each of these
> coincides with the main HEVCContext except in exactly one field:
> The corresponding HEVCLocalContext.
> This makes it possible to pass the HEVCContext everywhere where
> logically a HEVCLocalContext should be used.
>
> This led to confusion in the first version of what eventually became
> commit c8bc0f66a875bc3708d8dc11b757f2198606ffd7:
> Before said commit, the initialization of the Rice parameter derivation
> state was incorrect; the fix for single-threaded as well as
> frame-threaded decoding was to add backup stats to HEVCContext
> that are used when the cabac state is updated*, see
> https://ffmpeg.org/pipermail/ffmpeg-devel/2020-August/268861.html
> Yet due to what has been said above, this does not work for
> slice-threading, because the each HEVCLocalContext has its own
> HEVCContext, so the Rice parameter state would not be transferred
> between threads.
>
> This is fixed in c8bc0f66a875bc3708d8dc11b757f2198606ffd7
> by a hack: It rederives what the previous thread was and accesses
> the corresponding HEVCContext.
>
> Fix this by treating the Rice parameter state the same way
> the ordinary CABAC parameters are shared between threads:
> Make them part of the same struct that is shared between
> slice threads. This does not cause races, because
> the parts of the code that access these Rice parameters
> are a subset of the parts of code that access the CABAC parameters.
>
> *: And if the persistent_rice_adaptation_enabled_flag is set.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> libavcodec/hevc_cabac.c | 17 ++++++++---------
> libavcodec/hevcdec.c | 10 +++++-----
> libavcodec/hevcdec.h | 10 +++++++---
> 3 files changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/libavcodec/hevc_cabac.c b/libavcodec/hevc_cabac.c
> index a194f8a02a..985c97ef2a 100644
> --- a/libavcodec/hevc_cabac.c
> +++ b/libavcodec/hevc_cabac.c
> @@ -453,19 +453,18 @@ void ff_hevc_save_states(HEVCContext *s, int ctb_addr_ts)
> (ctb_addr_ts % s->ps.sps->ctb_width == 2 ||
> (s->ps.sps->ctb_width == 2 &&
> ctb_addr_ts % s->ps.sps->ctb_width == 0))) {
> - memcpy(s->cabac_state, s->HEVClc->cabac_state, HEVC_CONTEXTS);
> + memcpy(s->cabac->state, s->HEVClc->cabac_state, HEVC_CONTEXTS);
So if I'm reading this right, this copies the per-slice-context state
into the decoder-global state. And it's done from slice threads with no
locks. So how is this not racy?
--
Anton Khirnov
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev reply other threads:[~2022-07-02 8:35 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 21:48 [FFmpeg-devel] [PATCH v2 01/18] avcodec/pthread_slice: Don't reinitialise initialised mutex Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 02/18] fate/hevc: add clip for persistent_rice_adaptation_enabled_flag Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 03/18] avcodec/hevcdec: Don't initialize HEVCContexts twice Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 04/18] avcodec/hevcdec: Add pointers to logctx and parent ctx to HEVCLocalCtx Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 05/18] avcodec/hevc_refs: Constify ff_hevc_get_ref_list() Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 06/18] avcodec/hevc_cabac: Don't cast const away unnecessarily Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 07/18] avcodec/hevc_mvs: Pass HEVCLocalContext when slice-threading Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 08/18] avcodec/hevc_filter: " Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 09/18] avcodec/hevcdec: Add stat_coeffs to HEVCABACState Andreas Rheinhardt
2022-07-02 8:34 ` Anton Khirnov [this message]
2022-07-02 10:40 ` Andreas Rheinhardt
2022-07-02 11:31 ` Andreas Rheinhardt
2022-07-02 11:43 ` Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 10/18] avcodec/hevc_cabac: Pass HEVCLocalContext when slice-threading Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 11/18] avcodec/hevcpred: " Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 12/18] avcodec/hevcdec: " Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 13/18] avcodec/hevcdec: Pass HEVCLocalContext** via execute2 Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 14/18] avcodec/hevcdec: Don't allocate redundant HEVCContexts Andreas Rheinhardt
2022-07-01 21:25 ` Michael Niedermayer
2022-07-02 6:32 ` Andreas Rheinhardt
2022-07-05 22:24 ` Michael Niedermayer
2022-07-06 8:21 ` Andreas Rheinhardt
2022-07-23 5:44 ` Andreas Rheinhardt
2022-07-23 14:38 ` Michael Niedermayer
2022-07-23 21:42 ` Andreas Rheinhardt
2022-07-24 21:23 ` Michael Niedermayer
2022-07-24 21:26 ` Andreas Rheinhardt
2022-07-25 19:44 ` Michael Niedermayer
2022-07-25 19:58 ` Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 15/18] avcodec/hevcdec: Check allocation Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 16/18] avcodec/pthread_slice: Combine allocating and zeroing entries Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 17/18] avcodec/pthread_slice: Reuse buffer if possible Andreas Rheinhardt
2022-07-01 11:33 ` Paul B Mahol
2022-07-01 13:21 ` Tomas Härdin
2022-07-22 20:04 ` Andreas Rheinhardt
2022-06-30 22:29 ` [FFmpeg-devel] [PATCH 18/18] avcodec/hevcdec: Move allocation after error checks Andreas Rheinhardt
2022-07-01 13:30 ` [FFmpeg-devel] [PATCH v2 01/18] avcodec/pthread_slice: Don't reinitialise initialised mutex Tomas Härdin
2022-07-01 12:10 [FFmpeg-devel] [PATCH 09/18] avcodec/hevcdec: Add stat_coeffs to HEVCABACState Anton Khirnov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=165675088963.31466.628326916294051579@lain.khirnov.net \
--to=anton@khirnov.net \
--cc=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git