mfvideosrc: Handle I420/IYUV subtypes for UWP cases

Microsoft defines two I420 formats, one is I420, and the other is
IYUV (but both are same, just names are different).
Since both will be converted to GST_VIDEO_FORMAT_I420,
we should check both I420 and IYUV subtypes during
GstVideoFormat to Microsoft's format conversion.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1478>
This commit is contained in:
Seungha Yang 2020-07-31 03:46:39 +09:00 committed by GStreamer Merge Bot
parent 2303ad7bf4
commit 3fb8caf635

View file

@ -74,7 +74,8 @@ gst_media_capture_subtype_to_video_format (const std::string &subtype)
return "NV12"; return "NV12";
else if (g_ascii_strcasecmp (subtype.c_str(), "YV12") == 0) else if (g_ascii_strcasecmp (subtype.c_str(), "YV12") == 0)
return "YV12"; return "YV12";
else if (g_ascii_strcasecmp (subtype.c_str(), "IYUV") == 0) else if (g_ascii_strcasecmp (subtype.c_str(), "IYUV") == 0 ||
g_ascii_strcasecmp (subtype.c_str(), "I420") == 0)
return "I420"; return "I420";
else if (g_ascii_strcasecmp (subtype.c_str(), "YUY2") == 0) else if (g_ascii_strcasecmp (subtype.c_str(), "YUY2") == 0)
return "YUY2"; return "YUY2";
@ -654,6 +655,8 @@ MediaCaptureWrapper::mediaCaptureInitPost (ComPtr<IAsyncAction> init_async,
UINT32 count = 0; UINT32 count = 0;
GstVideoInfo videoInfo; GstVideoInfo videoInfo;
HRESULT hr; HRESULT hr;
bool is_I420_subtype = false;
std::string target_subtype;
ComPtr<ITypedEventHandler<MediaFrameReader*, MediaFrameArrivedEventArgs*>> ComPtr<ITypedEventHandler<MediaFrameReader*, MediaFrameArrivedEventArgs*>>
frame_arrived_handler = Callback<ITypedEventHandler<MediaFrameReader*, frame_arrived_handler = Callback<ITypedEventHandler<MediaFrameReader*,
MediaFrameArrivedEventArgs*>> ([&] MediaFrameArrivedEventArgs*>> ([&]
@ -676,6 +679,12 @@ MediaCaptureWrapper::mediaCaptureInitPost (ComPtr<IAsyncAction> init_async,
goto done; goto done;
} }
/* Windows defines two I420 format, one is I420 and the other is IYUV.
* So, if requested video format was I420, we should accept both I420 and
* IYUV formats */
is_I420_subtype = GST_VIDEO_INFO_FORMAT (&videoInfo) == GST_VIDEO_FORMAT_I420;
target_subtype = convert_hstring_to_string (&media_desc_->subtype_);
hr = media_capture.As (&media_capture5); hr = media_capture.As (&media_capture5);
if (!gst_mf_result (hr)) if (!gst_mf_result (hr))
goto done; goto done;
@ -809,11 +818,16 @@ MediaCaptureWrapper::mediaCaptureInitPost (ComPtr<IAsyncAction> init_async,
if (!gst_mf_result (hr)) if (!gst_mf_result (hr))
continue; continue;
if (wcscmp (subtype.GetRawBuffer (nullptr),
media_desc_->subtype_.GetRawBuffer (nullptr))) {
std::string cur_subtype = convert_hstring_to_string (&subtype); std::string cur_subtype = convert_hstring_to_string (&subtype);
std::string target_subtype =
convert_hstring_to_string (&media_desc_->subtype_); if (is_I420_subtype) {
/* Special handling for I420 */
if (cur_subtype != "I420" && cur_subtype != "IYUV") {
GST_LOG ("IMediaFrameFormat[%d], subtype %s is not equal to target %s",
i, cur_subtype.c_str (), target_subtype.c_str ());
continue;
}
} else if (cur_subtype != target_subtype) {
GST_LOG ("IMediaFrameFormat[%d], subtype %s is not equal to target %s", GST_LOG ("IMediaFrameFormat[%d], subtype %s is not equal to target %s",
i, cur_subtype.c_str (), target_subtype.c_str ()); i, cur_subtype.c_str (), target_subtype.c_str ());
continue; continue;