From 371b181292d27643bb990c9bc4c5e773a15c5738 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Mon, 3 Feb 2020 22:23:21 +0900 Subject: [PATCH] d3d11decoder: Use consistent resolution between output caps and video meta h264/h265 decoded buffer might have crop area then we need to adjust video meta based on the padding space --- sys/d3d11/gstd3d11decoder.c | 24 ++++++++++++++++++------ sys/d3d11/gstd3d11decoder.h | 2 ++ sys/d3d11/gstd3d11h264dec.c | 12 ++++++------ sys/d3d11/gstd3d11h265dec.c | 11 ++++++----- sys/d3d11/gstd3d11vp9dec.c | 5 +++-- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/sys/d3d11/gstd3d11decoder.c b/sys/d3d11/gstd3d11decoder.c index ca877a1..da2a75c 100644 --- a/sys/d3d11/gstd3d11decoder.c +++ b/sys/d3d11/gstd3d11decoder.c @@ -347,13 +347,15 @@ gst_d3d11_decoder_ensure_output_view (GstD3D11Decoder * self, /* Must be called from D3D11Device thread */ static gboolean gst_d3d11_decoder_prepare_output_view_pool (GstD3D11Decoder * self, - GstVideoInfo * info, guint pool_size, const GUID * decoder_profile) + GstVideoInfo * info, guint coded_width, guint coded_height, + guint pool_size, const GUID * decoder_profile) { GstD3D11DecoderPrivate *priv = self->priv; GstD3D11AllocationParams *alloc_params = NULL; GstBufferPool *pool = NULL; GstStructure *config = NULL; GstCaps *caps = NULL; + GstVideoAlignment align; gst_clear_object (&priv->internal_pool); @@ -366,6 +368,14 @@ gst_d3d11_decoder_prepare_output_view_pool (GstD3D11Decoder * self, } alloc_params->desc[0].ArraySize = pool_size; + gst_video_alignment_reset (&align); + + align.padding_right = coded_width - GST_VIDEO_INFO_WIDTH (info); + align.padding_bottom = coded_height - GST_VIDEO_INFO_HEIGHT (info); + if (!gst_d3d11_allocation_params_alignment (alloc_params, &align)) { + GST_ERROR_OBJECT (self, "Cannot set alignment"); + return FALSE; + } pool = gst_d3d11_buffer_pool_new (priv->device); if (!pool) { @@ -415,8 +425,8 @@ error: gboolean gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, - GstVideoInfo * info, guint pool_size, const GUID ** decoder_profiles, - guint profile_size) + GstVideoInfo * info, guint coded_width, guint coded_height, + guint pool_size, const GUID ** decoder_profiles, guint profile_size) { GstD3D11DecoderPrivate *priv; const GstD3D11Format *d3d11_format; @@ -435,6 +445,8 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, 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 (coded_width >= GST_VIDEO_INFO_WIDTH (info), FALSE); + g_return_val_if_fail (coded_height >= GST_VIDEO_INFO_HEIGHT (info), FALSE); g_return_val_if_fail (pool_size > 0, FALSE); g_return_val_if_fail (decoder_profiles != NULL, FALSE); g_return_val_if_fail (profile_size > 0, FALSE); @@ -531,8 +543,8 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, gst_d3d11_decoder_reset_unlocked (decoder); - decoder_desc.SampleWidth = GST_VIDEO_INFO_WIDTH (info); - decoder_desc.SampleHeight = GST_VIDEO_INFO_HEIGHT (info); + decoder_desc.SampleWidth = coded_width; + decoder_desc.SampleHeight = coded_height; decoder_desc.OutputFormat = d3d11_format->dxgi_format; decoder_desc.Guid = *selected_profile; @@ -577,7 +589,7 @@ gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, } if (!gst_d3d11_decoder_prepare_output_view_pool (decoder, - info, pool_size, selected_profile)) { + info, coded_width, coded_height, pool_size, selected_profile)) { GST_ERROR_OBJECT (decoder, "Couldn't prepare output view pool"); goto error; } diff --git a/sys/d3d11/gstd3d11decoder.h b/sys/d3d11/gstd3d11decoder.h index 1efcfca..80c5a1b 100644 --- a/sys/d3d11/gstd3d11decoder.h +++ b/sys/d3d11/gstd3d11decoder.h @@ -85,6 +85,8 @@ GstD3D11Decoder * gst_d3d11_decoder_new (GstD3D11Device * device); gboolean gst_d3d11_decoder_open (GstD3D11Decoder * decoder, GstD3D11Codec codec, GstVideoInfo * info, + guint codec_width, + guint codec_height, guint pool_size, const GUID ** decoder_profiles, guint profile_size); diff --git a/sys/d3d11/gstd3d11h264dec.c b/sys/d3d11/gstd3d11h264dec.c index bb4762f..898f70d 100644 --- a/sys/d3d11/gstd3d11h264dec.c +++ b/sys/d3d11/gstd3d11h264dec.c @@ -517,7 +517,8 @@ gst_d3d11_h264_dec_new_sequence (GstH264Decoder * decoder, if (self->width != crop_width || self->height != crop_height || self->coded_width != sps->width || self->coded_height != sps->height) { - GST_INFO_OBJECT (self, "resolution changed %dx%d", crop_width, crop_height); + GST_INFO_OBJECT (self, "resolution changed %dx%d (%dx%d)", + crop_width, crop_height, sps->width, sps->height); self->width = crop_width; self->height = crop_height; self->coded_width = sps->width; @@ -561,14 +562,13 @@ gst_d3d11_h264_dec_new_sequence (GstH264Decoder * decoder, return FALSE; } - /* allocated internal pool with coded width/height */ gst_video_info_set_format (&info, - self->out_format, self->coded_width, self->coded_height); + self->out_format, self->width, self->height); gst_d3d11_decoder_reset (self->d3d11_decoder); if (!gst_d3d11_decoder_open (self->d3d11_decoder, GST_D3D11_CODEC_H264, - &info, NUM_OUTPUT_VIEW, supported_profiles, - G_N_ELEMENTS (supported_profiles))) { + &info, self->coded_width, self->coded_height, NUM_OUTPUT_VIEW, + supported_profiles, G_N_ELEMENTS (supported_profiles))) { GST_ERROR_OBJECT (self, "Failed to create decoder"); return FALSE; } @@ -1237,7 +1237,7 @@ gst_d3d11_h264_dec_register (GstPlugin * plugin, GstD3D11Device * device, gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1280, 720); ret = gst_d3d11_decoder_open (decoder, GST_D3D11_CODEC_H264, - &info, NUM_OUTPUT_VIEW, supported_profiles, + &info, 1280, 720, NUM_OUTPUT_VIEW, supported_profiles, G_N_ELEMENTS (supported_profiles)); gst_object_unref (decoder); diff --git a/sys/d3d11/gstd3d11h265dec.c b/sys/d3d11/gstd3d11h265dec.c index 25b84f9..0cbb4b9 100644 --- a/sys/d3d11/gstd3d11h265dec.c +++ b/sys/d3d11/gstd3d11h265dec.c @@ -479,7 +479,8 @@ gst_d3d11_h265_dec_new_sequence (GstH265Decoder * decoder, if (self->width != crop_width || self->height != crop_height || self->coded_width != sps->width || self->coded_height != sps->height) { - GST_INFO_OBJECT (self, "resolution changed %dx%d", crop_width, crop_height); + GST_INFO_OBJECT (self, "resolution changed %dx%d (%dx%d)", + crop_width, crop_height, sps->width, sps->height); self->width = crop_width; self->height = crop_height; self->coded_width = sps->width; @@ -526,13 +527,13 @@ gst_d3d11_h265_dec_new_sequence (GstH265Decoder * decoder, return FALSE; } - /* allocated internal pool with coded width/height */ gst_video_info_set_format (&info, - self->out_format, self->coded_width, self->coded_height); + self->out_format, self->width, self->height); gst_d3d11_decoder_reset (self->d3d11_decoder); if (!gst_d3d11_decoder_open (self->d3d11_decoder, GST_D3D11_CODEC_H265, - &info, NUM_OUTPUT_VIEW, &profile_guid, 1)) { + &info, self->coded_width, self->coded_height, + NUM_OUTPUT_VIEW, &profile_guid, 1)) { GST_ERROR_OBJECT (self, "Failed to create decoder"); return FALSE; } @@ -1452,7 +1453,7 @@ gst_d3d11_h265_dec_register (GstPlugin * plugin, GstD3D11Device * device, gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1280, 720); ret = gst_d3d11_decoder_open (decoder, GST_D3D11_CODEC_H265, - &info, NUM_OUTPUT_VIEW, supported_profiles, + &info, 1280, 720, NUM_OUTPUT_VIEW, supported_profiles, G_N_ELEMENTS (supported_profiles)); gst_object_unref (decoder); diff --git a/sys/d3d11/gstd3d11vp9dec.c b/sys/d3d11/gstd3d11vp9dec.c index c0b92cf..2b50b29 100644 --- a/sys/d3d11/gstd3d11vp9dec.c +++ b/sys/d3d11/gstd3d11vp9dec.c @@ -512,7 +512,8 @@ gst_d3d11_vp9_dec_new_sequence (GstVp9Decoder * decoder, gst_d3d11_decoder_reset (self->d3d11_decoder); if (!gst_d3d11_decoder_open (self->d3d11_decoder, GST_D3D11_CODEC_VP9, - &info, NUM_OUTPUT_VIEW, &profile_guid, 1)) { + &info, self->width, self->height, + NUM_OUTPUT_VIEW, &profile_guid, 1)) { GST_ERROR_OBJECT (self, "Failed to create decoder"); return FALSE; } @@ -1217,7 +1218,7 @@ gst_d3d11_vp9_dec_register (GstPlugin * plugin, GstD3D11Device * device, gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12, 1280, 720); ret = gst_d3d11_decoder_open (decoder, GST_D3D11_CODEC_VP9, - &info, NUM_OUTPUT_VIEW, supported_profiles, + &info, 1280, 720, NUM_OUTPUT_VIEW, supported_profiles, G_N_ELEMENTS (supported_profiles)); gst_object_unref (decoder); -- 2.7.4