va: refactor caps convertion to va caps

To avoid code duplication in code related with buffer importation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5257>
This commit is contained in:
Víctor Manuel Jáquez Leal 2023-08-29 20:33:33 +02:00 committed by GStreamer Marge Bot
parent 89b0a6fa23
commit 52971faf14
4 changed files with 43 additions and 59 deletions

View file

@ -26,6 +26,7 @@
#include <gst/video/video.h>
#include <gst/va/gstvavideoformat.h>
#include <gst/va/vasurfaceimage.h>
#define GST_CAT_DEFAULT (importer->debug_category)
@ -188,3 +189,35 @@ invalid_buffer:
return GST_FLOW_ERROR;
}
}
gboolean
gst_va_base_convert_caps_to_va (GstCaps * caps)
{
g_return_val_if_fail (gst_caps_is_fixed (caps), FALSE);
/* For DMA buffer, we can only import linear buffers. Replace the drm-format
* into format field. */
if (gst_video_is_dma_drm_caps (caps)) {
GstVideoInfoDmaDrm dma_info;
GstVideoInfo info;
if (!gst_video_info_dma_drm_from_caps (&dma_info, caps))
return FALSE;
if (dma_info.drm_modifier != DRM_FORMAT_MOD_LINEAR)
return FALSE;
if (!gst_va_dma_drm_info_to_video_info (&dma_info, &info))
return FALSE;
gst_caps_set_simple (caps, "format", G_TYPE_STRING,
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&info)), NULL);
gst_structure_remove_field (gst_caps_get_structure (caps, 0), "drm-format");
}
gst_caps_set_features_simple (caps,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VA));
return TRUE;
}

View file

@ -46,3 +46,5 @@ struct _GstVaBufferImporter
GstFlowReturn gst_va_buffer_importer_import (GstVaBufferImporter * base,
GstBuffer * inbuf,
GstBuffer ** outbuf);
gboolean gst_va_base_convert_caps_to_va (GstCaps * caps);

View file

@ -210,38 +210,13 @@ _get_sinkpad_pool (GstElement * element, gpointer data)
g_assert (base->input_state);
caps = gst_caps_copy (base->input_state->caps);
g_assert (gst_caps_is_fixed (caps));
/* For DMA buffer, we can only import linear buffers.
Replace the drm-format into format field. */
if (gst_video_is_dma_drm_caps (caps)) {
GstVideoInfoDmaDrm dma_info;
GstVideoInfo info;
if (!gst_video_info_dma_drm_from_caps (&dma_info, caps)) {
GST_ERROR_OBJECT (base, "Cannot parse caps %" GST_PTR_FORMAT, caps);
if (!gst_va_base_convert_caps_to_va (caps)) {
GST_ERROR_OBJECT (base, "Invalid caps %" GST_PTR_FORMAT, caps);
gst_caps_unref (caps);
return NULL;
}
if (dma_info.drm_modifier != DRM_FORMAT_MOD_LINEAR) {
GST_ERROR_OBJECT (base, "Cannot import non-linear DMA buffer");
gst_caps_unref (caps);
return NULL;
}
if (!gst_va_dma_drm_info_to_video_info (&dma_info, &info)) {
GST_ERROR_OBJECT (base, "Cannot get va video info");
gst_caps_unref (caps);
return NULL;
}
gst_caps_set_simple (caps, "format", G_TYPE_STRING,
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&info)), NULL);
gst_structure_remove_field (gst_caps_get_structure (caps, 0), "drm-format");
}
gst_caps_set_features_simple (caps,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VA));
gst_allocation_params_init (&params);
size = GST_VIDEO_INFO_SIZE (&base->input_state->info);

View file

@ -763,38 +763,12 @@ _get_sinkpad_pool (GstElement * element, gpointer data)
else
caps = gst_caps_copy (self->in_caps);
g_assert (gst_caps_is_fixed (caps));
/* For DMA buffer, we can only import linear buffers.
Replace the drm-format into format field. */
if (gst_video_is_dma_drm_caps (caps)) {
GstVideoInfoDmaDrm dma_info;
GstVideoInfo info;
if (!gst_video_info_dma_drm_from_caps (&dma_info, caps)) {
GST_ERROR_OBJECT (self, "Cannot parse caps %" GST_PTR_FORMAT, caps);
if (!gst_va_base_convert_caps_to_va (caps)) {
GST_ERROR_OBJECT (self, "Invalid caps %" GST_PTR_FORMAT, caps);
gst_caps_unref (caps);
return NULL;
}
if (dma_info.drm_modifier != DRM_FORMAT_MOD_LINEAR) {
GST_ERROR_OBJECT (self, "Cannot import non-linear DMA buffer");
gst_caps_unref (caps);
return NULL;
}
if (!gst_va_dma_drm_info_to_video_info (&dma_info, &info)) {
GST_ERROR_OBJECT (self, "Cannot get va video info");
gst_caps_unref (caps);
return NULL;
}
gst_caps_set_simple (caps, "format", G_TYPE_STRING,
gst_video_format_to_string (GST_VIDEO_INFO_FORMAT (&info)), NULL);
gst_structure_remove_field (gst_caps_get_structure (caps, 0), "drm-format");
}
gst_caps_set_features_simple (caps,
gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VA));
/* When the input buffer contains video crop meta, the real video
resolution can be bigger than the caps. The video meta should
contain the real video resolution. */