feat(webcam): Implement threaded streaming for high FPS#2
Conversation
This commit completely overhauls the webcam functionality to provide a much smoother, higher frame-rate live stream. Previously, each request for `cam.jpg` would open the camera device, capture a single frame, and then close the device. This process was extremely slow, resulting in a frame rate of less than 1 FPS and causing unnecessary wear on the flash storage. The new implementation introduces a background thread for continuous capture: - A dedicated pthread is spawned on the first request to the webcam page. - This thread keeps the camera device open and continuously captures frames into `/tmp/cam.jpg` (a RAM disk), significantly reducing latency and eliminating flash writes. - The thread automatically terminates and releases the camera if no new web requests are received within a 2-second timeout. - The frontend refresh interval has been reduced from 2000ms to 125ms, enabling a frame rate of ~8 FPS. To support this new model, the webcam C API was refactored: - `v_capture_image` is replaced by `v_open_camera`, `v_capture_frame_to_file`, and `v_close_camera` for more granular control over the device state. Additionally, a minor fix was made to the config parser to include the file path in the "cannot read" error message.
|
Thanks for the contribution! This project is no longer a priority and it is used exactly as it was designed to be used: when the printer is in the basement from time to time to see visually if there is a printing issue and when the print is done. Never needed more than 1fps because we experienced a lot of issues with complex print jobs when loading the CPU or using more than the minimum possible RAM. Only highly optimized minimal version was able to survive in parallel. We stopped many extension projects because of that weak hardware that is barely keep working with just printing in some cases. The same is for the resolution, limited to the minimum that is still good but not getting too much resources. But if someone reduces a lot of the print speed searching for quality prints, or use very simple print jobs, then yes, the frame rate (and/or the resolution) can be increased. |
Overhauls the webcam functionality to provide a much smoother, higher frame-rate live stream.
Previously, each request for
cam.jpgwould open the camera device, capture a single frame, and then close the device. This process was extremely slow, resulting in a frame rate of less than 1 FPS and causing unnecessary wear on the flash storage.The new implementation introduces a background thread for continuous capture:
/tmp/cam.jpg(a RAM disk), significantly reducing latency and eliminating flash writes.To support this new model, the webcam C API was refactored:
v_capture_imageis replaced byv_open_camera,v_capture_frame_to_file, andv_close_camerafor more granular control over the device state.