2019-12-20 14:05:52 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2019 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.
|
|
|
|
*
|
|
|
|
* NOTE: some of implementations are copied/modified from Chromium code
|
|
|
|
*
|
|
|
|
* Copyright 2015 The Chromium Authors. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * 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.
|
|
|
|
* * Neither the name of Google Inc. 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
|
|
|
|
* OWNER 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.
|
|
|
|
*/
|
|
|
|
|
2021-02-21 08:38:38 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-d3d11vp9dec
|
|
|
|
* @title: d3d11vp9dec
|
|
|
|
*
|
|
|
|
* A Direct3D11/DXVA based VP9 video decoder
|
|
|
|
*
|
|
|
|
* ## Example launch line
|
|
|
|
* ```
|
|
|
|
* gst-launch-1.0 filesrc location=/path/to/vp9/file ! parsebin ! d3d11vp9dec ! d3d11videosink
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-12-20 14:05:52 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstd3d11vp9dec.h"
|
2021-12-02 07:26:08 +00:00
|
|
|
#include "gstd3d11pluginutils.h"
|
2020-01-31 22:54:57 +00:00
|
|
|
|
|
|
|
#include <gst/codecs/gstvp9decoder.h>
|
2019-12-20 14:05:52 +00:00
|
|
|
#include <string.h>
|
2021-09-15 15:59:37 +00:00
|
|
|
#include <vector>
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2019-12-31 04:36:59 +00:00
|
|
|
/* HACK: to expose dxva data structure on UWP */
|
|
|
|
#ifdef WINAPI_PARTITION_DESKTOP
|
|
|
|
#undef WINAPI_PARTITION_DESKTOP
|
|
|
|
#endif
|
|
|
|
#define WINAPI_PARTITION_DESKTOP 1
|
|
|
|
#include <d3d9.h>
|
|
|
|
#include <dxva.h>
|
|
|
|
|
2019-12-20 14:05:52 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp9_dec_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_d3d11_vp9_dec_debug
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
typedef struct _GstD3D11Vp9DecInner
|
2020-02-14 16:23:32 +00:00
|
|
|
{
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Device *device = nullptr;
|
|
|
|
GstD3D11Decoder *d3d11_decoder = nullptr;
|
|
|
|
|
|
|
|
DXVA_PicParams_VP9 pic_params;
|
|
|
|
DXVA_Slice_VPx_Short slice;
|
2020-02-14 16:23:32 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
/* In case of VP9, there's only one slice per picture so we don't
|
|
|
|
* need this bitstream buffer, but this will be used for 128 bytes alignment */
|
|
|
|
std::vector<guint8> bitstream_buffer;
|
2021-07-04 16:54:02 +00:00
|
|
|
|
|
|
|
/* To calculate use_prev_in_find_mv_refs */
|
2021-09-15 15:59:37 +00:00
|
|
|
guint last_frame_width = 0;
|
|
|
|
guint last_frame_height = 0;
|
|
|
|
gboolean last_show_frame = FALSE;
|
|
|
|
} GstD3D11Vp9DecInner;
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
|
|
|
typedef struct _GstD3D11Vp9Dec
|
|
|
|
{
|
|
|
|
GstVp9Decoder parent;
|
|
|
|
GstD3D11Vp9DecInner *inner;
|
2020-02-14 16:23:32 +00:00
|
|
|
} GstD3D11Vp9Dec;
|
|
|
|
|
|
|
|
typedef struct _GstD3D11Vp9DecClass
|
|
|
|
{
|
|
|
|
GstVp9DecoderClass parent_class;
|
2021-09-15 14:41:39 +00:00
|
|
|
GstD3D11DecoderSubClassData class_data;
|
2020-02-14 16:23:32 +00:00
|
|
|
} GstD3D11Vp9DecClass;
|
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
#define GST_D3D11_VP9_DEC(object) ((GstD3D11Vp9Dec *) (object))
|
|
|
|
#define GST_D3D11_VP9_DEC_GET_CLASS(object) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS ((object),G_TYPE_FROM_INSTANCE (object),GstD3D11Vp9DecClass))
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
static void gst_d3d11_vp9_dec_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
2021-09-15 15:59:37 +00:00
|
|
|
static void gst_d3d11_vp9_dec_finalize (GObject * object);
|
2019-12-20 14:05:52 +00:00
|
|
|
static void gst_d3d11_vp9_dec_set_context (GstElement * element,
|
|
|
|
GstContext * context);
|
|
|
|
|
|
|
|
static gboolean gst_d3d11_vp9_dec_open (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_d3d11_vp9_dec_close (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_d3d11_vp9_dec_negotiate (GstVideoDecoder * decoder);
|
|
|
|
static gboolean gst_d3d11_vp9_dec_decide_allocation (GstVideoDecoder *
|
|
|
|
decoder, GstQuery * query);
|
|
|
|
static gboolean gst_d3d11_vp9_dec_src_query (GstVideoDecoder * decoder,
|
|
|
|
GstQuery * query);
|
2021-04-23 14:20:54 +00:00
|
|
|
static gboolean gst_d3d11_vp9_dec_sink_event (GstVideoDecoder * decoder,
|
|
|
|
GstEvent * event);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
/* GstVp9Decoder */
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
|
2022-04-27 19:25:05 +00:00
|
|
|
const GstVp9FrameHeader * frame_hdr, gint max_dpb_size);
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_new_picture (GstVp9Decoder * decoder,
|
2020-07-21 14:08:15 +00:00
|
|
|
GstVideoCodecFrame * frame, GstVp9Picture * picture);
|
2019-12-20 14:05:52 +00:00
|
|
|
static GstVp9Picture *gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder *
|
2021-03-28 17:11:22 +00:00
|
|
|
decoder, GstVideoCodecFrame * frame, GstVp9Picture * picture);
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_start_picture (GstVp9Decoder * decoder,
|
2019-12-20 14:05:52 +00:00
|
|
|
GstVp9Picture * picture);
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_decode_picture (GstVp9Decoder * decoder,
|
2019-12-20 14:05:52 +00:00
|
|
|
GstVp9Picture * picture, GstVp9Dpb * dpb);
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_end_picture (GstVp9Decoder * decoder,
|
2019-12-20 14:05:52 +00:00
|
|
|
GstVp9Picture * picture);
|
2021-09-15 15:59:37 +00:00
|
|
|
static GstFlowReturn gst_d3d11_vp9_dec_output_picture (GstVp9Decoder *
|
|
|
|
decoder, GstVideoCodecFrame * frame, GstVp9Picture * picture);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
static void
|
2020-02-14 16:23:32 +00:00
|
|
|
gst_d3d11_vp9_dec_class_init (GstD3D11Vp9DecClass * klass, gpointer data)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
|
|
|
GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (klass);
|
|
|
|
GstVp9DecoderClass *vp9decoder_class = GST_VP9_DECODER_CLASS (klass);
|
2020-02-14 16:23:32 +00:00
|
|
|
GstD3D11DecoderClassData *cdata = (GstD3D11DecoderClassData *) data;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
gobject_class->get_property = gst_d3d11_vp9_dec_get_property;
|
2021-09-15 15:59:37 +00:00
|
|
|
gobject_class->finalize = gst_d3d11_vp9_dec_finalize;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
element_class->set_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_set_context);
|
|
|
|
|
2021-09-15 14:41:39 +00:00
|
|
|
parent_class = (GstElementClass *) g_type_class_peek_parent (klass);
|
|
|
|
gst_d3d11_decoder_class_data_fill_subclass_data (cdata, &klass->class_data);
|
2021-10-21 10:41:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GstD3D11Vp9Dec:adapter-luid:
|
|
|
|
*
|
2022-01-28 19:46:24 +00:00
|
|
|
* DXGI Adapter LUID for this element
|
2021-10-21 10:41:15 +00:00
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
|
2021-09-15 14:41:39 +00:00
|
|
|
gst_d3d11_decoder_proxy_class_init (element_class, cdata,
|
2019-12-20 14:05:52 +00:00
|
|
|
"Seungha Yang <seungha.yang@navercorp.com>");
|
|
|
|
|
|
|
|
decoder_class->open = GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_open);
|
|
|
|
decoder_class->close = GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_close);
|
|
|
|
decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_negotiate);
|
|
|
|
decoder_class->decide_allocation =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_decide_allocation);
|
|
|
|
decoder_class->src_query = GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_src_query);
|
2021-04-23 14:20:54 +00:00
|
|
|
decoder_class->sink_event = GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_sink_event);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
vp9decoder_class->new_sequence =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_new_sequence);
|
|
|
|
vp9decoder_class->new_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_new_picture);
|
|
|
|
vp9decoder_class->duplicate_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_duplicate_picture);
|
|
|
|
vp9decoder_class->start_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_start_picture);
|
|
|
|
vp9decoder_class->decode_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_decode_picture);
|
|
|
|
vp9decoder_class->end_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_end_picture);
|
2021-09-15 15:59:37 +00:00
|
|
|
vp9decoder_class->output_picture =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_output_picture);
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_init (GstD3D11Vp9Dec * self)
|
|
|
|
{
|
2021-09-15 15:59:37 +00:00
|
|
|
self->inner = new GstD3D11Vp9DecInner ();
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-02-14 16:23:32 +00:00
|
|
|
GstD3D11Vp9DecClass *klass = GST_D3D11_VP9_DEC_GET_CLASS (object);
|
2021-09-15 14:41:39 +00:00
|
|
|
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 14:41:39 +00:00
|
|
|
gst_d3d11_decoder_proxy_get_property (object, prop_id, value, pspec, cdata);
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (object);
|
|
|
|
|
|
|
|
delete self->inner;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2019-12-20 14:05:52 +00:00
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_set_context (GstElement * element, GstContext * context)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (element);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2020-02-14 16:23:32 +00:00
|
|
|
GstD3D11Vp9DecClass *klass = GST_D3D11_VP9_DEC_GET_CLASS (self);
|
2021-09-15 14:41:39 +00:00
|
|
|
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-10-08 13:37:20 +00:00
|
|
|
gst_d3d11_handle_set_context_for_adapter_luid (element,
|
|
|
|
context, cdata->adapter_luid, &inner->device);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_vp9_dec_open (GstVideoDecoder * decoder)
|
|
|
|
{
|
2021-12-02 07:26:08 +00:00
|
|
|
GstVp9Decoder *vp9dec = GST_VP9_DECODER (decoder);
|
2019-12-20 14:05:52 +00:00
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2020-02-14 16:23:32 +00:00
|
|
|
GstD3D11Vp9DecClass *klass = GST_D3D11_VP9_DEC_GET_CLASS (self);
|
2021-09-15 14:41:39 +00:00
|
|
|
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-10-08 13:37:20 +00:00
|
|
|
if (!gst_d3d11_decoder_proxy_open (decoder,
|
|
|
|
cdata, &inner->device, &inner->d3d11_decoder)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to open decoder");
|
2019-12-20 14:05:52 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-12-02 07:26:08 +00:00
|
|
|
/* XXX: ConfigDecoderSpecific bit 12 indicates whether accelerator can
|
|
|
|
* support non-keyframe format change or not, but it doesn't seem to be
|
|
|
|
* reliable, since 1b means that it's supported and 0b indicates it may not be
|
|
|
|
* supported. Because some GPUs can support it even if the bit 12 is not
|
|
|
|
* set, do filtering by vendor for now (AMD and Intel looks fine) */
|
|
|
|
if (gst_d3d11_get_device_vendor (inner->device) ==
|
|
|
|
GST_D3D11_DEVICE_VENDOR_NVIDIA) {
|
|
|
|
gst_vp9_decoder_set_non_keyframe_format_change_support (vp9dec, FALSE);
|
|
|
|
}
|
|
|
|
|
2019-12-20 14:05:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_vp9_dec_close (GstVideoDecoder * decoder)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_clear_object (&inner->d3d11_decoder);
|
|
|
|
gst_clear_object (&inner->device);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_vp9_dec_negotiate (GstVideoDecoder * decoder)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (!gst_d3d11_decoder_negotiate (inner->d3d11_decoder, decoder))
|
2020-03-29 14:31:13 +00:00
|
|
|
return FALSE;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_vp9_dec_decide_allocation (GstVideoDecoder * decoder,
|
|
|
|
GstQuery * query)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (!gst_d3d11_decoder_decide_allocation (inner->d3d11_decoder,
|
2021-03-14 07:11:12 +00:00
|
|
|
decoder, query)) {
|
2019-12-20 14:05:52 +00:00
|
|
|
return FALSE;
|
2021-03-14 07:11:12 +00:00
|
|
|
}
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->decide_allocation
|
|
|
|
(decoder, query);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_d3d11_vp9_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
|
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
|
|
|
case GST_QUERY_CONTEXT:
|
|
|
|
if (gst_d3d11_handle_context_query (GST_ELEMENT (decoder),
|
2021-09-15 15:59:37 +00:00
|
|
|
query, inner->device)) {
|
2019-12-20 14:05:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->src_query (decoder, query);
|
|
|
|
}
|
|
|
|
|
2021-03-15 09:26:03 +00:00
|
|
|
static gboolean
|
2021-04-23 14:20:54 +00:00
|
|
|
gst_d3d11_vp9_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
|
2021-03-15 09:26:03 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2021-03-15 09:26:03 +00:00
|
|
|
|
2021-04-23 14:20:54 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_FLUSH_START:
|
2021-09-15 15:59:37 +00:00
|
|
|
if (inner->d3d11_decoder)
|
|
|
|
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, TRUE);
|
2021-04-23 14:20:54 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
2021-09-15 15:59:37 +00:00
|
|
|
if (inner->d3d11_decoder)
|
|
|
|
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, FALSE);
|
2021-04-23 14:20:54 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-03-15 09:26:03 +00:00
|
|
|
|
2021-04-23 14:20:54 +00:00
|
|
|
return GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
|
2021-03-15 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn
|
2019-12-20 14:05:52 +00:00
|
|
|
gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
|
2022-04-27 19:25:05 +00:00
|
|
|
const GstVp9FrameHeader * frame_hdr, gint max_dpb_size)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2021-03-28 07:06:55 +00:00
|
|
|
GstVideoInfo info;
|
|
|
|
GstVideoFormat out_format = GST_VIDEO_FORMAT_UNKNOWN;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
GST_LOG_OBJECT (self, "new sequence");
|
|
|
|
|
2021-03-28 07:06:55 +00:00
|
|
|
if (frame_hdr->profile == GST_VP9_PROFILE_0)
|
|
|
|
out_format = GST_VIDEO_FORMAT_NV12;
|
|
|
|
else if (frame_hdr->profile == GST_VP9_PROFILE_2)
|
|
|
|
out_format = GST_VIDEO_FORMAT_P010_10LE;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-03-28 07:06:55 +00:00
|
|
|
if (out_format == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
GST_ERROR_OBJECT (self, "Could not support profile %d", frame_hdr->profile);
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-28 07:06:55 +00:00
|
|
|
gst_video_info_set_format (&info,
|
|
|
|
out_format, frame_hdr->width, frame_hdr->height);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (!gst_d3d11_decoder_configure (inner->d3d11_decoder,
|
2022-06-16 20:11:08 +00:00
|
|
|
decoder->input_state, &info, 0, 0, (gint) frame_hdr->width,
|
2022-05-02 13:41:53 +00:00
|
|
|
(gint) frame_hdr->height, max_dpb_size)) {
|
2021-03-28 07:06:55 +00:00
|
|
|
GST_ERROR_OBJECT (self, "Failed to create decoder");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2021-03-28 07:06:55 +00:00
|
|
|
}
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-03-28 07:06:55 +00:00
|
|
|
if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
|
2022-05-24 17:38:01 +00:00
|
|
|
GST_WARNING_OBJECT (self, "Failed to negotiate with downstream");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_NOT_NEGOTIATED;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-07-04 16:54:02 +00:00
|
|
|
/* Will be updated per decode_picture */
|
2021-09-15 15:59:37 +00:00
|
|
|
inner->last_frame_width = inner->last_frame_height = 0;
|
|
|
|
inner->last_show_frame = FALSE;
|
2021-07-04 16:54:02 +00:00
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_OK;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn
|
2020-07-21 14:08:15 +00:00
|
|
|
gst_d3d11_vp9_dec_new_picture (GstVp9Decoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame, GstVp9Picture * picture)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
GstBuffer *view_buffer;
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
view_buffer = gst_d3d11_decoder_get_output_view_buffer (inner->d3d11_decoder,
|
2021-02-14 12:01:32 +00:00
|
|
|
GST_VIDEO_DECODER (decoder));
|
2019-12-20 14:05:52 +00:00
|
|
|
if (!view_buffer) {
|
2021-06-10 14:35:38 +00:00
|
|
|
GST_DEBUG_OBJECT (self, "No available output view buffer");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_FLUSHING;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2020-12-19 17:39:40 +00:00
|
|
|
GST_LOG_OBJECT (self, "New output view buffer %" GST_PTR_FORMAT, view_buffer);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
gst_vp9_picture_set_user_data (picture,
|
|
|
|
view_buffer, (GDestroyNotify) gst_buffer_unref);
|
|
|
|
|
|
|
|
GST_LOG_OBJECT (self, "New VP9 picture %p", picture);
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_OK;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstVp9Picture *
|
|
|
|
gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder * decoder,
|
2021-03-28 17:11:22 +00:00
|
|
|
GstVideoCodecFrame * frame, GstVp9Picture * picture)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
|
|
|
GstBuffer *view_buffer;
|
|
|
|
GstVp9Picture *new_picture;
|
|
|
|
|
2021-03-13 08:40:57 +00:00
|
|
|
view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
if (!view_buffer) {
|
|
|
|
GST_ERROR_OBJECT (self, "Parent picture does not have output view buffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_picture = gst_vp9_picture_new ();
|
|
|
|
new_picture->frame_hdr = picture->frame_hdr;
|
|
|
|
|
2020-12-19 17:39:40 +00:00
|
|
|
GST_LOG_OBJECT (self, "Duplicate output with buffer %" GST_PTR_FORMAT,
|
|
|
|
view_buffer);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
gst_vp9_picture_set_user_data (new_picture,
|
|
|
|
gst_buffer_ref (view_buffer), (GDestroyNotify) gst_buffer_unref);
|
|
|
|
|
|
|
|
return new_picture;
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_vp9_dec_start_picture (GstVp9Decoder * decoder,
|
|
|
|
GstVp9Picture * picture)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
inner->bitstream_buffer.resize (0);
|
2020-07-21 14:08:15 +00:00
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_OK;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 08:31:17 +00:00
|
|
|
static ID3D11VideoDecoderOutputView *
|
2019-12-20 14:05:52 +00:00
|
|
|
gst_d3d11_vp9_dec_get_output_view_from_picture (GstD3D11Vp9Dec * self,
|
2021-03-20 10:52:16 +00:00
|
|
|
GstVp9Picture * picture, guint8 * view_id)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2019-12-20 14:05:52 +00:00
|
|
|
GstBuffer *view_buffer;
|
2020-10-20 08:31:17 +00:00
|
|
|
ID3D11VideoDecoderOutputView *view;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
|
|
|
|
if (!view_buffer) {
|
|
|
|
GST_DEBUG_OBJECT (self, "current picture does not have output view buffer");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
view =
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_decoder_get_output_view_from_buffer (inner->d3d11_decoder,
|
2021-03-20 10:52:16 +00:00
|
|
|
view_buffer, view_id);
|
2019-12-20 14:05:52 +00:00
|
|
|
if (!view) {
|
|
|
|
GST_DEBUG_OBJECT (self, "current picture does not have output view handle");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_frame_params (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
2021-03-30 02:49:43 +00:00
|
|
|
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
params->profile = frame_hdr->profile;
|
|
|
|
params->frame_type = frame_hdr->frame_type;
|
|
|
|
params->show_frame = frame_hdr->show_frame;
|
|
|
|
params->error_resilient_mode = frame_hdr->error_resilient_mode;
|
2021-03-30 02:49:43 +00:00
|
|
|
params->subsampling_x = frame_hdr->subsampling_x;
|
|
|
|
params->subsampling_y = frame_hdr->subsampling_y;
|
2019-12-20 14:05:52 +00:00
|
|
|
params->refresh_frame_context = frame_hdr->refresh_frame_context;
|
|
|
|
params->frame_parallel_decoding_mode =
|
|
|
|
frame_hdr->frame_parallel_decoding_mode;
|
|
|
|
params->intra_only = frame_hdr->intra_only;
|
|
|
|
params->frame_context_idx = frame_hdr->frame_context_idx;
|
|
|
|
params->reset_frame_context = frame_hdr->reset_frame_context;
|
|
|
|
if (frame_hdr->frame_type == GST_VP9_KEY_FRAME)
|
|
|
|
params->allow_high_precision_mv = 0;
|
|
|
|
else
|
|
|
|
params->allow_high_precision_mv = frame_hdr->allow_high_precision_mv;
|
|
|
|
|
|
|
|
params->width = frame_hdr->width;
|
|
|
|
params->height = frame_hdr->height;
|
2021-03-30 02:49:43 +00:00
|
|
|
params->BitDepthMinus8Luma = frame_hdr->bit_depth - 8;
|
|
|
|
params->BitDepthMinus8Chroma = frame_hdr->bit_depth - 8;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-03-30 02:49:43 +00:00
|
|
|
params->interp_filter = frame_hdr->interpolation_filter;
|
|
|
|
params->log2_tile_cols = frame_hdr->tile_cols_log2;
|
|
|
|
params->log2_tile_rows = frame_hdr->tile_rows_log2;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_reference_frames (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, GstVp9Dpb * dpb, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VP9_REF_FRAMES; i++) {
|
|
|
|
if (dpb->pic_list[i]) {
|
|
|
|
GstVp9Picture *other_pic = dpb->pic_list[i];
|
2020-10-20 08:31:17 +00:00
|
|
|
ID3D11VideoDecoderOutputView *view;
|
2021-03-20 10:52:16 +00:00
|
|
|
guint8 view_id = 0xff;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-03-20 10:52:16 +00:00
|
|
|
view = gst_d3d11_vp9_dec_get_output_view_from_picture (self, other_pic,
|
|
|
|
&view_id);
|
2019-12-20 14:05:52 +00:00
|
|
|
if (!view) {
|
|
|
|
GST_ERROR_OBJECT (self, "picture does not have output view handle");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-20 10:52:16 +00:00
|
|
|
params->ref_frame_map[i].Index7Bits = view_id;
|
2019-12-20 14:05:52 +00:00
|
|
|
params->ref_frame_coded_width[i] = picture->frame_hdr.width;
|
|
|
|
params->ref_frame_coded_height[i] = picture->frame_hdr.height;
|
|
|
|
} else {
|
|
|
|
params->ref_frame_map[i].bPicEntry = 0xff;
|
|
|
|
params->ref_frame_coded_width[i] = 0;
|
|
|
|
params->ref_frame_coded_height[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_frame_refs (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
2021-03-30 02:49:43 +00:00
|
|
|
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
|
2019-12-20 14:05:52 +00:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < GST_VP9_REFS_PER_FRAME; i++) {
|
2021-03-30 02:49:43 +00:00
|
|
|
params->frame_refs[i] = params->ref_frame_map[frame_hdr->ref_frame_idx[i]];
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-03-30 02:49:43 +00:00
|
|
|
G_STATIC_ASSERT (G_N_ELEMENTS (params->ref_frame_sign_bias) ==
|
|
|
|
G_N_ELEMENTS (frame_hdr->ref_frame_sign_bias));
|
|
|
|
G_STATIC_ASSERT (sizeof (params->ref_frame_sign_bias) ==
|
|
|
|
sizeof (frame_hdr->ref_frame_sign_bias));
|
|
|
|
memcpy (params->ref_frame_sign_bias,
|
|
|
|
frame_hdr->ref_frame_sign_bias, sizeof (frame_hdr->ref_frame_sign_bias));
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_loop_filter_params (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2021-03-30 02:49:43 +00:00
|
|
|
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
|
|
|
|
const GstVp9LoopFilterParams *lfp = &frame_hdr->loop_filter_params;
|
|
|
|
|
|
|
|
params->filter_level = lfp->loop_filter_level;
|
|
|
|
params->sharpness_level = lfp->loop_filter_sharpness;
|
|
|
|
params->mode_ref_delta_enabled = lfp->loop_filter_delta_enabled;
|
|
|
|
params->mode_ref_delta_update = lfp->loop_filter_delta_update;
|
2021-07-04 16:54:02 +00:00
|
|
|
params->use_prev_in_find_mv_refs =
|
2021-10-02 16:45:57 +00:00
|
|
|
inner->last_show_frame && !frame_hdr->error_resilient_mode;
|
|
|
|
|
|
|
|
if (frame_hdr->frame_type != GST_VP9_KEY_FRAME && !frame_hdr->intra_only) {
|
|
|
|
params->use_prev_in_find_mv_refs &=
|
|
|
|
(frame_hdr->width == inner->last_frame_width &&
|
|
|
|
frame_hdr->height == inner->last_frame_height);
|
|
|
|
}
|
2021-03-30 02:49:43 +00:00
|
|
|
|
|
|
|
G_STATIC_ASSERT (G_N_ELEMENTS (params->ref_deltas) ==
|
|
|
|
G_N_ELEMENTS (lfp->loop_filter_ref_deltas));
|
|
|
|
G_STATIC_ASSERT (sizeof (params->ref_deltas) ==
|
|
|
|
sizeof (lfp->loop_filter_ref_deltas));
|
|
|
|
memcpy (params->ref_deltas, lfp->loop_filter_ref_deltas,
|
|
|
|
sizeof (lfp->loop_filter_ref_deltas));
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (G_N_ELEMENTS (params->mode_deltas) ==
|
|
|
|
G_N_ELEMENTS (lfp->loop_filter_mode_deltas));
|
|
|
|
G_STATIC_ASSERT (sizeof (params->mode_deltas) ==
|
|
|
|
sizeof (lfp->loop_filter_mode_deltas));
|
|
|
|
memcpy (params->mode_deltas, lfp->loop_filter_mode_deltas,
|
|
|
|
sizeof (lfp->loop_filter_mode_deltas));
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_quant_params (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
2021-03-30 02:49:43 +00:00
|
|
|
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
|
|
|
|
const GstVp9QuantizationParams *qp = &frame_hdr->quantization_params;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-03-30 02:49:43 +00:00
|
|
|
params->base_qindex = qp->base_q_idx;
|
|
|
|
params->y_dc_delta_q = qp->delta_q_y_dc;
|
|
|
|
params->uv_dc_delta_q = qp->delta_q_uv_dc;
|
|
|
|
params->uv_ac_delta_q = qp->delta_q_uv_ac;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_d3d11_vp9_dec_copy_segmentation_params (GstD3D11Vp9Dec * self,
|
|
|
|
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
|
|
|
|
{
|
2021-03-30 02:49:43 +00:00
|
|
|
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
|
|
|
|
const GstVp9SegmentationParams *sp = &frame_hdr->segmentation_params;
|
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
params->stVP9Segments.enabled = sp->segmentation_enabled;
|
|
|
|
params->stVP9Segments.update_map = sp->segmentation_update_map;
|
|
|
|
params->stVP9Segments.temporal_update = sp->segmentation_temporal_update;
|
|
|
|
params->stVP9Segments.abs_delta = sp->segmentation_abs_or_delta_update;
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (G_N_ELEMENTS (params->stVP9Segments.tree_probs) ==
|
|
|
|
G_N_ELEMENTS (sp->segmentation_tree_probs));
|
|
|
|
G_STATIC_ASSERT (sizeof (params->stVP9Segments.tree_probs) ==
|
|
|
|
sizeof (sp->segmentation_tree_probs));
|
|
|
|
memcpy (params->stVP9Segments.tree_probs, sp->segmentation_tree_probs,
|
|
|
|
sizeof (sp->segmentation_tree_probs));
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (G_N_ELEMENTS (params->stVP9Segments.pred_probs) ==
|
|
|
|
G_N_ELEMENTS (sp->segmentation_pred_prob));
|
|
|
|
G_STATIC_ASSERT (sizeof (params->stVP9Segments.pred_probs) ==
|
|
|
|
sizeof (sp->segmentation_pred_prob));
|
|
|
|
|
|
|
|
if (sp->segmentation_temporal_update) {
|
|
|
|
memcpy (params->stVP9Segments.pred_probs, sp->segmentation_pred_prob,
|
|
|
|
sizeof (params->stVP9Segments.pred_probs));
|
|
|
|
} else {
|
|
|
|
memset (params->stVP9Segments.pred_probs, 255,
|
|
|
|
sizeof (params->stVP9Segments.pred_probs));
|
|
|
|
}
|
2019-12-20 14:05:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < GST_VP9_MAX_SEGMENTS; i++) {
|
2021-03-30 02:49:43 +00:00
|
|
|
params->stVP9Segments.feature_mask[i] =
|
|
|
|
(sp->feature_enabled[i][GST_VP9_SEG_LVL_ALT_Q] << 0) |
|
|
|
|
(sp->feature_enabled[i][GST_VP9_SEG_LVL_ALT_L] << 1) |
|
|
|
|
(sp->feature_enabled[i][GST_VP9_SEG_LVL_REF_FRAME] << 2) |
|
|
|
|
(sp->feature_enabled[i][GST_VP9_SEG_SEG_LVL_SKIP] << 3);
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
params->stVP9Segments.feature_data[i][j] = sp->feature_data[i][j];
|
2019-12-20 14:05:52 +00:00
|
|
|
params->stVP9Segments.feature_data[i][3] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_vp9_dec_decode_picture (GstVp9Decoder * decoder,
|
|
|
|
GstVp9Picture * picture, GstVp9Dpb * dpb)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
|
|
|
DXVA_PicParams_VP9 *pic_params = &inner->pic_params;
|
|
|
|
DXVA_Slice_VPx_Short *slice = &inner->slice;
|
|
|
|
ID3D11VideoDecoderOutputView *view;
|
|
|
|
guint8 view_id = 0xff;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
view = gst_d3d11_vp9_dec_get_output_view_from_picture (self, picture,
|
|
|
|
&view_id);
|
|
|
|
if (!view) {
|
|
|
|
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
memset (pic_params, 0, sizeof (DXVA_PicParams_VP9));
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
pic_params->CurrPic.Index7Bits = view_id;
|
|
|
|
pic_params->uncompressed_header_size_byte_aligned =
|
|
|
|
picture->frame_hdr.frame_header_length_in_bytes;
|
|
|
|
pic_params->first_partition_size = picture->frame_hdr.header_size_in_bytes;
|
|
|
|
pic_params->StatusReportFeedbackNumber = 1;
|
2020-02-21 12:02:47 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_vp9_dec_copy_frame_params (self, picture, pic_params);
|
|
|
|
gst_d3d11_vp9_dec_copy_reference_frames (self, picture, dpb, pic_params);
|
|
|
|
gst_d3d11_vp9_dec_copy_frame_refs (self, picture, pic_params);
|
|
|
|
gst_d3d11_vp9_dec_copy_loop_filter_params (self, picture, pic_params);
|
|
|
|
gst_d3d11_vp9_dec_copy_quant_params (self, picture, pic_params);
|
|
|
|
gst_d3d11_vp9_dec_copy_segmentation_params (self, picture, pic_params);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
inner->bitstream_buffer.resize (picture->size);
|
|
|
|
memcpy (&inner->bitstream_buffer[0], picture->data, picture->size);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
slice->BSNALunitDataLocation = 0;
|
|
|
|
slice->SliceBytesInBuffer = inner->bitstream_buffer.size ();
|
|
|
|
slice->wBadSliceChopping = 0;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
inner->last_frame_width = pic_params->width;
|
|
|
|
inner->last_frame_height = pic_params->height;
|
2021-10-02 16:45:57 +00:00
|
|
|
inner->last_show_frame = pic_params->show_frame;
|
2021-07-04 16:54:02 +00:00
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_OK;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
static GstFlowReturn
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_vp9_dec_end_picture (GstVp9Decoder * decoder, GstVp9Picture * picture)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
2020-10-20 08:31:17 +00:00
|
|
|
ID3D11VideoDecoderOutputView *view;
|
2021-03-20 10:52:16 +00:00
|
|
|
guint8 view_id = 0xff;
|
2021-09-15 15:59:37 +00:00
|
|
|
size_t bitstream_buffer_size;
|
|
|
|
size_t bitstream_pos;
|
|
|
|
GstD3D11DecodeInputStreamArgs input_args;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (inner->bitstream_buffer.empty ()) {
|
|
|
|
GST_ERROR_OBJECT (self, "No bitstream buffer to submit");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2021-09-15 15:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view = gst_d3d11_vp9_dec_get_output_view_from_picture (self,
|
|
|
|
picture, &view_id);
|
2019-12-20 14:05:52 +00:00
|
|
|
if (!view) {
|
|
|
|
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
|
2021-09-17 15:09:24 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
memset (&input_args, 0, sizeof (GstD3D11DecodeInputStreamArgs));
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
bitstream_pos = inner->bitstream_buffer.size ();
|
|
|
|
bitstream_buffer_size = GST_ROUND_UP_128 (bitstream_pos);
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (bitstream_buffer_size > bitstream_pos) {
|
|
|
|
size_t padding = bitstream_buffer_size - bitstream_pos;
|
|
|
|
|
|
|
|
/* As per DXVA spec, total amount of bitstream buffer size should be
|
|
|
|
* 128 bytes aligned. If actual data is not multiple of 128 bytes,
|
|
|
|
* the last slice data needs to be zero-padded */
|
|
|
|
inner->bitstream_buffer.resize (bitstream_buffer_size, 0);
|
|
|
|
|
|
|
|
inner->slice.SliceBytesInBuffer += padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_args.picture_params = &inner->pic_params;
|
|
|
|
input_args.picture_params_size = sizeof (DXVA_PicParams_VP9);
|
|
|
|
input_args.slice_control = &inner->slice;
|
|
|
|
input_args.slice_control_size = sizeof (DXVA_Slice_VPx_Short);
|
|
|
|
input_args.bitstream = &inner->bitstream_buffer[0];
|
|
|
|
input_args.bitstream_size = inner->bitstream_buffer.size ();
|
|
|
|
|
2021-09-17 15:09:24 +00:00
|
|
|
if (!gst_d3d11_decoder_decode_frame (inner->d3d11_decoder, view, &input_args))
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_d3d11_vp9_dec_output_picture (GstVp9Decoder * decoder,
|
|
|
|
GstVideoCodecFrame * frame, GstVp9Picture * picture)
|
2019-12-20 14:05:52 +00:00
|
|
|
{
|
|
|
|
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
|
2021-09-15 15:59:37 +00:00
|
|
|
GstD3D11Vp9DecInner *inner = self->inner;
|
|
|
|
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
|
|
|
|
GstBuffer *view_buffer;
|
2019-12-20 14:05:52 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
GST_LOG_OBJECT (self, "Outputting picture %p", picture);
|
|
|
|
|
|
|
|
view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
|
|
|
|
|
|
|
|
if (!view_buffer) {
|
|
|
|
GST_ERROR_OBJECT (self, "Could not get output view");
|
|
|
|
goto error;
|
2019-12-20 14:05:52 +00:00
|
|
|
}
|
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
if (!gst_d3d11_decoder_process_output (inner->d3d11_decoder, vdec,
|
|
|
|
picture->frame_hdr.width, picture->frame_hdr.height, view_buffer,
|
|
|
|
&frame->output_buffer)) {
|
|
|
|
GST_ERROR_OBJECT (self, "Failed to copy buffer");
|
|
|
|
goto error;
|
|
|
|
}
|
2020-01-10 15:01:55 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_vp9_picture_unref (picture);
|
|
|
|
|
|
|
|
return gst_video_decoder_finish_frame (vdec, frame);
|
|
|
|
|
|
|
|
error:
|
|
|
|
gst_vp9_picture_unref (picture);
|
|
|
|
gst_video_decoder_release_frame (vdec, frame);
|
|
|
|
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
2020-02-14 16:23:32 +00:00
|
|
|
|
2020-01-10 15:01:55 +00:00
|
|
|
void
|
|
|
|
gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
|
2021-09-15 15:59:37 +00:00
|
|
|
guint rank)
|
2020-01-10 15:01:55 +00:00
|
|
|
{
|
2020-02-14 16:23:32 +00:00
|
|
|
GType type;
|
|
|
|
gchar *type_name;
|
|
|
|
gchar *feature_name;
|
|
|
|
guint index = 0;
|
|
|
|
guint i;
|
2021-03-14 06:08:01 +00:00
|
|
|
const GUID *profile;
|
2020-02-14 16:23:32 +00:00
|
|
|
GTypeInfo type_info = {
|
|
|
|
sizeof (GstD3D11Vp9DecClass),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_d3d11_vp9_dec_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstD3D11Vp9Dec),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_d3d11_vp9_dec_init,
|
|
|
|
};
|
2021-03-14 06:08:01 +00:00
|
|
|
const GUID *profile2_guid = NULL;
|
|
|
|
const GUID *profile0_guid = NULL;
|
2020-02-14 16:23:32 +00:00
|
|
|
GstCaps *sink_caps = NULL;
|
|
|
|
GstCaps *src_caps = NULL;
|
|
|
|
guint max_width = 0;
|
|
|
|
guint max_height = 0;
|
|
|
|
guint resolution;
|
|
|
|
gboolean have_profile2 = FALSE;
|
|
|
|
gboolean have_profile0 = FALSE;
|
|
|
|
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
|
2020-09-10 11:32:13 +00:00
|
|
|
GValue vp9_profiles = G_VALUE_INIT;
|
2020-02-14 16:23:32 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
have_profile2 = gst_d3d11_decoder_get_supported_decoder_profile (device,
|
|
|
|
GST_DXVA_CODEC_VP9, GST_VIDEO_FORMAT_P010_10LE, &profile2_guid);
|
2020-02-14 16:23:32 +00:00
|
|
|
if (!have_profile2) {
|
|
|
|
GST_DEBUG_OBJECT (device,
|
|
|
|
"decoder does not support VP9_VLD_10BIT_PROFILE2");
|
|
|
|
} else {
|
|
|
|
have_profile2 &=
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_decoder_supports_format (device,
|
2021-03-14 06:08:01 +00:00
|
|
|
profile2_guid, DXGI_FORMAT_P010);
|
2020-02-14 16:23:32 +00:00
|
|
|
if (!have_profile2) {
|
2020-10-30 15:37:48 +00:00
|
|
|
GST_FIXME_OBJECT (device, "device does not support P010 format");
|
2020-02-14 16:23:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-10 15:01:55 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
have_profile0 = gst_d3d11_decoder_get_supported_decoder_profile (device,
|
|
|
|
GST_DXVA_CODEC_VP9, GST_VIDEO_FORMAT_NV12, &profile0_guid);
|
2020-02-14 16:23:32 +00:00
|
|
|
if (!have_profile0) {
|
|
|
|
GST_DEBUG_OBJECT (device, "decoder does not support VP9_VLD_PROFILE0");
|
|
|
|
} else {
|
|
|
|
have_profile0 =
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_decoder_supports_format (device, profile0_guid,
|
2021-03-14 06:08:01 +00:00
|
|
|
DXGI_FORMAT_NV12);
|
2020-02-14 16:23:32 +00:00
|
|
|
if (!have_profile0) {
|
|
|
|
GST_FIXME_OBJECT (device, "device does not support NV12 format");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_profile2 && !have_profile0) {
|
|
|
|
GST_INFO_OBJECT (device, "device does not support VP9 decoding");
|
2020-01-10 15:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-14 16:23:32 +00:00
|
|
|
if (have_profile0) {
|
2021-03-14 06:08:01 +00:00
|
|
|
profile = profile0_guid;
|
2020-02-14 16:23:32 +00:00
|
|
|
format = DXGI_FORMAT_NV12;
|
|
|
|
} else {
|
2021-03-14 06:08:01 +00:00
|
|
|
profile = profile2_guid;
|
2020-02-14 16:23:32 +00:00
|
|
|
format = DXGI_FORMAT_P010;
|
|
|
|
}
|
2020-01-10 15:01:55 +00:00
|
|
|
|
2021-09-15 15:59:37 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (gst_dxva_resolutions); i++) {
|
|
|
|
if (gst_d3d11_decoder_supports_resolution (device, profile,
|
|
|
|
format, gst_dxva_resolutions[i].width,
|
|
|
|
gst_dxva_resolutions[i].height)) {
|
|
|
|
max_width = gst_dxva_resolutions[i].width;
|
|
|
|
max_height = gst_dxva_resolutions[i].height;
|
2020-01-10 15:01:55 +00:00
|
|
|
|
2020-02-14 16:23:32 +00:00
|
|
|
GST_DEBUG_OBJECT (device,
|
|
|
|
"device support resolution %dx%d", max_width, max_height);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max_width == 0 || max_height == 0) {
|
|
|
|
GST_WARNING_OBJECT (device, "Couldn't query supported resolution");
|
2020-01-10 15:01:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-31 11:31:51 +00:00
|
|
|
sink_caps = gst_caps_from_string ("video/x-vp9, alignment = (string) frame");
|
2020-02-14 16:23:32 +00:00
|
|
|
src_caps = gst_caps_from_string ("video/x-raw("
|
2020-10-31 11:31:51 +00:00
|
|
|
GST_CAPS_FEATURE_MEMORY_D3D11_MEMORY "); video/x-raw");
|
2020-02-14 16:23:32 +00:00
|
|
|
|
2020-09-10 11:32:13 +00:00
|
|
|
g_value_init (&vp9_profiles, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
if (have_profile0) {
|
|
|
|
GValue vp9_profile_val = G_VALUE_INIT;
|
|
|
|
|
|
|
|
g_value_init (&vp9_profile_val, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&vp9_profile_val, "0");
|
|
|
|
gst_value_list_append_and_take_value (&vp9_profiles, &vp9_profile_val);
|
|
|
|
}
|
|
|
|
|
2020-02-14 16:23:32 +00:00
|
|
|
if (have_profile2) {
|
|
|
|
GValue format_list = G_VALUE_INIT;
|
|
|
|
GValue format_value = G_VALUE_INIT;
|
2020-09-10 11:32:13 +00:00
|
|
|
GValue vp9_profile_val = G_VALUE_INIT;
|
2020-02-14 16:23:32 +00:00
|
|
|
|
|
|
|
g_value_init (&format_list, GST_TYPE_LIST);
|
|
|
|
|
|
|
|
g_value_init (&format_value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&format_value, "NV12");
|
|
|
|
gst_value_list_append_and_take_value (&format_list, &format_value);
|
|
|
|
|
|
|
|
g_value_init (&format_value, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&format_value, "P010_10LE");
|
|
|
|
gst_value_list_append_and_take_value (&format_list, &format_value);
|
|
|
|
|
|
|
|
gst_caps_set_value (src_caps, "format", &format_list);
|
|
|
|
g_value_unset (&format_list);
|
2020-09-10 11:32:13 +00:00
|
|
|
|
|
|
|
g_value_init (&vp9_profile_val, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&vp9_profile_val, "2");
|
|
|
|
gst_value_list_append_and_take_value (&vp9_profiles, &vp9_profile_val);
|
2020-02-14 16:23:32 +00:00
|
|
|
} else {
|
|
|
|
gst_caps_set_simple (src_caps, "format", G_TYPE_STRING, "NV12", NULL);
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:32:13 +00:00
|
|
|
gst_caps_set_value (sink_caps, "profile", &vp9_profiles);
|
|
|
|
g_value_unset (&vp9_profiles);
|
|
|
|
|
2020-02-14 16:23:32 +00:00
|
|
|
/* To cover both landscape and portrait, select max value */
|
|
|
|
resolution = MAX (max_width, max_height);
|
|
|
|
|
|
|
|
type_info.class_data =
|
2021-09-15 15:59:37 +00:00
|
|
|
gst_d3d11_decoder_class_data_new (device, GST_DXVA_CODEC_VP9,
|
2022-05-11 20:13:08 +00:00
|
|
|
sink_caps, src_caps, resolution);
|
2020-02-14 16:23:32 +00:00
|
|
|
|
|
|
|
type_name = g_strdup ("GstD3D11Vp9Dec");
|
|
|
|
feature_name = g_strdup ("d3d11vp9dec");
|
|
|
|
|
|
|
|
while (g_type_from_name (type_name)) {
|
|
|
|
index++;
|
|
|
|
g_free (type_name);
|
|
|
|
g_free (feature_name);
|
|
|
|
type_name = g_strdup_printf ("GstD3D11Vp9Device%dDec", index);
|
|
|
|
feature_name = g_strdup_printf ("d3d11vp9device%ddec", index);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = g_type_register_static (GST_TYPE_VP9_DECODER,
|
2021-03-13 08:40:57 +00:00
|
|
|
type_name, &type_info, (GTypeFlags) 0);
|
2020-02-14 16:23:32 +00:00
|
|
|
|
|
|
|
/* make lower rank than default device */
|
|
|
|
if (rank > 0 && index != 0)
|
|
|
|
rank--;
|
|
|
|
|
2021-10-21 10:41:15 +00:00
|
|
|
if (index != 0)
|
|
|
|
gst_element_type_set_skip_documentation (type);
|
|
|
|
|
2020-02-14 16:23:32 +00:00
|
|
|
if (!gst_element_register (plugin, feature_name, rank, type))
|
|
|
|
GST_WARNING ("Failed to register plugin '%s'", type_name);
|
|
|
|
|
|
|
|
g_free (type_name);
|
|
|
|
g_free (feature_name);
|
2020-01-10 15:01:55 +00:00
|
|
|
}
|