diff mbox series

[FFmpeg-devel,26/35] avdevice: Add internal helpers for querying device capabilities

Message ID 20210607230414.612-27-dcnieho@gmail.com
State Superseded, archived
Headers show
Series avdevice (mostly dshow) enhancements | expand

Checks

Context Check Description
andriy/x86_make fail Make failed
andriy/PPC64_make warning Make failed

Commit Message

Diederick C. Niehorster June 7, 2021, 11:04 p.m. UTC
Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
---
 libavdevice/internal.h | 31 +++++++++++++++++++++++++++
 libavdevice/utils.c    | 48 ++++++++++++++++++++++++++++++++++++++++++
 libavdevice/version.h  |  2 +-
 3 files changed, 80 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer June 8, 2021, 1:30 p.m. UTC | #1
On Tue, Jun 08, 2021 at 01:04:05AM +0200, Diederick Niehorster wrote:
> Signed-off-by: Diederick Niehorster <dcnieho@gmail.com>
> ---
>  libavdevice/internal.h | 31 +++++++++++++++++++++++++++
>  libavdevice/utils.c    | 48 ++++++++++++++++++++++++++++++++++++++++++
>  libavdevice/version.h  |  2 +-
>  3 files changed, 80 insertions(+), 1 deletion(-)

brakes build
CC	libavdevice/utils.o
libavdevice/utils.c:64:29: error: field ‘query_type’ has incomplete type
     enum DshowCapQueryType  query_type;
                             ^~~~~~~~~~
libavdevice/utils.c: In function ‘ff_device_get_query_type’:
libavdevice/utils.c:86:20: error: incompatible types when returning type ‘const AVDeviceCapabilitiesQueryTypeEntry * {aka const struct AVDeviceCapabilitiesQueryTypeEntry *}’ but ‘enum AVDeviceCapabilitiesQueryType’ was expected
             return query_table[i].query_type;
                    ^~~~~~~~~~~
libavdevice/utils.c: In function ‘ff_device_get_query_component_name’:
libavdevice/utils.c:101:43: warning: comparison between pointer and integer
             if (query_table[i].query_type == query_type)
                                           ^~
ffbuild/common.mak:67: recipe for target 'libavdevice/utils.o' failed
make: *** [libavdevice/utils.o] Error 1

[...]
Diederick C. Niehorster June 8, 2021, 6:51 p.m. UTC | #2
On Tue, Jun 8, 2021 at 3:30 PM Michael Niedermayer <michael@niedermayer.cc>
wrote:

> On Tue, Jun 08, 2021 at 01:04:05AM +0200, Diederick Niehorster wrote:
>
> brakes build
> CC      libavdevice/utils.o
> libavdevice/utils.c:64:29: error: field ‘query_type’ has incomplete type
>      enum DshowCapQueryType  query_type;
>                              ^~~~~~~~~~
> libavdevice/utils.c: In function ‘ff_device_get_query_type’:
>

argh! This slipped through and actually built and worked fine with the
msvc-toolchain (implicit int?). That toolchain throws a lot of warnings,
didn't spot this one in the noise. Fixed!
diff mbox series

Patch

diff --git a/libavdevice/internal.h b/libavdevice/internal.h
index fe4be64ee7..10e1cdb80c 100644
--- a/libavdevice/internal.h
+++ b/libavdevice/internal.h
@@ -58,4 +58,35 @@  typedef struct AVDeviceCapabilitiesQuery {
  */
 extern const AVOption av_device_capabilities[];
 
+/**
+ * Enumeration indicating which device capability is being queried.
+ */
+enum AVDeviceCapabilitiesQueryType {
+    AV_DEV_CAP_QUERY_NONE = 0,
+    // both audio and video
+    AV_DEV_CAP_QUERY_CODEC,
+    // audio
+    AV_DEV_CAP_QUERY_SAMPLE_FORMAT,
+    AV_DEV_CAP_QUERY_SAMPLE_RATE,
+    AV_DEV_CAP_QUERY_CHANNELS,
+    AV_DEV_CAP_QUERY_CHANNEL_LAYOUT,
+    // video
+    AV_DEV_CAP_QUERY_PIXEL_FORMAT,
+    AV_DEV_CAP_QUERY_WINDOW_SIZE,
+    AV_DEV_CAP_QUERY_FRAME_SIZE,
+    AV_DEV_CAP_QUERY_FPS
+};
+
+/**
+ * Find AVDeviceCapabilitiesQueryType enumeration by means of options name.
+ * Returns AV_DEV_CAP_QUERY_NONE if not found.
+ */
+enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name);
+
+/**
+ * Get component name from AVDeviceCapabilitiesQueryType enumeration and component index.
+ * (Some options have multiple components, e.g. AV_DEV_CAP_QUERY_FRAME_SIZE).
+ */
+const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component);
+
 #endif
