Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MergingMediaSource failed when use side loaded Text tracks #1853

Closed
ChernyshovYuriy opened this issue Sep 23, 2016 · 4 comments
Closed

MergingMediaSource failed when use side loaded Text tracks #1853

ChernyshovYuriy opened this issue Sep 23, 2016 · 4 comments
Assignees
Labels

Comments

@ChernyshovYuriy
Copy link

ChernyshovYuriy commented Sep 23, 2016

Dear colleagues,
In the current ExoPlayer v2, when use side loaded text tracks along side with dash source, there is last track missing in the MergingMediaPeriod#periods field. It results to NullPointerException at the line 180 of the MergingMediaPeriod.java.
I did investigation and found that callback.onPrepared() dispatches too earlier, in fact prior to MediaPeriod added to the array.
Be more specific, there are two callbacks that dispatches prior to MediaPeriod added to the array:

  • SingleSampleMediaSource.java, line 103
  • DashMediaPeriod.java, line 79

All these callback dispatches prior to MergingMediaSource.java line 120. Upon this callback MergingMediaPeriod decremented counter at the line 175, that leads to the wrong "pendingChildPrepareCount == 0" event and reveal farther logic. Then, when execution reached line 179, there is missing element in "periods" array.

I eliminate this effect temporary by commented callback "callback.onPrepared(this);" on lines 103 and 79 (described above) and modify MergingMediaSource.java:

for (int i = 0; i < periods.length; i++) {
      periods[i] = mediaSources[i].createPeriod(index, mergingPeriod, allocator, positionUs);
      Assertions.checkState(periods[i] != null, "Child source must not return null period");
      // Dispatch event only when element is in array
      mergingPeriod.onPrepared(periods[i]);
    }

I added media sources as:

new MergingMediaSource([DashMediaSource, SingleSampleMediaSource])

Also, still a bug in the SingleSampleMediaPeriod.java and it's filed "private byte[] sampleData" line 239. It is necessary to initialize it as well by:

private byte[] sampleData = new byte[INITIAL_SAMPLE_SIZE];

Otherwise there is NullPointerException at the line 267.
Excuse me for such technical description with dive into code, I hope that you will understand the issue.

@ChernyshovYuriy
Copy link
Author

I have to notice that in case of no side loaded content we still need a callback dispatched from DashMediaPeriod's constructor. So it would be not an easy solution without know all aspects of the ExoPlayer structure.

@asapehrsson
Copy link

I have the same problem.

My workaround: Modify MergingMediaPeriod.java, MergingMediaSource.java and SingleSampleMediaPeriod.java.

First, change MergingMediaPeriod.java line 175.

if (--pendingChildPrepareCount > 0) {

to

if (pendingChildPrepareCount-- > 0) {

Then add code, MergingMediaSource.java, line 121

for (int i = 0; i < periods.length; i++) {
     periods[i] = mediaSources[i].createPeriod(index, mergingPeriod, allocator, positionUs);
    Assertions.checkState(periods[i] != null, "Child source must not return null period");
}
mergingPeriod.onPrepared(null); //added this line

Finally initialize sampleData in SingleSampleMediaPeriod.java

@ojw28
Copy link
Contributor

ojw28 commented Sep 26, 2016

@andrewlewis - Fixing this may well link into getting all the onPrepared calls onto the right thread.

@ojw28
Copy link
Contributor

ojw28 commented Sep 26, 2016

The issue is best understood by looking at MergingMediaSource.createPeriod:

periods[i] = mediaSources[i].createPeriod(index, mergingPeriod, allocator, positionUs);

Some createPeriod calls ends up calling onPrepared synchronously, so such calls happen before periods[i] is actually set to the period being created. MergingMediaSource.onPrepared relies on all entries in periods being non-null at the point where pendingChildPrepareCount is decremented to 0.

ojw28 pushed a commit that referenced this issue Sep 28, 2016
Issue: #1853

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134409897
@ojw28 ojw28 closed this as completed Sep 28, 2016
@google google locked and limited conversation to collaborators Jun 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants