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
15 15
16API changes, most recent first:16API changes, most recent first:
17 17
182017-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
182017-06-14 - xxxxxxx - lavu 55.64.100 - hwcontext.h222017-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
libavutil/hwcontext.c+43−1
@@ -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
31static const HWContextType *hw_table[] = {31static const HWContextType *const hw_table[] = {
32#if CONFIG_CUDA32#if CONFIG_CUDA
33 &ff_hwcontext_type_cuda,33 &ff_hwcontext_type_cuda,
34#endif34#endif
@@ -50,6 +50,48 @@ static const HWContextType *hw_table[] = { · 15 unmodified lines
50 NULL,50 NULL,
51};51};
52 52
53static 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
62enum 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
72const 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
80enum 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
53static const AVClass hwdevice_ctx_class = {95static 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,
libavutil/hwcontext.h+28−0
@@ -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
36typedef struct AVHWDeviceInternal AVHWDeviceInternal;37typedef 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 */
234enum 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 */
242const 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 */
252enum 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 *
libavutil/version.h+1−1
@@ -80,7 +80,7 @@ · 79 unmodified lines
80 80
81 81
82#define LIBAVUTIL_VERSION_MAJOR 5582#define LIBAVUTIL_VERSION_MAJOR 55
83#define LIBAVUTIL_VERSION_MINOR 6483#define LIBAVUTIL_VERSION_MINOR 65
84#define LIBAVUTIL_VERSION_MICRO 10084#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, \

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