Quoting Mark Thompson (2016-02-20 19:30:14)
> ---
>  libavutil/hwcontext.c          | 38 +++++++++++++++++++++++++++
>  libavutil/hwcontext.h          | 58 
> ++++++++++++++++++++++++++++++++++++++++++
>  libavutil/hwcontext_internal.h | 10 ++++++++
>  3 files changed, 106 insertions(+)
> 
> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
> index b6d0518..b193212 100644
> --- a/libavutil/hwcontext.c
> +++ b/libavutil/hwcontext.c
> @@ -400,3 +400,41 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
> AVFrame *frame, int flags)
> 
>      return 0;
>  }
> +
> +AVHWFramesConstraints *av_hwframe_constraints_alloc(void)
> +{
> +    AVHWFramesConstraints *constraints;
> +
> +    constraints = av_mallocz(sizeof(*constraints));
> +    if (!constraints)
> +        return NULL;
> +
> +    constraints->min_width = constraints->min_height = 0;
> +    constraints->max_width = constraints->max_height = INT_MAX;
> +
> +    return constraints;
> +}
> +
> +void *av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
> +{
> +    AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
> +    const HWContextType  *hw_type = ctx->internal->hw_type;
> +
> +    if (hw_type->device_hwconfig_size == 0)
> +        return NULL;
> +
> +    return av_mallocz(hw_type->device_hwconfig_size);
> +}
> +
> +int av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
> +                                        void *hwconfig,
> +                                        AVHWFramesConstraints *constraints)
> +{
> +    AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
> +    const HWContextType  *hw_type = ctx->internal->hw_type;
> +
> +    if (!hw_type->frames_get_constraints)
> +        return AVERROR(ENOSYS);
> +
> +    return hw_type->frames_get_constraints(ctx, hwconfig, constraints);
> +}
> diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
> index 81ae817..a73c515 100644
> --- a/libavutil/hwcontext.h
> +++ b/libavutil/hwcontext.h
> @@ -326,4 +326,62 @@ int av_hwframe_transfer_get_formats(AVBufferRef 
> *hwframe_ctx,
>                                      enum AVPixelFormat **formats, int flags);
> 
> 
> +/**
> + * This struct describes the constraints on hardware frames attached to
> + * a given device with a hardware-specific configuration.
> + */
> +typedef struct AVHWFramesConstraints {
> +    /**
> +     * A list of possible values for sw_format in the hw_frames_ctx.
> +     * The list is terminated by AV_PIX_FMT_NONE and must be freed by the
> +     * caller with av_free() when the whole constraint structure is freed.
> +     * Can be NULL if this information is not known.
> +     */
> +    enum AVPixelFormat *valid_sw_formats;

I think it would be better to add a destructor for AVHWFramesConstraints
and free this array there.
Otherwise, if we add more allocated fields to it, old callers won't
free them, resulting in memleaks.

> +
> +    /**
> +     * The minimum size of frames in this hw_frames_ctx.
> +     * (Zero if not known.)
> +     */
> +    int min_width;
> +    int min_height;
> +
> +    /**
> +     * The maximum size of frames in this hw_frames_ctx.
> +     * (INT_MAX if not known / no limit.)
> +     */
> +    int max_width;
> +    int max_height;
> +} AVHWFramesConstraints;
> +
> +/**
> + * Allocate an AVHWFrameConstraints structure for a given hwdevice.
> + *
> + * @return The newly created AVHWFrameConstraints structure.
> + */
> +AVHWFramesConstraints *av_hwframe_constraints_alloc(void);
> +
> +/**
> + * Allocate a HW-specific configuration structure for a given HW device.
> + *
> + * @param device_ctx a reference to the associated AVHWDeviceContext.
> + * @return The newly created HW-specific configuration structure on
> + *         success or NULL on failure.
> + */
> +void *av_hwdevice_hwconfig_alloc(AVBufferRef *device_ctx);
> +
> +/**
> + * Get the constraints on HW frames given a device and the HW-specific
> + * configuration to be used with that device.
> + *
> + * @param device_ctx a reference to the associated AVHWDeviceContext.
> + * @param hwconfig a filled HW-specific configuration structure.
> + * @param constraints on successful return, the constraints which apply
> + *        to frames in this device configuration.
> + * @return 0 on success, a negative AVERROR code on failure.
> + */
> +int av_hwdevice_get_hwframe_constraints(AVBufferRef *device_ctx,
> +                                        void *hwconfig,

Should this be const? It's not completely clear from the API whether
hwconfig is read-only to this function and how it should be freed.

I guess your intention was to have it freed just by av_free() and all
fields in it are assumed to be owned by the caller at all times. That is
ok with me, but should be clearly documented.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to