0

My UWP store app that uses the webcam to scan QR code images does not work on certain laptops. I am using the MediaCapture class to preview and scan. I had reports from various users that certain devices just don't show any image(and no error message) in the app while others show the camera preview just fine. Below is a list of devices to help narrow down where the issue might be. Some of these I tested by going into a big box retailer that has laptops on display.

These work:

  • Dell E5450 (tested myself)
  • Lenovo u310 (tested myself)
  • Lenovo u310 with additional webcam attached (tested myself)
  • Lenovo tablet (reported by user, not verified, has multiple cameras)
  • HP elitebook 850 g5 (tested myself, has Windows Hello)
  • Multiple generic high end laptops

These don't work:

  • Surface Go (reported by user, verified myself, has Windows Hello)
  • Surface Laptop (reported by user, unsure which model, has Windows Hello)
  • Dell Latitude 7275 (reported by user, not verified, has RealSense camera)

Initially, I thought this was caused by multiple camera's being connected or their higher resolution, but after more reports and testing, I think it might be these 'special' camera's that are causing trouble.

This is the initialization code:

mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
List<VideoEncodingProperties> availableResolutions = null;
try { 
    availableResolutions = mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview).Where(properties=>properties is VideoEncodingProperties).Select(properties=>(VideoEncodingProperties)properties).ToList();
}
catch(Exception ex)
{
    MessageManager.ShowMessageToUserAsync("No resolutions could be detected, trying default mode.");
}
VideoEncodingProperties bestVideoResolution = this.findBestResolution(availableResolutions);
VideoEncodingProperties bestPhotoResolution = this.findBestResolution(availableResolutions);
if (bestVideoResolution != null)
{
    await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, bestVideoResolution);
}
if (bestPhotoResolution != null)
{
    await mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, bestPhotoResolution);
}
displayRequest.RequestActive();
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
previewWindowElement.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();

The entire file is here: https://github.com/matthiasduyck/WifiQRCodeReader/blob/b774cbca4f9dc58f9aed53ebdb827666f4924bb2/Wifi%20QR%20code%20scanner/Managers/QRCameraManager.cs

And this is the full project at the revision currently in the store: https://github.com/matthiasduyck/WifiQRCodeReader/tree/b774cbca4f9dc58f9aed53ebdb827666f4924bb2

This is the app in the store: https://www.microsoft.com/en-us/p/wifi-qr-code-scanner/9pnhnrbg9wlh

Does anyone know what is going on and how I can resolve this issue?

Edit: I have update the app to try and filter out non-color style camera's(depth, infrared, etc). It looks like my updated code does not do this properly. This is the code that tries to find all color cameras only:

var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var groups = await MediaFrameSourceGroup.FindAllAsync();

// Filter out color video preview and video record type sources and remove duplicates video devices.
var _frameSourceGroups = groups.Where(g => g.SourceInfos.Any(s => s.SourceKind == MediaFrameSourceKind.Color &&
                        (s.MediaStreamType == MediaStreamType.VideoPreview || s.MediaStreamType == MediaStreamType.VideoRecord))
                        && g.SourceInfos.All(sourceInfo => videoDevices.Any(vd => vd.Id == sourceInfo.DeviceInformation.Id))).ToList();
availableColorCameras = _frameSourceGroups.SelectMany(x => x.SourceInfos.Select(y => y.DeviceInformation));

This is the dropdown that a user with a windows hello style camera got: camera dropdown options, 6 cameras listed

  • So I could not reproduce your issue my current machine. If you think multiple cameras cause this issue, you could specific the camera with device [enumeration](https://github.com/microsoft/Windows-universal-samples/blob/master/Samples/CameraStarterKit/cs/MainPage.xaml.cs#L220). – Nico Zhu Aug 13 '19 at 13:47
  • Well, I get your point and I add the comment above please check, – Nico Zhu Aug 13 '19 at 13:54
  • @NicoZhu-MSFT It is **not** due to multiple cameras, I have tested that that is working fine. I think it might be due to the realsense/windows hello camera, but I'm not sure why the microsoft samples would not work with these. – Matthias Duyck Aug 13 '19 at 13:54
  • Could you reproduce this with windows hello camera ? – Nico Zhu Aug 13 '19 at 13:57
  • @NicoZhu-MSFT As mentioned in my question, I could reproduce the issue on a Surface Go, which has a Windows Hello camera. A user reported the same on a Surface Laptop(Windows Hello) and another on a Laptop with RealSense camera. I don't own any of these devices so I cannot debug my code on it. – Matthias Duyck Aug 13 '19 at 14:02
  • emm, I also have not above devices, I will report this to related team. Waiting for news :). – Nico Zhu Aug 13 '19 at 14:06
  • @NicoZhu-MSFT Thank you! – Matthias Duyck Aug 13 '19 at 14:12
  • @MatthiasDuyck, Thanks for reporting this issue. Could you please report this issue in your Windows 10 Feedback Hub and share the link in here? In this way you can monitor the status of this issue and our engineering team can get the diagnostics trace as well. – Amy Peng - MSFT Aug 15 '19 at 07:02
  • In another thread where [preview does not always show](https://stackoverflow.com/questions/57290614/uwp-barcodescanner-preview-captureelement-doesnt-show-any-preview) it was finally root caused to be caused by threat protection software which prevents 'some' apps for using the camera, depending on settings. – Tom Kennard Aug 15 '19 at 15:21
  • Other things mediaCapture apps might have issues with: Check the Privacy settingsy: Settings -> Privacy -> Camera. In the app, try to open the camera with SharingMode = MediaCaptureSharingMode.SharedReadOnly, In the app, reduce consent prompts: StreamingCaptureMode = StreamingCaptureMode.Video Try other commons apps to troubleshoot: Camera-App, or [JustScanIt](https://aka.ms/JustScanIt) – Tom Kennard Aug 15 '19 at 15:34
  • @AmyPeng-MSFT I can personally not reproduce the issue, as I have no Windows Hello or depth camera on any of my devices. So I don't think I can run a diagnostics trace, right? – Matthias Duyck Aug 16 '19 at 08:09
  • @TomKennard I doubt it is the issue, as one user with a surface go that seems quite technically capable has shown me he has given camera access to the app... I added a device with a Windows Hello camera to the list of working devices, so my hypothesis is might be incorrect that it is purely due to these fancy camera's. – Matthias Duyck Aug 20 '19 at 08:59

0 Answers0