FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
hwcontext.c File Reference
#include "config.h"
#include "buffer.h"
#include "common.h"
#include "hwcontext.h"
#include "hwcontext_internal.h"
#include "imgutils.h"
#include "log.h"
#include "mem.h"
#include "pixdesc.h"
#include "pixfmt.h"

Go to the source code of this file.

Functions

static void hwdevice_ctx_free (void *opaque, uint8_t *data)
 
AVBufferRefav_hwdevice_ctx_alloc (enum AVHWDeviceType type)
 Allocate an AVHWDeviceContext for a given pixel format. More...
 
int av_hwdevice_ctx_init (AVBufferRef *ref)
 Finalize the device context before use. More...
 
static void hwframe_ctx_free (void *opaque, uint8_t *data)
 
AVBufferRefav_hwframe_ctx_alloc (AVBufferRef *device_ref_in)
 Allocate an AVHWFramesContext tied to a given device context. More...
 
static int hwframe_pool_prealloc (AVBufferRef *ref)
 
int av_hwframe_ctx_init (AVBufferRef *ref)
 Finalize the context before use. More...
 
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(). More...
 
static int transfer_data_alloc (AVFrame *dst, const AVFrame *src, int flags)
 
int av_hwframe_transfer_data (AVFrame *dst, const AVFrame *src, int flags)
 Copy data to or from a hw surface. More...
 
int av_hwframe_get_buffer (AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
 Allocate a new frame attached to the given AVHWFramesContext. More...
 
voidav_hwdevice_hwconfig_alloc (AVBufferRef *ref)
 Allocate a HW-specific configuration structure for a given HW device. More...
 
AVHWFramesConstraintsav_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 that device. More...
 
void av_hwframe_constraints_free (AVHWFramesConstraints **constraints)
 Free an AVHWFrameConstraints structure. More...
 
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. More...
 

Variables

static const HWContextTypehw_table []
 
static const AVClass hwdevice_ctx_class
 
static const AVClass hwframe_ctx_class
 

Function Documentation

static void hwdevice_ctx_free ( void opaque,
uint8_t data 
)
static

Definition at line 56 of file hwcontext.c.

Referenced by av_hwdevice_ctx_alloc().

AVBufferRef* av_hwdevice_ctx_alloc ( enum AVHWDeviceType  type)

Allocate an AVHWDeviceContext for a given pixel format.

Parameters
formata hwaccel pixel format (AV_PIX_FMT_FLAG_HWACCEL must be set on the corresponding format descriptor)
Returns
a reference to the newly created AVHWDeviceContext on success or NULL on failure.

Definition at line 74 of file hwcontext.c.

Referenced by av_hwdevice_ctx_create(), cudaupload_init(), and qsv_init_child_ctx().

int av_hwdevice_ctx_init ( AVBufferRef ref)

Finalize the device context before use.

This function must be called after the context is filled with all the required information and before it is used in any way.

Parameters
refa reference to the AVHWDeviceContext
Returns
0 on success, a negative AVERROR code on failure

Definition at line 132 of file hwcontext.c.

Referenced by av_hwdevice_ctx_create(), cudaupload_init(), and qsv_init_child_ctx().

static void hwframe_ctx_free ( void opaque,
uint8_t data 
)
static

Definition at line 156 of file hwcontext.c.

Referenced by av_hwframe_ctx_alloc().

AVBufferRef* av_hwframe_ctx_alloc ( AVBufferRef device_ctx)

Allocate an AVHWFramesContext tied to a given device context.

Parameters
device_ctxa reference to a AVHWDeviceContext. This function will make a new reference for internal use, the one passed to the function remains owned by the caller.
Returns
a reference to the newly created AVHWFramesContext on success or NULL on failure.

Definition at line 177 of file hwcontext.c.

Referenced by cudaupload_config_output(), cuvid_decode_init(), cuvid_transcode_init(), dxva2_create_decoder(), ff_vaapi_encode_init(), hwupload_config_output(), init_stage(), qsv_init_child_ctx(), scale_vaapi_config_output(), vaapi_decode_init(), and vdpau_alloc().

static int hwframe_pool_prealloc ( AVBufferRef ref)
static

Definition at line 235 of file hwcontext.c.

Referenced by av_hwframe_ctx_init().

int av_hwframe_ctx_init ( AVBufferRef ref)

Finalize the context before use.

This function must be called after the context is filled with all the required information and before it is attached to any frames.

Parameters
refa reference to the AVHWFramesContext
Returns
0 on success, a negative AVERROR code on failure

Definition at line 263 of file hwcontext.c.

Referenced by cudaupload_config_output(), dxva2_create_decoder(), ff_vaapi_encode_init(), hwupload_config_output(), init_stage(), qsv_init_child_ctx(), scale_vaapi_config_output(), vaapi_decode_init(), and vdpau_alloc().

int av_hwframe_transfer_get_formats ( AVBufferRef hwframe_ctx,
enum AVHWFrameTransferDirection  dir,
enum AVPixelFormat **  formats,
int  flags 
)

Get a list of possible source or target formats usable in av_hwframe_transfer_data().

Parameters
hwframe_ctxthe frame context to obtain the information for
dirthe direction of the transfer
formatsthe pointer to the output format list will be written here. The list is terminated with AV_PIX_FMT_NONE and must be freed by the caller when no longer needed using av_free(). If this function returns successfully, the format list will have at least one item (not counting the terminator). On failure, the contents of this pointer are unspecified.
flagscurrently unused, should be set to zero
Returns
0 on success, a negative AVERROR code on failure.

Definition at line 310 of file hwcontext.c.

Referenced by hwdownload_config_output(), and transfer_data_alloc().

static int transfer_data_alloc ( AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 322 of file hwcontext.c.

Referenced by av_hwframe_transfer_data().

int av_hwframe_transfer_data ( AVFrame dst,
const AVFrame src,
int  flags 
)

Copy data to or from a hw surface.

At least one of dst/src must have an AVHWFramesContext attached.

If src has an AVHWFramesContext attached, then the format of dst (if set) must use one of the formats returned by av_hwframe_transfer_get_formats(src, AV_HWFRAME_TRANSFER_DIRECTION_FROM). If dst has an AVHWFramesContext attached, then the format of src must use one of the formats returned by av_hwframe_transfer_get_formats(dst, AV_HWFRAME_TRANSFER_DIRECTION_TO)

dst may be "clean" (i.e. with data/buf pointers unset), in which case the data buffers will be allocated by this function using av_frame_get_buffer(). If dst->format is set, then this format will be used, otherwise (when dst->format is AV_PIX_FMT_NONE) the first acceptable format will be chosen.

Parameters
dstthe destination frame. dst is not touched on failure.
srcthe source frame.
flagscurrently unused, should be set to zero
Returns
0 on success, a negative AVERROR error code on failure.

Definition at line 364 of file hwcontext.c.

Referenced by cudaupload_filter_frame(), cuvid_output_frame(), dxva2_retrieve_data(), hwdownload_filter_frame(), hwupload_filter_frame(), transfer_data_alloc(), vaapi_retrieve_data(), and vdpau_retrieve_data().

int av_hwframe_get_buffer ( AVBufferRef hwframe_ctx,
AVFrame frame,
int  flags 
)

Allocate a new frame attached to the given AVHWFramesContext.

Parameters
hwframe_ctxa reference to an AVHWFramesContext
framean empty (freshly allocated or unreffed) frame to be filled with newly allocated buffers.
flagscurrently unused, should be set to zero
Returns
0 on success, a negative AVERROR code on failure

Definition at line 390 of file hwcontext.c.

Referenced by avcodec_default_get_buffer2(), cudaupload_filter_frame(), cuvid_output_frame(), dxva2_get_buffer(), hwframe_pool_prealloc(), hwupload_filter_frame(), init_stage(), nppscale_scale(), scale_vaapi_filter_frame(), vaapi_encode_issue(), vaapi_get_buffer(), and vdpau_get_buffer().

void* av_hwdevice_hwconfig_alloc ( AVBufferRef device_ctx)

Allocate a HW-specific configuration structure for a given HW device.

After use, the user must free all members as required by the specific hardware structure being used, then free the structure itself with av_free().

Parameters
device_ctxa reference to the associated AVHWDeviceContext.
Returns
The newly created HW-specific configuration structure on success or NULL on failure.

Definition at line 414 of file hwcontext.c.

Referenced by ff_vaapi_encode_init(), scale_vaapi_config_output(), and vaapi_build_decoder_config().

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

If no HW-specific configuration is provided, returns the maximum possible capabilities of the device.

Parameters
device_ctxa reference to the associated AVHWDeviceContext.
hwconfiga filled HW-specific configuration structure, or NULL to return the maximum possible capabilities of the device.
Returns
AVHWFramesConstraints structure describing the constraints on the device, or NULL if not available.

Definition at line 425 of file hwcontext.c.

Referenced by ff_vaapi_encode_init(), hwupload_query_formats(), scale_vaapi_config_output(), and vaapi_build_decoder_config().

void av_hwframe_constraints_free ( AVHWFramesConstraints **  constraints)

Free an AVHWFrameConstraints structure.

Parameters
constraintsThe (filled or unfilled) AVHWFrameConstraints structure.

Definition at line 450 of file hwcontext.c.

Referenced by av_hwdevice_get_hwframe_constraints(), ff_vaapi_encode_init(), hwupload_query_formats(), scale_vaapi_config_output(), and vaapi_build_decoder_config().

int av_hwdevice_ctx_create ( AVBufferRef **  device_ctx,
enum AVHWDeviceType  type,
const char *  device,
AVDictionary opts,
int  flags 
)

Open a device of the specified type and create an AVHWDeviceContext for it.

This is a convenience function intended to cover the simple cases. Callers who need to fine-tune device creation/management should open the device manually and then wrap it in an AVHWDeviceContext using av_hwdevice_ctx_alloc()/av_hwdevice_ctx_init().

The returned context is already initialized and ready for use, the caller should not call av_hwdevice_ctx_init() on it. The user_opaque/free fields of the created AVHWDeviceContext are set by this function and should not be touched by the caller.

Parameters
device_ctxOn success, a reference to the newly-created device context will be written here. The reference is owned by the caller and must be released with av_buffer_unref() when no longer needed. On failure, NULL will be written to this pointer.
typeThe type of the device to create.
deviceA type-specific string identifying the device to open.
optsA dictionary of additional (type-specific) options to use in opening the device. The dictionary remains owned by the caller.
flagscurrently unused
Returns
0 on success, a negative AVERROR code on failure.

Definition at line 459 of file hwcontext.c.

Referenced by cuvid_decode_init(), cuvid_transcode_init(), dxva2_alloc(), qsv_device_create(), vaapi_device_init(), and vdpau_alloc().

Variable Documentation

const HWContextType* hw_table[]
static
Initial value:
= {
}
#define NULL
Definition: coverity.c:32

Definition at line 31 of file hwcontext.c.

const AVClass hwdevice_ctx_class
static
Initial value:
= {
.class_name = "AVHWDeviceContext",
.item_name = av_default_item_name,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name

Definition at line 50 of file hwcontext.c.

Referenced by av_hwdevice_ctx_alloc().

const AVClass hwframe_ctx_class
static
Initial value:
= {
.class_name = "AVHWFramesContext",
.item_name = av_default_item_name,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
av_default_item_name

Definition at line 150 of file hwcontext.c.

Referenced by av_hwframe_ctx_alloc().