Skip to content

VPAAMP-205 eliminate recursion and other concerns in HandleSeekEOSAndPeriodTransition#1365

Merged
pstroffolino merged 9 commits into
dev_sprint_25_2from
feature/VPAAMP-205
Apr 28, 2026
Merged

VPAAMP-205 eliminate recursion and other concerns in HandleSeekEOSAndPeriodTransition#1365
pstroffolino merged 9 commits into
dev_sprint_25_2from
feature/VPAAMP-205

Conversation

@pstroffolino
Copy link
Copy Markdown
Contributor

@pstroffolino pstroffolino commented Apr 27, 2026

Reason for Change: HandleSeekEOSAndPeriodTransition() performs a recursive call back into SeekInPeriod(). If a seek remainder spans many periods, this can recurse once per period and risks unnecessary stack growth.

Risk: Low

Test Guidance: requires basic regression-only, but may want to consider having the developer generate a new stress test.

@pstroffolino pstroffolino requested a review from a team as a code owner April 27, 2026 16:47
@pstroffolino pstroffolino requested a review from Copilot April 27, 2026 17:09
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 PR removes recursive period-by-period seek handling in SeekInPeriod() for DASH MPD playback by introducing an iterative loop and a helper to perform period transitions, reducing stack-growth risk when seeks span many periods.

Changes:

  • Added HandleSeekEOSAndPeriodTransition() to switch to the next playable period when a seek crosses a period boundary.
  • Refactored SeekInPeriod() to an iterative loop that repeatedly skips fragments and advances periods until the seek remainder is consumed or no further periods exist.
  • Added a new functional test to validate that mFirstPTS updates correctly when a seek crosses from one period to the next.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
fragmentcollector_mpd.cpp Introduces the period-transition helper and refactors SeekInPeriod() from recursive-style behavior to an iterative loop.
fragmentcollector_mpd.h Declares the new HandleSeekEOSAndPeriodTransition() helper.
test/utests/tests/StreamAbstractionAAMP_MPD/FunctionalTests.cpp Adds a test wrapper class and a new test covering SeekInPeriod() across two periods.

Comment thread fragmentcollector_mpd.cpp
Comment thread fragmentcollector_mpd.cpp Outdated
Comment thread test/utests/tests/StreamAbstractionAAMP_MPD/FunctionalTests.cpp
Comment thread test/utests/tests/StreamAbstractionAAMP_MPD/FunctionalTests.cpp Outdated
Comment thread fragmentcollector_mpd.h
Comment thread fragmentcollector_mpd.cpp
Comment thread fragmentcollector_mpd.cpp
@pstroffolino pstroffolino changed the title Feature/vpaamp 205 VPAAMP-205 eliminate recession concerns in HandleSeekEOSAndPeriodTransition Apr 27, 2026
@pstroffolino pstroffolino force-pushed the feature/VPAAMP-205 branch 2 times, most recently from c9d1075 to 825e7e7 Compare April 27, 2026 17:43
@pstroffolino pstroffolino changed the title VPAAMP-205 eliminate recession concerns in HandleSeekEOSAndPeriodTransition VPAAMP-205 eliminate recursion and other concerns in HandleSeekEOSAndPeriodTransition Apr 27, 2026
Convert SeekInPeriod from a recursive design into an iterative while-loop.
HandleSeekEOSAndPeriodTransition now only handles the period state transition
and returns true/false; SeekInPeriod drives the loop, calling SkipFragments
and HandleSeekEOSAndPeriodTransition until no further period transition is
needed or no playable period remains.

This eliminates the theoretical unbounded stack growth that arose when a seek
remainder spanned multiple consecutive short periods.
…sition/SeekInPeriod

1. Add 'enabled' guard to EOS check (HandleSeekEOSAndPeriodTransition)
   A disabled/unselected track (e.g. alternate audio, subtitle when off)
   may carry stale eos=true from a prior operation and must not trigger a
   spurious period transition. Guard with mMediaStreamContext[i]->enabled,
   matching the established pattern used throughout fragmentcollector_mpd.cpp.

2. Capture remaining seek from primary video track only (SeekInPeriod)
   The subtitle SkipFragments call omits skipToEnd and can return a different
   remainder than A/V. Since subtitle is last in the loop (VIDEO=0, AUDIO=1,
   SUBTITLE=2), it previously overwrote trackRemainingSeek on every seek with
   subtitles active, driving incorrect period transitions and carry-over offsets.
   Now: subtitle result is discarded; trackRemainingSeek is set from video, or
   from the first enabled non-subtitle track if video is absent.

3. Save/restore period state around UpdateTrackInfo (HandleSeekEOSAndPeriodTransition)
   Five members (mCurrentPeriodIdx, mCurrentPeriod, mBasePeriodId,
   mPeriodStartTime/Duration/EndTime) were mutated before UpdateTrackInfo was
   called. On failure the object was left in a half-switched state (period index
   updated, track info not). Save the previous values and restore them on failure
   so the player remains in a consistent state.
