mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 11:11:08 +00:00
d3d12: Add d3d12download element
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5345>
This commit is contained in:
parent
8965b1e92f
commit
6c9d023861
7 changed files with 688 additions and 1 deletions
262
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12basefilter.cpp
Normal file
262
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12basefilter.cpp
Normal file
|
@ -0,0 +1,262 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include "gstd3d12basefilter.h"
|
||||
#include "gstd3d12device.h"
|
||||
#include "gstd3d12utils.h"
|
||||
#include "gstd3d12memory.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_d3d12_base_filter_debug);
|
||||
#define GST_CAT_DEFAULT gst_d3d12_base_filter_debug
|
||||
|
||||
#define META_TAG_VIDEO meta_tag_video_quark
|
||||
static GQuark meta_tag_video_quark;
|
||||
|
||||
#define gst_d3d12_base_filter_parent_class parent_class
|
||||
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstD3D12BaseFilter, gst_d3d12_base_filter,
|
||||
GST_TYPE_BASE_TRANSFORM,
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d12_base_filter_debug,
|
||||
"d3d12basefilter", 0, "d3d12 basefilter"));
|
||||
|
||||
static void gst_d3d12_base_filter_dispose (GObject * object);
|
||||
static void gst_d3d12_base_filter_set_context (GstElement * element,
|
||||
GstContext * context);
|
||||
static gboolean gst_d3d12_base_filter_start (GstBaseTransform * trans);
|
||||
static gboolean gst_d3d12_base_filter_stop (GstBaseTransform * trans);
|
||||
static gboolean gst_d3d12_base_filter_set_caps (GstBaseTransform * trans,
|
||||
GstCaps * incaps, GstCaps * outcaps);
|
||||
static gboolean gst_d3d12_base_filter_get_unit_size (GstBaseTransform * trans,
|
||||
GstCaps * caps, gsize * size);
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_query (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstQuery * query);
|
||||
static void gst_d3d12_base_filter_before_transform (GstBaseTransform * trans,
|
||||
GstBuffer * buffer);
|
||||
static gboolean gst_d3d12_base_filter_transform_meta (GstBaseTransform * trans,
|
||||
GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf);
|
||||
|
||||
static void
|
||||
gst_d3d12_base_filter_class_init (GstD3D12BaseFilterClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
|
||||
|
||||
gobject_class->dispose = gst_d3d12_base_filter_dispose;
|
||||
|
||||
element_class->set_context =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_set_context);
|
||||
|
||||
trans_class->start = GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_start);
|
||||
trans_class->stop = GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_stop);
|
||||
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_set_caps);
|
||||
trans_class->query = GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_query);
|
||||
trans_class->before_transform =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_before_transform);
|
||||
trans_class->transform_meta =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_base_filter_transform_meta);
|
||||
|
||||
gst_type_mark_as_plugin_api (GST_TYPE_D3D12_BASE_FILTER,
|
||||
(GstPluginAPIFlags) 0);
|
||||
meta_tag_video_quark = g_quark_from_static_string (GST_META_TAG_VIDEO_STR);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_base_filter_init (GstD3D12BaseFilter * filter)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_base_filter_dispose (GObject * object)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (object);
|
||||
|
||||
gst_clear_object (&self->device);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_base_filter_set_context (GstElement * element, GstContext * context)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (element);
|
||||
|
||||
gst_d3d12_handle_set_context (element, context, -1, &self->device);
|
||||
|
||||
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_start (GstBaseTransform * trans)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (trans);
|
||||
|
||||
if (!gst_d3d12_ensure_element_data (GST_ELEMENT_CAST (self),
|
||||
-1, &self->device)) {
|
||||
GST_ERROR_OBJECT (self, "Failed to get D3D12 device");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_stop (GstBaseTransform * trans)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (trans);
|
||||
|
||||
gst_clear_object (&self->device);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
||||
GstCaps * outcaps)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (trans);
|
||||
GstVideoInfo in_info, out_info;
|
||||
GstD3D12BaseFilterClass *klass;
|
||||
gboolean res;
|
||||
|
||||
if (!self->device) {
|
||||
GST_ERROR_OBJECT (self, "No available D3D12 device");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_video_info_from_caps (&in_info, incaps)) {
|
||||
GST_ERROR_OBJECT (self, "Invalid input caps %" GST_PTR_FORMAT, incaps);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_video_info_from_caps (&out_info, outcaps)) {
|
||||
GST_ERROR_OBJECT (self, "Invalid output caps %" GST_PTR_FORMAT, outcaps);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
klass = GST_D3D12_BASE_FILTER_GET_CLASS (self);
|
||||
if (klass->set_info)
|
||||
res = klass->set_info (self, incaps, &in_info, outcaps, &out_info);
|
||||
else
|
||||
res = TRUE;
|
||||
|
||||
if (res) {
|
||||
self->in_info = in_info;
|
||||
self->out_info = out_info;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_query (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstQuery * query)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (trans);
|
||||
|
||||
switch (GST_QUERY_TYPE (query)) {
|
||||
case GST_QUERY_CONTEXT:
|
||||
{
|
||||
if (gst_d3d12_handle_context_query (GST_ELEMENT (self), query,
|
||||
self->device)) {
|
||||
return TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return GST_BASE_TRANSFORM_CLASS (parent_class)->query (trans, direction,
|
||||
query);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_base_filter_before_transform (GstBaseTransform * trans,
|
||||
GstBuffer * buffer)
|
||||
{
|
||||
GstD3D12BaseFilter *self = GST_D3D12_BASE_FILTER (trans);
|
||||
GstD3D12Memory *dmem;
|
||||
GstMemory *mem;
|
||||
GstCaps *in_caps = nullptr;
|
||||
GstCaps *out_caps = nullptr;
|
||||
|
||||
mem = gst_buffer_peek_memory (buffer, 0);
|
||||
if (!gst_is_d3d12_memory (mem))
|
||||
return;
|
||||
|
||||
dmem = GST_D3D12_MEMORY_CAST (mem);
|
||||
/* d3d12 devices are singletons per adapter */
|
||||
if (dmem->device == self->device)
|
||||
return;
|
||||
|
||||
GST_INFO_OBJECT (self, "Updating device %" GST_PTR_FORMAT " -> %"
|
||||
GST_PTR_FORMAT, self->device, dmem->device);
|
||||
|
||||
gst_object_unref (self->device);
|
||||
self->device = (GstD3D12Device *) gst_object_ref (dmem->device);
|
||||
|
||||
in_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SINK_PAD (trans));
|
||||
if (!in_caps) {
|
||||
GST_WARNING_OBJECT (self, "sinkpad has null caps");
|
||||
goto out;
|
||||
}
|
||||
|
||||
out_caps = gst_pad_get_current_caps (GST_BASE_TRANSFORM_SRC_PAD (trans));
|
||||
if (!out_caps) {
|
||||
GST_WARNING_OBJECT (self, "Has no configured output caps");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* subclass will update internal object.
|
||||
* Note that gst_base_transform_reconfigure() might not trigger this
|
||||
* unless caps was changed meanwhile */
|
||||
gst_d3d12_base_filter_set_caps (trans, in_caps, out_caps);
|
||||
|
||||
/* Mark reconfigure so that we can update pool */
|
||||
gst_base_transform_reconfigure_src (trans);
|
||||
|
||||
out:
|
||||
gst_clear_caps (&in_caps);
|
||||
gst_clear_caps (&out_caps);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_base_filter_transform_meta (GstBaseTransform * trans,
|
||||
GstBuffer * outbuf, GstMeta * meta, GstBuffer * inbuf)
|
||||
{
|
||||
const GstMetaInfo *info = meta->info;
|
||||
const gchar *const *tags;
|
||||
|
||||
tags = gst_meta_api_type_get_tags (info->api);
|
||||
|
||||
if (!tags || (g_strv_length ((gchar **) tags) == 1
|
||||
&& gst_meta_api_type_has_tag (info->api, META_TAG_VIDEO))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return GST_BASE_TRANSFORM_CLASS (parent_class)->transform_meta (trans, outbuf,
|
||||
meta, inbuf);
|
||||
}
|
65
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12basefilter.h
Normal file
65
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12basefilter.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include <gst/base/gstbasetransform.h>
|
||||
#include "gstd3d12_fwd.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_D3D12_BASE_FILTER (gst_d3d12_base_filter_get_type())
|
||||
#define GST_D3D12_BASE_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D12_BASE_FILTER,GstD3D12BaseFilter))
|
||||
#define GST_D3D12_BASE_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_D3D12_BASE_FILTER,GstD3D12BaseFilterClass))
|
||||
#define GST_D3D12_BASE_FILTER_GET_CLASS(obj) (GST_D3D12_BASE_FILTER_CLASS(G_OBJECT_GET_CLASS(obj)))
|
||||
#define GST_IS_D3D12_BASE_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D12_BASE_FILTER))
|
||||
#define GST_IS_D3D12_BASE_FILTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_D3D12_BASE_FILTER))
|
||||
|
||||
typedef struct _GstD3D12BaseFilter GstD3D12BaseFilter;
|
||||
typedef struct _GstD3D12BaseFilterClass GstD3D12BaseFilterClass;
|
||||
|
||||
struct _GstD3D12BaseFilter
|
||||
{
|
||||
GstBaseTransform parent;
|
||||
|
||||
GstD3D12Device *device;
|
||||
|
||||
GstVideoInfo in_info;
|
||||
GstVideoInfo out_info;
|
||||
};
|
||||
|
||||
struct _GstD3D12BaseFilterClass
|
||||
{
|
||||
GstBaseTransformClass parent_class;
|
||||
|
||||
gboolean (*set_info) (GstD3D12BaseFilter * filter,
|
||||
GstCaps * in_caps,
|
||||
GstVideoInfo * in_info,
|
||||
GstCaps * out_caps,
|
||||
GstVideoInfo * out_info);
|
||||
};
|
||||
|
||||
GType gst_d3d12_base_filter_get_type (void);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GstD3D12BaseFilter, gst_object_unref)
|
||||
|
||||
G_END_DECLS
|
||||
|
323
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12download.cpp
Normal file
323
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12download.cpp
Normal file
|
@ -0,0 +1,323 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "gstd3d12download.h"
|
||||
#include "gstd3d12bufferpool.h"
|
||||
#include "gstd3d12format.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_d3d12_download_debug);
|
||||
#define GST_CAT_DEFAULT gst_d3d12_download_debug
|
||||
|
||||
static GstStaticPadTemplate sink_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY, GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY ","
|
||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
|
||||
GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE (GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY ","
|
||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
|
||||
GST_D3D12_ALL_FORMATS)));
|
||||
|
||||
static GstStaticPadTemplate src_template =
|
||||
GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY, GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY ","
|
||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
|
||||
GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE (GST_D3D12_ALL_FORMATS) "; "
|
||||
GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
||||
(GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY ","
|
||||
GST_CAPS_FEATURE_META_GST_VIDEO_OVERLAY_COMPOSITION,
|
||||
GST_D3D12_ALL_FORMATS)));
|
||||
|
||||
struct _GstD3D12Download
|
||||
{
|
||||
GstD3D12BaseFilter parent;
|
||||
};
|
||||
|
||||
#define gst_d3d12_download_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstD3D12Download, gst_d3d12_download,
|
||||
GST_TYPE_D3D12_BASE_FILTER);
|
||||
|
||||
static GstCaps *gst_d3d12_download_transform_caps (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
||||
static gboolean gst_d3d12_download_propose_allocation (GstBaseTransform * trans,
|
||||
GstQuery * decide_query, GstQuery * query);
|
||||
static gboolean gst_d3d12_download_decide_allocation (GstBaseTransform * trans,
|
||||
GstQuery * query);
|
||||
static GstFlowReturn gst_d3d12_download_transform (GstBaseTransform * trans,
|
||||
GstBuffer * inbuf, GstBuffer * outbuf);
|
||||
|
||||
static void
|
||||
gst_d3d12_download_class_init (GstD3D12DownloadClass * klass)
|
||||
{
|
||||
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||
GstBaseTransformClass *trans_class = GST_BASE_TRANSFORM_CLASS (klass);
|
||||
|
||||
gst_element_class_add_static_pad_template (element_class, &sink_template);
|
||||
gst_element_class_add_static_pad_template (element_class, &src_template);
|
||||
|
||||
gst_element_class_set_static_metadata (element_class,
|
||||
"Direct3D12 Downloader", "Filter/Video",
|
||||
"Downloads Direct3D12 texture memory into system memory",
|
||||
"Seungha Yang <seungha@centricular.com>");
|
||||
|
||||
trans_class->passthrough_on_same_caps = TRUE;
|
||||
|
||||
trans_class->transform_caps =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_download_transform_caps);
|
||||
trans_class->propose_allocation =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_download_propose_allocation);
|
||||
trans_class->decide_allocation =
|
||||
GST_DEBUG_FUNCPTR (gst_d3d12_download_decide_allocation);
|
||||
trans_class->transform = GST_DEBUG_FUNCPTR (gst_d3d12_download_transform);
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_d3d12_download_debug,
|
||||
"d3d12download", 0, "d3d12download Element");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_download_init (GstD3D12Download * self)
|
||||
{
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
_set_caps_features (const GstCaps * caps, const gchar * feature_name)
|
||||
{
|
||||
GstCaps *tmp = gst_caps_copy (caps);
|
||||
guint n = gst_caps_get_size (tmp);
|
||||
guint i = 0;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
gst_caps_set_features (tmp, i,
|
||||
gst_caps_features_from_string (feature_name));
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
gst_d3d12_download_transform_caps (GstBaseTransform * trans,
|
||||
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
||||
{
|
||||
GstCaps *result, *tmp;
|
||||
|
||||
GST_DEBUG_OBJECT (trans,
|
||||
"Transforming caps %" GST_PTR_FORMAT " in direction %s", caps,
|
||||
(direction == GST_PAD_SINK) ? "sink" : "src");
|
||||
|
||||
if (direction == GST_PAD_SINK) {
|
||||
tmp = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_SYSTEM_MEMORY);
|
||||
tmp = gst_caps_merge (gst_caps_ref (caps), tmp);
|
||||
} else {
|
||||
GstCaps *newcaps;
|
||||
tmp = gst_caps_ref (caps);
|
||||
|
||||
newcaps = _set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY);
|
||||
tmp = gst_caps_merge (tmp, newcaps);
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
||||
gst_caps_unref (tmp);
|
||||
} else {
|
||||
result = tmp;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_download_propose_allocation (GstBaseTransform * trans,
|
||||
GstQuery * decide_query, GstQuery * query)
|
||||
{
|
||||
GstD3D12BaseFilter *filter = GST_D3D12_BASE_FILTER (trans);
|
||||
GstVideoInfo info;
|
||||
GstBufferPool *pool;
|
||||
GstCaps *caps;
|
||||
guint size;
|
||||
gboolean is_d3d12 = FALSE;
|
||||
|
||||
if (!GST_BASE_TRANSFORM_CLASS (parent_class)->propose_allocation (trans,
|
||||
decide_query, query))
|
||||
return FALSE;
|
||||
|
||||
/* passthrough, we're done */
|
||||
if (!decide_query)
|
||||
return TRUE;
|
||||
|
||||
gst_query_parse_allocation (query, &caps, nullptr);
|
||||
|
||||
if (!caps) {
|
||||
GST_WARNING_OBJECT (filter, "Allocation query without caps");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_video_info_from_caps (&info, caps))
|
||||
return FALSE;
|
||||
|
||||
if (gst_query_get_n_allocation_pools (query) == 0) {
|
||||
GstCapsFeatures *features;
|
||||
GstStructure *config;
|
||||
|
||||
features = gst_caps_get_features (caps, 0);
|
||||
|
||||
if (features && gst_caps_features_contains (features,
|
||||
GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY)) {
|
||||
GST_DEBUG_OBJECT (filter, "upstream support d3d12 memory");
|
||||
pool = gst_d3d12_buffer_pool_new (filter->device);
|
||||
is_d3d12 = TRUE;
|
||||
} else {
|
||||
pool = gst_video_buffer_pool_new ();
|
||||
}
|
||||
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
|
||||
gst_buffer_pool_config_add_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
if (!is_d3d12) {
|
||||
gst_buffer_pool_config_add_option (config,
|
||||
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
||||
}
|
||||
|
||||
size = GST_VIDEO_INFO_SIZE (&info);
|
||||
gst_buffer_pool_config_set_params (config, caps, size, 0, 0);
|
||||
|
||||
if (!gst_buffer_pool_set_config (pool, config)) {
|
||||
GST_ERROR_OBJECT (filter, "Bufferpool config failed");
|
||||
gst_object_unref (pool);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* d3d12 buffer pool will update buffer size based on allocated texture,
|
||||
* get size from config again */
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_get_params (config,
|
||||
nullptr, &size, nullptr, nullptr);
|
||||
gst_structure_free (config);
|
||||
|
||||
gst_query_add_allocation_pool (query, pool, size, 0, 0);
|
||||
gst_object_unref (pool);
|
||||
}
|
||||
|
||||
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, nullptr);
|
||||
gst_query_add_allocation_meta (query,
|
||||
GST_VIDEO_OVERLAY_COMPOSITION_META_API_TYPE, nullptr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_d3d12_download_decide_allocation (GstBaseTransform * trans,
|
||||
GstQuery * query)
|
||||
{
|
||||
GstBufferPool *pool = nullptr;
|
||||
GstStructure *config;
|
||||
guint min, max, size;
|
||||
gboolean update_pool;
|
||||
GstCaps *outcaps = nullptr;
|
||||
|
||||
gst_query_parse_allocation (query, &outcaps, nullptr);
|
||||
|
||||
if (!outcaps) {
|
||||
GST_WARNING_OBJECT (trans, "Allocation query without caps");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (gst_query_get_n_allocation_pools (query) > 0) {
|
||||
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
|
||||
|
||||
update_pool = TRUE;
|
||||
} else {
|
||||
GstVideoInfo vinfo;
|
||||
|
||||
gst_video_info_from_caps (&vinfo, outcaps);
|
||||
size = vinfo.size;
|
||||
min = max = 0;
|
||||
update_pool = FALSE;
|
||||
}
|
||||
|
||||
if (!pool) {
|
||||
pool = gst_video_buffer_pool_new ();
|
||||
}
|
||||
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_add_option (config, GST_BUFFER_POOL_OPTION_VIDEO_META);
|
||||
gst_buffer_pool_config_set_params (config, outcaps, size, min, max);
|
||||
gst_buffer_pool_set_config (pool, config);
|
||||
|
||||
/* d3d12 buffer pool will update buffer size based on allocated texture,
|
||||
* get size from config again */
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_get_params (config, nullptr, &size, nullptr, nullptr);
|
||||
gst_structure_free (config);
|
||||
|
||||
if (update_pool)
|
||||
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
|
||||
else
|
||||
gst_query_add_allocation_pool (query, pool, size, min, max);
|
||||
|
||||
gst_object_unref (pool);
|
||||
|
||||
return GST_BASE_TRANSFORM_CLASS (parent_class)->decide_allocation (trans,
|
||||
query);
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
gst_d3d12_download_transform (GstBaseTransform * trans, GstBuffer * inbuf,
|
||||
GstBuffer * outbuf)
|
||||
{
|
||||
GstD3D12BaseFilter *filter = GST_D3D12_BASE_FILTER (trans);
|
||||
GstVideoFrame in_frame, out_frame;
|
||||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
|
||||
if (!gst_video_frame_map (&in_frame, &filter->in_info, inbuf, GST_MAP_READ)) {
|
||||
GST_ERROR_OBJECT (filter, "Couldn't map input frame");
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
if (!gst_video_frame_map (&out_frame,
|
||||
&filter->out_info, outbuf, GST_MAP_WRITE)) {
|
||||
GST_ERROR_OBJECT (filter, "Couldn't map output frame");
|
||||
gst_video_frame_unmap (&in_frame);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
if (!gst_video_frame_copy (&out_frame, &in_frame)) {
|
||||
GST_ERROR_OBJECT (filter, "Copy failed");
|
||||
ret = GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
gst_video_frame_unmap (&out_frame);
|
||||
gst_video_frame_unmap (&in_frame);
|
||||
|
||||
return ret;
|
||||
}
|
31
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12download.h
Normal file
31
subprojects/gst-plugins-bad/sys/d3d12/gstd3d12download.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gstd3d12basefilter.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_D3D12_DOWNLOAD (gst_d3d12_download_get_type())
|
||||
G_DECLARE_FINAL_TYPE (GstD3D12Download,
|
||||
gst_d3d12_download, GST, D3D12_DOWNLOAD, GstD3D12BaseFilter);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
@ -34,7 +34,7 @@ G_BEGIN_DECLS
|
|||
#define GST_D3D12_SRC_FORMATS \
|
||||
"{ " GST_D3D12_COMMON_FORMATS " }"
|
||||
|
||||
#define GST_D3D12_FORMATS_ALL \
|
||||
#define GST_D3D12_ALL_FORMATS \
|
||||
"{ " GST_D3D12_COMMON_FORMATS " }"
|
||||
|
||||
struct _GstD3D12Format
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
d3d12_sources = [
|
||||
'gstd3d12av1dec.cpp',
|
||||
'gstd3d12basefilter.cpp',
|
||||
'gstd3d12bufferpool.cpp',
|
||||
'gstd3d12decoder.cpp',
|
||||
'gstd3d12device.cpp',
|
||||
'gstd3d12download.cpp',
|
||||
'gstd3d12fence.cpp',
|
||||
'gstd3d12format.cpp',
|
||||
'gstd3d12h264dec.cpp',
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
#include "gstd3d12device.h"
|
||||
#include "gstd3d12download.h"
|
||||
#include "gstd3d12h264dec.h"
|
||||
#include "gstd3d12h265dec.h"
|
||||
#include "gstd3d12vp9dec.h"
|
||||
|
@ -93,6 +94,9 @@ plugin_init (GstPlugin * plugin)
|
|||
gst_object_unref (device);
|
||||
}
|
||||
|
||||
gst_element_register (plugin,
|
||||
"d3d12download", GST_RANK_NONE, GST_TYPE_D3D12_DOWNLOAD);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue