Commit 79cdd036 by Oliver Woodman

Filter unsupported video formats for HLS.

parent b405d3d9
...@@ -229,7 +229,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback, ...@@ -229,7 +229,7 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
return new DashRendererBuilder(this, userAgent, contentUri.toString(), return new DashRendererBuilder(this, userAgent, contentUri.toString(),
new WidevineTestMediaDrmCallback(contentId), debugTextView, audioCapabilities); new WidevineTestMediaDrmCallback(contentId), debugTextView, audioCapabilities);
case DemoUtil.TYPE_HLS: case DemoUtil.TYPE_HLS:
return new HlsRendererBuilder(userAgent, contentUri.toString(), debugTextView); return new HlsRendererBuilder(this, userAgent, contentUri.toString(), debugTextView);
case DemoUtil.TYPE_MP4: case DemoUtil.TYPE_MP4:
return new ExtractorRendererBuilder(userAgent, contentUri, debugTextView, return new ExtractorRendererBuilder(userAgent, contentUri, debugTextView,
new Mp4Extractor()); new Mp4Extractor());
......
...@@ -16,11 +16,14 @@ ...@@ -16,11 +16,14 @@
package com.google.android.exoplayer.demo.player; package com.google.android.exoplayer.demo.player;
import com.google.android.exoplayer.MediaCodecAudioTrackRenderer; import com.google.android.exoplayer.MediaCodecAudioTrackRenderer;
import com.google.android.exoplayer.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer.MediaCodecVideoTrackRenderer; import com.google.android.exoplayer.MediaCodecVideoTrackRenderer;
import com.google.android.exoplayer.TrackRenderer; import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.chunk.VideoFormatSelectorUtil;
import com.google.android.exoplayer.demo.player.DemoPlayer.RendererBuilder; import com.google.android.exoplayer.demo.player.DemoPlayer.RendererBuilder;
import com.google.android.exoplayer.demo.player.DemoPlayer.RendererBuilderCallback; import com.google.android.exoplayer.demo.player.DemoPlayer.RendererBuilderCallback;
import com.google.android.exoplayer.hls.HlsChunkSource; import com.google.android.exoplayer.hls.HlsChunkSource;
import com.google.android.exoplayer.hls.HlsMasterPlaylist;
import com.google.android.exoplayer.hls.HlsPlaylist; import com.google.android.exoplayer.hls.HlsPlaylist;
import com.google.android.exoplayer.hls.HlsPlaylistParser; import com.google.android.exoplayer.hls.HlsPlaylistParser;
import com.google.android.exoplayer.hls.HlsSampleSource; import com.google.android.exoplayer.hls.HlsSampleSource;
...@@ -33,6 +36,7 @@ import com.google.android.exoplayer.upstream.DefaultUriDataSource; ...@@ -33,6 +36,7 @@ import com.google.android.exoplayer.upstream.DefaultUriDataSource;
import com.google.android.exoplayer.util.ManifestFetcher; import com.google.android.exoplayer.util.ManifestFetcher;
import com.google.android.exoplayer.util.ManifestFetcher.ManifestCallback; import com.google.android.exoplayer.util.ManifestFetcher.ManifestCallback;
import android.content.Context;
import android.media.MediaCodec; import android.media.MediaCodec;
import android.os.Handler; import android.os.Handler;
import android.widget.TextView; import android.widget.TextView;
...@@ -48,6 +52,7 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls ...@@ -48,6 +52,7 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls
private static final int REQUESTED_BUFFER_SIZE = 18 * 1024 * 1024; private static final int REQUESTED_BUFFER_SIZE = 18 * 1024 * 1024;
private static final long REQUESTED_BUFFER_DURATION_MS = 40000; private static final long REQUESTED_BUFFER_DURATION_MS = 40000;
private final Context context;
private final String userAgent; private final String userAgent;
private final String url; private final String url;
private final TextView debugTextView; private final TextView debugTextView;
...@@ -55,7 +60,8 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls ...@@ -55,7 +60,8 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls
private DemoPlayer player; private DemoPlayer player;
private RendererBuilderCallback callback; private RendererBuilderCallback callback;
public HlsRendererBuilder(String userAgent, String url, TextView debugTextView) { public HlsRendererBuilder(Context context, String userAgent, String url, TextView debugTextView) {
this.context = context;
this.userAgent = userAgent; this.userAgent = userAgent;
this.url = url; this.url = url;
this.debugTextView = debugTextView; this.debugTextView = debugTextView;
...@@ -81,9 +87,21 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls ...@@ -81,9 +87,21 @@ public class HlsRendererBuilder implements RendererBuilder, ManifestCallback<Hls
Handler mainHandler = player.getMainHandler(); Handler mainHandler = player.getMainHandler();
DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
int[] variantIndices = null;
if (manifest instanceof HlsMasterPlaylist) {
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) manifest;
try {
variantIndices = VideoFormatSelectorUtil.selectVideoFormatsForDefaultDisplay(
context, masterPlaylist.variants, null, false);
} catch (DecoderQueryException e) {
callback.onRenderersError(e);
return;
}
}
DataSource dataSource = new DefaultUriDataSource(userAgent, bandwidthMeter); DataSource dataSource = new DefaultUriDataSource(userAgent, bandwidthMeter);
HlsChunkSource chunkSource = new HlsChunkSource(dataSource, url, manifest, bandwidthMeter, null, HlsChunkSource chunkSource = new HlsChunkSource(dataSource, url, manifest, bandwidthMeter,
HlsChunkSource.ADAPTIVE_MODE_SPLICE); variantIndices, HlsChunkSource.ADAPTIVE_MODE_SPLICE);
HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, true, 3, REQUESTED_BUFFER_SIZE, HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, true, 3, REQUESTED_BUFFER_SIZE,
REQUESTED_BUFFER_DURATION_MS, mainHandler, player, DemoPlayer.TYPE_VIDEO); REQUESTED_BUFFER_DURATION_MS, mainHandler, player, DemoPlayer.TYPE_VIDEO);
MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource,
......
...@@ -126,8 +126,8 @@ public final class VideoFormatSelectorUtil { ...@@ -126,8 +126,8 @@ public final class VideoFormatSelectorUtil {
// viewport. // viewport.
for (int i = selectedIndexList.size() - 1; i >= 0; i--) { for (int i = selectedIndexList.size() - 1; i >= 0; i--) {
Format format = formatWrappers.get(i).getFormat(); Format format = formatWrappers.get(i).getFormat();
int videoPixels = format.width * format.height; if (format.width != -1 && format.height != -1
if (format.width != -1 && format.height != -1 && videoPixels > maxVideoPixelsToRetain) { && format.width * format.height > maxVideoPixelsToRetain) {
selectedIndexList.remove(i); selectedIndexList.remove(i);
} }
} }
......
...@@ -150,8 +150,9 @@ public class HlsChunkSource { ...@@ -150,8 +150,9 @@ public class HlsChunkSource {
* @param playlistUrl The playlist URL. * @param playlistUrl The playlist URL.
* @param playlist The hls playlist. * @param playlist The hls playlist.
* @param bandwidthMeter provides an estimate of the currently available bandwidth. * @param bandwidthMeter provides an estimate of the currently available bandwidth.
* @param variantIndices A subset of variant indices to consider, or null to consider all of the * @param variantIndices If {@code playlist} is a {@link HlsMasterPlaylist}, the subset of variant
* variants in the master playlist. * indices to consider, or null to consider all of the variants. For other playlist types
* this parameter is ignored.
* @param adaptiveMode The mode for switching from one variant to another. One of * @param adaptiveMode The mode for switching from one variant to another. One of
* {@link #ADAPTIVE_MODE_NONE}, {@link #ADAPTIVE_MODE_ABRUPT} and * {@link #ADAPTIVE_MODE_NONE}, {@link #ADAPTIVE_MODE_ABRUPT} and
* {@link #ADAPTIVE_MODE_SPLICE}. * {@link #ADAPTIVE_MODE_SPLICE}.
......
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