Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions doc/classes/CameraServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@
<member name="monitoring_feeds" type="bool" setter="set_monitoring_feeds" getter="is_monitoring_feeds" default="false">
If [code]true[/code], the server is actively monitoring available camera feeds.
This has a performance cost, so only set it to [code]true[/code] when you're actively accessing the camera.
[b]Note:[/b] After setting it to [code]true[/code], you can receive updated camera feeds through the [signal camera_feeds_updated] signal.
[codeblocks]
[gdscript]
func _ready():
CameraServer.camera_feeds_updated.connect(_on_camera_feeds_updated)
CameraServer.monitoring_feeds = true

func _on_camera_feeds_updated():
var feeds = CameraServer.feeds()
[/gdscript]
[csharp]
public override void _Ready()
{
CameraServer.CameraFeedsUpdated += OnCameraFeedsUpdated;
CameraServer.MonitoringFeeds = true;
}

void OnCameraFeedsUpdated()
{
var feeds = CameraServer.Feeds();
}
[/csharp]
[/codeblocks]
</member>
</members>
<signals>
Expand All @@ -64,6 +87,11 @@
Emitted when a [CameraFeed] is removed (e.g. a webcam is unplugged).
</description>
</signal>
<signal name="camera_feeds_updated">
<description>
Emitted when camera feeds are updated.
</description>
</signal>
</signals>
<constants>
<constant name="FEED_RGBA_IMAGE" value="0" enum="FeedImage">
Expand Down
1 change: 1 addition & 0 deletions modules/camera/camera_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ void CameraAndroid::update_feeds() {
}

ACameraManager_deleteCameraIdList(cameraIds);
emit_signal(SNAME(CameraServer::feeds_updated_signal_name));
}

void CameraAndroid::remove_all_feeds() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should the signal also be fired when all the feeds are removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cameraIds is a temporary variable within this function to receive camera IDs from ACameraManager_getCameraIdList(). ACameraManager_deleteCameraIdList() releases that variable. Since we updated the camera feed before that point, we need to emit the feeds_updated signal.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if this answered @m4gr3d's question

Expand Down
1 change: 1 addition & 0 deletions modules/camera/camera_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void CameraLinux::_update_devices() {
free(devices);
}

call_deferred("emit_signal", SNAME(CameraServer::feeds_updated_signal_name));
usleep(1000000);
}
}
Expand Down
1 change: 1 addition & 0 deletions modules/camera/camera_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ - (void)dealloc {
add_feed(newfeed);
};
};
emit_signal(SNAME(CameraServer::feeds_updated_signal_name));
}

void CameraMacOS::set_monitoring_feeds(bool p_monitoring_feeds) {
Expand Down
1 change: 1 addition & 0 deletions servers/camera_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void CameraServer::_bind_methods() {

ADD_SIGNAL(MethodInfo("camera_feed_added", PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo("camera_feed_removed", PropertyInfo(Variant::INT, "id")));
ADD_SIGNAL(MethodInfo(feeds_updated_signal_name));

BIND_ENUM_CONSTANT(FEED_RGBA_IMAGE);
BIND_ENUM_CONSTANT(FEED_YCBCR_IMAGE);
Expand Down
1 change: 1 addition & 0 deletions servers/camera_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CameraServer : public Object {
};

typedef CameraServer *(*CreateFunc)();
static inline constexpr const char feeds_updated_signal_name[] = "camera_feeds_updated";

private:
protected:
Expand Down
Loading