diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabase.c b/subprojects/gst-plugins-bad/sys/va/gstvabase.c index d8f0975166..7e766bbc64 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabase.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabase.c @@ -26,6 +26,7 @@ #include +#include #include #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; +} diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabase.h b/subprojects/gst-plugins-bad/sys/va/gstvabase.h index 229d6c3c22..a4e97b847c 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabase.h +++ b/subprojects/gst-plugins-bad/sys/va/gstvabase.h @@ -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); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c index 1111850bc0..5b2d84f967 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabaseenc.c @@ -210,37 +210,12 @@ _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); - 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"); + 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; } - gst_caps_set_features_simple (caps, - gst_caps_features_from_string (GST_CAPS_FEATURE_MEMORY_VA)); gst_allocation_params_init (¶ms); diff --git a/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c b/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c index f5d145d353..be57878ab7 100644 --- a/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c +++ b/subprojects/gst-plugins-bad/sys/va/gstvabasetransform.c @@ -763,37 +763,11 @@ _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); - 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"); + 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; } - 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