Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Anton Khirnov <anton@khirnov.net>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 03/29] libavutil/opt: rework figuring out option sizes
Date: Mon,  4 Mar 2024 14:06:18 +0100
Message-ID: <20240304130657.30631-3-anton@khirnov.net> (raw)
In-Reply-To: <20240304130657.30631-1-anton@khirnov.net>

Replace the opt_size() function, currently only called from
av_opt_copy(), with
* a constant array of element sizes
* a function that signals whether an option type is POD (i.e.
  memcpyable) or not

Will be useful in following commits.
---
 libavutil/opt.c | 100 +++++++++++++++++++++++++++---------------------
 1 file changed, 56 insertions(+), 44 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index b372c76120..051a121331 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -56,6 +56,56 @@ const AVOption *av_opt_next(const void *obj, const AVOption *last)
     return NULL;
 }
 
+static const size_t opt_elem_size[] = {
+    [AV_OPT_TYPE_FLAGS]         = sizeof(unsigned),
+    [AV_OPT_TYPE_INT]           = sizeof(int),
+    [AV_OPT_TYPE_INT64]         = sizeof(int64_t),
+    [AV_OPT_TYPE_UINT64]        = sizeof(uint64_t),
+    [AV_OPT_TYPE_DOUBLE]        = sizeof(double),
+    [AV_OPT_TYPE_FLOAT]         = sizeof(float),
+    [AV_OPT_TYPE_STRING]        = sizeof(char *),
+    [AV_OPT_TYPE_RATIONAL]      = sizeof(AVRational),
+    [AV_OPT_TYPE_BINARY]        = sizeof(uint8_t *),
+    [AV_OPT_TYPE_DICT]          = sizeof(AVDictionary *),
+    [AV_OPT_TYPE_IMAGE_SIZE]    = sizeof(int[2]),
+    [AV_OPT_TYPE_VIDEO_RATE]    = sizeof(AVRational),
+    [AV_OPT_TYPE_PIXEL_FMT]     = sizeof(int),
+    [AV_OPT_TYPE_SAMPLE_FMT]    = sizeof(int),
+    [AV_OPT_TYPE_DURATION]      = sizeof(int64_t),
+    [AV_OPT_TYPE_COLOR]         = sizeof(uint8_t[4]),
+#if FF_API_OLD_CHANNEL_LAYOUT
+    [AV_OPT_TYPE_CHANNEL_LAYOUT]= sizeof(uint64_t),
+#endif
+    [AV_OPT_TYPE_CHLAYOUT]      = sizeof(AVChannelLayout),
+    [AV_OPT_TYPE_BOOL]          = sizeof(int),
+};
+
+// option is plain old data
+static int opt_is_pod(enum AVOptionType type)
+{
+    switch (type) {
+    case AV_OPT_TYPE_FLAGS:
+    case AV_OPT_TYPE_INT:
+    case AV_OPT_TYPE_INT64:
+    case AV_OPT_TYPE_DOUBLE:
+    case AV_OPT_TYPE_FLOAT:
+    case AV_OPT_TYPE_RATIONAL:
+    case AV_OPT_TYPE_UINT64:
+    case AV_OPT_TYPE_IMAGE_SIZE:
+    case AV_OPT_TYPE_PIXEL_FMT:
+    case AV_OPT_TYPE_SAMPLE_FMT:
+    case AV_OPT_TYPE_VIDEO_RATE:
+    case AV_OPT_TYPE_DURATION:
+    case AV_OPT_TYPE_COLOR:
+#if FF_API_OLD_CHANNEL_LAYOUT
+    case AV_OPT_TYPE_CHANNEL_LAYOUT:
+#endif
+    case AV_OPT_TYPE_BOOL:
+        return 1;
+    }
+    return 0;
+}
+
 static int read_number(const AVOption *o, const void *dst, double *num, int *den, int64_t *intnum)
 {
     switch (o->type) {
@@ -1850,45 +1900,6 @@ void *av_opt_ptr(const AVClass *class, void *obj, const char *name)
     return (uint8_t*)obj + opt->offset;
 }
 
-static int opt_size(enum AVOptionType type)
-{
-    switch(type) {
-    case AV_OPT_TYPE_BOOL:
-    case AV_OPT_TYPE_INT:
-    case AV_OPT_TYPE_FLAGS:
-        return sizeof(int);
-    case AV_OPT_TYPE_DURATION:
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    case AV_OPT_TYPE_CHANNEL_LAYOUT:
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-    case AV_OPT_TYPE_INT64:
-    case AV_OPT_TYPE_UINT64:
-        return sizeof(int64_t);
-    case AV_OPT_TYPE_DOUBLE:
-        return sizeof(double);
-    case AV_OPT_TYPE_FLOAT:
-        return sizeof(float);
-    case AV_OPT_TYPE_STRING:
-        return sizeof(uint8_t*);
-    case AV_OPT_TYPE_VIDEO_RATE:
-    case AV_OPT_TYPE_RATIONAL:
-        return sizeof(AVRational);
-    case AV_OPT_TYPE_BINARY:
-        return sizeof(uint8_t*) + sizeof(int);
-    case AV_OPT_TYPE_IMAGE_SIZE:
-        return sizeof(int[2]);
-    case AV_OPT_TYPE_PIXEL_FMT:
-        return sizeof(enum AVPixelFormat);
-    case AV_OPT_TYPE_SAMPLE_FMT:
-        return sizeof(enum AVSampleFormat);
-    case AV_OPT_TYPE_COLOR:
-        return 4;
-    }
-    return AVERROR(EINVAL);
-}
-
 int av_opt_copy(void *dst, const void *src)
 {
     const AVOption *o = NULL;
@@ -1939,12 +1950,13 @@ int av_opt_copy(void *dst, const void *src)
         } else if (o->type == AV_OPT_TYPE_CHLAYOUT) {
             if (field_dst != field_src)
                 ret = av_channel_layout_copy(field_dst, field_src);
+        } else if (opt_is_pod(o->type)) {
+            size_t size = opt_elem_size[o->type];
+            memcpy(field_dst, field_src, size);
         } else {
-            int size = opt_size(o->type);
-            if (size < 0)
-                ret = size;
-            else
-                memcpy(field_dst, field_src, size);
+            av_log(dst, AV_LOG_ERROR, "Unhandled option type: %d\n",
+                   o->type);
+            ret = AVERROR(EINVAL);
         }
     }
     return ret;
