On 06/03/17 08:13, wm4 wrote:
> On Sat, 4 Mar 2017 23:57:29 +0000
> Mark Thompson <[email protected]> wrote:
>
>> 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.
>> ---
>> libavutil/hwcontext.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>> libavutil/hwcontext.h | 28 ++++++++++++++++++++++++++++
>> 2 files changed, 74 insertions(+)
>>
>> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
>> index 252dd32e3..8195a7245 100644
>> --- a/libavutil/hwcontext.c
>> +++ b/libavutil/hwcontext.c
>> @@ -47,6 +47,52 @@ static const HWContextType * const hw_table[] = {
>> NULL,
>> };
>>
>> +static const struct {
>> + enum AVHWDeviceType type;
>> + const char *name;
>> +} hw_type_map[] = {
>> + { 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" },
>> +};
>
> Could use direct indexing of the device type to make it slightly
> simpler? Like:
>
> static const struct {
> const char *name;
> } hw_type_map[] = {
> [AV_HWDEVICE_TYPE_CUDA] = { "cuda" },
> ...
Sure, will change.
>> +
>> +enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
>> +{
>> + int i;
>> + for (i = 0; i < FF_ARRAY_ELEMS(hw_type_map); i++) {
>> + if (!strcmp(hw_type_map[i].name, name))
>> + return hw_type_map[i].type;
>> + }
>> + return AV_HWDEVICE_TYPE_NONE;
>> +}
>> +
>> +const char *av_hwdevice_get_type_name(enum AVHWDeviceType type)
>> +{
>> + int i;
>> + for (i = 0; i < FF_ARRAY_ELEMS(hw_type_map); i++) {
>> + if (hw_type_map[i].type == type)
>> + return hw_type_map[i].name;
>> + }
>> + 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,
>> diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
>> index 49c7a21c1..cce7cdc7e 100644
>> --- a/libavutil/hwcontext.h
>> +++ b/libavutil/hwcontext.h
>> @@ -30,6 +30,8 @@ enum AVHWDeviceType {
>> AV_HWDEVICE_TYPE_VAAPI,
>> AV_HWDEVICE_TYPE_DXVA2,
>> AV_HWDEVICE_TYPE_QSV,
>> +
>> + AV_HWDEVICE_TYPE_NONE
>
> I wouldn't add a space here... too easy to tempt adding new device
> types before the NONE.
Yeah, apparently far too tempting. I was trying to distinguish it because of
the possibility of moving NONE to be 0 at the major bump, hopefully soon - I'll
add #ifs to do that now and then it will be clearer what is going on.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel