* [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext
@ 2024-02-12 0:01 Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 02/23] avutil/hwcontext: Don't check before av_buffer_unref() Andreas Rheinhardt
` (23 more replies)
0 siblings, 24 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:01 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
The currently used pointer when unmapping DXVA2 and D3D11
actually points to an OpenCLDeviceContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
1. I'd appreciate testing of this.
2. Most of the patches in this patchset can be applied immediately;
only those two patches that remove AVHWDeviceInternal and
AVHWFramesInternal need to be applied at the bump.
libavutil/hwcontext_opencl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 247834aaf6..c1764ed098 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -2346,7 +2346,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc,
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
- OpenCLFramesContext *frames_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2511,7 +2511,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
- OpenCLFramesContext *frames_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 02/23] avutil/hwcontext: Don't check before av_buffer_unref()
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 03/23] avutil/hwcontext_vaapi: Allocate public and priv device hwctx together Andreas Rheinhardt
` (22 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
av_buffer_unref() can handle AVBufferRef** that point
to a NULL AVBufferRef*.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index e23bad230f..63fc1a6a22 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -297,8 +297,7 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
return buf;
fail:
- if (device_ref)
- av_buffer_unref(&device_ref);
+ av_buffer_unref(&device_ref);
if (ctx->internal)
av_freep(&ctx->internal->priv);
av_freep(&ctx->internal);
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 03/23] avutil/hwcontext_vaapi: Allocate public and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 02/23] avutil/hwcontext: Don't check before av_buffer_unref() Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 04/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
` (21 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VAAPIDeviceContext as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vaapi.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 29fc8bd648..7019769f24 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -75,6 +75,11 @@ typedef struct VAAPISurfaceFormat {
} VAAPISurfaceFormat;
typedef struct VAAPIDeviceContext {
+ /**
+ * The public AVVAAPIDeviceContext. See hwcontext_vaapi.h for it.
+ */
+ AVVAAPIDeviceContext p;
+
// Surface formats which can be used with this device.
VAAPISurfaceFormat *formats;
int nb_formats;
@@ -207,7 +212,7 @@ static int vaapi_get_image_format(AVHWDeviceContext *hwdev,
enum AVPixelFormat pix_fmt,
VAImageFormat **image_format)
{
- VAAPIDeviceContext *ctx = hwdev->internal->priv;
+ VAAPIDeviceContext *ctx = hwdev->hwctx;
int i;
for (i = 0; i < ctx->nb_formats; i++) {
@@ -224,9 +229,9 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev,
const void *hwconfig,
AVHWFramesConstraints *constraints)
{
- AVVAAPIDeviceContext *hwctx = hwdev->hwctx;
+ VAAPIDeviceContext *ctx = hwdev->hwctx;
+ AVVAAPIDeviceContext *hwctx = &ctx->p;
const AVVAAPIHWConfig *config = hwconfig;
- VAAPIDeviceContext *ctx = hwdev->internal->priv;
VASurfaceAttrib *attr_list = NULL;
VAStatus vas;
enum AVPixelFormat pix_fmt;
@@ -384,8 +389,8 @@ static const struct {
static int vaapi_device_init(AVHWDeviceContext *hwdev)
{
- VAAPIDeviceContext *ctx = hwdev->internal->priv;
- AVVAAPIDeviceContext *hwctx = hwdev->hwctx;
+ VAAPIDeviceContext *ctx = hwdev->hwctx;
+ AVVAAPIDeviceContext *hwctx = &ctx->p;
VAImageFormat *image_list = NULL;
VAStatus vas;
const char *vendor_string;
@@ -474,7 +479,7 @@ fail:
static void vaapi_device_uninit(AVHWDeviceContext *hwdev)
{
- VAAPIDeviceContext *ctx = hwdev->internal->priv;
+ VAAPIDeviceContext *ctx = hwdev->hwctx;
av_freep(&ctx->formats);
}
@@ -718,7 +723,7 @@ static int vaapi_transfer_get_formats(AVHWFramesContext *hwfc,
enum AVHWFrameTransferDirection dir,
enum AVPixelFormat **formats)
{
- VAAPIDeviceContext *ctx = hwfc->device_ctx->internal->priv;
+ VAAPIDeviceContext *ctx = hwfc->device_ctx->hwctx;
enum AVPixelFormat *pix_fmts;
int i, k, sw_format_available;
@@ -2007,8 +2012,7 @@ const HWContextType ff_hwcontext_type_vaapi = {
.type = AV_HWDEVICE_TYPE_VAAPI,
.name = "VAAPI",
- .device_hwctx_size = sizeof(AVVAAPIDeviceContext),
- .device_priv_size = sizeof(VAAPIDeviceContext),
+ .device_hwctx_size = sizeof(VAAPIDeviceContext),
.device_hwconfig_size = sizeof(AVVAAPIHWConfig),
.frames_hwctx_size = sizeof(AVVAAPIFramesContext),
.frames_priv_size = sizeof(VAAPIFramesContext),
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 04/23] avutil/hwcontext_vulkan: Allocate public and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 02/23] avutil/hwcontext: Don't check before av_buffer_unref() Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 03/23] avutil/hwcontext_vaapi: Allocate public and priv device hwctx together Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 05/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
` (20 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VulkanDevicePriv as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vulkan.c | 109 ++++++++++++++++++-----------------
1 file changed, 56 insertions(+), 53 deletions(-)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index a84713e621..3d591dedf9 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -81,6 +81,11 @@ typedef struct VulkanQueueCtx {
} VulkanQueueCtx;
typedef struct VulkanDevicePriv {
+ /**
+ * The public AVVulkanDeviceContext. See hwcontext_vulkan.h for it.
+ */
+ AVVulkanDeviceContext p;
+
/* Vulkan library and loader functions */
void *libvulkan;
@@ -288,8 +293,8 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
VkImageUsageFlags *supported_usage, /* Output supported usage */
int disable_multiplane, int need_storage)
{
- AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
- VulkanDevicePriv *priv = dev_ctx->internal->priv;
+ VulkanDevicePriv *priv = dev_ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &priv->p;
FFVulkanFunctions *vk = &priv->vkctx.vkfn;
const VkFormatFeatureFlagBits2 basic_flags = VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT |
@@ -369,8 +374,8 @@ static int vkfmt_from_pixfmt2(AVHWDeviceContext *dev_ctx, enum AVPixelFormat p,
static int load_libvulkan(AVHWDeviceContext *ctx)
{
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
static const char *lib_names[] = {
#if defined(_WIN32)
@@ -488,9 +493,9 @@ static int check_extensions(AVHWDeviceContext *ctx, int dev, AVDictionary *opts,
{
const char *tstr;
const char **extension_names = NULL;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
int err = 0, found, extensions_found = 0;
const char *mod;
@@ -619,7 +624,7 @@ static int check_validation_layers(AVHWDeviceContext *ctx, AVDictionary *opts,
static const char default_layer[] = { "VK_LAYER_KHRONOS_validation" };
int found = 0, err = 0;
- VulkanDevicePriv *priv = ctx->internal->priv;
+ VulkanDevicePriv *priv = ctx->hwctx;
FFVulkanFunctions *vk = &priv->vkctx.vkfn;
uint32_t sup_layer_count;
@@ -726,9 +731,9 @@ static int create_instance(AVHWDeviceContext *ctx, AVDictionary *opts)
{
int err = 0, debug_mode = 0;
VkResult ret;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
VkApplicationInfo application_info = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = "ffmpeg",
@@ -866,13 +871,13 @@ static int find_device(AVHWDeviceContext *ctx, VulkanDeviceSelection *select)
int err = 0, choice = -1;
uint32_t num;
VkResult ret;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkPhysicalDevice *devices = NULL;
VkPhysicalDeviceIDProperties *idp = NULL;
VkPhysicalDeviceProperties2 *prop = NULL;
VkPhysicalDeviceDrmPropertiesEXT *drm_prop = NULL;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
ret = vk->EnumeratePhysicalDevices(hwctx->inst, &num, NULL);
if (ret != VK_SUCCESS || !num) {
@@ -1046,9 +1051,9 @@ static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
uint32_t num;
float *weights;
VkQueueFamilyProperties *qf = NULL;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
int graph_index, comp_index, tx_index, enc_index, dec_index;
/* First get the number of queue families */
@@ -1182,9 +1187,9 @@ static int setup_queue_families(AVHWDeviceContext *ctx, VkDeviceCreateInfo *cd)
*/
static void vulkan_device_free(AVHWDeviceContext *ctx)
{
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
if (hwctx->act_dev)
vk->DestroyDevice(hwctx->act_dev, hwctx->alloc);
@@ -1205,7 +1210,7 @@ static void vulkan_device_free(AVHWDeviceContext *ctx)
static void vulkan_device_uninit(AVHWDeviceContext *ctx)
{
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
for (uint32_t i = 0; i < p->nb_tot_qfs; i++) {
pthread_mutex_destroy(p->qf_mutex[i]);
@@ -1224,9 +1229,9 @@ static int vulkan_device_create_internal(AVHWDeviceContext *ctx,
int err = 0;
VkResult ret;
AVDictionaryEntry *opt_d;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
/*
* VkPhysicalDeviceVulkan12Features has a timelineSemaphore field, but
@@ -1401,13 +1406,13 @@ end:
static void lock_queue(AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
{
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
pthread_mutex_lock(&p->qf_mutex[queue_family][index]);
}
static void unlock_queue(AVHWDeviceContext *ctx, uint32_t queue_family, uint32_t index)
{
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
pthread_mutex_unlock(&p->qf_mutex[queue_family][index]);
}
@@ -1415,8 +1420,8 @@ static int vulkan_device_init(AVHWDeviceContext *ctx)
{
int err;
uint32_t qf_num;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkQueueFamilyProperties *qf;
int graph_index, comp_index, tx_index, enc_index, dec_index;
@@ -1666,7 +1671,7 @@ static int vulkan_frames_get_constraints(AVHWDeviceContext *ctx,
AVHWFramesConstraints *constraints)
{
int count = 0;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
for (enum AVPixelFormat i = 0; i < nb_vk_formats_list; i++) {
count += vkfmt_from_pixfmt2(ctx, vk_formats_list[i].pixfmt,
@@ -1713,9 +1718,9 @@ static int alloc_mem(AVHWDeviceContext *ctx, VkMemoryRequirements *req,
{
VkResult ret;
int index = -1;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *dev_hwctx = ctx->hwctx;
+ AVVulkanDeviceContext *dev_hwctx = &p->p;
VkMemoryAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = alloc_extension,
@@ -1803,8 +1808,8 @@ static void vulkan_free_internal(AVVkFrame *f)
static void vulkan_frame_free(AVHWFramesContext *hwfc, AVVkFrame *f)
{
- AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
int nb_images = ff_vk_count_images(f);
@@ -1840,12 +1845,11 @@ static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f,
int img_cnt = 0, err;
VkResult ret;
AVHWDeviceContext *ctx = hwfc->device_ctx;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } };
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
-
while (f->img[img_cnt]) {
int use_ded_mem;
VkImageMemoryRequirementsInfo2 req_desc = {
@@ -1916,7 +1920,7 @@ static int prepare_frame(AVHWFramesContext *hwfc, FFVkExecPool *ectx,
AVVkFrame *frame, enum PrepMode pmode)
{
int err;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
int nb_img_bar = 0;
@@ -2020,9 +2024,9 @@ static int create_frame(AVHWFramesContext *hwfc, AVVkFrame **frame,
VkResult ret;
AVVulkanFramesContext *hwfc_vk = hwfc->hwctx;
AVHWDeviceContext *ctx = hwfc->device_ctx;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
VkExportSemaphoreCreateInfo ext_sem_info = {
.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO,
@@ -2126,8 +2130,8 @@ static void try_export_flags(AVHWFramesContext *hwfc,
{
VkResult ret;
AVVulkanFramesContext *hwctx = hwfc->hwctx;
- AVVulkanDeviceContext *dev_hwctx = hwfc->device_ctx->hwctx;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
+ AVVulkanDeviceContext *dev_hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
const VkImageDrmFormatModifierListCreateInfoEXT *drm_mod_info =
@@ -2188,7 +2192,7 @@ static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
AVBufferRef *avbuf = NULL;
AVHWFramesContext *hwfc = opaque;
AVVulkanFramesContext *hwctx = hwfc->hwctx;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv;
VkExternalMemoryHandleTypeFlags e = 0x0;
VkExportMemoryAllocateInfo eminfo[AV_NUM_DATA_POINTERS];
@@ -2259,7 +2263,7 @@ static void unlock_frame(AVHWFramesContext *fc, AVVkFrame *vkf)
static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
{
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv;
if (fp->modifier_info) {
@@ -2279,7 +2283,7 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
AVVkFrame *f;
AVVulkanFramesContext *hwctx = hwfc->hwctx;
VulkanFramesPriv *fp = hwfc->internal->priv;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VkImageUsageFlagBits supported_usage;
const struct FFVkFormatEntry *fmt;
int disable_multiplane = p->disable_multiplane ||
@@ -2486,8 +2490,8 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
AVVkFrame *f;
int bind_counts = 0;
AVHWDeviceContext *ctx = hwfc->device_ctx;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VulkanFramesPriv *fp = hwfc->internal->priv;
const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0];
@@ -2831,10 +2835,10 @@ static int vulkan_export_to_cuda(AVHWFramesContext *hwfc,
AVVkFrame *dst_f;
AVVkFrameInternal *dst_int;
AVHWDeviceContext *ctx = hwfc->device_ctx;
- AVVulkanDeviceContext *hwctx = ctx->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
- VulkanDevicePriv *p = ctx->internal->priv;
+ VulkanDevicePriv *p = ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
AVHWFramesContext *cuda_fc = (AVHWFramesContext*)cuda_hwfc->data;
@@ -3087,7 +3091,7 @@ fail:
static int vulkan_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src, int flags)
{
- av_unused VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ av_unused VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
switch (src->format) {
#if CONFIG_LIBDRM
@@ -3139,10 +3143,10 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
int err = 0;
VkResult ret;
AVVkFrame *f = (AVVkFrame *)src->data[0];
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VulkanFramesPriv *fp = hwfc->internal->priv;
- AVVulkanDeviceContext *hwctx = hwfc->device_ctx->hwctx;
AVVulkanFramesContext *hwfctx = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
VkImageDrmFormatModifierPropertiesEXT drm_mod = {
@@ -3274,7 +3278,7 @@ fail:
static int vulkan_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src, int flags)
{
- av_unused VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ av_unused VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
switch (dst->format) {
#if CONFIG_LIBDRM
@@ -3314,7 +3318,7 @@ static int transfer_image_buf(AVHWFramesContext *hwfc, AVFrame *f,
int err;
AVVkFrame *frame = (AVVkFrame *)f->data[0];
VulkanFramesPriv *fp = hwfc->internal->priv;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
int nb_img_bar = 0;
@@ -3406,8 +3410,8 @@ static int vulkan_transfer_data(AVHWFramesContext *hwfc, const AVFrame *vkf,
int err = 0;
VkResult ret;
AVHWDeviceContext *dev_ctx = hwfc->device_ctx;
- AVVulkanDeviceContext *hwctx = dev_ctx->hwctx;
- VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ VulkanDevicePriv *p = dev_ctx->hwctx;
+ AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
AVFrame tmp;
@@ -3546,7 +3550,7 @@ end:
static int vulkan_transfer_data_to(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src)
{
- av_unused VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ av_unused VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
switch (src->format) {
#if CONFIG_CUDA
@@ -3663,7 +3667,7 @@ fail:
static int vulkan_transfer_data_from(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src)
{
- av_unused VulkanDevicePriv *p = hwfc->device_ctx->internal->priv;
+ av_unused VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
switch (dst->format) {
#if CONFIG_CUDA
@@ -3718,8 +3722,7 @@ const HWContextType ff_hwcontext_type_vulkan = {
.type = AV_HWDEVICE_TYPE_VULKAN,
.name = "Vulkan",
- .device_hwctx_size = sizeof(AVVulkanDeviceContext),
- .device_priv_size = sizeof(VulkanDevicePriv),
+ .device_hwctx_size = sizeof(VulkanDevicePriv),
.frames_hwctx_size = sizeof(AVVulkanFramesContext),
.frames_priv_size = sizeof(VulkanFramesPriv),
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 05/23] avutil/hwcontext_qsv: Allocate public and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (2 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 04/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 06/23] avutil/hwcontext_vdpau: " Andreas Rheinhardt
` (19 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to QSVDeviceContext as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_qsv.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index a67552b5ac..99d974f25f 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -70,6 +70,11 @@ typedef struct QSVDevicePriv {
} QSVDevicePriv;
typedef struct QSVDeviceContext {
+ /**
+ * The public AVQSVDeviceContext. See hwcontext_qsv.h for it.
+ */
+ AVQSVDeviceContext p;
+
mfxHDL handle;
mfxHandleType handle_type;
mfxVersion ver;
@@ -268,8 +273,8 @@ static int qsv_fill_border(AVFrame *dst, const AVFrame *src)
static int qsv_device_init(AVHWDeviceContext *ctx)
{
- AVQSVDeviceContext *hwctx = ctx->hwctx;
- QSVDeviceContext *s = ctx->internal->priv;
+ QSVDeviceContext *s = ctx->hwctx;
+ AVQSVDeviceContext *hwctx = &s->p;
int hw_handle_supported = 0;
mfxHandleType handle_type;
enum AVHWDeviceType device_type;
@@ -378,7 +383,7 @@ static int qsv_init_child_ctx(AVHWFramesContext *ctx)
{
AVQSVFramesContext *hwctx = ctx->hwctx;
QSVFramesContext *s = ctx->internal->priv;
- QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+ QSVDeviceContext *device_priv = ctx->device_ctx->hwctx;
AVBufferRef *child_device_ref = NULL;
AVBufferRef *child_frames_ref = NULL;
@@ -1108,7 +1113,8 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
mfxSession *session, int upload)
{
AVQSVFramesContext *frames_hwctx = ctx->hwctx;
- QSVDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+ QSVDeviceContext *device_priv = ctx->device_ctx->hwctx;
+ AVQSVDeviceContext *hwctx = &device_priv->p;
int opaque = 0;
mfxFrameAllocator frame_allocator = {
@@ -1123,7 +1129,6 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
mfxVideoParam par;
mfxStatus err;
int ret = AVERROR_UNKNOWN;
- AVQSVDeviceContext *hwctx = ctx->device_ctx->hwctx;
/* hwctx->loader is non-NULL for oneVPL user and NULL for non-oneVPL user */
void **loader = &hwctx->loader;
@@ -2246,8 +2251,7 @@ const HWContextType ff_hwcontext_type_qsv = {
.type = AV_HWDEVICE_TYPE_QSV,
.name = "QSV",
- .device_hwctx_size = sizeof(AVQSVDeviceContext),
- .device_priv_size = sizeof(QSVDeviceContext),
+ .device_hwctx_size = sizeof(QSVDeviceContext),
.frames_hwctx_size = sizeof(AVQSVFramesContext),
.frames_priv_size = sizeof(QSVFramesContext),
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 06/23] avutil/hwcontext_vdpau: Allocate public and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (3 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 05/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 07/23] avutil/hwcontext_opencl: Allocate pub " Andreas Rheinhardt
` (18 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VDPAUDeviceContext as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vdpau.c | 28 ++++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
index 5b78e95529..016300db1e 100644
--- a/libavutil/hwcontext_vdpau.c
+++ b/libavutil/hwcontext_vdpau.c
@@ -83,6 +83,11 @@ static const struct {
};
typedef struct VDPAUDeviceContext {
+ /**
+ * The public AVVDPAUDeviceContext. See hwcontext_vdpau.h for it.
+ */
+ AVVDPAUDeviceContext p;
+
VdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities *get_transfer_caps;
VdpVideoSurfaceGetBitsYCbCr *get_data;
VdpVideoSurfacePutBitsYCbCr *put_data;
@@ -115,8 +120,8 @@ static int count_pixfmts(const VDPAUPixFmtMap *map)
static int vdpau_init_pixmfts(AVHWDeviceContext *ctx)
{
- AVVDPAUDeviceContext *hwctx = ctx->hwctx;
- VDPAUDeviceContext *priv = ctx->internal->priv;
+ VDPAUDeviceContext *priv = ctx->hwctx;
+ AVVDPAUDeviceContext *hwctx = &priv->p;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(priv->pix_fmts); i++) {
@@ -157,8 +162,8 @@ do {
static int vdpau_device_init(AVHWDeviceContext *ctx)
{
- AVVDPAUDeviceContext *hwctx = ctx->hwctx;
- VDPAUDeviceContext *priv = ctx->internal->priv;
+ VDPAUDeviceContext *priv = ctx->hwctx;
+ AVVDPAUDeviceContext *hwctx = &priv->p;
VdpStatus err;
int ret;
@@ -180,7 +185,7 @@ static int vdpau_device_init(AVHWDeviceContext *ctx)
static void vdpau_device_uninit(AVHWDeviceContext *ctx)
{
- VDPAUDeviceContext *priv = ctx->internal->priv;
+ VDPAUDeviceContext *priv = ctx->hwctx;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(priv->pix_fmts); i++)
@@ -191,7 +196,7 @@ static int vdpau_frames_get_constraints(AVHWDeviceContext *ctx,
const void *hwconfig,
AVHWFramesConstraints *constraints)
{
- VDPAUDeviceContext *priv = ctx->internal->priv;
+ VDPAUDeviceContext *priv = ctx->hwctx;
int nb_sw_formats = 0;
int i;
@@ -219,7 +224,7 @@ static int vdpau_frames_get_constraints(AVHWDeviceContext *ctx,
static void vdpau_buffer_free(void *opaque, uint8_t *data)
{
AVHWFramesContext *ctx = opaque;
- VDPAUDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+ VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)data;
device_priv->surf_destroy(surf);
@@ -229,8 +234,8 @@ static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = opaque;
VDPAUFramesContext *priv = ctx->internal->priv;
- AVVDPAUDeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- VDPAUDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+ VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
+ AVVDPAUDeviceContext *device_hwctx = &device_priv->p;
AVBufferRef *ret;
VdpVideoSurface surf;
@@ -255,7 +260,7 @@ static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
static int vdpau_frames_init(AVHWFramesContext *ctx)
{
- VDPAUDeviceContext *device_priv = ctx->device_ctx->internal->priv;
+ VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
VDPAUFramesContext *priv = ctx->internal->priv;
int i;
@@ -508,8 +513,7 @@ const HWContextType ff_hwcontext_type_vdpau = {
.type = AV_HWDEVICE_TYPE_VDPAU,
.name = "VDPAU",
- .device_hwctx_size = sizeof(AVVDPAUDeviceContext),
- .device_priv_size = sizeof(VDPAUDeviceContext),
+ .device_hwctx_size = sizeof(VDPAUDeviceContext),
.frames_priv_size = sizeof(VDPAUFramesContext),
#if HAVE_VDPAU_X11
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 07/23] avutil/hwcontext_opencl: Allocate pub and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (4 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 06/23] avutil/hwcontext_vdpau: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 08/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
` (17 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to OpenCLDeviceContext as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_opencl.c | 50 +++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 23 deletions(-)
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index c1764ed098..54c050ab40 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -80,6 +80,11 @@ extern int ff_qsv_get_surface_base_handle(mfxFrameSurface1 *surf,
typedef struct OpenCLDeviceContext {
+ /**
+ * The public AVOpenCLDeviceContext. See hwcontext_opencl.h for it.
+ */
+ AVOpenCLDeviceContext p;
+
// Default command queue to use for transfer/mapping operations on
// the device. If the user supplies one, this is a reference to it.
// Otherwise, it is newly-created.
@@ -276,8 +281,8 @@ static int opencl_check_device_extension(cl_device_id device_id,
static av_unused int opencl_check_extension(AVHWDeviceContext *hwdev,
const char *name)
{
- AVOpenCLDeviceContext *hwctx = hwdev->hwctx;
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
if (opencl_check_platform_extension(priv->platform_id, name)) {
av_log(hwdev, AV_LOG_DEBUG,
@@ -658,8 +663,8 @@ static int opencl_device_create(AVHWDeviceContext *hwdev, const char *device,
static int opencl_device_init(AVHWDeviceContext *hwdev)
{
- AVOpenCLDeviceContext *hwctx = hwdev->hwctx;
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
cl_int cle;
if (hwctx->command_queue) {
@@ -894,7 +899,7 @@ static int opencl_device_init(AVHWDeviceContext *hwdev)
static void opencl_device_uninit(AVHWDeviceContext *hwdev)
{
- OpenCLDeviceContext *priv = hwdev->internal->priv;
+ OpenCLDeviceContext *priv = hwdev->hwctx;
cl_int cle;
if (priv->command_queue) {
@@ -1685,7 +1690,7 @@ fail:
static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
{
AVOpenCLFramesContext *hwctx = hwfc->hwctx;
- OpenCLDeviceContext *devpriv = hwfc->device_ctx->internal->priv;
+ OpenCLDeviceContext *devpriv = hwfc->device_ctx->hwctx;
OpenCLFramesContext *priv = hwfc->internal->priv;
cl_int cle;
@@ -2079,8 +2084,8 @@ static int opencl_map_from_drm_beignet(AVHWFramesContext *dst_fc,
AVFrame *dst, const AVFrame *src,
int flags)
{
- AVOpenCLDeviceContext *hwctx = dst_fc->device_ctx->hwctx;
- OpenCLDeviceContext *priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *hwctx = &priv->p;
DRMBeignetToOpenCLMapping *mapping;
const AVDRMFrameDescriptor *desc;
cl_int cle;
@@ -2211,7 +2216,7 @@ static void opencl_unmap_from_qsv(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2246,8 +2251,8 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
{
AVHWFramesContext *src_fc =
(AVHWFramesContext*)src->hw_frames_ctx->data;
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
VASurfaceID va_surface;
@@ -2345,7 +2350,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2370,7 +2375,7 @@ static int opencl_map_from_dxva2(AVHWFramesContext *dst_fc, AVFrame *dst,
AVHWFramesContext *src_fc =
(AVHWFramesContext*)src->hw_frames_ctx->data;
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
cl_event event;
@@ -2431,9 +2436,9 @@ fail:
static int opencl_frames_derive_from_dxva2(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_mem_flags cl_flags;
cl_int cle;
@@ -2510,7 +2515,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
HWMapDescriptor *hwmap)
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_event event;
cl_int cle;
@@ -2529,7 +2534,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
static int opencl_map_from_d3d11(AVHWFramesContext *dst_fc, AVFrame *dst,
const AVFrame *src, int flags)
{
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
AVOpenCLFrameDescriptor *desc;
cl_event event;
@@ -2587,9 +2592,9 @@ fail:
static int opencl_frames_derive_from_d3d11(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- AVOpenCLDeviceContext *dst_dev = dst_fc->device_ctx->hwctx;
AVD3D11VAFramesContext *src_hwctx = src_fc->hwctx;
- OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
+ OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
+ AVOpenCLDeviceContext *dst_dev = &device_priv->p;
OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
cl_mem_flags cl_flags;
cl_int cle;
@@ -2830,7 +2835,7 @@ static int opencl_map_from(AVHWFramesContext *hwfc, AVFrame *dst,
static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src, int flags)
{
- av_unused OpenCLDeviceContext *priv = hwfc->device_ctx->internal->priv;
+ av_unused OpenCLDeviceContext *priv = hwfc->device_ctx->hwctx;
av_assert0(dst->format == AV_PIX_FMT_OPENCL);
switch (src->format) {
#if HAVE_OPENCL_DRM_BEIGNET
@@ -2871,7 +2876,7 @@ static int opencl_map_to(AVHWFramesContext *hwfc, AVFrame *dst,
static int opencl_frames_derive_to(AVHWFramesContext *dst_fc,
AVHWFramesContext *src_fc, int flags)
{
- av_unused OpenCLDeviceContext *priv = dst_fc->device_ctx->internal->priv;
+ av_unused OpenCLDeviceContext *priv = dst_fc->device_ctx->hwctx;
switch (src_fc->device_ctx->type) {
#if HAVE_OPENCL_DRM_BEIGNET
case AV_HWDEVICE_TYPE_DRM:
@@ -2932,8 +2937,7 @@ const HWContextType ff_hwcontext_type_opencl = {
.type = AV_HWDEVICE_TYPE_OPENCL,
.name = "OpenCL",
- .device_hwctx_size = sizeof(AVOpenCLDeviceContext),
- .device_priv_size = sizeof(OpenCLDeviceContext),
+ .device_hwctx_size = sizeof(OpenCLDeviceContext),
.frames_hwctx_size = sizeof(AVOpenCLFramesContext),
.frames_priv_size = sizeof(OpenCLFramesContext),
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 08/23] avutil/hwcontext_d3d12va: Allocate pub and priv device hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (5 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 07/23] avutil/hwcontext_opencl: Allocate pub " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 09/23] avutil/hwcontext: Remove unused AVHWDeviceInternal.priv Andreas Rheinhardt
` (16 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to D3D12VADevicePriv as one no longer has to
go through AVHWDeviceInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_d3d12va.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 3acd5ac43a..6b4cd22899 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -46,6 +46,10 @@ typedef struct D3D12VAFramesContext {
} D3D12VAFramesContext;
typedef struct D3D12VADevicePriv {
+ /**
+ * The public AVD3D12VADeviceContext. See hwcontext_d3d12va.h for it.
+ */
+ AVD3D12VADeviceContext p;
HANDLE d3d12lib;
HANDLE dxgilib;
PFN_CREATE_DXGI_FACTORY2 create_dxgi_factory2;
@@ -526,7 +530,7 @@ fail:
static int d3d12va_load_functions(AVHWDeviceContext *hwdev)
{
- D3D12VADevicePriv *priv = hwdev->internal->priv;
+ D3D12VADevicePriv *priv = hwdev->hwctx;
#if !HAVE_UWP
priv->d3d12lib = dlopen("d3d12.dll", 0);
@@ -558,8 +562,8 @@ fail:
static void d3d12va_device_free(AVHWDeviceContext *hwdev)
{
- AVD3D12VADeviceContext *ctx = hwdev->hwctx;
- D3D12VADevicePriv *priv = hwdev->internal->priv;
+ D3D12VADevicePriv *priv = hwdev->hwctx;
+ AVD3D12VADeviceContext *ctx = &priv->p;
D3D12_OBJECT_RELEASE(ctx->device);
@@ -609,8 +613,8 @@ static void d3d12va_device_uninit(AVHWDeviceContext *hwdev)
static int d3d12va_device_create(AVHWDeviceContext *hwdev, const char *device,
AVDictionary *opts, int flags)
{
- AVD3D12VADeviceContext *ctx = hwdev->hwctx;
- D3D12VADevicePriv *priv = hwdev->internal->priv;
+ D3D12VADevicePriv *priv = hwdev->hwctx;
+ AVD3D12VADeviceContext *ctx = &priv->p;
HRESULT hr;
UINT create_flags = 0;
@@ -670,8 +674,7 @@ const HWContextType ff_hwcontext_type_d3d12va = {
.type = AV_HWDEVICE_TYPE_D3D12VA,
.name = "D3D12VA",
- .device_hwctx_size = sizeof(AVD3D12VADeviceContext),
- .device_priv_size = sizeof(D3D12VADevicePriv),
+ .device_hwctx_size = sizeof(D3D12VADevicePriv),
.frames_hwctx_size = sizeof(AVD3D12VAFramesContext),
.frames_priv_size = sizeof(D3D12VAFramesContext),
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 09/23] avutil/hwcontext: Remove unused AVHWDeviceInternal.priv
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (6 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 08/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 10/23] avutil/hwcontext: Allocate AVHWDevCtx jointly with its internals Andreas Rheinhardt
` (15 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is no longer used by any hwcontext, as they all allocate
their private data together with their public data and access
it via AVHWDeviceContext.hwctx.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.c | 9 ---------
libavutil/hwcontext_internal.h | 6 ------
2 files changed, 15 deletions(-)
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 63fc1a6a22..02e9668c31 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -139,7 +139,6 @@ static void hwdevice_ctx_free(void *opaque, uint8_t *data)
av_buffer_unref(&ctx->internal->source_device);
av_freep(&ctx->hwctx);
- av_freep(&ctx->internal->priv);
av_freep(&ctx->internal);
av_freep(&ctx);
}
@@ -168,12 +167,6 @@ AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
if (!ctx->internal)
goto fail;
- if (hw_type->device_priv_size) {
- ctx->internal->priv = av_mallocz(hw_type->device_priv_size);
- if (!ctx->internal->priv)
- goto fail;
- }
-
if (hw_type->device_hwctx_size) {
ctx->hwctx = av_mallocz(hw_type->device_hwctx_size);
if (!ctx->hwctx)
@@ -194,8 +187,6 @@ AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
return buf;
fail:
- if (ctx->internal)
- av_freep(&ctx->internal->priv);
av_freep(&ctx->internal);
av_freep(&ctx->hwctx);
av_freep(&ctx);
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 4df516ee6a..374c6dde2f 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -41,11 +41,6 @@ typedef struct HWContextType {
* i.e. AVHWDeviceContext.hwctx
*/
size_t device_hwctx_size;
- /**
- * size of the private data, i.e.
- * AVHWDeviceInternal.priv
- */
- size_t device_priv_size;
/**
* Size of the hardware-specific device configuration.
@@ -102,7 +97,6 @@ typedef struct HWContextType {
struct AVHWDeviceInternal {
const HWContextType *hw_type;
- void *priv;
/**
* For a derived device, a reference to the original device
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 10/23] avutil/hwcontext: Allocate AVHWDevCtx jointly with its internals
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (7 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 09/23] avutil/hwcontext: Remove unused AVHWDeviceInternal.priv Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 11/23] avutil/hwcontext_vaapi: Allocate pub and priv frames hwctx together Andreas Rheinhardt
` (14 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of these structures coincide.
It has the advantage of allowing to remove the AVHWDeviceInternal
from the public header; given that AVHWDeviceInternal.priv is no more,
all accesses to it happen in hwcontext.c, so that this commit moves
the joint structure there.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.c | 102 ++++++++++++++++++---------------
libavutil/hwcontext.h | 8 ---
libavutil/hwcontext_internal.h | 10 ----
3 files changed, 57 insertions(+), 63 deletions(-)
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 02e9668c31..c962c19f3e 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -84,6 +84,21 @@ static const char *const hw_type_names[] = {
[AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
};
+typedef struct FFHWDeviceContext {
+ /**
+ * The public AVHWDeviceContext. See hwcontext.h for it.
+ */
+ AVHWDeviceContext p;
+
+ const HWContextType *hw_type;
+
+ /**
+ * For a derived device, a reference to the original device
+ * context it was derived from.
+ */
+ AVBufferRef *source_device;
+} FFHWDeviceContext;
+
enum AVHWDeviceType av_hwdevice_find_type_by_name(const char *name)
{
int type;
@@ -126,25 +141,26 @@ static const AVClass hwdevice_ctx_class = {
static void hwdevice_ctx_free(void *opaque, uint8_t *data)
{
- AVHWDeviceContext *ctx = (AVHWDeviceContext*)data;
+ FFHWDeviceContext *ctxi = (FFHWDeviceContext*)data;
+ AVHWDeviceContext *ctx = &ctxi->p;
/* uninit might still want access the hw context and the user
* free() callback might destroy it, so uninit has to be called first */
- if (ctx->internal->hw_type->device_uninit)
- ctx->internal->hw_type->device_uninit(ctx);
+ if (ctxi->hw_type->device_uninit)
+ ctxi->hw_type->device_uninit(ctx);
if (ctx->free)
ctx->free(ctx);
- av_buffer_unref(&ctx->internal->source_device);
+ av_buffer_unref(&ctxi->source_device);
av_freep(&ctx->hwctx);
- av_freep(&ctx->internal);
av_freep(&ctx);
}
AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
{
+ FFHWDeviceContext *ctxi;
AVHWDeviceContext *ctx;
AVBufferRef *buf;
const HWContextType *hw_type = NULL;
@@ -159,13 +175,10 @@ AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
if (!hw_type)
return NULL;
- ctx = av_mallocz(sizeof(*ctx));
- if (!ctx)
+ ctxi = av_mallocz(sizeof(*ctxi));
+ if (!ctxi)
return NULL;
-
- ctx->internal = av_mallocz(sizeof(*ctx->internal));
- if (!ctx->internal)
- goto fail;
+ ctx = &ctxi->p;
if (hw_type->device_hwctx_size) {
ctx->hwctx = av_mallocz(hw_type->device_hwctx_size);
@@ -182,12 +195,11 @@ AVBufferRef *av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
ctx->type = type;
ctx->av_class = &hwdevice_ctx_class;
- ctx->internal->hw_type = hw_type;
+ ctxi->hw_type = hw_type;
return buf;
fail:
- av_freep(&ctx->internal);
av_freep(&ctx->hwctx);
av_freep(&ctx);
return NULL;
@@ -195,19 +207,20 @@ fail:
int av_hwdevice_ctx_init(AVBufferRef *ref)
{
- AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
+ FFHWDeviceContext *ctxi = (FFHWDeviceContext*)ref->data;
+ AVHWDeviceContext *ctx = &ctxi->p;
int ret;
- if (ctx->internal->hw_type->device_init) {
- ret = ctx->internal->hw_type->device_init(ctx);
+ if (ctxi->hw_type->device_init) {
+ ret = ctxi->hw_type->device_init(ctx);
if (ret < 0)
goto fail;
}
return 0;
fail:
- if (ctx->internal->hw_type->device_uninit)
- ctx->internal->hw_type->device_uninit(ctx);
+ if (ctxi->hw_type->device_uninit)
+ ctxi->hw_type->device_uninit(ctx);
return ret;
}
@@ -242,8 +255,8 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data)
AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
{
- AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)device_ref_in->data;
- const HWContextType *hw_type = device_ctx->internal->hw_type;
+ FFHWDeviceContext *device_ctx = (FFHWDeviceContext*)device_ref_in->data;
+ const HWContextType *hw_type = device_ctx->hw_type;
AVHWFramesContext *ctx;
AVBufferRef *buf, *device_ref = NULL;
@@ -279,7 +292,7 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
ctx->av_class = &hwframe_ctx_class;
ctx->device_ref = device_ref;
- ctx->device_ctx = device_ctx;
+ ctx->device_ctx = &device_ctx->p;
ctx->format = AV_PIX_FMT_NONE;
ctx->sw_format = AV_PIX_FMT_NONE;
@@ -563,8 +576,8 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
void *av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
{
- AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
- const HWContextType *hw_type = ctx->internal->hw_type;
+ FFHWDeviceContext *ctx = (FFHWDeviceContext*)ref->data;
+ const HWContextType *hw_type = ctx->hw_type;
if (hw_type->device_hwconfig_size == 0)
return NULL;
@@ -575,8 +588,8 @@ void *av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
const void *hwconfig)
{
- AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
- const HWContextType *hw_type = ctx->internal->hw_type;
+ FFHWDeviceContext *ctx = (FFHWDeviceContext*)ref->data;
+ const HWContextType *hw_type = ctx->hw_type;
AVHWFramesConstraints *constraints;
if (!hw_type->frames_get_constraints)
@@ -589,7 +602,7 @@ AVHWFramesConstraints *av_hwdevice_get_hwframe_constraints(AVBufferRef *ref,
constraints->min_width = constraints->min_height = 0;
constraints->max_width = constraints->max_height = INT_MAX;
- if (hw_type->frames_get_constraints(ctx, hwconfig, constraints) >= 0) {
+ if (hw_type->frames_get_constraints(&ctx->p, hwconfig, constraints) >= 0) {
return constraints;
} else {
av_hwframe_constraints_free(&constraints);
@@ -610,7 +623,7 @@ int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type,
const char *device, AVDictionary *opts, int flags)
{
AVBufferRef *device_ref = NULL;
- AVHWDeviceContext *device_ctx;
+ FFHWDeviceContext *device_ctx;
int ret = 0;
device_ref = av_hwdevice_ctx_alloc(type);
@@ -618,15 +631,15 @@ int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type,
ret = AVERROR(ENOMEM);
goto fail;
}
- device_ctx = (AVHWDeviceContext*)device_ref->data;
+ device_ctx = (FFHWDeviceContext*)device_ref->data;
- if (!device_ctx->internal->hw_type->device_create) {
+ if (!device_ctx->hw_type->device_create) {
ret = AVERROR(ENOSYS);
goto fail;
}
- ret = device_ctx->internal->hw_type->device_create(device_ctx, device,
- opts, flags);
+ ret = device_ctx->hw_type->device_create(&device_ctx->p, device,
+ opts, flags);
if (ret < 0)
goto fail;
@@ -648,13 +661,13 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
AVDictionary *options, int flags)
{
AVBufferRef *dst_ref = NULL, *tmp_ref;
- AVHWDeviceContext *dst_ctx, *tmp_ctx;
+ FFHWDeviceContext *dst_ctx;
int ret = 0;
tmp_ref = src_ref;
while (tmp_ref) {
- tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
- if (tmp_ctx->type == type) {
+ FFHWDeviceContext *tmp_ctx = (FFHWDeviceContext*)tmp_ref->data;
+ if (tmp_ctx->p.type == type) {
dst_ref = av_buffer_ref(tmp_ref);
if (!dst_ref) {
ret = AVERROR(ENOMEM);
@@ -662,7 +675,7 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
}
goto done;
}
- tmp_ref = tmp_ctx->internal->source_device;
+ tmp_ref = tmp_ctx->source_device;
}
dst_ref = av_hwdevice_ctx_alloc(type);
@@ -670,19 +683,18 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
ret = AVERROR(ENOMEM);
goto fail;
}
- dst_ctx = (AVHWDeviceContext*)dst_ref->data;
+ dst_ctx = (FFHWDeviceContext*)dst_ref->data;
tmp_ref = src_ref;
while (tmp_ref) {
- tmp_ctx = (AVHWDeviceContext*)tmp_ref->data;
- if (dst_ctx->internal->hw_type->device_derive) {
- ret = dst_ctx->internal->hw_type->device_derive(dst_ctx,
- tmp_ctx,
- options,
- flags);
+ FFHWDeviceContext *tmp_ctx = (FFHWDeviceContext*)tmp_ref->data;
+ if (dst_ctx->hw_type->device_derive) {
+ ret = dst_ctx->hw_type->device_derive(&dst_ctx->p,
+ &tmp_ctx->p,
+ options, flags);
if (ret == 0) {
- dst_ctx->internal->source_device = av_buffer_ref(src_ref);
- if (!dst_ctx->internal->source_device) {
+ dst_ctx->source_device = av_buffer_ref(src_ref);
+ if (!dst_ctx->source_device) {
ret = AVERROR(ENOMEM);
goto fail;
}
@@ -694,7 +706,7 @@ int av_hwdevice_ctx_create_derived_opts(AVBufferRef **dst_ref_ptr,
if (ret != AVERROR(ENOSYS))
goto fail;
}
- tmp_ref = tmp_ctx->internal->source_device;
+ tmp_ref = tmp_ctx->source_device;
}
ret = AVERROR(ENOSYS);
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 2b33721a97..d91391294b 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -40,8 +40,6 @@ enum AVHWDeviceType {
AV_HWDEVICE_TYPE_D3D12VA,
};
-typedef struct AVHWDeviceInternal AVHWDeviceInternal;
-
/**
* This struct aggregates all the (hardware/vendor-specific) "high-level" state,
* i.e. state that is not tied to a concrete processing configuration.
@@ -65,12 +63,6 @@ typedef struct AVHWDeviceContext {
*/
const AVClass *av_class;
- /**
- * Private data used internally by libavutil. Must not be accessed in any
- * way by the caller.
- */
- AVHWDeviceInternal *internal;
-
/**
* This field identifies the underlying API used for hardware access.
*
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 374c6dde2f..3745867283 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -95,16 +95,6 @@ typedef struct HWContextType {
AVHWFramesContext *src_ctx, int flags);
} HWContextType;
-struct AVHWDeviceInternal {
- const HWContextType *hw_type;
-
- /**
- * For a derived device, a reference to the original device
- * context it was derived from.
- */
- AVBufferRef *source_device;
-};
-
struct AVHWFramesInternal {
const HWContextType *hw_type;
void *priv;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 11/23] avutil/hwcontext_vaapi: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (8 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 10/23] avutil/hwcontext: Allocate AVHWDevCtx jointly with its internals Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 12/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
` (13 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VAAPIFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vaapi.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 7019769f24..2c75f5f5b1 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -86,6 +86,11 @@ typedef struct VAAPIDeviceContext {
} VAAPIDeviceContext;
typedef struct VAAPIFramesContext {
+ /**
+ * The public AVVAAPIFramesContext. See hwcontext_vaapi.h for it.
+ */
+ AVVAAPIFramesContext p;
+
// Surface attributes set at create time.
VASurfaceAttrib *attributes;
int nb_attributes;
@@ -503,9 +508,9 @@ static void vaapi_buffer_free(void *opaque, uint8_t *data)
static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *hwfc = opaque;
- VAAPIFramesContext *ctx = hwfc->internal->priv;
+ VAAPIFramesContext *ctx = hwfc->hwctx;
+ AVVAAPIFramesContext *avfc = &ctx->p;
AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx;
- AVVAAPIFramesContext *avfc = hwfc->hwctx;
VASurfaceID surface_id;
VAStatus vas;
AVBufferRef *ref;
@@ -546,8 +551,8 @@ static AVBufferRef *vaapi_pool_alloc(void *opaque, size_t size)
static int vaapi_frames_init(AVHWFramesContext *hwfc)
{
- AVVAAPIFramesContext *avfc = hwfc->hwctx;
- VAAPIFramesContext *ctx = hwfc->internal->priv;
+ VAAPIFramesContext *ctx = hwfc->hwctx;
+ AVVAAPIFramesContext *avfc = &ctx->p;
AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx;
const VAAPIFormatDescriptor *desc;
VAImageFormat *expected_format;
@@ -698,8 +703,8 @@ fail:
static void vaapi_frames_uninit(AVHWFramesContext *hwfc)
{
- AVVAAPIFramesContext *avfc = hwfc->hwctx;
- VAAPIFramesContext *ctx = hwfc->internal->priv;
+ VAAPIFramesContext *ctx = hwfc->hwctx;
+ AVVAAPIFramesContext *avfc = &ctx->p;
av_freep(&avfc->surface_ids);
av_freep(&ctx->attributes);
@@ -796,7 +801,7 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc,
AVFrame *dst, const AVFrame *src, int flags)
{
AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx;
- VAAPIFramesContext *ctx = hwfc->internal->priv;
+ VAAPIFramesContext *ctx = hwfc->hwctx;
VASurfaceID surface_id;
const VAAPIFormatDescriptor *desc;
VAImageFormat *image_format;
@@ -1075,7 +1080,7 @@ static int vaapi_map_from_drm(AVHWFramesContext *src_fc, AVFrame *dst,
const AVFrame *src, int flags)
{
#if VA_CHECK_VERSION(1, 1, 0)
- VAAPIFramesContext *src_vafc = src_fc->internal->priv;
+ VAAPIFramesContext *src_vafc = src_fc->hwctx;
int use_prime2;
#else
int k;
@@ -2014,8 +2019,7 @@ const HWContextType ff_hwcontext_type_vaapi = {
.device_hwctx_size = sizeof(VAAPIDeviceContext),
.device_hwconfig_size = sizeof(AVVAAPIHWConfig),
- .frames_hwctx_size = sizeof(AVVAAPIFramesContext),
- .frames_priv_size = sizeof(VAAPIFramesContext),
+ .frames_hwctx_size = sizeof(VAAPIFramesContext),
.device_create = &vaapi_device_create,
.device_derive = &vaapi_device_derive,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 12/23] avutil/hwcontext_vulkan: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (9 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 11/23] avutil/hwcontext_vaapi: Allocate pub and priv frames hwctx together Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 13/23] avutil/hwcontext_videotoolbox: " Andreas Rheinhardt
` (12 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VulkanFramesPriv as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vulkan.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 3d591dedf9..449a6a2fef 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -129,6 +129,11 @@ typedef struct VulkanDevicePriv {
} VulkanDevicePriv;
typedef struct VulkanFramesPriv {
+ /**
+ * The public AVVulkanFramesContext. See hwcontext_vulkan.h for it.
+ */
+ AVVulkanFramesContext p;
+
/* Image conversions */
FFVkExecPool compute_exec;
@@ -2191,9 +2196,9 @@ static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
AVVkFrame *f;
AVBufferRef *avbuf = NULL;
AVHWFramesContext *hwfc = opaque;
- AVVulkanFramesContext *hwctx = hwfc->hwctx;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
+ AVVulkanFramesContext *hwctx = &fp->p;
VkExternalMemoryHandleTypeFlags e = 0x0;
VkExportMemoryAllocateInfo eminfo[AV_NUM_DATA_POINTERS];
@@ -2264,7 +2269,7 @@ static void unlock_frame(AVHWFramesContext *fc, AVVkFrame *vkf)
static void vulkan_frames_uninit(AVHWFramesContext *hwfc)
{
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
if (fp->modifier_info) {
if (fp->modifier_info->pDrmFormatModifiers)
@@ -2281,8 +2286,8 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
{
int err;
AVVkFrame *f;
- AVVulkanFramesContext *hwctx = hwfc->hwctx;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
+ AVVulkanFramesContext *hwctx = &fp->p;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
VkImageUsageFlagBits supported_usage;
const struct FFVkFormatEntry *fmt;
@@ -2493,7 +2498,7 @@ static int vulkan_map_from_drm_frame_desc(AVHWFramesContext *hwfc, AVVkFrame **f
VulkanDevicePriv *p = ctx->hwctx;
AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
const AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)src->data[0];
VkBindImageMemoryInfo bind_info[AV_DRM_MAX_PLANES];
VkBindImagePlaneMemoryInfo plane_info[AV_DRM_MAX_PLANES];
@@ -3004,7 +3009,7 @@ static int vulkan_transfer_data_from_cuda(AVHWFramesContext *hwfc,
CUcontext dummy;
AVVkFrame *dst_f;
AVVkFrameInternal *dst_int;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
@@ -3146,8 +3151,8 @@ static int vulkan_map_to_drm(AVHWFramesContext *hwfc, AVFrame *dst,
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
AVVulkanDeviceContext *hwctx = &p->p;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
- VulkanFramesPriv *fp = hwfc->internal->priv;
- AVVulkanFramesContext *hwfctx = hwfc->hwctx;
+ VulkanFramesPriv *fp = hwfc->hwctx;
+ AVVulkanFramesContext *hwfctx = &fp->p;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
VkImageDrmFormatModifierPropertiesEXT drm_mod = {
.sType = VK_STRUCTURE_TYPE_IMAGE_DRM_FORMAT_MODIFIER_PROPERTIES_EXT,
@@ -3317,7 +3322,7 @@ static int transfer_image_buf(AVHWFramesContext *hwfc, AVFrame *f,
{
int err;
AVVkFrame *frame = (AVVkFrame *)f->data[0];
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
FFVulkanFunctions *vk = &p->vkctx.vkfn;
VkImageMemoryBarrier2 img_bar[AV_NUM_DATA_POINTERS];
@@ -3580,7 +3585,7 @@ static int vulkan_transfer_data_to_cuda(AVHWFramesContext *hwfc, AVFrame *dst,
CUcontext dummy;
AVVkFrame *dst_f;
AVVkFrameInternal *dst_int;
- VulkanFramesPriv *fp = hwfc->internal->priv;
+ VulkanFramesPriv *fp = hwfc->hwctx;
const int planes = av_pix_fmt_count_planes(hwfc->sw_format);
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(hwfc->sw_format);
@@ -3723,8 +3728,7 @@ const HWContextType ff_hwcontext_type_vulkan = {
.name = "Vulkan",
.device_hwctx_size = sizeof(VulkanDevicePriv),
- .frames_hwctx_size = sizeof(AVVulkanFramesContext),
- .frames_priv_size = sizeof(VulkanFramesPriv),
+ .frames_hwctx_size = sizeof(VulkanFramesPriv),
.device_init = &vulkan_device_init,
.device_uninit = &vulkan_device_uninit,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 13/23] avutil/hwcontext_videotoolbox: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (10 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 12/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 14/23] avutil/hwcontext_opencl: " Andreas Rheinhardt
` (11 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to VTFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_videotoolbox.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
index fe469dc161..823cf9a8ee 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -34,6 +34,10 @@
#include "pixdesc.h"
typedef struct VTFramesContext {
+ /**
+ * The public AVVTFramesContext. See hwcontext_videotoolbox.h for it.
+ */
+ AVVTFramesContext p;
CVPixelBufferPoolRef pool;
} VTFramesContext;
@@ -176,12 +180,12 @@ uint32_t av_map_videotoolbox_format_from_pixfmt2(enum AVPixelFormat pix_fmt, boo
static int vt_pool_alloc(AVHWFramesContext *ctx)
{
- VTFramesContext *fctx = ctx->internal->priv;
+ VTFramesContext *fctx = ctx->hwctx;
+ AVVTFramesContext *hw_ctx = &fctx->p;
CVReturn err;
CFNumberRef w, h, pixfmt;
uint32_t cv_pixfmt;
CFMutableDictionaryRef attributes, iosurface_properties;
- AVVTFramesContext *hw_ctx = ctx->hwctx;
attributes = CFDictionaryCreateMutable(
NULL,
@@ -237,7 +241,7 @@ static AVBufferRef *vt_pool_alloc_buffer(void *opaque, size_t size)
AVBufferRef *buf;
CVReturn err;
AVHWFramesContext *ctx = opaque;
- VTFramesContext *fctx = ctx->internal->priv;
+ VTFramesContext *fctx = ctx->hwctx;
err = CVPixelBufferPoolCreatePixelBuffer(
NULL,
@@ -260,7 +264,7 @@ static AVBufferRef *vt_pool_alloc_buffer(void *opaque, size_t size)
static void vt_frames_uninit(AVHWFramesContext *ctx)
{
- VTFramesContext *fctx = ctx->internal->priv;
+ VTFramesContext *fctx = ctx->hwctx;
if (fctx->pool) {
CVPixelBufferPoolRelease(fctx->pool);
fctx->pool = NULL;
@@ -763,10 +767,9 @@ const HWContextType ff_hwcontext_type_videotoolbox = {
.type = AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
.name = "videotoolbox",
- .frames_priv_size = sizeof(VTFramesContext),
+ .frames_hwctx_size = sizeof(VTFramesContext),
.device_create = vt_device_create,
- .frames_hwctx_size = sizeof(AVVTFramesContext),
.frames_init = vt_frames_init,
.frames_get_buffer = vt_get_buffer,
.frames_get_constraints = vt_frames_get_constraints,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 14/23] avutil/hwcontext_opencl: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (11 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 13/23] avutil/hwcontext_videotoolbox: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 15/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
` (10 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to OpenCLFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_opencl.c | 38 ++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 17 deletions(-)
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index 54c050ab40..c5af1aec74 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -138,6 +138,11 @@ typedef struct OpenCLDeviceContext {
} OpenCLDeviceContext;
typedef struct OpenCLFramesContext {
+ /**
+ * The public AVOpenCLFramesContext. See hwcontext_opencl.h for it.
+ */
+ AVOpenCLFramesContext p;
+
// Command queue used for transfer/mapping operations on this frames
// context. If the user supplies one, this is a reference to it.
// Otherwise, it is a reference to the default command queue for the
@@ -1689,9 +1694,9 @@ fail:
static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
{
- AVOpenCLFramesContext *hwctx = hwfc->hwctx;
+ OpenCLFramesContext *priv = hwfc->hwctx;
+ AVOpenCLFramesContext *hwctx = &priv->p;
OpenCLDeviceContext *devpriv = hwfc->device_ctx->hwctx;
- OpenCLFramesContext *priv = hwfc->internal->priv;
cl_int cle;
priv->command_queue = hwctx->command_queue ? hwctx->command_queue
@@ -1721,7 +1726,7 @@ static int opencl_frames_init(AVHWFramesContext *hwfc)
static void opencl_frames_uninit(AVHWFramesContext *hwfc)
{
- OpenCLFramesContext *priv = hwfc->internal->priv;
+ OpenCLFramesContext *priv = hwfc->hwctx;
cl_int cle;
#if HAVE_OPENCL_DXVA2 || HAVE_OPENCL_D3D11
@@ -1815,7 +1820,7 @@ static int opencl_wait_events(AVHWFramesContext *hwfc,
static int opencl_transfer_data_from(AVHWFramesContext *hwfc,
AVFrame *dst, const AVFrame *src)
{
- OpenCLFramesContext *priv = hwfc->internal->priv;
+ OpenCLFramesContext *priv = hwfc->hwctx;
cl_image_format image_format;
cl_image_desc image_desc;
cl_int cle;
@@ -1870,7 +1875,7 @@ static int opencl_transfer_data_from(AVHWFramesContext *hwfc,
static int opencl_transfer_data_to(AVHWFramesContext *hwfc,
AVFrame *dst, const AVFrame *src)
{
- OpenCLFramesContext *priv = hwfc->internal->priv;
+ OpenCLFramesContext *priv = hwfc->hwctx;
cl_image_format image_format;
cl_image_desc image_desc;
cl_int cle;
@@ -1932,7 +1937,7 @@ typedef struct OpenCLMapping {
static void opencl_unmap_frame(AVHWFramesContext *hwfc,
HWMapDescriptor *hwmap)
{
- OpenCLFramesContext *priv = hwfc->internal->priv;
+ OpenCLFramesContext *priv = hwfc->hwctx;
OpenCLMapping *map = hwmap->priv;
cl_event events[AV_NUM_DATA_POINTERS];
int p, e;
@@ -1961,7 +1966,7 @@ static void opencl_unmap_frame(AVHWFramesContext *hwfc,
static int opencl_map_frame(AVHWFramesContext *hwfc, AVFrame *dst,
const AVFrame *src, int flags)
{
- OpenCLFramesContext *priv = hwfc->internal->priv;
+ OpenCLFramesContext *priv = hwfc->hwctx;
cl_map_flags map_flags;
cl_image_format image_format;
cl_image_desc image_desc;
@@ -2217,7 +2222,7 @@ static void opencl_unmap_from_qsv(AVHWFramesContext *dst_fc,
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
cl_event event;
cl_int cle;
int p;
@@ -2253,7 +2258,7 @@ static int opencl_map_from_qsv(AVHWFramesContext *dst_fc, AVFrame *dst,
(AVHWFramesContext*)src->hw_frames_ctx->data;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
AVOpenCLDeviceContext *dst_dev = &device_priv->p;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
AVOpenCLFrameDescriptor *desc;
VASurfaceID va_surface;
cl_mem_flags cl_flags;
@@ -2351,7 +2356,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc,
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
cl_event event;
cl_int cle;
@@ -2376,7 +2381,7 @@ static int opencl_map_from_dxva2(AVHWFramesContext *dst_fc, AVFrame *dst,
(AVHWFramesContext*)src->hw_frames_ctx->data;
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
AVOpenCLFrameDescriptor *desc;
cl_event event;
cl_int cle;
@@ -2439,7 +2444,7 @@ static int opencl_frames_derive_from_dxva2(AVHWFramesContext *dst_fc,
AVDXVA2FramesContext *src_hwctx = src_fc->hwctx;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
AVOpenCLDeviceContext *dst_dev = &device_priv->p;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
cl_mem_flags cl_flags;
cl_int cle;
int err, i, p, nb_planes;
@@ -2516,7 +2521,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
{
AVOpenCLFrameDescriptor *desc = hwmap->priv;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
cl_event event;
cl_int cle;
@@ -2535,7 +2540,7 @@ static int opencl_map_from_d3d11(AVHWFramesContext *dst_fc, AVFrame *dst,
const AVFrame *src, int flags)
{
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
AVOpenCLFrameDescriptor *desc;
cl_event event;
cl_int cle;
@@ -2595,7 +2600,7 @@ static int opencl_frames_derive_from_d3d11(AVHWFramesContext *dst_fc,
AVD3D11VAFramesContext *src_hwctx = src_fc->hwctx;
OpenCLDeviceContext *device_priv = dst_fc->device_ctx->hwctx;
AVOpenCLDeviceContext *dst_dev = &device_priv->p;
- OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
+ OpenCLFramesContext *frames_priv = dst_fc->hwctx;
cl_mem_flags cl_flags;
cl_int cle;
int err, i, p, nb_planes;
@@ -2938,8 +2943,7 @@ const HWContextType ff_hwcontext_type_opencl = {
.name = "OpenCL",
.device_hwctx_size = sizeof(OpenCLDeviceContext),
- .frames_hwctx_size = sizeof(AVOpenCLFramesContext),
- .frames_priv_size = sizeof(OpenCLFramesContext),
+ .frames_hwctx_size = sizeof(OpenCLFramesContext),
.device_create = &opencl_device_create,
.device_derive = &opencl_device_derive,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 15/23] avutil/hwcontext_qsv: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (12 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 14/23] avutil/hwcontext_opencl: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 16/23] avutil/hwcontext_dxva2: " Andreas Rheinhardt
` (9 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to QSVFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_qsv.c | 46 +++++++++++++++++++++------------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 99d974f25f..f524a663b1 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -85,6 +85,11 @@ typedef struct QSVDeviceContext {
} QSVDeviceContext;
typedef struct QSVFramesContext {
+ /**
+ * The public AVQSVFramesContext. See hwcontext_qsv.h for it.
+ */
+ AVQSVFramesContext p;
+
mfxSession session_download;
atomic_int session_download_init;
mfxSession session_upload;
@@ -329,7 +334,7 @@ static int qsv_device_init(AVHWDeviceContext *ctx)
static void qsv_frames_uninit(AVHWFramesContext *ctx)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
if (s->session_download) {
MFXVideoVPP_Close(s->session_download);
@@ -367,8 +372,8 @@ static void qsv_pool_release_dummy(void *opaque, uint8_t *data)
static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
- QSVFramesContext *s = ctx->internal->priv;
- AVQSVFramesContext *hwctx = ctx->hwctx;
+ QSVFramesContext *s = ctx->hwctx;
+ AVQSVFramesContext *hwctx = &s->p;
if (s->nb_surfaces_used < hwctx->nb_surfaces) {
s->nb_surfaces_used++;
@@ -381,9 +386,9 @@ static AVBufferRef *qsv_pool_alloc(void *opaque, size_t size)
static int qsv_init_child_ctx(AVHWFramesContext *ctx)
{
- AVQSVFramesContext *hwctx = ctx->hwctx;
- QSVFramesContext *s = ctx->internal->priv;
QSVDeviceContext *device_priv = ctx->device_ctx->hwctx;
+ QSVFramesContext *s = ctx->hwctx;
+ AVQSVFramesContext *hwctx = &s->p;
AVBufferRef *child_device_ref = NULL;
AVBufferRef *child_frames_ref = NULL;
@@ -562,8 +567,8 @@ static int qsv_init_surface(AVHWFramesContext *ctx, mfxFrameSurface1 *surf)
static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
{
- QSVFramesContext *s = ctx->internal->priv;
- AVQSVFramesContext *frames_hwctx = ctx->hwctx;
+ QSVFramesContext *s = ctx->hwctx;
+ AVQSVFramesContext *frames_hwctx = &s->p;
int i, ret = 0;
@@ -615,8 +620,8 @@ static mfxStatus frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req,
mfxFrameAllocResponse *resp)
{
AVHWFramesContext *ctx = pthis;
- QSVFramesContext *s = ctx->internal->priv;
- AVQSVFramesContext *hwctx = ctx->hwctx;
+ QSVFramesContext *s = ctx->hwctx;
+ AVQSVFramesContext *hwctx = &s->p;
mfxFrameInfo *i = &req->Info;
mfxFrameInfo *i1 = &hwctx->surfaces[0].Info;
@@ -1133,7 +1138,7 @@ static int qsv_init_internal_session(AVHWFramesContext *ctx,
void **loader = &hwctx->loader;
#if QSV_HAVE_OPAQUE
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
opaque = !!(frames_hwctx->frame_type & MFX_MEMTYPE_OPAQUE_FRAME);
#endif
@@ -1210,8 +1215,8 @@ fail:
static int qsv_frames_init(AVHWFramesContext *ctx)
{
- QSVFramesContext *s = ctx->internal->priv;
- AVQSVFramesContext *frames_hwctx = ctx->hwctx;
+ QSVFramesContext *s = ctx->hwctx;
+ AVQSVFramesContext *frames_hwctx = &s->p;
int opaque = 0;
@@ -1387,7 +1392,7 @@ static int qsv_frames_derive_from(AVHWFramesContext *dst_ctx,
static int qsv_map_from(AVHWFramesContext *ctx,
AVFrame *dst, const AVFrame *src, int flags)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
mfxFrameSurface1 *surf = (mfxFrameSurface1*)src->data[3];
AVHWFramesContext *child_frames_ctx;
const AVPixFmtDescriptor *desc;
@@ -1490,7 +1495,7 @@ fail:
static int qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
AVHWFramesContext *child_frames_ctx = (AVHWFramesContext*)s->child_frames_ref->data;
int download = !!src->hw_frames_ctx;
mfxFrameSurface1 *surf = (mfxFrameSurface1*)(download ? src->data[3] : dst->data[3]);
@@ -1592,7 +1597,7 @@ static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1 *surface)
static int qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
atomic_int *inited = upload ? &s->session_upload_init : &s->session_download_init;
mfxSession *session = upload ? &s->session_upload : &s->session_download;
int ret = 0;
@@ -1619,7 +1624,7 @@ static int qsv_internal_session_check_init(AVHWFramesContext *ctx, int upload)
static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
mfxFrameSurface1 out = {{ 0 }};
mfxFrameSurface1 *in = (mfxFrameSurface1*)src->data[3];
@@ -1702,7 +1707,7 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- QSVFramesContext *s = ctx->internal->priv;
+ QSVFramesContext *s = ctx->hwctx;
mfxFrameSurface1 in = {{ 0 }};
mfxFrameSurface1 *out = (mfxFrameSurface1*)dst->data[3];
mfxFrameInfo tmp_info;
@@ -1795,8 +1800,8 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx,
AVHWFramesContext *src_ctx, int flags)
{
- QSVFramesContext *s = dst_ctx->internal->priv;
- AVQSVFramesContext *dst_hwctx = dst_ctx->hwctx;
+ QSVFramesContext *s = dst_ctx->hwctx;
+ AVQSVFramesContext *dst_hwctx = &s->p;
int i;
if (src_ctx->initial_pool_size == 0) {
@@ -2252,8 +2257,7 @@ const HWContextType ff_hwcontext_type_qsv = {
.name = "QSV",
.device_hwctx_size = sizeof(QSVDeviceContext),
- .frames_hwctx_size = sizeof(AVQSVFramesContext),
- .frames_priv_size = sizeof(QSVFramesContext),
+ .frames_hwctx_size = sizeof(QSVFramesContext),
.device_create = qsv_device_create,
.device_derive = qsv_device_derive,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 16/23] avutil/hwcontext_dxva2: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (13 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 15/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 17/23] avutil/hwcontext_d3d11va: " Andreas Rheinhardt
` (8 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to DXVA2FramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_dxva2.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c
index 2c11f151ff..0922776342 100644
--- a/libavutil/hwcontext_dxva2.c
+++ b/libavutil/hwcontext_dxva2.c
@@ -57,6 +57,11 @@ typedef struct DXVA2Mapping {
} DXVA2Mapping;
typedef struct DXVA2FramesContext {
+ /**
+ * The public AVDXVA2FramesContext. See hwcontext_dxva2.h for it.
+ */
+ AVDXVA2FramesContext p;
+
IDirect3DSurface9 **surfaces_internal;
int nb_surfaces_used;
@@ -99,8 +104,8 @@ DEFINE_GUID(video_processor_service, 0xfc51a552, 0xd5e7, 0x11d9, 0xaf, 0x55, 0x0
static void dxva2_frames_uninit(AVHWFramesContext *ctx)
{
AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
- DXVA2FramesContext *s = ctx->internal->priv;
+ DXVA2FramesContext *s = ctx->hwctx;
+ AVDXVA2FramesContext *frames_hwctx = &s->p;
int i;
if (frames_hwctx->decoder_to_release)
@@ -135,8 +140,8 @@ static void dxva2_pool_release_dummy(void *opaque, uint8_t *data)
static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
- DXVA2FramesContext *s = ctx->internal->priv;
- AVDXVA2FramesContext *hwctx = ctx->hwctx;
+ DXVA2FramesContext *s = ctx->hwctx;
+ AVDXVA2FramesContext *hwctx = &s->p;
if (s->nb_surfaces_used < hwctx->nb_surfaces) {
s->nb_surfaces_used++;
@@ -149,9 +154,9 @@ static AVBufferRef *dxva2_pool_alloc(void *opaque, size_t size)
static int dxva2_init_pool(AVHWFramesContext *ctx)
{
- AVDXVA2FramesContext *frames_hwctx = ctx->hwctx;
AVDXVA2DeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- DXVA2FramesContext *s = ctx->internal->priv;
+ DXVA2FramesContext *s = ctx->hwctx;
+ AVDXVA2FramesContext *frames_hwctx = &s->p;
int decode = (frames_hwctx->surface_type == DXVA2_VideoDecoderRenderTarget);
int i;
@@ -216,8 +221,8 @@ static int dxva2_init_pool(AVHWFramesContext *ctx)
static int dxva2_frames_init(AVHWFramesContext *ctx)
{
- AVDXVA2FramesContext *hwctx = ctx->hwctx;
- DXVA2FramesContext *s = ctx->internal->priv;
+ DXVA2FramesContext *s = ctx->hwctx;
+ AVDXVA2FramesContext *hwctx = &s->p;
int ret;
if (hwctx->surface_type != DXVA2_VideoDecoderRenderTarget &&
@@ -586,8 +591,7 @@ const HWContextType ff_hwcontext_type_dxva2 = {
.name = "DXVA2",
.device_hwctx_size = sizeof(AVDXVA2DeviceContext),
- .frames_hwctx_size = sizeof(AVDXVA2FramesContext),
- .frames_priv_size = sizeof(DXVA2FramesContext),
+ .frames_hwctx_size = sizeof(DXVA2FramesContext),
.device_create = dxva2_device_create,
.frames_init = dxva2_frames_init,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 17/23] avutil/hwcontext_d3d11va: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (14 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 16/23] avutil/hwcontext_dxva2: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 18/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
` (7 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to D3D11VAFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_d3d11va.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 2fd3561c88..19fcf37a84 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -72,6 +72,11 @@ static av_cold void load_functions(void)
}
typedef struct D3D11VAFramesContext {
+ /**
+ * The public AVD3D11VAFramesContext. See hwcontext_d3d11va.h for it.
+ */
+ AVD3D11VAFramesContext p;
+
int nb_surfaces;
int nb_surfaces_used;
@@ -113,8 +118,8 @@ static void d3d11va_default_unlock(void *ctx)
static void d3d11va_frames_uninit(AVHWFramesContext *ctx)
{
- AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx;
- D3D11VAFramesContext *s = ctx->internal->priv;
+ D3D11VAFramesContext *s = ctx->hwctx;
+ AVD3D11VAFramesContext *frames_hwctx = &s->p;
if (frames_hwctx->texture)
ID3D11Texture2D_Release(frames_hwctx->texture);
@@ -169,8 +174,8 @@ static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *te
{
AVBufferRef *buf;
AVD3D11FrameDescriptor *desc = av_mallocz(sizeof(*desc));
- D3D11VAFramesContext *s = ctx->internal->priv;
- AVD3D11VAFramesContext *frames_hwctx = ctx->hwctx;
+ D3D11VAFramesContext *s = ctx->hwctx;
+ AVD3D11VAFramesContext *frames_hwctx = &s->p;
if (!desc) {
ID3D11Texture2D_Release(tex);
return NULL;
@@ -206,8 +211,8 @@ static AVBufferRef *wrap_texture_buf(AVHWFramesContext *ctx, ID3D11Texture2D *te
static AVBufferRef *d3d11va_alloc_single(AVHWFramesContext *ctx)
{
- D3D11VAFramesContext *s = ctx->internal->priv;
- AVD3D11VAFramesContext *hwctx = ctx->hwctx;
+ D3D11VAFramesContext *s = ctx->hwctx;
+ AVD3D11VAFramesContext *hwctx = &s->p;
AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
HRESULT hr;
ID3D11Texture2D *tex;
@@ -235,8 +240,8 @@ static AVBufferRef *d3d11va_alloc_single(AVHWFramesContext *ctx)
static AVBufferRef *d3d11va_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = (AVHWFramesContext*)opaque;
- D3D11VAFramesContext *s = ctx->internal->priv;
- AVD3D11VAFramesContext *hwctx = ctx->hwctx;
+ D3D11VAFramesContext *s = ctx->hwctx;
+ AVD3D11VAFramesContext *hwctx = &s->p;
D3D11_TEXTURE2D_DESC texDesc;
if (!hwctx->texture)
@@ -255,9 +260,9 @@ static AVBufferRef *d3d11va_pool_alloc(void *opaque, size_t size)
static int d3d11va_frames_init(AVHWFramesContext *ctx)
{
- AVD3D11VAFramesContext *hwctx = ctx->hwctx;
AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- D3D11VAFramesContext *s = ctx->internal->priv;
+ D3D11VAFramesContext *s = ctx->hwctx;
+ AVD3D11VAFramesContext *hwctx = &s->p;
int i;
HRESULT hr;
@@ -345,7 +350,7 @@ static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx,
enum AVHWFrameTransferDirection dir,
enum AVPixelFormat **formats)
{
- D3D11VAFramesContext *s = ctx->internal->priv;
+ D3D11VAFramesContext *s = ctx->hwctx;
enum AVPixelFormat *fmts;
fmts = av_malloc_array(2, sizeof(*fmts));
@@ -367,7 +372,7 @@ static int d3d11va_transfer_get_formats(AVHWFramesContext *ctx,
static int d3d11va_create_staging_texture(AVHWFramesContext *ctx, DXGI_FORMAT format)
{
AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- D3D11VAFramesContext *s = ctx->internal->priv;
+ D3D11VAFramesContext *s = ctx->hwctx;
HRESULT hr;
D3D11_TEXTURE2D_DESC texDesc = {
.Width = ctx->width,
@@ -407,7 +412,7 @@ static int d3d11va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
AVD3D11VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- D3D11VAFramesContext *s = ctx->internal->priv;
+ D3D11VAFramesContext *s = ctx->hwctx;
int download = src->format == AV_PIX_FMT_D3D11;
const AVFrame *frame = download ? src : dst;
const AVFrame *other = download ? dst : src;
@@ -696,8 +701,7 @@ const HWContextType ff_hwcontext_type_d3d11va = {
.name = "D3D11VA",
.device_hwctx_size = sizeof(AVD3D11VADeviceContext),
- .frames_hwctx_size = sizeof(AVD3D11VAFramesContext),
- .frames_priv_size = sizeof(D3D11VAFramesContext),
+ .frames_hwctx_size = sizeof(D3D11VAFramesContext),
.device_create = d3d11va_device_create,
.device_init = d3d11va_device_init,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 18/23] avutil/hwcontext_d3d12va: Allocate pub and priv frames hwctx together
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (15 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 17/23] avutil/hwcontext_d3d11va: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 19/23] avutil/hwcontext: Clarify documentation of AVHWFramesContext.hwctx Andreas Rheinhardt
` (6 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of both coincide.
Besides reducing the number of allocations this also simplifies
access to D3D12VAFramesContext as one no longer has to
go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_d3d12va.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 6b4cd22899..16c07868f3 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -36,6 +36,11 @@
typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT Flags, REFIID riid, void **ppFactory);
typedef struct D3D12VAFramesContext {
+ /**
+ * The public AVD3D12VAFramesContext. See hwcontext_d3d12va.h for it.
+ */
+ AVD3D12VAFramesContext p;
+
ID3D12Resource *staging_download_buffer;
ID3D12Resource *staging_upload_buffer;
ID3D12CommandQueue *command_queue;
@@ -101,7 +106,7 @@ static int d3d12va_create_staging_buffer_resource(AVHWFramesContext *ctx, D3D12_
ID3D12Resource **ppResource, int download)
{
AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- D3D12VAFramesContext *s = ctx->internal->priv;
+ D3D12VAFramesContext *s = ctx->hwctx;
D3D12_HEAP_PROPERTIES props = { .Type = download ? D3D12_HEAP_TYPE_READBACK : D3D12_HEAP_TYPE_UPLOAD };
D3D12_RESOURCE_DESC desc = {
.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER,
@@ -128,8 +133,8 @@ static int d3d12va_create_staging_buffer_resource(AVHWFramesContext *ctx, D3D12_
static int d3d12va_create_helper_objects(AVHWFramesContext *ctx)
{
AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
- AVD3D12VAFramesContext *frames_hwctx = ctx->hwctx;
- D3D12VAFramesContext *s = ctx->internal->priv;
+ D3D12VAFramesContext *s = ctx->hwctx;
+ AVD3D12VAFramesContext *frames_hwctx = &s->p;
D3D12_COMMAND_QUEUE_DESC queue_desc = {
.Type = D3D12_COMMAND_LIST_TYPE_COPY,
@@ -168,7 +173,7 @@ fail:
static void d3d12va_frames_uninit(AVHWFramesContext *ctx)
{
- D3D12VAFramesContext *s = ctx->internal->priv;
+ D3D12VAFramesContext *s = ctx->hwctx;
D3D12_OBJECT_RELEASE(s->sync_ctx.fence);
if (s->sync_ctx.event)
@@ -345,8 +350,8 @@ static int d3d12va_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
AVD3D12VADeviceContext *hwctx = ctx->device_ctx->hwctx;
- AVD3D12VAFramesContext *frames_hwctx = ctx->hwctx;
- D3D12VAFramesContext *s = ctx->internal->priv;
+ D3D12VAFramesContext *s = ctx->hwctx;
+ AVD3D12VAFramesContext *frames_hwctx = &s->p;
int ret;
int download = src->format == AV_PIX_FMT_D3D12;
@@ -675,8 +680,7 @@ const HWContextType ff_hwcontext_type_d3d12va = {
.name = "D3D12VA",
.device_hwctx_size = sizeof(D3D12VADevicePriv),
- .frames_hwctx_size = sizeof(AVD3D12VAFramesContext),
- .frames_priv_size = sizeof(D3D12VAFramesContext),
+ .frames_hwctx_size = sizeof(D3D12VAFramesContext),
.device_create = d3d12va_device_create,
.device_init = d3d12va_device_init,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 19/23] avutil/hwcontext: Clarify documentation of AVHWFramesContext.hwctx
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (16 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 18/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 20/23] avutil/hwcontext_vdpau: Don't use AVHWFramesInternal.priv Andreas Rheinhardt
` (5 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Correct the names of the format-specific headers (not hwframe_*.h)
and clarify that the user shall ignore this field if there is no
public context associated with it.
In particular, this allows to use this field for the private context
alone if there is no public context. This can't break conforming
API users, because they always have to live with the possibility
that a new public context has been introduced.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index d91391294b..091bceb2f9 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -145,9 +145,12 @@ typedef struct AVHWFramesContext {
* The format-specific data, allocated and freed automatically along with
* this context.
*
- * Should be cast by the user to the format-specific context defined in the
- * corresponding header (hwframe_*.h) and filled as described in the
- * documentation before calling av_hwframe_ctx_init().
+ * The user shall ignore this field if the corresponding format-specific
+ * header (hwcontext_*.h) does not define a context to be used as
+ * AVHWFramesContext.hwctx.
+ *
+ * Otherwise, it should be cast by the user to said context and filled
+ * as described in the documentation before calling av_hwframe_ctx_init().
*
* After any frames using this context are created, the contents of this
* struct should not be modified by the caller.
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 20/23] avutil/hwcontext_vdpau: Don't use AVHWFramesInternal.priv
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (17 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 19/23] avutil/hwcontext: Clarify documentation of AVHWFramesContext.hwctx Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 21/23] avutil/hwcontext_cuda: " Andreas Rheinhardt
` (4 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Use AVHWFramesContext.hwctx instead.
This simplifies access to VDPAUFramesContext as one no longer has
to go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_vdpau.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
index 016300db1e..0a1a33f8b1 100644
--- a/libavutil/hwcontext_vdpau.c
+++ b/libavutil/hwcontext_vdpau.c
@@ -233,7 +233,7 @@ static void vdpau_buffer_free(void *opaque, uint8_t *data)
static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
{
AVHWFramesContext *ctx = opaque;
- VDPAUFramesContext *priv = ctx->internal->priv;
+ VDPAUFramesContext *priv = ctx->hwctx;
VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
AVVDPAUDeviceContext *device_hwctx = &device_priv->p;
@@ -261,7 +261,7 @@ static AVBufferRef *vdpau_pool_alloc(void *opaque, size_t size)
static int vdpau_frames_init(AVHWFramesContext *ctx)
{
VDPAUDeviceContext *device_priv = ctx->device_ctx->hwctx;
- VDPAUFramesContext *priv = ctx->internal->priv;
+ VDPAUFramesContext *priv = ctx->hwctx;
int i;
@@ -311,7 +311,7 @@ static int vdpau_transfer_get_formats(AVHWFramesContext *ctx,
enum AVHWFrameTransferDirection dir,
enum AVPixelFormat **formats)
{
- VDPAUFramesContext *priv = ctx->internal->priv;
+ VDPAUFramesContext *priv = ctx->hwctx;
enum AVPixelFormat *fmts;
@@ -334,7 +334,7 @@ static int vdpau_transfer_get_formats(AVHWFramesContext *ctx,
static int vdpau_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- VDPAUFramesContext *priv = ctx->internal->priv;
+ VDPAUFramesContext *priv = ctx->hwctx;
VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)src->data[3];
void *data[3];
@@ -392,7 +392,7 @@ static int vdpau_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
static int vdpau_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- VDPAUFramesContext *priv = ctx->internal->priv;
+ VDPAUFramesContext *priv = ctx->hwctx;
VdpVideoSurface surf = (VdpVideoSurface)(uintptr_t)dst->data[3];
const void *data[3];
@@ -514,7 +514,7 @@ const HWContextType ff_hwcontext_type_vdpau = {
.name = "VDPAU",
.device_hwctx_size = sizeof(VDPAUDeviceContext),
- .frames_priv_size = sizeof(VDPAUFramesContext),
+ .frames_hwctx_size = sizeof(VDPAUFramesContext),
#if HAVE_VDPAU_X11
.device_create = vdpau_device_create,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 21/23] avutil/hwcontext_cuda: Don't use AVHWFramesInternal.priv
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (18 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 20/23] avutil/hwcontext_vdpau: Don't use AVHWFramesInternal.priv Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 22/23] avutil/hwcontext_internal: Remove unused AVHWFramesInternal.priv Andreas Rheinhardt
` (3 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Use AVHWFramesContext.hwctx instead.
This simplifies accesses to VDPAUFramesContext as one no longer has
to go through AVHWFramesInternal.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_cuda.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 0312d3b9d7..1c61b36d69 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -130,7 +130,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
{
AVHWDeviceContext *device_ctx = ctx->device_ctx;
AVCUDADeviceContext *hwctx = device_ctx->hwctx;
- CUDAFramesContext *priv = ctx->internal->priv;
+ CUDAFramesContext *priv = ctx->hwctx;
CudaFunctions *cu = hwctx->internal->cuda_dl;
int err, i;
@@ -175,7 +175,7 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
{
- CUDAFramesContext *priv = ctx->internal->priv;
+ CUDAFramesContext *priv = ctx->hwctx;
int res;
frame->buf[0] = av_buffer_pool_get(ctx->pool);
@@ -223,7 +223,7 @@ static int cuda_transfer_get_formats(AVHWFramesContext *ctx,
static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst,
const AVFrame *src)
{
- CUDAFramesContext *priv = ctx->internal->priv;
+ CUDAFramesContext *priv = ctx->hwctx;
AVHWDeviceContext *device_ctx = ctx->device_ctx;
AVCUDADeviceContext *hwctx = device_ctx->hwctx;
CudaFunctions *cu = hwctx->internal->cuda_dl;
@@ -563,7 +563,7 @@ const HWContextType ff_hwcontext_type_cuda = {
.name = "CUDA",
.device_hwctx_size = sizeof(AVCUDADeviceContext),
- .frames_priv_size = sizeof(CUDAFramesContext),
+ .frames_hwctx_size = sizeof(CUDAFramesContext),
.device_create = cuda_device_create,
.device_derive = cuda_device_derive,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 22/23] avutil/hwcontext_internal: Remove unused AVHWFramesInternal.priv
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (19 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 21/23] avutil/hwcontext_cuda: " Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 23/23] avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals Andreas Rheinhardt
` (2 subsequent siblings)
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
It is no longer used by any hwcontext, as they all allocate
their private data together with their public data and access
it via AVHWFramesContext.hwctx.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.c | 9 ---------
libavutil/hwcontext_internal.h | 6 ------
2 files changed, 15 deletions(-)
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index c962c19f3e..8ecefd2bc4 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -248,7 +248,6 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data)
av_buffer_unref(&ctx->device_ref);
av_freep(&ctx->hwctx);
- av_freep(&ctx->internal->priv);
av_freep(&ctx->internal);
av_freep(&ctx);
}
@@ -268,12 +267,6 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
if (!ctx->internal)
goto fail;
- if (hw_type->frames_priv_size) {
- ctx->internal->priv = av_mallocz(hw_type->frames_priv_size);
- if (!ctx->internal->priv)
- goto fail;
- }
-
if (hw_type->frames_hwctx_size) {
ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size);
if (!ctx->hwctx)
@@ -302,8 +295,6 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
fail:
av_buffer_unref(&device_ref);
- if (ctx->internal)
- av_freep(&ctx->internal->priv);
av_freep(&ctx->internal);
av_freep(&ctx->hwctx);
av_freep(&ctx);
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 3745867283..1476def1d7 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -53,11 +53,6 @@ typedef struct HWContextType {
* i.e. AVHWFramesContext.hwctx
*/
size_t frames_hwctx_size;
- /**
- * size of the private data, i.e.
- * AVHWFramesInternal.priv
- */
- size_t frames_priv_size;
int (*device_create)(AVHWDeviceContext *ctx, const char *device,
AVDictionary *opts, int flags);
@@ -97,7 +92,6 @@ typedef struct HWContextType {
struct AVHWFramesInternal {
const HWContextType *hw_type;
- void *priv;
AVBufferPool *pool_internal;
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 23/23] avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (20 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 22/23] avutil/hwcontext_internal: Remove unused AVHWFramesInternal.priv Andreas Rheinhardt
@ 2024-02-12 0:03 ` Andreas Rheinhardt
2024-02-12 22:04 ` [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Mark Thompson
2024-02-13 12:23 ` [FFmpeg-devel] [PATCH 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly Andreas Rheinhardt
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-12 0:03 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
This is possible because the lifetime of these structures coincide.
It has the advantage of allowing to remove AVHWFramesInternal
from the public header; given that AVHWFramesInternal.priv is no more,
most accesses to AVHWFramesInternal are no more; indeed, the only
field accessed of it outside of hwcontext.c is the internal frame pool,
making this commit very simple.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext.c | 158 ++++++++++++++---------------
libavutil/hwcontext.h | 8 --
libavutil/hwcontext_cuda.c | 5 +-
libavutil/hwcontext_d3d11va.c | 7 +-
libavutil/hwcontext_d3d12va.c | 4 +-
libavutil/hwcontext_dxva2.c | 7 +-
libavutil/hwcontext_internal.h | 14 ++-
libavutil/hwcontext_opencl.c | 4 +-
libavutil/hwcontext_qsv.c | 6 +-
libavutil/hwcontext_vaapi.c | 6 +-
libavutil/hwcontext_vdpau.c | 7 +-
libavutil/hwcontext_videotoolbox.c | 4 +-
libavutil/hwcontext_vulkan.c | 8 +-
13 files changed, 121 insertions(+), 117 deletions(-)
diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 8ecefd2bc4..a0192f4fa9 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -232,23 +232,23 @@ static const AVClass hwframe_ctx_class = {
static void hwframe_ctx_free(void *opaque, uint8_t *data)
{
- AVHWFramesContext *ctx = (AVHWFramesContext*)data;
+ FFHWFramesContext *ctxi = (FFHWFramesContext*)data;
+ AVHWFramesContext *ctx = &ctxi->p;
- if (ctx->internal->pool_internal)
- av_buffer_pool_uninit(&ctx->internal->pool_internal);
+ if (ctxi->pool_internal)
+ av_buffer_pool_uninit(&ctxi->pool_internal);
- if (ctx->internal->hw_type->frames_uninit)
- ctx->internal->hw_type->frames_uninit(ctx);
+ if (ctxi->hw_type->frames_uninit)
+ ctxi->hw_type->frames_uninit(ctx);
if (ctx->free)
ctx->free(ctx);
- av_buffer_unref(&ctx->internal->source_frames);
+ av_buffer_unref(&ctxi->source_frames);
av_buffer_unref(&ctx->device_ref);
av_freep(&ctx->hwctx);
- av_freep(&ctx->internal);
av_freep(&ctx);
}
@@ -256,16 +256,14 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
{
FFHWDeviceContext *device_ctx = (FFHWDeviceContext*)device_ref_in->data;
const HWContextType *hw_type = device_ctx->hw_type;
+ FFHWFramesContext *ctxi;
AVHWFramesContext *ctx;
AVBufferRef *buf, *device_ref = NULL;
- ctx = av_mallocz(sizeof(*ctx));
- if (!ctx)
+ ctxi = av_mallocz(sizeof(*ctxi));
+ if (!ctxi)
return NULL;
-
- ctx->internal = av_mallocz(sizeof(*ctx->internal));
- if (!ctx->internal)
- goto fail;
+ ctx = &ctxi->p;
if (hw_type->frames_hwctx_size) {
ctx->hwctx = av_mallocz(hw_type->frames_hwctx_size);
@@ -289,13 +287,12 @@ AVBufferRef *av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
ctx->format = AV_PIX_FMT_NONE;
ctx->sw_format = AV_PIX_FMT_NONE;
- ctx->internal->hw_type = hw_type;
+ ctxi->hw_type = hw_type;
return buf;
fail:
av_buffer_unref(&device_ref);
- av_freep(&ctx->internal);
av_freep(&ctx->hwctx);
av_freep(&ctx);
return NULL;
@@ -331,24 +328,25 @@ fail:
int av_hwframe_ctx_init(AVBufferRef *ref)
{
- AVHWFramesContext *ctx = (AVHWFramesContext*)ref->data;
+ FFHWFramesContext *ctxi = (FFHWFramesContext*)ref->data;
+ AVHWFramesContext *ctx = &ctxi->p;
const enum AVPixelFormat *pix_fmt;
int ret;
- if (ctx->internal->source_frames) {
+ if (ctxi->source_frames) {
/* A derived frame context is already initialised. */
return 0;
}
/* validate the pixel format */
- for (pix_fmt = ctx->internal->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
+ for (pix_fmt = ctxi->hw_type->pix_fmts; *pix_fmt != AV_PIX_FMT_NONE; pix_fmt++) {
if (*pix_fmt == ctx->format)
break;
}
if (*pix_fmt == AV_PIX_FMT_NONE) {
av_log(ctx, AV_LOG_ERROR,
"The hardware pixel format '%s' is not supported by the device type '%s'\n",
- av_get_pix_fmt_name(ctx->format), ctx->internal->hw_type->name);
+ av_get_pix_fmt_name(ctx->format), ctxi->hw_type->name);
return AVERROR(ENOSYS);
}
@@ -358,14 +356,14 @@ int av_hwframe_ctx_init(AVBufferRef *ref)
return ret;
/* format-specific init */
- if (ctx->internal->hw_type->frames_init) {
- ret = ctx->internal->hw_type->frames_init(ctx);
+ if (ctxi->hw_type->frames_init) {
+ ret = ctxi->hw_type->frames_init(ctx);
if (ret < 0)
goto fail;
}
- if (ctx->internal->pool_internal && !ctx->pool)
- ctx->pool = ctx->internal->pool_internal;
+ if (ctxi->pool_internal && !ctx->pool)
+ ctx->pool = ctxi->pool_internal;
/* preallocate the frames in the pool, if requested */
if (ctx->initial_pool_size > 0) {
@@ -376,8 +374,8 @@ int av_hwframe_ctx_init(AVBufferRef *ref)
return 0;
fail:
- if (ctx->internal->hw_type->frames_uninit)
- ctx->internal->hw_type->frames_uninit(ctx);
+ if (ctxi->hw_type->frames_uninit)
+ ctxi->hw_type->frames_uninit(ctx);
return ret;
}
@@ -385,12 +383,12 @@ int av_hwframe_transfer_get_formats(AVBufferRef *hwframe_ref,
enum AVHWFrameTransferDirection dir,
enum AVPixelFormat **formats, int flags)
{
- AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
+ FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data;
- if (!ctx->internal->hw_type->transfer_get_formats)
+ if (!ctxi->hw_type->transfer_get_formats)
return AVERROR(ENOSYS);
- return ctx->internal->hw_type->transfer_get_formats(ctx, dir, formats);
+ return ctxi->hw_type->transfer_get_formats(&ctxi->p, dir, formats);
}
static int transfer_data_alloc(AVFrame *dst, const AVFrame *src, int flags)
@@ -445,7 +443,6 @@ fail:
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
{
- AVHWFramesContext *ctx;
int ret;
if (!dst->buf[0])
@@ -458,41 +455,41 @@ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
* the specific combination of hardware.
*/
if (src->hw_frames_ctx && dst->hw_frames_ctx) {
- AVHWFramesContext *src_ctx =
- (AVHWFramesContext*)src->hw_frames_ctx->data;
- AVHWFramesContext *dst_ctx =
- (AVHWFramesContext*)dst->hw_frames_ctx->data;
+ FFHWFramesContext *src_ctx =
+ (FFHWFramesContext*)src->hw_frames_ctx->data;
+ FFHWFramesContext *dst_ctx =
+ (FFHWFramesContext*)dst->hw_frames_ctx->data;
- if (src_ctx->internal->source_frames) {
+ if (src_ctx->source_frames) {
av_log(src_ctx, AV_LOG_ERROR,
"A device with a derived frame context cannot be used as "
"the source of a HW -> HW transfer.");
return AVERROR(ENOSYS);
}
- if (dst_ctx->internal->source_frames) {
+ if (dst_ctx->source_frames) {
av_log(src_ctx, AV_LOG_ERROR,
"A device with a derived frame context cannot be used as "
"the destination of a HW -> HW transfer.");
return AVERROR(ENOSYS);
}
- ret = src_ctx->internal->hw_type->transfer_data_from(src_ctx, dst, src);
+ ret = src_ctx->hw_type->transfer_data_from(&src_ctx->p, dst, src);
if (ret == AVERROR(ENOSYS))
- ret = dst_ctx->internal->hw_type->transfer_data_to(dst_ctx, dst, src);
+ ret = dst_ctx->hw_type->transfer_data_to(&dst_ctx->p, dst, src);
if (ret < 0)
return ret;
} else {
if (src->hw_frames_ctx) {
- ctx = (AVHWFramesContext*)src->hw_frames_ctx->data;
+ FFHWFramesContext *ctx = (FFHWFramesContext*)src->hw_frames_ctx->data;
- ret = ctx->internal->hw_type->transfer_data_from(ctx, dst, src);
+ ret = ctx->hw_type->transfer_data_from(&ctx->p, dst, src);
if (ret < 0)
return ret;
} else if (dst->hw_frames_ctx) {
- ctx = (AVHWFramesContext*)dst->hw_frames_ctx->data;
+ FFHWFramesContext *ctx = (FFHWFramesContext*)dst->hw_frames_ctx->data;
- ret = ctx->internal->hw_type->transfer_data_to(ctx, dst, src);
+ ret = ctx->hw_type->transfer_data_to(&ctx->p, dst, src);
if (ret < 0)
return ret;
} else {
@@ -504,10 +501,11 @@ int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
{
- AVHWFramesContext *ctx = (AVHWFramesContext*)hwframe_ref->data;
+ FFHWFramesContext *ctxi = (FFHWFramesContext*)hwframe_ref->data;
+ AVHWFramesContext *ctx = &ctxi->p;
int ret;
- if (ctx->internal->source_frames) {
+ if (ctxi->source_frames) {
// This is a derived frame context, so we allocate in the source
// and map the frame immediately.
AVFrame *src_frame;
@@ -521,7 +519,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
if (!src_frame)
return AVERROR(ENOMEM);
- ret = av_hwframe_get_buffer(ctx->internal->source_frames,
+ ret = av_hwframe_get_buffer(ctxi->source_frames,
src_frame, 0);
if (ret < 0) {
av_frame_free(&src_frame);
@@ -529,7 +527,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
}
ret = av_hwframe_map(frame, src_frame,
- ctx->internal->source_allocation_map_flags);
+ ctxi->source_allocation_map_flags);
if (ret) {
av_log(ctx, AV_LOG_ERROR, "Failed to map frame into derived "
"frame context: %d.\n", ret);
@@ -544,7 +542,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
return 0;
}
- if (!ctx->internal->hw_type->frames_get_buffer)
+ if (!ctxi->hw_type->frames_get_buffer)
return AVERROR(ENOSYS);
if (!ctx->pool)
@@ -554,7 +552,7 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
if (!frame->hw_frames_ctx)
return AVERROR(ENOMEM);
- ret = ctx->internal->hw_type->frames_get_buffer(ctx, frame);
+ ret = ctxi->hw_type->frames_get_buffer(ctx, frame);
if (ret < 0) {
av_buffer_unref(&frame->hw_frames_ctx);
return ret;
@@ -792,19 +790,18 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
{
AVBufferRef *orig_dst_frames = dst->hw_frames_ctx;
enum AVPixelFormat orig_dst_fmt = dst->format;
- AVHWFramesContext *src_frames, *dst_frames;
HWMapDescriptor *hwmap;
int ret;
if (src->hw_frames_ctx && dst->hw_frames_ctx) {
- src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
- dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
+ FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data;
+ FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data;
if ((src_frames == dst_frames &&
- src->format == dst_frames->sw_format &&
- dst->format == dst_frames->format) ||
- (src_frames->internal->source_frames &&
- src_frames->internal->source_frames->data ==
+ src->format == dst_frames->p.sw_format &&
+ dst->format == dst_frames->p.format) ||
+ (src_frames->source_frames &&
+ src_frames->source_frames->data ==
(uint8_t*)dst_frames)) {
// This is an unmap operation. We don't need to directly
// do anything here other than fill in the original frame,
@@ -821,12 +818,12 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
}
if (src->hw_frames_ctx) {
- src_frames = (AVHWFramesContext*)src->hw_frames_ctx->data;
+ FFHWFramesContext *src_frames = (FFHWFramesContext*)src->hw_frames_ctx->data;
- if (src_frames->format == src->format &&
- src_frames->internal->hw_type->map_from) {
- ret = src_frames->internal->hw_type->map_from(src_frames,
- dst, src, flags);
+ if (src_frames->p.format == src->format &&
+ src_frames->hw_type->map_from) {
+ ret = src_frames->hw_type->map_from(&src_frames->p,
+ dst, src, flags);
if (ret >= 0)
return ret;
else if (ret != AVERROR(ENOSYS))
@@ -835,12 +832,12 @@ int av_hwframe_map(AVFrame *dst, const AVFrame *src, int flags)
}
if (dst->hw_frames_ctx) {
- dst_frames = (AVHWFramesContext*)dst->hw_frames_ctx->data;
+ FFHWFramesContext *dst_frames = (FFHWFramesContext*)dst->hw_frames_ctx->data;
- if (dst_frames->format == dst->format &&
- dst_frames->internal->hw_type->map_to) {
- ret = dst_frames->internal->hw_type->map_to(dst_frames,
- dst, src, flags);
+ if (dst_frames->p.format == dst->format &&
+ dst_frames->hw_type->map_to) {
+ ret = dst_frames->hw_type->map_to(&dst_frames->p,
+ dst, src, flags);
if (ret >= 0)
return ret;
else if (ret != AVERROR(ENOSYS))
@@ -874,21 +871,21 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
int flags)
{
AVBufferRef *dst_ref = NULL;
- AVHWFramesContext *dst = NULL;
- AVHWFramesContext *src = (AVHWFramesContext*)source_frame_ctx->data;
+ FFHWFramesContext *dsti = NULL;
+ FFHWFramesContext *srci = (FFHWFramesContext*)source_frame_ctx->data;
+ AVHWFramesContext *dst, *src = &srci->p;
int ret;
- if (src->internal->source_frames) {
+ if (srci->source_frames) {
AVHWFramesContext *src_src =
- (AVHWFramesContext*)src->internal->source_frames->data;
+ (AVHWFramesContext*)srci->source_frames->data;
AVHWDeviceContext *dst_dev =
(AVHWDeviceContext*)derived_device_ctx->data;
if (src_src->device_ctx == dst_dev) {
// This is actually an unmapping, so we just return a
// reference to the source frame context.
- *derived_frame_ctx =
- av_buffer_ref(src->internal->source_frames);
+ *derived_frame_ctx = av_buffer_ref(srci->source_frames);
if (!*derived_frame_ctx) {
ret = AVERROR(ENOMEM);
goto fail;
@@ -903,31 +900,32 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
goto fail;
}
- dst = (AVHWFramesContext*)dst_ref->data;
+ dsti = (FFHWFramesContext*)dst_ref->data;
+ dst = &dsti->p;
dst->format = format;
dst->sw_format = src->sw_format;
dst->width = src->width;
dst->height = src->height;
- dst->internal->source_frames = av_buffer_ref(source_frame_ctx);
- if (!dst->internal->source_frames) {
+ dsti->source_frames = av_buffer_ref(source_frame_ctx);
+ if (!dsti->source_frames) {
ret = AVERROR(ENOMEM);
goto fail;
}
- dst->internal->source_allocation_map_flags =
+ dsti->source_allocation_map_flags =
flags & (AV_HWFRAME_MAP_READ |
AV_HWFRAME_MAP_WRITE |
AV_HWFRAME_MAP_OVERWRITE |
AV_HWFRAME_MAP_DIRECT);
ret = AVERROR(ENOSYS);
- if (src->internal->hw_type->frames_derive_from)
- ret = src->internal->hw_type->frames_derive_from(dst, src, flags);
+ if (srci->hw_type->frames_derive_from)
+ ret = srci->hw_type->frames_derive_from(dst, src, flags);
if (ret == AVERROR(ENOSYS) &&
- dst->internal->hw_type->frames_derive_to)
- ret = dst->internal->hw_type->frames_derive_to(dst, src, flags);
+ dsti->hw_type->frames_derive_to)
+ ret = dsti->hw_type->frames_derive_to(dst, src, flags);
if (ret == AVERROR(ENOSYS))
ret = 0;
if (ret)
@@ -937,8 +935,8 @@ int av_hwframe_ctx_create_derived(AVBufferRef **derived_frame_ctx,
return 0;
fail:
- if (dst)
- av_buffer_unref(&dst->internal->source_frames);
+ if (dsti)
+ av_buffer_unref(&dsti->source_frames);
av_buffer_unref(&dst_ref);
return ret;
}
diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 091bceb2f9..bac30debae 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -102,8 +102,6 @@ typedef struct AVHWDeviceContext {
void *user_opaque;
} AVHWDeviceContext;
-typedef struct AVHWFramesInternal AVHWFramesInternal;
-
/**
* This struct describes a set or pool of "hardware" frames (i.e. those with
* data not located in normal system memory). All the frames in the pool are
@@ -120,12 +118,6 @@ typedef struct AVHWFramesContext {
*/
const AVClass *av_class;
- /**
- * Private data used internally by libavutil. Must not be accessed in any
- * way by the caller.
- */
- AVHWFramesInternal *internal;
-
/**
* A reference to the parent AVHWDeviceContext. This reference is owned and
* managed by the enclosing AVHWFramesContext, but the caller may derive
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index 1c61b36d69..b430b42f62 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -165,8 +165,9 @@ static int cuda_frames_init(AVHWFramesContext *ctx)
if (size < 0)
return size;
- ctx->internal->pool_internal = av_buffer_pool_init2(size, ctx, cuda_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ ffhwframesctx(ctx)->pool_internal =
+ av_buffer_pool_init2(size, ctx, cuda_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
}
diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 19fcf37a84..24b3546e7b 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -319,9 +319,10 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
return AVERROR(ENOMEM);
s->nb_surfaces = ctx->initial_pool_size;
- ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor),
- ctx, d3d11va_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ ffhwframesctx(ctx)->pool_internal =
+ av_buffer_pool_init2(sizeof(AVD3D11FrameDescriptor),
+ ctx, d3d11va_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
return 0;
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 16c07868f3..353807359b 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -297,10 +297,10 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx)
return AVERROR(EINVAL);
}
- ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame),
+ ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame),
ctx, d3d12va_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
return 0;
diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c
index 0922776342..77f34919a8 100644
--- a/libavutil/hwcontext_dxva2.c
+++ b/libavutil/hwcontext_dxva2.c
@@ -208,9 +208,10 @@ static int dxva2_init_pool(AVHWFramesContext *ctx)
return AVERROR_UNKNOWN;
}
- ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(*s->surfaces_internal),
- ctx, dxva2_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ ffhwframesctx(ctx)->pool_internal =
+ av_buffer_pool_init2(sizeof(*s->surfaces_internal),
+ ctx, dxva2_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
frames_hwctx->surfaces = s->surfaces_internal;
diff --git a/libavutil/hwcontext_internal.h b/libavutil/hwcontext_internal.h
index 1476def1d7..e32b786238 100644
--- a/libavutil/hwcontext_internal.h
+++ b/libavutil/hwcontext_internal.h
@@ -90,7 +90,12 @@ typedef struct HWContextType {
AVHWFramesContext *src_ctx, int flags);
} HWContextType;
-struct AVHWFramesInternal {
+typedef struct FFHWFramesContext {
+ /**
+ * The public AVHWFramesContext. See hwcontext.h for it.
+ */
+ AVHWFramesContext p;
+
const HWContextType *hw_type;
AVBufferPool *pool_internal;
@@ -105,7 +110,12 @@ struct AVHWFramesInternal {
* frame context when trying to allocate in the derived context.
*/
int source_allocation_map_flags;
-};
+} FFHWFramesContext;
+
+static inline FFHWFramesContext *ffhwframesctx(AVHWFramesContext *ctx)
+{
+ return (FFHWFramesContext*)ctx;
+}
typedef struct HWMapDescriptor {
/**
diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
index c5af1aec74..b449c5c31b 100644
--- a/libavutil/hwcontext_opencl.c
+++ b/libavutil/hwcontext_opencl.c
@@ -1714,10 +1714,10 @@ static int opencl_frames_init_command_queue(AVHWFramesContext *hwfc)
static int opencl_frames_init(AVHWFramesContext *hwfc)
{
if (!hwfc->pool) {
- hwfc->internal->pool_internal =
+ ffhwframesctx(hwfc)->pool_internal =
av_buffer_pool_init2(sizeof(cl_mem), hwfc,
&opencl_pool_alloc, NULL);
- if (!hwfc->internal->pool_internal)
+ if (!ffhwframesctx(hwfc)->pool_internal)
return AVERROR(ENOMEM);
}
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index f524a663b1..378cd5e826 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -605,9 +605,9 @@ static int qsv_init_pool(AVHWFramesContext *ctx, uint32_t fourcc)
return ret;
#endif
- ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
- ctx, qsv_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(mfxFrameSurface1),
+ ctx, qsv_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
frames_hwctx->surfaces = s->surfaces_internal;
diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 2c75f5f5b1..56d03aa4cd 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -633,10 +633,10 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
avfc->surface_ids = NULL;
}
- hwfc->internal->pool_internal =
+ ffhwframesctx(hwfc)->pool_internal =
av_buffer_pool_init2(sizeof(VASurfaceID), hwfc,
&vaapi_pool_alloc, NULL);
- if (!hwfc->internal->pool_internal) {
+ if (!ffhwframesctx(hwfc)->pool_internal) {
av_log(hwfc, AV_LOG_ERROR, "Failed to create VAAPI surface pool.\n");
err = AVERROR(ENOMEM);
goto fail;
@@ -654,7 +654,7 @@ static int vaapi_frames_init(AVHWFramesContext *hwfc)
goto fail;
}
} else {
- test_surface = av_buffer_pool_get(hwfc->internal->pool_internal);
+ test_surface = av_buffer_pool_get(ffhwframesctx(hwfc)->pool_internal);
if (!test_surface) {
av_log(hwfc, AV_LOG_ERROR, "Unable to allocate a surface from "
"internal buffer pool.\n");
diff --git a/libavutil/hwcontext_vdpau.c b/libavutil/hwcontext_vdpau.c
index 0a1a33f8b1..081b863e0c 100644
--- a/libavutil/hwcontext_vdpau.c
+++ b/libavutil/hwcontext_vdpau.c
@@ -281,9 +281,10 @@ static int vdpau_frames_init(AVHWFramesContext *ctx)
}
if (!ctx->pool) {
- ctx->internal->pool_internal = av_buffer_pool_init2(sizeof(VdpVideoSurface), ctx,
- vdpau_pool_alloc, NULL);
- if (!ctx->internal->pool_internal)
+ ffhwframesctx(ctx)->pool_internal =
+ av_buffer_pool_init2(sizeof(VdpVideoSurface), ctx,
+ vdpau_pool_alloc, NULL);
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
}
diff --git a/libavutil/hwcontext_videotoolbox.c b/libavutil/hwcontext_videotoolbox.c
index 823cf9a8ee..9f82b104c3 100644
--- a/libavutil/hwcontext_videotoolbox.c
+++ b/libavutil/hwcontext_videotoolbox.c
@@ -286,9 +286,9 @@ static int vt_frames_init(AVHWFramesContext *ctx)
}
if (!ctx->pool) {
- ctx->internal->pool_internal = av_buffer_pool_init2(
+ ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(
sizeof(CVPixelBufferRef), ctx, vt_pool_alloc_buffer, NULL);
- if (!ctx->internal->pool_internal)
+ if (!ffhwframesctx(ctx)->pool_internal)
return AVERROR(ENOMEM);
}
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c
index 449a6a2fef..f6ecdcbfda 100644
--- a/libavutil/hwcontext_vulkan.c
+++ b/libavutil/hwcontext_vulkan.c
@@ -2399,10 +2399,10 @@ static int vulkan_frames_init(AVHWFramesContext *hwfc)
/* If user did not specify a pool, hwfc->pool will be set to the internal one
* in hwcontext.c just after this gets called */
if (!hwfc->pool) {
- hwfc->internal->pool_internal = av_buffer_pool_init2(sizeof(AVVkFrame),
- hwfc, vulkan_pool_alloc,
- NULL);
- if (!hwfc->internal->pool_internal)
+ ffhwframesctx(hwfc)->pool_internal = av_buffer_pool_init2(sizeof(AVVkFrame),
+ hwfc, vulkan_pool_alloc,
+ NULL);
+ if (!ffhwframesctx(hwfc)->pool_internal)
return AVERROR(ENOMEM);
}
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (21 preceding siblings ...)
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 23/23] avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals Andreas Rheinhardt
@ 2024-02-12 22:04 ` Mark Thompson
2024-02-13 12:23 ` [FFmpeg-devel] [PATCH 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly Andreas Rheinhardt
23 siblings, 0 replies; 25+ messages in thread
From: Mark Thompson @ 2024-02-12 22:04 UTC (permalink / raw)
To: ffmpeg-devel
On 12/02/2024 00:01, Andreas Rheinhardt wrote:
> The currently used pointer when unmapping DXVA2 and D3D11
> actually points to an OpenCLDeviceContext.
>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
> 1. I'd appreciate testing of this.
DXVA2 mapping tested and working on AMD. D3D11 mapping doesn't work on AMD for unrelated reasons.
D3D11 mapping tested and working on Intel. DXVA2 didn't work on that test machine at all (old laptop, I think Nvidia was causing the problem).
> 2. Most of the patches in this patchset can be applied immediately;
> only those two patches that remove AVHWDeviceInternal and
> AVHWFramesInternal need to be applied at the bump.
>
> libavutil/hwcontext_opencl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavutil/hwcontext_opencl.c b/libavutil/hwcontext_opencl.c
> index 247834aaf6..c1764ed098 100644
> --- a/libavutil/hwcontext_opencl.c
> +++ b/libavutil/hwcontext_opencl.c
> @@ -2346,7 +2346,7 @@ static void opencl_unmap_from_dxva2(AVHWFramesContext *dst_fc,
> {
> AVOpenCLFrameDescriptor *desc = hwmap->priv;
> OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
> - OpenCLFramesContext *frames_priv = dst_fc->device_ctx->internal->priv;
> + OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
> cl_event event;
> cl_int cle;
>
> @@ -2511,7 +2511,7 @@ static void opencl_unmap_from_d3d11(AVHWFramesContext *dst_fc,
> {
> AVOpenCLFrameDescriptor *desc = hwmap->priv;
> OpenCLDeviceContext *device_priv = dst_fc->device_ctx->internal->priv;
> - OpenCLFramesContext *frames_priv = dst_fc->device_ctx->internal->priv;
> + OpenCLFramesContext *frames_priv = dst_fc->internal->priv;
> cl_event event;
> cl_int cle;
>
LGTM, good spot.
Thanks,
- Mark
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
* [FFmpeg-devel] [PATCH 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
` (22 preceding siblings ...)
2024-02-12 22:04 ` [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Mark Thompson
@ 2024-02-13 12:23 ` Andreas Rheinhardt
23 siblings, 0 replies; 25+ messages in thread
From: Andreas Rheinhardt @ 2024-02-13 12:23 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Andreas Rheinhardt
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/hwcontext_cuda.c | 43 +++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/libavutil/hwcontext_cuda.c b/libavutil/hwcontext_cuda.c
index b430b42f62..3de3847399 100644
--- a/libavutil/hwcontext_cuda.c
+++ b/libavutil/hwcontext_cuda.c
@@ -35,6 +35,11 @@ typedef struct CUDAFramesContext {
int tex_alignment;
} CUDAFramesContext;
+typedef struct CUDADeviceContext {
+ AVCUDADeviceContext p;
+ AVCUDADeviceContextInternal internal;
+} CUDADeviceContext;
+
static const enum AVPixelFormat supported_formats[] = {
AV_PIX_FMT_NV12,
AV_PIX_FMT_YUV420P,
@@ -283,39 +288,35 @@ exit:
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
{
- AVCUDADeviceContext *hwctx = device_ctx->hwctx;
+ CUDADeviceContext *hwctx = device_ctx->hwctx;
- if (hwctx->internal) {
- CudaFunctions *cu = hwctx->internal->cuda_dl;
+ if (hwctx->p.internal) {
+ CudaFunctions *cu = hwctx->internal.cuda_dl;
- if (hwctx->internal->is_allocated && hwctx->cuda_ctx) {
- if (hwctx->internal->flags & AV_CUDA_USE_PRIMARY_CONTEXT)
- CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal->cuda_device));
- else if (!(hwctx->internal->flags & AV_CUDA_USE_CURRENT_CONTEXT))
- CHECK_CU(cu->cuCtxDestroy(hwctx->cuda_ctx));
+ if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) {
+ if (hwctx->internal.flags & AV_CUDA_USE_PRIMARY_CONTEXT)
+ CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device));
+ else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT))
+ CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx));
- hwctx->cuda_ctx = NULL;
+ hwctx->p.cuda_ctx = NULL;
}
- cuda_free_functions(&hwctx->internal->cuda_dl);
+ cuda_free_functions(&hwctx->internal.cuda_dl);
+ memset(&hwctx->internal, 0, sizeof(hwctx->internal));
+ hwctx->p.internal = NULL;
}
-
- av_freep(&hwctx->internal);
}
static int cuda_device_init(AVHWDeviceContext *ctx)
{
- AVCUDADeviceContext *hwctx = ctx->hwctx;
+ CUDADeviceContext *hwctx = ctx->hwctx;
int ret;
- if (!hwctx->internal) {
- hwctx->internal = av_mallocz(sizeof(*hwctx->internal));
- if (!hwctx->internal)
- return AVERROR(ENOMEM);
- }
+ hwctx->p.internal = &hwctx->internal;
- if (!hwctx->internal->cuda_dl) {
- ret = cuda_load_functions(&hwctx->internal->cuda_dl, ctx);
+ if (!hwctx->internal.cuda_dl) {
+ ret = cuda_load_functions(&hwctx->internal.cuda_dl, ctx);
if (ret < 0) {
av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
goto error;
@@ -563,7 +564,7 @@ const HWContextType ff_hwcontext_type_cuda = {
.type = AV_HWDEVICE_TYPE_CUDA,
.name = "CUDA",
- .device_hwctx_size = sizeof(AVCUDADeviceContext),
+ .device_hwctx_size = sizeof(CUDADeviceContext),
.frames_hwctx_size = sizeof(CUDAFramesContext),
.device_create = cuda_device_create,
--
2.34.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2024-02-13 12:21 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-12 0:01 [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 02/23] avutil/hwcontext: Don't check before av_buffer_unref() Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 03/23] avutil/hwcontext_vaapi: Allocate public and priv device hwctx together Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 04/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 05/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 06/23] avutil/hwcontext_vdpau: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 07/23] avutil/hwcontext_opencl: Allocate pub " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 08/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 09/23] avutil/hwcontext: Remove unused AVHWDeviceInternal.priv Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 10/23] avutil/hwcontext: Allocate AVHWDevCtx jointly with its internals Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 11/23] avutil/hwcontext_vaapi: Allocate pub and priv frames hwctx together Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 12/23] avutil/hwcontext_vulkan: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 13/23] avutil/hwcontext_videotoolbox: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 14/23] avutil/hwcontext_opencl: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 15/23] avutil/hwcontext_qsv: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 16/23] avutil/hwcontext_dxva2: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 17/23] avutil/hwcontext_d3d11va: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 18/23] avutil/hwcontext_d3d12va: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 19/23] avutil/hwcontext: Clarify documentation of AVHWFramesContext.hwctx Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 20/23] avutil/hwcontext_vdpau: Don't use AVHWFramesInternal.priv Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 21/23] avutil/hwcontext_cuda: " Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 22/23] avutil/hwcontext_internal: Remove unused AVHWFramesInternal.priv Andreas Rheinhardt
2024-02-12 0:03 ` [FFmpeg-devel] [PATCH 23/23] avutil/hwcontext: Allocate AVHWFramesCtx jointly with its internals Andreas Rheinhardt
2024-02-12 22:04 ` [FFmpeg-devel] [PATCH 01/23] avutil/hwcontext_opencl: Use proper OpenCLFramesContext Mark Thompson
2024-02-13 12:23 ` [FFmpeg-devel] [PATCH 24/24] avutil/hwcontext_cuda: Allocate public and internal device ctx jointly Andreas Rheinhardt
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git