@@ -58,4 +58,35 @@ typedef struct AVDeviceCapabilitiesQuery {
*/
extern const AVOption ff_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
@@ -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 AVDeviceCapabilitiesQueryType 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
@@ -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, \
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(-)