Skip to content
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

[RSDK-9538] - Throttle frame fetches by configured framerate #30

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

seanavery
Copy link
Collaborator

@seanavery seanavery commented Dec 13, 2024

Description

This PR simply adds a ticker throttle based on the specified framerate to the fetchFrames routine to prevent over-polling of the source camera. See ticket here for analysis.

Tests

  • Verify that fetchFrames is now throttled to framerate ✅
-16T16:39:17.463Z"}
2024-12-16T16:39:18.454Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.18      {"log_ts":"2024-12-16T16:39:18.451Z"}
2024-12-16T16:39:19.463Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.03      {"log_ts":"2024-12-16T16:39:19.461Z"}
2024-12-16T16:39:20.416Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 18.97      {"log_ts":"2024-12-16T16:39:20.411Z"}
2024-12-16T16:39:21.362Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.00      {"log_ts":"2024-12-16T16:39:21.360Z"}
2024-12-16T16:39:22.359Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.08      {"log_ts":"2024-12-16T16:39:22.357Z"}
2024-12-16T16:39:23.351Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.23      {"log_ts":"2024-12-16T16:39:23.349Z"}
2024-12-16T16:39:24.348Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.28      {"log_ts":"2024-12-16T16:39:24.346Z"}
2024-12-16T16:39:25.315Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 18.94      {"log_ts":"2024-12-16T16:39:25.312Z"}
2024-12-16T16:39:26.302Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.21      {"log_ts":"2024-12-16T16:39:26.300Z"}
2024-12-16T16:39:27.300Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.24      {"log_ts":"2024-12-16T16:39:27.298Z"}
2024-12-16T16:39:28.298Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.26      {"log_ts":"2024-12-16T16:39:28.297Z"}
2024-12-16T16:39:29.313Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.04      {"log_ts":"2024-12-16T16:39:29.310Z"}
2024-12-16T16:39:30.308Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.09      {"log_ts":"2024-12-16T16:39:30.306Z"}
2024-12-16T16:39:31.312Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.05      {"log_ts":"2024-12-16T16:39:31.309Z"}
2024-12-16T16:39:32.272Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 18.80      {"log_ts":"2024-12-16T16:39:32.270Z"}
2024-12-16T16:39:33.257Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.30      {"log_ts":"2024-12-16T16:39:33.256Z"}
2024-12-16T16:39:34.249Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.26      {"log_ts":"2024-12-16T16:39:34.247Z"}
2024-12-16T16:39:35.247Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.29      {"log_ts":"2024-12-16T16:39:35.246Z"}
2024-12-16T16:39:36.242Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.39      {"log_ts":"2024-12-16T16:39:36.241Z"}
2024-12-16T16:39:37.258Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.11      {"log_ts":"2024-12-16T16:39:37.256Z"}
2024-12-16T16:39:38.261Z        INFO    rdk:component:camera/video-store        cam/cam.go:376  Current FPS: 19.05      {"log_ts":"2024-12
  • Verify decreased CPU utilization with smaller 240p frame size stream ✅
ffmpeg -re -f lavfi -i testsrc=size=360x240:rate=30 -vcodec libx264 -pix_fmt yuv420p -f rtsp -rtsp_transport tcp rtsp://0.0.0.0:8554/live.stream
Screenshot 2024-12-16 at 11 56 56 AM Screenshot 2024-12-16 at 11 54 34 AM

@seanavery seanavery changed the title Throttle frame fetches by configured framerate [RSDK-9538] - Throttle frame fetches by configured framerate Dec 13, 2024
@seanavery seanavery requested a review from hexbabe December 16, 2024 16:59
Copy link
Collaborator

@hexbabe hexbabe left a comment

Choose a reason for hiding this comment

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

LGTM!

cam/cam.go Outdated
@@ -337,25 +337,28 @@ func (vs *videostore) Properties(_ context.Context) (camera.Properties, error) {
// in the latestFrame atomic pointer. This routine runs as fast as possible
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks!

@seanavery seanavery merged commit b06d495 into viam-modules:main Dec 16, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants