Commit 928cbfa7 by tonihei Committed by Oliver Woodman

Replace hash by Object reference for uids.

There is the small (but unlikely) chance that the uids clash because the
Objects have the same hash code.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=198855724
parent 7d076924
...@@ -19,7 +19,6 @@ import android.os.Handler; ...@@ -19,7 +19,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.SparseIntArray;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ExoPlayer;
...@@ -34,6 +33,7 @@ import java.util.ArrayList; ...@@ -34,6 +33,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.IdentityHashMap; import java.util.IdentityHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -656,7 +656,7 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -656,7 +656,7 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
/* package */ static final class MediaSourceHolder implements Comparable<MediaSourceHolder> { /* package */ static final class MediaSourceHolder implements Comparable<MediaSourceHolder> {
public final MediaSource mediaSource; public final MediaSource mediaSource;
public final int uid; public final Object uid;
public DeferredTimeline timeline; public DeferredTimeline timeline;
public int childIndex; public int childIndex;
...@@ -671,6 +671,7 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -671,6 +671,7 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
this.uid = System.identityHashCode(this); this.uid = System.identityHashCode(this);
this.timeline = new DeferredTimeline(); this.timeline = new DeferredTimeline();
this.activeMediaPeriods = new ArrayList<>(); this.activeMediaPeriods = new ArrayList<>();
this.uid = new Object();
} }
public void reset(int childIndex, int firstWindowIndexInChild, int firstPeriodIndexInChild) { public void reset(int childIndex, int firstWindowIndexInChild, int firstPeriodIndexInChild) {
...@@ -728,8 +729,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -728,8 +729,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
private final int[] firstPeriodInChildIndices; private final int[] firstPeriodInChildIndices;
private final int[] firstWindowInChildIndices; private final int[] firstWindowInChildIndices;
private final Timeline[] timelines; private final Timeline[] timelines;
private final int[] uids; private final Object[] uids;
private final SparseIntArray childIndexByUid; private final HashMap<Object, Integer> childIndexByUid;
public ConcatenatedTimeline( public ConcatenatedTimeline(
Collection<MediaSourceHolder> mediaSourceHolders, Collection<MediaSourceHolder> mediaSourceHolders,
...@@ -744,8 +745,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -744,8 +745,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
firstPeriodInChildIndices = new int[childCount]; firstPeriodInChildIndices = new int[childCount];
firstWindowInChildIndices = new int[childCount]; firstWindowInChildIndices = new int[childCount];
timelines = new Timeline[childCount]; timelines = new Timeline[childCount];
uids = new int[childCount]; uids = new Object[childCount];
childIndexByUid = new SparseIntArray(); childIndexByUid = new HashMap<>();
int index = 0; int index = 0;
for (MediaSourceHolder mediaSourceHolder : mediaSourceHolders) { for (MediaSourceHolder mediaSourceHolder : mediaSourceHolders) {
timelines[index] = mediaSourceHolder.timeline; timelines[index] = mediaSourceHolder.timeline;
...@@ -768,11 +769,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -768,11 +769,8 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
@Override @Override
protected int getChildIndexByChildUid(Object childUid) { protected int getChildIndexByChildUid(Object childUid) {
if (!(childUid instanceof Integer)) { Integer index = childIndexByUid.get(childUid);
return C.INDEX_UNSET; return index == null ? C.INDEX_UNSET : index;
}
int index = childIndexByUid.get((int) childUid, -1);
return index == -1 ? C.INDEX_UNSET : index;
} }
@Override @Override
...@@ -804,7 +802,6 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo ...@@ -804,7 +802,6 @@ public class ConcatenatingMediaSource extends CompositeMediaSource<MediaSourceHo
public int getPeriodCount() { public int getPeriodCount() {
return periodCount; return periodCount;
} }
} }
/** /**
......
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