History

hwcontext: Make it easier to work with device types

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.

Mark Thompson committed 9 years ago

Commit b7487f41 parent b266ad54 files · +74 −1Browse files

Unified · Split

4 files
  1. doc/APIchanges +4 −0
  2. libavutil/hwcontext.c +41 −0
  3. libavutil/hwcontext.h +28 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2015-08-28 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2017-03-xx - xxxxxxx - lavu 55.35.0 - hwcontext.h
17+ Add AV_HWDEVICE_TYPE_NONE, av_hwdevice_find_type_by_name(),
18+ av_hwdevice_get_type_name() and av_hwdevice_iterate_types().
19+
1620 2017-03-xx - xxxxxxx - lavu 55.34.0 - hwcontext.h
1721 Add av_hwdevice_ctx_create_derived().
1822
libavutil/hwcontext.c+41−0
@@ -47,6 +47,47 @@ static const HWContextType * const hw_table[] = { · 46 unmodified lines
4747 NULL,
4848 };
4949
50+const char *hw_type_names[] = {
51+ [AV_HWDEVICE_TYPE_CUDA] = "cuda",
52+ [AV_HWDEVICE_TYPE_DXVA2] = "dxva2",
53+ [AV_HWDEVICE_TYPE_QSV] = "qsv",
54+ [AV_HWDEVICE_TYPE_VAAPI] = "vaapi",
55+ [AV_HWDEVICE_TYPE_VDPAU] = "vdpau",
56+};
57+
58+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
59+{
60+ int type;
61+ for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
62+ if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
63+ return type;
64+ }
65+ return AV_HWDEVICE_TYPE_NONE;
66+}
67+
68+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)
69+{
70+ if (type >= 0 && type < FF_ARRAY_ELEMS(hw_type_names))
71+ return hw_type_names[type];
72+ else
73+ return NULL;
74+}
75+
76+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
77+{
78+ enum AVHWDeviceType next;
79+ int i, set = 0;
80+ for (i = 0; hw_table[i]; i++) {
81+ if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
82+ continue;
83+ if (!set || hw_table[i]->type < next) {
84+ next = hw_table[i]->type;
85+ set = 1;
86+ }
87+ }
88+ return set ? next : AV_HWDEVICE_TYPE_NONE;
89+}
90+
5091 static const AVClass hwdevice_ctx_class = {
5192 .class_name = "AVHWDeviceContext",
5293 .item_name = av_default_item_name,
libavutil/hwcontext.h+28−0
@@ -30,6 +30,7 @@ enum AVHWDeviceType { · 29 unmodified lines
3030 AV_HWDEVICE_TYPE_VAAPI,
3131 AV_HWDEVICE_TYPE_DXVA2,
3232 AV_HWDEVICE_TYPE_QSV,
33+ AV_HWDEVICE_TYPE_NONE,
3334 };
3435
3536 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
@@ -222,6 +223,33 @@ typedef struct AVHWFramesContext { · 186 unmodified lines
222223 int width, height;
223224 } AVHWFramesContext;
224225
226+/**
227+ * Look up an AVHWDeviceType by name.
228+ *
229+ * @param name String name of the device type (case-insensitive).
230+ * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
231+ * not found.
232+ */
233+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
234+
235+/** Get the string name of an AVHWDeviceType.
236+ *
237+ * @param type Type from enum AVHWDeviceType.
238+ * @return Pointer to a static string containing the name, or NULL if the type
239+ * is not valid.
240+ */
241+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
242+
243+/**
244+ * Iterate over supported device types.
245+ *
246+ * @param type AV_HWDEVICE_TYPE_NONE initially, then the previous type
247+ * returned by this function in subsequent iterations.
248+ * @return The next usable device type from enum AVHWDeviceType, or
249+ * AV_HWDEVICE_TYPE_NONE if there are no more.
250+ */
251+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
252+
225253 /**
226254 * Allocate an AVHWDeviceContext for a given pixel format.
227255 *
libavutil/version.h+1−1
@@ -54,7 +54,7 @@ · 53 unmodified lines
5454 */
5555
5656 #define LIBAVUTIL_VERSION_MAJOR 55
57−#define LIBAVUTIL_VERSION_MINOR 34
57+#define LIBAVUTIL_VERSION_MINOR 35
5858 #define LIBAVUTIL_VERSION_MICRO 0
5959
6060 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t