Commit 002df729 by aquilescanta Committed by Oliver Woodman

Allow late HLS sample queue building

Issue:#3149

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177836048
parent fbfa43f5
*** ISSUES THAT IGNORE THIS TEMPLATE WILL BE CLOSED WITHOUT INVESTIGATION ***
Before filing an issue:
-----------------------
- Search existing issues, including issues that are closed.
......
......@@ -15,6 +15,7 @@
*/
package com.google.android.exoplayer2.source.hls;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.source.SampleStream;
......@@ -25,33 +26,60 @@ import java.io.IOException;
*/
/* package */ final class HlsSampleStream implements SampleStream {
public final int sampleQueueIndex;
private final int trackGroupIndex;
private final HlsSampleStreamWrapper sampleStreamWrapper;
private int sampleQueueIndex;
public HlsSampleStream(HlsSampleStreamWrapper sampleStreamWrapper, int sampleQueueIndex) {
public HlsSampleStream(HlsSampleStreamWrapper sampleStreamWrapper, int trackGroupIndex) {
this.sampleStreamWrapper = sampleStreamWrapper;
this.sampleQueueIndex = sampleQueueIndex;
this.trackGroupIndex = trackGroupIndex;
}
public void unbindSampleQueue() {
if (sampleQueueIndex != C.INDEX_UNSET) {
sampleStreamWrapper.unbindSampleQueue(trackGroupIndex);
}
}
// SampleStream implementation.
@Override
public boolean isReady() {
return sampleStreamWrapper.isReady(sampleQueueIndex);
return ensureBoundSampleQueue() && sampleStreamWrapper.isReady(sampleQueueIndex);
}
@Override
public void maybeThrowError() throws IOException {
if (!ensureBoundSampleQueue()) {
throw new SampleQueueMappingException(
sampleStreamWrapper.getTrackGroups().get(trackGroupIndex).getFormat(0).sampleMimeType);
}
sampleStreamWrapper.maybeThrowError();
}
@Override
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer, boolean requireFormat) {
if (!ensureBoundSampleQueue()) {
return C.RESULT_NOTHING_READ;
}
return sampleStreamWrapper.readData(sampleQueueIndex, formatHolder, buffer, requireFormat);
}
@Override
public int skipData(long positionUs) {
if (!ensureBoundSampleQueue()) {
return 0;
}
return sampleStreamWrapper.skipData(sampleQueueIndex, positionUs);
}
// Internal methods.
private boolean ensureBoundSampleQueue() {
if (sampleQueueIndex != C.INDEX_UNSET) {
return true;
}
sampleQueueIndex = sampleStreamWrapper.bindSampleQueueToSampleStream(trackGroupIndex);
return sampleQueueIndex != C.INDEX_UNSET;
}
}
/*
* Copyright (C) 2017 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.source.hls;
import com.google.android.exoplayer2.source.SampleQueue;
import com.google.android.exoplayer2.source.TrackGroup;
import java.io.IOException;
/** Thrown when it is not possible to map a {@link TrackGroup} to a {@link SampleQueue}. */
public final class SampleQueueMappingException extends IOException {
/** @param mimeType The mime type of the track group whose mapping failed. */
public SampleQueueMappingException(String mimeType) {
super("Unable to bind a sample queue to TrackGroup with mime type " + mimeType + ".");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment