On 20/02/17 05:42, wm4 wrote:
> On Sun, 19 Feb 2017 18:46:24 +0000
> Mark Thompson <[email protected]> wrote:
>
>> ---
>> libavutil/hwcontext.c | 11 +++++++++++
>> libavutil/hwcontext.h | 8 ++++++++
>> 2 files changed, 19 insertions(+)
>>
>> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
>> index 1f9442622..e3484c78c 100644
>> --- a/libavutil/hwcontext.c
>> +++ b/libavutil/hwcontext.c
>> @@ -18,6 +18,7 @@
>>
>> #include "config.h"
>>
>> +#include "avstring.h"
>> #include "buffer.h"
>> #include "common.h"
>> #include "hwcontext.h"
>> @@ -47,6 +48,16 @@ static const HWContextType * const hw_table[] = {
>> NULL,
>> };
>>
>> +enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
>> +{
>> + int i;
>> + for (i = 0; hw_table[i]; i++) {
>> + if (!av_strcasecmp(hw_table[i]->name, name))
>> + return hw_table[i]->type;
>> + }
>> + return -1;
>> +}
>> +
>
> You could argue that this shouldn't depend on whether the
> implementation is compiled-in.
You could - would you like to so argue?
I don't mind, it was easier to do this way because the list would have to be
duplicated. (The difference in current code is between hwmap saying "Invalid
device type" and "Failed to created derived device context".)
> Why is it case-insensitive?
Again don't mind. Current strings are upper-case, but I wanted to use
lower-case in avconv. I guess the user can do tolower() or whatever anyway.
Feel free make an arbitrary choice and I'll do it.
>> 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 a31799267..98f9172ee 100644
>> --- a/libavutil/hwcontext.h
>> +++ b/libavutil/hwcontext.h
>> @@ -223,6 +223,14 @@ typedef struct AVHWFramesContext {
>> } AVHWFramesContext;
>>
>> /**
>> + * Look up an AVHWDeviceType by name.
>> + *
>> + * @param name String name of the device type (case-insensitive).
>> + * @return The type from enum AVHWDeviceType, or -1 on failure.
>> + */
>> +enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name);
>> +
>> +/**
>
> There should also be a way to turn a AVHWDeviceType into a string.
Sure.
> I agree that the -1 should be part of the enum. We should probably fix
> the enum in the next ABI bump to start with an NONE entry with the
> value 0.
>
> Actually, I'd just make it for now:
>
> enum AVHWDeviceType {
> AV_HWDEVICE_TYPE_VDPAU,
> AV_HWDEVICE_TYPE_CUDA,
> AV_HWDEVICE_TYPE_VAAPI,
> AV_HWDEVICE_TYPE_DXVA2,
> AV_HWDEVICE_TYPE_QSV,
> AV_HWDEVICE_TYPE_NONE,
> };
>
> A bit dumb, but can be fixed in the next ABI bump by moving it up.
Yeah, that's probably the best option.
>> * Allocate an AVHWDeviceContext for a given pixel format.
>> *
>> * @return a reference to the newly created AVHWDeviceContext on success or
>> NULL
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel