Decouple HlsSampleStream from HlsSampleStreamWrapper

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131731376
This commit is contained in:
aquilescanta 2016-08-30 11:10:28 -07:00 committed by Oliver Woodman
parent 797cd46e89
commit f0c0b3efbf
2 changed files with 63 additions and 32 deletions

View file

@ -0,0 +1,57 @@
/*
* 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);
}
}

View file

@ -154,7 +154,7 @@ import java.util.LinkedList;
// Disable old tracks.
for (int i = 0; i < selections.length; 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);
sampleQueues.valueAt(group).disable();
streams[i] = null;
@ -170,7 +170,7 @@ import java.util.LinkedList;
if (group == primaryTrackGroupIndex) {
chunkSource.selectTracks(selection);
}
streams[i] = new SampleStreamImpl(group);
streams[i] = new HlsSampleStream(this, group);
streamResetFlags[i] = true;
selectedNewTracks = true;
}
@ -283,6 +283,10 @@ import java.util.LinkedList;
lastSeekPositionUs);
}
/* package */ void skipToKeyframeBefore(int group, long timeUs) {
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs);
}
private boolean finishedReadingChunk(HlsMediaChunk chunk) {
int chunkUid = chunk.uid;
for (int i = 0; i < sampleQueues.size(); i++) {
@ -600,34 +604,4 @@ import java.util.LinkedList;
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);
}
}
}