Commit f0c0b3ef by aquilescanta Committed by Oliver Woodman

Decouple HlsSampleStream from HlsSampleStreamWrapper

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131731376
parent 797cd46e
/*
* 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.source.hls;
import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.source.SampleStream;
import java.io.IOException;
/**
* {@link SampleStream} for a particular track group in HLS.
*/
/* package */ final class HlsSampleStream implements SampleStream {
public final int group;
private final HlsSampleStreamWrapper sampleStreamWrapper;
public HlsSampleStream(HlsSampleStreamWrapper sampleStreamWrapper, int group) {
this.sampleStreamWrapper = sampleStreamWrapper;
this.group = group;
}
@Override
public boolean isReady() {
return sampleStreamWrapper.isReady(group);
}
@Override
public void maybeThrowError() throws IOException {
sampleStreamWrapper.maybeThrowError();
}
@Override
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
return sampleStreamWrapper.readData(group, formatHolder, buffer);
}
@Override
public void skipToKeyframeBefore(long timeUs) {
sampleStreamWrapper.skipToKeyframeBefore(group, timeUs);
}
}
...@@ -154,7 +154,7 @@ import java.util.LinkedList; ...@@ -154,7 +154,7 @@ import java.util.LinkedList;
// Disable old tracks. // Disable old tracks.
for (int i = 0; i < selections.length; i++) { for (int i = 0; i < selections.length; i++) {
if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) { if (streams[i] != null && (selections[i] == null || !mayRetainStreamFlags[i])) {
int group = ((SampleStreamImpl) streams[i]).group; int group = ((HlsSampleStream) streams[i]).group;
setTrackGroupEnabledState(group, false); setTrackGroupEnabledState(group, false);
sampleQueues.valueAt(group).disable(); sampleQueues.valueAt(group).disable();
streams[i] = null; streams[i] = null;
...@@ -170,7 +170,7 @@ import java.util.LinkedList; ...@@ -170,7 +170,7 @@ import java.util.LinkedList;
if (group == primaryTrackGroupIndex) { if (group == primaryTrackGroupIndex) {
chunkSource.selectTracks(selection); chunkSource.selectTracks(selection);
} }
streams[i] = new SampleStreamImpl(group); streams[i] = new HlsSampleStream(this, group);
streamResetFlags[i] = true; streamResetFlags[i] = true;
selectedNewTracks = true; selectedNewTracks = true;
} }
...@@ -283,6 +283,10 @@ import java.util.LinkedList; ...@@ -283,6 +283,10 @@ import java.util.LinkedList;
lastSeekPositionUs); lastSeekPositionUs);
} }
/* package */ void skipToKeyframeBefore(int group, long timeUs) {
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs);
}
private boolean finishedReadingChunk(HlsMediaChunk chunk) { private boolean finishedReadingChunk(HlsMediaChunk chunk) {
int chunkUid = chunk.uid; int chunkUid = chunk.uid;
for (int i = 0; i < sampleQueues.size(); i++) { for (int i = 0; i < sampleQueues.size(); i++) {
...@@ -600,34 +604,4 @@ import java.util.LinkedList; ...@@ -600,34 +604,4 @@ import java.util.LinkedList;
return pendingResetPositionUs != C.TIME_UNSET; return pendingResetPositionUs != C.TIME_UNSET;
} }
private final class SampleStreamImpl implements SampleStream {
private final int group;
public SampleStreamImpl(int group) {
this.group = group;
}
@Override
public boolean isReady() {
return HlsSampleStreamWrapper.this.isReady(group);
}
@Override
public void maybeThrowError() throws IOException {
HlsSampleStreamWrapper.this.maybeThrowError();
}
@Override
public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer) {
return HlsSampleStreamWrapper.this.readData(group, formatHolder, buffer);
}
@Override
public void skipToKeyframeBefore(long timeUs) {
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs);
}
}
} }
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