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. (cherry picked from commit b7487f4f3c39b4b202e1ea7bb2de13902f2dee45)

Mark Thompson committed 9 years ago

Commit 0b1794a1 parent b22172f4 files · +76 −2Browse files

Unified · Split

4 files
  1. doc/APIchanges +4 −0
  2. libavutil/hwcontext.c +43 −1
  3. libavutil/hwcontext.h +28 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+4−0
@@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines
1515
1616 API changes, most recent first:
1717
18+2017-06-14 - xxxxxxx - lavu 55.65.100 - hwcontext.h
19+ Add AV_HWDEVICE_TYPE_NONE, av_hwdevice_find_type_by_name(),
20+ av_hwdevice_get_type_name() and av_hwdevice_iterate_types().
21+
1822 2017-06-14 - xxxxxxx - lavu 55.64.100 - hwcontext.h
1923 Add av_hwdevice_ctx_create_derived().
2024
libavutil/hwcontext.c+43−1
@@ -28,7 +28,7 @@ · 27 unmodified lines
2828 #include "pixdesc.h"
2929 #include "pixfmt.h"
3030
31−static const HWContextType *hw_table[] = {
31+static const HWContextType *const hw_table[] = {
3232 #if CONFIG_CUDA
3333 &ff_hwcontext_type_cuda,
3434 #endif
@@ -50,6 +50,48 @@ static const HWContextType *hw_table[] = { · 15 unmodified lines
5050 NULL,
5151 };
5252
53+static const char *const hw_type_names[] = {
54+ [AV_HWDEVICE_TYPE_CUDA] = "cuda",
55+ [AV_HWDEVICE_TYPE_DXVA2] = "dxva2",
56+ [AV_HWDEVICE_TYPE_QSV] = "qsv",
57+ [AV_HWDEVICE_TYPE_VAAPI] = "vaapi",
58+ [AV_HWDEVICE_TYPE_VDPAU] = "vdpau",
59+ [AV_HWDEVICE_TYPE_VIDEOTOOLBOX] = "videotoolbox",
60+};
61+
62+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
63+{
64+ int type;
65+ for (type = 0; type < FF_ARRAY_ELEMS(hw_type_names); type++) {
66+ if (hw_type_names[type] && !strcmp(hw_type_names[type], name))
67+ return type;
68+ }
69+ return AV_HWDEVICE_TYPE_NONE;
70+}
71+
72+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)
73+{
74+ if (type >= 0 && type < FF_ARRAY_ELEMS(hw_type_names))
75+ return hw_type_names[type];
76+ else
77+ return NULL;
78+}
79+
80+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
81+{
82+ enum AVHWDeviceType next;
83+ int i, set = 0;
84+ for (i = 0; hw_table[i]; i++) {
85+ if (prev != AV_HWDEVICE_TYPE_NONE && hw_table[i]->type <= prev)
86+ continue;
87+ if (!set || hw_table[i]->type < next) {
88+ next = hw_table[i]->type;
89+ set = 1;
90+ }
91+ }
92+ return set ? next : AV_HWDEVICE_TYPE_NONE;
93+}
94+
5395 static const AVClass hwdevice_ctx_class = {
5496 .class_name = "AVHWDeviceContext",
5597 .item_name = av_default_item_name,
libavutil/hwcontext.h+28−0
@@ -31,6 +31,7 @@ enum AVHWDeviceType { · 30 unmodified lines
3131 AV_HWDEVICE_TYPE_DXVA2,
3232 AV_HWDEVICE_TYPE_QSV,
3333 AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
34+ AV_HWDEVICE_TYPE_NONE,
3435 };
3536
3637 typedef struct AVHWDeviceInternal AVHWDeviceInternal;
@@ -223,6 +224,33 @@ typedef struct AVHWFramesContext { · 186 unmodified lines
223224 int width, height;
224225 } AVHWFramesContext;
225226
227+/**
228+ * Look up an AVHWDeviceType by name.
229+ *
230+ * @param name String name of the device type (case-insensitive).
231+ * @return The type from enum AVHWDeviceType, or AV_HWDEVICE_TYPE_NONE if
232+ * not found.
233+ */
234+enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
235+
236+/** Get the string name of an AVHWDeviceType.
237+ *
238+ * @param type Type from enum AVHWDeviceType.
239+ * @return Pointer to a static string containing the name, or NULL if the type
240+ * is not valid.
241+ */
242+const char *av_hwdevice_get_type_name(enum AVHWDeviceType type);
243+
244+/**
245+ * Iterate over supported device types.
246+ *
247+ * @param type AV_HWDEVICE_TYPE_NONE initially, then the previous type
248+ * returned by this function in subsequent iterations.
249+ * @return The next usable device type from enum AVHWDeviceType, or
250+ * AV_HWDEVICE_TYPE_NONE if there are no more.
251+ */
252+enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
253+
226254 /**
227255 * Allocate an AVHWDeviceContext for a given hardware type.
228256 *
libavutil/version.h+1−1
@@ -80,7 +80,7 @@ · 79 unmodified lines
8080
8181
8282 #define LIBAVUTIL_VERSION_MAJOR 55
83−#define LIBAVUTIL_VERSION_MINOR 64
83+#define LIBAVUTIL_VERSION_MINOR 65
8484 #define LIBAVUTIL_VERSION_MICRO 100
8585
8686 #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