Skip to content

VPLAY-11126 [AAMP TSB] TsbReader waits for fragments in a tight loop#1093

Open
hthakkar-synamedia wants to merge 1 commit intosupport/2.9.0_8.3_vipafrom
feature/VPLAY-11126_8.3_vipa
Open

VPLAY-11126 [AAMP TSB] TsbReader waits for fragments in a tight loop#1093
hthakkar-synamedia wants to merge 1 commit intosupport/2.9.0_8.3_vipafrom
feature/VPLAY-11126_8.3_vipa

Conversation

@hthakkar-synamedia
Copy link
Copy Markdown
Contributor

Reason for Change: When TsbReader tries to read the fragments that are not downloaded yet by the FetcherLoop, it enters into a quick tight loop. Fix here implements producer consumer design and wait for a conditional variable until new fragment is available.

Test Procedure: - Refer Ticket

Risks:low

Reason for Change: When TsbReader tries to read the fragments that are
not downloaded yet by the FetcherLoop, it enters into a quick tight loop.
Fix here implements producer consumer design and wait for a conditional
variable until new fragment is available.

Test Procedure: - Refer Ticket

Risks:low
@hthakkar-synamedia hthakkar-synamedia requested a review from a team as a code owner February 26, 2026 17:29
Copilot AI review requested due to automatic review settings February 26, 2026 17:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements a producer-consumer pattern with condition variables to prevent the TsbReader thread from spinning in a tight loop when waiting for fragments that haven't been downloaded yet by the FetcherLoop. The change addresses the issue where TsbReader would continuously loop checking for new fragments, consuming CPU unnecessarily.

Changes:

  • Added condition variable synchronization mechanism to AampTSBSessionManager for signaling when new video TSB content is available
  • Modified AdvanceTsbFetch to return a boolean indicating whether a segment was found and cached
  • Updated TsbReader loop to wait on condition variable when no segments are available during fast-forward playback
  • Added notification in DisableDownloads to wake up waiting threads during shutdown

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
AampTSBSessionManager.h Added WaitForVideoTsbContentOrAbort and NotifyVideoTsbWaiters methods, added mNewVideoTsbContentCV condition variable and mStopWaitingForVideoTsb flag
AampTSBSessionManager.cpp Implemented wait/notify methods, initialized flag in Init(), added notification after writing video fragments in ProcessWriteQueue
fragmentcollector_mpd.h Changed AdvanceTsbFetch signature to return bool
fragmentcollector_mpd.cpp Implemented return value for AdvanceTsbFetch, modified TsbReader loop to track segmentFound and wait on condition variable when appropriate
priv_aamp.cpp Added NotifyVideoTsbWaiters call in DisableDownloads to unblock waiting threads during shutdown
test/utests/tests/FragmentCollectorMpdTests/FragmentCollectorMpdTestCases.cpp Updated tests to verify AdvanceTsbFetch return value
test/utests/tests/AampTsbSessionManagerTests_Mocked/FunctionalTests.cpp Added tests for NotifyVideoTsbWaiters and WaitForVideoTsbContentOrAbort functionality
test/utests/fakes/FakeTSBSessionManager.cpp Added empty stub implementations for new methods

Comment thread AampTSBSessionManager.cpp

UnlockReadMutex();

if (mediatype == eMEDIATYPE_VIDEO)
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

The notification is triggered for both init fragments and regular fragments without distinction. Init fragments cause NewInitWaiting to be set to true, which may prevent PushNextTsbFragment from caching content. When only an init fragment is written, the reader thread will wake up, find no cacheable content (segmentFound remains false), and immediately call WaitForVideoTsbContentOrAbort again. While functionally correct, this results in unnecessary wake-ups. Consider notifying only when regular (non-init) fragments are written, or ensure that the wait condition checks for actual consumable content availability.

Suggested change
if (mediatype == eMEDIATYPE_VIDEO)
// Notify video TSB waiters only when a non-init fragment is written,
// to avoid unnecessary wake-ups on init-only writes.
if (mediatype == eMEDIATYPE_VIDEO && !writeData.cachedFragment->initFragment)

Copilot uses AI. Check for mistakes.
Comment thread fragmentcollector_mpd.cpp
}
else
{
AAMPLOG_WARN("No segment found for rate <= AAMP_NORMAL_PLAY_RATE");
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

When no segment is found during normal playback (rate <= AAMP_NORMAL_PLAY_RATE), a warning is logged but the thread continues to loop without waiting. This differs from the fast-forward case where WaitForVideoTsbContentOrAbort is called to avoid a tight loop. While this may be intentional (as the warning suggests this is an unexpected condition), it could still result in a tight loop consuming CPU if this condition persists. Consider whether a similar wait mechanism or at least a small sleep should be applied to this case as well.

Suggested change
AAMPLOG_WARN("No segment found for rate <= AAMP_NORMAL_PLAY_RATE");
AAMPLOG_WARN("No segment found for rate <= AAMP_NORMAL_PLAY_RATE");
// Avoid a tight loop consuming CPU when no segment is found during normal playback
aamp->interruptibleMsSleep(50);

Copilot uses AI. Check for mistakes.
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