Get all track key objects into a consistent state
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=195421908
This commit is contained in:
parent
b8206a70e6
commit
0edc832d67
@ -294,9 +294,9 @@ public class DownloadActivity extends Activity {
|
||||
trackFormats.add(DUMMY_FORMAT);
|
||||
} else {
|
||||
HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist;
|
||||
addRepresentationItems(masterPlaylist.variants, RenditionKey.GROUP_VARIANTS);
|
||||
addRepresentationItems(masterPlaylist.audios, RenditionKey.GROUP_AUDIOS);
|
||||
addRepresentationItems(masterPlaylist.subtitles, RenditionKey.GROUP_SUBTITLES);
|
||||
addRepresentationItems(masterPlaylist.variants, RenditionKey.TYPE_VARIANT);
|
||||
addRepresentationItems(masterPlaylist.audios, RenditionKey.TYPE_AUDIO);
|
||||
addRepresentationItems(masterPlaylist.subtitles, RenditionKey.TYPE_SUBTITLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,43 @@ public final class RepresentationKey implements Parcelable, Comparable<Represent
|
||||
return periodIndex + "." + adaptationSetIndex + "." + representationIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RepresentationKey that = (RepresentationKey) o;
|
||||
return periodIndex == that.periodIndex
|
||||
&& adaptationSetIndex == that.adaptationSetIndex
|
||||
&& representationIndex == that.representationIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = periodIndex;
|
||||
result = 31 * result + adaptationSetIndex;
|
||||
result = 31 * result + representationIndex;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull RepresentationKey o) {
|
||||
int result = periodIndex - o.periodIndex;
|
||||
if (result == 0) {
|
||||
result = adaptationSetIndex - o.adaptationSetIndex;
|
||||
if (result == 0) {
|
||||
result = representationIndex - o.representationIndex;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Parcelable implementation.
|
||||
|
||||
@Override
|
||||
@ -67,41 +104,4 @@ public final class RepresentationKey implements Parcelable, Comparable<Represent
|
||||
}
|
||||
};
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull RepresentationKey o) {
|
||||
int result = periodIndex - o.periodIndex;
|
||||
if (result == 0) {
|
||||
result = adaptationSetIndex - o.adaptationSetIndex;
|
||||
if (result == 0) {
|
||||
result = representationIndex - o.representationIndex;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RepresentationKey that = (RepresentationKey) o;
|
||||
return periodIndex == that.periodIndex
|
||||
&& adaptationSetIndex == that.adaptationSetIndex
|
||||
&& representationIndex == that.representationIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = periodIndex;
|
||||
result = 31 * result + adaptationSetIndex;
|
||||
result = 31 * result + representationIndex;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public final class HlsDownloadAction extends SegmentDownloadAction<RenditionKey>
|
||||
|
||||
@Override
|
||||
protected void writeKey(DataOutputStream output, RenditionKey key) throws IOException {
|
||||
output.writeInt(key.renditionGroup);
|
||||
output.writeInt(key.type);
|
||||
output.writeInt(key.trackIndex);
|
||||
}
|
||||
|
||||
|
@ -119,9 +119,9 @@ public final class HlsMasterPlaylist extends HlsPlaylist<HlsMasterPlaylist> {
|
||||
return new HlsMasterPlaylist(
|
||||
baseUri,
|
||||
tags,
|
||||
copyRenditionsList(variants, RenditionKey.GROUP_VARIANTS, renditionKeys),
|
||||
copyRenditionsList(audios, RenditionKey.GROUP_AUDIOS, renditionKeys),
|
||||
copyRenditionsList(subtitles, RenditionKey.GROUP_SUBTITLES, renditionKeys),
|
||||
copyRenditionsList(variants, RenditionKey.TYPE_VARIANT, renditionKeys),
|
||||
copyRenditionsList(audios, RenditionKey.TYPE_AUDIO, renditionKeys),
|
||||
copyRenditionsList(subtitles, RenditionKey.TYPE_SUBTITLE, renditionKeys),
|
||||
muxedAudioFormat,
|
||||
muxedCaptionFormats);
|
||||
}
|
||||
@ -140,13 +140,13 @@ public final class HlsMasterPlaylist extends HlsPlaylist<HlsMasterPlaylist> {
|
||||
}
|
||||
|
||||
private static List<HlsUrl> copyRenditionsList(
|
||||
List<HlsUrl> renditions, int renditionGroup, List<RenditionKey> renditionKeys) {
|
||||
List<HlsUrl> renditions, int renditionType, List<RenditionKey> renditionKeys) {
|
||||
List<HlsUrl> copiedRenditions = new ArrayList<>(renditionKeys.size());
|
||||
for (int i = 0; i < renditions.size(); i++) {
|
||||
HlsUrl rendition = renditions.get(i);
|
||||
for (int j = 0; j < renditionKeys.size(); j++) {
|
||||
RenditionKey renditionKey = renditionKeys.get(j);
|
||||
if (renditionKey.renditionGroup == renditionGroup && renditionKey.trackIndex == i) {
|
||||
if (renditionKey.type == renditionType && renditionKey.trackIndex == i) {
|
||||
copiedRenditions.add(rendition);
|
||||
break;
|
||||
}
|
||||
|
@ -17,23 +17,68 @@ package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/** Uniquely identifies a rendition in an {@link HlsMasterPlaylist}. */
|
||||
public final class RenditionKey implements Parcelable, Comparable<RenditionKey> {
|
||||
|
||||
public static final int GROUP_VARIANTS = 0;
|
||||
public static final int GROUP_AUDIOS = 1;
|
||||
public static final int GROUP_SUBTITLES = 2;
|
||||
/** Types of rendition. */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({TYPE_VARIANT, TYPE_AUDIO, TYPE_SUBTITLE})
|
||||
public @interface Type {}
|
||||
|
||||
public final int renditionGroup;
|
||||
public static final int TYPE_VARIANT = 0;
|
||||
public static final int TYPE_AUDIO = 1;
|
||||
public static final int TYPE_SUBTITLE = 2;
|
||||
|
||||
public final @Type int type;
|
||||
public final int trackIndex;
|
||||
|
||||
public RenditionKey(int renditionGroup, int trackIndex) {
|
||||
this.renditionGroup = renditionGroup;
|
||||
public RenditionKey(@Type int type, int trackIndex) {
|
||||
this.type = type;
|
||||
this.trackIndex = trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type + "." + trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RenditionKey that = (RenditionKey) o;
|
||||
return type == that.type && trackIndex == that.trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = type;
|
||||
result = 31 * result + trackIndex;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull RenditionKey other) {
|
||||
int result = type - other.type;
|
||||
if (result == 0) {
|
||||
result = trackIndex - other.trackIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Parcelable implementation.
|
||||
|
||||
@Override
|
||||
@ -43,7 +88,7 @@ public final class RenditionKey implements Parcelable, Comparable<RenditionKey>
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(renditionGroup);
|
||||
dest.writeInt(type);
|
||||
dest.writeInt(trackIndex);
|
||||
}
|
||||
|
||||
@ -59,15 +104,4 @@ public final class RenditionKey implements Parcelable, Comparable<RenditionKey>
|
||||
return new RenditionKey[size];
|
||||
}
|
||||
};
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull RenditionKey other) {
|
||||
int result = renditionGroup - other.renditionGroup;
|
||||
if (result == 0) {
|
||||
result = trackIndex - other.trackIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class HlsDownloaderTest {
|
||||
private static ArrayList<RenditionKey> getKeys(int... variantIndices) {
|
||||
ArrayList<RenditionKey> renditionKeys = new ArrayList<>();
|
||||
for (int variantIndex : variantIndices) {
|
||||
renditionKeys.add(new RenditionKey(RenditionKey.GROUP_VARIANTS, variantIndex));
|
||||
renditionKeys.add(new RenditionKey(RenditionKey.TYPE_VARIANT, variantIndex));
|
||||
}
|
||||
return renditionKeys;
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.smoothstreaming.manifest;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Uniquely identifies a track in a {@link SsManifest}.
|
||||
@ -37,6 +38,37 @@ public final class TrackKey implements Parcelable, Comparable<TrackKey> {
|
||||
return streamElementIndex + "." + trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TrackKey that = (TrackKey) o;
|
||||
return streamElementIndex == that.streamElementIndex && trackIndex == that.trackIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = streamElementIndex;
|
||||
result = 31 * result + trackIndex;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull TrackKey o) {
|
||||
int result = streamElementIndex - o.streamElementIndex;
|
||||
if (result == 0) {
|
||||
result = trackIndex - o.trackIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Parcelable implementation.
|
||||
|
||||
@Override
|
||||
@ -61,16 +93,4 @@ public final class TrackKey implements Parcelable, Comparable<TrackKey> {
|
||||
return new TrackKey[size];
|
||||
}
|
||||
};
|
||||
|
||||
// Comparable implementation.
|
||||
|
||||
@Override
|
||||
public int compareTo(@NonNull TrackKey o) {
|
||||
int result = streamElementIndex - o.streamElementIndex;
|
||||
if (result == 0) {
|
||||
result = trackIndex - o.trackIndex;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user