mirror of
https://github.com/androidx/media.git
synced 2025-05-15 19:49:50 +08:00
SmoothStreaming track selector feature parity with DASH.
This gives DefaultSmoothStreamingTrackSelector feature parity with DefaultDashTrackSelector. Note that the code duplication across these classes will go away eventually, when we rework track selection as described in Github Issue #1121. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=111688784
This commit is contained in:
parent
00e903b32e
commit
b9ec51dbed
@ -33,7 +33,6 @@ import com.google.android.exoplayer.drm.UnsupportedDrmException;
|
|||||||
import com.google.android.exoplayer.smoothstreaming.DefaultSmoothStreamingTrackSelector;
|
import com.google.android.exoplayer.smoothstreaming.DefaultSmoothStreamingTrackSelector;
|
||||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingChunkSource;
|
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingChunkSource;
|
||||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest;
|
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest;
|
||||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.StreamElement;
|
|
||||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifestParser;
|
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifestParser;
|
||||||
import com.google.android.exoplayer.text.TextTrackRenderer;
|
import com.google.android.exoplayer.text.TextTrackRenderer;
|
||||||
import com.google.android.exoplayer.upstream.DataSource;
|
import com.google.android.exoplayer.upstream.DataSource;
|
||||||
@ -160,7 +159,7 @@ public class SmoothStreamingRendererBuilder implements RendererBuilder {
|
|||||||
// Build the video renderer.
|
// Build the video renderer.
|
||||||
DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
DataSource videoDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
||||||
ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
ChunkSource videoChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
||||||
new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_VIDEO),
|
DefaultSmoothStreamingTrackSelector.newVideoInstance(context, true, false),
|
||||||
videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
|
videoDataSource, new AdaptiveEvaluator(bandwidthMeter), LIVE_EDGE_LATENCY_MS);
|
||||||
ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
|
ChunkSampleSource videoSampleSource = new ChunkSampleSource(videoChunkSource, loadControl,
|
||||||
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
VIDEO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
||||||
@ -172,7 +171,7 @@ public class SmoothStreamingRendererBuilder implements RendererBuilder {
|
|||||||
// Build the audio renderer.
|
// Build the audio renderer.
|
||||||
DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
DataSource audioDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
||||||
ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
ChunkSource audioChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
||||||
new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_AUDIO),
|
DefaultSmoothStreamingTrackSelector.newAudioInstance(),
|
||||||
audioDataSource, null, LIVE_EDGE_LATENCY_MS);
|
audioDataSource, null, LIVE_EDGE_LATENCY_MS);
|
||||||
ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
|
ChunkSampleSource audioSampleSource = new ChunkSampleSource(audioChunkSource, loadControl,
|
||||||
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
AUDIO_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
||||||
@ -184,7 +183,7 @@ public class SmoothStreamingRendererBuilder implements RendererBuilder {
|
|||||||
// Build the text renderer.
|
// Build the text renderer.
|
||||||
DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
DataSource textDataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
|
||||||
ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
ChunkSource textChunkSource = new SmoothStreamingChunkSource(manifestFetcher,
|
||||||
new DefaultSmoothStreamingTrackSelector(context, StreamElement.TYPE_TEXT),
|
DefaultSmoothStreamingTrackSelector.newTextInstance(),
|
||||||
textDataSource, null, LIVE_EDGE_LATENCY_MS);
|
textDataSource, null, LIVE_EDGE_LATENCY_MS);
|
||||||
ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
|
ChunkSampleSource textSampleSource = new ChunkSampleSource(textChunkSource, loadControl,
|
||||||
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
TEXT_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player,
|
||||||
|
@ -17,6 +17,8 @@ package com.google.android.exoplayer.smoothstreaming;
|
|||||||
|
|
||||||
import com.google.android.exoplayer.chunk.VideoFormatSelectorUtil;
|
import com.google.android.exoplayer.chunk.VideoFormatSelectorUtil;
|
||||||
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.StreamElement;
|
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.StreamElement;
|
||||||
|
import com.google.android.exoplayer.smoothstreaming.SmoothStreamingManifest.TrackElement;
|
||||||
|
import com.google.android.exoplayer.util.Util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
@ -26,30 +28,60 @@ import java.util.Arrays;
|
|||||||
/**
|
/**
|
||||||
* A default {@link SmoothStreamingTrackSelector} implementation.
|
* A default {@link SmoothStreamingTrackSelector} implementation.
|
||||||
*/
|
*/
|
||||||
// TODO: Add configuration options (e.g. ability to disable adaptive track output, disable format
|
// TODO: Add more configuration options (e.g. ability to disable adaptive track output).
|
||||||
// filtering etc).
|
|
||||||
public final class DefaultSmoothStreamingTrackSelector implements SmoothStreamingTrackSelector {
|
public final class DefaultSmoothStreamingTrackSelector implements SmoothStreamingTrackSelector {
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private final int streamElementType;
|
private final int streamElementType;
|
||||||
|
|
||||||
|
private final Context context;
|
||||||
|
private final boolean filterVideoRepresentations;
|
||||||
|
private final boolean filterProtectedHdContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param context A context.
|
* @param context A context. May be null if {@code filterVideoRepresentations == false}.
|
||||||
* @param streamElementType The type of stream to select. One of {@link StreamElement#TYPE_AUDIO},
|
* @param filterVideoRepresentations Whether video representations should be filtered according to
|
||||||
* {@link StreamElement#TYPE_VIDEO} and {@link StreamElement#TYPE_TEXT}.
|
* the capabilities of the device. It is strongly recommended to set this to {@code true},
|
||||||
|
* unless the application has already verified that all representations are playable.
|
||||||
|
* @param filterProtectedHdContent Whether video representations that are both drm protected and
|
||||||
|
* high definition should be filtered when tracks are built. If
|
||||||
|
* {@code filterVideoRepresentations == false} then this parameter is ignored.
|
||||||
*/
|
*/
|
||||||
public DefaultSmoothStreamingTrackSelector(Context context, int streamElementType) {
|
public static DefaultSmoothStreamingTrackSelector newVideoInstance(Context context,
|
||||||
|
boolean filterVideoRepresentations, boolean filterProtectedHdContent) {
|
||||||
|
return new DefaultSmoothStreamingTrackSelector(StreamElement.TYPE_VIDEO, context,
|
||||||
|
filterVideoRepresentations, filterProtectedHdContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DefaultSmoothStreamingTrackSelector newAudioInstance() {
|
||||||
|
return new DefaultSmoothStreamingTrackSelector(StreamElement.TYPE_AUDIO, null, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DefaultSmoothStreamingTrackSelector newTextInstance() {
|
||||||
|
return new DefaultSmoothStreamingTrackSelector(StreamElement.TYPE_TEXT, null, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DefaultSmoothStreamingTrackSelector(int streamElementType, Context context,
|
||||||
|
boolean filterVideoRepresentations, boolean filterProtectedHdContent) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.streamElementType = streamElementType;
|
this.streamElementType = streamElementType;
|
||||||
|
this.filterVideoRepresentations = filterVideoRepresentations;
|
||||||
|
this.filterProtectedHdContent = filterProtectedHdContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectTracks(SmoothStreamingManifest manifest, Output output) throws IOException {
|
public void selectTracks(SmoothStreamingManifest manifest, Output output) throws IOException {
|
||||||
for (int i = 0; i < manifest.streamElements.length; i++) {
|
for (int i = 0; i < manifest.streamElements.length; i++) {
|
||||||
|
TrackElement[] tracks = manifest.streamElements[i].tracks;
|
||||||
if (manifest.streamElements[i].type == streamElementType) {
|
if (manifest.streamElements[i].type == streamElementType) {
|
||||||
if (streamElementType == StreamElement.TYPE_VIDEO) {
|
if (streamElementType == StreamElement.TYPE_VIDEO) {
|
||||||
int[] trackIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(
|
int[] trackIndices;
|
||||||
context, Arrays.asList(manifest.streamElements[i].tracks), null, false);
|
if (filterVideoRepresentations) {
|
||||||
|
trackIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(
|
||||||
|
context, Arrays.asList(tracks), null,
|
||||||
|
filterProtectedHdContent && manifest.protectionElement != null);
|
||||||
|
} else {
|
||||||
|
trackIndices = Util.firstIntegersArray(tracks.length);
|
||||||
|
}
|
||||||
int trackCount = trackIndices.length;
|
int trackCount = trackIndices.length;
|
||||||
if (trackCount > 1) {
|
if (trackCount > 1) {
|
||||||
output.adaptiveTrack(manifest, i, trackIndices);
|
output.adaptiveTrack(manifest, i, trackIndices);
|
||||||
@ -58,7 +90,7 @@ public final class DefaultSmoothStreamingTrackSelector implements SmoothStreamin
|
|||||||
output.fixedTrack(manifest, i, trackIndices[j]);
|
output.fixedTrack(manifest, i, trackIndices[j]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int j = 0; j < manifest.streamElements[i].tracks.length; j++) {
|
for (int j = 0; j < tracks.length; j++) {
|
||||||
output.fixedTrack(manifest, i, j);
|
output.fixedTrack(manifest, i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user