From 6294e4846dcfb484034e80b08d9fc4d605855e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 14 Feb 2025 01:23:52 +0100 Subject: [PATCH] demux/stheader: use atomic types for mp_codec_params names Notably they are exchanged between demux and decode thread. It's fine because we know those pointers will be alive as long as avctx is alive. And only the value may change during decoding in rare situations. Make those pointers atomic for the sake of it. It shouldn't change anything, except some codegen. From https://www.gnu.org/software/libc/manual/html_node/Atomic-Types.html#Atomic-Types: In practice, you can assume that int is atomic. You can also assume that pointer types are atomic; that is very convenient. Both of these assumptions are true on all of the machines that the GNU C Library supports and on all POSIX systems we know of. --- demux/stheader.h | 11 ++++++----- sub/sd_ass.c | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/demux/stheader.h b/demux/stheader.h index e28678a6a6..d0d9b2a52a 100644 --- a/demux/stheader.h +++ b/demux/stheader.h @@ -18,6 +18,7 @@ #ifndef MPLAYER_STHEADER_H #define MPLAYER_STHEADER_H +#include #include #include "common/common.h" @@ -70,19 +71,19 @@ struct mp_codec_params { enum stream_type type; // E.g. "h264" (usually corresponds to AVCodecDescriptor.name) - const char *codec; + const char *_Atomic codec; // Usually corresponds to AVCodecDescriptor.long_name - const char *codec_desc; + const char *_Atomic codec_desc; // Corresponding codec profile - const char *codec_profile; + const char *_Atomic codec_profile; // E.g. "h264" (usually corresponds to AVCodec.name) - const char *decoder; + const char *_Atomic decoder; // Usually corresponds to AVCodec.long_name - const char *decoder_desc; + const char *_Atomic decoder_desc; // Usually a FourCC, exact meaning depends on codec. unsigned int codec_tag; diff --git a/sub/sd_ass.c b/sub/sd_ass.c index 8f703dfa8e..2f27b6a3e4 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -316,7 +316,7 @@ static int init(struct sd *sd) ctx->packer = mp_ass_packer_alloc(ctx); // Subtitles does not have any profile value, so put the converted type as a profile. - const char **desc = ctx->converter ? &sd->codec->codec_profile : &sd->codec->codec_desc; + const char *_Atomic *desc = ctx->converter ? &sd->codec->codec_profile : &sd->codec->codec_desc; switch (ctx->ass_track->track_type) { case TRACK_TYPE_ASS: *desc = "Advanced Sub Station Alpha";