Allow merging of both periods and sources.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=127073129
This commit is contained in:
parent
9558a4cb99
commit
a89bf3a477
@ -16,7 +16,7 @@
|
|||||||
package com.google.android.exoplayer2;
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link MediaSource} that concatenates multiple {@link MediaSource}s.
|
* Concatenates multiple {@link MediaSource}s.
|
||||||
*/
|
*/
|
||||||
public final class ConcatenatingMediaSource implements MediaSource {
|
public final class ConcatenatingMediaSource implements MediaSource {
|
||||||
|
|
||||||
|
@ -24,11 +24,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.IdentityHashMap;
|
import java.util.IdentityHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
// TODO: Make this a MediaSource
|
|
||||||
/**
|
/**
|
||||||
* Merges multiple {@link MediaPeriod} instances.
|
* Merges multiple {@link MediaPeriod} instances.
|
||||||
*/
|
*/
|
||||||
public final class MultiMediaPeriod implements MediaPeriod, MediaPeriod.Callback {
|
public final class MergingMediaPeriod implements MediaPeriod, MediaPeriod.Callback {
|
||||||
|
|
||||||
private final MediaPeriod[] periods;
|
private final MediaPeriod[] periods;
|
||||||
private final IdentityHashMap<TrackStream, MediaPeriod> trackStreamPeriods;
|
private final IdentityHashMap<TrackStream, MediaPeriod> trackStreamPeriods;
|
||||||
@ -43,7 +42,7 @@ public final class MultiMediaPeriod implements MediaPeriod, MediaPeriod.Callback
|
|||||||
private MediaPeriod[] enabledPeriods;
|
private MediaPeriod[] enabledPeriods;
|
||||||
private SequenceableLoader sequenceableLoader;
|
private SequenceableLoader sequenceableLoader;
|
||||||
|
|
||||||
public MultiMediaPeriod(MediaPeriod... periods) {
|
public MergingMediaPeriod(MediaPeriod... periods) {
|
||||||
this.periods = periods;
|
this.periods = periods;
|
||||||
pendingChildPrepareCount = periods.length;
|
pendingChildPrepareCount = periods.length;
|
||||||
trackStreamPeriods = new IdentityHashMap<>();
|
trackStreamPeriods = new IdentityHashMap<>();
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.google.android.exoplayer2;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Merges multiple {@link MediaPeriod} instances.
|
||||||
|
* <p>
|
||||||
|
* The {@link MediaSource}s being merged must have known and equal period counts, and may not return
|
||||||
|
* {@code null} from {@link #createPeriod(int)}.
|
||||||
|
*/
|
||||||
|
public final class MergingMediaSource implements MediaSource {
|
||||||
|
|
||||||
|
private final MediaSource[] mediaSources;
|
||||||
|
private final int periodCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mediaSources The {@link MediaSource}s to merge.
|
||||||
|
*/
|
||||||
|
public MergingMediaSource(MediaSource... mediaSources) {
|
||||||
|
this.mediaSources = mediaSources;
|
||||||
|
periodCount = mediaSources[0].getPeriodCount();
|
||||||
|
Assertions.checkState(periodCount != MediaSource.UNKNOWN_PERIOD_COUNT,
|
||||||
|
"Child sources must have known period counts");
|
||||||
|
for (int i = 1; i < mediaSources.length; i++) {
|
||||||
|
Assertions.checkState(mediaSources[i].getPeriodCount() == periodCount,
|
||||||
|
"Child sources must have equal period counts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPeriodCount() {
|
||||||
|
return periodCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MediaPeriod createPeriod(int index) {
|
||||||
|
MediaPeriod[] periods = new MediaPeriod[mediaSources.length];
|
||||||
|
for (int i = 0; i < periods.length; i++) {
|
||||||
|
periods[i] = mediaSources[i].createPeriod(index);
|
||||||
|
Assertions.checkState(periods[i] != null, "Child source must not return null period");
|
||||||
|
}
|
||||||
|
return new MergingMediaPeriod(periods);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user