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)
Unified · Split
| @@ -15,6 +15,10 @@ libavutil: 2015-08-28 · 14 unmodified lines | |||
| 15 | 15 | ||
| 16 | API changes, most recent first: | 16 | API changes, most recent first: |
| 17 | 17 | ||
| 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 | |||
| 18 | 2017-06-14 - xxxxxxx - lavu 55.64.100 - hwcontext.h | 22 | 2017-06-14 - xxxxxxx - lavu 55.64.100 - hwcontext.h |
| 19 | Add av_hwdevice_ctx_create_derived(). | 23 | Add av_hwdevice_ctx_create_derived(). |
| 20 | 24 | ||
| @@ -28,7 +28,7 @@ · 27 unmodified lines | |||
| 28 | #include "pixdesc.h" | 28 | #include "pixdesc.h" |
| 29 | #include "pixfmt.h" | 29 | #include "pixfmt.h" |
| 30 | 30 | ||
| 31 | static const HWContextType *hw_table[] = { | 31 | static const HWContextType *const hw_table[] = { |
| 32 | #if CONFIG_CUDA | 32 | #if CONFIG_CUDA |
| 33 | &ff_hwcontext_type_cuda, | 33 | &ff_hwcontext_type_cuda, |
| 34 | #endif | 34 | #endif |
| @@ -50,6 +50,48 @@ static const HWContextType *hw_table[] = { · 15 unmodified lines | |||
| 50 | NULL, | 50 | NULL, |
| 51 | }; | 51 | }; |
| 52 | 52 | ||
| 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 | |||
| 53 | static const AVClass hwdevice_ctx_class = { | 95 | static const AVClass hwdevice_ctx_class = { |
| 54 | .class_name = "AVHWDeviceContext", | 96 | .class_name = "AVHWDeviceContext", |
| 55 | .item_name = av_default_item_name, | 97 | .item_name = av_default_item_name, |
| @@ -31,6 +31,7 @@ enum AVHWDeviceType { · 30 unmodified lines | |||
| 31 | AV_HWDEVICE_TYPE_DXVA2, | 31 | AV_HWDEVICE_TYPE_DXVA2, |
| 32 | AV_HWDEVICE_TYPE_QSV, | 32 | AV_HWDEVICE_TYPE_QSV, |
| 33 | AV_HWDEVICE_TYPE_VIDEOTOOLBOX, | 33 | AV_HWDEVICE_TYPE_VIDEOTOOLBOX, |
| 34 | AV_HWDEVICE_TYPE_NONE, | ||
| 34 | }; | 35 | }; |
| 35 | 36 | ||
| 36 | typedef struct AVHWDeviceInternal AVHWDeviceInternal; | 37 | typedef struct AVHWDeviceInternal AVHWDeviceInternal; |
| @@ -223,6 +224,33 @@ typedef struct AVHWFramesContext { · 186 unmodified lines | |||
| 223 | int width, height; | 224 | int width, height; |
| 224 | } AVHWFramesContext; | 225 | } AVHWFramesContext; |
| 225 | 226 | ||
| 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 | |||
| 226 | /** | 254 | /** |
| 227 | * Allocate an AVHWDeviceContext for a given hardware type. | 255 | * Allocate an AVHWDeviceContext for a given hardware type. |
| 228 | * | 256 | * |
| @@ -80,7 +80,7 @@ · 79 unmodified lines | |||
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | #define LIBAVUTIL_VERSION_MAJOR 55 | 82 | #define LIBAVUTIL_VERSION_MAJOR 55 |
| 83 | #define LIBAVUTIL_VERSION_MINOR 64 | 83 | #define LIBAVUTIL_VERSION_MINOR 65 |
| 84 | #define LIBAVUTIL_VERSION_MICRO 100 | 84 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 85 | 85 | ||
| 86 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 86 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |