Skip to content

Unexpected behavior after HLS media segment download timeout and switching to a lower variant #3362

Description

@sruditsky

Version

Media3 1.8.0

Description

We noticed that sometimes at the moment of the variant changing down the presentation timestamps of the samples pushed into the video decoder are repeating.

While investigating this the following 3 issues where found:

  1. Partial samples are not purged from the SampleQueue when a media chunk is excluded (root cause of "PTS going back")
    Potential location of the issue: HlsSampleStreamWrapper.onLoadError.
    Symptom: Renderer PTS goes back and sometimes the decoder is getting stuck

  2. Live playback rewinds live playback to the initial playback position.
    Potential location of the issue: HlsSampleStreamWrapper.onLoadError. pendingResetPositionUs = lastSeekPositionUs inside
    if (isMediaChunk && bytesLoaded == 0)
    Symptom: After a burst of network errors that empties mediaChunks, playback "skips back" by a significant amount (tens of minutes).

  3. the same segment (with the same variant) is being downloaded multiple times.
    Potential location of the issue: HlsChunkSource.getNextChunk, inside the upstream if (shouldForceKeepCurrentTrackSelection) branch.
    Symptom: During bad network conditions same segment URL is downloaded multiple times back to back on the just-blacklisted variant.

Devices that reproduce the issue

This was reproduced on a proprietary Android device, but it does not look like the specific device is important.

Devices that do not reproduce the issue

Not applicable

Reproducible in the demo app?

Not tested

Reproduction steps

1, Play live HLS stream with multiple video variants.

  1. Simulate a network problem that causes at least one video segment load to time out mid-transfer (RequestTimeoutException at ~10 s with bytesLoaded > 0).

Expected result

  • The playback continues and the video sample are queued into the decoder in the correct order of PTSs.
  • Each media segment in a particular variant is loaded only once.

Actual result

  • The PTS values sometimes jump back (sometimes by several seconds and sometimes by multiple minutes).
  • Sometimes the same variant of a specific video segment is downloaded multiple times.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions