diff --git a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastUtils.java b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastUtils.java index 6ace54fea5..f17c39bdbf 100644 --- a/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastUtils.java +++ b/extensions/cast/src/main/java/com/google/android/exoplayer2/ext/cast/CastUtils.java @@ -20,17 +20,12 @@ import com.google.android.exoplayer2.Format; import com.google.android.gms.cast.CastStatusCodes; import com.google.android.gms.cast.MediaInfo; import com.google.android.gms.cast.MediaTrack; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; /** * Utility methods for ExoPlayer/Cast integration. */ /* package */ final class CastUtils { - private static final Map CAST_STATUS_CODE_TO_STRING; - /** * Returns the duration in microseconds advertised by a media info, or {@link C#TIME_UNSET} if * unknown or not applicable. @@ -53,8 +48,49 @@ import java.util.Map; * {@link CastStatusCodes}. */ public static String getLogString(int statusCode) { - String description = CAST_STATUS_CODE_TO_STRING.get(statusCode); - return description != null ? description : "Unknown."; + switch (statusCode) { + case CastStatusCodes.APPLICATION_NOT_FOUND: + return "A requested application could not be found."; + case CastStatusCodes.APPLICATION_NOT_RUNNING: + return "A requested application is not currently running."; + case CastStatusCodes.AUTHENTICATION_FAILED: + return "Authentication failure."; + case CastStatusCodes.CANCELED: + return "An in-progress request has been canceled, most likely because another action has " + + "preempted it."; + case CastStatusCodes.ERROR_SERVICE_CREATION_FAILED: + return "The Cast Remote Display service could not be created."; + case CastStatusCodes.ERROR_SERVICE_DISCONNECTED: + return "The Cast Remote Display service was disconnected."; + case CastStatusCodes.FAILED: + return "The in-progress request failed."; + case CastStatusCodes.INTERNAL_ERROR: + return "An internal error has occurred."; + case CastStatusCodes.INTERRUPTED: + return "A blocking call was interrupted while waiting and did not run to completion."; + case CastStatusCodes.INVALID_REQUEST: + return "An invalid request was made."; + case CastStatusCodes.MESSAGE_SEND_BUFFER_TOO_FULL: + return "A message could not be sent because there is not enough room in the send buffer at " + + "this time."; + case CastStatusCodes.MESSAGE_TOO_LARGE: + return "A message could not be sent because it is too large."; + case CastStatusCodes.NETWORK_ERROR: + return "Network I/O error."; + case CastStatusCodes.NOT_ALLOWED: + return "The request was disallowed and could not be completed."; + case CastStatusCodes.REPLACED: + return "The request's progress is no longer being tracked because another request of the " + + "same type has been made before the first request completed."; + case CastStatusCodes.SUCCESS: + return "Success."; + case CastStatusCodes.TIMEOUT: + return "An operation has timed out."; + case CastStatusCodes.UNKNOWN_ERROR: + return "An unknown, unexpected error has occurred."; + default: + return "Unknown: " + statusCode; + } } /** @@ -69,41 +105,6 @@ import java.util.Map; null, null, Format.NO_VALUE, 0, mediaTrack.getLanguage()); } - static { - HashMap statusCodeToString = new HashMap<>(); - statusCodeToString.put(CastStatusCodes.APPLICATION_NOT_FOUND, - "A requested application could not be found."); - statusCodeToString.put(CastStatusCodes.APPLICATION_NOT_RUNNING, - "A requested application is not currently running."); - statusCodeToString.put(CastStatusCodes.AUTHENTICATION_FAILED, "Authentication failure."); - statusCodeToString.put(CastStatusCodes.CANCELED, "An in-progress request has been " - + "canceled, most likely because another action has preempted it."); - statusCodeToString.put(CastStatusCodes.ERROR_SERVICE_CREATION_FAILED, - "The Cast Remote Display service could not be created."); - statusCodeToString.put(CastStatusCodes.ERROR_SERVICE_DISCONNECTED, - "The Cast Remote Display service was disconnected."); - statusCodeToString.put(CastStatusCodes.FAILED, "The in-progress request failed."); - statusCodeToString.put(CastStatusCodes.INTERNAL_ERROR, "An internal error has occurred."); - statusCodeToString.put(CastStatusCodes.INTERRUPTED, - "A blocking call was interrupted while waiting and did not run to completion."); - statusCodeToString.put(CastStatusCodes.INVALID_REQUEST, "An invalid request was made."); - statusCodeToString.put(CastStatusCodes.MESSAGE_SEND_BUFFER_TOO_FULL, "A message could " - + "not be sent because there is not enough room in the send buffer at this time."); - statusCodeToString.put(CastStatusCodes.MESSAGE_TOO_LARGE, - "A message could not be sent because it is too large."); - statusCodeToString.put(CastStatusCodes.NETWORK_ERROR, "Network I/O error."); - statusCodeToString.put(CastStatusCodes.NOT_ALLOWED, - "The request was disallowed and could not be completed."); - statusCodeToString.put(CastStatusCodes.REPLACED, - "The request's progress is no longer being tracked because another request of the same type" - + " has been made before the first request completed."); - statusCodeToString.put(CastStatusCodes.SUCCESS, "Success."); - statusCodeToString.put(CastStatusCodes.TIMEOUT, "An operation has timed out."); - statusCodeToString.put(CastStatusCodes.UNKNOWN_ERROR, - "An unknown, unexpected error has occurred."); - CAST_STATUS_CODE_TO_STRING = Collections.unmodifiableMap(statusCodeToString); - } - private CastUtils() {} } diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java index 4dab4e2279..d6d6ca821c 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java @@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.dash; import android.support.annotation.IntDef; import android.util.Pair; +import android.util.SparseArray; import android.util.SparseIntArray; import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.Format; @@ -48,10 +49,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; -import java.util.Map; /** A DASH {@link MediaPeriod}. */ /* package */ final class DashMediaPeriod @@ -182,7 +181,7 @@ import java.util.Map; @Override public long selectTracks(TrackSelection[] selections, boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, long positionUs) { - Map> primarySampleStreams = new HashMap<>(); + SparseArray> primarySampleStreams = new SparseArray<>(); List eventSampleStreamList = new ArrayList<>(); selectPrimarySampleStreams(selections, mayRetainStreamFlags, streams, streamResetFlags, @@ -193,7 +192,9 @@ import java.util.Map; positionUs, primarySampleStreams); sampleStreams = newSampleStreamArray(primarySampleStreams.size()); - primarySampleStreams.values().toArray(sampleStreams); + for (int i = 0; i < sampleStreams.length; i++) { + sampleStreams[i] = primarySampleStreams.valueAt(i); + } eventSampleStreams = new EventSampleStream[eventSampleStreamList.size()]; eventSampleStreamList.toArray(eventSampleStreams); compositeSequenceableLoader = @@ -201,9 +202,13 @@ import java.util.Map; return positionUs; } - private void selectPrimarySampleStreams(TrackSelection[] selections, - boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, - long positionUs, Map> primarySampleStreams) { + private void selectPrimarySampleStreams( + TrackSelection[] selections, + boolean[] mayRetainStreamFlags, + SampleStream[] streams, + boolean[] streamResetFlags, + long positionUs, + SparseArray> primarySampleStreams) { for (int i = 0; i < selections.length; i++) { if (streams[i] instanceof ChunkSampleStream) { @SuppressWarnings("unchecked") @@ -259,9 +264,13 @@ import java.util.Map; } } - private void selectEmbeddedSampleStreams(TrackSelection[] selections, - boolean[] mayRetainStreamFlags, SampleStream[] streams, boolean[] streamResetFlags, - long positionUs, Map> primarySampleStreams) { + private void selectEmbeddedSampleStreams( + TrackSelection[] selections, + boolean[] mayRetainStreamFlags, + SampleStream[] streams, + boolean[] streamResetFlags, + long positionUs, + SparseArray> primarySampleStreams) { for (int i = 0; i < selections.length; i++) { if ((streams[i] instanceof EmbeddedSampleStream || streams[i] instanceof EmptySampleStream) && (selections[i] == null || !mayRetainStreamFlags[i])) {