On Thu, 25 Feb 2016 23:47:39 +0000
Mark Thompson <[email protected]> wrote:
> ---
> libavutil/hwcontext.c | 45 ++++++++++++++++++++++++++++
> libavutil/hwcontext.h | 68
> ++++++++++++++++++++++++++++++++++++++++++
> libavutil/hwcontext_internal.h | 10 +++++++
> 3 files changed, 123 insertions(+)
>
> diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
> index b6d0518..a00a7e6 100644
> --- a/libavutil/hwcontext.c
> +++ b/libavutil/hwcontext.c
> @@ -400,3 +400,48 @@ 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);
> +}
> +
> +void av_hwframe_constraints_free(AVHWFramesConstraints *constraints)
> +{
> + av_freep(&constraints->valid_sw_formats);
> + av_freep(&constraints);
> +}
> +
> +int av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
> + const 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..f49a58a 100644
> --- a/libavutil/hwcontext.h
> +++ b/libavutil/hwcontext.h
> @@ -326,4 +326,72 @@ 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;
> +
> + /**
> + * 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);
> +
> +/**
> + * Free an AVHWFrameConstraints structure.
> + *
> + * @param constraints The (filled or unfilled) AVHWFrameConstraints
> structure.
> + */
> +void av_hwframe_constraints_free(AVHWFramesConstraints *constraints);
> +
> +/**
> + * 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. If no HW-specific
> + * confgiuration is provided, returns the maximum possible capabilities
> + * of the device.
> + *
> + * @param device_ctx a reference to the associated AVHWDeviceContext.
> + * @param hwconfig a filled HW-specific configuration structure, or null
> + * to return the maximum possible capabilities of the device.
> + * @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,
> + const void *hwconfig,
> + AVHWFramesConstraints *constraints);
> +
> #endif /* AVUTIL_HWCONTEXT_H */
> diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
> index 641232f..27de1f9 100644
> --- a/libavutil/hwcontext_internal.h
> +++ b/libavutil/hwcontext_internal.h
> @@ -48,6 +48,12 @@ typedef struct HWContextType {
> size_t device_priv_size;
>
> /**
> + * Size of the hardware-specific device configuration.
> + * (Used to query hwframe constraints.)
> + */
> + size_t device_hwconfig_size;
> +
> + /**
> * size of the public frame pool hardware-specific context,
> * i.e. AVHWFramesContext.hwctx
> */
> @@ -61,6 +67,10 @@ typedef struct HWContextType {
> int (*device_init)(AVHWDeviceContext *ctx);
> void (*device_uninit)(AVHWDeviceContext *ctx);
>
> + int (*frames_get_constraints)(AVHWDeviceContext *ctx,
> + const void *hwconfig,
> + AVHWFramesConstraints
> *constraints);
> +
> int (*frames_init)(AVHWFramesContext *ctx);
> void (*frames_uninit)(AVHWFramesContext *ctx);
>
Maybe I'm a bit too late to the party, but...
This seems all a bit roundabout. Can't the implementation just alloc
the struct and return it from HWContextType.frames_get_constraints,
instead of making the common call alloc it and requiring a
device_hwconfig_size field?
Only av_hwframe_constraints_free() seems to be required as public API.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel