-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] Implement Microsoft Media Foundation on camera_win.cpp
#44498
base: 3.x
Are you sure you want to change the base?
Conversation
proof of concept for webcam on ms windows
set attribute to prevent shudown
formatting changes
This looks really good at first glance, thanks ! I get why some of the stuff is all done within the CPP source file while it should really be split into a header file I can see that can be an issue with some of the MF stuff. This won't work on the master branch because the camera server at it's heart is still very much based on OpenGL, That said if this all works fine and has its rough sides polished a bit we should merge it into master even if disabled so we can make it all work on both OpenGL and Vulkan renderers. Definitely would suggest getting the logic to work to detect when cameras are attached after Godot has started running. |
} | ||
|
||
void TransformImage_YUY2( | ||
BYTE *pDest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the MacOS camera stuff I made a shader that can handle YUV so we didn't need to do conversions on the CPU side. Is it worth looking at this further and adding YUY2 support as well or does it make more sense to have this RGB conversion in?
I believe there is a conversion library already linked in as a 3rd party module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't seem to find the conversion library, but found some reference code to do it within MF itself. Curious why the provided sample files didn't use them. Going to implement them.
if (SUCCEEDED(hr)) { | ||
hr = pAttributes->SetUINT32(MF_SOURCE_READER_DISCONNECT_MEDIASOURCE_ON_SHUTDOWN, TRUE); | ||
if (FAILED(hr)) { | ||
printf("Set attribute (disable shutdown on disconnect) failed\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking but it is better to use Godots internal print methods so the messages get locked to the log in the editor. You can also switch between what is considered info and what is actually an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. i am going to do some tidying up as well.
}; | ||
|
||
CameraWindows::CameraWindows() { | ||
// Find cameras active right now | ||
HRESULT hr = MFStartup(MF_VERSION); | ||
add_active_cameras(); | ||
|
||
// need to add something that will react to devices being connected/removed... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we should add logic that ensures we detect cameras being connected or disconnected to the PC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an existing mechanism - the one used by the joypad to detect hotplug hardware - using WM_DEVICECHANGE - but it seems it's going to touch a lot of other files so I'll leave it for some other time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left a few remarks for improvements, I hope others have some time to put this through its paces, but it looks good enough to me for a first version on which we can improve.
@choonway Please, merge commits together as required by our pipeline (https://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#modifying-a-pull-request) |
@BastiaanOlij There is also a bug with the R and B swapped. Give me a few days to implement the changes. |
@choonway Hey, are you still working on this? |
71cb8d3
to
c58391c
Compare
this is because
The problem with For joypad, this is directly handled by godot/platform/windows/os_windows.cpp Lines 1147 to 1149 in 5600be9
godot/platform/windows/display_server_windows.cpp Lines 3186 to 3188 in 20d6672
but We could maybe introduce a signal to solve this |
Wanted to try this out, but trying to compile: https://github.com/godotengine/godot/tree/23e3ce8d8724ee3965dceeed3fc5bbbc84793083
I tried adding the changes to |
@KnightNine Can you test this? I tried this last year.But I can't remember if I tested the #49763 or this. The conversion shader from yuv to rgb is used. |
@saierXP Your shader was probably meant to work with this PR which I can't get the CbCr feed from. so it only appears in monocolor. thus this shader works with 49763: shader_type canvas_item;
uniform sampler2D camera;
void fragment() {
vec3 color;
color.rgb = texture(camera, UV).rgb;
COLOR = vec4(color,1.0);
} |
camera_win.cpp
Is there interest in migrating this to godot engine master 4? I am also investigating video playback. |
camera_win.cpp
camera_win.cpp
Proof of concept for webcam on windows on media foundation based on their examples (MFCaptureD3D)
quality is Frankenstein.
not able to test on master branch due to bugs (texture related?)
test files can be obtained from https://github.com/choonway/godot-camera_win-test
tested to work on camera on HTC Vive.
If camera can't be accessed by camera app on windows, chances are that it won't work.
limitations:
virtual cameras and some webcams don't work (HTC Vive Pro Eye cameras)
hotplug not working/implemented