Skip to content

Conversation

@j20001970
Copy link
Contributor

Implement CameraFeedMacOS::set_format and CameraFeedMacOS::get_formats.

When activating the feed, if selected_format is specified, try locking the device to set active format for it, and unlocking the device upon deactivated.

@j20001970 j20001970 force-pushed the camera-format-macos branch 2 times, most recently from ab9927a to 19c603f Compare May 24, 2025 17:50
@j20001970 j20001970 marked this pull request as ready for review May 24, 2025 17:58
@j20001970 j20001970 requested a review from a team as a code owner May 24, 2025 17:58
@bruvzg bruvzg self-requested a review May 25, 2025 19:57
@AThousandShips AThousandShips added this to the 4.x milestone May 27, 2025
@j20001970 j20001970 force-pushed the camera-format-macos branch from 19c603f to 003c5ea Compare June 21, 2025 06:43
ERR_FAIL_INDEX_V((unsigned int)p_index, device.formats.count, false);
ERR_FAIL_COND_V_MSG(capture_session != nullptr, false, "Feed is active.");
selected_format = p_index;
emit_signal("format_changed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on when format_changed should be emitted, the Linux driver emits the signal whenever a format is selected:

parameters = p_parameters.duplicate();
selected_format = p_index;
emit_signal(SNAME("format_changed"));

while camera_feed.cpp emit the signal when current camera frame size is different from the previous. Could someone clarify that whether format_changed should be emitted as soon as a format is selected for the camera feed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the format_changed signal is emitted within set_ycbcr_images on the following line when the image size differs from the previous call, so combined with the call within set_format, it gets emitted twice per frame - we should choose one or the other. It's a dilemma which one should emit it, but I imagine what an app using CameraFeed would want to do when receiving the format_changed signal. Emitting from set_ycbcr_images allows receiving image data with the changed format. If emitted from set_format, there's a possibility that image data isn't available yet. Comparing these two, I think emitting from set_ycbcr_images would be better.
https://github.com/godotengine/godot/blob/master/modules/camera/camera_macos.mm#L185

@j20001970 j20001970 force-pushed the camera-format-macos branch 2 times, most recently from 94974b3 to 1487dfa Compare June 27, 2025 18:53
@j20001970 j20001970 force-pushed the camera-format-macos branch 2 times, most recently from 97939ae to a153d20 Compare July 6, 2025 14:02
@j20001970 j20001970 force-pushed the camera-format-macos branch 6 times, most recently from 1f82a8f to dd48972 Compare August 14, 2025 22:39
@j20001970 j20001970 force-pushed the camera-format-macos branch 7 times, most recently from ee2e1e7 to 310ccdc Compare August 22, 2025 04:46
@j20001970 j20001970 force-pushed the camera-format-macos branch 6 times, most recently from 0551489 to 6d9913a Compare September 25, 2025 14:26
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally on macOS 26 (MBP 16" 2024 with M4 Max), it works as expected.

However, some formats in the list look broken:

Image Image

The following formats have an appearance like this, with green diagonal lines and what seems to be an incorrect stride (the image does update, but looks skewed):

Image
  • 1760x1328
  • 1328x1760
  • 1552x1552
  • 1080x1920 (1920x1080 is fine)

@j20001970 j20001970 force-pushed the camera-format-macos branch 2 times, most recently from ae36848 to 30959dc Compare September 30, 2025 15:39
@j20001970
Copy link
Contributor Author

30959dc try to handle padded image data.

Please let me know if it fixes skewed image for some formats.

@j20001970 j20001970 force-pushed the camera-format-macos branch from 30959dc to 83c1d2f Compare October 1, 2025 02:29
@Calinou
Copy link
Member

Calinou commented Oct 2, 2025

30959dc try to handle padded image data.

Please let me know if it fixes skewed image for some formats.

Works great now 🙂 I can get all formats to display.

However, in https://github.com/shiena/godot-camerafeed-demo, switching formats occasionally leads to a black screen until I resize the window (the webcam display appears as a tiny square in the top-right corner). Sometimes, switching formats will still result in a black screen until I restart the project. No errors or warnings are printed in the output log. This is presumably a bug in the demo rather than in this PR though.

cc @shiena

@j20001970
Copy link
Contributor Author

I didn't take into account that camera feed format could change while activated (current implementation just remember selected format index to use before next feed activation), maybe there are still parts that can be improved.

@j20001970 j20001970 force-pushed the camera-format-macos branch from 83c1d2f to 76a317e Compare October 3, 2025 09:30
@j20001970
Copy link
Contributor Author

I didn't take into account that camera feed format could change while activated (current implementation just remember selected format index to use before next feed activation), maybe there are still parts that can be improved.

With 76a317e and shiena/godot-camerafeed-demo@a10d76c, camera feeds should be able to change format while still active.

The problem of disappeared camera preview after stopping and starting the feed without changing format seems to be caused by rotation of camera preview in godot-camerafeed-demo.

The last issue that I'm aware of is that, after changing feed format, it does not take effect immediately. On my machine with a USB webcam, camera feed still output a frame or two in previously configured format, even when camera feed is deactivated then activated again.

@j20001970 j20001970 force-pushed the camera-format-macos branch 6 times, most recently from 6447ccc to e3f15cf Compare October 8, 2025 14:47
@j20001970 j20001970 force-pushed the camera-format-macos branch 4 times, most recently from 32ad606 to fac938b Compare October 16, 2025 02:26
@j20001970 j20001970 force-pushed the camera-format-macos branch 2 times, most recently from 1a24340 to c1f9190 Compare October 26, 2025 08:59
@j20001970 j20001970 force-pushed the camera-format-macos branch from c1f9190 to f926356 Compare November 2, 2025 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants