From: Seungha Yang Date: Sat, 25 Jun 2022 21:39:54 +0000 (+0900) Subject: mfvideoenc: Fix broken encoding when resolution is not an even number X-Git-Tag: 1.22.0~1363 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=236378c9d5be1fc8dbbff897888ecd86d421a9d0;p=platform%2Fupstream%2Fgstreamer.git mfvideoenc: Fix broken encoding when resolution is not an even number Width and height values of 4:2:0 subsampled YUV format should be even number, and if it's not the case, there should be padding which is not a contiguous memory layout. Do copy input frames to MediaFoundation's memory in that case for now. Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1165 Part-of: --- diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.cpp b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.cpp index eed4394..01f657c 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.cpp +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.cpp @@ -316,6 +316,14 @@ gst_mf_video_encoder_init_mft (GstMFVideoEncoder * self) } #endif + /* TODO: We support I420/NV12/P010 only for now. + * Consider other subsampling once we add it */ + if ((info->width % 2) != 0 || (info->height % 2) != 0) { + self->need_align = TRUE; + } else { + self->need_align = FALSE; + } + hr = MFCreateMediaType (&out_type); if (!gst_mf_result (hr)) return FALSE; @@ -944,7 +952,7 @@ gst_mf_video_encoder_create_input_sample (GstMFVideoEncoder * self, gint i, j; GstVideoFrame *vframe = nullptr; BYTE *data = nullptr; - gboolean need_copy; + gboolean need_copy = self->need_align; vframe = g_new0 (GstVideoFrame, 1); @@ -959,7 +967,9 @@ gst_mf_video_encoder_create_input_sample (GstMFVideoEncoder * self, goto error; /* Check if we can forward this memory to Media Foundation without copy */ - need_copy = gst_mf_video_encoder_frame_needs_copy (vframe); + if (!need_copy) + need_copy = gst_mf_video_encoder_frame_needs_copy (vframe); + if (need_copy) { GST_TRACE_OBJECT (self, "Copy input buffer into Media Foundation memory"); hr = MFCreateMemoryBuffer (GST_VIDEO_INFO_SIZE (info), &media_buffer); diff --git a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.h b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.h index aa96b75..69892bd 100644 --- a/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.h +++ b/subprojects/gst-plugins-bad/sys/mediafoundation/gstmfvideoencoder.h @@ -107,6 +107,8 @@ struct _GstMFVideoEncoder * when B-frame is enabled. */ LONGLONG mf_pts_offset; + gboolean need_align; + #if GST_MF_HAVE_D3D11 /* For D3D11 interop. */ GstD3D11Device *other_d3d11_device;