VPLAY-11126 [AAMP TSB] TsbReader waits for fragments in a tight loop#1093
VPLAY-11126 [AAMP TSB] TsbReader waits for fragments in a tight loop#1093hthakkar-synamedia wants to merge 1 commit intosupport/2.9.0_8.3_vipafrom
Conversation
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
There was a problem hiding this comment.
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 |
|
|
||
| UnlockReadMutex(); | ||
|
|
||
| if (mediatype == eMEDIATYPE_VIDEO) |
There was a problem hiding this comment.
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.
| 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) |
| } | ||
| else | ||
| { | ||
| AAMPLOG_WARN("No segment found for rate <= AAMP_NORMAL_PLAY_RATE"); |
There was a problem hiding this comment.
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.
| 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); |
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