mirror of
https://github.com/samsonjs/media.git
synced 2026-04-06 11:25:46 +00:00
Remove TrackKey and its remaining usages.
This is no longer needed as the public API uses TrackSelection as the way to specify selected tracks. PiperOrigin-RevId: 225158867
This commit is contained in:
parent
8cedfc46fb
commit
c03b7e32e2
7 changed files with 34 additions and 135 deletions
|
|
@ -281,7 +281,7 @@ public abstract class DownloadHelper<T> {
|
|||
public final DownloadAction getDownloadAction(@Nullable byte[] data) {
|
||||
Assertions.checkNotNull(trackSelectionsByPeriodAndRenderer);
|
||||
Assertions.checkNotNull(trackGroupArrays);
|
||||
List<TrackKey> trackKeys = new ArrayList<>();
|
||||
List<StreamKey> streamKeys = new ArrayList<>();
|
||||
int periodCount = trackSelectionsByPeriodAndRenderer.length;
|
||||
for (int periodIndex = 0; periodIndex < periodCount; periodIndex++) {
|
||||
int rendererCount = trackSelectionsByPeriodAndRenderer[periodIndex].length;
|
||||
|
|
@ -295,27 +295,12 @@ public abstract class DownloadHelper<T> {
|
|||
int trackCount = trackSelection.length();
|
||||
for (int trackListIndex = 0; trackListIndex < trackCount; trackListIndex++) {
|
||||
int trackIndex = trackSelection.getIndexInTrackGroup(trackListIndex);
|
||||
trackKeys.add(new TrackKey(periodIndex, trackGroupIndex, trackIndex));
|
||||
streamKeys.add(toStreamKey(periodIndex, trackGroupIndex, trackIndex));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DownloadAction.createDownloadAction(
|
||||
downloadType, uri, toStreamKeys(trackKeys), cacheKey, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a {@link DownloadAction} for downloading the specified tracks. Must not be called until
|
||||
* after preparation completes.
|
||||
*
|
||||
* @param data Application provided data to store in {@link DownloadAction#data}.
|
||||
* @param trackKeys The selected tracks. If empty, all streams will be downloaded.
|
||||
* @return The built {@link DownloadAction}.
|
||||
*/
|
||||
public final DownloadAction getDownloadAction(@Nullable byte[] data, List<TrackKey> trackKeys) {
|
||||
// TODO: Remove as soon as all usages have been updated to new getDownloadAction method.
|
||||
return DownloadAction.createDownloadAction(
|
||||
downloadType, uri, toStreamKeys(trackKeys), cacheKey, data);
|
||||
return DownloadAction.createDownloadAction(downloadType, uri, streamKeys, cacheKey, data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -344,12 +329,15 @@ public abstract class DownloadHelper<T> {
|
|||
protected abstract TrackGroupArray[] getTrackGroupArrays(T manifest);
|
||||
|
||||
/**
|
||||
* Converts a list of {@link TrackKey track keys} to {@link StreamKey stream keys}.
|
||||
* Converts a track of a track group of a period to the corresponding {@link StreamKey}.
|
||||
*
|
||||
* @param trackKeys A list of track keys.
|
||||
* @return A corresponding list of stream keys.
|
||||
* @param periodIndex The index of the containing period.
|
||||
* @param trackGroupIndex The index of the containing track group within the period.
|
||||
* @param trackIndexInTrackGroup The index of the track within the track group.
|
||||
* @return The corresponding {@link StreamKey}.
|
||||
*/
|
||||
protected abstract List<StreamKey> toStreamKeys(List<TrackKey> trackKeys);
|
||||
protected abstract StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@EnsuresNonNull("trackSelectionsByPeriodAndRenderer")
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ import android.net.Uri;
|
|||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.Renderer;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** A {@link DownloadHelper} for progressive streams. */
|
||||
public final class ProgressiveDownloadHelper extends DownloadHelper<Void> {
|
||||
|
|
@ -61,7 +59,8 @@ public final class ProgressiveDownloadHelper extends DownloadHelper<Void> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
|
||||
return Collections.emptyList();
|
||||
protected StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup) {
|
||||
return new StreamKey(periodIndex, trackGroupIndex, trackIndexInTrackGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* 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.offline;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Identifies a given track by the index of the containing period, the index of the containing group
|
||||
* within the period, and the index of the track within the group.
|
||||
*/
|
||||
public final class TrackKey {
|
||||
|
||||
/** The period index. */
|
||||
public final int periodIndex;
|
||||
/** The group index. */
|
||||
public final int groupIndex;
|
||||
/** The track index. */
|
||||
public final int trackIndex;
|
||||
|
||||
/**
|
||||
* @param periodIndex The period index.
|
||||
* @param groupIndex The group index.
|
||||
* @param trackIndex The track index.
|
||||
*/
|
||||
public TrackKey(int periodIndex, int groupIndex, int trackIndex) {
|
||||
this.periodIndex = periodIndex;
|
||||
this.groupIndex = groupIndex;
|
||||
this.trackIndex = trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
if (other == null || getClass() != other.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TrackKey that = (TrackKey) other;
|
||||
return periodIndex == that.periodIndex
|
||||
&& groupIndex == that.groupIndex
|
||||
&& trackIndex == that.trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * (31 * periodIndex + groupIndex) + trackIndex;
|
||||
}
|
||||
}
|
||||
|
|
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.offline;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.Renderer;
|
||||
|
|
@ -50,8 +49,6 @@ public class DownloadHelperTest {
|
|||
private static final String TEST_DOWNLOAD_TYPE = "downloadType";
|
||||
private static final String TEST_CACHE_KEY = "cacheKey";
|
||||
private static final ManifestType TEST_MANIFEST = new ManifestType();
|
||||
private static final List<StreamKey> testStreamKeys =
|
||||
Arrays.asList(new StreamKey(0, 1, 2), new StreamKey(1, 3, 4));
|
||||
|
||||
private static final Format VIDEO_FORMAT_LOW = createVideoFormat(/* bitrate= */ 200_000);
|
||||
private static final Format VIDEO_FORMAT_HIGH = createVideoFormat(/* bitrate= */ 800_000);
|
||||
|
|
@ -313,16 +310,15 @@ public class DownloadHelperTest {
|
|||
assertThat(downloadAction.customCacheKey).isEqualTo(TEST_CACHE_KEY);
|
||||
assertThat(downloadAction.isRemoveAction).isFalse();
|
||||
assertThat(downloadAction.data).isEqualTo(data);
|
||||
assertThat(downloadAction.keys).isEqualTo(testStreamKeys);
|
||||
assertThat(downloadHelper.lastCreatedTrackKeys)
|
||||
assertThat(downloadAction.keys)
|
||||
.containsExactly(
|
||||
new TrackKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
||||
new TrackKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),
|
||||
new TrackKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 0),
|
||||
new TrackKey(/* periodIndex= */ 0, /* groupIndex= */ 2, /* trackIndex= */ 0),
|
||||
new TrackKey(/* periodIndex= */ 0, /* groupIndex= */ 3, /* trackIndex= */ 0),
|
||||
new TrackKey(/* periodIndex= */ 1, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
||||
new TrackKey(/* periodIndex= */ 1, /* groupIndex= */ 1, /* trackIndex= */ 0));
|
||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 0, /* trackIndex= */ 1),
|
||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 1, /* trackIndex= */ 0),
|
||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 2, /* trackIndex= */ 0),
|
||||
new StreamKey(/* periodIndex= */ 0, /* groupIndex= */ 3, /* trackIndex= */ 0),
|
||||
new StreamKey(/* periodIndex= */ 1, /* groupIndex= */ 0, /* trackIndex= */ 0),
|
||||
new StreamKey(/* periodIndex= */ 1, /* groupIndex= */ 1, /* trackIndex= */ 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -419,8 +415,6 @@ public class DownloadHelperTest {
|
|||
|
||||
private static final class FakeDownloadHelper extends DownloadHelper<ManifestType> {
|
||||
|
||||
@Nullable public List<TrackKey> lastCreatedTrackKeys;
|
||||
|
||||
public FakeDownloadHelper(Uri testUri, RenderersFactory renderersFactory) {
|
||||
super(
|
||||
TEST_DOWNLOAD_TYPE,
|
||||
|
|
@ -443,9 +437,9 @@ public class DownloadHelperTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
|
||||
lastCreatedTrackKeys = trackKeys;
|
||||
return testStreamKeys;
|
||||
protected StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup) {
|
||||
return new StreamKey(periodIndex, trackGroupIndex, trackIndexInTrackGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
|||
import com.google.android.exoplayer2.offline.DownloadAction;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.offline.TrackKey;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.AdaptationSet;
|
||||
|
|
@ -36,7 +35,6 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
|||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A {@link DownloadHelper} for DASH streams. */
|
||||
|
|
@ -121,12 +119,8 @@ public final class DashDownloadHelper extends DownloadHelper<DashManifest> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
|
||||
List<StreamKey> streamKeys = new ArrayList<>(trackKeys.size());
|
||||
for (int i = 0; i < trackKeys.size(); i++) {
|
||||
TrackKey trackKey = trackKeys.get(i);
|
||||
streamKeys.add(new StreamKey(trackKey.periodIndex, trackKey.groupIndex, trackKey.trackIndex));
|
||||
}
|
||||
return streamKeys;
|
||||
protected StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup) {
|
||||
return new StreamKey(periodIndex, trackGroupIndex, trackIndexInTrackGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
|||
import com.google.android.exoplayer2.offline.DownloadAction;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.offline.TrackKey;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist;
|
||||
|
|
@ -37,7 +36,6 @@ import com.google.android.exoplayer2.upstream.DataSource;
|
|||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -110,7 +108,7 @@ public final class HlsDownloadHelper extends DownloadHelper<HlsPlaylist> {
|
|||
renditionGroups = new int[0];
|
||||
return new TrackGroupArray[] {TrackGroupArray.EMPTY};
|
||||
}
|
||||
// TODO: Generate track groups as in playback. Reverse the mapping in getDownloadAction.
|
||||
// TODO: Generate track groups as in playback. Reverse the mapping in toStreamKey.
|
||||
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist;
|
||||
TrackGroup[] trackGroups = new TrackGroup[3];
|
||||
renditionGroups = new int[3];
|
||||
|
|
@ -131,14 +129,9 @@ public final class HlsDownloadHelper extends DownloadHelper<HlsPlaylist> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
|
||||
List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
|
||||
for (int i = 0; i < trackKeys.size(); i++) {
|
||||
TrackKey trackKey = trackKeys.get(i);
|
||||
representationKeys.add(
|
||||
new StreamKey(renditionGroups[trackKey.groupIndex], trackKey.trackIndex));
|
||||
}
|
||||
return representationKeys;
|
||||
protected StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup) {
|
||||
return new StreamKey(renditionGroups[trackGroupIndex], trackIndexInTrackGroup);
|
||||
}
|
||||
|
||||
private static Format[] toFormats(List<HlsMasterPlaylist.HlsUrl> hlsUrls) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
|||
import com.google.android.exoplayer2.offline.DownloadAction;
|
||||
import com.google.android.exoplayer2.offline.DownloadHelper;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.offline.TrackKey;
|
||||
import com.google.android.exoplayer2.source.TrackGroup;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
|
||||
|
|
@ -34,8 +33,6 @@ import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
|||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/** A {@link DownloadHelper} for SmoothStreaming streams. */
|
||||
public final class SsDownloadHelper extends DownloadHelper<SsManifest> {
|
||||
|
|
@ -109,12 +106,8 @@ public final class SsDownloadHelper extends DownloadHelper<SsManifest> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<StreamKey> toStreamKeys(List<TrackKey> trackKeys) {
|
||||
List<StreamKey> representationKeys = new ArrayList<>(trackKeys.size());
|
||||
for (int i = 0; i < trackKeys.size(); i++) {
|
||||
TrackKey trackKey = trackKeys.get(i);
|
||||
representationKeys.add(new StreamKey(trackKey.groupIndex, trackKey.trackIndex));
|
||||
}
|
||||
return representationKeys;
|
||||
protected StreamKey toStreamKey(
|
||||
int periodIndex, int trackGroupIndex, int trackIndexInTrackGroup) {
|
||||
return new StreamKey(trackGroupIndex, trackIndexInTrackGroup);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue