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.
Unified · Split
| @@ -13,6 +13,10 @@ libavutil: 2015-08-28 · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | API changes, most recent first: | 14 | API changes, most recent first: |
| 15 | 15 | ||
| 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 | |||
| 16 | 2017-03-xx - xxxxxxx - lavu 55.34.0 - hwcontext.h | 20 | 2017-03-xx - xxxxxxx - lavu 55.34.0 - hwcontext.h |
| 17 | Add av_hwdevice_ctx_create_derived(). | 21 | Add av_hwdevice_ctx_create_derived(). |
| 18 | 22 | ||
| @@ -47,6 +47,47 @@ static const HWContextType * const hw_table[] = { · 46 unmodified lines | |||
| 47 | NULL, | 47 | NULL, |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 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 | |||
| 50 | static const AVClass hwdevice_ctx_class = { | 91 | static const AVClass hwdevice_ctx_class = { |
| 51 | .class_name = "AVHWDeviceContext", | 92 | .class_name = "AVHWDeviceContext", |
| 52 | .item_name = av_default_item_name, | 93 | .item_name = av_default_item_name, |
| @@ -30,6 +30,7 @@ enum AVHWDeviceType { · 29 unmodified lines | |||
| 30 | AV_HWDEVICE_TYPE_VAAPI, | 30 | AV_HWDEVICE_TYPE_VAAPI, |
| 31 | AV_HWDEVICE_TYPE_DXVA2, | 31 | AV_HWDEVICE_TYPE_DXVA2, |
| 32 | AV_HWDEVICE_TYPE_QSV, | 32 | AV_HWDEVICE_TYPE_QSV, |
| 33 | AV_HWDEVICE_TYPE_NONE, | ||
| 33 | }; | 34 | }; |
| 34 | 35 | ||
| 35 | typedef struct AVHWDeviceInternal AVHWDeviceInternal; | 36 | typedef struct AVHWDeviceInternal AVHWDeviceInternal; |
| @@ -222,6 +223,33 @@ typedef struct AVHWFramesContext { · 186 unmodified lines | |||
| 222 | int width, height; | 223 | int width, height; |
| 223 | } AVHWFramesContext; | 224 | } AVHWFramesContext; |
| 224 | 225 | ||
| 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 | |||
| 225 | /** | 253 | /** |
| 226 | * Allocate an AVHWDeviceContext for a given pixel format. | 254 | * Allocate an AVHWDeviceContext for a given pixel format. |
| 227 | * | 255 | * |
| @@ -54,7 +54,7 @@ · 53 unmodified lines | |||
| 54 | */ | 54 | */ |
| 55 | 55 | ||
| 56 | #define LIBAVUTIL_VERSION_MAJOR 55 | 56 | #define LIBAVUTIL_VERSION_MAJOR 55 |
| 57 | #define LIBAVUTIL_VERSION_MINOR 34 | 57 | #define LIBAVUTIL_VERSION_MINOR 35 |
| 58 | #define LIBAVUTIL_VERSION_MICRO 0 | 58 | #define LIBAVUTIL_VERSION_MICRO 0 |
| 59 | 59 | ||
| 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | 60 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |