FFmpeg
Data Structures | Macros | Functions | Variables
hwcontext_opencl.c File Reference
#include <string.h>
#include "config.h"
#include "avassert.h"
#include "avstring.h"
#include "common.h"
#include "hwcontext.h"
#include "hwcontext_internal.h"
#include "hwcontext_opencl.h"
#include "mem.h"
#include "pixdesc.h"

Go to the source code of this file.

Data Structures

struct  OpenCLDeviceContext
 
struct  OpenCLFramesContext
 
struct  OpenCLDeviceSelector
 
struct  OpenCLMapping
 

Macros

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
 
#define CL_FUNC(name, desc)
 
#define CHANNEL_ORDER(order, type)   case order: image_format->image_channel_order = type; break;
 

Functions

static void CL_CALLBACK opencl_error_callback (const char *errinfo, const void *private_info, size_t cb, void *user_data)
 
static void opencl_device_free (AVHWDeviceContext *hwdev)
 
static char * opencl_get_platform_string (cl_platform_id platform_id, cl_platform_info key)
 
static char * opencl_get_device_string (cl_device_id device_id, cl_device_info key)
 
static int opencl_check_platform_extension (cl_platform_id platform_id, const char *name)
 
static int opencl_check_device_extension (cl_device_id device_id, const char *name)
 
static av_unused int opencl_check_extension (AVHWDeviceContext *hwdev, const char *name)
 
static int opencl_enumerate_platforms (AVHWDeviceContext *hwdev, cl_uint *nb_platforms, cl_platform_id **platforms, void *context)
 
static int opencl_filter_platform (AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, void *context)
 
static int opencl_enumerate_devices (AVHWDeviceContext *hwdev, cl_platform_id platform_id, const char *platform_name, cl_uint *nb_devices, cl_device_id **devices, void *context)
 
static int opencl_filter_device (AVHWDeviceContext *hwdev, cl_device_id device_id, const char *device_name, void *context)
 
static int opencl_device_create_internal (AVHWDeviceContext *hwdev, const OpenCLDeviceSelector *selector, cl_context_properties *props)
 
static int opencl_device_create (AVHWDeviceContext *hwdev, const char *device, AVDictionary *opts, int flags)
 
static int opencl_device_init (AVHWDeviceContext *hwdev)
 
static void opencl_device_uninit (AVHWDeviceContext *hwdev)
 
static int opencl_device_derive (AVHWDeviceContext *hwdev, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
 
static int opencl_get_plane_format (enum AVPixelFormat pixfmt, int plane, int width, int height, cl_image_format *image_format, cl_image_desc *image_desc)
 
static int opencl_frames_get_constraints (AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints)
 
static void opencl_pool_free (void *opaque, uint8_t *data)
 
static AVBufferRefopencl_pool_alloc (void *opaque, size_t size)
 
static int opencl_frames_init_command_queue (AVHWFramesContext *hwfc)
 
static int opencl_frames_init (AVHWFramesContext *hwfc)
 
static void opencl_frames_uninit (AVHWFramesContext *hwfc)
 
static int opencl_get_buffer (AVHWFramesContext *hwfc, AVFrame *frame)
 
static int opencl_transfer_get_formats (AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
 
static int opencl_wait_events (AVHWFramesContext *hwfc, cl_event *events, int nb_events)
 
static int opencl_transfer_data_from (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
 
static int opencl_transfer_data_to (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
 
static void opencl_unmap_frame (AVHWFramesContext *hwfc, HWMapDescriptor *hwmap)
 
static int opencl_map_frame (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
 
static cl_mem_flags opencl_mem_flags_for_mapping (int map_flags)
 
static int opencl_map_from (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
 
static int opencl_map_to (AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
 
static int opencl_frames_derive_to (AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
 

Variables

struct {
   const char *   key
 
   cl_platform_info   name
 
opencl_platform_params []
 
struct {
   const char *   key
 
   cl_device_info   name
 
opencl_device_params []
 
struct {
   const char *   key
 
   cl_device_type   type
 
opencl_device_types []
 
const HWContextType ff_hwcontext_type_opencl
 

Macro Definition Documentation

◆ CL_USE_DEPRECATED_OPENCL_1_2_APIS

#define CL_USE_DEPRECATED_OPENCL_1_2_APIS

Definition at line 19 of file hwcontext_opencl.c.

◆ CL_FUNC

#define CL_FUNC (   name,
  desc 
)
Value:
do { \
if (fail) \
break; \
priv->name = clGetExtensionFunctionAddressForPlatform( \
priv->platform_id, #name); \
if (!priv->name) { \
av_log(hwdev, AV_LOG_VERBOSE, \
desc " function not found (%s).\n", #name); \
fail = 1; \
} else { \
av_log(hwdev, AV_LOG_VERBOSE, \
desc " function found (%s).\n", #name); \
} \
} while (0)

◆ CHANNEL_ORDER

#define CHANNEL_ORDER (   order,
  type 
)    case order: image_format->image_channel_order = type; break;

Function Documentation

◆ opencl_error_callback()

static void CL_CALLBACK opencl_error_callback ( const char *  errinfo,
const void *  private_info,
size_t  cb,
void *  user_data 
)
static

Definition at line 167 of file hwcontext_opencl.c.

Referenced by opencl_device_create_internal().

◆ opencl_device_free()

static void opencl_device_free ( AVHWDeviceContext hwdev)
static

Definition at line 176 of file hwcontext_opencl.c.

Referenced by opencl_device_create_internal().

◆ opencl_get_platform_string()

static char* opencl_get_platform_string ( cl_platform_id  platform_id,
cl_platform_info  key 
)
static

◆ opencl_get_device_string()

static char* opencl_get_device_string ( cl_device_id  device_id,
cl_device_info  key 
)
static

◆ opencl_check_platform_extension()

static int opencl_check_platform_extension ( cl_platform_id  platform_id,
const char *  name 
)
static

Definition at line 265 of file hwcontext_opencl.c.

Referenced by opencl_check_extension().

◆ opencl_check_device_extension()

static int opencl_check_device_extension ( cl_device_id  device_id,
const char *  name 
)
static

Definition at line 278 of file hwcontext_opencl.c.

Referenced by opencl_check_extension().

◆ opencl_check_extension()

static av_unused int opencl_check_extension ( AVHWDeviceContext hwdev,
const char *  name 
)
static

Definition at line 291 of file hwcontext_opencl.c.

Referenced by opencl_device_init().

◆ opencl_enumerate_platforms()

static int opencl_enumerate_platforms ( AVHWDeviceContext hwdev,
cl_uint *  nb_platforms,
cl_platform_id **  platforms,
void *  context 
)
static

Definition at line 312 of file hwcontext_opencl.c.

Referenced by opencl_device_create(), and opencl_device_derive().

◆ opencl_filter_platform()

static int opencl_filter_platform ( AVHWDeviceContext hwdev,
cl_platform_id  platform_id,
const char *  platform_name,
void *  context 
)
static

Definition at line 343 of file hwcontext_opencl.c.

Referenced by opencl_device_create(), and opencl_device_derive().

◆ opencl_enumerate_devices()

static int opencl_enumerate_devices ( AVHWDeviceContext hwdev,
cl_platform_id  platform_id,
const char *  platform_name,
cl_uint *  nb_devices,
cl_device_id **  devices,
void *  context 
)
static

Definition at line 378 of file hwcontext_opencl.c.

Referenced by opencl_device_create(), and opencl_device_derive().

◆ opencl_filter_device()

static int opencl_filter_device ( AVHWDeviceContext hwdev,
cl_device_id  device_id,
const char *  device_name,
void *  context 
)
static

Definition at line 418 of file hwcontext_opencl.c.

Referenced by opencl_device_create().

◆ opencl_device_create_internal()

static int opencl_device_create_internal ( AVHWDeviceContext hwdev,
const OpenCLDeviceSelector selector,
cl_context_properties *  props 
)
static

Definition at line 508 of file hwcontext_opencl.c.

Referenced by opencl_device_create(), and opencl_device_derive().

◆ opencl_device_create()

static int opencl_device_create ( AVHWDeviceContext hwdev,
const char *  device,
AVDictionary opts,
int  flags 
)
static

Definition at line 641 of file hwcontext_opencl.c.

Referenced by opencl_device_derive().

◆ opencl_device_init()

static int opencl_device_init ( AVHWDeviceContext hwdev)
static

Definition at line 674 of file hwcontext_opencl.c.

◆ opencl_device_uninit()

static void opencl_device_uninit ( AVHWDeviceContext hwdev)
static

Definition at line 910 of file hwcontext_opencl.c.

◆ opencl_device_derive()

static int opencl_device_derive ( AVHWDeviceContext hwdev,
AVHWDeviceContext src_ctx,
AVDictionary opts,
int  flags 
)
static

Definition at line 1217 of file hwcontext_opencl.c.

◆ opencl_get_plane_format()

static int opencl_get_plane_format ( enum AVPixelFormat  pixfmt,
int  plane,
int  width,
int  height,
cl_image_format *  image_format,
cl_image_desc *  image_desc 
)
static

◆ opencl_frames_get_constraints()

static int opencl_frames_get_constraints ( AVHWDeviceContext hwdev,
const void *  hwconfig,
AVHWFramesConstraints constraints 
)
static

Definition at line 1505 of file hwcontext_opencl.c.

◆ opencl_pool_free()

static void opencl_pool_free ( void *  opaque,
uint8_t *  data 
)
static

Definition at line 1632 of file hwcontext_opencl.c.

Referenced by opencl_pool_alloc().

◆ opencl_pool_alloc()

static AVBufferRef* opencl_pool_alloc ( void *  opaque,
size_t  size 
)
static

Definition at line 1650 of file hwcontext_opencl.c.

Referenced by opencl_frames_init().

◆ opencl_frames_init_command_queue()

static int opencl_frames_init_command_queue ( AVHWFramesContext hwfc)
static

Definition at line 1706 of file hwcontext_opencl.c.

Referenced by opencl_frames_derive_to(), and opencl_frames_init().

◆ opencl_frames_init()

static int opencl_frames_init ( AVHWFramesContext hwfc)
static

Definition at line 1725 of file hwcontext_opencl.c.

◆ opencl_frames_uninit()

static void opencl_frames_uninit ( AVHWFramesContext hwfc)
static

Definition at line 1738 of file hwcontext_opencl.c.

◆ opencl_get_buffer()

static int opencl_get_buffer ( AVHWFramesContext hwfc,
AVFrame frame 
)
static

Definition at line 1769 of file hwcontext_opencl.c.

◆ opencl_transfer_get_formats()

static int opencl_transfer_get_formats ( AVHWFramesContext hwfc,
enum AVHWFrameTransferDirection  dir,
enum AVPixelFormat **  formats 
)
static

Definition at line 1790 of file hwcontext_opencl.c.

◆ opencl_wait_events()

static int opencl_wait_events ( AVHWFramesContext hwfc,
cl_event *  events,
int  nb_events 
)
static

◆ opencl_transfer_data_from()

static int opencl_transfer_data_from ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src 
)
static

Definition at line 1831 of file hwcontext_opencl.c.

◆ opencl_transfer_data_to()

static int opencl_transfer_data_to ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src 
)
static

Definition at line 1886 of file hwcontext_opencl.c.

◆ opencl_unmap_frame()

static void opencl_unmap_frame ( AVHWFramesContext hwfc,
HWMapDescriptor hwmap 
)
static

Definition at line 1948 of file hwcontext_opencl.c.

Referenced by opencl_map_frame().

◆ opencl_map_frame()

static int opencl_map_frame ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 1977 of file hwcontext_opencl.c.

Referenced by opencl_map_from().

◆ opencl_mem_flags_for_mapping()

static cl_mem_flags opencl_mem_flags_for_mapping ( int  map_flags)
inlinestatic

Definition at line 2217 of file hwcontext_opencl.c.

◆ opencl_map_from()

static int opencl_map_from ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 2921 of file hwcontext_opencl.c.

◆ opencl_map_to()

static int opencl_map_to ( AVHWFramesContext hwfc,
AVFrame dst,
const AVFrame src,
int  flags 
)
static

Definition at line 2930 of file hwcontext_opencl.c.

◆ opencl_frames_derive_to()

static int opencl_frames_derive_to ( AVHWFramesContext dst_fc,
AVHWFramesContext src_fc,
int  flags 
)
static

Definition at line 2975 of file hwcontext_opencl.c.

Variable Documentation

◆ key

const char* key
Examples
qsv_transcode.c.

Definition at line 189 of file hwcontext_opencl.c.

Referenced by aa_read_header(), add_metadata(), add_opt(), add_timecode_metadata(), amf_parse_object(), ape_tag_read_field(), av_aes_ctr_init(), av_aes_init(), av_blowfish_init(), av_camellia_init(), av_cast5_init(), av_des_init(), av_dict_get(), av_dict_set(), av_dict_set_fxp(), av_dict_set_int(), av_hmac_calc(), av_hmac_init(), av_opt_get_key_value(), av_opt_query_ranges(), av_opt_query_ranges_default(), av_opt_set_from_string(), av_packet_unpack_dictionary(), av_rc4_init(), av_tea_init(), av_tree_find(), av_tree_insert(), av_twofish_init(), av_xtea_init(), av_xtea_le_init(), avi_read_packet(), avi_read_tag(), avpriv_dict_set_timestamp(), cat_header(), check_keyboard_interaction(), cipher_init56_create_table(), cmp(), cmp_find(), cmp_id_key(), cmp_insert(), compact_print_int(), compact_print_str(), compare_sl(), cri_decode_frame(), dat_read_packet(), decode_block(), decode_frame(), decode_header(), decode_key(), default_print_int(), default_print_str(), descriptor_compare(), dict_copy_entry(), dict_iterate(), djb2_hash(), do_encrypt(), dss_read_metadata_date(), dss_read_metadata_string(), ea_read_packet(), epic_add_pixel_to_cache(), epic_hash_add(), epic_hash_find(), ff_asfcrypt_dec(), ff_attributes_dump(), ff_dolby_e_convert_input(), ff_dolby_e_parse_header(), ff_filter_opt_parse(), ff_http_auth_handle_header(), ff_id3v2_parse_priv_dict(), ff_metadata_conv(), ff_parse_key_value(), ff_read_riff_info(), ff_rtmp_calc_digest(), ff_tee_parse_slave_options(), filter_frame(), filter_opt_apply(), flat_print_int(), flat_print_str(), free_segment_dynarray(), gain_entry_compare(), gen_roundkeys(), get_geokey_val(), get_meta(), get_string(), get_tag(), handle_basic_params(), handle_digest_params(), handle_digest_update(), handle_init_section_args(), handle_key_args(), handle_rendition_args(), handle_variant_args(), hls_encryption_start(), hls_read_header(), hpel_motion_search(), ht_delete(), ht_lookup_and_upsert(), id3v1_set_string(), id3v2_3_metadata_split_date(), id3v2_put_priv(), ini_print_int(), ini_print_str(), init_report(), ivr_read_header(), json_print_int(), json_print_item_str(), json_print_str(), libx265_param_parse_float(), libx265_param_parse_int(), main(), match_stream_specifier(), mediaformat_jni_getBuffer(), mediaformat_jni_getFloat(), mediaformat_jni_getInt32(), mediaformat_jni_getInt64(), mediaformat_jni_getString(), mediaformat_jni_setBuffer(), mediaformat_jni_setFloat(), mediaformat_jni_setInt32(), mediaformat_jni_setInt64(), mediaformat_jni_setString(), metadata_header_size(), microdvd_close_no_persistent_tags(), microdvd_init(), microdvd_open_tags(), mkv_write_simpletag(), mov_metadata_gnre(), mov_metadata_int8_bypass_padding(), mov_metadata_int8_no_padding(), mov_metadata_loci(), mov_metadata_track_or_disc_number(), mov_parse_vc1_frame(), mov_read_custom(), mov_read_udta_string(), mov_write_raw_metadata_tag(), move_metadata(), mpegts_write_pes(), multiswap_dec(), multiswap_enc(), mxf_add_timecode_metadata(), mxf_add_umid_metadata(), mxf_is_partition_pack_key(), mxf_match_uid(), mxf_parse_package_comments(), mxf_read_indirect_value(), mxf_read_sync(), mxf_write_cdci_common(), mxf_write_generic_desc(), mxf_write_generic_sound_common(), mxf_write_opatom_body_partition(), mxf_write_partition(), mxf_write_wav_common(), nist_read_header(), nuv_read_dts(), offset_fn(), ogm_chapter(), open_input(), opencl_filter_device(), opencl_filter_platform(), opencl_get_device_string(), opencl_get_platform_string(), opt_preset(), parse_audio(), parse_key(), parse_key_value_pair(), parse_legacy_attrib(), parse_playlist(), parse_str_int(), parse_utf(), put_meta(), read_comment(), read_info_chunk(), read_odml_index(), read_sb_block(), read_tag(), read_ttag(), read_uslt(), read_vblock(), redspark_probe(), redspark_read_header(), sab_diamond_search(), set_encoder_int_property_or_log(), set_encoder_property_or_log(), set_meta(), set_metadata_float(), set_metadata_int(), small_diamond_search(), str_to_dict(), subviewer_read_header(), test(), test_encrypt(), update_metadata(), url_alloc_for_protocol(), viv_read_header(), vivo_read_header(), vpx_ts_param_parse(), write_metadata_header(), write_sm_data(), write_tag(), write_tag_int32(), writer_print_integer(), writer_print_rational(), writer_print_string(), writer_print_time(), writer_print_ts(), xml_print_int(), xml_print_str(), xml_print_value(), and xor_block().

◆ name

cl_device_info name

◆ opencl_platform_params

struct { ... } opencl_platform_params[]
Initial value:
= {
{ "platform_profile", CL_PLATFORM_PROFILE },
{ "platform_version", CL_PLATFORM_VERSION },
{ "platform_name", CL_PLATFORM_NAME },
{ "platform_vendor", CL_PLATFORM_VENDOR },
{ "platform_extensions", CL_PLATFORM_EXTENSIONS },
}

Referenced by opencl_filter_platform().

◆ opencl_device_params

struct { ... } opencl_device_params[]
Initial value:
= {
{ "device_name", CL_DEVICE_NAME },
{ "device_vendor", CL_DEVICE_VENDOR },
{ "driver_version", CL_DRIVER_VERSION },
{ "device_version", CL_DEVICE_VERSION },
{ "device_profile", CL_DEVICE_PROFILE },
{ "device_extensions", CL_DEVICE_EXTENSIONS },
}

Referenced by opencl_filter_device().

◆ type

cl_device_type type

Definition at line 213 of file hwcontext_opencl.c.

◆ opencl_device_types

struct { ... } opencl_device_types[]
Initial value:
= {
{ "cpu", CL_DEVICE_TYPE_CPU },
{ "gpu", CL_DEVICE_TYPE_GPU },
{ "accelerator", CL_DEVICE_TYPE_ACCELERATOR },
{ "custom", CL_DEVICE_TYPE_CUSTOM },
{ "default", CL_DEVICE_TYPE_DEFAULT },
{ "all", CL_DEVICE_TYPE_ALL },
}

Referenced by opencl_filter_device().

◆ ff_hwcontext_type_opencl

const HWContextType ff_hwcontext_type_opencl
Initial value:
= {
.name = "OpenCL",
.device_hwctx_size = sizeof(OpenCLDeviceContext),
.frames_hwctx_size = sizeof(OpenCLFramesContext),
.device_create = &opencl_device_create,
.device_derive = &opencl_device_derive,
.device_init = &opencl_device_init,
.device_uninit = &opencl_device_uninit,
.frames_get_constraints = &opencl_frames_get_constraints,
.frames_init = &opencl_frames_init,
.frames_uninit = &opencl_frames_uninit,
.frames_get_buffer = &opencl_get_buffer,
.transfer_get_formats = &opencl_transfer_get_formats,
.transfer_data_to = &opencl_transfer_data_to,
.transfer_data_from = &opencl_transfer_data_from,
.map_from = &opencl_map_from,
.map_to = &opencl_map_to,
.frames_derive_to = &opencl_frames_derive_to,
.pix_fmts = (const enum AVPixelFormat[]) {
},
}

Definition at line 3039 of file hwcontext_opencl.c.

AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
opencl_device_init
static int opencl_device_init(AVHWDeviceContext *hwdev)
Definition: hwcontext_opencl.c:674
opencl_map_from
static int opencl_map_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_opencl.c:2921
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:196
name
cl_platform_info name
Definition: hwcontext_opencl.c:190
opencl_map_to
static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src, int flags)
Definition: hwcontext_opencl.c:2930
fail
#define fail()
Definition: checkasm.h:179
opencl_frames_init
static int opencl_frames_init(AVHWFramesContext *hwfc)
Definition: hwcontext_opencl.c:1725
opencl_device_derive
static int opencl_device_derive(AVHWDeviceContext *hwdev, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
Definition: hwcontext_opencl.c:1217
OpenCLFramesContext
Definition: hwcontext_opencl.c:145
OpenCLDeviceContext
Definition: hwcontext_opencl.c:87
opencl_frames_get_constraints
static int opencl_frames_get_constraints(AVHWDeviceContext *hwdev, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_opencl.c:1505
opencl_transfer_get_formats
static int opencl_transfer_get_formats(AVHWFramesContext *hwfc, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_opencl.c:1790
opencl_frames_uninit
static void opencl_frames_uninit(AVHWFramesContext *hwfc)
Definition: hwcontext_opencl.c:1738
opencl_transfer_data_from
static int opencl_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_opencl.c:1831
AV_PIX_FMT_OPENCL
@ AV_PIX_FMT_OPENCL
Hardware surfaces for OpenCL.
Definition: pixfmt.h:358
AV_HWDEVICE_TYPE_OPENCL
@ AV_HWDEVICE_TYPE_OPENCL
Definition: hwcontext.h:37
opencl_device_uninit
static void opencl_device_uninit(AVHWDeviceContext *hwdev)
Definition: hwcontext_opencl.c:910
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
opencl_device_create
static int opencl_device_create(AVHWDeviceContext *hwdev, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_opencl.c:641
desc
const char * desc
Definition: libsvtav1.c:75
opencl_transfer_data_to
static int opencl_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_opencl.c:1886
opencl_get_buffer
static int opencl_get_buffer(AVHWFramesContext *hwfc, AVFrame *frame)
Definition: hwcontext_opencl.c:1769
opencl_frames_derive_to
static int opencl_frames_derive_to(AVHWFramesContext *dst_fc, AVHWFramesContext *src_fc, int flags)
Definition: hwcontext_opencl.c:2975