Commit 770f2c2c by olly Committed by Oliver Woodman

Refactor #6.HLS.1

1. Merge HlsOutput and HlsSampleSource -> HlsTrackStreamWrapper.
2. Rename HlsSource -> HlsSampleSource2. This will be renamed to
   HlsSampleSource in a subsequent CL.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=122415970
parent 51cf8bed
...@@ -29,7 +29,7 @@ import com.google.android.exoplayer.demo.player.DemoPlayer; ...@@ -29,7 +29,7 @@ import com.google.android.exoplayer.demo.player.DemoPlayer;
import com.google.android.exoplayer.demo.ui.TrackSelectionHelper; import com.google.android.exoplayer.demo.ui.TrackSelectionHelper;
import com.google.android.exoplayer.drm.UnsupportedDrmException; import com.google.android.exoplayer.drm.UnsupportedDrmException;
import com.google.android.exoplayer.extractor.ExtractorSampleSource; import com.google.android.exoplayer.extractor.ExtractorSampleSource;
import com.google.android.exoplayer.hls.HlsSource; import com.google.android.exoplayer.hls.HlsSampleSource2;
import com.google.android.exoplayer.metadata.id3.GeobFrame; import com.google.android.exoplayer.metadata.id3.GeobFrame;
import com.google.android.exoplayer.metadata.id3.Id3Frame; import com.google.android.exoplayer.metadata.id3.Id3Frame;
import com.google.android.exoplayer.metadata.id3.PrivFrame; import com.google.android.exoplayer.metadata.id3.PrivFrame;
...@@ -278,7 +278,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback, ...@@ -278,7 +278,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
return new DashSampleSource(uri, dataSourceFactory, player.getBandwidthMeter(), return new DashSampleSource(uri, dataSourceFactory, player.getBandwidthMeter(),
player.getMainHandler(), player); player.getMainHandler(), player);
case Util.TYPE_HLS: case Util.TYPE_HLS:
return new HlsSource(uri, dataSourceFactory, player.getBandwidthMeter(), return new HlsSampleSource2(uri, dataSourceFactory, player.getBandwidthMeter(),
player.getMainHandler(), player); player.getMainHandler(), player);
case Util.TYPE_OTHER: case Util.TYPE_OTHER:
Allocator allocator = new DefaultAllocator(C.DEFAULT_BUFFER_SEGMENT_SIZE); Allocator allocator = new DefaultAllocator(C.DEFAULT_BUFFER_SEGMENT_SIZE);
......
...@@ -461,7 +461,7 @@ public class HlsChunkSource { ...@@ -461,7 +461,7 @@ public class HlsChunkSource {
} }
/** /**
* Invoked when the {@link HlsSampleSource} has finished loading a chunk obtained from this * Invoked when the {@link HlsTrackStreamWrapper} has finished loading a chunk obtained from this
* source. * source.
* *
* @param chunk The chunk whose load has been completed. * @param chunk The chunk whose load has been completed.
...@@ -480,8 +480,8 @@ public class HlsChunkSource { ...@@ -480,8 +480,8 @@ public class HlsChunkSource {
} }
/** /**
* Invoked when the {@link HlsSampleSource} encounters an error loading a chunk obtained from * Invoked when the {@link HlsTrackStreamWrapper} encounters an error loading a chunk obtained
* this source. * from this source.
* *
* @param chunk The chunk whose load encountered the error. * @param chunk The chunk whose load encountered the error.
* @param cancelable Whether the load can be canceled. * @param cancelable Whether the load can be canceled.
......
...@@ -59,9 +59,9 @@ import java.io.IOException; ...@@ -59,9 +59,9 @@ import java.io.IOException;
* @param discontinuitySequenceNumber The discontinuity sequence number of the chunk. * @param discontinuitySequenceNumber The discontinuity sequence number of the chunk.
* @param extractor The extractor to parse samples from the data. * @param extractor The extractor to parse samples from the data.
* @param extractorNeedsInit Whether the extractor needs initializing with the target * @param extractorNeedsInit Whether the extractor needs initializing with the target
* {@link HlsOutput}. * {@link HlsTrackStreamWrapper}.
* @param shouldSpliceIn Whether the samples parsed from this chunk should be spliced into any * @param shouldSpliceIn Whether the samples parsed from this chunk should be spliced into any
* samples already queued to the {@link HlsOutput}. * samples already queued to the {@link HlsTrackStreamWrapper}.
* @param encryptionKey For AES encryption chunks, the encryption key. * @param encryptionKey For AES encryption chunks, the encryption key.
* @param encryptionIv For AES encryption chunks, the encryption initialization vector. * @param encryptionIv For AES encryption chunks, the encryption initialization vector.
*/ */
...@@ -80,12 +80,12 @@ import java.io.IOException; ...@@ -80,12 +80,12 @@ import java.io.IOException;
} }
/** /**
* Initializes the chunk for loading, setting the {@link HlsOutput} that will receive samples as * Initializes the chunk for loading, setting the {@link HlsTrackStreamWrapper} that will receive
* they are loaded. * samples as they are loaded.
* *
* @param output The output that will receive the loaded samples. * @param output The output that will receive the loaded samples.
*/ */
public void init(HlsOutput output) { public void init(HlsTrackStreamWrapper output) {
if (shouldSpliceIn) { if (shouldSpliceIn) {
output.splice(); output.splice();
} }
......
/*
* Copyright (C) 2014 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.exoplayer.hls;
import com.google.android.exoplayer.extractor.DefaultTrackOutput;
import com.google.android.exoplayer.extractor.ExtractorOutput;
import com.google.android.exoplayer.extractor.SeekMap;
import com.google.android.exoplayer.upstream.Allocator;
import android.util.SparseArray;
/**
* An {@link ExtractorOutput} for HLS playbacks.
*/
/* package */ final class HlsOutput implements ExtractorOutput {
private final Allocator allocator;
private final SparseArray<DefaultTrackOutput> sampleQueues = new SparseArray<>();
private boolean prepared;
private DefaultTrackOutput[] trackOutputArray;
private volatile boolean tracksBuilt;
public HlsOutput(Allocator allocator) {
this.allocator = allocator;
}
// Called by the consuming thread.
/**
* Prepares the output, or does nothing if the output is already prepared.
*
* @return True if the output is prepared, false otherwise.
*/
public boolean prepare() {
if (prepared) {
return true;
} else if (!tracksBuilt) {
return false;
} else {
if (trackOutputArray == null) {
trackOutputArray = new DefaultTrackOutput[sampleQueues.size()];
for (int i = 0; i < trackOutputArray.length; i++) {
trackOutputArray[i] = sampleQueues.valueAt(i);
}
}
for (DefaultTrackOutput sampleQueue : trackOutputArray) {
if (sampleQueue.getUpstreamFormat() == null) {
return false;
}
}
prepared = true;
return true;
}
}
/**
* Returns the array of track outputs, or null if the output is not yet prepared.
*/
public DefaultTrackOutput[] getTrackOutputs() {
return trackOutputArray;
}
// Called by the consuming thread, but only when there is no loading thread.
/**
* Clears all track outputs.
*/
public void clear() {
for (int i = 0; i < sampleQueues.size(); i++) {
sampleQueues.valueAt(i).clear();
}
}
/**
* Indicates to all track outputs that they should splice in subsequently queued samples.
*/
public void splice() {
for (int i = 0; i < sampleQueues.size(); i++) {
sampleQueues.valueAt(i).splice();
}
}
// ExtractorOutput implementation. Called by the loading thread.
@Override
public DefaultTrackOutput track(int id) {
if (sampleQueues.indexOfKey(id) >= 0) {
return sampleQueues.get(id);
}
DefaultTrackOutput trackOutput = new DefaultTrackOutput(allocator);
sampleQueues.put(id, trackOutput);
return trackOutput;
}
@Override
public void endTracks() {
tracksBuilt = true;
}
@Override
public void seekMap(SeekMap seekMap) {
// Do nothing.
}
}
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