microsoft / Windows-Camera

Tools and samples for camera related APIs on Windows
MIT License
217 stars 69 forks source link

AugmentedMediaSource not work #29

Closed comor86 closed 2 years ago

comor86 commented 2 years ago

The simpleMediaSource and HWMediaSource work well on my computer. But with AugmentedMediaSource, I have tried many times, like using UWP, using Installer, changing some codes, and virtual camera can be created,but no image shown in preview or CameraApp. When I select the AugmentedMediaSource option, the Installer will crash and UWP reports an unspecified error. the CameraApp also reports an error.

image

image

comor86 commented 2 years ago

For clean show, I changed some log code. and crash log like below. image

LPBourret commented 2 years ago

Hi, yes I see the issue, as you can see in the trace, AugmentedMediaStream::Initialize() will filter through the set of MediaTypes exposed on the source you want to wrap and will keep only the one it can understand (i.e. in this case NV12 MediaTypes below 1080p at max 30fps. Problem is that first this routine runs on the client side and I assume your USB camera exposes MJPEG MediaTypes.. which FrameServer duplicates as well as NV12 MediaTypes (decode on the fly. However, when the virtual camera is then created on the frame server side, it does not have access to those MJPEG->NV12 MediaTypes and does not find any other compliant MediaType on any pin of the camera and fails to expose a stream.. (0xc00d36b4 == MF_E_INVALIDMEDIATYPE). There are a couple of things you can do to accommodate your camera in Windows 11 build 22000, although note that in the next release of Windows 11 there will be a new API to avoid this problem entirely..

You could accept MJPEG MediaType to go through in AugmentedMediaStream::Initialize() (and expose them out as NV12 MediaTypes) and insert a MJPEG decoder to decode samples on the fly on your own (see IMFTransform https://docs.microsoft.com/en-us/windows/win32/medfound/basic-mft-processing-model?redirectedfrom=MSDN

I think we need to provide a sample to do this anyway and I will take it as an action item

comor86 commented 2 years ago

Thanks very much for the email to guide me fix this, I've made this work. https://github.com/comor86/Windows-Camera