[Dash:DefaultDashChunkSource]: Wrong segmentNumShift was calculated in copyWithNewRepresentation
[REQUIRED] Issue description
We are using AWS MediaPackager with Elemental for LIVE streaming, (etc, https://skysport3.akamaized.net/out/v1/686ec493b68042c7b943b4f55c95b867/index.mpd), by default the timeShiftBufferDepth="PT57.000S", we configured a 1800s availability window on the AWS MediaPackager, so that we could get MPD via somehing like https://skysport3.akamaized.net/out/v1/686ec493b68042c7b943b4f55c95b867/index.mpd?start=1569876612, which has timeShiftBufferDepth="PT1800.000S" with the start parameter. Somehow the AWS MediaPackager is not 100% stable, so when the ExoPlayer request the MPD with the start parameter, suppose it will return all the MPDs with timeShiftBufferDepth="PT1800.000S", but randomly rarely timeShiftBufferDepth="PT57.000S" instead.
Above is the background the reason lead to the wrong segmentNumShift problem.
The root cause: In DefaultDashChunkSource.copyWithNewRepresentation, it will handle the logic that new MPD manifest file is updated and calculate a newSegmentNumShift for furthermore segNum index calculation in getSegmentUrl, when a 57s MPD updated and then back to 1800s MPD, copyWithNewRepresentation will go into the overlap case. For example: When 57s MPD was updated:
10-02 11:19:54.451 24089 24089 D EventLogger: timelineChanged [30.75, 24.83, window=0, period=0, periodCount=1, windowCount=1, reason=DYNAMIC
10-02 11:19:54.451 24089 24089 D EventLogger: period [?]
10-02 11:19:54.451 24089 24089 D EventLogger: window [59.98, true, true]
10-02 11:19:54.451 24089 24089 D EventLogger: ]
10-02 11:19:55.652 24089 25278 D EventLogger: getNextChunk: previous: 193603
10-02 11:19:55.652 24089 25278 D EventLogger: getNextChunk: firstAvailableSegmentNum: 193595 lastAvailableSegmentNum: 193604 segmentNum: 193604
10-02 11:19:55.654 24089 25278 D EventLogger: getNextChunk: maxSegmentCount: 1 segmentNum: 193604
10-02 11:20:10.032 24089 25278 D EventLogger: copyWithNewRepresentation: oldIndexSegmentCount: 10
10-02 11:20:10.032 24089 25278 D EventLogger: copyWithNewRepresentation: oldIndex.getFirstSegmentNum(): 193595 newIndexFirstSegmentNum: 193306 // Here is the case that new_first < old_first, but go into overlap case
10-02 11:20:10.032 24089 25278 D EventLogger: copyWithNewRepresentation: segmentNumShift: 0 newSegmentNumShift: 289 // Here is the wrong SegmentNumShift
When 1800s MPD was updated:
10-02 11:20:10.035 24089 24089 D EventLogger: timelineChanged [46.33, 1774.44, window=0, period=0, periodCount=1, windowCount=1, reason=DYNAMIC
10-02 11:20:10.035 24089 24089 D EventLogger: period [?]
10-02 11:20:10.036 24089 24089 D EventLogger: window [1811.99, true, true]
10-02 11:20:10.036 24089 24089 D EventLogger: ]
10-02 11:20:11.127 24089 25278 D EventLogger: getNextChunk: previous: 193605
10-02 11:20:11.127 24089 25278 D EventLogger: getNextChunk: firstAvailableSegmentNum: 193595 lastAvailableSegmentNum: 193896 segmentNum: 193606
10-02 11:20:11.128 24089 25278 D EventLogger: getNextChunk: maxSegmentCount: 1 segmentNum: 193606
10-02 11:20:11.128 24089 25278 D EventLogger: getSegmentUrl: segNum: 193606 segmentNumShift: 289 // The original segNum was correct, but with wrong segmentNumShift
10-02 11:20:11.128 24089 25278 D EventLogger: getSegmentUrl: urlIndex: 193317 url: RangedUri(referenceUri=index_video_9_0_193317.mp4?m=1569796293, start=0, length=-1) // Wrong segmentUrl was returned to download
Solution A solution could consider this case that new_first < old_first && new_last > old_last, so the new index includes the whole old index, newSegmentNumShift could be kept as is instead of calculating as overlaps. PR will be followed soon.
[REQUIRED] Reproduction [steps]
Play the test content in the ExoPlayer demo for a while, after the MPD randomly drop to 57S, the video playback will be stuck and OOM in the end.
[REQUIRED] Link to test content
Add the following in the ExoPlayer demo's media.exolist.json
{
"name": "Test LIVE DASH + WV",
"uri": "https://skysport3.akamaized.net/out/v1/686ec493b68042c7b943b4f55c95b867/index.mpd?start=1569957852",
"drm_scheme": "widevine",
"drm_license_url": "https://widevine.entitlement.theplatform.com/wv/web/ModularDrm/getRawWidevineLicense?schema=1.0&token=Qh-JLBe8igAg_phMrQYQUcBowPBUwEBS&account=http://access.auth.theplatform.com/data/Account/2682481919&releasePid=6n3vPYRNy5VV"
}
[REQUIRED] A full bug report captured from the device
Not really needed in this case EventLogger can be download via https://send.firefox.com/download/fa4e73269846a34b/#106lwvZyqBhxGG4hUGkkIA
[REQUIRED] Version of ExoPlayer being used
2.10.4 and 2.10.5
[REQUIRED] Device(s) and version(s) of Android being used
One Plus 7 Android 10
Somehow the AWS MediaPackager is not 100% stable
It seems pretty sub-optimal to be relying on technology that's not behaving in a stable way :). Have you reported the issue to AWS, and are they planning on fixing it?
PR will be followed soon.
Let's discuss directly on the PR. Thanks!
Yes, we reported to the AWS as while as try to fix from ExoPlayer side.