mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-26 11:41:09 +00:00
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:
parent
89b0a6fa23
commit
52971faf14
4 changed files with 43 additions and 59 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
|
#include <gst/va/gstvavideoformat.h>
|
||||||
#include <gst/va/vasurfaceimage.h>
|
#include <gst/va/vasurfaceimage.h>
|
||||||
|
|
||||||
#define GST_CAT_DEFAULT (importer->debug_category)
|
#define GST_CAT_DEFAULT (importer->debug_category)
|
||||||
|
@ -188,3 +189,35 @@ invalid_buffer:
|
||||||
return GST_FLOW_ERROR;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -46,3 +46,5 @@ struct _GstVaBufferImporter
|
||||||
GstFlowReturn gst_va_buffer_importer_import (GstVaBufferImporter * base,
|
GstFlowReturn gst_va_buffer_importer_import (GstVaBufferImporter * base,
|
||||||
GstBuffer * inbuf,
|
GstBuffer * inbuf,
|
||||||
GstBuffer ** outbuf);
|
GstBuffer ** outbuf);
|
||||||
|
|
||||||
|
gboolean gst_va_base_convert_caps_to_va (GstCaps * caps);
|
||||||
|
|
|
@ -210,37 +210,12 @@ _get_sinkpad_pool (GstElement * element, gpointer data)
|
||||||
|
|
||||||
g_assert (base->input_state);
|
g_assert (base->input_state);
|
||||||
caps = gst_caps_copy (base->input_state->caps);
|
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)) {
|
if (!gst_va_base_convert_caps_to_va (caps)) {
|
||||||
GST_ERROR_OBJECT (base, "Cannot parse caps %" GST_PTR_FORMAT, caps);
|
GST_ERROR_OBJECT (base, "Invalid caps %" GST_PTR_FORMAT, caps);
|
||||||
gst_caps_unref (caps);
|
gst_caps_unref (caps);
|
||||||
return NULL;
|
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 (¶ms);
|
gst_allocation_params_init (¶ms);
|
||||||
|
|
||||||
|
|
|
@ -763,37 +763,11 @@ _get_sinkpad_pool (GstElement * element, gpointer data)
|
||||||
else
|
else
|
||||||
caps = gst_caps_copy (self->in_caps);
|
caps = gst_caps_copy (self->in_caps);
|
||||||
|
|
||||||
g_assert (gst_caps_is_fixed (caps));
|
if (!gst_va_base_convert_caps_to_va (caps)) {
|
||||||
/* For DMA buffer, we can only import linear buffers.
|
GST_ERROR_OBJECT (self, "Invalid caps %" GST_PTR_FORMAT, caps);
|
||||||
Replace the drm-format into format field. */
|
gst_caps_unref (caps);
|
||||||
if (gst_video_is_dma_drm_caps (caps)) {
|
return NULL;
|
||||||
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);
|
|
||||||
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
|
/* When the input buffer contains video crop meta, the real video
|
||||||
resolution can be bigger than the caps. The video meta should
|
resolution can be bigger than the caps. The video meta should
|
||||||
|
|
Loading…
Reference in a new issue