mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
Add filtering manifest parsers for DASH, HLS and SmoothStreaming
These parsers can be used to get a manifest which includes only the representations identified by the given keys. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=182932874
This commit is contained in:
parent
4671c23c4d
commit
8b79028880
3 changed files with 132 additions and 0 deletions
|
|
@ -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<DashManifest> {
|
||||
|
||||
private final DashManifestParser dashManifestParser;
|
||||
private final ArrayList<RepresentationKey> filter;
|
||||
|
||||
/** @param filter The representation keys that should be retained in the parsed manifests. */
|
||||
public FilteringDashManifestParser(ArrayList<RepresentationKey> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<HlsPlaylist> {
|
||||
|
||||
private final HlsPlaylistParser hlsPlaylistParser;
|
||||
private final List<String> filter;
|
||||
|
||||
/** @param filter The urls to renditions that should be retained in the parsed playlists. */
|
||||
public FilteringHlsPlaylistParser(List<String> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<SsManifest> {
|
||||
|
||||
private final SsManifestParser ssManifestParser;
|
||||
private final List<TrackKey> filter;
|
||||
|
||||
/** @param filter The track keys that should be retained in the parsed manifests. */
|
||||
public FilteringSsManifestParser(List<TrackKey> 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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue