WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

CameraPreview control not working on WinUI 3

Open LeoCarriere opened this issue 2 years ago • 11 comments

Describe the bug

The Problem :

CameraPreview from CommunityToolkit.WinUI.UI.Controls ( which I managed to make it work perfectly fine under UWP on the same computer ) is unable to show frames from the camera.

Output from Debug :

When the StartAsync() method is initiated I get multiple instance of the following error ( see screenshots section ) : avcore\mf\frameserver\fsutils\fsutils.cpp(362)\MFSENSORGROUP.dll!5F640094: (caller: 5F61190D) ReturnHr(1) tid(49e4) 80070490 Element not found.

avcore\mf\frameserver\fsutils\fsutils.cpp(639)\MFSENSORGROUP.dll!5F640610: (caller: 5F613F90) ReturnHr(4) tid(49e4) 80070002 The system cannot find the file specified.

Regression

No response

Reproducible in sample app?

  • [ ] This bug can be reproduced in the sample app.

Steps to reproduce

You can directly try yourself by using the public repositories i created :
- WinUI version (not working) : https://github.com/LeoCarriere/CameraPreviewTestWinUI
- UWP version (working): https://github.com/LeoCarriere/CameraPreviewTestUWP

The steps I followed:
- create a blank app from WinUI template using Visual Studio Community 2022 (17.2.3)
- Install the toolkit using the following article : https://devblogs.microsoft.com/ifdef-windows/windows-community-toolkit-for-project-reunion-0-5/ with of curse all Microsoft.Toolkit.Uwp.* renamed to be CommunityToolkit.WinUI.* .
- Add a Button and a CameraPreview
- Add a function to start the camera preview on the click of the button

Expected behavior

Get a frame like the uwp control (see the screenshot section)

Screenshots

WinUI version of the app output (not working) :

error

UWP version of the app output (working):

UWP

Windows Build Number

  • [ ] Windows 10 1809 (Build 17763)
  • [ ] Windows 10 1903 (Build 18362)
  • [ ] Windows 10 1909 (Build 18363)
  • [ ] Windows 10 2004 (Build 19041)
  • [ ] Windows 10 20H2 (Build 19042)
  • [ ] Windows 10 21H1 (Build 19043)
  • [X] Windows 11 21H2 (Build 22000)
  • [ ] Other (specify)

Other Windows Build number

No response

App minimum and target SDK version

  • [X] Windows 10, version 1809 (Build 17763)
  • [ ] Windows 10, version 1903 (Build 18362)
  • [ ] Windows 10, version 1909 (Build 18363)
  • [ ] Windows 10, version 2004 (Build 19041)
  • [ ] Other (specify)

Other SDK version

No response

Visual Studio Version

No response

Visual Studio Build Number

No response

Device form factor

No response

Nuget packages

  • CommunityToolkit.WinUI (7.1.2)
  • CommunityToolkit.WinUI.UI.Controls (7.1.2)
  • Microsoft.Windows.SDK.BuildTools (10.0.22000.197)
  • Microsoft.WindowsAppSDK (1.1.0)

Additional context

Attempt to fix it :

After some research I came to the understanding that MFSENSORGROUP.dll is from the Microsoft Media Foundation or Media Feature Pack.

So I updated Windows and check for integrety of the system to see if it was a problem with my own computer / version of windows, This attempt did not fix the problem. cmd

I also did a quick search on my C: drive ( were the OS is installed ) and found many instance of the mfsensorgroup.dll so maybe the CommunityToolkit use a wrong path to find the dll. DLLsearch

Looking forward for any help, thank you ! 😊

Help us help you

Yes, I'd like to be assigned to work on this item.

LeoCarriere avatar Jun 13 '22 10:06 LeoCarriere

Hello LeoCarriere, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Jun 13 '22 10:06 ghost

