diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/FilteringDashManifestParser.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/FilteringDashManifestParser.java new file mode 100644 index 0000000000..84c899f6c2 --- /dev/null +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/FilteringDashManifestParser.java @@ -0,0 +1,43 @@ +/* + * 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.dash.manifest; + +import android.net.Uri; +import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; + +/** + * A parser of media presentation description files which includes only the representations + * identified by the given keys. + */ +public final class FilteringDashManifestParser implements Parser { + + private final DashManifestParser dashManifestParser; + private final ArrayList filter; + + /** @param filter The representation keys that should be retained in the parsed manifests. */ + public FilteringDashManifestParser(ArrayList filter) { + this.dashManifestParser = new DashManifestParser(); + this.filter = filter; + } + + @Override + public DashManifest parse(Uri uri, InputStream inputStream) throws IOException { + return dashManifestParser.parse(uri, inputStream).copy(filter); + } +} diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/FilteringHlsPlaylistParser.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/FilteringHlsPlaylistParser.java new file mode 100644 index 0000000000..d57363b257 --- /dev/null +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/FilteringHlsPlaylistParser.java @@ -0,0 +1,47 @@ +/* + * 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 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 { + + private final HlsPlaylistParser hlsPlaylistParser; + private final List filter; + + /** @param filter The urls to renditions that should be retained in the parsed playlists. */ + public FilteringHlsPlaylistParser(List filter) { + this.hlsPlaylistParser = new HlsPlaylistParser(); + this.filter = filter; + } + + @Override + public HlsPlaylist parse(Uri uri, InputStream inputStream) throws IOException { + HlsPlaylist hlsPlaylist = hlsPlaylistParser.parse(uri, inputStream); + HlsMasterPlaylist hlsMasterPlaylist; + if (hlsPlaylist instanceof HlsMasterPlaylist) { + hlsMasterPlaylist = (HlsMasterPlaylist) hlsPlaylist; + } else { + hlsMasterPlaylist = HlsMasterPlaylist.createSingleVariantMasterPlaylist(hlsPlaylist.baseUri); + } + return hlsMasterPlaylist.copy(filter); + } +} diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/FilteringSsManifestParser.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/FilteringSsManifestParser.java new file mode 100644 index 0000000000..eed040df97 --- /dev/null +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/FilteringSsManifestParser.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2017 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.smoothstreaming.manifest; + +import android.net.Uri; +import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; + +/** + * A parser of SmoothStreaming manifest which includes only the tracks identified by the given keys. + */ +public final class FilteringSsManifestParser implements Parser { + + private final SsManifestParser ssManifestParser; + private final List filter; + + /** @param filter The track keys that should be retained in the parsed manifests. */ + public FilteringSsManifestParser(List filter) { + this.ssManifestParser = new SsManifestParser(); + this.filter = filter; + } + + @Override + public SsManifest parse(Uri uri, InputStream inputStream) throws IOException { + return ssManifestParser.parse(uri, inputStream).copy(filter); + } +}