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.

Why is it case-insensitive?

>  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.

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.

>   * 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

Reply via email to