Hello @LeoCarriere , thanks for the report. Unfortunately, this is a known issue, as the CameraPreview control depends on MediaPlayerElement, which is still not supported on WinUI3. Not sure if it will make it into WAS 1.2, but maybe @andrewleader knows?

azchohfi avatar Jun 13 '22 18:06 azchohfi

@marb2000 is the person to ask for WinAppSDK

andrewleader avatar Jun 13 '22 18:06 andrewleader

We are still closing the engineering plan for 1.2. Media player is part of the plan, but we can't commit it yet.

marb2000 avatar Jun 13 '22 21:06 marb2000

Thank you for your fast response, I im impatient to see the next update then.

LeoCarriere avatar Jun 14 '22 06:06 LeoCarriere

Hello, it's been a year, with last WinAppSDK version being 1.3.3 (1.3.230724000) and I believe that the MediaPlayerElement has been added. Windows App SDK Version 1.2 :

WinUI 3 apps can play audio and video with the MediaPlayerElement and MediaTransportControls media playback controls. For more info on how and when to use media controls, see Media players.

I just tried to run some similar apps freshly created, but I still run into the same issue. Since then, we have made the choice to develop our app with WPF and some FFMPEG / FFPlay wizardry to make it work.

I'm interested if you have some updates on the topic @azchohfi @andrewleader.

LeoCarriere avatar Aug 02 '23 06:08 LeoCarriere

@LeoCarriere We have been working on the 8.0 release of the Toolkit, which included a major revamp of our infrastructure so that we can release packages for WinUI, UWP and Uno out of a single code base - without maintaining multiple branches.

We have ported over CameraPreview as well - making use of WASDK 1.3: https://github.com/CommunityToolkit/Windows/tree/main/components%2FCameraPreview

Would you mind trying adding the CommunityToolkit.WinUI.Controls.CameraPreview package to see if that resolves your issue? (It requires to add the preview nuget feed, see the main readme)

niels9001 avatar Aug 02 '23 07:08 niels9001

Hey @niels9001 I figured out how to add the NuGet feed to package source from the new repository (aka https://github.com/CommunityToolkit/Windows/tree/main). Now when I fire CameraPreviewControl.StartAsync() I can see few frames of the webcam for less than a second then video feed freeze.

https://github.com/CommunityToolkit/WindowsCommunityToolkit/assets/45718362/a7de6516-1589-40ca-a0b0-b439fc0bdd7e

I confess that I am a bit confuse about the multiple packages sources. I might have done something wrong or it's related to WindowsAppSDK. Here is a glance of my .csproj :

<ItemGroup>
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.3.230724000" />
    <PackageReference Include="CommunityToolkit.WinUI.Controls.CameraPreview" Version="8.0.230801-preview" />
    <Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

I also have a warning message in Visual Studio's Error List :

Warning		DEP0840: Project 'App2' requires packages 'MicrosoftCorporationII.WinAppRuntime.Main.1.3_8wekyb3d8bbwe' and 'MicrosoftCorporationII.WinAppRuntime.Singleton_8wekyb3d8bbwe' with version >= '3000.934.1904.0'. These packages should be installed on first run, if not please visit http://go.microsoft.com/fwlink/?linkid=2222757 for installation instructions.	App2		

(This is probably not relevent nowadays but I didn't find out how to add <DeviceCapability Name="webcam"/> in the manifest file like you would on UWP)

LeoCarriere avatar Aug 02 '23 09:08 LeoCarriere

Seems to be related to a platform bug :(..

https://github.com/microsoft/WindowsAppSDK/issues/2774#issuecomment-1624399099

niels9001 avatar Aug 02 '23 11:08 niels9001

Thank you @niels9001 I'll stay tuned.

LeoCarriere avatar Aug 02 '23 11:08 LeoCarriere

I believe this is an issue with WCT’s CameraHelper rather than a platform bug. My comments here elaborate.

BreeceW avatar Mar 18 '24 04:03 BreeceW