diff --git a/libavdevice/utils.c b/libavdevice/utils.c
index d9a52c53ab..73fdc5766e 100644
--- a/libavdevice/utils.c
+++ b/libavdevice/utils.c
@@ -19,6 +19,7 @@ 
 #include "internal.h"
 #include "libavutil/opt.h"
 #include "libavformat/avformat.h"
+#include "libavutil/avassert.h"
 
 int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat *iformat, const char *format)
 {
@@ -57,3 +58,50 @@  int ff_alloc_input_device_context(AVFormatContext **avctx, const AVInputFormat *
     avformat_free_context(s);
     return ret;
 }
+
+typedef struct AVDeviceCapabilitiesQueryTypeEntry {
+    const char* name;
+    enum DshowCapQueryType  query_type;
+} AVDeviceCapabilitiesQueryTypeEntry;
+
+static const AVDeviceCapabilitiesQueryTypeEntry query_table[] = {
+    // both audio and video
+    { "codec",          AV_DEV_CAP_QUERY_CODEC },
+    // audio
+    { "sample_format",  AV_DEV_CAP_QUERY_SAMPLE_FORMAT },
+    { "sample_rate",    AV_DEV_CAP_QUERY_SAMPLE_RATE },
+    { "channels",       AV_DEV_CAP_QUERY_CHANNELS },
+    { "channel_layout", AV_DEV_CAP_QUERY_CHANNEL_LAYOUT },
+    // video
+    { "pixel_format",   AV_DEV_CAP_QUERY_PIXEL_FORMAT },
+    { "frame_size",     AV_DEV_CAP_QUERY_FRAME_SIZE },
+    { "window_size",    AV_DEV_CAP_QUERY_WINDOW_SIZE },
+    { "fps",            AV_DEV_CAP_QUERY_FPS },
+};
+
+enum AVDeviceCapabilitiesQueryType ff_device_get_query_type(const char* option_name)
+{
+    for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) {
+        if (!strcmp(query_table[i].name, option_name))
+            return query_table[i].query_type;
+    }
+    // not found
+    return AV_DEV_CAP_QUERY_NONE;
+}
+
+const char* ff_device_get_query_component_name(enum AVDeviceCapabilitiesQueryType query_type, int component)
+{
+    if (query_type == AV_DEV_CAP_QUERY_WINDOW_SIZE || query_type == AV_DEV_CAP_QUERY_FRAME_SIZE) {
+        // special case: different name for each component
+        return component == 0 ? "pixel_count" : (component == 1 ? "width" : (component == 2 ? "height" : ""));
+    }
+    else {
+        av_assert0(component == 0);
+        for (int i = 0; i < FF_ARRAY_ELEMS(query_table); ++i) {
+            if (query_table[i].query_type == query_type)
+                return query_table[i].name;
+        }
+    }
+    // not found
+    return NULL;
+}
\ No newline at end of file
diff --git a/libavdevice/version.h b/libavdevice/version.h
index 53af6fa0d0..e0361aebc1 100644
--- a/libavdevice/version.h
+++ b/libavdevice/version.h
@@ -29,7 +29,7 @@ 
 
 #define LIBAVDEVICE_VERSION_MAJOR  59
 #define LIBAVDEVICE_VERSION_MINOR   3
-#define LIBAVDEVICE_VERSION_MICRO 100
+#define LIBAVDEVICE_VERSION_MICRO 101
 
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
                                                LIBAVDEVICE_VERSION_MINOR, \