-- 
2.43.0

_______________________________________________
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".

  parent reply	other threads:[~2024-03-04 13:07 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 13:06 [FFmpeg-devel] [PATCH 01/29] lavu/opt: factor per-type dispatch out of av_opt_get() Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 02/29] lavu/opt: factor per-type dispatch out of av_opt_set() Anton Khirnov
2024-03-04 13:06 ` Anton Khirnov [this message]
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 04/29] lavu/opt: factor per-type dispatch out of av_opt_copy() Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 05/29] lavu/opt: distinguish between native and foreign access for AVOption fields Anton Khirnov
2024-03-04 22:39   ` Marton Balint
2024-03-05  9:48     ` Anton Khirnov
2024-03-05 10:17     ` Diederick C. Niehorster
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 06/29] lavu/opt: add array options Anton Khirnov
2024-03-04 13:29   ` Andreas Rheinhardt
2024-03-04 21:00     ` Anton Khirnov
2024-03-05  8:52       ` Andreas Rheinhardt
2024-03-07 14:50     ` Andreas Rheinhardt
2024-03-07 15:24       ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-03-04 21:32   ` [FFmpeg-devel] [PATCH " Marton Balint
2024-03-05  9:50     ` Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 07/29] lavc: add a decoder option for configuring side data preference Anton Khirnov
2024-03-04 14:05   ` Derek Buitenhuis
2024-03-05  9:57     ` Anton Khirnov
2024-03-05 12:30   ` James Almer
2024-03-05 14:29     ` Anton Khirnov
2024-03-05 14:35       ` James Almer
2024-03-05 14:54         ` Anton Khirnov
2024-03-05 15:07           ` James Almer
2024-03-05 15:19             ` Anton Khirnov
2024-03-06 13:58   ` [FFmpeg-devel] [PATCH v2 " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 08/29] avcodec: add internal side data wrappers Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 09/29] lavc: add content light/mastering display " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 10/29] avcodec/av1dec: respect side data preference Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 11/29] avcodec/cri: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 12/29] avcodec/h264_slice: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 13/29] lavc/hevcdec: pass an actual codec context to ff_h2645_sei_to_frame() Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 14/29] avcodec/hevcdec: respect side data preference Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 15/29] avcodec/libjxldec: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 16/29] avcodec/mjpegdec: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 17/29] avcodec/mpeg12dec: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 18/29] avcodec/pngdec: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 19/29] avcodec/tiff: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 20/29] avcodec/webp: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 21/29] avcodec/libdav1d: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 22/29] avcodec/dpx: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 23/29] avcodec/mpeg12dec: use ff_frame_new_side_data Anton Khirnov
2024-03-04 13:36   ` Andreas Rheinhardt
2024-03-05 10:00     ` Anton Khirnov
2024-03-07 11:19       ` Andreas Rheinhardt
2024-03-07 12:18         ` Anton Khirnov
2024-03-07 12:25           ` James Almer
2024-03-07 12:37             ` Anton Khirnov
2024-03-07 20:05       ` Niklas Haas
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 24/29] avcodec/h2645_sei: use ff_frame_new_side_data_from_buf Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 25/29] avcodec/snowdec: use ff_frame_new_side_data Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 26/29] avcodec/mjpegdec: " Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 27/29] avcodec/hevcdec: switch to ff_frame_new_side_data_from_buf Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 28/29] lavc/*dec: use side data preference for mastering display/content light metadata Anton Khirnov
2024-03-04 13:06 ` [FFmpeg-devel] [PATCH 29/29] tests/fate/matroska: add tests for side data preference Anton Khirnov
2024-03-07 23:42   ` Andreas Rheinhardt
2024-03-07  9:30 ` [FFmpeg-devel] [PATCH 01/29] lavu/opt: factor per-type dispatch out of av_opt_get() 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=20240304130657.30631-3-anton@khirnov.net \
    --to=anton@khirnov.net \
    --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