pstroffolino and others added 7 commits April 27, 2026 14:49
…essage

- Replace 0.0-sentinel track selection with an explicit primaryCaptured
  flag so the first enabled non-subtitle track (video, else audio) is
  deterministically chosen as the period-transition remainder, avoiding
  ambiguity when the primary track legitimately returns 0.0.
- Replace NULL with nullptr in HandleSeekEOSAndPeriodTransition guard.
- Clarify log message: 'caller will re-run SkipFragments on the new
  period' instead of the misleading 'calling SkipFragments'.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…d/unused

skipToEnd is accepted for API consistency with SeekInPeriod and reserved
for future direction-aware empty-period handling, but is not read inside
the function body. Comment out the parameter name in the definition to
silence -Wunused-parameter without removing the parameter, and update the
Doxygen @param to explain the rationale.
@pstroffolino pstroffolino merged commit 7a344e6 into dev_sprint_25_2 Apr 28, 2026
10 checks passed
@pstroffolino pstroffolino deleted the feature/VPAAMP-205 branch April 28, 2026 17:51
DomSyna pushed a commit that referenced this pull request Apr 29, 2026
…PeriodTransition (#1365)

* VPAAMP-205 Eliminate recursion in HandleSeekEOSAndPeriodTransition

Reason for Change: Convert SeekInPeriod from a recursive design into an iterative while-loop.
HandleSeekEOSAndPeriodTransition now only handles the period state transition
and returns true/false; SeekInPeriod drives the loop, calling SkipFragments
and HandleSeekEOSAndPeriodTransition until no further period transition is
needed or no playable period remains.

This eliminates the theoretical unbounded stack growth that arose when a seek
remainder spanned multiple consecutive short periods.

* VPAAMP-205 Fix three correctness issues in HandleSeekEOSAndPeriodTransition/SeekInPeriod

1. Add 'enabled' guard to EOS check (HandleSeekEOSAndPeriodTransition)
   A disabled/unselected track (e.g. alternate audio, subtitle when off)
   may carry stale eos=true from a prior operation and must not trigger a
   spurious period transition. Guard with mMediaStreamContext[i]->enabled,
   matching the established pattern used throughout fragmentcollector_mpd.cpp.

2. Capture remaining seek from primary video track only (SeekInPeriod)
   The subtitle SkipFragments call omits skipToEnd and can return a different
   remainder than A/V. Since subtitle is last in the loop (VIDEO=0, AUDIO=1,
   SUBTITLE=2), it previously overwrote trackRemainingSeek on every seek with
   subtitles active, driving incorrect period transitions and carry-over offsets.
   Now: subtitle result is discarded; trackRemainingSeek is set from video, or
   from the first enabled non-subtitle track if video is absent.

3. Save/restore period state around UpdateTrackInfo (HandleSeekEOSAndPeriodTransition)
   Five members (mCurrentPeriodIdx, mCurrentPeriod, mBasePeriodId,
   mPeriodStartTime/Duration/EndTime) were mutated before UpdateTrackInfo was
   called. On failure the object was left in a half-switched state (period index
   updated, track info not). Save the previous values and restore them on failure
   so the player remains in a consistent state.

* VPAAMP-205 SeekInPeriod: use primaryCaptured flag, nullptr, fix log message

- Replace 0.0-sentinel track selection with an explicit primaryCaptured
  flag so the first enabled non-subtitle track (video, else audio) is
  deterministically chosen as the period-transition remainder, avoiding
  ambiguity when the primary track legitimately returns 0.0.
- Replace NULL with nullptr in HandleSeekEOSAndPeriodTransition guard.
- Clarify log message: 'caller will re-run SkipFragments on the new
  period' instead of the misleading 'calling SkipFragments'.

- skipToEnd is accepted for API consistency with SeekInPeriod and reserved
for future direction-aware empty-period handling, but is not read inside
the function body. Comment out the parameter name in the definition to
silence -Wunused-parameter without removing the parameter, and update the
Doxygen @param to explain the rationale.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Abhi-jith-S pushed a commit that referenced this pull request May 12, 2026
…PeriodTransition (#1365)

* VPAAMP-205 Eliminate recursion in HandleSeekEOSAndPeriodTransition

Reason for Change: Convert SeekInPeriod from a recursive design into an iterative while-loop.
HandleSeekEOSAndPeriodTransition now only handles the period state transition
and returns true/false; SeekInPeriod drives the loop, calling SkipFragments
and HandleSeekEOSAndPeriodTransition until no further period transition is
needed or no playable period remains.

This eliminates the theoretical unbounded stack growth that arose when a seek
remainder spanned multiple consecutive short periods.

* VPAAMP-205 Fix three correctness issues in HandleSeekEOSAndPeriodTransition/SeekInPeriod

1. Add 'enabled' guard to EOS check (HandleSeekEOSAndPeriodTransition)
   A disabled/unselected track (e.g. alternate audio, subtitle when off)
   may carry stale eos=true from a prior operation and must not trigger a
   spurious period transition. Guard with mMediaStreamContext[i]->enabled,
   matching the established pattern used throughout fragmentcollector_mpd.cpp.

2. Capture remaining seek from primary video track only (SeekInPeriod)
   The subtitle SkipFragments call omits skipToEnd and can return a different
   remainder than A/V. Since subtitle is last in the loop (VIDEO=0, AUDIO=1,
   SUBTITLE=2), it previously overwrote trackRemainingSeek on every seek with
   subtitles active, driving incorrect period transitions and carry-over offsets.
   Now: subtitle result is discarded; trackRemainingSeek is set from video, or
   from the first enabled non-subtitle track if video is absent.

3. Save/restore period state around UpdateTrackInfo (HandleSeekEOSAndPeriodTransition)
   Five members (mCurrentPeriodIdx, mCurrentPeriod, mBasePeriodId,
   mPeriodStartTime/Duration/EndTime) were mutated before UpdateTrackInfo was
   called. On failure the object was left in a half-switched state (period index
   updated, track info not). Save the previous values and restore them on failure
   so the player remains in a consistent state.

* VPAAMP-205 SeekInPeriod: use primaryCaptured flag, nullptr, fix log message

- Replace 0.0-sentinel track selection with an explicit primaryCaptured
  flag so the first enabled non-subtitle track (video, else audio) is
  deterministically chosen as the period-transition remainder, avoiding
  ambiguity when the primary track legitimately returns 0.0.
- Replace NULL with nullptr in HandleSeekEOSAndPeriodTransition guard.
- Clarify log message: 'caller will re-run SkipFragments on the new
  period' instead of the misleading 'calling SkipFragments'.

- skipToEnd is accepted for API consistency with SeekInPeriod and reserved
for future direction-aware empty-period handling, but is not read inside
the function body. Comment out the parameter name in the definition to
silence -Wunused-parameter without removing the parameter, and update the
Doxygen @param to explain the rationale.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
varatharajan568 pushed a commit that referenced this pull request May 20, 2026
…PeriodTransition (#1365)

* VPAAMP-205 Eliminate recursion in HandleSeekEOSAndPeriodTransition

Reason for Change: Convert SeekInPeriod from a recursive design into an iterative while-loop.
HandleSeekEOSAndPeriodTransition now only handles the period state transition
and returns true/false; SeekInPeriod drives the loop, calling SkipFragments
and HandleSeekEOSAndPeriodTransition until no further period transition is
needed or no playable period remains.

This eliminates the theoretical unbounded stack growth that arose when a seek
remainder spanned multiple consecutive short periods.

* VPAAMP-205 Fix three correctness issues in HandleSeekEOSAndPeriodTransition/SeekInPeriod

1. Add 'enabled' guard to EOS check (HandleSeekEOSAndPeriodTransition)
   A disabled/unselected track (e.g. alternate audio, subtitle when off)
   may carry stale eos=true from a prior operation and must not trigger a
   spurious period transition. Guard with mMediaStreamContext[i]->enabled,
   matching the established pattern used throughout fragmentcollector_mpd.cpp.

2. Capture remaining seek from primary video track only (SeekInPeriod)
   The subtitle SkipFragments call omits skipToEnd and can return a different
   remainder than A/V. Since subtitle is last in the loop (VIDEO=0, AUDIO=1,
   SUBTITLE=2), it previously overwrote trackRemainingSeek on every seek with
   subtitles active, driving incorrect period transitions and carry-over offsets.
   Now: subtitle result is discarded; trackRemainingSeek is set from video, or
   from the first enabled non-subtitle track if video is absent.

3. Save/restore period state around UpdateTrackInfo (HandleSeekEOSAndPeriodTransition)
   Five members (mCurrentPeriodIdx, mCurrentPeriod, mBasePeriodId,
   mPeriodStartTime/Duration/EndTime) were mutated before UpdateTrackInfo was
   called. On failure the object was left in a half-switched state (period index
   updated, track info not). Save the previous values and restore them on failure
   so the player remains in a consistent state.

* VPAAMP-205 SeekInPeriod: use primaryCaptured flag, nullptr, fix log message

- Replace 0.0-sentinel track selection with an explicit primaryCaptured
  flag so the first enabled non-subtitle track (video, else audio) is
  deterministically chosen as the period-transition remainder, avoiding
  ambiguity when the primary track legitimately returns 0.0.
- Replace NULL with nullptr in HandleSeekEOSAndPeriodTransition guard.
- Clarify log message: 'caller will re-run SkipFragments on the new
  period' instead of the misleading 'calling SkipFragments'.

- skipToEnd is accepted for API consistency with SeekInPeriod and reserved
for future direction-aware empty-period handling, but is not read inside
the function body. Comment out the parameter name in the definition to
silence -Wunused-parameter without removing the parameter, and update the
Doxygen @param to explain the rationale.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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