Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Thompson <sw@jkqxz.net>2017-03-05 02:57:29 +0300
committerMark Thompson <sw@jkqxz.net>2017-03-21 02:15:43 +0300
commitb7487f4f3c39b4b202e1ea7bb2de13902f2dee45 (patch)
tree1acb24ecaa19ce105040f71db8ddc87a379b5e8a /libavutil/hwcontext.c
parentb266ad56fe0e4ce5bb70118ba2e2b1dabfaf76ce (diff)
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.
Diffstat (limited to 'libavutil/hwcontext.c')
-rw-r--r--libavutil/hwcontext.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 252dd32e38..2c6d51ee55 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -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,