]> git.sesse.net Git - ffmpeg/commitdiff
hwcontext: Make it easier to work with device types
authorMark Thompson <sw@jkqxz.net>
Sat, 4 Mar 2017 23:57:29 +0000 (23:57 +0000)
committerMark Thompson <sw@jkqxz.net>
Mon, 20 Mar 2017 23:15:43 +0000 (23:15 +0000)
Adds functions to convert to/from strings and a function to iterate
over all supported device types.  Also adds a new invalid type
AV_HWDEVICE_TYPE_NONE, which acts as a sentinel value.

doc/APIchanges
libavutil/hwcontext.c
libavutil/hwcontext.h
libavutil/version.h

index 335c1634793e1dcc16fd103d99a9056c7146dbc1..70b3391988eb20ae6bbc4fe6fc55b0254f86302b 100644 (file)
@@ -13,6 +13,10 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2017-03-xx - xxxxxxx - lavu 55.35.0 - hwcontext.h
+  Add AV_HWDEVICE_TYPE_NONE, av_hwdevice_find_type_by_name(),
+  av_hwdevice_get_type_name() and av_hwdevice_iterate_types().
+
 2017-03-xx - xxxxxxx - lavu 55.34.0 - hwcontext.h
   Add av_hwdevice_ctx_create_derived().
 
index 252dd32e38355069a3043cbc5aee0d32e00b8522..2c6d51ee55df7e7686d03f59f6e89590103ba165 100644 (file)
@@ -47,6 +47,47 @@ static const HWContextType * const hw_table[] = {
     NULL,
 };
 
+const char *hw_type_names[] = {
+    [AV_HWDEVICE_TYPE_CUDA]   = "cuda",
+    [AV_HWDEVICE_TYPE_DXVA2]  = "dxva2",
+    [AV_HWDEVICE_TYPE_QSV]    = "qsv",
+    [AV_HWDEVICE_TYPE_VAAPI]  = "vaapi",
+    [AV_HWDEVICE_TYPE_VDPAU]  = "vdpau",
+};
+
+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
+{
+    int type;
+    for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
+        if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
+            return type;
+    }
+    return AV_HWDEVICE_TYPE_NONE;
+}
+
+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)
+{
+    if (type >= 0 && type < FF_ARRAY_ELEMS(hw_type_names))
+        return hw_type_names[type];
+    else
+        return NULL;
+}
+
+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
+{
+    enum AVHWDeviceType next;
+    int i, set = 0;
+    for (i = 0; hw_table[i]; i++) {
+        if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
+            continue;
+        if (!set || hw_table[i]->type < next) {
+            next = hw_table[i]->type;
+            set = 1;
+        }
+    }
+    return set ? next : AV_HWDEVICE_TYPE_NONE;
+}
+
 static const AVClass hwdevice_ctx_class = {
     .class_name = "AVHWDeviceContext",
     .item_name  = av_default_item_name,
index 49c7a21c1e748a0890a639316b9a6d0fb2fac06a..040e010b308653aa9e952a6de094a36dbbce20e1 100644 (file)
@@ -30,6 +30,7 @@ enum AVHWDeviceType {
     AV_HWDEVICE_TYPE_VAAPI,
     AV_HWDEVICE_TYPE_DXVA2,
     AV_HWDEVICE_TYPE_QSV,
+    AV_HWDEVICE_TYPE_NONE,
 };
 
 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
@@ -222,6 +223,33 @@ typedef struct AVHWFramesContext {
     int width, height;
 } AVHWFramesContext;
 
+/**
+ * Look up an AVHWDeviceType by name.
+ *
+ * @param name String name of the device type (case-insensitive).
+ * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
+ *         not found.
+ */
+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
+
+/** Get the string name of an AVHWDeviceType.
+ *
+ * @param type Type from enum AVHWDeviceType.
+ * @return Pointer to a static string containing the name, or NULL if the type
+ *         is not valid.
+ */
+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
+
+/**
+ * Iterate over supported device types.
+ *
+ * @param type AV_HWDEVICE_TYPE_NONE initially, then the previous type
+ *             returned by this function in subsequent iterations.
+ * @return The next usable device type from enum AVHWDeviceType, or
+ *         AV_HWDEVICE_TYPE_NONE if there are no more.
+ */
+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
+
 /**
  * Allocate an AVHWDeviceContext for a given pixel format.
  *
index 7c0e852498cb22c6e920d7bf1ac19beeb495dadc..f952cc48dd250d16678b0002f13cf87c7eae301d 100644 (file)
@@ -54,7 +54,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 55
-#define LIBAVUTIL_VERSION_MINOR 34
+#define LIBAVUTIL_VERSION_MINOR 35
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \