mfvideosrc: Check framerate for target IMediaFrameFormat selection
authorSeungha Yang <seungha@centricular.com>
Fri, 31 Jul 2020 15:53:46 +0000 (00:53 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sat, 1 Aug 2020 15:17:05 +0000 (15:17 +0000)
Not only resolution and format, but framerate needs to be checked
for proper target IMediaFrameFormat selection.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1478>

sys/mediafoundation/mediacapturewrapper.cpp

index 657673a..dac3708 100644 (file)
@@ -787,6 +787,8 @@ MediaCaptureWrapper::mediaCaptureInitPost (ComPtr<IAsyncAction> init_async,
     HString subtype;
     UINT32 width = 0;
     UINT32 height = 0;
+    UINT32 fps_n = 0;
+    UINT32 fps_d = 1;
 
     hr = formatList->GetAt (i, &fmt);
     if (!gst_mf_result (hr))
@@ -813,6 +815,27 @@ MediaCaptureWrapper::mediaCaptureInitPost (ComPtr<IAsyncAction> init_async,
       continue;
     }
 
+    hr = fmt->get_FrameRate (&ratio);
+    if (!gst_mf_result (hr))
+      continue;
+
+    hr = ratio->get_Numerator (&fps_n);
+    if (!gst_mf_result (hr))
+      continue;
+
+    hr = ratio->get_Denominator (&fps_d);
+    if (!gst_mf_result (hr))
+      continue;
+
+    if ((gint) fps_n != GST_VIDEO_INFO_FPS_N (&videoInfo) ||
+        (gint) fps_d != GST_VIDEO_INFO_FPS_D (&videoInfo)) {
+      GST_DEBUG ("IMediaFrameFormat[%d], framerate %d/%d is not equal to "
+          "target framerate %d/%d", i, width, height,
+          GST_VIDEO_INFO_FPS_N (&videoInfo),
+          GST_VIDEO_INFO_FPS_D (&videoInfo));
+      continue;
+    }
+
     /* TODO: check major type for audio */
     hr = fmt->get_Subtype (subtype.GetAddressOf ());
     if (!gst_mf_result (hr))