[FFmpeg-devel] [PATCH 1/5] avcodec/progressframe: Explain how unnamed union can simplify accesses
Andreas Rheinhardt
andreas.rheinhardt at outlook.com
Fri Apr 19 18:58:10 EEST 2024
This relies on the common initial seqence guarantee
(and on C11 support for unnamed members).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
Alternatively, we could rely on type punning via unions and even use
union {
AVFrame *const f;
ProgressFrame pf;
};
libavcodec/progressframe.h | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/libavcodec/progressframe.h b/libavcodec/progressframe.h
index dc841f30d2..428a461659 100644
--- a/libavcodec/progressframe.h
+++ b/libavcodec/progressframe.h
@@ -58,6 +58,18 @@
struct AVCodecContext;
+/**
+ * The ProgressFrame structure.
+ * Hint: It is guaranteed that the AVFrame pointer is at the start
+ * of ProgressFrame. This allows to use an unnamed
+ * union {
+ * struct {
+ * AVFrame *f;
+ * };
+ * ProgressFrame pf;
+ * };
+ * to simplify accessing the embedded AVFrame.
+ */
typedef struct ProgressFrame {
struct AVFrame *f;
struct ProgressInternal *progress;
--
2.40.1
More information about the ffmpeg-devel
mailing list