d3d11decoder: Refactor for more unified decoding flow

... and various code cleanup.

* Move spreaded decoding API calls into one method
Previously, decoding flow of most codecs are
- Call DecoderBeginFrame() on start_picture()
- Call {Get,Release}DecoderBuffer() on decode_slice()
- Call SubmitDecoderBuffers() and DecoderEndFrame() on end_picture()
Such spreaded API calls make it hard to keep track of status
of decoding. Now it will be done at once in a new method.

* Drop a code for non-zero wBadSliceChopping
When bitstream buffer provided by driver is not sufficient
to write compressed bitstream data, host decoder needs to make use
of wBadSliceChopping so that driver can understand there are
multiple bitstream buffer. But it's a bit unrealistic and
not tested. Since FFMpeg's DXVA implemetaion doesn't support it,
we might be able to ignore the case for now.

* Make code more portable
Consider common logic of GstCodecs -> DXVA translation for all D3D APIs
(i,e., D3D9, D3D11, and D3D12).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2525>
This commit is contained in:
Seungha Yang 2021-09-16 00:59:37 +09:00
parent a77f793c8b
commit 7d1f6459a0
15 changed files with 1825 additions and 2722 deletions

View file

@ -40,6 +40,7 @@
#include <gst/codecs/gstav1decoder.h>
#include <string.h>
#include <vector>
/* HACK: to expose dxva data structure on UWP */
#ifdef WINAPI_PARTITION_DESKTOP
@ -353,26 +354,28 @@ typedef struct _GST_DXVA_Tile_AV1
/* reference list 8 + 4 margin */
#define NUM_OUTPUT_VIEW 12
/* *INDENT-OFF* */
typedef struct _GstD3D11AV1DecInner
{
GstD3D11Device *device = nullptr;
GstD3D11Decoder *d3d11_decoder = nullptr;
GstAV1SequenceHeaderOBU seq_hdr;
GST_DXVA_PicParams_AV1 pic_params;
std::vector<GST_DXVA_Tile_AV1> tile_list;
std::vector<guint8> bitstream_buffer;
guint max_width = 0;
guint max_height = 0;
guint bitdepth = 0;
} GstD3D11AV1DecInner;
/* *INDENT-ON* */
typedef struct _GstD3D11AV1Dec
{
GstAV1Decoder parent;
GstD3D11Device *device;
GstD3D11Decoder *d3d11_decoder;
GstAV1SequenceHeaderOBU seq_hdr;
GST_DXVA_PicParams_AV1 pic_params;
/* Array of GST_DXVA_Tile_AV1 */
GArray *tile_list;
guint written_buffer_size;
guint remaining_buffer_size;
guint8 *bitstream_buffer_data;
guint max_width;
guint max_height;
guint bitdepth;
GstD3D11AV1DecInner *inner;
} GstD3D11AV1Dec;
typedef struct _GstD3D11AV1DecClass
@ -389,7 +392,7 @@ static GstElementClass *parent_class = NULL;
static void gst_d3d11_av1_dec_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_d3d11_av1_dec_dispose (GObject * object);
static void gst_d3d11_av1_dec_finalize (GObject * object);
static void gst_d3d11_av1_dec_set_context (GstElement * element,
GstContext * context);
@ -430,7 +433,7 @@ gst_d3d11_av1_dec_class_init (GstD3D11AV1DecClass * klass, gpointer data)
GstD3D11DecoderClassData *cdata = (GstD3D11DecoderClassData *) data;
gobject_class->get_property = gst_d3d11_av1_dec_get_property;
gobject_class->dispose = gst_d3d11_av1_dec_dispose;
gobject_class->finalize = gst_d3d11_av1_dec_finalize;
element_class->set_context =
GST_DEBUG_FUNCPTR (gst_d3d11_av1_dec_set_context);
@ -467,7 +470,7 @@ gst_d3d11_av1_dec_class_init (GstD3D11AV1DecClass * klass, gpointer data)
static void
gst_d3d11_av1_dec_init (GstD3D11AV1Dec * self)
{
self->tile_list = g_array_new (FALSE, TRUE, sizeof (GST_DXVA_Tile_AV1));
self->inner = new GstD3D11AV1DecInner ();
}
static void
@ -481,24 +484,25 @@ gst_d3d11_av1_dec_get_property (GObject * object, guint prop_id,
}
static void
gst_d3d11_av1_dec_dispose (GObject * object)
gst_d3d11_av1_dec_finalize (GObject * object)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (object);
g_clear_pointer (&self->tile_list, g_array_unref);
delete self->inner;
G_OBJECT_CLASS (parent_class)->dispose (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_d3d11_av1_dec_set_context (GstElement * element, GstContext * context)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (element);
GstD3D11AV1DecInner *inner = self->inner;
GstD3D11AV1DecClass *klass = GST_D3D11_AV1_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
gst_d3d11_handle_set_context (element, context, cdata->adapter,
&self->device);
&inner->device);
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
@ -507,20 +511,22 @@ static gboolean
gst_d3d11_av1_dec_open (GstVideoDecoder * decoder)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
GstD3D11AV1DecClass *klass = GST_D3D11_AV1_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self), cdata->adapter,
&self->device)) {
&inner->device)) {
GST_ERROR_OBJECT (self, "Cannot create d3d11device");
return FALSE;
}
self->d3d11_decoder = gst_d3d11_decoder_new (self->device);
inner->d3d11_decoder = gst_d3d11_decoder_new (inner->device,
GST_DXVA_CODEC_AV1);
if (!self->d3d11_decoder) {
if (!inner->d3d11_decoder) {
GST_ERROR_OBJECT (self, "Cannot create d3d11 decoder");
gst_clear_object (&self->device);
gst_clear_object (&inner->device);
return FALSE;
}
@ -531,9 +537,10 @@ static gboolean
gst_d3d11_av1_dec_close (GstVideoDecoder * decoder)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
gst_clear_object (&self->d3d11_decoder);
gst_clear_object (&self->device);
gst_clear_object (&inner->d3d11_decoder);
gst_clear_object (&inner->device);
return TRUE;
}
@ -542,8 +549,9 @@ static gboolean
gst_d3d11_av1_dec_negotiate (GstVideoDecoder * decoder)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
if (!gst_d3d11_decoder_negotiate (self->d3d11_decoder, decoder))
if (!gst_d3d11_decoder_negotiate (inner->d3d11_decoder, decoder))
return FALSE;
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
@ -554,8 +562,9 @@ gst_d3d11_av1_dec_decide_allocation (GstVideoDecoder * decoder,
GstQuery * query)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
if (!gst_d3d11_decoder_decide_allocation (self->d3d11_decoder,
if (!gst_d3d11_decoder_decide_allocation (inner->d3d11_decoder,
decoder, query)) {
return FALSE;
}
@ -568,11 +577,12 @@ static gboolean
gst_d3d11_av1_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONTEXT:
if (gst_d3d11_handle_context_query (GST_ELEMENT (decoder),
query, self->device)) {
query, inner->device)) {
return TRUE;
}
break;
@ -587,15 +597,16 @@ static gboolean
gst_d3d11_av1_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, TRUE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, TRUE);
break;
case GST_EVENT_FLUSH_STOP:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, FALSE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, FALSE);
break;
default:
break;
@ -609,6 +620,7 @@ gst_d3d11_av1_dec_new_sequence (GstAV1Decoder * decoder,
const GstAV1SequenceHeaderOBU * seq_hdr)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
gboolean modified = FALSE;
guint max_width, max_height;
@ -624,33 +636,33 @@ gst_d3d11_av1_dec_new_sequence (GstAV1Decoder * decoder,
return FALSE;
}
self->seq_hdr = *seq_hdr;
inner->seq_hdr = *seq_hdr;
if (self->bitdepth != seq_hdr->bit_depth) {
GST_INFO_OBJECT (self, "Bitdepth changed %d -> %d", self->bitdepth,
if (inner->bitdepth != seq_hdr->bit_depth) {
GST_INFO_OBJECT (self, "Bitdepth changed %d -> %d", inner->bitdepth,
seq_hdr->bit_depth);
self->bitdepth = seq_hdr->bit_depth;
inner->bitdepth = seq_hdr->bit_depth;
modified = TRUE;
}
max_width = seq_hdr->max_frame_width_minus_1 + 1;
max_height = seq_hdr->max_frame_height_minus_1 + 1;
if (self->max_width != max_width || self->max_height != max_height) {
if (inner->max_width != max_width || inner->max_height != max_height) {
GST_INFO_OBJECT (self, "Resolution changed %dx%d -> %dx%d",
self->max_width, self->max_height, max_width, max_height);
self->max_width = max_width;
self->max_height = max_height;
inner->max_width, inner->max_height, max_width, max_height);
inner->max_width = max_width;
inner->max_height = max_height;
modified = TRUE;
}
if (modified || !gst_d3d11_decoder_is_configured (self->d3d11_decoder)) {
if (modified || !gst_d3d11_decoder_is_configured (inner->d3d11_decoder)) {
GstVideoInfo info;
GstVideoFormat out_format = GST_VIDEO_FORMAT_UNKNOWN;
if (self->bitdepth == 8) {
if (inner->bitdepth == 8) {
out_format = GST_VIDEO_FORMAT_NV12;
} else if (self->bitdepth == 10) {
} else if (inner->bitdepth == 10) {
out_format = GST_VIDEO_FORMAT_P010_10LE;
} else {
GST_WARNING_OBJECT (self, "Invalid bit-depth %d", seq_hdr->bit_depth);
@ -658,11 +670,11 @@ gst_d3d11_av1_dec_new_sequence (GstAV1Decoder * decoder,
}
gst_video_info_set_format (&info,
out_format, self->max_width, self->max_height);
out_format, inner->max_width, inner->max_height);
if (!gst_d3d11_decoder_configure (self->d3d11_decoder, GST_D3D11_CODEC_AV1,
decoder->input_state, &info, (gint) self->max_width,
(gint) self->max_height, NUM_OUTPUT_VIEW)) {
if (!gst_d3d11_decoder_configure (inner->d3d11_decoder,
decoder->input_state, &info, (gint) inner->max_width,
(gint) inner->max_height, NUM_OUTPUT_VIEW)) {
GST_ERROR_OBJECT (self, "Failed to create decoder");
return FALSE;
}
@ -681,9 +693,10 @@ gst_d3d11_av1_dec_new_picture (GstAV1Decoder * decoder,
GstVideoCodecFrame * frame, GstAV1Picture * picture)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
GstBuffer *view_buffer;
view_buffer = gst_d3d11_decoder_get_output_view_buffer (self->d3d11_decoder,
view_buffer = gst_d3d11_decoder_get_output_view_buffer (inner->d3d11_decoder,
GST_VIDEO_DECODER (decoder));
if (!view_buffer) {
GST_DEBUG_OBJECT (self, "No available output view buffer");
@ -726,28 +739,11 @@ gst_d3d11_av1_dec_duplicate_picture (GstAV1Decoder * decoder,
return new_picture;
}
static gboolean
gst_d3d11_av1_dec_get_bitstream_buffer (GstD3D11AV1Dec * self)
{
GST_TRACE_OBJECT (self, "Getting bitstream buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &self->remaining_buffer_size,
(gpointer *) & self->bitstream_buffer_data)) {
GST_ERROR_OBJECT (self, "Faild to get bitstream buffer");
return FALSE;
}
GST_TRACE_OBJECT (self, "Got bitstream buffer %p with size %d",
self->bitstream_buffer_data, self->remaining_buffer_size);
self->written_buffer_size = 0;
return TRUE;
}
static ID3D11VideoDecoderOutputView *
gst_d3d11_av1_dec_get_output_view_from_picture (GstD3D11AV1Dec * self,
GstAV1Picture * picture, guint8 * view_id)
{
GstD3D11AV1DecInner *inner = self->inner;
GstBuffer *view_buffer;
ID3D11VideoDecoderOutputView *view;
@ -758,7 +754,7 @@ gst_d3d11_av1_dec_get_output_view_from_picture (GstD3D11AV1Dec * self,
}
view =
gst_d3d11_decoder_get_output_view_from_buffer (self->d3d11_decoder,
gst_d3d11_decoder_get_output_view_from_buffer (inner->d3d11_decoder,
view_buffer, view_id);
if (!view) {
GST_DEBUG_OBJECT (self, "current picture does not have output view handle");
@ -773,10 +769,11 @@ gst_d3d11_av1_dec_start_picture (GstAV1Decoder * decoder,
GstAV1Picture * picture, GstAV1Dpb * dpb)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
const GstAV1SequenceHeaderOBU *seq_hdr = &self->seq_hdr;
GstD3D11AV1DecInner *inner = self->inner;
const GstAV1SequenceHeaderOBU *seq_hdr = &inner->seq_hdr;
const GstAV1FrameHeaderOBU *frame_hdr = &picture->frame_hdr;
ID3D11VideoDecoderOutputView *view;
GST_DXVA_PicParams_AV1 *pic_params = &self->pic_params;
GST_DXVA_PicParams_AV1 *pic_params = &inner->pic_params;
guint8 view_id = 0xff;
guint i, j;
@ -787,13 +784,6 @@ gst_d3d11_av1_dec_start_picture (GstAV1Decoder * decoder,
return FALSE;
}
GST_TRACE_OBJECT (self, "Begin frame");
if (!gst_d3d11_decoder_begin_frame (self->d3d11_decoder, view, 0, NULL)) {
GST_ERROR_OBJECT (self, "Failed to begin frame");
return FALSE;
}
memset (pic_params, 0, sizeof (GST_DXVA_PicParams_AV1));
pic_params->width = frame_hdr->frame_width;
@ -1097,7 +1087,10 @@ gst_d3d11_av1_dec_start_picture (GstAV1Decoder * decoder,
pic_params->film_grain.cr_offset = frame_hdr->film_grain_params.cr_offset;
}
return gst_d3d11_av1_dec_get_bitstream_buffer (self);
inner->bitstream_buffer.resize (0);
inner->tile_list.resize (0);
return TRUE;
}
static gboolean
@ -1105,43 +1098,27 @@ gst_d3d11_av1_dec_decode_tile (GstAV1Decoder * decoder,
GstAV1Picture * picture, GstAV1Tile * tile)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
GstAV1TileGroupOBU *tile_group = &tile->tile_group;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
guint i;
view = gst_d3d11_av1_dec_get_output_view_from_picture (self, picture,
&view_id);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
if (tile_group->num_tiles > inner->tile_list.size ())
inner->tile_list.resize (tile_group->num_tiles);
if (tile_group->num_tiles > self->tile_list->len)
g_array_set_size (self->tile_list, tile_group->num_tiles);
g_assert (tile_group->tg_end < self->tile_list->len);
if (tile->obu.obu_size > self->remaining_buffer_size) {
GST_ERROR_OBJECT (self, "Too large OBU size");
return FALSE;
}
g_assert (tile_group->tg_end < inner->tile_list.size ());
GST_LOG_OBJECT (self, "Decode tile, tile count %d (start: %d - end: %d)",
tile_group->num_tiles, tile_group->tg_start, tile_group->tg_end);
for (i = tile_group->tg_start; i <= tile_group->tg_end; i++) {
GST_DXVA_Tile_AV1 *dxva_tile =
&g_array_index (self->tile_list, GST_DXVA_Tile_AV1, i);
for (guint i = tile_group->tg_start; i <= tile_group->tg_end; i++) {
GST_DXVA_Tile_AV1 *dxva_tile = &inner->tile_list[i];
GST_TRACE_OBJECT (self,
"Written size %d, Tile offset %d, size %d, row %d, col %d",
self->written_buffer_size,
"Tile offset %d, size %d, row %d, col %d",
tile_group->entry[i].tile_offset, tile_group->entry[i].tile_size,
tile_group->entry[i].tile_row, tile_group->entry[i].tile_col);
dxva_tile->DataOffset =
self->written_buffer_size + tile_group->entry[i].tile_offset;
dxva_tile->DataOffset = inner->bitstream_buffer.size () +
tile_group->entry[i].tile_offset;
dxva_tile->DataSize = tile_group->entry[i].tile_size;
dxva_tile->row = tile_group->entry[i].tile_row;
dxva_tile->column = tile_group->entry[i].tile_col;
@ -1151,10 +1128,11 @@ gst_d3d11_av1_dec_decode_tile (GstAV1Decoder * decoder,
GST_TRACE_OBJECT (self, "OBU size %d", tile->obu.obu_size);
memcpy (self->bitstream_buffer_data, tile->obu.data, tile->obu.obu_size);
self->remaining_buffer_size -= tile->obu.obu_size;
self->bitstream_buffer_data += tile->obu.obu_size;
self->written_buffer_size += tile->obu.obu_size;
size_t pos = inner->bitstream_buffer.size ();
inner->bitstream_buffer.resize (pos + tile->obu.obu_size);
memcpy (&inner->bitstream_buffer[0] + pos,
tile->obu.data, tile->obu.obu_size);
return TRUE;
}
@ -1163,112 +1141,52 @@ static gboolean
gst_d3d11_av1_dec_end_picture (GstAV1Decoder * decoder, GstAV1Picture * picture)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
guint d3d11_buffer_size;
gpointer d3d11_buffer;
guint padding;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3];
guint i;
guint8 *data;
gsize offset = 0;
GstD3D11AV1DecInner *inner = self->inner;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
size_t bitstream_buffer_size;
size_t bitstream_pos;
GstD3D11DecodeInputStreamArgs input_args;
GST_TRACE_OBJECT (self, "Getting picture params buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self,
"Failed to get decoder buffer for picture parameters");
if (inner->bitstream_buffer.empty () || inner->tile_list.empty ()) {
GST_ERROR_OBJECT (self, "No bitstream buffer to submit");
return FALSE;
}
if (d3d11_buffer_size < sizeof (GST_DXVA_PicParams_AV1)) {
GST_ERROR_OBJECT (self,
"Too small picture param buffer %d", d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS);
view = gst_d3d11_av1_dec_get_output_view_from_picture (self, picture,
&view_id);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
memcpy (d3d11_buffer, &self->pic_params, sizeof (GST_DXVA_PicParams_AV1));
memset (&input_args, 0, sizeof (GstD3D11DecodeInputStreamArgs));
GST_TRACE_OBJECT (self, "Release picture param decoder buffer");
bitstream_pos = inner->bitstream_buffer.size ();
bitstream_buffer_size = GST_ROUND_UP_128 (bitstream_pos);
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS)) {
GST_ERROR_OBJECT (self, "Failed to release decoder buffer");
return FALSE;
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);
GST_DXVA_Tile_AV1 & tile = inner->tile_list.back ();
tile.DataSize += padding;
}
GST_TRACE_OBJECT (self, "Getting slice control buffer");
input_args.picture_params = &inner->pic_params;
input_args.picture_params_size = sizeof (GST_DXVA_PicParams_AV1);
input_args.slice_control = &inner->tile_list[0];
input_args.slice_control_size =
sizeof (GST_DXVA_Tile_AV1) * inner->tile_list.size ();
input_args.bitstream = &inner->bitstream_buffer[0];
input_args.bitstream_size = inner->bitstream_buffer.size ();
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get slice control buffer");
return FALSE;
}
if (d3d11_buffer_size < sizeof (GST_DXVA_Tile_AV1) * self->tile_list->len) {
GST_ERROR_OBJECT (self, "Too small slice control buffer %d",
d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL);
return FALSE;
}
data = (guint8 *) d3d11_buffer;
for (i = 0; i < self->tile_list->len; i++) {
GST_DXVA_Tile_AV1 *dxva_tile =
&g_array_index (self->tile_list, GST_DXVA_Tile_AV1, i);
memcpy (data + offset, dxva_tile, sizeof (GST_DXVA_Tile_AV1));
offset += sizeof (GST_DXVA_Tile_AV1);
}
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL)) {
GST_ERROR_OBJECT (self, "Failed to release slice control buffer");
return FALSE;
}
padding = MIN (GST_ROUND_UP_128 (self->written_buffer_size) -
self->written_buffer_size, self->remaining_buffer_size);
if (padding) {
memset (self->bitstream_buffer_data, 0, padding);
self->written_buffer_size += padding;
}
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM)) {
GST_ERROR_OBJECT (self, "Failed to release bitstream buffer");
return FALSE;
}
buffer_desc[0].BufferType = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
buffer_desc[0].DataOffset = 0;
buffer_desc[0].DataSize = sizeof (GST_DXVA_PicParams_AV1);
buffer_desc[1].BufferType = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
buffer_desc[1].DataOffset = 0;
buffer_desc[1].DataSize = sizeof (GST_DXVA_Tile_AV1) * self->tile_list->len;
buffer_desc[2].BufferType = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
buffer_desc[2].DataOffset = 0;
buffer_desc[2].DataSize = self->written_buffer_size;
if (!gst_d3d11_decoder_submit_decoder_buffers (self->d3d11_decoder,
3, buffer_desc)) {
GST_ERROR_OBJECT (self, "Couldn't submit decoder buffers");
return FALSE;
}
if (!gst_d3d11_decoder_end_frame (self->d3d11_decoder)) {
GST_ERROR_OBJECT (self, "Failed to EndFrame");
return FALSE;
}
return TRUE;
return gst_d3d11_decoder_decode_frame (inner->d3d11_decoder,
view, &input_args);
}
static GstFlowReturn
@ -1276,6 +1194,7 @@ gst_d3d11_av1_dec_output_picture (GstAV1Decoder * decoder,
GstVideoCodecFrame * frame, GstAV1Picture * picture)
{
GstD3D11AV1Dec *self = GST_D3D11_AV1_DEC (decoder);
GstD3D11AV1DecInner *inner = self->inner;
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
@ -1289,7 +1208,7 @@ gst_d3d11_av1_dec_output_picture (GstAV1Decoder * decoder,
goto error;
}
if (!gst_d3d11_decoder_process_output (self->d3d11_decoder, vdec,
if (!gst_d3d11_decoder_process_output (inner->d3d11_decoder, vdec,
picture->frame_hdr.render_width, picture->frame_hdr.render_height,
view_buffer, &frame->output_buffer)) {
GST_ERROR_OBJECT (self, "Failed to copy buffer");
@ -1302,20 +1221,14 @@ gst_d3d11_av1_dec_output_picture (GstAV1Decoder * decoder,
error:
gst_av1_picture_unref (picture);
gst_video_decoder_drop_frame (vdec, frame);
gst_video_decoder_release_frame (vdec, frame);
return GST_FLOW_ERROR;
}
typedef struct
{
guint width;
guint height;
} GstD3D11AV1DecResolution;
void
gst_d3d11_av1_dec_register (GstPlugin * plugin, GstD3D11Device * device,
GstD3D11Decoder * decoder, guint rank)
guint rank)
{
GType type;
gchar *type_name;
@ -1334,10 +1247,6 @@ gst_d3d11_av1_dec_register (GstPlugin * plugin, GstD3D11Device * device,
(GInstanceInitFunc) gst_d3d11_av1_dec_init,
};
const GUID *profile_guid = NULL;
/* values were taken from chromium. See supported_profile_helper.cc */
GstD3D11AV1DecResolution resolutions_to_check[] = {
{4096, 2160}, {4096, 2304}, {7680, 4320}, {8192, 4320}, {8192, 8192}
};
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
guint max_width = 0;
@ -1347,29 +1256,29 @@ gst_d3d11_av1_dec_register (GstPlugin * plugin, GstD3D11Device * device,
gboolean have_gray = FALSE;
gboolean have_gray10 = FALSE;
if (!gst_d3d11_decoder_get_supported_decoder_profile (decoder,
GST_D3D11_CODEC_AV1, GST_VIDEO_FORMAT_NV12, &profile_guid)) {
if (!gst_d3d11_decoder_get_supported_decoder_profile (device,
GST_DXVA_CODEC_AV1, GST_VIDEO_FORMAT_NV12, &profile_guid)) {
GST_INFO_OBJECT (device, "device does not support VP8 decoding");
return;
}
have_p010 = gst_d3d11_decoder_supports_format (decoder,
have_p010 = gst_d3d11_decoder_supports_format (device,
profile_guid, DXGI_FORMAT_P010);
have_gray = gst_d3d11_decoder_supports_format (decoder,
have_gray = gst_d3d11_decoder_supports_format (device,
profile_guid, DXGI_FORMAT_R8_UNORM);
have_gray10 = gst_d3d11_decoder_supports_format (decoder,
have_gray10 = gst_d3d11_decoder_supports_format (device,
profile_guid, DXGI_FORMAT_R16_UNORM);
GST_INFO_OBJECT (device, "Decoder support P010: %d, R8: %d, R16: %d",
have_p010, have_gray, have_gray10);
/* TODO: add test monochrome formats */
for (i = 0; i < G_N_ELEMENTS (resolutions_to_check); i++) {
if (gst_d3d11_decoder_supports_resolution (decoder, profile_guid,
DXGI_FORMAT_NV12, resolutions_to_check[i].width,
resolutions_to_check[i].height)) {
max_width = resolutions_to_check[i].width;
max_height = resolutions_to_check[i].height;
for (i = 0; i < G_N_ELEMENTS (gst_dxva_resolutions); i++) {
if (gst_d3d11_decoder_supports_resolution (device, profile_guid,
DXGI_FORMAT_NV12, gst_dxva_resolutions[i].width,
gst_dxva_resolutions[i].height)) {
max_width = gst_dxva_resolutions[i].width;
max_height = gst_dxva_resolutions[i].height;
GST_DEBUG_OBJECT (device,
"device support resolution %dx%d", max_width, max_height);
@ -1419,7 +1328,7 @@ gst_d3d11_av1_dec_register (GstPlugin * plugin, GstD3D11Device * device,
"height", GST_TYPE_INT_RANGE, 1, resolution, NULL);
type_info.class_data =
gst_d3d11_decoder_class_data_new (device, GST_D3D11_CODEC_AV1,
gst_d3d11_decoder_class_data_new (device, GST_DXVA_CODEC_AV1,
sink_caps, src_caps);
type_name = g_strdup ("GstD3D11AV1Dec");

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_av1_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank);
G_END_DECLS

View file

@ -61,8 +61,8 @@
#include <timeapi.h>
#endif
GST_DEBUG_CATEGORY (d3d11_decoder_debug);
#define GST_CAT_DEFAULT d3d11_decoder_debug
GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_decoder_debug);
#define GST_CAT_DEFAULT gst_d3d11_decoder_debug
/* GUID might not be defined in MinGW header */
DEFINE_GUID (GST_GUID_D3D11_DECODER_PROFILE_H264_IDCT_FGT, 0x1b81be67, 0xa0c7,
@ -146,7 +146,7 @@ struct _GstD3D11Decoder
GstVideoInfo info;
GstVideoInfo output_info;
GstD3D11Codec codec;
GstDXVACodec codec;
gint coded_width;
gint coded_height;
DXGI_FORMAT decoder_format;
@ -214,9 +214,6 @@ gst_d3d11_decoder_class_init (GstD3D11DecoderClass * klass)
"D3D11 Devicd to use", GST_TYPE_D3D11_DEVICE,
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
GST_DEBUG_CATEGORY_INIT (d3d11_decoder_debug,
"d3d11decoder", 0, "Direct3D11 Base Video Decoder object");
}
static void
@ -359,11 +356,13 @@ gst_d3d11_decoder_finalize (GObject * obj)
}
GstD3D11Decoder *
gst_d3d11_decoder_new (GstD3D11Device * device)
gst_d3d11_decoder_new (GstD3D11Device * device, GstDXVACodec codec)
{
GstD3D11Decoder *self;
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), nullptr);
g_return_val_if_fail (codec > GST_DXVA_CODEC_NONE, nullptr);
g_return_val_if_fail (codec < GST_DXVA_CODEC_LAST, nullptr);
self = (GstD3D11Decoder *)
g_object_new (GST_TYPE_D3D11_DECODER, "device", device, NULL);
@ -373,6 +372,8 @@ gst_d3d11_decoder_new (GstD3D11Device * device)
return NULL;
}
self->codec = codec;
gst_object_ref_sink (self);
return self;
@ -537,22 +538,22 @@ error:
}
static const gchar *
gst_d3d11_codec_to_string (GstD3D11Codec codec)
gst_dxva_codec_to_string (GstDXVACodec codec)
{
switch (codec) {
case GST_D3D11_CODEC_NONE:
case GST_DXVA_CODEC_NONE:
return "none";
case GST_D3D11_CODEC_H264:
case GST_DXVA_CODEC_H264:
return "H.264";
case GST_D3D11_CODEC_VP9:
case GST_DXVA_CODEC_VP9:
return "VP9";
case GST_D3D11_CODEC_H265:
case GST_DXVA_CODEC_H265:
return "H.265";
case GST_D3D11_CODEC_VP8:
case GST_DXVA_CODEC_VP8:
return "VP8";
case GST_D3D11_CODEC_MPEG2:
case GST_DXVA_CODEC_MPEG2:
return "MPEG2";
case GST_D3D11_CODEC_AV1:
case GST_DXVA_CODEC_AV1:
return "AV1";
default:
g_assert_not_reached ();
@ -563,29 +564,33 @@ gst_d3d11_codec_to_string (GstD3D11Codec codec)
}
gboolean
gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
GstD3D11Codec codec, GstVideoFormat format, const GUID ** selected_profile)
gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Device * device,
GstDXVACodec codec, GstVideoFormat format, const GUID ** selected_profile)
{
GUID *guid_list = NULL;
const GUID *profile = NULL;
GUID *guid_list = nullptr;
const GUID *profile = nullptr;
guint available_profile_count;
guint i, j;
HRESULT hr;
ID3D11VideoDevice *video_device;
const GUID **profile_list = NULL;
const GUID **profile_list = nullptr;
guint profile_size = 0;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (selected_profile != NULL, FALSE);
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE);
g_return_val_if_fail (selected_profile != nullptr, FALSE);
video_device = gst_d3d11_device_get_video_device_handle (device);
if (!video_device)
return FALSE;
switch (codec) {
case GST_D3D11_CODEC_H264:
case GST_DXVA_CODEC_H264:
if (format == GST_VIDEO_FORMAT_NV12) {
profile_list = profile_h264_list;
profile_size = G_N_ELEMENTS (profile_h264_list);
}
break;
case GST_D3D11_CODEC_H265:
case GST_DXVA_CODEC_H265:
if (format == GST_VIDEO_FORMAT_NV12) {
profile_list = profile_hevc_list;
profile_size = G_N_ELEMENTS (profile_hevc_list);
@ -594,13 +599,13 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
profile_size = G_N_ELEMENTS (profile_hevc_10_list);
}
break;
case GST_D3D11_CODEC_VP8:
case GST_DXVA_CODEC_VP8:
if (format == GST_VIDEO_FORMAT_NV12) {
profile_list = profile_vp8_list;
profile_size = G_N_ELEMENTS (profile_vp8_list);
}
break;
case GST_D3D11_CODEC_VP9:
case GST_DXVA_CODEC_VP9:
if (format == GST_VIDEO_FORMAT_NV12) {
profile_list = profile_vp9_list;
profile_size = G_N_ELEMENTS (profile_vp9_list);
@ -609,13 +614,13 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
profile_size = G_N_ELEMENTS (profile_vp9_10_list);
}
break;
case GST_D3D11_CODEC_MPEG2:
case GST_DXVA_CODEC_MPEG2:
if (format == GST_VIDEO_FORMAT_NV12) {
profile_list = profile_mpeg2_list;
profile_size = G_N_ELEMENTS (profile_mpeg2_list);
}
break;
case GST_D3D11_CODEC_AV1:
case GST_DXVA_CODEC_AV1:
profile_list = profile_av1_list;
profile_size = G_N_ELEMENTS (profile_av1_list);
break;
@ -624,50 +629,48 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
}
if (!profile_list) {
GST_ERROR_OBJECT (decoder,
GST_ERROR_OBJECT (device,
"Not supported codec (%d) and format (%s) configuration", codec,
gst_video_format_to_string (format));
return FALSE;
}
video_device = decoder->video_device;
available_profile_count = video_device->GetVideoDecoderProfileCount ();
if (available_profile_count == 0) {
GST_WARNING_OBJECT (decoder, "No available decoder profile");
GST_INFO_OBJECT (device, "No available decoder profile");
return FALSE;
}
GST_DEBUG_OBJECT (decoder,
GST_DEBUG_OBJECT (device,
"Have %u available decoder profiles", available_profile_count);
guid_list = (GUID *) g_alloca (sizeof (GUID) * available_profile_count);
for (i = 0; i < available_profile_count; i++) {
hr = video_device->GetVideoDecoderProfile (i, &guid_list[i]);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "Failed to get %d th decoder profile", i);
if (!gst_d3d11_result (hr, device)) {
GST_WARNING_OBJECT (device, "Failed to get %d th decoder profile", i);
return FALSE;
}
}
#ifndef GST_DISABLE_GST_DEBUG
GST_LOG_OBJECT (decoder, "Supported decoder GUID");
GST_LOG_OBJECT (device, "Supported decoder GUID");
for (i = 0; i < available_profile_count; i++) {
const GUID *guid = &guid_list[i];
GST_LOG_OBJECT (decoder,
GST_LOG_OBJECT (device,
"\t { %8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x }",
(guint) guid->Data1, (guint) guid->Data2, (guint) guid->Data3,
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
}
GST_LOG_OBJECT (decoder, "Requested decoder GUID");
GST_LOG_OBJECT (device, "Requested decoder GUID");
for (i = 0; i < profile_size; i++) {
const GUID *guid = profile_list[i];
GST_LOG_OBJECT (decoder,
GST_LOG_OBJECT (device,
"\t { %8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x }",
(guint) guid->Data1, (guint) guid->Data2, (guint) guid->Data3,
guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
@ -685,14 +688,14 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
}
if (!profile) {
GST_INFO_OBJECT (decoder, "No supported decoder profile for %s codec",
gst_d3d11_codec_to_string (codec));
GST_INFO_OBJECT (device, "No supported decoder profile for %s codec",
gst_dxva_codec_to_string (codec));
return FALSE;
}
*selected_profile = profile;
GST_DEBUG_OBJECT (decoder,
GST_DEBUG_OBJECT (device,
"Selected guid "
"{ %8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x }",
(guint) profile->Data1, (guint) profile->Data2, (guint) profile->Data3,
@ -705,15 +708,13 @@ gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
gboolean
gst_d3d11_decoder_configure (GstD3D11Decoder * decoder, GstD3D11Codec codec,
gst_d3d11_decoder_configure (GstD3D11Decoder * decoder,
GstVideoCodecState * input_state, GstVideoInfo * info, gint coded_width,
gint coded_height, guint dpb_size)
{
const GstD3D11Format *d3d11_format;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (codec > GST_D3D11_CODEC_NONE, FALSE);
g_return_val_if_fail (codec < GST_D3D11_CODEC_LAST, FALSE);
g_return_val_if_fail (info != NULL, FALSE);
g_return_val_if_fail (input_state != NULL, FALSE);
g_return_val_if_fail (coded_width >= GST_VIDEO_INFO_WIDTH (info), FALSE);
@ -730,7 +731,6 @@ gst_d3d11_decoder_configure (GstD3D11Decoder * decoder, GstD3D11Codec codec,
return FALSE;
}
decoder->codec = codec;
decoder->input_state = gst_video_codec_state_ref (input_state);
decoder->info = decoder->output_info = *info;
decoder->coded_width = coded_width;
@ -832,7 +832,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self)
video_device = self->video_device;
gst_d3d11_device_lock (self->device);
if (!gst_d3d11_decoder_get_supported_decoder_profile (self,
if (!gst_d3d11_decoder_get_supported_decoder_profile (self->device,
self->codec, GST_VIDEO_INFO_FORMAT (info), &selected_profile)) {
goto error;
}
@ -867,15 +867,15 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self)
* directx_va_Setup() in directx_va.c of vlc.
* But... where it is? */
switch (self->codec) {
case GST_D3D11_CODEC_H265:
case GST_D3D11_CODEC_AV1:
case GST_DXVA_CODEC_H265:
case GST_DXVA_CODEC_AV1:
/* See directx_va_Setup() impl. in vlc */
if (vendor != GST_D3D11_DEVICE_VENDOR_XBOX)
alignment = 128;
else
alignment = 16;
break;
case GST_D3D11_CODEC_MPEG2:
case GST_DXVA_CODEC_MPEG2:
/* XXX: ffmpeg does this */
alignment = 32;
break;
@ -926,15 +926,15 @@ gst_d3d11_decoder_open (GstD3D11Decoder * self)
/* FIXME: need support DXVA_Slice_H264_Long ?? */
/* this config uses DXVA_Slice_H264_Short */
switch (self->codec) {
case GST_D3D11_CODEC_H264:
case GST_DXVA_CODEC_H264:
if (config_list[i].ConfigBitstreamRaw == 2)
best_config = &config_list[i];
break;
case GST_D3D11_CODEC_H265:
case GST_D3D11_CODEC_VP9:
case GST_D3D11_CODEC_VP8:
case GST_D3D11_CODEC_MPEG2:
case GST_D3D11_CODEC_AV1:
case GST_DXVA_CODEC_H265:
case GST_DXVA_CODEC_VP9:
case GST_DXVA_CODEC_VP8:
case GST_DXVA_CODEC_MPEG2:
case GST_DXVA_CODEC_AV1:
if (config_list[i].ConfigBitstreamRaw == 1)
best_config = &config_list[i];
break;
@ -1001,7 +1001,7 @@ error:
return FALSE;
}
gboolean
static gboolean
gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
ID3D11VideoDecoderOutputView * output_view, guint content_key_size,
gconstpointer content_key)
@ -1015,12 +1015,8 @@ gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
if (decoder->timer_resolution)
retry_threshold = 500;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (output_view != NULL, FALSE);
video_context = decoder->video_context;
gst_d3d11_device_lock (decoder->device);
do {
GST_LOG_OBJECT (decoder, "Try begin frame, retry count %d", retry_count);
hr = video_context->DecoderBeginFrame (decoder->decoder_handle,
@ -1041,7 +1037,6 @@ gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
retry_count++;
} while (TRUE);
gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_ERROR_OBJECT (decoder, "Failed to begin frame, hr: 0x%x", (guint) hr);
@ -1051,19 +1046,14 @@ gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
return TRUE;
}
gboolean
static gboolean
gst_d3d11_decoder_end_frame (GstD3D11Decoder * decoder)
{
HRESULT hr;
ID3D11VideoContext *video_context;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
video_context = decoder->video_context;
gst_d3d11_device_lock (decoder->device);
hr = video_context->DecoderEndFrame (decoder->decoder_handle);
gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "EndFrame failed, hr: 0x%x", (guint) hr);
@ -1073,7 +1063,7 @@ gst_d3d11_decoder_end_frame (GstD3D11Decoder * decoder)
return TRUE;
}
gboolean
static gboolean
gst_d3d11_decoder_get_decoder_buffer (GstD3D11Decoder * decoder,
D3D11_VIDEO_DECODER_BUFFER_TYPE type, guint * buffer_size,
gpointer * buffer)
@ -1083,14 +1073,9 @@ gst_d3d11_decoder_get_decoder_buffer (GstD3D11Decoder * decoder,
HRESULT hr;
ID3D11VideoContext *video_context;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
video_context = decoder->video_context;
gst_d3d11_device_lock (decoder->device);
hr = video_context->GetDecoderBuffer (decoder->decoder_handle,
type, &size, &decoder_buffer);
gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "Getting buffer type %d error, hr: 0x%x",
@ -1104,20 +1089,15 @@ gst_d3d11_decoder_get_decoder_buffer (GstD3D11Decoder * decoder,
return TRUE;
}
gboolean
static gboolean
gst_d3d11_decoder_release_decoder_buffer (GstD3D11Decoder * decoder,
D3D11_VIDEO_DECODER_BUFFER_TYPE type)
{
HRESULT hr;
ID3D11VideoContext *video_context;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
video_context = decoder->video_context;
gst_d3d11_device_lock (decoder->device);
hr = video_context->ReleaseDecoderBuffer (decoder->decoder_handle, type);
gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "ReleaseDecoderBuffer failed, hr: 0x%x",
@ -1128,22 +1108,16 @@ gst_d3d11_decoder_release_decoder_buffer (GstD3D11Decoder * decoder,
return TRUE;
}
gboolean
static gboolean
gst_d3d11_decoder_submit_decoder_buffers (GstD3D11Decoder * decoder,
guint buffer_count, const D3D11_VIDEO_DECODER_BUFFER_DESC * buffers)
{
HRESULT hr;
ID3D11VideoContext *video_context;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
video_context = decoder->video_context;
gst_d3d11_device_lock (decoder->device);
hr = video_context->SubmitDecoderBuffers (decoder->decoder_handle,
buffer_count, buffers);
gst_d3d11_device_unlock (decoder->device);
if (!gst_d3d11_result (hr, decoder->device)) {
GST_WARNING_OBJECT (decoder, "SubmitDecoderBuffers failed, hr: 0x%x",
(guint) hr);
@ -1153,6 +1127,174 @@ gst_d3d11_decoder_submit_decoder_buffers (GstD3D11Decoder * decoder,
return TRUE;
}
gboolean
gst_d3d11_decoder_decode_frame (GstD3D11Decoder * decoder,
ID3D11VideoDecoderOutputView * output_view,
GstD3D11DecodeInputStreamArgs * input_args)
{
guint d3d11_buffer_size;
gpointer d3d11_buffer;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4];
guint buffer_desc_size;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (output_view != nullptr, FALSE);
g_return_val_if_fail (input_args != nullptr, FALSE);
memset (buffer_desc, 0, sizeof (buffer_desc));
buffer_desc[0].BufferType = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
buffer_desc[0].DataSize = input_args->picture_params_size;
buffer_desc[1].BufferType = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
buffer_desc[1].DataSize = input_args->slice_control_size;
buffer_desc[2].BufferType = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
buffer_desc[2].DataOffset = 0;
buffer_desc[2].DataSize = input_args->bitstream_size;
buffer_desc_size = 3;
if (input_args->inverse_quantization_matrix &&
input_args->inverse_quantization_matrix_size > 0) {
buffer_desc[3].BufferType =
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX;
buffer_desc[3].DataSize = input_args->inverse_quantization_matrix_size;
buffer_desc_size++;
}
gst_d3d11_device_lock (decoder->device);
if (!gst_d3d11_decoder_begin_frame (decoder, output_view, 0, nullptr)) {
gst_d3d11_device_unlock (decoder->device);
return FALSE;
}
if (!gst_d3d11_decoder_get_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (decoder,
"Failed to get decoder buffer for picture parameters");
goto error;
}
if (d3d11_buffer_size < input_args->picture_params_size) {
GST_ERROR_OBJECT (decoder,
"Too small picture param buffer size %d", d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS);
goto error;
}
memcpy (d3d11_buffer, input_args->picture_params,
input_args->picture_params_size);
if (!gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS)) {
GST_ERROR_OBJECT (decoder, "Failed to release picture param buffer");
goto error;
}
if (!gst_d3d11_decoder_get_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (decoder, "Failed to get slice control buffer");
goto error;
}
if (d3d11_buffer_size < input_args->slice_control_size) {
GST_ERROR_OBJECT (decoder,
"Too small slice control buffer size %d", d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL);
goto error;
}
memcpy (d3d11_buffer,
input_args->slice_control, input_args->slice_control_size);
if (!gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL)) {
GST_ERROR_OBJECT (decoder, "Failed to release slice control buffer");
goto error;
}
if (!gst_d3d11_decoder_get_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (decoder, "Failed to get bitstream buffer");
goto error;
}
if (d3d11_buffer_size < input_args->bitstream_size) {
GST_ERROR_OBJECT (decoder, "Too small bitstream buffer size %d",
d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM);
goto error;
}
memcpy (d3d11_buffer, input_args->bitstream, input_args->bitstream_size);
if (!gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM)) {
GST_ERROR_OBJECT (decoder, "Failed to release bitstream buffer");
goto error;
}
if (input_args->inverse_quantization_matrix_size > 0) {
if (!gst_d3d11_decoder_get_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX,
&d3d11_buffer_size, &d3d11_buffer)) {
GST_ERROR_OBJECT (decoder,
"Failed to get inverse quantization matrix buffer");
goto error;
}
if (d3d11_buffer_size < input_args->inverse_quantization_matrix_size) {
GST_ERROR_OBJECT (decoder,
"Too small inverse quantization matrix buffer buffer %d",
d3d11_buffer_size);
gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX);
goto error;
}
memcpy (d3d11_buffer, input_args->inverse_quantization_matrix,
input_args->inverse_quantization_matrix_size);
if (!gst_d3d11_decoder_release_decoder_buffer (decoder,
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX)) {
GST_ERROR_OBJECT (decoder,
"Failed to release inverse quantization matrix buffer");
goto error;
}
}
if (!gst_d3d11_decoder_submit_decoder_buffers (decoder,
buffer_desc_size, buffer_desc)) {
GST_ERROR_OBJECT (decoder, "Failed to submit decoder buffers");
goto error;
}
if (!gst_d3d11_decoder_end_frame (decoder)) {
gst_d3d11_device_unlock (decoder->device);
return FALSE;
}
gst_d3d11_device_unlock (decoder->device);
return TRUE;
error:
gst_d3d11_decoder_end_frame (decoder);
gst_d3d11_device_unlock (decoder->device);
return FALSE;
}
GstBuffer *
gst_d3d11_decoder_get_output_view_buffer (GstD3D11Decoder * decoder,
GstVideoDecoder * videodec)
@ -1885,23 +2027,25 @@ gst_d3d11_decoder_util_is_legacy_device (GstD3D11Device * device)
}
gboolean
gst_d3d11_decoder_supports_format (GstD3D11Decoder * decoder,
gst_d3d11_decoder_supports_format (GstD3D11Device * device,
const GUID * decoder_profile, DXGI_FORMAT format)
{
HRESULT hr;
BOOL can_support = FALSE;
ID3D11VideoDevice *video_device;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE);
g_return_val_if_fail (decoder_profile != NULL, FALSE);
g_return_val_if_fail (format != DXGI_FORMAT_UNKNOWN, FALSE);
video_device = decoder->video_device;
video_device = gst_d3d11_device_get_video_device_handle (device);
if (!video_device)
return FALSE;
hr = video_device->CheckVideoDecoderFormat (decoder_profile, format,
&can_support);
if (!gst_d3d11_result (hr, decoder->device) || !can_support) {
GST_DEBUG_OBJECT (decoder,
if (!gst_d3d11_result (hr, device) || !can_support) {
GST_DEBUG_OBJECT (device,
"VideoDevice could not support dxgi format %d, hr: 0x%x",
format, (guint) hr);
@ -1913,7 +2057,7 @@ gst_d3d11_decoder_supports_format (GstD3D11Decoder * decoder,
/* Don't call this method with legacy device */
gboolean
gst_d3d11_decoder_supports_resolution (GstD3D11Decoder * decoder,
gst_d3d11_decoder_supports_resolution (GstD3D11Device * device,
const GUID * decoder_profile, DXGI_FORMAT format, guint width, guint height)
{
D3D11_VIDEO_DECODER_DESC desc;
@ -1921,11 +2065,13 @@ gst_d3d11_decoder_supports_resolution (GstD3D11Decoder * decoder,
UINT config_count;
ID3D11VideoDevice *video_device;
g_return_val_if_fail (GST_IS_D3D11_DECODER (decoder), FALSE);
g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), FALSE);
g_return_val_if_fail (decoder_profile != NULL, FALSE);
g_return_val_if_fail (format != DXGI_FORMAT_UNKNOWN, FALSE);
video_device = decoder->video_device;
video_device = gst_d3d11_device_get_video_device_handle (device);
if (!video_device)
return FALSE;
desc.SampleWidth = width;
desc.SampleHeight = height;
@ -1933,8 +2079,8 @@ gst_d3d11_decoder_supports_resolution (GstD3D11Decoder * decoder,
desc.Guid = *decoder_profile;
hr = video_device->GetVideoDecoderConfigCount (&desc, &config_count);
if (!gst_d3d11_result (hr, decoder->device) || config_count == 0) {
GST_DEBUG_OBJECT (decoder, "Could not get decoder config count, hr: 0x%x",
if (!gst_d3d11_result (hr, device) || config_count == 0) {
GST_DEBUG_OBJECT (device, "Could not get decoder config count, hr: 0x%x",
(guint) hr);
return FALSE;
}
@ -1955,7 +2101,7 @@ struct _GstD3D11DecoderClassData
GstCaps *sink_caps;
GstCaps *src_caps;
gchar *description;
GstD3D11Codec codec;
GstDXVACodec codec;
};
/**
@ -1969,7 +2115,7 @@ struct _GstD3D11DecoderClassData
* Returns: (transfer full): the new #GstD3D11DecoderClassData
*/
GstD3D11DecoderClassData *
gst_d3d11_decoder_class_data_new (GstD3D11Device * device, GstD3D11Codec codec,
gst_d3d11_decoder_class_data_new (GstD3D11Device * device, GstDXVACodec codec,
GstCaps * sink_caps, GstCaps * src_caps)
{
GstD3D11DecoderClassData *ret;
@ -2044,7 +2190,7 @@ gst_d3d11_decoder_proxy_class_init (GstElementClass * klass,
"DXGI Vendor ID", 0, G_MAXUINT32, 0,
(GParamFlags) (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
codec_name = gst_d3d11_codec_to_string (data->codec);
codec_name = gst_dxva_codec_to_string (data->codec);
long_name = "Direct3D11/DXVA " + std::string (codec_name) + " " +
std::string (data->description) + " Decoder";
description = "Direct3D11/DXVA based " + std::string (codec_name) +

View file

@ -34,17 +34,17 @@ typedef struct _GstD3D11DecoderClassData GstD3D11DecoderClassData;
typedef enum
{
GST_D3D11_CODEC_NONE,
GST_D3D11_CODEC_H264,
GST_D3D11_CODEC_VP9,
GST_D3D11_CODEC_H265,
GST_D3D11_CODEC_VP8,
GST_D3D11_CODEC_MPEG2,
GST_D3D11_CODEC_AV1,
GST_DXVA_CODEC_NONE,
GST_DXVA_CODEC_MPEG2,
GST_DXVA_CODEC_H264,
GST_DXVA_CODEC_H265,
GST_DXVA_CODEC_VP8,
GST_DXVA_CODEC_VP9,
GST_DXVA_CODEC_AV1,
/* the last of supported codec */
GST_D3D11_CODEC_LAST
} GstD3D11Codec;
GST_DXVA_CODEC_LAST
} GstDXVACodec;
typedef struct
{
@ -53,36 +53,37 @@ typedef struct
guint vendor_id;
} GstD3D11DecoderSubClassData;
GstD3D11Decoder * gst_d3d11_decoder_new (GstD3D11Device * device);
typedef struct _GstD3D11DecodeInputStreamArgs
{
gpointer picture_params;
gsize picture_params_size;
gpointer slice_control;
gsize slice_control_size;
gpointer bitstream;
gsize bitstream_size;
gpointer inverse_quantization_matrix;
gsize inverse_quantization_matrix_size;
} GstD3D11DecodeInputStreamArgs;
GstD3D11Decoder * gst_d3d11_decoder_new (GstD3D11Device * device,
GstDXVACodec codec);
gboolean gst_d3d11_decoder_is_configured (GstD3D11Decoder * decoder);
gboolean gst_d3d11_decoder_configure (GstD3D11Decoder * decoder,
GstD3D11Codec codec,
GstVideoCodecState * input_state,
GstVideoInfo * info,
gint coded_width,
gint coded_height,
guint dpb_size);
gboolean gst_d3d11_decoder_begin_frame (GstD3D11Decoder * decoder,
ID3D11VideoDecoderOutputView * output_view,
guint content_key_size,
gconstpointer content_key);
gboolean gst_d3d11_decoder_decode_frame (GstD3D11Decoder * decoder,
ID3D11VideoDecoderOutputView * output_view,
GstD3D11DecodeInputStreamArgs * input_args);
gboolean gst_d3d11_decoder_end_frame (GstD3D11Decoder * decoder);
gboolean gst_d3d11_decoder_get_decoder_buffer (GstD3D11Decoder * decoder,
D3D11_VIDEO_DECODER_BUFFER_TYPE type,
guint * buffer_size,
gpointer * buffer);
gboolean gst_d3d11_decoder_release_decoder_buffer (GstD3D11Decoder * decoder,
D3D11_VIDEO_DECODER_BUFFER_TYPE type);
gboolean gst_d3d11_decoder_submit_decoder_buffers (GstD3D11Decoder * decoder,
guint buffer_count,
const D3D11_VIDEO_DECODER_BUFFER_DESC * buffers);
GstBuffer * gst_d3d11_decoder_get_output_view_buffer (GstD3D11Decoder * decoder,
GstVideoDecoder * videodec);
@ -110,25 +111,36 @@ gboolean gst_d3d11_decoder_set_flushing (GstD3D11Decoder * decod
gboolean flushing);
/* Utils for class registration */
typedef struct _GstDXVAResolution
{
guint width;
guint height;
} GstDXVAResolution;
static const GstDXVAResolution gst_dxva_resolutions[] = {
{1920, 1088}, {2560, 1440}, {3840, 2160}, {4096, 2160},
{7680, 4320}, {8192, 4320}
};
gboolean gst_d3d11_decoder_util_is_legacy_device (GstD3D11Device * device);
gboolean gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Decoder * decoder,
GstD3D11Codec codec,
gboolean gst_d3d11_decoder_get_supported_decoder_profile (GstD3D11Device * device,
GstDXVACodec codec,
GstVideoFormat format,
const GUID ** selected_profile);
gboolean gst_d3d11_decoder_supports_format (GstD3D11Decoder * decoder,
gboolean gst_d3d11_decoder_supports_format (GstD3D11Device * device,
const GUID * decoder_profile,
DXGI_FORMAT format);
gboolean gst_d3d11_decoder_supports_resolution (GstD3D11Decoder * decoder,
gboolean gst_d3d11_decoder_supports_resolution (GstD3D11Device * device,
const GUID * decoder_profile,
DXGI_FORMAT format,
guint width,
guint height);
GstD3D11DecoderClassData * gst_d3d11_decoder_class_data_new (GstD3D11Device * device,
GstD3D11Codec codec,
GstDXVACodec codec,
GstCaps * sink_caps,
GstCaps * src_caps);

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_h264_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank,
gboolean legacy);

File diff suppressed because it is too large Load diff

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_h265_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank);
G_END_DECLS

View file

@ -40,6 +40,7 @@
#include <gst/codecs/gstmpeg2decoder.h>
#include <string.h>
#include <vector>
/* HACK: to expose dxva data structure on UWP */
#ifdef WINAPI_PARTITION_DESKTOP
@ -55,28 +56,35 @@ GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_mpeg2_dec_debug);
/* reference list 2 + 4 margin */
#define NUM_OUTPUT_VIEW 6
/* *INDENT-OFF* */
typedef struct _GstD3D11Mpeg2DecInner
{
GstD3D11Device *device = nullptr;
GstD3D11Decoder *d3d11_decoder = nullptr;
DXVA_PictureParameters pic_params;
DXVA_QmatrixData iq_matrix;
std::vector<DXVA_SliceInfo> slice_list;
std::vector<guint8> bitstream_buffer;
gboolean submit_iq_data;
gint width = 0;
gint height = 0;
guint width_in_mb = 0;
guint height_in_mb = 0;
GstVideoFormat out_format = GST_VIDEO_FORMAT_UNKNOWN;
GstMpegVideoSequenceHdr seq;
GstMpegVideoProfile profile = GST_MPEG_VIDEO_PROFILE_MAIN;
gboolean interlaced = FALSE;
} GstD3D11Mpeg2DecInner;
/* *INDENT-ON* */
typedef struct _GstD3D11Mpeg2Dec
{
GstMpeg2Decoder parent;
GstD3D11Device *device;
GstD3D11Decoder *d3d11_decoder;
gint width, height;
guint width_in_mb, height_in_mb;
GstVideoFormat out_format;
GstMpegVideoSequenceHdr seq;
GstMpegVideoProfile profile;
gboolean interlaced;
/* Array of DXVA_SliceInfo */
GArray *slice_list;
gboolean submit_iq_data;
/* Pointing current bitstream buffer */
guint written_buffer_size;
guint remaining_buffer_size;
guint8 *bitstream_buffer_data;
GstD3D11Mpeg2DecInner *inner;
} GstD3D11Mpeg2Dec;
typedef struct _GstD3D11Mpeg2DecClass
@ -91,9 +99,9 @@ static GstElementClass *parent_class = NULL;
#define GST_D3D11_MPEG2_DEC_GET_CLASS(object) \
(G_TYPE_INSTANCE_GET_CLASS ((object),G_TYPE_FROM_INSTANCE (object),GstD3D11Mpeg2DecClass))
static void gst_d3d11_mpeg2_dec_finalize (GObject * object);
static void gst_d3d11_mpeg2_dec_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_d3d11_mpeg2_dec_finalize (GObject * object);
static void gst_d3d11_mpeg2_dec_set_context (GstElement * element,
GstContext * context);
@ -176,18 +184,7 @@ gst_d3d11_mpeg2_dec_class_init (GstD3D11Mpeg2DecClass * klass, gpointer data)
static void
gst_d3d11_mpeg2_dec_init (GstD3D11Mpeg2Dec * self)
{
self->slice_list = g_array_new (FALSE, TRUE, sizeof (DXVA_SliceInfo));
self->profile = GST_MPEG_VIDEO_PROFILE_MAIN;
}
static void
gst_d3d11_mpeg2_dec_finalize (GObject * object)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (object);
g_array_unref (self->slice_list);
G_OBJECT_CLASS (parent_class)->finalize (object);
self->inner = new GstD3D11Mpeg2DecInner ();
}
static void
@ -200,15 +197,26 @@ gst_d3d11_mpeg2_dec_get_property (GObject * object, guint prop_id,
gst_d3d11_decoder_proxy_get_property (object, prop_id, value, pspec, cdata);
}
static void
gst_d3d11_mpeg2_dec_finalize (GObject * object)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (object);
delete self->inner;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_d3d11_mpeg2_dec_set_context (GstElement * element, GstContext * context)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (element);
GstD3D11Mpeg2DecInner *inner = self->inner;
GstD3D11Mpeg2DecClass *klass = GST_D3D11_MPEG2_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
gst_d3d11_handle_set_context (element, context, cdata->adapter,
&self->device);
&inner->device);
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
@ -217,20 +225,22 @@ static gboolean
gst_d3d11_mpeg2_dec_open (GstVideoDecoder * decoder)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
GstD3D11Mpeg2DecClass *klass = GST_D3D11_MPEG2_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self), cdata->adapter,
&self->device)) {
&inner->device)) {
GST_ERROR_OBJECT (self, "Cannot create d3d11device");
return FALSE;
}
self->d3d11_decoder = gst_d3d11_decoder_new (self->device);
inner->d3d11_decoder = gst_d3d11_decoder_new (inner->device,
GST_DXVA_CODEC_MPEG2);
if (!self->d3d11_decoder) {
if (!inner->d3d11_decoder) {
GST_ERROR_OBJECT (self, "Cannot create d3d11 decoder");
gst_clear_object (&self->device);
gst_clear_object (&inner->device);
return FALSE;
}
@ -241,9 +251,10 @@ static gboolean
gst_d3d11_mpeg2_dec_close (GstVideoDecoder * decoder)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
gst_clear_object (&self->d3d11_decoder);
gst_clear_object (&self->device);
gst_clear_object (&inner->d3d11_decoder);
gst_clear_object (&inner->device);
return TRUE;
}
@ -252,8 +263,9 @@ static gboolean
gst_d3d11_mpeg2_dec_negotiate (GstVideoDecoder * decoder)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
if (!gst_d3d11_decoder_negotiate (self->d3d11_decoder, decoder))
if (!gst_d3d11_decoder_negotiate (inner->d3d11_decoder, decoder))
return FALSE;
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
@ -264,8 +276,9 @@ gst_d3d11_mpeg2_dec_decide_allocation (GstVideoDecoder * decoder,
GstQuery * query)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
if (!gst_d3d11_decoder_decide_allocation (self->d3d11_decoder,
if (!gst_d3d11_decoder_decide_allocation (inner->d3d11_decoder,
decoder, query)) {
return FALSE;
}
@ -278,11 +291,12 @@ static gboolean
gst_d3d11_mpeg2_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONTEXT:
if (gst_d3d11_handle_context_query (GST_ELEMENT (decoder),
query, self->device)) {
query, inner->device)) {
return TRUE;
}
break;
@ -297,15 +311,16 @@ static gboolean
gst_d3d11_mpeg2_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, TRUE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, TRUE);
break;
case GST_EVENT_FLUSH_STOP:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, FALSE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, FALSE);
default:
break;
}
@ -321,6 +336,7 @@ gst_d3d11_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
const GstMpegVideoSequenceScalableExt * seq_scalable_ext)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
gboolean interlaced;
gboolean modified = FALSE;
gint width, height;
@ -329,9 +345,9 @@ gst_d3d11_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
GST_LOG_OBJECT (self, "new sequence");
interlaced = seq_ext ? !seq_ext->progressive : FALSE;
if (self->interlaced != interlaced) {
if (inner->interlaced != interlaced) {
GST_INFO_OBJECT (self, "interlaced sequence change");
self->interlaced = interlaced;
inner->interlaced = interlaced;
modified = TRUE;
}
@ -342,13 +358,13 @@ gst_d3d11_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
height = (height & 0x0fff) | ((guint32) seq_ext->vert_size_ext << 12);
}
if (self->width != width || self->height != height) {
if (inner->width != width || inner->height != height) {
GST_INFO_OBJECT (self, "resolution change %dx%d -> %dx%d",
self->width, self->height, width, height);
self->width = width;
self->height = height;
self->width_in_mb = GST_ROUND_UP_16 (width) >> 4;
self->height_in_mb = GST_ROUND_UP_16 (height) >> 4;
inner->width, inner->height, width, height);
inner->width = width;
inner->height = height;
inner->width_in_mb = GST_ROUND_UP_16 (width) >> 4;
inner->height_in_mb = GST_ROUND_UP_16 (height) >> 4;
modified = TRUE;
}
@ -362,27 +378,27 @@ gst_d3d11_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
return FALSE;
}
if (self->profile != mpeg_profile) {
if (inner->profile != mpeg_profile) {
GST_INFO_OBJECT (self, "Profile change %d -> %d",
self->profile, mpeg_profile);
self->profile = mpeg_profile;
inner->profile, mpeg_profile);
inner->profile = mpeg_profile;
modified = TRUE;
}
if (modified || !gst_d3d11_decoder_is_configured (self->d3d11_decoder)) {
if (modified || !gst_d3d11_decoder_is_configured (inner->d3d11_decoder)) {
GstVideoInfo info;
/* FIXME: support I420 */
self->out_format = GST_VIDEO_FORMAT_NV12;
inner->out_format = GST_VIDEO_FORMAT_NV12;
gst_video_info_set_format (&info,
self->out_format, self->width, self->height);
if (self->interlaced)
inner->out_format, inner->width, inner->height);
if (inner->interlaced)
GST_VIDEO_INFO_INTERLACE_MODE (&info) = GST_VIDEO_INTERLACE_MODE_MIXED;
if (!gst_d3d11_decoder_configure (self->d3d11_decoder,
GST_D3D11_CODEC_MPEG2, decoder->input_state, &info,
self->width, self->height, NUM_OUTPUT_VIEW)) {
if (!gst_d3d11_decoder_configure (inner->d3d11_decoder,
decoder->input_state, &info,
inner->width, inner->height, NUM_OUTPUT_VIEW)) {
GST_ERROR_OBJECT (self, "Failed to create decoder");
return FALSE;
}
@ -401,9 +417,10 @@ gst_d3d11_mpeg2_dec_new_picture (GstMpeg2Decoder * decoder,
GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
GstBuffer *view_buffer;
view_buffer = gst_d3d11_decoder_get_output_view_buffer (self->d3d11_decoder,
view_buffer = gst_d3d11_decoder_get_output_view_buffer (inner->d3d11_decoder,
GST_VIDEO_DECODER (decoder));
if (!view_buffer) {
GST_DEBUG_OBJECT (self, "No available output view buffer");
@ -444,33 +461,11 @@ gst_d3d11_mpeg2_dec_new_field_picture (GstMpeg2Decoder * decoder,
return TRUE;
}
static gboolean
gst_d3d11_mpeg2_dec_get_bitstream_buffer (GstD3D11Mpeg2Dec * self)
{
GST_TRACE_OBJECT (self, "Getting bitstream buffer");
self->written_buffer_size = 0;
self->remaining_buffer_size = 0;
self->bitstream_buffer_data = NULL;
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &self->remaining_buffer_size,
(gpointer *) & self->bitstream_buffer_data)) {
GST_ERROR_OBJECT (self, "Faild to get bitstream buffer");
return FALSE;
}
GST_TRACE_OBJECT (self, "Got bitstream buffer %p with size %d",
self->bitstream_buffer_data, self->remaining_buffer_size);
self->written_buffer_size = 0;
return TRUE;
}
static ID3D11VideoDecoderOutputView *
gst_d3d11_mpeg2_dec_get_output_view_from_picture (GstD3D11Mpeg2Dec * self,
GstMpeg2Picture * picture, guint8 * view_id)
{
GstD3D11Mpeg2DecInner *inner = self->inner;
GstBuffer *view_buffer;
ID3D11VideoDecoderOutputView *view;
@ -484,7 +479,7 @@ gst_d3d11_mpeg2_dec_get_output_view_from_picture (GstD3D11Mpeg2Dec * self,
}
view =
gst_d3d11_decoder_get_output_view_from_buffer (self->d3d11_decoder,
gst_d3d11_decoder_get_output_view_from_buffer (inner->d3d11_decoder,
view_buffer, view_id);
if (!view) {
GST_DEBUG_OBJECT (self, "current picture does not have output view handle");
@ -525,14 +520,13 @@ gst_d3d11_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
GstMpeg2Picture * prev_picture, GstMpeg2Picture * next_picture)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
DXVA_PictureParameters *pic_params = &inner->pic_params;
DXVA_QmatrixData *iq_matrix = &inner->iq_matrix;
ID3D11VideoDecoderOutputView *view;
ID3D11VideoDecoderOutputView *other_view;
guint8 view_id = 0xff;
guint8 other_view_id = 0xff;
DXVA_PictureParameters pic_params = { 0, };
DXVA_QmatrixData iq_matrix = { 0, };
guint d3d11_buffer_size = 0;
gpointer d3d11_buffer = NULL;
gboolean is_field =
picture->structure != GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME;
@ -543,16 +537,13 @@ gst_d3d11_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
return FALSE;
}
GST_TRACE_OBJECT (self, "Begin frame");
if (!gst_d3d11_decoder_begin_frame (self->d3d11_decoder, view, 0, NULL)) {
GST_ERROR_OBJECT (self, "Failed to begin frame");
return FALSE;
}
memset (pic_params, 0, sizeof (DXVA_PictureParameters));
memset (iq_matrix, 0, sizeof (DXVA_QmatrixData));
/* Fill DXVA_PictureParameters */
pic_params.wDecodedPictureIndex = view_id;
pic_params.wForwardRefPictureIndex = 0xffff;
pic_params.wBackwardRefPictureIndex = 0xffff;
pic_params->wDecodedPictureIndex = view_id;
pic_params->wForwardRefPictureIndex = 0xffff;
pic_params->wBackwardRefPictureIndex = 0xffff;
switch (picture->type) {
case GST_MPEG_VIDEO_PICTURE_TYPE_B:{
@ -561,7 +552,7 @@ gst_d3d11_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
gst_d3d11_mpeg2_dec_get_output_view_from_picture (self,
next_picture, &other_view_id);
if (other_view)
pic_params.wBackwardRefPictureIndex = other_view_id;
pic_params->wBackwardRefPictureIndex = other_view_id;
}
}
/* fall-through */
@ -571,51 +562,33 @@ gst_d3d11_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
gst_d3d11_mpeg2_dec_get_output_view_from_picture (self,
prev_picture, &other_view_id);
if (other_view)
pic_params.wForwardRefPictureIndex = other_view_id;
pic_params->wForwardRefPictureIndex = other_view_id;
}
}
default:
break;
}
/* *INDENT-OFF* */
pic_params.wPicWidthInMBminus1 = self->width_in_mb - 1;
pic_params.wPicHeightInMBminus1 = (self->height_in_mb >> is_field) - 1;
pic_params.bMacroblockWidthMinus1 = 15;
pic_params.bMacroblockHeightMinus1 = 15;
pic_params.bBlockWidthMinus1 = 7;
pic_params.bBlockHeightMinus1 = 7;
pic_params.bBPPminus1 = 7;
pic_params.bPicStructure = (BYTE) picture->structure;
pic_params.bSecondField = is_field && ! !picture->first_field;
pic_params.bPicIntra = picture->type == GST_MPEG_VIDEO_PICTURE_TYPE_I;
pic_params.bPicBackwardPrediction =
pic_params->wPicWidthInMBminus1 = inner->width_in_mb - 1;
pic_params->wPicHeightInMBminus1 = (inner->height_in_mb >> is_field) - 1;
pic_params->bMacroblockWidthMinus1 = 15;
pic_params->bMacroblockHeightMinus1 = 15;
pic_params->bBlockWidthMinus1 = 7;
pic_params->bBlockHeightMinus1 = 7;
pic_params->bBPPminus1 = 7;
pic_params->bPicStructure = (BYTE) picture->structure;
if (picture->first_field && is_field) {
pic_params->bSecondField = TRUE;
}
pic_params->bPicIntra = picture->type == GST_MPEG_VIDEO_PICTURE_TYPE_I;
pic_params->bPicBackwardPrediction =
picture->type == GST_MPEG_VIDEO_PICTURE_TYPE_B;
/* FIXME: 1 -> 4:2:0, 2 -> 4:2:2, 3 -> 4:4:4 */
pic_params.bChromaFormat = 1;
pic_params.bPicScanFixed = 1;
pic_params.bPicScanMethod = slice->pic_ext->alternate_scan;
pic_params.wBitstreamFcodes = _pack_f_codes (slice->pic_ext->f_code);
pic_params.wBitstreamPCEelements = _pack_pce_elements (slice);
/* *INDENT-ON* */
GST_TRACE_OBJECT (self, "Getting picture param decoder buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self,
"Failed to get decoder buffer for picture parameters");
return FALSE;
}
memcpy (d3d11_buffer, &pic_params, sizeof (pic_params));
GST_TRACE_OBJECT (self, "Release picture param decoder buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS)) {
GST_ERROR_OBJECT (self, "Failed to release decoder buffer");
return FALSE;
}
pic_params->bChromaFormat = 1;
pic_params->bPicScanFixed = 1;
pic_params->bPicScanMethod = slice->pic_ext->alternate_scan;
pic_params->wBitstreamFcodes = _pack_f_codes (slice->pic_ext->f_code);
pic_params->wBitstreamPCEelements = _pack_pce_elements (slice);
/* Fill DXVA_QmatrixData */
if (slice->quant_matrix &&
@ -625,157 +598,46 @@ gst_d3d11_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
(slice->quant_matrix->load_intra_quantiser_matrix ||
slice->quant_matrix->load_non_intra_quantiser_matrix)) {
GstMpegVideoQuantMatrixExt *quant_matrix = slice->quant_matrix;
self->submit_iq_data = TRUE;
if (quant_matrix->load_intra_quantiser_matrix) {
iq_matrix.bNewQmatrix[0] = 1;
memcpy (iq_matrix.Qmatrix[0], quant_matrix->intra_quantiser_matrix,
sizeof (quant_matrix->intra_quantiser_matrix));
iq_matrix->bNewQmatrix[0] = 1;
for (guint i = 0; i < 64; i++) {
iq_matrix->Qmatrix[0][i] = quant_matrix->intra_quantiser_matrix[i];
}
}
if (quant_matrix->load_non_intra_quantiser_matrix) {
iq_matrix.bNewQmatrix[1] = 1;
memcpy (iq_matrix.Qmatrix[1], quant_matrix->non_intra_quantiser_matrix,
sizeof (quant_matrix->non_intra_quantiser_matrix));
iq_matrix->bNewQmatrix[1] = 1;
for (guint i = 0; i < 64; i++) {
iq_matrix->Qmatrix[1][i] = quant_matrix->non_intra_quantiser_matrix[i];
}
}
if (quant_matrix->load_chroma_intra_quantiser_matrix) {
iq_matrix.bNewQmatrix[2] = 1;
memcpy (iq_matrix.Qmatrix[2], quant_matrix->chroma_intra_quantiser_matrix,
sizeof (quant_matrix->chroma_intra_quantiser_matrix));
iq_matrix->bNewQmatrix[2] = 1;
for (guint i = 0; i < 64; i++) {
iq_matrix->Qmatrix[2][i] =
quant_matrix->chroma_intra_quantiser_matrix[i];
}
}
if (quant_matrix->load_chroma_non_intra_quantiser_matrix) {
iq_matrix.bNewQmatrix[3] = 1;
memcpy (iq_matrix.Qmatrix[3],
quant_matrix->chroma_non_intra_quantiser_matrix,
sizeof (quant_matrix->chroma_non_intra_quantiser_matrix));
iq_matrix->bNewQmatrix[3] = 1;
for (guint i = 0; i < 64; i++) {
iq_matrix->Qmatrix[3][i] =
quant_matrix->chroma_non_intra_quantiser_matrix[i];
}
}
GST_TRACE_OBJECT (self, "Getting inverse quantization matrix buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX,
&d3d11_buffer_size, &d3d11_buffer)) {
GST_ERROR_OBJECT (self,
"Failed to get decoder buffer for inv. quantization matrix");
return FALSE;
}
memcpy (d3d11_buffer, &iq_matrix, sizeof (DXVA_QmatrixData));
GST_TRACE_OBJECT (self, "Release inverse quantization matrix buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX)) {
GST_ERROR_OBJECT (self, "Failed to release decoder buffer");
return FALSE;
}
inner->submit_iq_data = TRUE;
} else {
self->submit_iq_data = FALSE;
inner->submit_iq_data = FALSE;
}
g_array_set_size (self->slice_list, 0);
inner->slice_list.resize (0);
inner->bitstream_buffer.resize (0);
return gst_d3d11_mpeg2_dec_get_bitstream_buffer (self);
}
static gboolean
gst_d3d11_mpeg2_dec_submit_slice_data (GstD3D11Mpeg2Dec * self,
GstMpeg2Picture * picture)
{
guint buffer_size;
gpointer buffer;
guint8 *data;
gsize offset = 0;
guint i;
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[4];
gboolean ret;
guint buffer_count = 0;
DXVA_SliceInfo *slice_data;
gboolean is_field =
picture->structure != GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME;
guint mb_count = self->width_in_mb * (self->height_in_mb >> is_field);
if (self->slice_list->len < 1) {
GST_WARNING_OBJECT (self, "Nothing to submit");
return FALSE;
}
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting slice control buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL, &buffer_size, &buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get slice control buffer");
return FALSE;
}
data = (guint8 *) buffer;
for (i = 0; i < self->slice_list->len; i++) {
slice_data = &g_array_index (self->slice_list, DXVA_SliceInfo, i);
/* Update the number of MBs per slice */
if (i == self->slice_list->len - 1) {
slice_data->wNumberMBsInSlice = mb_count - slice_data->wNumberMBsInSlice;
} else {
DXVA_SliceInfo *next =
&g_array_index (self->slice_list, DXVA_SliceInfo, i + 1);
slice_data->wNumberMBsInSlice =
next->wNumberMBsInSlice - slice_data->wNumberMBsInSlice;
}
memcpy (data + offset, slice_data, sizeof (DXVA_SliceInfo));
offset += sizeof (DXVA_SliceInfo);
}
GST_TRACE_OBJECT (self, "Release slice control buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL)) {
GST_ERROR_OBJECT (self, "Failed to release slice control buffer");
return FALSE;
}
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM)) {
GST_ERROR_OBJECT (self, "Failed to release bitstream buffer");
return FALSE;
}
buffer_desc[buffer_count].BufferType =
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
buffer_desc[buffer_count].DataOffset = 0;
buffer_desc[buffer_count].DataSize = sizeof (DXVA_PictureParameters);
buffer_count++;
if (self->submit_iq_data) {
buffer_desc[buffer_count].BufferType =
D3D11_VIDEO_DECODER_BUFFER_INVERSE_QUANTIZATION_MATRIX;
buffer_desc[buffer_count].DataOffset = 0;
buffer_desc[buffer_count].DataSize = sizeof (DXVA_QmatrixData);
buffer_count++;
}
buffer_desc[buffer_count].BufferType =
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
buffer_desc[buffer_count].DataOffset = 0;
buffer_desc[buffer_count].DataSize =
sizeof (DXVA_SliceInfo) * self->slice_list->len;
buffer_count++;
buffer_desc[buffer_count].BufferType = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
buffer_desc[buffer_count].DataOffset = 0;
buffer_desc[buffer_count].DataSize = self->written_buffer_size;
buffer_count++;
ret = gst_d3d11_decoder_submit_decoder_buffers (self->d3d11_decoder,
buffer_count, buffer_desc);
self->written_buffer_size = 0;
self->bitstream_buffer_data = NULL;
self->remaining_buffer_size = 0;
g_array_set_size (self->slice_list, 0);
return ret;
return TRUE;
}
static gboolean
@ -783,58 +645,98 @@ gst_d3d11_mpeg2_dec_decode_slice (GstMpeg2Decoder * decoder,
GstMpeg2Picture * picture, GstMpeg2Slice * slice)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
GstMpegVideoSliceHdr *header = &slice->header;
GstMpegVideoPacket *packet = &slice->packet;
/* including start code 4 bytes */
guint to_write = packet->size + 4;
DXVA_SliceInfo slice_info = { 0, };
g_assert (packet->offset >= 4);
/* FIXME: DXVA wants to know the number of MBs per slice
* (not sure whether it's actually used by driver). But in case that
* one slice is splitted into two bitstream buffer, it's almost impossible
* to know the number of MBs per splitted bitstream buffer.
* So, we will not support too large bitstream buffer which requires multiple
* hardware bitstream buffer at this moment.
*/
if (self->remaining_buffer_size < to_write) {
/* Submit slice data we have so that release acquired bitstream buffers */
if (self->bitstream_buffer_data)
gst_d3d11_mpeg2_dec_submit_slice_data (self, picture);
self->bitstream_buffer_data = 0;
GST_ERROR_OBJECT (self, "Slice data is too large");
return FALSE;
}
slice_info.wHorizontalPosition = header->mb_column;
slice_info.wVerticalPosition = header->mb_row;
slice_info.dwSliceBitsInBuffer = 8 * to_write;
slice_info.dwSliceDataLocation = self->written_buffer_size;
/* including start code 4 bytes */
slice_info.dwSliceBitsInBuffer = 8 * (packet->size + 4);
slice_info.dwSliceDataLocation = inner->bitstream_buffer.size ();
/* XXX: We don't have information about the number of MBs in this slice.
* Just store offset here, and actual number will be calculated later */
slice_info.wNumberMBsInSlice =
(header->mb_row * self->width_in_mb) + header->mb_column;
(header->mb_row * inner->width_in_mb) + header->mb_column;
slice_info.wQuantizerScaleCode = header->quantiser_scale_code;
slice_info.wMBbitOffset = header->header_size + 32;
memcpy (self->bitstream_buffer_data, packet->data + packet->offset - 4,
to_write);
g_array_append_val (self->slice_list, slice_info);
self->remaining_buffer_size -= to_write;
self->written_buffer_size += to_write;
self->bitstream_buffer_data += to_write;
inner->slice_list.push_back (slice_info);
size_t pos = inner->bitstream_buffer.size ();
inner->bitstream_buffer.resize (pos + packet->size + 4);
memcpy (&inner->bitstream_buffer[0] + pos, packet->data + packet->offset - 4,
packet->size + 4);
return TRUE;
}
static gboolean
gst_d3d11_mpeg2_dec_end_picture (GstMpeg2Decoder * decoder,
GstMpeg2Picture * picture)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
GstD3D11DecodeInputStreamArgs input_args;
gboolean is_field =
picture->structure != GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME;
guint mb_count = inner->width_in_mb * (inner->height_in_mb >> is_field);
if (inner->bitstream_buffer.empty ()) {
GST_ERROR_OBJECT (self, "No bitstream buffer to submit");
return FALSE;
}
view = gst_d3d11_mpeg2_dec_get_output_view_from_picture (self, picture,
&view_id);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
memset (&input_args, 0, sizeof (GstD3D11DecodeInputStreamArgs));
DXVA_SliceInfo *first = &inner->slice_list[0];
for (size_t i = 0; i < inner->slice_list.size (); i++) {
DXVA_SliceInfo *slice = first + i;
/* Update the number of MBs per slice */
if (i == inner->slice_list.size () - 1) {
slice->wNumberMBsInSlice = mb_count - slice->wNumberMBsInSlice;
} else {
DXVA_SliceInfo *next = first + i + 1;
slice->wNumberMBsInSlice =
next->wNumberMBsInSlice - slice->wNumberMBsInSlice;
}
}
input_args.picture_params = &inner->pic_params;
input_args.picture_params_size = sizeof (DXVA_PictureParameters);
input_args.slice_control = &inner->slice_list[0];
input_args.slice_control_size =
sizeof (DXVA_SliceInfo) * inner->slice_list.size ();
input_args.bitstream = &inner->bitstream_buffer[0];
input_args.bitstream_size = inner->bitstream_buffer.size ();
if (inner->submit_iq_data) {
input_args.inverse_quantization_matrix = &inner->iq_matrix;
input_args.inverse_quantization_matrix_size = sizeof (DXVA_QmatrixData);
}
return gst_d3d11_decoder_decode_frame (inner->d3d11_decoder,
view, &input_args);
}
static GstFlowReturn
gst_d3d11_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
GstD3D11Mpeg2DecInner *inner = self->inner;
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
@ -847,8 +749,8 @@ gst_d3d11_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
goto error;
}
if (!gst_d3d11_decoder_process_output (self->d3d11_decoder, vdec,
self->width, self->height, view_buffer, &frame->output_buffer)) {
if (!gst_d3d11_decoder_process_output (inner->d3d11_decoder, vdec,
inner->width, inner->height, view_buffer, &frame->output_buffer)) {
GST_ERROR_OBJECT (self, "Failed to copy buffer");
goto error;
}
@ -869,40 +771,15 @@ gst_d3d11_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
return gst_video_decoder_finish_frame (vdec, frame);
error:
gst_video_decoder_drop_frame (vdec, frame);
gst_mpeg2_picture_unref (picture);
gst_video_decoder_release_frame (vdec, frame);
return GST_FLOW_ERROR;
}
static gboolean
gst_d3d11_mpeg2_dec_end_picture (GstMpeg2Decoder * decoder,
GstMpeg2Picture * picture)
{
GstD3D11Mpeg2Dec *self = GST_D3D11_MPEG2_DEC (decoder);
if (!gst_d3d11_mpeg2_dec_submit_slice_data (self, picture)) {
GST_ERROR_OBJECT (self, "Failed to submit slice data");
return FALSE;
}
if (!gst_d3d11_decoder_end_frame (self->d3d11_decoder)) {
GST_ERROR_OBJECT (self, "Failed to EndFrame");
return FALSE;
}
return TRUE;
}
typedef struct
{
guint width;
guint height;
} GstD3D11Mpeg2DecResolution;
void
gst_d3d11_mpeg2_dec_register (GstPlugin * plugin, GstD3D11Device * device,
GstD3D11Decoder * decoder, guint rank)
guint rank)
{
GType type;
gchar *type_name;
@ -923,8 +800,8 @@ gst_d3d11_mpeg2_dec_register (GstPlugin * plugin, GstD3D11Device * device,
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
if (!gst_d3d11_decoder_get_supported_decoder_profile (decoder,
GST_D3D11_CODEC_MPEG2, GST_VIDEO_FORMAT_NV12, &supported_profile)) {
if (!gst_d3d11_decoder_get_supported_decoder_profile (device,
GST_DXVA_CODEC_MPEG2, GST_VIDEO_FORMAT_NV12, &supported_profile)) {
GST_INFO_OBJECT (device, "device does not support MPEG-2 video decoding");
return;
}
@ -946,7 +823,7 @@ gst_d3d11_mpeg2_dec_register (GstPlugin * plugin, GstD3D11Device * device,
"height", GST_TYPE_INT_RANGE, 1, 1920, NULL);
type_info.class_data =
gst_d3d11_decoder_class_data_new (device, GST_D3D11_CODEC_MPEG2,
gst_d3d11_decoder_class_data_new (device, GST_DXVA_CODEC_MPEG2,
sink_caps, src_caps);
type_name = g_strdup ("GstD3D11Mpeg2Dec");

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_mpeg2_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank);
G_END_DECLS

View file

@ -40,6 +40,7 @@
#include <gst/codecs/gstvp8decoder.h>
#include <string.h>
#include <vector>
/* HACK: to expose dxva data structure on UWP */
#ifdef WINAPI_PARTITION_DESKTOP
@ -55,15 +56,29 @@ GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp8_dec_debug);
/* reference list 4 + 4 margin */
#define NUM_OUTPUT_VIEW 8
/* *INDENT-OFF* */
typedef struct _GstD3D11Vp8DecInner
{
GstD3D11Device *device = nullptr;
GstD3D11Decoder *d3d11_decoder = nullptr;
DXVA_PicParams_VP8 pic_params;
DXVA_Slice_VPx_Short slice;
/* In case of VP8, 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;
guint width = 0;
guint height = 0;
GstVideoFormat out_format = GST_VIDEO_FORMAT_UNKNOWN;
} GstD3D11Vp8DecInner;
/* *INDENT-ON* */
typedef struct _GstD3D11Vp8Dec
{
GstVp8Decoder parent;
GstD3D11Device *device;
GstD3D11Decoder *d3d11_decoder;
guint width, height;
GstVideoFormat out_format;
GstD3D11Vp8DecInner *inner;
} GstD3D11Vp8Dec;
typedef struct _GstD3D11Vp8DecClass
@ -80,6 +95,7 @@ static GstElementClass *parent_class = NULL;
static void gst_d3d11_vp8_dec_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_d3d11_vp8_dec_finalize (GObject * object);
static void gst_d3d11_vp8_dec_set_context (GstElement * element,
GstContext * context);
@ -98,14 +114,14 @@ static gboolean gst_d3d11_vp8_dec_new_sequence (GstVp8Decoder * decoder,
const GstVp8FrameHdr * frame_hdr);
static gboolean gst_d3d11_vp8_dec_new_picture (GstVp8Decoder * decoder,
GstVideoCodecFrame * frame, GstVp8Picture * picture);
static GstFlowReturn gst_d3d11_vp8_dec_output_picture (GstVp8Decoder *
decoder, GstVideoCodecFrame * frame, GstVp8Picture * picture);
static gboolean gst_d3d11_vp8_dec_start_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture);
static gboolean gst_d3d11_vp8_dec_decode_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture, GstVp8Parser * parser);
static gboolean gst_d3d11_vp8_dec_end_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture);
static GstFlowReturn gst_d3d11_vp8_dec_output_picture (GstVp8Decoder *
decoder, GstVideoCodecFrame * frame, GstVp8Picture * picture);
static void
gst_d3d11_vp8_dec_class_init (GstD3D11Vp8DecClass * klass, gpointer data)
@ -117,6 +133,7 @@ gst_d3d11_vp8_dec_class_init (GstD3D11Vp8DecClass * klass, gpointer data)
GstD3D11DecoderClassData *cdata = (GstD3D11DecoderClassData *) data;
gobject_class->get_property = gst_d3d11_vp8_dec_get_property;
gobject_class->finalize = gst_d3d11_vp8_dec_finalize;
element_class->set_context =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_set_context);
@ -138,19 +155,20 @@ gst_d3d11_vp8_dec_class_init (GstD3D11Vp8DecClass * klass, gpointer data)
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_new_sequence);
vp8decoder_class->new_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_new_picture);
vp8decoder_class->output_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_output_picture);
vp8decoder_class->start_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_start_picture);
vp8decoder_class->decode_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_decode_picture);
vp8decoder_class->end_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_end_picture);
vp8decoder_class->output_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp8_dec_output_picture);
}
static void
gst_d3d11_vp8_dec_init (GstD3D11Vp8Dec * self)
{
self->inner = new GstD3D11Vp8DecInner ();
}
static void
@ -163,15 +181,26 @@ gst_d3d11_vp8_dec_get_property (GObject * object, guint prop_id,
gst_d3d11_decoder_proxy_get_property (object, prop_id, value, pspec, cdata);
}
static void
gst_d3d11_vp8_dec_finalize (GObject * object)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (object);
delete self->inner;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_d3d11_vp8_dec_set_context (GstElement * element, GstContext * context)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (element);
GstD3D11Vp8DecInner *inner = self->inner;
GstD3D11Vp8DecClass *klass = GST_D3D11_VP8_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
gst_d3d11_handle_set_context (element, context, cdata->adapter,
&self->device);
&inner->device);
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
@ -180,20 +209,22 @@ static gboolean
gst_d3d11_vp8_dec_open (GstVideoDecoder * decoder)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
GstD3D11Vp8DecClass *klass = GST_D3D11_VP8_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self), cdata->adapter,
&self->device)) {
&inner->device)) {
GST_ERROR_OBJECT (self, "Cannot create d3d11device");
return FALSE;
}
self->d3d11_decoder = gst_d3d11_decoder_new (self->device);
inner->d3d11_decoder = gst_d3d11_decoder_new (inner->device,
GST_DXVA_CODEC_VP8);
if (!self->d3d11_decoder) {
if (!inner->d3d11_decoder) {
GST_ERROR_OBJECT (self, "Cannot create d3d11 decoder");
gst_clear_object (&self->device);
gst_clear_object (&inner->device);
return FALSE;
}
@ -204,9 +235,10 @@ static gboolean
gst_d3d11_vp8_dec_close (GstVideoDecoder * decoder)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
gst_clear_object (&self->d3d11_decoder);
gst_clear_object (&self->device);
gst_clear_object (&inner->d3d11_decoder);
gst_clear_object (&inner->device);
return TRUE;
}
@ -215,8 +247,9 @@ static gboolean
gst_d3d11_vp8_dec_negotiate (GstVideoDecoder * decoder)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
if (!gst_d3d11_decoder_negotiate (self->d3d11_decoder, decoder))
if (!gst_d3d11_decoder_negotiate (inner->d3d11_decoder, decoder))
return FALSE;
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
@ -227,8 +260,9 @@ gst_d3d11_vp8_dec_decide_allocation (GstVideoDecoder * decoder,
GstQuery * query)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
if (!gst_d3d11_decoder_decide_allocation (self->d3d11_decoder, decoder,
if (!gst_d3d11_decoder_decide_allocation (inner->d3d11_decoder, decoder,
query)) {
return FALSE;
}
@ -241,11 +275,12 @@ static gboolean
gst_d3d11_vp8_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONTEXT:
if (gst_d3d11_handle_context_query (GST_ELEMENT (decoder),
query, self->device)) {
query, inner->device)) {
return TRUE;
}
break;
@ -260,15 +295,16 @@ static gboolean
gst_d3d11_vp8_sink_event (GstVideoDecoder * decoder, GstEvent * event)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, TRUE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, TRUE);
break;
case GST_EVENT_FLUSH_STOP:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, FALSE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, FALSE);
default:
break;
}
@ -281,20 +317,21 @@ gst_d3d11_vp8_dec_new_sequence (GstVp8Decoder * decoder,
const GstVp8FrameHdr * frame_hdr)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
GstVideoInfo info;
GST_LOG_OBJECT (self, "new sequence");
/* FIXME: support I420 */
self->out_format = GST_VIDEO_FORMAT_NV12;
self->width = frame_hdr->width;
self->height = frame_hdr->height;
inner->out_format = GST_VIDEO_FORMAT_NV12;
inner->width = frame_hdr->width;
inner->height = frame_hdr->height;
gst_video_info_set_format (&info,
self->out_format, self->width, self->height);
inner->out_format, inner->width, inner->height);
if (!gst_d3d11_decoder_configure (self->d3d11_decoder, GST_D3D11_CODEC_VP8,
decoder->input_state, &info, self->width, self->height,
if (!gst_d3d11_decoder_configure (inner->d3d11_decoder,
decoder->input_state, &info, inner->width, inner->height,
NUM_OUTPUT_VIEW)) {
GST_ERROR_OBJECT (self, "Failed to create decoder");
return FALSE;
@ -313,9 +350,10 @@ gst_d3d11_vp8_dec_new_picture (GstVp8Decoder * decoder,
GstVideoCodecFrame * frame, GstVp8Picture * picture)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
GstBuffer *view_buffer;
view_buffer = gst_d3d11_decoder_get_output_view_buffer (self->d3d11_decoder,
view_buffer = gst_d3d11_decoder_get_output_view_buffer (inner->d3d11_decoder,
GST_VIDEO_DECODER (decoder));
if (!view_buffer) {
GST_DEBUG_OBJECT (self, "No available output view buffer");
@ -332,46 +370,23 @@ gst_d3d11_vp8_dec_new_picture (GstVp8Decoder * decoder,
return TRUE;
}
static GstFlowReturn
gst_d3d11_vp8_dec_output_picture (GstVp8Decoder * decoder,
GstVideoCodecFrame * frame, GstVp8Picture * picture)
static gboolean
gst_d3d11_vp8_dec_start_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
GstD3D11Vp8DecInner *inner = self->inner;
g_assert (picture->frame_hdr.show_frame);
inner->bitstream_buffer.resize (0);
GST_LOG_OBJECT (self, "Outputting picture %p", picture);
view_buffer = (GstBuffer *) gst_vp8_picture_get_user_data (picture);
if (!view_buffer) {
GST_ERROR_OBJECT (self, "Could not get output view");
goto error;
}
if (!gst_d3d11_decoder_process_output (self->d3d11_decoder, vdec,
self->width, self->height, view_buffer, &frame->output_buffer)) {
GST_ERROR_OBJECT (self, "Failed to copy buffer");
goto error;
}
gst_vp8_picture_unref (picture);
return gst_video_decoder_finish_frame (vdec, frame);
error:
gst_video_decoder_drop_frame (vdec, frame);
gst_vp8_picture_unref (picture);
return GST_FLOW_ERROR;
return TRUE;
}
static ID3D11VideoDecoderOutputView *
gst_d3d11_vp8_dec_get_output_view_from_picture (GstD3D11Vp8Dec * self,
GstVp8Picture * picture, guint8 * view_id)
{
GstD3D11Vp8DecInner *inner = self->inner;
GstBuffer *view_buffer;
ID3D11VideoDecoderOutputView *view;
@ -382,7 +397,7 @@ gst_d3d11_vp8_dec_get_output_view_from_picture (GstD3D11Vp8Dec * self,
}
view =
gst_d3d11_decoder_get_output_view_from_buffer (self->d3d11_decoder,
gst_d3d11_decoder_get_output_view_from_buffer (inner->d3d11_decoder,
view_buffer, view_id);
if (!view) {
GST_DEBUG_OBJECT (self, "current picture does not have output view handle");
@ -392,29 +407,6 @@ gst_d3d11_vp8_dec_get_output_view_from_picture (GstD3D11Vp8Dec * self,
return view;
}
static gboolean
gst_d3d11_vp8_dec_start_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
ID3D11VideoDecoderOutputView *view;
view = gst_d3d11_vp8_dec_get_output_view_from_picture (self, picture, NULL);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
GST_TRACE_OBJECT (self, "Begin frame");
if (!gst_d3d11_decoder_begin_frame (self->d3d11_decoder, view, 0, NULL)) {
GST_ERROR_OBJECT (self, "Failed to begin frame");
return FALSE;
}
return TRUE;
}
static void
gst_d3d11_vp8_dec_copy_frame_params (GstD3D11Vp8Dec * self,
GstVp8Picture * picture, GstVp8Parser * parser, DXVA_PicParams_VP8 * params)
@ -545,188 +537,14 @@ gst_d3d11_vp8_dec_copy_segmentation_params (GstD3D11Vp8Dec * self,
}
}
static gboolean
gst_d3d11_vp8_dec_submit_picture_data (GstD3D11Vp8Dec * self,
GstVp8Picture * picture, DXVA_PicParams_VP8 * params)
{
guint d3d11_buffer_size;
gpointer d3d11_buffer;
gsize buffer_offset = 0;
gboolean is_first = TRUE;
GST_TRACE_OBJECT (self, "Getting picture params buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self,
"Failed to get decoder buffer for picture parameters");
return FALSE;
}
memcpy (d3d11_buffer, params, sizeof (DXVA_PicParams_VP8));
GST_TRACE_OBJECT (self, "Release picture param decoder buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS)) {
GST_ERROR_OBJECT (self, "Failed to release decoder buffer");
return FALSE;
}
if (!picture->data || !picture->size) {
GST_ERROR_OBJECT (self, "No data to submit");
return FALSE;
}
GST_TRACE_OBJECT (self, "Submit total %" G_GSIZE_FORMAT " bytes",
picture->size);
while (buffer_offset < picture->size) {
gsize bytes_to_copy = picture->size - buffer_offset;
gsize written_buffer_size;
gboolean is_last = TRUE;
DXVA_Slice_VPx_Short slice_short = { 0, };
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3];
gboolean bad_aligned_bitstream_buffer = FALSE;
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting bitstream buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get bitstream buffer");
goto error;
}
if ((d3d11_buffer_size & 127) != 0) {
GST_WARNING_OBJECT (self,
"The size of bitstream buffer is not 128 bytes aligned");
bad_aligned_bitstream_buffer = TRUE;
}
if (bytes_to_copy > d3d11_buffer_size) {
/* if the size of this slice is larger than the size of remaining d3d11
* decoder bitstream memory, write the data up to the remaining d3d11
* decoder bitstream memory size and the rest would be written to the
* next d3d11 bitstream memory */
bytes_to_copy = d3d11_buffer_size;
is_last = FALSE;
}
memcpy (d3d11_buffer, picture->data + buffer_offset, bytes_to_copy);
written_buffer_size = bytes_to_copy;
/* DXVA2 spec is saying that written bitstream data must be 128 bytes
* aligned if the bitstream buffer contains end of frame
* (i.e., wBadSliceChopping == 0 or 2) */
if (is_last) {
guint padding = MIN (GST_ROUND_UP_128 (bytes_to_copy) - bytes_to_copy,
d3d11_buffer_size - bytes_to_copy);
if (padding) {
GST_TRACE_OBJECT (self,
"Written bitstream buffer size %" G_GSIZE_FORMAT
" is not 128 bytes aligned, add padding %d bytes",
bytes_to_copy, padding);
memset ((guint8 *) d3d11_buffer + bytes_to_copy, 0, padding);
written_buffer_size += padding;
}
}
GST_TRACE_OBJECT (self, "Release bitstream buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM)) {
GST_ERROR_OBJECT (self, "Failed to release bitstream buffer");
goto error;
}
slice_short.BSNALunitDataLocation = 0;
slice_short.SliceBytesInBuffer = (UINT) written_buffer_size;
/* wBadSliceChopping: (dxva spec.)
* 0: All bits for the slice are located within the corresponding
* bitstream data buffer
* 1: The bitstream data buffer contains the start of the slice,
* but not the entire slice, because the buffer is full
* 2: The bitstream data buffer contains the end of the slice.
* It does not contain the start of the slice, because the start of
* the slice was located in the previous bitstream data buffer.
* 3: The bitstream data buffer does not contain the start of the slice
* (because the start of the slice was located in the previous
* bitstream data buffer), and it does not contain the end of the slice
* (because the current bitstream data buffer is also full).
*/
if (is_last && is_first) {
slice_short.wBadSliceChopping = 0;
} else if (!is_last && is_first) {
slice_short.wBadSliceChopping = 1;
} else if (is_last && !is_first) {
slice_short.wBadSliceChopping = 2;
} else {
slice_short.wBadSliceChopping = 3;
}
GST_TRACE_OBJECT (self, "Getting slice control buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get slice control buffer");
goto error;
}
memcpy (d3d11_buffer, &slice_short, sizeof (DXVA_Slice_VPx_Short));
GST_TRACE_OBJECT (self, "Release slice control buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL)) {
GST_ERROR_OBJECT (self, "Failed to release slice control buffer");
goto error;
}
buffer_desc[0].BufferType = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
buffer_desc[0].DataOffset = 0;
buffer_desc[0].DataSize = sizeof (DXVA_PicParams_VP8);
buffer_desc[1].BufferType = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
buffer_desc[1].DataOffset = 0;
buffer_desc[1].DataSize = sizeof (DXVA_Slice_VPx_Short);
if (!bad_aligned_bitstream_buffer && (written_buffer_size & 127) != 0) {
GST_WARNING_OBJECT (self,
"Written bitstream buffer size %" G_GSIZE_FORMAT
" is not 128 bytes aligned", written_buffer_size);
}
buffer_desc[2].BufferType = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
buffer_desc[2].DataOffset = 0;
buffer_desc[2].DataSize = written_buffer_size;
if (!gst_d3d11_decoder_submit_decoder_buffers (self->d3d11_decoder,
3, buffer_desc)) {
GST_ERROR_OBJECT (self, "Couldn't submit decoder buffers");
goto error;
}
buffer_offset += bytes_to_copy;
is_first = FALSE;
}
return TRUE;
error:
return FALSE;
}
static gboolean
gst_d3d11_vp8_dec_decode_picture (GstVp8Decoder * decoder,
GstVp8Picture * picture, GstVp8Parser * parser)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
DXVA_PicParams_VP8 pic_params = { 0, };
GstD3D11Vp8DecInner *inner = self->inner;
DXVA_PicParams_VP8 *pic_params = &inner->pic_params;
DXVA_Slice_VPx_Short *slice = &inner->slice;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
const GstVp8FrameHdr *frame_hdr = &picture->frame_hdr;
@ -738,41 +556,118 @@ gst_d3d11_vp8_dec_decode_picture (GstVp8Decoder * decoder,
return FALSE;
}
pic_params.first_part_size = frame_hdr->first_part_size;
pic_params.width = self->width;
pic_params.height = self->height;
pic_params.CurrPic.Index7Bits = view_id;
pic_params.StatusReportFeedbackNumber = 1;
memset (pic_params, 0, sizeof (DXVA_PicParams_VP8));
gst_d3d11_vp8_dec_copy_frame_params (self, picture, parser, &pic_params);
gst_d3d11_vp8_dec_copy_reference_frames (self, &pic_params);
gst_d3d11_vp8_dec_copy_segmentation_params (self, parser, &pic_params);
pic_params->first_part_size = frame_hdr->first_part_size;
pic_params->width = inner->width;
pic_params->height = inner->height;
pic_params->CurrPic.Index7Bits = view_id;
pic_params->StatusReportFeedbackNumber = 1;
return gst_d3d11_vp8_dec_submit_picture_data (self, picture, &pic_params);
gst_d3d11_vp8_dec_copy_frame_params (self, picture, parser, pic_params);
gst_d3d11_vp8_dec_copy_reference_frames (self, pic_params);
gst_d3d11_vp8_dec_copy_segmentation_params (self, parser, pic_params);
inner->bitstream_buffer.resize (picture->size);
memcpy (&inner->bitstream_buffer[0], picture->data, picture->size);
slice->BSNALunitDataLocation = 0;
slice->SliceBytesInBuffer = inner->bitstream_buffer.size ();
slice->wBadSliceChopping = 0;
return TRUE;
}
static gboolean
gst_d3d11_vp8_dec_end_picture (GstVp8Decoder * decoder, GstVp8Picture * picture)
{
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
size_t bitstream_buffer_size;
size_t bitstream_pos;
GstD3D11DecodeInputStreamArgs input_args;
if (!gst_d3d11_decoder_end_frame (self->d3d11_decoder)) {
GST_ERROR_OBJECT (self, "Failed to EndFrame");
if (inner->bitstream_buffer.empty ()) {
GST_ERROR_OBJECT (self, "No bitstream buffer to submit");
return FALSE;
}
return TRUE;
view = gst_d3d11_vp8_dec_get_output_view_from_picture (self,
picture, &view_id);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
memset (&input_args, 0, sizeof (GstD3D11DecodeInputStreamArgs));
bitstream_pos = inner->bitstream_buffer.size ();
bitstream_buffer_size = GST_ROUND_UP_128 (bitstream_pos);
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_VP8);
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 ();
return gst_d3d11_decoder_decode_frame (inner->d3d11_decoder,
view, &input_args);
}
typedef struct
static GstFlowReturn
gst_d3d11_vp8_dec_output_picture (GstVp8Decoder * decoder,
GstVideoCodecFrame * frame, GstVp8Picture * picture)
{
guint width;
guint height;
} GstD3D11Vp8DecResolution;
GstD3D11Vp8Dec *self = GST_D3D11_VP8_DEC (decoder);
GstD3D11Vp8DecInner *inner = self->inner;
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
g_assert (picture->frame_hdr.show_frame);
GST_LOG_OBJECT (self, "Outputting picture %p", picture);
view_buffer = (GstBuffer *) gst_vp8_picture_get_user_data (picture);
if (!view_buffer) {
GST_ERROR_OBJECT (self, "Could not get output view");
goto error;
}
if (!gst_d3d11_decoder_process_output (inner->d3d11_decoder, vdec,
inner->width, inner->height, view_buffer, &frame->output_buffer)) {
GST_ERROR_OBJECT (self, "Failed to copy buffer");
goto error;
}
gst_vp8_picture_unref (picture);
return gst_video_decoder_finish_frame (vdec, frame);
error:
gst_vp8_picture_unref (picture);
gst_video_decoder_release_frame (vdec, frame);
return GST_FLOW_ERROR;
}
void
gst_d3d11_vp8_dec_register (GstPlugin * plugin, GstD3D11Device * device,
GstD3D11Decoder * decoder, guint rank)
guint rank)
{
GType type;
gchar *type_name;
@ -791,10 +686,6 @@ gst_d3d11_vp8_dec_register (GstPlugin * plugin, GstD3D11Device * device,
(GInstanceInitFunc) gst_d3d11_vp8_dec_init,
};
const GUID *profile_guid = NULL;
/* values were taken from chromium. See supported_profile_helper.cc */
GstD3D11Vp8DecResolution resolutions_to_check[] = {
{1920, 1088}, {2560, 1440}, {3840, 2160}, {4096, 2160}, {4096, 2304}
};
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
guint max_width = 0;
@ -802,18 +693,18 @@ gst_d3d11_vp8_dec_register (GstPlugin * plugin, GstD3D11Device * device,
guint resolution;
DXGI_FORMAT format = DXGI_FORMAT_NV12;
if (!gst_d3d11_decoder_get_supported_decoder_profile (decoder,
GST_D3D11_CODEC_VP8, GST_VIDEO_FORMAT_NV12, &profile_guid)) {
if (!gst_d3d11_decoder_get_supported_decoder_profile (device,
GST_DXVA_CODEC_VP8, GST_VIDEO_FORMAT_NV12, &profile_guid)) {
GST_INFO_OBJECT (device, "device does not support VP8 decoding");
return;
}
for (i = 0; i < G_N_ELEMENTS (resolutions_to_check); i++) {
if (gst_d3d11_decoder_supports_resolution (decoder, profile_guid,
format, resolutions_to_check[i].width,
resolutions_to_check[i].height)) {
max_width = resolutions_to_check[i].width;
max_height = resolutions_to_check[i].height;
for (i = 0; i < G_N_ELEMENTS (gst_dxva_resolutions); i++) {
if (gst_d3d11_decoder_supports_resolution (device, profile_guid,
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;
GST_DEBUG_OBJECT (device,
"device support resolution %dx%d", max_width, max_height);
@ -843,7 +734,7 @@ gst_d3d11_vp8_dec_register (GstPlugin * plugin, GstD3D11Device * device,
"height", GST_TYPE_INT_RANGE, 1, resolution, NULL);
type_info.class_data =
gst_d3d11_decoder_class_data_new (device, GST_D3D11_CODEC_VP8,
gst_d3d11_decoder_class_data_new (device, GST_DXVA_CODEC_VP8,
sink_caps, src_caps);
type_name = g_strdup ("GstD3D11Vp8Dec");

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_vp8_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank);
G_END_DECLS

View file

@ -70,6 +70,7 @@
#include <gst/codecs/gstvp9decoder.h>
#include <string.h>
#include <vector>
/* HACK: to expose dxva data structure on UWP */
#ifdef WINAPI_PARTITION_DESKTOP
@ -85,17 +86,30 @@ GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_vp9_dec_debug);
/* reference list 8 + 4 margin */
#define NUM_OUTPUT_VIEW 12
/* *INDENT-OFF* */
typedef struct _GstD3D11Vp9DecInner
{
GstD3D11Device *device = nullptr;
GstD3D11Decoder *d3d11_decoder = nullptr;
DXVA_PicParams_VP9 pic_params;
DXVA_Slice_VPx_Short slice;
/* 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;
/* To calculate use_prev_in_find_mv_refs */
guint last_frame_width = 0;
guint last_frame_height = 0;
gboolean last_show_frame = FALSE;
} GstD3D11Vp9DecInner;
/* *INDENT-ON* */
typedef struct _GstD3D11Vp9Dec
{
GstVp9Decoder parent;
GstD3D11Device *device;
GstD3D11Decoder *d3d11_decoder;
/* To calculate use_prev_in_find_mv_refs */
guint last_frame_width;
guint last_frame_height;
gboolean last_show_frame;
GstD3D11Vp9DecInner *inner;
} GstD3D11Vp9Dec;
typedef struct _GstD3D11Vp9DecClass
@ -112,6 +126,7 @@ static GstElementClass *parent_class = NULL;
static void gst_d3d11_vp9_dec_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec);
static void gst_d3d11_vp9_dec_finalize (GObject * object);
static void gst_d3d11_vp9_dec_set_context (GstElement * element,
GstContext * context);
@ -132,14 +147,14 @@ static gboolean gst_d3d11_vp9_dec_new_picture (GstVp9Decoder * decoder,
GstVideoCodecFrame * frame, GstVp9Picture * picture);
static GstVp9Picture *gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder *
decoder, GstVideoCodecFrame * frame, GstVp9Picture * picture);
static GstFlowReturn gst_d3d11_vp9_dec_output_picture (GstVp9Decoder *
decoder, GstVideoCodecFrame * frame, GstVp9Picture * picture);
static gboolean gst_d3d11_vp9_dec_start_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture);
static gboolean gst_d3d11_vp9_dec_decode_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture, GstVp9Dpb * dpb);
static gboolean gst_d3d11_vp9_dec_end_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture);
static GstFlowReturn gst_d3d11_vp9_dec_output_picture (GstVp9Decoder *
decoder, GstVideoCodecFrame * frame, GstVp9Picture * picture);
static void
gst_d3d11_vp9_dec_class_init (GstD3D11Vp9DecClass * klass, gpointer data)
@ -151,6 +166,7 @@ gst_d3d11_vp9_dec_class_init (GstD3D11Vp9DecClass * klass, gpointer data)
GstD3D11DecoderClassData *cdata = (GstD3D11DecoderClassData *) data;
gobject_class->get_property = gst_d3d11_vp9_dec_get_property;
gobject_class->finalize = gst_d3d11_vp9_dec_finalize;
element_class->set_context =
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_set_context);
@ -174,19 +190,20 @@ gst_d3d11_vp9_dec_class_init (GstD3D11Vp9DecClass * klass, gpointer data)
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_new_picture);
vp9decoder_class->duplicate_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_duplicate_picture);
vp9decoder_class->output_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_output_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);
vp9decoder_class->output_picture =
GST_DEBUG_FUNCPTR (gst_d3d11_vp9_dec_output_picture);
}
static void
gst_d3d11_vp9_dec_init (GstD3D11Vp9Dec * self)
{
self->inner = new GstD3D11Vp9DecInner ();
}
static void
@ -199,15 +216,26 @@ gst_d3d11_vp9_dec_get_property (GObject * object, guint prop_id,
gst_d3d11_decoder_proxy_get_property (object, prop_id, value, pspec, cdata);
}
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);
}
static void
gst_d3d11_vp9_dec_set_context (GstElement * element, GstContext * context)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (element);
GstD3D11Vp9DecInner *inner = self->inner;
GstD3D11Vp9DecClass *klass = GST_D3D11_VP9_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
gst_d3d11_handle_set_context (element, context, cdata->adapter,
&self->device);
&inner->device);
GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
}
@ -216,20 +244,22 @@ static gboolean
gst_d3d11_vp9_dec_open (GstVideoDecoder * decoder)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
GstD3D11Vp9DecClass *klass = GST_D3D11_VP9_DEC_GET_CLASS (self);
GstD3D11DecoderSubClassData *cdata = &klass->class_data;
if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self), cdata->adapter,
&self->device)) {
&inner->device)) {
GST_ERROR_OBJECT (self, "Cannot create d3d11device");
return FALSE;
}
self->d3d11_decoder = gst_d3d11_decoder_new (self->device);
inner->d3d11_decoder = gst_d3d11_decoder_new (inner->device,
GST_DXVA_CODEC_VP9);
if (!self->d3d11_decoder) {
if (!inner->d3d11_decoder) {
GST_ERROR_OBJECT (self, "Cannot create d3d11 decoder");
gst_clear_object (&self->device);
gst_clear_object (&inner->device);
return FALSE;
}
@ -240,9 +270,10 @@ static gboolean
gst_d3d11_vp9_dec_close (GstVideoDecoder * decoder)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
gst_clear_object (&self->d3d11_decoder);
gst_clear_object (&self->device);
gst_clear_object (&inner->d3d11_decoder);
gst_clear_object (&inner->device);
return TRUE;
}
@ -251,8 +282,9 @@ static gboolean
gst_d3d11_vp9_dec_negotiate (GstVideoDecoder * decoder)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
if (!gst_d3d11_decoder_negotiate (self->d3d11_decoder, decoder))
if (!gst_d3d11_decoder_negotiate (inner->d3d11_decoder, decoder))
return FALSE;
return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
@ -263,8 +295,9 @@ gst_d3d11_vp9_dec_decide_allocation (GstVideoDecoder * decoder,
GstQuery * query)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
if (!gst_d3d11_decoder_decide_allocation (self->d3d11_decoder,
if (!gst_d3d11_decoder_decide_allocation (inner->d3d11_decoder,
decoder, query)) {
return FALSE;
}
@ -277,11 +310,12 @@ static gboolean
gst_d3d11_vp9_dec_src_query (GstVideoDecoder * decoder, GstQuery * query)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONTEXT:
if (gst_d3d11_handle_context_query (GST_ELEMENT (decoder),
query, self->device)) {
query, inner->device)) {
return TRUE;
}
break;
@ -296,15 +330,16 @@ static gboolean
gst_d3d11_vp9_dec_sink_event (GstVideoDecoder * decoder, GstEvent * event)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_START:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, TRUE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, TRUE);
break;
case GST_EVENT_FLUSH_STOP:
if (self->d3d11_decoder)
gst_d3d11_decoder_set_flushing (self->d3d11_decoder, decoder, FALSE);
if (inner->d3d11_decoder)
gst_d3d11_decoder_set_flushing (inner->d3d11_decoder, decoder, FALSE);
default:
break;
}
@ -317,6 +352,7 @@ gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
const GstVp9FrameHeader * frame_hdr)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
GstVideoInfo info;
GstVideoFormat out_format = GST_VIDEO_FORMAT_UNKNOWN;
@ -335,7 +371,7 @@ gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
gst_video_info_set_format (&info,
out_format, frame_hdr->width, frame_hdr->height);
if (!gst_d3d11_decoder_configure (self->d3d11_decoder, GST_D3D11_CODEC_VP9,
if (!gst_d3d11_decoder_configure (inner->d3d11_decoder,
decoder->input_state, &info, (gint) frame_hdr->width,
(gint) frame_hdr->height, NUM_OUTPUT_VIEW)) {
GST_ERROR_OBJECT (self, "Failed to create decoder");
@ -348,7 +384,8 @@ gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder,
}
/* Will be updated per decode_picture */
self->last_frame_width = self->last_frame_height = 0;
inner->last_frame_width = inner->last_frame_height = 0;
inner->last_show_frame = FALSE;
return TRUE;
}
@ -358,9 +395,10 @@ gst_d3d11_vp9_dec_new_picture (GstVp9Decoder * decoder,
GstVideoCodecFrame * frame, GstVp9Picture * picture)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
GstBuffer *view_buffer;
view_buffer = gst_d3d11_decoder_get_output_view_buffer (self->d3d11_decoder,
view_buffer = gst_d3d11_decoder_get_output_view_buffer (inner->d3d11_decoder,
GST_VIDEO_DECODER (decoder));
if (!view_buffer) {
GST_DEBUG_OBJECT (self, "No available output view buffer");
@ -382,11 +420,12 @@ gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder * decoder,
GstVideoCodecFrame * frame, GstVp9Picture * picture)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
GstBuffer *view_buffer;
GstVp9Picture *new_picture;
/* This method is called when show_frame == FALSE */
self->last_show_frame = FALSE;
inner->last_show_frame = FALSE;
view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
@ -407,45 +446,23 @@ gst_d3d11_vp9_dec_duplicate_picture (GstVp9Decoder * decoder,
return new_picture;
}
static GstFlowReturn
gst_d3d11_vp9_dec_output_picture (GstVp9Decoder * decoder,
GstVideoCodecFrame * frame, GstVp9Picture * picture)
static gboolean
gst_d3d11_vp9_dec_start_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
GstD3D11Vp9DecInner *inner = self->inner;
GST_LOG_OBJECT (self, "Outputting picture %p", picture);
inner->bitstream_buffer.resize (0);
view_buffer = (GstBuffer *) gst_vp9_picture_get_user_data (picture);
if (!view_buffer) {
GST_ERROR_OBJECT (self, "Could not get output view");
goto error;
}
if (!gst_d3d11_decoder_process_output (self->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;
}
gst_vp9_picture_unref (picture);
return gst_video_decoder_finish_frame (vdec, frame);
error:
gst_vp9_picture_unref (picture);
gst_video_decoder_drop_frame (vdec, frame);
return GST_FLOW_ERROR;
return TRUE;
}
static ID3D11VideoDecoderOutputView *
gst_d3d11_vp9_dec_get_output_view_from_picture (GstD3D11Vp9Dec * self,
GstVp9Picture * picture, guint8 * view_id)
{
GstD3D11Vp9DecInner *inner = self->inner;
GstBuffer *view_buffer;
ID3D11VideoDecoderOutputView *view;
@ -456,7 +473,7 @@ gst_d3d11_vp9_dec_get_output_view_from_picture (GstD3D11Vp9Dec * self,
}
view =
gst_d3d11_decoder_get_output_view_from_buffer (self->d3d11_decoder,
gst_d3d11_decoder_get_output_view_from_buffer (inner->d3d11_decoder,
view_buffer, view_id);
if (!view) {
GST_DEBUG_OBJECT (self, "current picture does not have output view handle");
@ -466,29 +483,6 @@ gst_d3d11_vp9_dec_get_output_view_from_picture (GstD3D11Vp9Dec * self,
return view;
}
static gboolean
gst_d3d11_vp9_dec_start_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
ID3D11VideoDecoderOutputView *view;
view = gst_d3d11_vp9_dec_get_output_view_from_picture (self, picture, NULL);
if (!view) {
GST_ERROR_OBJECT (self, "current picture does not have output view handle");
return FALSE;
}
GST_TRACE_OBJECT (self, "Begin frame");
if (!gst_d3d11_decoder_begin_frame (self->d3d11_decoder, view, 0, NULL)) {
GST_ERROR_OBJECT (self, "Failed to begin frame");
return FALSE;
}
return TRUE;
}
static void
gst_d3d11_vp9_dec_copy_frame_params (GstD3D11Vp9Dec * self,
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
@ -575,6 +569,7 @@ static void
gst_d3d11_vp9_dec_copy_loop_filter_params (GstD3D11Vp9Dec * self,
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
{
GstD3D11Vp9DecInner *inner = self->inner;
const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
const GstVp9LoopFilterParams *lfp = &frame_hdr->loop_filter_params;
@ -583,9 +578,9 @@ gst_d3d11_vp9_dec_copy_loop_filter_params (GstD3D11Vp9Dec * self,
params->mode_ref_delta_enabled = lfp->loop_filter_delta_enabled;
params->mode_ref_delta_update = lfp->loop_filter_delta_update;
params->use_prev_in_find_mv_refs =
self->last_show_frame &&
frame_hdr->width == self->last_frame_width &&
frame_hdr->height == self->last_frame_height &&
inner->last_show_frame &&
frame_hdr->width == inner->last_frame_width &&
frame_hdr->height == inner->last_frame_height &&
!frame_hdr->error_resilient_mode &&
!(frame_hdr->frame_type == GST_VP9_KEY_FRAME || frame_hdr->intra_only);
@ -663,192 +658,14 @@ gst_d3d11_vp9_dec_copy_segmentation_params (GstD3D11Vp9Dec * self,
}
}
static gboolean
gst_d3d11_vp9_dec_submit_picture_data (GstD3D11Vp9Dec * self,
GstVp9Picture * picture, DXVA_PicParams_VP9 * params)
{
guint d3d11_buffer_size;
gpointer d3d11_buffer;
gsize buffer_offset = 0;
gboolean is_first = TRUE;
GST_TRACE_OBJECT (self, "Getting picture params buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self,
"Failed to get decoder buffer for picture parameters");
return FALSE;
}
memcpy (d3d11_buffer, params, sizeof (DXVA_PicParams_VP9));
GST_TRACE_OBJECT (self, "Release picture param decoder buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS)) {
GST_ERROR_OBJECT (self, "Failed to release decoder buffer");
return FALSE;
}
if (!picture->data || !picture->size) {
GST_ERROR_OBJECT (self, "No data to submit");
return FALSE;
}
GST_TRACE_OBJECT (self, "Submit total %" G_GSIZE_FORMAT " bytes",
picture->size);
while (buffer_offset < picture->size) {
gsize bytes_to_copy = picture->size - buffer_offset;
gsize written_buffer_size;
gboolean is_last = TRUE;
DXVA_Slice_VPx_Short slice_short = { 0, };
D3D11_VIDEO_DECODER_BUFFER_DESC buffer_desc[3];
gboolean bad_aligned_bitstream_buffer = FALSE;
memset (buffer_desc, 0, sizeof (buffer_desc));
GST_TRACE_OBJECT (self, "Getting bitstream buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get bitstream buffer");
goto error;
}
if ((d3d11_buffer_size & 127) != 0) {
GST_WARNING_OBJECT (self,
"The size of bitstream buffer is not 128 bytes aligned");
bad_aligned_bitstream_buffer = TRUE;
}
if (bytes_to_copy > d3d11_buffer_size) {
/* if the size of this slice is larger than the size of remaining d3d11
* decoder bitstream memory, write the data up to the remaining d3d11
* decoder bitstream memory size and the rest would be written to the
* next d3d11 bitstream memory */
bytes_to_copy = d3d11_buffer_size;
is_last = FALSE;
}
memcpy (d3d11_buffer, picture->data + buffer_offset, bytes_to_copy);
written_buffer_size = bytes_to_copy;
/* DXVA2 spec is saying that written bitstream data must be 128 bytes
* aligned if the bitstream buffer contains end of frame
* (i.e., wBadSliceChopping == 0 or 2) */
if (is_last) {
guint padding = MIN (GST_ROUND_UP_128 (bytes_to_copy) - bytes_to_copy,
d3d11_buffer_size - bytes_to_copy);
if (padding) {
GST_TRACE_OBJECT (self,
"Written bitstream buffer size %" G_GSIZE_FORMAT
" is not 128 bytes aligned, add padding %d bytes",
bytes_to_copy, padding);
memset ((guint8 *) d3d11_buffer + bytes_to_copy, 0, padding);
written_buffer_size += padding;
}
}
GST_TRACE_OBJECT (self, "Release bitstream buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_BITSTREAM)) {
GST_ERROR_OBJECT (self, "Failed to release bitstream buffer");
goto error;
}
slice_short.BSNALunitDataLocation = 0;
slice_short.SliceBytesInBuffer = (UINT) written_buffer_size;
/* wBadSliceChopping: (dxva spec.)
* 0: All bits for the slice are located within the corresponding
* bitstream data buffer
* 1: The bitstream data buffer contains the start of the slice,
* but not the entire slice, because the buffer is full
* 2: The bitstream data buffer contains the end of the slice.
* It does not contain the start of the slice, because the start of
* the slice was located in the previous bitstream data buffer.
* 3: The bitstream data buffer does not contain the start of the slice
* (because the start of the slice was located in the previous
* bitstream data buffer), and it does not contain the end of the slice
* (because the current bitstream data buffer is also full).
*/
if (is_last && is_first) {
slice_short.wBadSliceChopping = 0;
} else if (!is_last && is_first) {
slice_short.wBadSliceChopping = 1;
} else if (is_last && !is_first) {
slice_short.wBadSliceChopping = 2;
} else {
slice_short.wBadSliceChopping = 3;
}
GST_TRACE_OBJECT (self, "Getting slice control buffer");
if (!gst_d3d11_decoder_get_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL, &d3d11_buffer_size,
&d3d11_buffer)) {
GST_ERROR_OBJECT (self, "Couldn't get slice control buffer");
goto error;
}
memcpy (d3d11_buffer, &slice_short, sizeof (DXVA_Slice_VPx_Short));
GST_TRACE_OBJECT (self, "Release slice control buffer");
if (!gst_d3d11_decoder_release_decoder_buffer (self->d3d11_decoder,
D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL)) {
GST_ERROR_OBJECT (self, "Failed to release slice control buffer");
goto error;
}
buffer_desc[0].BufferType = D3D11_VIDEO_DECODER_BUFFER_PICTURE_PARAMETERS;
buffer_desc[0].DataOffset = 0;
buffer_desc[0].DataSize = sizeof (DXVA_PicParams_VP9);
buffer_desc[1].BufferType = D3D11_VIDEO_DECODER_BUFFER_SLICE_CONTROL;
buffer_desc[1].DataOffset = 0;
buffer_desc[1].DataSize = sizeof (DXVA_Slice_VPx_Short);
if (!bad_aligned_bitstream_buffer && (written_buffer_size & 127) != 0) {
GST_WARNING_OBJECT (self,
"Written bitstream buffer size %" G_GSIZE_FORMAT
" is not 128 bytes aligned", written_buffer_size);
}
buffer_desc[2].BufferType = D3D11_VIDEO_DECODER_BUFFER_BITSTREAM;
buffer_desc[2].DataOffset = 0;
buffer_desc[2].DataSize = written_buffer_size;
if (!gst_d3d11_decoder_submit_decoder_buffers (self->d3d11_decoder,
3, buffer_desc)) {
GST_ERROR_OBJECT (self, "Couldn't submit decoder buffers");
goto error;
}
buffer_offset += bytes_to_copy;
is_first = FALSE;
}
self->last_frame_width = params->width;
self->last_frame_height = params->height;
self->last_show_frame = TRUE;
return TRUE;
error:
return FALSE;
}
static gboolean
gst_d3d11_vp9_dec_decode_picture (GstVp9Decoder * decoder,
GstVp9Picture * picture, GstVp9Dpb * dpb)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
DXVA_PicParams_VP9 pic_params = { 0, };
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;
@ -859,44 +676,124 @@ gst_d3d11_vp9_dec_decode_picture (GstVp9Decoder * decoder,
return FALSE;
}
pic_params.CurrPic.Index7Bits = view_id;
pic_params.uncompressed_header_size_byte_aligned =
memset (pic_params, 0, sizeof (DXVA_PicParams_VP9));
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;
pic_params->first_partition_size = picture->frame_hdr.header_size_in_bytes;
pic_params->StatusReportFeedbackNumber = 1;
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);
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);
return gst_d3d11_vp9_dec_submit_picture_data (self, picture, &pic_params);
inner->bitstream_buffer.resize (picture->size);
memcpy (&inner->bitstream_buffer[0], picture->data, picture->size);
slice->BSNALunitDataLocation = 0;
slice->SliceBytesInBuffer = inner->bitstream_buffer.size ();
slice->wBadSliceChopping = 0;
inner->last_frame_width = pic_params->width;
inner->last_frame_height = pic_params->height;
inner->last_show_frame = TRUE;
return TRUE;
}
static gboolean
gst_d3d11_vp9_dec_end_picture (GstVp9Decoder * decoder, GstVp9Picture * picture)
{
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
ID3D11VideoDecoderOutputView *view;
guint8 view_id = 0xff;
size_t bitstream_buffer_size;
size_t bitstream_pos;
GstD3D11DecodeInputStreamArgs input_args;
if (!gst_d3d11_decoder_end_frame (self->d3d11_decoder)) {
GST_ERROR_OBJECT (self, "Failed to EndFrame");
if (inner->bitstream_buffer.empty ()) {
GST_ERROR_OBJECT (self, "No bitstream buffer to submit");
return FALSE;
}
return TRUE;
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");
return FALSE;
}
memset (&input_args, 0, sizeof (GstD3D11DecodeInputStreamArgs));
bitstream_pos = inner->bitstream_buffer.size ();
bitstream_buffer_size = GST_ROUND_UP_128 (bitstream_pos);
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 ();
return gst_d3d11_decoder_decode_frame (inner->d3d11_decoder,
view, &input_args);
}
typedef struct
static GstFlowReturn
gst_d3d11_vp9_dec_output_picture (GstVp9Decoder * decoder,
GstVideoCodecFrame * frame, GstVp9Picture * picture)
{
guint width;
guint height;
} GstD3D11Vp9DecResolution;
GstD3D11Vp9Dec *self = GST_D3D11_VP9_DEC (decoder);
GstD3D11Vp9DecInner *inner = self->inner;
GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
GstBuffer *view_buffer;
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;
}
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;
}
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;
}
void
gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
GstD3D11Decoder * decoder, guint rank)
guint rank)
{
GType type;
gchar *type_name;
@ -917,10 +814,6 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
};
const GUID *profile2_guid = NULL;
const GUID *profile0_guid = NULL;
/* values were taken from chromium. See supported_profile_helper.cc */
GstD3D11Vp9DecResolution resolutions_to_check[] = {
{4096, 2160}, {4096, 2304}, {7680, 4320}, {8192, 4320}, {8192, 8192}
};
GstCaps *sink_caps = NULL;
GstCaps *src_caps = NULL;
guint max_width = 0;
@ -931,27 +824,27 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
DXGI_FORMAT format = DXGI_FORMAT_UNKNOWN;
GValue vp9_profiles = G_VALUE_INIT;
have_profile2 = gst_d3d11_decoder_get_supported_decoder_profile (decoder,
GST_D3D11_CODEC_VP9, GST_VIDEO_FORMAT_P010_10LE, &profile2_guid);
have_profile2 = gst_d3d11_decoder_get_supported_decoder_profile (device,
GST_DXVA_CODEC_VP9, GST_VIDEO_FORMAT_P010_10LE, &profile2_guid);
if (!have_profile2) {
GST_DEBUG_OBJECT (device,
"decoder does not support VP9_VLD_10BIT_PROFILE2");
} else {
have_profile2 &=
gst_d3d11_decoder_supports_format (decoder,
gst_d3d11_decoder_supports_format (device,
profile2_guid, DXGI_FORMAT_P010);
if (!have_profile2) {
GST_FIXME_OBJECT (device, "device does not support P010 format");
}
}
have_profile0 = gst_d3d11_decoder_get_supported_decoder_profile (decoder,
GST_D3D11_CODEC_VP9, GST_VIDEO_FORMAT_NV12, &profile0_guid);
have_profile0 = gst_d3d11_decoder_get_supported_decoder_profile (device,
GST_DXVA_CODEC_VP9, GST_VIDEO_FORMAT_NV12, &profile0_guid);
if (!have_profile0) {
GST_DEBUG_OBJECT (device, "decoder does not support VP9_VLD_PROFILE0");
} else {
have_profile0 =
gst_d3d11_decoder_supports_format (decoder, profile0_guid,
gst_d3d11_decoder_supports_format (device, profile0_guid,
DXGI_FORMAT_NV12);
if (!have_profile0) {
GST_FIXME_OBJECT (device, "device does not support NV12 format");
@ -971,12 +864,12 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
format = DXGI_FORMAT_P010;
}
for (i = 0; i < G_N_ELEMENTS (resolutions_to_check); i++) {
if (gst_d3d11_decoder_supports_resolution (decoder, profile,
format, resolutions_to_check[i].width,
resolutions_to_check[i].height)) {
max_width = resolutions_to_check[i].width;
max_height = resolutions_to_check[i].height;
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;
GST_DEBUG_OBJECT (device,
"device support resolution %dx%d", max_width, max_height);
@ -1042,7 +935,7 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device,
"height", GST_TYPE_INT_RANGE, 1, resolution, NULL);
type_info.class_data =
gst_d3d11_decoder_class_data_new (device, GST_D3D11_CODEC_VP9,
gst_d3d11_decoder_class_data_new (device, GST_DXVA_CODEC_VP9,
sink_caps, src_caps);
type_name = g_strdup ("GstD3D11Vp9Dec");

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
void gst_d3d11_vp9_dec_register (GstPlugin * plugin,
GstD3D11Device * device,
GstD3D11Decoder * decoder,
guint rank);
G_END_DECLS

View file

@ -57,6 +57,7 @@ GST_DEBUG_CATEGORY (gst_d3d11_video_processor_debug);
GST_DEBUG_CATEGORY (gst_d3d11_compositor_debug);
#ifdef HAVE_DXVA_H
GST_DEBUG_CATEGORY (gst_d3d11_decoder_debug);
GST_DEBUG_CATEGORY (gst_d3d11_h264_dec_debug);
GST_DEBUG_CATEGORY (gst_d3d11_h265_dec_debug);
GST_DEBUG_CATEGORY (gst_d3d11_vp9_dec_debug);
@ -105,6 +106,8 @@ plugin_init (GstPlugin * plugin)
#ifdef HAVE_DXVA_H
/* DXVA2 API is availble since Windows 8 */
if (gst_d3d11_is_windows_8_or_greater ()) {
GST_DEBUG_CATEGORY_INIT (gst_d3d11_decoder_debug,
"d3d11decoder", 0, "Direct3D11 Video Decoder object");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_h264_dec_debug,
"d3d11h264dec", 0, "Direct3D11 H.264 Video Decoder");
GST_DEBUG_CATEGORY_INIT (gst_d3d11_vp9_dec_debug,
@ -145,38 +148,18 @@ plugin_init (GstPlugin * plugin)
#ifdef HAVE_DXVA_H
/* DXVA2 API is availble since Windows 8 */
if (gst_d3d11_is_windows_8_or_greater ()) {
GstD3D11Decoder *decoder = NULL;
gboolean legacy;
gboolean hardware;
if (gst_d3d11_is_windows_8_or_greater () &&
gst_d3d11_device_get_video_device_handle (device)) {
gboolean legacy = gst_d3d11_decoder_util_is_legacy_device (device);
g_object_get (device, "hardware", &hardware, NULL);
if (!hardware)
goto done;
decoder = gst_d3d11_decoder_new (device);
if (!decoder)
goto done;
legacy = gst_d3d11_decoder_util_is_legacy_device (device);
gst_d3d11_h264_dec_register (plugin,
device, decoder, GST_RANK_SECONDARY, legacy);
gst_d3d11_h264_dec_register (plugin, device, GST_RANK_SECONDARY, legacy);
if (!legacy) {
gst_d3d11_h265_dec_register (plugin, device, decoder,
GST_RANK_SECONDARY);
gst_d3d11_vp9_dec_register (plugin, device, decoder,
GST_RANK_SECONDARY);
gst_d3d11_vp8_dec_register (plugin, device, decoder,
GST_RANK_SECONDARY);
gst_d3d11_mpeg2_dec_register (plugin, device, decoder,
GST_RANK_SECONDARY);
gst_d3d11_av1_dec_register (plugin, device, decoder,
GST_RANK_SECONDARY);
gst_d3d11_h265_dec_register (plugin, device, GST_RANK_SECONDARY);
gst_d3d11_vp9_dec_register (plugin, device, GST_RANK_SECONDARY);
gst_d3d11_vp8_dec_register (plugin, device, GST_RANK_SECONDARY);
gst_d3d11_mpeg2_dec_register (plugin, device, GST_RANK_SECONDARY);
gst_d3d11_av1_dec_register (plugin, device, GST_RANK_SECONDARY);
}
done:
gst_clear_object (&decoder);
}
#endif