Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Diederick Niehorster <dcnieho@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Diederick Niehorster <dcnieho@gmail.com>
Subject: [FFmpeg-devel] [PATCH v5 13/21] avdevice: improve capabilities' option API
Date: Wed, 30 Mar 2022 14:17:58 +0200
Message-ID: <20220330121806.822-14-dcnieho@gmail.com> (raw)
In-Reply-To: <20220330121806.822-1-dcnieho@gmail.com>

This adds avdevice_capabilities_get_class() to allow examining the
capabilities that can be queried/set through the capabilities API, and
avdevice_capabilities_bprint_num() which allows printing the value
returned when querying a capability. These values (min_value and
max_value of an AVOptionRange) are doubles and this function formats
them properly, e.g. 1. for a AV_OPT_TYPE_PIXEL_FMT -> yuyv422.

bump minor version.

Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
---
 libavdevice/avdevice.c | 80 ++++++++++++++++++++++++++++++++++++++++++
 libavdevice/avdevice.h | 27 ++++++++++++++
 libavdevice/version.h  |  4 +--
 3 files changed, 109 insertions(+), 2 deletions(-)

diff --git a/libavdevice/avdevice.c b/libavdevice/avdevice.c
index 863f8df477..e2c60618d3 100644
--- a/libavdevice/avdevice.c
+++ b/libavdevice/avdevice.c
@@ -19,6 +19,9 @@
 #include "libavutil/avassert.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/avutil.h"
+#include "libavcodec/codec_id.h"
 #include "libavformat/version.h"
 #include "avdevice.h"
 #include "internal.h"
@@ -141,6 +144,83 @@ int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatConte
     return ret;
 }
 
