Commit 0d9d1998 by olly Committed by Oliver Woodman

Centralize manifest filtering.

The generic type for track key will go away soon.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=194220450
parent b77d6c4e
...@@ -48,6 +48,7 @@ import com.google.android.exoplayer2.drm.HttpMediaDrmCallback; ...@@ -48,6 +48,7 @@ import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
import com.google.android.exoplayer2.drm.UnsupportedDrmException; import com.google.android.exoplayer2.drm.UnsupportedDrmException;
import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException; import com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException; import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer2.offline.FilteringManifestParser;
import com.google.android.exoplayer2.source.BehindLiveWindowException; import com.google.android.exoplayer2.source.BehindLiveWindowException;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource; import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.ExtractorMediaSource; import com.google.android.exoplayer2.source.ExtractorMediaSource;
...@@ -57,14 +58,14 @@ import com.google.android.exoplayer2.source.ads.AdsLoader; ...@@ -57,14 +58,14 @@ import com.google.android.exoplayer2.source.ads.AdsLoader;
import com.google.android.exoplayer2.source.ads.AdsMediaSource; import com.google.android.exoplayer2.source.ads.AdsMediaSource;
import com.google.android.exoplayer2.source.dash.DashMediaSource; import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource; import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource;
import com.google.android.exoplayer2.source.dash.manifest.FilteringDashManifestParser; import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser;
import com.google.android.exoplayer2.source.dash.manifest.RepresentationKey; import com.google.android.exoplayer2.source.dash.manifest.RepresentationKey;
import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.hls.playlist.FilteringHlsPlaylistParser; import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser;
import com.google.android.exoplayer2.source.hls.playlist.RenditionKey; import com.google.android.exoplayer2.source.hls.playlist.RenditionKey;
import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource; import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource;
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource; import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.FilteringSsManifestParser; import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestParser;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.TrackKey; import com.google.android.exoplayer2.source.smoothstreaming.manifest.TrackKey;
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
...@@ -459,17 +460,22 @@ public class PlayerActivity extends Activity ...@@ -459,17 +460,22 @@ public class PlayerActivity extends Activity
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), new DefaultDashChunkSource.Factory(mediaDataSourceFactory),
buildDataSourceFactory(false)) buildDataSourceFactory(false))
.setManifestParser( .setManifestParser(
new FilteringDashManifestParser((List<RepresentationKey>) manifestFilter)) new FilteringManifestParser<>(
new DashManifestParser(), (List<RepresentationKey>) manifestFilter))
.createMediaSource(uri); .createMediaSource(uri);
case C.TYPE_SS: case C.TYPE_SS:
return new SsMediaSource.Factory( return new SsMediaSource.Factory(
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), new DefaultSsChunkSource.Factory(mediaDataSourceFactory),
buildDataSourceFactory(false)) buildDataSourceFactory(false))
.setManifestParser(new FilteringSsManifestParser((List<TrackKey>) manifestFilter)) .setManifestParser(
new FilteringManifestParser<>(
new SsManifestParser(), (List<TrackKey>) manifestFilter))
.createMediaSource(uri); .createMediaSource(uri);
case C.TYPE_HLS: case C.TYPE_HLS:
return new HlsMediaSource.Factory(mediaDataSourceFactory) return new HlsMediaSource.Factory(mediaDataSourceFactory)
.setPlaylistParser(new FilteringHlsPlaylistParser((List<RenditionKey>) manifestFilter)) .setPlaylistParser(
new FilteringManifestParser<>(
new HlsPlaylistParser(), (List<RenditionKey>) manifestFilter))
.createMediaSource(uri); .createMediaSource(uri);
case C.TYPE_OTHER: case C.TYPE_OTHER:
return new ExtractorMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri); return new ExtractorMediaSource.Factory(mediaDataSourceFactory).createMediaSource(uri);
......
/* /*
* Copyright (C) 2017 The Android Open Source Project * Copyright (C) 2018 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -13,35 +13,24 @@ ...@@ -13,35 +13,24 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.source.smoothstreaming.manifest; package com.google.android.exoplayer2.offline;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser;
import java.io.IOException;
import java.io.InputStream;
import java.util.List; import java.util.List;
/** /**
* A parser of SmoothStreaming manifest which includes only the tracks identified by the given keys. * A manifest that can generate copies of itself including only the tracks specified by the given
* track keys.
*
* @param <T> The manifest type.
* @param <K> The track key type.
*/ */
public final class FilteringSsManifestParser implements Parser<SsManifest> { public interface FilterableManifest<T, K> {
private final SsManifestParser ssManifestParser;
private final List<TrackKey> filter;
/** /**
* @param filter The track keys that should be retained in the parsed manifests. If null, all * Returns a copy of the manifest including only the tracks specified by the given track keys.
* tracks are retained. *
* @param trackKeys A non-empty list of track keys.
* @return The filtered manifest.
*/ */
public FilteringSsManifestParser(@Nullable List<TrackKey> filter) { T copy(List<K> trackKeys);
this.ssManifestParser = new SsManifestParser();
this.filter = filter;
}
@Override
public SsManifest parse(Uri uri, InputStream inputStream) throws IOException {
SsManifest manifest = ssManifestParser.parse(uri, inputStream);
return filter != null ? manifest.copy(filter) : manifest;
}
} }
...@@ -13,36 +13,33 @@ ...@@ -13,36 +13,33 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.google.android.exoplayer2.source.dash.manifest; package com.google.android.exoplayer2.offline;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.List; import java.util.List;
/** /** A manifest parser that includes only the tracks identified by the given track keys. */
* A parser of media presentation description files which includes only the representations public final class FilteringManifestParser<T extends FilterableManifest<T, K>, K>
* identified by the given keys. implements Parser<T> {
*/
public final class FilteringDashManifestParser implements Parser<DashManifest> {
private final DashManifestParser dashManifestParser; private final Parser<T> parser;
private final List<RepresentationKey> filter; private final List<K> trackKeys;
/** /**
* @param filter The representation keys that should be retained in the parsed manifests. If null, * @param parser A parser for the manifest that will be filtered.
* all representation are retained. * @param trackKeys The track keys. If null or empty then filtering will not occur.
*/ */
public FilteringDashManifestParser(@Nullable List<RepresentationKey> filter) { public FilteringManifestParser(Parser<T> parser, List<K> trackKeys) {
this.dashManifestParser = new DashManifestParser(); this.parser = parser;
this.filter = filter; this.trackKeys = trackKeys;
} }
@Override @Override
public DashManifest parse(Uri uri, InputStream inputStream) throws IOException { public T parse(Uri uri, InputStream inputStream) throws IOException {
DashManifest manifest = dashManifestParser.parse(uri, inputStream); T manifest = parser.parse(uri, inputStream);
return filter != null ? manifest.copy(filter) : manifest; return trackKeys == null || trackKeys.isEmpty() ? manifest : manifest.copy(trackKeys);
} }
} }
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.dash.manifest; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.dash.manifest;
import android.net.Uri; import android.net.Uri;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.offline.FilterableManifest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -26,7 +27,7 @@ import java.util.List; ...@@ -26,7 +27,7 @@ import java.util.List;
* Represents a DASH media presentation description (mpd), as defined by ISO/IEC 23009-1:2014 * Represents a DASH media presentation description (mpd), as defined by ISO/IEC 23009-1:2014
* Section 5.3.1.2. * Section 5.3.1.2.
*/ */
public class DashManifest { public class DashManifest implements FilterableManifest<DashManifest, RepresentationKey> {
/** /**
* The {@code availabilityStartTime} value in milliseconds since epoch, or {@link C#TIME_UNSET} if * The {@code availabilityStartTime} value in milliseconds since epoch, or {@link C#TIME_UNSET} if
......
/*
* Copyright (C) 2018 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.playlist;
import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/** A HLS playlists parser which includes only the renditions identified by the given urls. */
public final class FilteringHlsPlaylistParser implements Parser<HlsPlaylist> {
private final HlsPlaylistParser hlsPlaylistParser;
private final List<RenditionKey> filter;
/**
* @param filter The urls to renditions that should be retained in the parsed playlists. If null,
* all renditions are retained.
*/
public FilteringHlsPlaylistParser(@Nullable List<RenditionKey> filter) {
this.hlsPlaylistParser = new HlsPlaylistParser();
this.filter = filter;
}
@Override
public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException {
HlsPlaylist hlsPlaylist = hlsPlaylistParser.parse(uri, inputStream);
if (hlsPlaylist instanceof HlsMasterPlaylist) {
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) hlsPlaylist;
return filter != null ? masterPlaylist.copy(filter) : masterPlaylist;
} else {
return hlsPlaylist;
}
}
}
...@@ -254,6 +254,11 @@ public final class HlsMediaPlaylist extends HlsPlaylist { ...@@ -254,6 +254,11 @@ public final class HlsMediaPlaylist extends HlsPlaylist {
: startOffsetUs >= 0 ? startOffsetUs : durationUs + startOffsetUs; : startOffsetUs >= 0 ? startOffsetUs : durationUs + startOffsetUs;
} }
@Override
public HlsMediaPlaylist copy(List<RenditionKey> renditionKeys) {
return this;
}
/** /**
* Returns whether this playlist is newer than {@code other}. * Returns whether this playlist is newer than {@code other}.
* *
......
...@@ -15,13 +15,12 @@ ...@@ -15,13 +15,12 @@
*/ */
package com.google.android.exoplayer2.source.hls.playlist; package com.google.android.exoplayer2.source.hls.playlist;
import com.google.android.exoplayer2.offline.FilterableManifest;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
/** /** Represents an HLS playlist. */
* Represents an HLS playlist. public abstract class HlsPlaylist implements FilterableManifest<HlsPlaylist, RenditionKey> {
*/
public abstract class HlsPlaylist {
/** /**
* The base uri. Used to resolve relative paths. * The base uri. Used to resolve relative paths.
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.manifest; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.manifest;
import android.net.Uri; import android.net.Uri;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.offline.FilterableManifest;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.UriUtil; import com.google.android.exoplayer2.util.UriUtil;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -30,10 +31,10 @@ import java.util.UUID; ...@@ -30,10 +31,10 @@ import java.util.UUID;
/** /**
* Represents a SmoothStreaming manifest. * Represents a SmoothStreaming manifest.
* *
* @see <a href="http://msdn.microsoft.com/en-us/library/ee673436(v=vs.90).aspx"> * @see <a href="http://msdn.microsoft.com/en-us/library/ee673436(v=vs.90).aspx">IIS Smooth
* IIS Smooth Streaming Client Manifest Format</a> * Streaming Client Manifest Format</a>
*/ */
public class SsManifest { public class SsManifest implements FilterableManifest<SsManifest, TrackKey> {
public static final int UNSET_LOOKAHEAD = -1; public static final int UNSET_LOOKAHEAD = -1;
......
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