2020-01-10 14:54:43 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <2020> Seungha Yang <seungha.yang@navercorp.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 "gstd3d11videoprocessor.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_video_processor_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_d3d11_video_processor_debug
|
|
|
|
|
|
|
|
struct _GstD3D11VideoProcessor
|
|
|
|
{
|
|
|
|
GstD3D11Device *device;
|
|
|
|
|
|
|
|
ID3D11VideoDevice *video_device;
|
|
|
|
ID3D11VideoContext *video_context;
|
|
|
|
ID3D11VideoContext1 *video_context1;
|
|
|
|
ID3D11VideoContext2 *video_context2;
|
|
|
|
ID3D11VideoProcessor *processor;
|
|
|
|
ID3D11VideoProcessorEnumerator *enumerator;
|
2020-10-25 20:09:40 +00:00
|
|
|
ID3D11VideoProcessorEnumerator1 *enumerator1;
|
2020-01-10 14:54:43 +00:00
|
|
|
D3D11_VIDEO_PROCESSOR_CAPS processor_caps;
|
|
|
|
};
|
|
|
|
|
|
|
|
GstD3D11VideoProcessor *
|
|
|
|
gst_d3d11_video_processor_new (GstD3D11Device * device, guint in_width,
|
|
|
|
guint in_height, guint out_width, guint out_height)
|
|
|
|
{
|
|
|
|
GstD3D11VideoProcessor *self;
|
2021-03-13 13:47:55 +00:00
|
|
|
ID3D11VideoDevice *video_device;
|
|
|
|
ID3D11VideoContext *video_context;
|
2020-01-10 14:54:43 +00:00
|
|
|
HRESULT hr;
|
2021-03-13 08:40:57 +00:00
|
|
|
D3D11_VIDEO_PROCESSOR_CONTENT_DESC desc;
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
|
|
|
|
|
2021-03-13 13:47:55 +00:00
|
|
|
video_device = gst_d3d11_device_get_video_device_handle (device);
|
|
|
|
if (!video_device) {
|
|
|
|
GST_WARNING_OBJECT (device, "ID3D11VideoDevice is not available");
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-03-13 08:40:57 +00:00
|
|
|
|
2021-03-13 13:47:55 +00:00
|
|
|
video_context = gst_d3d11_device_get_video_context_handle (device);
|
|
|
|
if (!video_context) {
|
|
|
|
GST_WARNING_OBJECT (device, "ID3D11VideoContext is not availale");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset (&desc, 0, sizeof (desc));
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
self = g_new0 (GstD3D11VideoProcessor, 1);
|
2021-03-13 08:40:57 +00:00
|
|
|
self->device = (GstD3D11Device *) gst_object_ref (device);
|
2020-01-10 14:54:43 +00:00
|
|
|
|
2021-03-13 13:47:55 +00:00
|
|
|
self->video_device = video_device;
|
|
|
|
video_device->AddRef ();
|
2020-01-10 14:54:43 +00:00
|
|
|
|
2021-03-13 13:47:55 +00:00
|
|
|
self->video_context = video_context;
|
|
|
|
video_context->AddRef ();
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
/* FIXME: Add support intelace */
|
|
|
|
desc.InputFrameFormat = D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE;
|
|
|
|
desc.InputWidth = in_width;
|
|
|
|
desc.InputHeight = in_height;
|
|
|
|
desc.OutputWidth = out_width;
|
|
|
|
desc.OutputHeight = out_height;
|
|
|
|
/* TODO: make option for this */
|
|
|
|
desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->video_device->CreateVideoProcessorEnumerator (&desc,
|
|
|
|
&self->enumerator);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, device))
|
|
|
|
goto fail;
|
2022-02-10 13:31:06 +00:00
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->enumerator->QueryInterface (IID_PPV_ARGS (&self->enumerator1));
|
2020-10-25 20:09:40 +00:00
|
|
|
if (gst_d3d11_result (hr, device)) {
|
|
|
|
GST_DEBUG ("ID3D11VideoProcessorEnumerator1 interface available");
|
|
|
|
}
|
2020-01-10 14:54:43 +00:00
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->enumerator->GetVideoProcessorCaps (&self->processor_caps);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, device))
|
|
|
|
goto fail;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->video_device->CreateVideoProcessor (self->enumerator, 0,
|
|
|
|
&self->processor);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, device))
|
|
|
|
goto fail;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->video_context->
|
|
|
|
QueryInterface (IID_PPV_ARGS (&self->video_context1));
|
2020-01-10 14:54:43 +00:00
|
|
|
if (gst_d3d11_result (hr, device)) {
|
|
|
|
GST_DEBUG ("ID3D11VideoContext1 interface available");
|
|
|
|
}
|
2022-02-10 13:31:06 +00:00
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->video_context->
|
|
|
|
QueryInterface (IID_PPV_ARGS (&self->video_context2));
|
2020-01-10 14:54:43 +00:00
|
|
|
if (gst_d3d11_result (hr, device)) {
|
|
|
|
GST_DEBUG ("ID3D11VideoContext2 interface available");
|
|
|
|
}
|
|
|
|
|
2021-03-02 09:07:36 +00:00
|
|
|
/* Setting up default options */
|
2021-03-20 07:15:35 +00:00
|
|
|
gst_d3d11_device_lock (self->device);
|
2021-03-02 09:07:36 +00:00
|
|
|
/* We don't want auto processing by driver */
|
2021-03-13 08:40:57 +00:00
|
|
|
self->video_context->VideoProcessorSetStreamAutoProcessingMode
|
|
|
|
(self->processor, 0, FALSE);
|
2021-03-20 07:15:35 +00:00
|
|
|
gst_d3d11_device_unlock (self->device);
|
2021-03-02 09:07:36 +00:00
|
|
|
|
2020-01-10 14:54:43 +00:00
|
|
|
return self;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
gst_d3d11_video_processor_free (self);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_d3d11_video_processor_free (GstD3D11VideoProcessor * processor)
|
|
|
|
{
|
|
|
|
g_return_if_fail (processor != NULL);
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
GST_D3D11_CLEAR_COM (processor->video_device);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->video_context);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->video_context1);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->video_context2);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->processor);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->enumerator);
|
|
|
|
GST_D3D11_CLEAR_COM (processor->enumerator1);
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
gst_clear_object (&processor->device);
|
|
|
|
g_free (processor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_video_processor_supports_format (GstD3D11VideoProcessor *
|
|
|
|
self, DXGI_FORMAT format, gboolean is_input)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2020-10-27 15:47:49 +00:00
|
|
|
UINT flag = 0;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = self->enumerator->CheckVideoProcessorFormat (format, &flag);
|
2020-10-27 15:47:49 +00:00
|
|
|
|
|
|
|
if (!gst_d3d11_result (hr, self->device))
|
|
|
|
return FALSE;
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
if (is_input) {
|
|
|
|
/* D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_INPUT, missing in mingw header */
|
2020-10-27 15:47:49 +00:00
|
|
|
if ((flag & 0x1) != 0)
|
|
|
|
return TRUE;
|
2020-01-10 14:54:43 +00:00
|
|
|
} else {
|
|
|
|
/* D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT, missing in mingw header */
|
2020-10-27 15:47:49 +00:00
|
|
|
if ((flag & 0x2) != 0)
|
|
|
|
return TRUE;
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 15:47:49 +00:00
|
|
|
return FALSE;
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_supports_input_format (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_FORMAT format)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (format == DXGI_FORMAT_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gst_d3d11_video_processor_supports_format (processor, format, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_supports_output_format (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_FORMAT format)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (format == DXGI_FORMAT_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gst_d3d11_video_processor_supports_format (processor, format, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_get_caps (GstD3D11VideoProcessor * processor,
|
|
|
|
D3D11_VIDEO_PROCESSOR_CAPS * caps)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (caps != NULL, FALSE);
|
|
|
|
|
|
|
|
*caps = processor->processor_caps;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
video_processor_color_space_from_gst (GstD3D11VideoProcessor * self,
|
|
|
|
GstVideoColorimetry * color, D3D11_VIDEO_PROCESSOR_COLOR_SPACE * colorspace)
|
|
|
|
{
|
|
|
|
/* D3D11_VIDEO_PROCESSOR_DEVICE_CAPS_xvYCC */
|
|
|
|
UINT can_xvYCC = 2;
|
|
|
|
|
|
|
|
/* 0: playback, 1: video processing */
|
|
|
|
colorspace->Usage = 0;
|
|
|
|
|
|
|
|
if (color->range == GST_VIDEO_COLOR_RANGE_0_255) {
|
|
|
|
colorspace->RGB_Range = 0;
|
|
|
|
colorspace->Nominal_Range = D3D11_VIDEO_PROCESSOR_NOMINAL_RANGE_0_255;
|
|
|
|
} else {
|
|
|
|
/* 16-235 */
|
|
|
|
colorspace->RGB_Range = 1;
|
|
|
|
colorspace->Nominal_Range = D3D11_VIDEO_PROCESSOR_NOMINAL_RANGE_16_235;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (color->matrix == GST_VIDEO_COLOR_MATRIX_BT601) {
|
|
|
|
colorspace->YCbCr_Matrix = 0;
|
|
|
|
} else {
|
|
|
|
/* BT.709, no other options (such as BT2020) */
|
|
|
|
colorspace->YCbCr_Matrix = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((self->processor_caps.DeviceCaps & can_xvYCC) == can_xvYCC) {
|
|
|
|
colorspace->YCbCr_xvYCC = 1;
|
|
|
|
} else {
|
|
|
|
colorspace->YCbCr_xvYCC = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_input_color_space (GstD3D11VideoProcessor *
|
|
|
|
processor, GstVideoColorimetry * color)
|
|
|
|
{
|
|
|
|
D3D11_VIDEO_PROCESSOR_COLOR_SPACE color_space;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (color != NULL, FALSE);
|
|
|
|
|
|
|
|
video_processor_color_space_from_gst (processor, color, &color_space);
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context->VideoProcessorSetStreamColorSpace
|
|
|
|
(processor->processor, 0, &color_space);
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_output_color_space (GstD3D11VideoProcessor *
|
|
|
|
processor, GstVideoColorimetry * color)
|
|
|
|
{
|
|
|
|
D3D11_VIDEO_PROCESSOR_COLOR_SPACE color_space;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (color != NULL, FALSE);
|
|
|
|
|
|
|
|
video_processor_color_space_from_gst (processor, color, &color_space);
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context->VideoProcessorSetOutputColorSpace
|
|
|
|
(processor->processor, &color_space);
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-25 20:09:40 +00:00
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_check_format_conversion (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_FORMAT in_format, DXGI_COLOR_SPACE_TYPE in_color_space,
|
|
|
|
DXGI_FORMAT out_format, DXGI_COLOR_SPACE_TYPE out_color_space)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
BOOL supported = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!processor->enumerator1)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = processor->enumerator1->CheckVideoProcessorFormatConversion
|
|
|
|
(in_format, in_color_space, out_format, out_color_space, &supported);
|
2020-10-25 20:09:40 +00:00
|
|
|
if (!gst_d3d11_result (hr, processor->device)) {
|
|
|
|
GST_WARNING ("Failed to check conversion support");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return supported;
|
|
|
|
}
|
|
|
|
|
2020-01-10 14:54:43 +00:00
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_input_dxgi_color_space (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_COLOR_SPACE_TYPE color_space)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (processor->video_context1) {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context1->VideoProcessorSetStreamColorSpace1
|
|
|
|
(processor->processor, 0, color_space);
|
2020-01-10 14:54:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_output_dxgi_color_space (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_COLOR_SPACE_TYPE color_space)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (processor->video_context1) {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context1->VideoProcessorSetOutputColorSpace1
|
|
|
|
(processor->processor, color_space);
|
2020-01-10 14:54:43 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* D3D11_VIDEO_PROCESSOR_FEATURE_CAPS_METADATA_HDR10
|
|
|
|
* missing in mingw header */
|
|
|
|
#define FEATURE_CAPS_METADATA_HDR10 (0x800)
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_input_hdr10_metadata (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_HDR_METADATA_HDR10 * hdr10_meta)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (processor->video_context2 && (processor->processor_caps.FeatureCaps &
|
|
|
|
FEATURE_CAPS_METADATA_HDR10)) {
|
|
|
|
if (hdr10_meta) {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context2->VideoProcessorSetStreamHDRMetaData
|
|
|
|
(processor->processor, 0,
|
2020-01-10 14:54:43 +00:00
|
|
|
DXGI_HDR_METADATA_TYPE_HDR10, sizeof (DXGI_HDR_METADATA_HDR10),
|
|
|
|
hdr10_meta);
|
|
|
|
} else {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context2->VideoProcessorSetStreamHDRMetaData
|
|
|
|
(processor->processor, 0, DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_set_output_hdr10_metadata (GstD3D11VideoProcessor *
|
|
|
|
processor, DXGI_HDR_METADATA_HDR10 * hdr10_meta)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
|
|
|
|
if (processor->video_context2 && (processor->processor_caps.FeatureCaps &
|
|
|
|
FEATURE_CAPS_METADATA_HDR10)) {
|
|
|
|
if (hdr10_meta) {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context2->VideoProcessorSetOutputHDRMetaData
|
|
|
|
(processor->processor, DXGI_HDR_METADATA_TYPE_HDR10,
|
|
|
|
sizeof (DXGI_HDR_METADATA_HDR10), hdr10_meta);
|
2020-01-10 14:54:43 +00:00
|
|
|
} else {
|
2021-03-13 08:40:57 +00:00
|
|
|
processor->video_context2->VideoProcessorSetOutputHDRMetaData
|
|
|
|
(processor->processor, DXGI_HDR_METADATA_TYPE_NONE, 0, NULL);
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_create_input_view (GstD3D11VideoProcessor * processor,
|
|
|
|
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC * desc, ID3D11Resource * resource,
|
|
|
|
ID3D11VideoProcessorInputView ** view)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (desc != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (resource != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (view != NULL, FALSE);
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = processor->video_device->CreateVideoProcessorInputView (resource,
|
|
|
|
processor->enumerator, desc, view);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, processor->device))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-12-19 17:39:40 +00:00
|
|
|
ID3D11VideoProcessorInputView *
|
|
|
|
gst_d3d11_video_processor_get_input_view (GstD3D11VideoProcessor * processor,
|
2020-10-23 07:59:00 +00:00
|
|
|
GstD3D11Memory * mem)
|
|
|
|
{
|
2020-12-19 17:39:40 +00:00
|
|
|
return gst_d3d11_memory_get_processor_input_view (mem,
|
2020-10-23 07:59:00 +00:00
|
|
|
processor->video_device, processor->enumerator);
|
|
|
|
}
|
|
|
|
|
2020-01-10 14:54:43 +00:00
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_create_output_view (GstD3D11VideoProcessor *
|
|
|
|
processor, D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC * desc,
|
|
|
|
ID3D11Resource * resource, ID3D11VideoProcessorOutputView ** view)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (desc != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (resource != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (view != NULL, FALSE);
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = processor->video_device->CreateVideoProcessorOutputView
|
|
|
|
(resource, processor->enumerator, desc, view);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, processor->device))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-12-19 17:39:40 +00:00
|
|
|
ID3D11VideoProcessorOutputView *
|
|
|
|
gst_d3d11_video_processor_get_output_view (GstD3D11VideoProcessor *
|
2020-10-23 17:47:22 +00:00
|
|
|
processor, GstD3D11Memory * mem)
|
|
|
|
{
|
2020-12-19 17:39:40 +00:00
|
|
|
return gst_d3d11_memory_get_processor_output_view (mem,
|
2020-10-23 17:47:22 +00:00
|
|
|
processor->video_device, processor->enumerator);
|
|
|
|
}
|
|
|
|
|
2020-01-10 14:54:43 +00:00
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_render (GstD3D11VideoProcessor * processor,
|
|
|
|
RECT * in_rect, ID3D11VideoProcessorInputView * in_view,
|
|
|
|
RECT * out_rect, ID3D11VideoProcessorOutputView * out_view)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (in_view != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (out_view != NULL, FALSE);
|
|
|
|
|
2021-03-20 07:15:35 +00:00
|
|
|
gst_d3d11_device_lock (processor->device);
|
2020-01-10 14:54:43 +00:00
|
|
|
ret = gst_d3d11_video_processor_render_unlocked (processor, in_rect, in_view,
|
|
|
|
out_rect, out_view);
|
2021-03-20 07:15:35 +00:00
|
|
|
gst_d3d11_device_unlock (processor->device);
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_render_unlocked (GstD3D11VideoProcessor * processor,
|
|
|
|
RECT * in_rect, ID3D11VideoProcessorInputView * in_view,
|
|
|
|
RECT * out_rect, ID3D11VideoProcessorOutputView * out_view)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
D3D11_VIDEO_PROCESSOR_STREAM stream = { 0, };
|
2021-03-13 08:40:57 +00:00
|
|
|
ID3D11VideoContext *context;
|
|
|
|
ID3D11VideoProcessor *proc;
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (processor != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (in_view != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (out_view != NULL, FALSE);
|
|
|
|
|
|
|
|
stream.Enable = TRUE;
|
|
|
|
stream.pInputSurface = in_view;
|
2021-03-13 08:40:57 +00:00
|
|
|
context = processor->video_context;
|
|
|
|
proc = processor->processor;
|
2020-01-10 14:54:43 +00:00
|
|
|
|
|
|
|
if (in_rect) {
|
2021-03-13 08:40:57 +00:00
|
|
|
context->VideoProcessorSetStreamSourceRect (proc, 0, TRUE, in_rect);
|
2020-01-10 14:54:43 +00:00
|
|
|
} else {
|
2021-03-13 08:40:57 +00:00
|
|
|
context->VideoProcessorSetStreamSourceRect (proc, 0, FALSE, NULL);
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (out_rect) {
|
2021-03-13 08:40:57 +00:00
|
|
|
context->VideoProcessorSetStreamDestRect (proc, 0, TRUE, out_rect);
|
|
|
|
context->VideoProcessorSetOutputTargetRect (proc, TRUE, out_rect);
|
2020-01-10 14:54:43 +00:00
|
|
|
} else {
|
2021-03-13 08:40:57 +00:00
|
|
|
context->VideoProcessorSetStreamDestRect (proc, 0, FALSE, NULL);
|
|
|
|
context->VideoProcessorSetOutputTargetRect (proc, FALSE, NULL);
|
2020-01-10 14:54:43 +00:00
|
|
|
}
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
hr = context->VideoProcessorBlt (proc, out_view, 0, 1, &stream);
|
2020-01-10 14:54:43 +00:00
|
|
|
if (!gst_d3d11_result (hr, processor->device))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_check_bind_flags_for_input_view (guint bind_flags)
|
|
|
|
{
|
|
|
|
static const guint compatible_flags = (D3D11_BIND_DECODER |
|
|
|
|
D3D11_BIND_VIDEO_ENCODER | D3D11_BIND_RENDER_TARGET |
|
|
|
|
D3D11_BIND_UNORDERED_ACCESS);
|
|
|
|
|
|
|
|
if (bind_flags == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if ((bind_flags & compatible_flags) != 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_d3d11_video_processor_check_bind_flags_for_output_view (guint bind_flags)
|
|
|
|
{
|
|
|
|
if ((bind_flags & D3D11_BIND_RENDER_TARGET) == D3D11_BIND_RENDER_TARGET)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|