wpilibsuite / allwpilib

Official Repository of WPILibJ and WPILibC
https://wpilib.org/
Other
1.07k stars 613 forks source link

CameraServer: Expose number of clients #3984

Closed agasser closed 2 years ago

agasser commented 2 years ago

It would be useful if CameraServer exposed the number of clients connected to the server for streaming video.

In a Python image pipeline, there may be additional work to prepare each frame for streaming. For example, the image may need to be resized and have its color converted from RGB to BGR. If there are no clients for the CameraServer this additional processing can be skipped, potentially increasing FPS for the pipeline.

Streaming the video from the imaging pipeline would often be something useful in the shop for debugging, but not useful during a competition, when FPS matters most.

There are workarounds, such as using a NetworkTable entry to toggle streaming.

This CD post has additional detail: CameraServer - is anyone watching?

sciencewhiz commented 2 years ago

Do you actually need count or just if anyone is connected. See csSource.isEnabled()

https://www.chiefdelphi.com/t/cameraserver-is-anyone-watching/402008/6

agasser commented 2 years ago

I think csSource.isEnabled() would do the trick. It's missing from robotpy so I didn't see it. I created an issue over there. https://github.com/robotpy/robotpy-cscore/issues/111

PeterJohnson commented 2 years ago

As noted in that thread, while the exact number of clients is not exposed, VideoSource::IsEnabled() can be used to determine on the source side if there are 1 or more active clients.