diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.c new file mode 100644 index 0000000000..03adc44575 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.c @@ -0,0 +1,49 @@ +/* GStreamer Intel MSDK plugin + * Copyright (c) 2023, Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "gstmsdkcaps.h" + +gboolean +gst_msdkcaps_has_feature (const GstCaps * caps, const gchar * feature) +{ + guint i; + + for (i = 0; i < gst_caps_get_size (caps); i++) { + GstCapsFeatures *const features = gst_caps_get_features (caps, i); + /* Skip ANY features, we need an exact match for correct evaluation */ + if (gst_caps_features_is_any (features)) + continue; + if (gst_caps_features_contains (features, feature)) + return TRUE; + } + + return FALSE; +} diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.h new file mode 100644 index 0000000000..018cd2f0dd --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkcaps.h @@ -0,0 +1,46 @@ +/* GStreamer Intel MSDK plugin + * Copyright (c) 2023, Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __GST_MSDKCAPS_H__ +#define __GST_MSDKCAPS_H__ + +#include "msdk.h" +#include +#include + +G_BEGIN_DECLS + +gboolean +gst_msdkcaps_has_feature (const GstCaps * caps, const gchar * feature); + +G_END_DECLS + +#endif /* __GST_MSDKCAPS_H__ */ diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c index 178ca9e097..b32e00d8de 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.c @@ -514,24 +514,6 @@ failed: return FALSE; } - -static gboolean -_gst_caps_has_feature (const GstCaps * caps, const gchar * feature) -{ - guint i; - - for (i = 0; i < gst_caps_get_size (caps); i++) { - GstCapsFeatures *const features = gst_caps_get_features (caps, i); - /* Skip ANY features, we need an exact match for correct evaluation */ - if (gst_caps_features_is_any (features)) - continue; - if (gst_caps_features_contains (features, feature)) - return TRUE; - } - - return FALSE; -} - static gboolean pad_accept_memory (GstMsdkDec * thiz, const gchar * mem_type, GstCaps * filter) { @@ -553,7 +535,7 @@ pad_accept_memory (GstMsdkDec * thiz, const gchar * mem_type, GstCaps * filter) if (gst_caps_is_any (out_caps) || gst_caps_is_empty (out_caps)) goto done; - if (_gst_caps_has_feature (out_caps, mem_type)) + if (gst_msdkcaps_has_feature (out_caps, mem_type)) ret = TRUE; done: if (caps) @@ -1819,7 +1801,7 @@ gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) /* this will get updated with msdk requirement */ thiz->min_prealloc_buffers = min_buffers; - if (_gst_caps_has_feature (pool_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { + if (gst_msdkcaps_has_feature (pool_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { thiz->use_dmabuf = TRUE; } /* Decoder always use its own pool. So we create a pool if msdk APIs @@ -1915,7 +1897,7 @@ gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) min_buffers = thiz->min_prealloc_buffers; if (!has_videometa && !thiz->ds_has_known_allocator - && _gst_caps_has_feature (pool_caps, + && gst_msdkcaps_has_feature (pool_caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY)) { /* We need to create other pool with system memory for copy use under conditions: * (1) downstream has no videometa; (2) downstream allocator is unknown; diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h index 28bd4554e3..4e00278380 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkdec.h @@ -38,6 +38,7 @@ #include "gstmsdkcontext.h" #include "msdk-enums.h" #include "gstmsdkdecproputil.h" +#include "gstmsdkcaps.h" G_BEGIN_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c index d8d7547e5b..abeeb6c784 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.c @@ -1456,24 +1456,6 @@ error_pool_config: } } -/* Fixme: Common routine used by all msdk elements, should be - * moved to a common util file */ -static gboolean -_gst_caps_has_feature (const GstCaps * caps, const gchar * feature) -{ - guint i; - - for (i = 0; i < gst_caps_get_size (caps); i++) { - GstCapsFeatures *const features = gst_caps_get_features (caps, i); - /* Skip ANY features, we need an exact match for correct evaluation */ - if (gst_caps_features_is_any (features)) - continue; - if (gst_caps_features_contains (features, feature)) - return TRUE; - } - return FALSE; -} - static gboolean sinkpad_can_dmabuf (GstMsdkEnc * thiz) { @@ -1491,7 +1473,7 @@ sinkpad_can_dmabuf (GstMsdkEnc * thiz) || allowed_caps == caps) goto done; - if (_gst_caps_has_feature (allowed_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) + if (gst_msdkcaps_has_feature (allowed_caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) ret = TRUE; done: @@ -2053,7 +2035,7 @@ gst_msdkenc_propose_allocation (GstVideoEncoder * encoder, GstQuery * query) /* if upstream allocation query supports dmabuf-capsfeatures, * we do allocate dmabuf backed memory */ - if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { + if (gst_msdkcaps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory"); thiz->use_dmabuf = TRUE; } diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h index 52b79c8636..abefdbe2d7 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkenc.h @@ -37,6 +37,7 @@ #include "msdk.h" #include "msdk-enums.h" #include "gstmsdkcontext.h" +#include "gstmsdkcaps.h" G_BEGIN_DECLS diff --git a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c index b5692c967b..120f6dc5a0 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c +++ b/subprojects/gst-plugins-bad/sys/msdk/gstmsdkvpp.c @@ -54,6 +54,7 @@ #include #include "gstmsdkvpp.h" +#include "gstmsdkcaps.h" #include "gstmsdkcontextutil.h" #include "gstmsdkvpputil.h" #include "gstmsdkallocator.h" @@ -598,22 +599,6 @@ error_pool_config: } } -static gboolean -_gst_caps_has_feature (const GstCaps * caps, const gchar * feature) -{ - guint i; - - for (i = 0; i < gst_caps_get_size (caps); i++) { - GstCapsFeatures *const features = gst_caps_get_features (caps, i); - /* Skip ANY features, we need an exact match for correct evaluation */ - if (gst_caps_features_is_any (features)) - continue; - if (gst_caps_features_contains (features, feature)) - return TRUE; - } - return FALSE; -} - static GstBufferPool * create_src_pool (GstMsdkVPP * thiz, GstQuery * query, GstCaps * caps) { @@ -688,7 +673,7 @@ gst_msdkvpp_decide_allocation (GstBaseTransform * trans, GstQuery * query) } /* We allocate the memory of type that downstream allocation requests */ #ifndef _WIN32 - if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { + if (gst_msdkcaps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory"); thiz->use_srcpad_dmabuf = TRUE; } @@ -740,7 +725,7 @@ gst_msdkvpp_propose_allocation (GstBaseTransform * trans, /* if upstream allocation query supports dmabuf-capsfeatures, * we do allocate dmabuf backed memory */ - if (_gst_caps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { + if (gst_msdkcaps_has_feature (caps, GST_CAPS_FEATURE_MEMORY_DMABUF)) { GST_INFO_OBJECT (thiz, "MSDK VPP srcpad uses DMABuf memory"); thiz->use_sinkpad_dmabuf = TRUE; } @@ -1412,7 +1397,7 @@ pad_accept_memory (GstMsdkVPP * thiz, const gchar * mem_type, || out_caps == caps) goto done; - if (_gst_caps_has_feature (out_caps, mem_type)) + if (gst_msdkcaps_has_feature (out_caps, mem_type)) ret = TRUE; done: if (caps) diff --git a/subprojects/gst-plugins-bad/sys/msdk/meson.build b/subprojects/gst-plugins-bad/sys/msdk/meson.build index f71c5f4e67..f1710f3fba 100644 --- a/subprojects/gst-plugins-bad/sys/msdk/meson.build +++ b/subprojects/gst-plugins-bad/sys/msdk/meson.build @@ -1,6 +1,7 @@ msdk_sources = [ 'gstmsdk.c', 'gstmsdkallocator.c', + 'gstmsdkcaps.c', 'gstmsdkcontext.c', 'gstmsdkcontextutil.c', 'gstmsdkdec.c',