va: Use GstVideoInfoDmaDrm in DMA allocator's get/set_format() API

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4044>
This commit is contained in:
He Junyan 2023-06-14 16:32:52 +08:00 committed by GStreamer Marge Bot
parent ab9d11bc17
commit d7d25de892
5 changed files with 40 additions and 33 deletions

View file

@ -642,8 +642,8 @@ otherwise.</doc>
<type name="Gst.Allocator" c:type="GstAllocator*"/> <type name="Gst.Allocator" c:type="GstAllocator*"/>
</parameter> </parameter>
<parameter name="info" direction="out" caller-allocates="1" transfer-ownership="none" optional="1" allow-none="1"> <parameter name="info" direction="out" caller-allocates="1" transfer-ownership="none" optional="1" allow-none="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">a #GstVideoInfo</doc> <doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">a #GstVideoInfoDmaDrm</doc>
<type name="GstVideo.VideoInfo" c:type="GstVideoInfo*"/> <type name="GstVideo.VideoInfoDmaDrm" c:type="GstVideoInfoDmaDrm*"/>
</parameter> </parameter>
<parameter name="usage_hint" direction="out" caller-allocates="0" transfer-ownership="full" optional="1" allow-none="1"> <parameter name="usage_hint" direction="out" caller-allocates="0" transfer-ownership="full" optional="1" allow-none="1">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">VA usage hint</doc> <doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">VA usage hint</doc>
@ -676,9 +676,9 @@ otherwise.</doc>
@allocator, and it tries the configuration, if @allocator has not @allocator, and it tries the configuration, if @allocator has not
allocated memories yet. allocated memories yet.
If @allocator has memory allocated already, and frame size and If @allocator has memory allocated already, and frame size, format
format in @info are the same as currently configured in @allocator, and modifier in @info are the same as currently configured in
the rest of @info parameters are updated internally.</doc> @allocator, the rest of @info parameters are updated internally.</doc>
<source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.h"/> <source-position filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.h"/>
<return-value transfer-ownership="none"> <return-value transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">%TRUE if the configuration is valid or updated; %FALSE if <doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">%TRUE if the configuration is valid or updated; %FALSE if
@ -691,8 +691,8 @@ configuration is not valid or not updated.</doc>
<type name="Gst.Allocator" c:type="GstAllocator*"/> <type name="Gst.Allocator" c:type="GstAllocator*"/>
</parameter> </parameter>
<parameter name="info" direction="out" caller-allocates="1" transfer-ownership="none"> <parameter name="info" direction="out" caller-allocates="1" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">a #GstVideoInfo</doc> <doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">a #GstVideoInfoDmaDrm</doc>
<type name="GstVideo.VideoInfo" c:type="GstVideoInfo*"/> <type name="GstVideo.VideoInfoDmaDrm" c:type="GstVideoInfoDmaDrm*"/>
</parameter> </parameter>
<parameter name="usage_hint" transfer-ownership="none"> <parameter name="usage_hint" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">VA usage hint</doc> <doc xml:space="preserve" filename="../subprojects/gst-plugins-bad/gst-libs/gst/va/gstvaallocator.c">VA usage hint</doc>

View file