+static const AVClass avdevice_capabilities_context_class = {
+    .class_name = "AVDeviceCapabilitiesQuery",
+    .item_name = av_default_item_name,
+    .option = ff_device_capabilities,
+    .version = LIBAVUTIL_VERSION_INT
+};
+
+const AVClass *avdevice_capabilities_get_class(void)
+{
+    return &avdevice_capabilities_context_class;
+}
+
+int avdevice_capabilities_bprint_num(AVBPrint *bp, const char *name, double val)
+{
+    int opt_type_set = 0, is_codec = 0;
+    enum AVOptionType type;  // will be set below, opt_type_set tracks if has been set
+    const AVClass *cap_class = avdevice_capabilities_get_class();
+
+    // may fail, e.g. if name of a component of a multi-component option was provided as input
+    const AVOption *field = av_opt_find(&cap_class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ);
+    if (field) {
+        type = field->type;
+        opt_type_set = 1;
+    }
+
+    // based on name, a type override or other extra info may be needed
+    if (opt_type_set && type==AV_OPT_TYPE_INT && strcmp(name, "codec")==0)
+        is_codec = 1;
+    // next three are for the three components of a AV_OPT_TYPE_IMAGE_SIZE
+    // NB: these wont be found by av_opt_find above
+    else if (
+        strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 0))==0 ||
+        strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 1))==0 ||
+        strcmp(name, ff_device_get_query_component_name(AV_DEV_CAP_QUERY_WINDOW_SIZE, 2))==0
+        ) {
+        type = AV_OPT_TYPE_INT;
+        opt_type_set = 1;
+    }
+
+    // now, format if type set, else error
+    if (!opt_type_set) {
+        av_log(NULL, AV_LOG_ERROR, "A device capability with the name '%s' is not known\n", name);
+        return AVERROR_OPTION_NOT_FOUND;
+    }
+
+    switch (type)
+    {
+    case AV_OPT_TYPE_INT:
+    {
+        int temp = lrint(val);
+        if (is_codec)
+            av_bprintf(bp, "%s", (char *)avcodec_get_name((enum AVCodecID)lrint(val)));
+        else
+            av_bprintf(bp, "%d", temp);
+        break;
+    }
+    case AV_OPT_TYPE_PIXEL_FMT:
+        av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_pix_fmt_name((enum AVPixelFormat)lrint(val)), "none"));
+        break;
+    case AV_OPT_TYPE_SAMPLE_FMT:
+        av_bprintf(bp, "%s", (char *)av_x_if_null(av_get_sample_fmt_name((enum AVSampleFormat)lrint(val)), "none"));
+        break;
+    case AV_OPT_TYPE_DOUBLE:
+        av_bprintf(bp, "%f", val);
+        break;
+    case AV_OPT_TYPE_CHANNEL_LAYOUT:
+        av_bprintf(bp, "0x%"PRIx64, llrint(val));
+        break;
+
+    default:
+        av_log(NULL, AV_LOG_ERROR, "avdevice_capabilities_bprint_num is not implemented for this option type\n", name);
+        return AVERROR_PATCHWELCOME;
+    }
+
+    return 0;
+}
+
 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
 {
     if (!s || !caps || !(*caps))
diff --git a/libavdevice/avdevice.h b/libavdevice/avdevice.h
index a815d65f12..5f9dfccc34 100644
--- a/libavdevice/avdevice.h
+++ b/libavdevice/avdevice.h
@@ -64,6 +64,7 @@
 #include "libavutil/log.h"
 #include "libavutil/opt.h"
 #include "libavutil/dict.h"
+#include "libavutil/bprint.h"
 #include "libavformat/avformat.h"
 
 /**
@@ -418,6 +419,16 @@ int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
  */
 typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery;
 
+/**
+ * Get the AVClass for AVDeviceCapabilitiesQuery. It can be used
+ * in combination with AV_OPT_SEARCH_FAKE_OBJ for examining
+ * which capabilities can be queried through the
+ * AVDeviceCapabilitiesQuery API.
+ *
+ * @see av_opt_find(), av_opt_next().
+ */
+const AVClass *avdevice_capabilities_get_class(void);
+
 /**
  * Initialize capabilities probing API based on AVOption API.
  *
@@ -438,6 +449,22 @@ typedef struct AVDeviceCapabilitiesQuery AVDeviceCapabilitiesQuery;
 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
                                  AVDictionary **device_options);
 
+/**
+ * Format a capabilities value as string and append to a bprint buffer.
+ * @param  bp A buffer to which the output string will be
+ *         appended.
+ * @param  name Name of the option to print (provide
+ *         AVOptionRange.str).
+ * @param  val An capabilities value represented as a
+ *         double (e.g. min_value or max_value of
+ *         AVOptionRange)
+ * @return 0 on success, a negative error code otherwise. Even if
+ * return value indicates success, the state of the bp variable
+ * should also be checked, as it may have experienced memory allocation
+ * trouble.
+ */
+int avdevice_capabilities_bprint_num(AVBPrint *bp, const char *name, double val);
+
 /**
  * Free resources created by avdevice_capabilities_create()
  *
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 181987d287..764aceccb5 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -30,8 +30,8 @@
 
 #include "version_major.h"
 
-#define LIBAVDEVICE_VERSION_MINOR   1
-#define LIBAVDEVICE_VERSION_MICRO 101
+#define LIBAVDEVICE_VERSION_MINOR   2
+#define LIBAVDEVICE_VERSION_MICRO 100
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \
-- 
2.28.0.windows.1

_______________________________________________
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:[~2022-03-30 12:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-30 12:17 [FFmpeg-devel] [PATCH v5 00/21] avdevice (mostly dshow) enhancements Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 01/21] avdevice: lock to minor version of avformat Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 02/21] avformat: add control_message function to AVInputFormat Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 03/21] avdevice/dshow: implement control_message interface Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 04/21] avdevice: add control message requesting to show config dialog Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 05/21] avdevice/dshow: accept show config dialog control message Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 06/21] avdevice/dshow: add config dialog command for crossbar and tv tuner Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 07/21] avdevice/avdevice: Revert "Deprecate AVDevice Capabilities API" Diederick Niehorster
2022-05-10 17:24   ` Andreas Rheinhardt
2022-05-10 17:40     ` Hendrik Leppkes
2022-05-12  8:17     ` Diederick C. Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 08/21] avdevice/avdevice: clean up avdevice_capabilities_create Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 09/21] avdevice: capabilities API details no longer public Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 10/21] avutil/opt: document AVOptionRange min_value > max_value Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 11/21] avdevice: Add internal helpers for querying device capabilities Diederick Niehorster
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 12/21] avdevice: change device capabilities option type Diederick Niehorster
2022-03-30 12:17 ` Diederick Niehorster [this message]
2022-03-30 12:17 ` [FFmpeg-devel] [PATCH v5 14/21] avdevice/dshow: move audio format helpers Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 15/21] avdevice/dshow: when closing, set context fields back to zero Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 16/21] avdevice/dshow: implement capabilities API Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 17/21] avdevice/dshow: cosmetics Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 18/21] avformat: add avformat_alloc_input_context() Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 19/21] doc/examples: adding device_get_capabilities example Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 20/21] Makefile/examples: cosmetics Diederick Niehorster
2022-03-30 12:18 ` [FFmpeg-devel] [PATCH v5 21/21] avdevice/dshow: capabilities query also works on opened device Diederick Niehorster
2022-04-25 20:23 ` [FFmpeg-devel] [PATCH v5 00/21] avdevice (mostly dshow) enhancements Diederick C. Niehorster

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=20220330121806.822-14-dcnieho@gmail.com \
    --to=dcnieho@gmail.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