Skip to content

Conversation

@drondeseries
Copy link
Contributor

feat: Implement client-specific cursors for shared streams

This commit fixes an issue where multiple clients watching the same stream would cause picture distortion and interruptions. The problem was that all clients were consuming from the same shared buffer, leading to data being missed by some clients.

To solve this, I implemented a client-specific cursor for each stream. This cursor is stored in Redis and tracks the last segment that each client has received. The getNextStreamSegments method in SharedStreamService was updated to use these cursors, ensuring that each client receives a complete and independent stream.

I also updated the removeClient method to clean up the client's cursor from Redis when they disconnect, and modified the BufferManagement job to clean up segments that have been consumed by all clients.

Fixes(cache): Ensure stream_key is always present in getAllActiveStreams
This commit fixes an 'Undefined array key "stream_key"' error that occurred when running the app:flush-ffmpeg-process-cache command. The error was caused by the getAllActiveStreams method in SharedStreamService not including the stream_key in the returned array when the stream_info from the database was null.

I have modified the getAllActiveStreams method to ensure that the stream_key is always present in the returned array, which resolves the issue.

Fix(streaming): Use posix_getpgid to detect running processes
This commit fixes an issue where active streams were being incorrectly identified as phantom streams. This was caused by the isProcessRunning method using shell_exec to check the process status, which was unreliable in some environments.

I have updated the isProcessRunning method to use the posix_getpgid function instead. This is a more reliable way to check if a process is running and should prevent the incorrect detection of phantom streams. I have also added a test case to verify the new implementation.

drondeseries and others added 8 commits July 13, 2025 16:29
fix: FFmpeg cleanup for shared streams using invalid key
feat: Add HLS bandwidth tracking
This commit fixes an issue where multiple clients watching the same stream would cause picture distortion and interruptions. The problem was that all clients were consuming from the same shared buffer, leading to data being missed by some clients.

To solve this, I implemented a client-specific cursor for each stream. This cursor is stored in Redis and tracks the last segment that each client has received. The `getNextStreamSegments` method in `SharedStreamService` was updated to use these cursors, ensuring that each client receives a complete and independent stream.

I also updated the `removeClient` method to clean up the client's cursor from Redis when they disconnect, and modified the `BufferManagement` job to clean up segments that have been consumed by all clients.

Fixes(cache): Ensure stream_key is always present in getAllActiveStreams
This commit fixes an 'Undefined array key "stream_key"' error that occurred when running the `app:flush-ffmpeg-process-cache` command. The error was caused by the `getAllActiveStreams` method in `SharedStreamService` not including the `stream_key` in the returned array when the `stream_info` from the database was null.

I have modified the `getAllActiveStreams` method to ensure that the `stream_key` is always present in the returned array, which resolves the issue.

Fix(streaming): Use posix_getpgid to detect running processes
This commit fixes an issue where active streams were being incorrectly identified as phantom streams. This was caused by the `isProcessRunning` method using `shell_exec` to check the process status, which was unreliable in some environments.

I have updated the `isProcessRunning` method to use the `posix_getpgid` function instead. This is a more reliable way to check if a process is running and should prevent the incorrect detection of phantom streams. I have also added a test case to verify the new implementation.
feat: Implement client-specific cursors for shared streams
This commit fixes an issue where the stream would terminate when the last client disconnected, causing interruptions for other clients that were about to connect.

The `removeClient` method in `SharedStreamService` was modified to no longer call `cleanupStream` immediately when the client count reaches zero. Instead, the `BufferManagement` job will now handle the cleanup of inactive streams.

The `cleanupStream` method was also modified to not remove the `client_cursors` key from Redis. This will ensure that the cursors are preserved for clients that reconnect.
fix: Prevent stream termination on client disconnect
…cific-cursors

Revert "fix: Prevent stream termination on client disconnect"
@sparkison sparkison merged commit c7ee491 into sparkison:experimental Jul 14, 2025
@drondeseries drondeseries deleted the dev branch July 16, 2025 00:35
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