@ -445,6 +445,8 @@ gst_va_dmabuf_allocator_init (GstVaDmabufAllocator * self)
self->parent_copy = allocator->mem_copy; self->parent_copy = allocator->mem_copy;
allocator->mem_copy = gst_va_dmabuf_mem_copy; allocator->mem_copy = gst_va_dmabuf_mem_copy;
gst_video_info_dma_drm_init (&self->info);
gst_va_memory_pool_init (&self->pool); gst_va_memory_pool_init (&self->pool);
} }
@ -546,7 +548,7 @@ _va_create_surface_and_export_to_dmabuf (GstVaDisplay * display,
VASurfaceAttribExternalBuffers *extbuf = NULL, ext_buf; VASurfaceAttribExternalBuffers *extbuf = NULL, ext_buf;
GstVideoFormat format; GstVideoFormat format;
VASurfaceID surface; VASurfaceID surface;
guint64 prev_modifier; guint64 prev_modifier = DRM_FORMAT_MOD_INVALID;
_init_debug_category (); _init_debug_category ();
@ -691,7 +693,7 @@ gst_va_dmabuf_allocator_setup_buffer_full (GstAllocator * allocator,
g_return_val_if_fail (GST_IS_VA_DMABUF_ALLOCATOR (allocator), FALSE); g_return_val_if_fail (GST_IS_VA_DMABUF_ALLOCATOR (allocator), FALSE);
if (!_va_create_surface_and_export_to_dmabuf (self->display, self->usage_hint, if (!_va_create_surface_and_export_to_dmabuf (self->display, self->usage_hint,
NULL, 0, &self->info.vinfo, &surface, &desc)) &self->info.drm_modifier, 1, &self->info.vinfo, &surface, &desc))
return FALSE; return FALSE;
buf = gst_va_buffer_surface_new (surface); buf = gst_va_buffer_surface_new (surface);
@ -956,16 +958,16 @@ gst_va_dmabuf_allocator_try (GstAllocator * allocator)
/** /**
* gst_va_dmabuf_allocator_set_format: * gst_va_dmabuf_allocator_set_format:
* @allocator: a #GstAllocator * @allocator: a #GstAllocator
* @info: (in) (out caller-allocates) (not nullable): a #GstVideoInfo * @info: (in) (out caller-allocates) (not nullable): a #GstVideoInfoDmaDrm
* @usage_hint: VA usage hint * @usage_hint: VA usage hint
* *
* Sets the configuration defined by @info and @usage_hint for * Sets the configuration defined by @info and @usage_hint for
* @allocator, and it tries the configuration, if @allocator has not * @allocator, and it tries the configuration, if @allocator has not
* allocated memories yet. * allocated memories yet.
* *
* If @allocator has memory allocated already, and frame size and * If @allocator has memory allocated already, and frame size, format
* format in @info are the same as currently configured in @allocator, * and modifier in @info are the same as currently configured in
* the rest of @info parameters are updated internally. * @allocator, the rest of @info parameters are updated internally.
* *
* Returns: %TRUE if the configuration is valid or updated; %FALSE if * Returns: %TRUE if the configuration is valid or updated; %FALSE if
* configuration is not valid or not updated. * configuration is not valid or not updated.
@ -974,43 +976,40 @@ gst_va_dmabuf_allocator_try (GstAllocator * allocator)
*/ */
gboolean gboolean
gst_va_dmabuf_allocator_set_format (GstAllocator * allocator, gst_va_dmabuf_allocator_set_format (GstAllocator * allocator,
GstVideoInfo * info, guint usage_hint) GstVideoInfoDmaDrm * info, guint usage_hint)
{ {
GstVaDmabufAllocator *self; GstVaDmabufAllocator *self;
gboolean ret; gboolean ret;
/* TODO: change API to pass GstVideoInfoDmaDrm, though ignoring the drm
* modifier since that's set by the driver. Still we might want to pass the
* list of available modifiers by upstream for the negotiated format */
g_return_val_if_fail (GST_IS_VA_DMABUF_ALLOCATOR (allocator), FALSE); g_return_val_if_fail (GST_IS_VA_DMABUF_ALLOCATOR (allocator), FALSE);
g_return_val_if_fail (info, FALSE); g_return_val_if_fail (info, FALSE);
self = GST_VA_DMABUF_ALLOCATOR (allocator); self = GST_VA_DMABUF_ALLOCATOR (allocator);
if (gst_va_memory_pool_surface_count (&self->pool) != 0) { if (gst_va_memory_pool_surface_count (&self->pool) != 0) {
if (GST_VIDEO_INFO_FORMAT (info) if (info->drm_modifier == self->info.drm_modifier
&& GST_VIDEO_INFO_FORMAT (&info->vinfo)
== GST_VIDEO_INFO_FORMAT (&self->info.vinfo) == GST_VIDEO_INFO_FORMAT (&self->info.vinfo)
&& GST_VIDEO_INFO_WIDTH (info) && GST_VIDEO_INFO_WIDTH (&info->vinfo)
== GST_VIDEO_INFO_WIDTH (&self->info.vinfo) == GST_VIDEO_INFO_WIDTH (&self->info.vinfo)
&& GST_VIDEO_INFO_HEIGHT (info) && GST_VIDEO_INFO_HEIGHT (&info->vinfo)
== GST_VIDEO_INFO_HEIGHT (&self->info.vinfo) == GST_VIDEO_INFO_HEIGHT (&self->info.vinfo)
&& usage_hint == self->usage_hint) { && usage_hint == self->usage_hint) {
*info = self->info.vinfo; /* update callee info (offset & stride) */ *info = self->info; /* update callee info (offset & stride) */
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
self->usage_hint = usage_hint; self->usage_hint = usage_hint;
self->info.vinfo = *info; self->info = *info;
g_clear_pointer (&self->copy, gst_va_surface_copy_free); g_clear_pointer (&self->copy, gst_va_surface_copy_free);
ret = gst_va_dmabuf_allocator_try (allocator); ret = gst_va_dmabuf_allocator_try (allocator);
if (ret) if (ret)
*info = self->info.vinfo; *info = self->info;
return ret; return ret;
} }
@ -1018,7 +1017,7 @@ gst_va_dmabuf_allocator_set_format (GstAllocator * allocator,
/** /**
* gst_va_dmabuf_allocator_get_format: * gst_va_dmabuf_allocator_get_format:
* @allocator: a #GstAllocator * @allocator: a #GstAllocator
* @info: (out) (optional): a #GstVideoInfo * @info: (out) (optional): a #GstVideoInfoDmaDrm
* @usage_hint: (out) (optional): VA usage hint * @usage_hint: (out) (optional): VA usage hint
* *
* Gets current internal configuration of @allocator. * Gets current internal configuration of @allocator.
@ -1030,7 +1029,7 @@ gst_va_dmabuf_allocator_set_format (GstAllocator * allocator,
*/ */
gboolean gboolean
gst_va_dmabuf_allocator_get_format (GstAllocator * allocator, gst_va_dmabuf_allocator_get_format (GstAllocator * allocator,
GstVideoInfo * info, guint * usage_hint) GstVideoInfoDmaDrm * info, guint * usage_hint)
{ {
GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator); GstVaDmabufAllocator *self = GST_VA_DMABUF_ALLOCATOR (allocator);
@ -1038,7 +1037,7 @@ gst_va_dmabuf_allocator_get_format (GstAllocator * allocator,
return FALSE; return FALSE;
if (info) if (info)
*info = self->info.vinfo; *info = self->info;
if (usage_hint) if (usage_hint)
*usage_hint = self->usage_hint; *usage_hint = self->usage_hint;

View file

@ -49,11 +49,11 @@ GST_VA_API
void gst_va_dmabuf_allocator_flush (GstAllocator * allocator); void gst_va_dmabuf_allocator_flush (GstAllocator * allocator);
GST_VA_API GST_VA_API
gboolean gst_va_dmabuf_allocator_set_format (GstAllocator * allocator, gboolean gst_va_dmabuf_allocator_set_format (GstAllocator * allocator,
GstVideoInfo * info, GstVideoInfoDmaDrm * info,
guint usage_hint); guint usage_hint);
GST_VA_API GST_VA_API
gboolean gst_va_dmabuf_allocator_get_format (GstAllocator * allocator, gboolean gst_va_dmabuf_allocator_get_format (GstAllocator * allocator,
GstVideoInfo * info, GstVideoInfoDmaDrm * info,
guint * usage_hint); guint * usage_hint);
GST_VA_API GST_VA_API

View file

@ -426,8 +426,10 @@ gst_va_base_transform_decide_allocation (GstBaseTransform * trans,
} }
if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) { if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) {
gst_va_dmabuf_allocator_get_format (allocator, &self->priv->srcpad_info, GstVideoInfoDmaDrm dma_info;
NULL);
gst_va_dmabuf_allocator_get_format (allocator, &dma_info, NULL);
self->priv->srcpad_info = dma_info.vinfo;
} else if (GST_IS_VA_ALLOCATOR (allocator)) { } else if (GST_IS_VA_ALLOCATOR (allocator)) {
gst_va_allocator_get_format (allocator, &self->priv->srcpad_info, NULL, gst_va_allocator_get_format (allocator, &self->priv->srcpad_info, NULL,
NULL); NULL);

View file

@ -737,7 +737,10 @@ gst_va_compositor_decide_allocation (GstAggregator * agg, GstQuery * query)
} }
if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) { if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) {
gst_va_dmabuf_allocator_get_format (allocator, &vagg->info, NULL); GstVideoInfoDmaDrm dma_info;
gst_va_dmabuf_allocator_get_format (allocator, &dma_info, NULL);
vagg->info = dma_info.vinfo;
} else if (GST_IS_VA_ALLOCATOR (allocator)) { } else if (GST_IS_VA_ALLOCATOR (allocator)) {
gst_va_allocator_get_format (allocator, &vagg->info, NULL, NULL); gst_va_allocator_get_format (allocator, &vagg->info, NULL, NULL);
} }
@ -819,7 +822,10 @@ _get_sinkpad_pool (GstVaCompositor * self, GstVaCompositorPad * pad)
} }
if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) { if (GST_IS_VA_DMABUF_ALLOCATOR (allocator)) {
gst_va_dmabuf_allocator_get_format (allocator, &info, NULL); GstVideoInfoDmaDrm dma_info;
gst_va_dmabuf_allocator_get_format (allocator, &dma_info, NULL);
info = dma_info.vinfo;
} else if (GST_IS_VA_ALLOCATOR (allocator)) { } else if (GST_IS_VA_ALLOCATOR (allocator)) {
gst_va_allocator_get_format (allocator, &info, NULL, NULL); gst_va_allocator_get_format (allocator, &info, NULL, NULL);
} }