Skip to content

Conversation

wafgo
Copy link

@wafgo wafgo commented Aug 13, 2025

Previously, a new buffer pool was allocated for every received frame-sized package. This led to several critical issues:

  • Excessive memory consumption: H264 frames have large variations in size, causing significant memory usage over time.

  • File descriptor leaks: Each invocation of gstreamer::BufferPool::new() created a new socketpair, resulting in a steady increase in open file descriptors. This can be observed with:

    watch -n1 "ls -l /proc/PID/fd | wc -l"

    Over time, this would exhaust available file descriptors.

  • Application instability: On devices such as the Lumus cam, memory usage would continuously rise (over 7-8GiB after 5 hours), eventually leading to a crash.

This commit resolves these issues by reusing buffer pools where possible and preventing unnecessary allocation of resources. This allocates a little bit too much memory for the frames, as it takes the next power of two for the buffer, but its worth it to stabilize the application

Tested-by: Wadim Mueller [email protected]

Previously, a new buffer pool was allocated for every received frame-sized package. This led to several critical issues:

- Excessive memory consumption: H264 frames have large variations in size, causing significant memory usage over time.
- File descriptor leaks: Each invocation of `gstreamer::BufferPool::new()` created a new socketpair, resulting in a steady increase in open file descriptors. This can be observed with:

  watch -n1 "ls -l /proc/<PID>/fd | wc -l"

  Over time, this would exhaust available file descriptors.

- Application instability: On devices such as the Lumus cam, memory usage would continuously rise (over 7-8GiB after 5 hours), eventually leading to a crash.

This commit resolves these issues by reusing buffer pools where
possible and preventing unnecessary allocation of resources. This
allocates a little bit too much memory for the frames, as it takes the
next power of two for the buffer, but its worth it to stabilize the application

Tested-by: Wadim Mueller <[email protected]>
@jmoney7823956789378
Copy link

Seems like even the max buffer isnt large enough for some 4K cameras, as it filled instantly and still was unable to stream. I have 16 of them though, so maybe my use-case is an outlier.

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.

4 participants