60#if CONFIG_VIDEOTOOLBOX
147 return ctx->hw_type->name;
151 .class_name =
"AVHWDeviceContext",
236 .class_name =
"AVHWFramesContext",
293 ctx->device_ref = device_ref;
294 ctx->device_ctx = &device_ctx->
p;
319 for (
i = 0;
i <
ctx->initial_pool_size;
i++) {
330 for (
i = 0;
i <
ctx->initial_pool_size;
i++)
356 "The hardware pixel format '%s' is not supported by the device type '%s'\n",
377 if (
ctx->initial_pool_size > 0) {
404 if (!
src->hw_frames_ctx)
414 if (
dst->format >= 0) {
461 if (
src->hw_frames_ctx &&
dst->hw_frames_ctx) {
469 "A device with a derived frame context cannot be used as "
470 "the source of a HW -> HW transfer.");
476 "A device with a derived frame context cannot be used as "
477 "the destination of a HW -> HW transfer.");
487 if (
src->hw_frames_ctx) {
490 ret =
ctx->hw_type->transfer_data_from(&
ctx->p,
dst,
src);
493 }
else if (
dst->hw_frames_ctx) {
496 ret =
ctx->hw_type->transfer_data_to(&
ctx->p,
dst,
src);
519 if (!
frame->hw_frames_ctx)
537 "frame context: %d.\n", ret);
556 if (!
frame->hw_frames_ctx)
582 const void *hwconfig)
591 constraints =
av_mallocz(
sizeof(*constraints));
609 av_freep(&(*constraints)->valid_hw_formats);
610 av_freep(&(*constraints)->valid_sw_formats);
643 *pdevice_ref = device_ref;
709 *dst_ref_ptr = dst_ref;
772 hwmap->
unmap = unmap;
800 if (
src->hw_frames_ctx &&
dst->hw_frames_ctx) {
804 if ((src_frames == dst_frames &&
809 (uint8_t*)dst_frames)) {
816 "found when attempting unmap.\n");
824 if (
src->hw_frames_ctx) {
833 else if (ret !=
AVERROR(ENOSYS))
838 if (
dst->hw_frames_ctx) {
847 else if (ret !=
AVERROR(ENOSYS))
858 orig_dst_frames ==
dst->hw_frames_ctx);
865 dst->hw_frames_ctx = orig_dst_frames;
866 dst->format = orig_dst_fmt;
893 if (!*derived_frame_ctx) {
911 dst->sw_format =
src->sw_format;
913 dst->height =
src->height;
938 *derived_frame_ctx = dst_ref;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
refcounted data buffer API
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
common internal and external API header
static enum AVPixelFormat pix_fmt
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
#define LIBAVUTIL_VERSION_INT
enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev)
Iterate over supported device types.
int av_hwdevice_ctx_init(AVBufferRef *ref)
Finalize the device context before use.
static void ff_hwframe_unmap(void *opaque, uint8_t *data)
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it.
int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ref, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats, int flags)
Get a list of possible source or target formats usable in av_hwframe_transfer_data().
static int hwframe_pool_prealloc(AVBufferRef *ref)
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
const char * av_hwdevice_get_type_name(enum AVHWDeviceType type)
Get the string name of an AVHWDeviceType.
static const char *const hw_type_names[]
int av_hwdevice_ctx_create_derived(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, int flags)
Create a new device of the specified type from an existing device.
int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx, enum AVPixelFormat format, AVBufferRef *derived_device_ctx, AVBufferRef *source_frame_ctx, int flags)
Create and initialise an AVHWFramesContext as a mapping of another existing AVHWFramesContext on a di...
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
Look up an AVHWDeviceType by name.
static const HWContextType *const hw_table[]
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
static const AVClass hwframe_ctx_class
static void hwframe_ctx_free(void *opaque, uint8_t *data)
int ff_hwframe_map_create(AVBufferRef *hwframe_ref, AVFrame *dst, const AVFrame *src, void(*unmap)(AVHWFramesContext *ctx, HWMapDescriptor *hwmap), void *priv)
static void hwdevice_ctx_free(void *opaque, uint8_t *data)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
Map a hardware frame.
static const char * hwdevice_ctx_get_name(void *ptr)
static const AVClass hwdevice_ctx_class
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr, enum AVHWDeviceType type, AVBufferRef *src_ref, AVDictionary *options, int flags)
Create a new device of the specified type from an existing device.
int ff_hwframe_map_replace(AVFrame *dst, const AVFrame *src)
Replace the current hwmap of dst with the one from src, used for indirect mappings like VAAPI->(DRM)-...
@ AV_HWFRAME_MAP_READ
The mapping must be readable.
@ AV_HWFRAME_MAP_DIRECT
The mapping must be direct.
@ AV_HWFRAME_MAP_WRITE
The mapping must be writeable.
@ AV_HWFRAME_MAP_OVERWRITE
The mapped frame will be overwritten completely in subsequent operations, so the current frame data n...
AVHWFrameTransferDirection
@ AV_HWFRAME_TRANSFER_DIRECTION_FROM
Transfer the data from the queried hw frame.
@ AV_HWDEVICE_TYPE_OHCODEC
@ AV_HWDEVICE_TYPE_D3D11VA
@ AV_HWDEVICE_TYPE_OPENCL
@ AV_HWDEVICE_TYPE_VULKAN
@ AV_HWDEVICE_TYPE_MEDIACODEC
@ AV_HWDEVICE_TYPE_VIDEOTOOLBOX
@ AV_HWDEVICE_TYPE_D3D12VA
const HWContextType ff_hwcontext_type_amf
const HWContextType ff_hwcontext_type_cuda
const HWContextType ff_hwcontext_type_d3d11va
const HWContextType ff_hwcontext_type_d3d12va
const HWContextType ff_hwcontext_type_drm
const HWContextType ff_hwcontext_type_dxva2
const HWContextType ff_hwcontext_type_opencl
const HWContextType ff_hwcontext_type_vaapi
const HWContextType ff_hwcontext_type_vdpau
const HWContextType ff_hwcontext_type_qsv
const HWContextType ff_hwcontext_type_oh
const HWContextType ff_hwcontext_type_videotoolbox
const HWContextType ff_hwcontext_type_vulkan
const HWContextType ff_hwcontext_type_mediacodec
@ AV_CLASS_CATEGORY_HWDEVICE
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
AVPixelFormat
Pixel format.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
Describe the class of an AVClass context structure.
This structure describes decoded (raw) audio or video data.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int max_width
The maximum size of frames in this hw_frames_ctx.
int min_width
The minimum size of frames in this hw_frames_ctx.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
const HWContextType * hw_type
AVBufferRef * source_device
For a derived device, a reference to the original device context it was derived from.
AVHWDeviceContext p
The public AVHWDeviceContext.
const HWContextType * hw_type
int source_allocation_map_flags
Flags to apply to the mapping from the source to the derived frame context when trying to allocate in...
AVHWFramesContext p
The public AVHWFramesContext.
AVBufferPool * pool_internal
AVBufferRef * source_frames
For a derived context, a reference to the original frames context it was derived from.
size_t frames_hwctx_size
size of the public frame pool hardware-specific context, i.e.
int(* transfer_data_from)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
int(* map_from)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
int(* frames_get_constraints)(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
int(* device_create)(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags)
int(* transfer_data_to)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
int(* transfer_get_formats)(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
int(* map_to)(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src, int flags)
int(* frames_get_buffer)(AVHWFramesContext *ctx, AVFrame *frame)
size_t device_hwctx_size
size of the public hardware-specific context, i.e.
int(* device_init)(AVHWDeviceContext *ctx)
int(* frames_derive_to)(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
void(* frames_uninit)(AVHWFramesContext *ctx)
int(* frames_derive_from)(AVHWFramesContext *dst_ctx, AVHWFramesContext *src_ctx, int flags)
size_t device_hwconfig_size
Size of the hardware-specific device configuration.
void(* device_uninit)(AVHWDeviceContext *ctx)
int(* device_derive)(AVHWDeviceContext *dst_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
int(* frames_init)(AVHWFramesContext *ctx)
enum AVPixelFormat * pix_fmts
An array of pixel formats supported by the AVHWFramesContext instances Terminated by AV_PIX_FMT_NONE.
void * priv
Hardware-specific private data associated with the mapping.
void(* unmap)(AVHWFramesContext *ctx, struct HWMapDescriptor *hwmap)
Unmap function.
AVFrame * source
A reference to the original source of the mapping.
AVBufferRef * hw_frames_ctx
A reference to the hardware frames context in which this mapping was made.
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
static AVDictionary * opts
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)