Skip to content

Fix buffered packet removal order - #7966

Open
jantekb wants to merge 2 commits into
masterfrom
bugfix/packet-removal
Open

jantekb wants to merge 2 commits into
masterfrom
bugfix/packet-removal

Conversation

@jantekb

@jantekb jantekb commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What changed

  • Remove the first buffered packet from bufferQueue before writing it.
  • Use pollFirst() so removal and retrieval happen as one queue operation.
  • Guard against a null result before writing and unreferencing the packet.

Why

bufferQueue is a ConcurrentSkipListSet ordered by packet DTS. The previous code called writePacket() before removing the packet, but writePacket() mutates its DTS and PTS. Mutating the ordering key while the packet was still in the set could make remove() fail.

The stale packet was then unreferenced while remaining in the queue and processed repeatedly with AV_NOPTS_VALUE. This produced millions of repeated DTS messages, blocked stream cleanup, left the temporary MP4 file visible to the test, and generated a 1.6 GiB JUnit report that the report publisher could not parse as a Node.js string.

Impact

Buffered packets are now removed before their timestamps are changed, preventing stale packets from becoming stuck in the queue and allowing stream finalization to complete normally.

Validation

  • mvn -q -Dtest=io.antmedia.test.StreamFetcherUnitTest#testStreamFetcherBuffer test
  • git diff --check
  • The focused test passed and produced an approximately 100 KiB JUnit XML report with no repeated AV_NOPTS_VALUE DTS messages.

@jantekb
jantekb force-pushed the bugfix/packet-removal branch from 3394880 to 6589d76 Compare July 21, 2026 09:43
@jantekb
jantekb marked this pull request as ready for review July 21, 2026 11:19
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

1 participant