Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/29] lavu/opt: factor per-type dispatch out of av_opt_get()
@ 2024-03-04 13:06 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
                   ` (28 more replies)
  0 siblings, 29 replies; 57+ messages in thread
From: Anton Khirnov @ 2024-03-04 13:06 UTC (permalink / raw)
  To: ffmpeg-devel

Will be useful in following commits.
---
 libavutil/opt.c | 220 ++++++++++++++++++++++++++----------------------
 1 file changed, 121 insertions(+), 99 deletions(-)

diff --git a/libavutil/opt.c b/libavutil/opt.c
index d68184c2cc..dac00478ee 100644
--- a/libavutil/opt.c
+++ b/libavutil/opt.c
@@ -844,13 +844,123 @@ static void format_duration(char *buf, size_t size, int64_t d)
         *(--e) = 0;
 }
 
+static int opt_get_elem(const AVOption *o, uint8_t **pbuf, size_t buf_len,
+                        void *dst, int search_flags)
+{
+    int ret;
+
+    switch (o->type) {
+    case AV_OPT_TYPE_BOOL:
+        ret = snprintf(*pbuf, buf_len, "%s", get_bool_name(*(int *)dst));
+        break;
+    case AV_OPT_TYPE_FLAGS:
+        ret = snprintf(*pbuf, buf_len, "0x%08X", *(int *)dst);
+        break;
+    case AV_OPT_TYPE_INT:
+        ret = snprintf(*pbuf, buf_len, "%d", *(int *)dst);
+        break;
+    case AV_OPT_TYPE_INT64:
+        ret = snprintf(*pbuf, buf_len, "%"PRId64, *(int64_t *)dst);
+        break;
+    case AV_OPT_TYPE_UINT64:
+        ret = snprintf(*pbuf, buf_len, "%"PRIu64, *(uint64_t *)dst);
+        break;
+    case AV_OPT_TYPE_FLOAT:
+        ret = snprintf(*pbuf, buf_len, "%f", *(float *)dst);
+        break;
+    case AV_OPT_TYPE_DOUBLE:
+        ret = snprintf(*pbuf, buf_len, "%f", *(double *)dst);
+        break;
+    case AV_OPT_TYPE_VIDEO_RATE:
+    case AV_OPT_TYPE_RATIONAL:
+        ret = snprintf(*pbuf, buf_len, "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
+        break;
+    case AV_OPT_TYPE_CONST:
+        ret = snprintf(*pbuf, buf_len, "%"PRId64, o->default_val.i64);
+        break;
+    case AV_OPT_TYPE_STRING:
+        if (*(uint8_t **)dst) {
+            *pbuf = av_strdup(*(uint8_t **)dst);
+        } else if (search_flags & AV_OPT_ALLOW_NULL) {
+            *pbuf = NULL;
+            return 0;
+        } else {
+            *pbuf = av_strdup("");
+        }
+        return *pbuf ? 0 : AVERROR(ENOMEM);
+    case AV_OPT_TYPE_BINARY: {
+        const uint8_t *bin;
+        int len;
+
+        if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
+            *pbuf = NULL;
+            return 0;
+        }
+        len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
+        if ((uint64_t)len * 2 + 1 > INT_MAX)
+            return AVERROR(EINVAL);
+        if (!(*pbuf = av_malloc(len * 2 + 1)))
+            return AVERROR(ENOMEM);
+        if (!len) {
+            *pbuf[0] = '\0';
+            return 0;
+        }
+        bin = *(uint8_t **)dst;
+        for (int i = 0; i < len; i++)
+            snprintf(*pbuf + i * 2, 3, "%02X", bin[i]);
+        return 0;
+    }
+    case AV_OPT_TYPE_IMAGE_SIZE:
+        ret = snprintf(*pbuf, buf_len, "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
+        break;
+    case AV_OPT_TYPE_PIXEL_FMT:
+        ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
+        break;
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        ret = snprintf(*pbuf, buf_len, "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
+        break;
+    case AV_OPT_TYPE_DURATION: {
+        int64_t i64 = *(int64_t *)dst;
+        format_duration(*pbuf, buf_len, i64);
+        ret = strlen(*pbuf); // no overflow possible, checked by an assert
+        break;
+    }
+    case AV_OPT_TYPE_COLOR:
+        ret = snprintf(*pbuf, buf_len, "0x%02x%02x%02x%02x",
+                       (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
+                       (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
+        break;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    case AV_OPT_TYPE_CHANNEL_LAYOUT: {
+        int64_t i64 = *(int64_t *)dst;
+        ret = snprintf(*pbuf, buf_len, "0x%"PRIx64, i64);
+        break;
+    }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    case AV_OPT_TYPE_CHLAYOUT:
+        ret = av_channel_layout_describe(dst, *pbuf, buf_len);
+        break;
+    case AV_OPT_TYPE_DICT:
+        if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
+            *pbuf = NULL;
+            return 0;
+        }
+        return av_dict_get_string(*(AVDictionary **)dst, (char **)pbuf, '=', ':');
+    default:
+        return AVERROR(EINVAL);
+    }
+
+    return ret;
+}
+
 int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
 {
     void *dst, *target_obj;
     const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj);
-    uint8_t *bin, buf[128];
-    int len, i, ret;
-    int64_t i64;
+    uint8_t *out, buf[128];
+    int ret;
 
     if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST))
         return AVERROR_OPTION_NOT_FOUND;
@@ -861,107 +971,19 @@ int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val)
     dst = (uint8_t *)target_obj + o->offset;
 
     buf[0] = 0;
-    switch (o->type) {
-    case AV_OPT_TYPE_BOOL:
-        ret = snprintf(buf, sizeof(buf), "%s", get_bool_name(*(int *)dst));
-        break;
-    case AV_OPT_TYPE_FLAGS:
-        ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);
-        break;
-    case AV_OPT_TYPE_INT:
-        ret = snprintf(buf, sizeof(buf), "%d", *(int *)dst);
-        break;
-    case AV_OPT_TYPE_INT64:
-        ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t *)dst);
-        break;
-    case AV_OPT_TYPE_UINT64:
-        ret = snprintf(buf, sizeof(buf), "%"PRIu64, *(uint64_t *)dst);
-        break;
-    case AV_OPT_TYPE_FLOAT:
-        ret = snprintf(buf, sizeof(buf), "%f", *(float *)dst);
-        break;
-    case AV_OPT_TYPE_DOUBLE:
-        ret = snprintf(buf, sizeof(buf), "%f", *(double *)dst);
-        break;
-    case AV_OPT_TYPE_VIDEO_RATE:
-    case AV_OPT_TYPE_RATIONAL:
-        ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational *)dst)->num, ((AVRational *)dst)->den);
-        break;
-    case AV_OPT_TYPE_CONST:
-        ret = snprintf(buf, sizeof(buf), "%"PRId64, o->default_val.i64);
-        break;
-    case AV_OPT_TYPE_STRING:
-        if (*(uint8_t **)dst) {
-            *out_val = av_strdup(*(uint8_t **)dst);
-        } else if (search_flags & AV_OPT_ALLOW_NULL) {
-            *out_val = NULL;
-            return 0;
-        } else {
-            *out_val = av_strdup("");
-        }
-        return *out_val ? 0 : AVERROR(ENOMEM);
-    case AV_OPT_TYPE_BINARY:
-        if (!*(uint8_t **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
-            *out_val = NULL;
-            return 0;
-        }
-        len = *(int *)(((uint8_t *)dst) + sizeof(uint8_t *));
-        if ((uint64_t)len * 2 + 1 > INT_MAX)
-            return AVERROR(EINVAL);
-        if (!(*out_val = av_malloc(len * 2 + 1)))
-            return AVERROR(ENOMEM);
-        if (!len) {
-            *out_val[0] = '\0';
-            return 0;
-        }
-        bin = *(uint8_t **)dst;
-        for (i = 0; i < len; i++)
-            snprintf(*out_val + i * 2, 3, "%02X", bin[i]);
-        return 0;
-    case AV_OPT_TYPE_IMAGE_SIZE:
-        ret = snprintf(buf, sizeof(buf), "%dx%d", ((int *)dst)[0], ((int *)dst)[1]);
-        break;
-    case AV_OPT_TYPE_PIXEL_FMT:
-        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_pix_fmt_name(*(enum AVPixelFormat *)dst), "none"));
-        break;
-    case AV_OPT_TYPE_SAMPLE_FMT:
-        ret = snprintf(buf, sizeof(buf), "%s", (char *)av_x_if_null(av_get_sample_fmt_name(*(enum AVSampleFormat *)dst), "none"));
-        break;
-    case AV_OPT_TYPE_DURATION:
-        i64 = *(int64_t *)dst;
-        format_duration(buf, sizeof(buf), i64);
-        ret = strlen(buf); // no overflow possible, checked by an assert
-        break;
-    case AV_OPT_TYPE_COLOR:
-        ret = snprintf(buf, sizeof(buf), "0x%02x%02x%02x%02x",
-                       (int)((uint8_t *)dst)[0], (int)((uint8_t *)dst)[1],
-                       (int)((uint8_t *)dst)[2], (int)((uint8_t *)dst)[3]);
-        break;
-#if FF_API_OLD_CHANNEL_LAYOUT
-FF_DISABLE_DEPRECATION_WARNINGS
-    case AV_OPT_TYPE_CHANNEL_LAYOUT:
 
-        i64 = *(int64_t *)dst;
-        ret = snprintf(buf, sizeof(buf), "0x%"PRIx64, i64);
-        break;
-FF_ENABLE_DEPRECATION_WARNINGS
-#endif
-    case AV_OPT_TYPE_CHLAYOUT:
-        ret = av_channel_layout_describe(dst, buf, sizeof(buf));
-        break;
-    case AV_OPT_TYPE_DICT:
-        if (!*(AVDictionary **)dst && (search_flags & AV_OPT_ALLOW_NULL)) {
-            *out_val = NULL;
-            return 0;
-        }
-        return av_dict_get_string(*(AVDictionary **)dst, (char **)out_val, '=', ':');
-    default:
-        return AVERROR(EINVAL);
+    out = buf;
+    ret = opt_get_elem(o, &out, sizeof(buf), dst, search_flags);
+    if (ret < 0)
+        return ret;
+    if (out != buf) {
+        *out_val = out;
+        return 0;
     }
 
     if (ret >= sizeof(buf))
         return AVERROR(EINVAL);
-    *out_val = av_strdup(buf);
+    *out_val = av_strdup(out);
     return *out_val ? 0 : AVERROR(ENOMEM);
 }
 
-- 
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".

^ permalink raw reply	[flat|nested] 57+ messages in thread

end of thread, other threads:[~2024-03-07 23:42 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [FFmpeg-devel] [PATCH 03/29] libavutil/opt: rework figuring out option sizes Anton Khirnov
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

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