Add Guava dependency to ExoPlayer
Guava is heavily optimized for Android and the impact on binary size is minimal (and outweighed by the organic growth of the ExoPlayer library). This change also replaces Util.toArray() with Guava's Ints.toArray() in order to introduce a Guava usage into a range of modules. PiperOrigin-RevId: 312449093
This commit is contained in:
parent
e87221c938
commit
b9157a9e23
@ -227,6 +227,7 @@
|
||||
* MediaSession extension: Set session playback state to BUFFERING only when
|
||||
actually playing ([#7367](https://github.com/google/ExoPlayer/pull/7367),
|
||||
[#7206](https://github.com/google/ExoPlayer/issues/7206)).
|
||||
* Add Guava dependency.
|
||||
|
||||
### 2.11.4 (2020-04-08)
|
||||
|
||||
|
@ -21,7 +21,7 @@ project.ext {
|
||||
compileSdkVersion = 29
|
||||
dexmakerVersion = '2.21.0'
|
||||
junitVersion = '4.13-rc-2'
|
||||
guavaVersion = '28.2-android'
|
||||
guavaVersion = '27.1-android'
|
||||
mockitoVersion = '2.25.0'
|
||||
robolectricVersion = '4.4-SNAPSHOT'
|
||||
checkerframeworkVersion = '2.5.0'
|
||||
|
@ -11,6 +11,7 @@
|
||||
// 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.
|
||||
apply from: "${buildscript.sourceFile.parentFile}/constants.gradle"
|
||||
apply from: "${buildscript.sourceFile.parentFile}/javadoc_util.gradle"
|
||||
|
||||
class CombinedJavadocPlugin implements Plugin<Project> {
|
||||
@ -29,7 +30,8 @@ class CombinedJavadocPlugin implements Plugin<Project> {
|
||||
classpath = project.files([])
|
||||
destinationDir = project.file("$project.buildDir/docs/javadoc")
|
||||
options {
|
||||
links "https://developer.android.com/reference"
|
||||
links "https://developer.android.com/reference",
|
||||
"https://guava.dev/releases/$project.ext.guavaVersion/api/docs"
|
||||
encoding = "UTF-8"
|
||||
}
|
||||
exclude "**/BuildConfig.java"
|
||||
|
@ -11,6 +11,7 @@
|
||||
// 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.
|
||||
apply from: "${buildscript.sourceFile.parentFile}/constants.gradle"
|
||||
apply from: "${buildscript.sourceFile.parentFile}/javadoc_util.gradle"
|
||||
|
||||
android.libraryVariants.all { variant ->
|
||||
@ -26,7 +27,8 @@ android.libraryVariants.all { variant ->
|
||||
title = "ExoPlayer ${javadocTitle}"
|
||||
source = allSourceDirs
|
||||
options {
|
||||
links "https://developer.android.com/reference"
|
||||
links "https://developer.android.com/reference",
|
||||
"https://guava.dev/releases/$project.ext.guavaVersion/api/docs"
|
||||
encoding = "UTF-8"
|
||||
}
|
||||
exclude "**/BuildConfig.java"
|
||||
|
@ -39,6 +39,7 @@ android {
|
||||
dependencies {
|
||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
||||
compileOnly 'com.google.guava:guava:' + guavaVersion
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||
|
@ -53,6 +53,7 @@ import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.MediaItem;
|
||||
import com.google.android.exoplayer2.ParserException;
|
||||
import com.google.android.exoplayer2.upstream.DataSource;
|
||||
import com.google.common.base.Ascii;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@ -63,7 +64,6 @@ import java.math.BigDecimal;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
@ -1234,41 +1234,6 @@ public final class Util {
|
||||
return Math.round((double) mediaDuration / speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a list of integers to a primitive array.
|
||||
*
|
||||
* @param list A list of integers.
|
||||
* @return The list in array form, or null if the input list was null.
|
||||
*/
|
||||
public static int @PolyNull [] toArray(@PolyNull List<Integer> list) {
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
int length = list.size();
|
||||
int[] intArray = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
intArray[i] = list.get(i);
|
||||
}
|
||||
return intArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array of primitive ints to a list of integers.
|
||||
*
|
||||
* @param ints The ints.
|
||||
* @return The input array in list form.
|
||||
*/
|
||||
public static List<Integer> toList(int... ints) {
|
||||
if (ints == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<Integer> integers = new ArrayList<>();
|
||||
for (int anInt : ints) {
|
||||
integers.add(anInt);
|
||||
}
|
||||
return integers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the integer equal to the big-endian concatenation of the characters in {@code string}
|
||||
* as bytes. The string must be no more than four characters long.
|
||||
@ -1312,6 +1277,9 @@ public final class Util {
|
||||
/**
|
||||
* Truncates a sequence of ASCII characters to a maximum length.
|
||||
*
|
||||
* <p>This preserves span styling in the {@link CharSequence}. If that's not important, use {@link
|
||||
* Ascii#truncate(CharSequence, int, String)}.
|
||||
*
|
||||
* <p><b>Note:</b> This is not safe to use in general on Unicode text because it may separate
|
||||
* characters from combining characters or split up surrogate pairs.
|
||||
*
|
||||
@ -1324,21 +1292,6 @@ public final class Util {
|
||||
return sequence.length() <= maxLength ? sequence : sequence.subSequence(0, maxLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncates a string of ASCII characters to a maximum length.
|
||||
*
|
||||
* <p><b>Note:</b> This is not safe to use in general on Unicode text because it may separate
|
||||
* characters from combining characters or split up surrogate pairs.
|
||||
*
|
||||
* @param string The string to truncate.
|
||||
* @param maxLength The max length to truncate to.
|
||||
* @return {@code string} directly if {@code string.length() <= maxLength}, otherwise {@code
|
||||
* string.substring(0, maxLength}.
|
||||
*/
|
||||
public static String truncateAscii(String string, int maxLength) {
|
||||
return string.length() <= maxLength ? string : string.substring(0, maxLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a byte array containing values parsed from the hex string provided.
|
||||
*
|
||||
|
@ -723,15 +723,13 @@ public class UtilTest {
|
||||
String input = "a short string";
|
||||
|
||||
assertThat(Util.truncateAscii(input, 100)).isSameInstanceAs(input);
|
||||
assertThat(Util.truncateAscii((CharSequence) input, 100)).isSameInstanceAs(input);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void truncateAscii_longInput_truncated() {
|
||||
String input = "a much longer string";
|
||||
|
||||
assertThat(Util.truncateAscii(input, 5)).isEqualTo("a muc");
|
||||
assertThat(Util.truncateAscii((CharSequence) input, 5).toString()).isEqualTo("a muc");
|
||||
assertThat(Util.truncateAscii(input, 5).toString()).isEqualTo("a muc");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -999,21 +997,6 @@ public class UtilTest {
|
||||
assertThat(Util.normalizeLanguageCode("hsn")).isEqualTo("zh-hsn");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toList() {
|
||||
assertThat(Util.toList(0, 3, 4)).containsExactly(0, 3, 4).inOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toList_nullPassed_returnsEmptyList() {
|
||||
assertThat(Util.toList(null)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toList_emptyArrayPassed_returnsEmptyList() {
|
||||
assertThat(Util.toList(new int[0])).isEmpty();
|
||||
}
|
||||
|
||||
private static void assertEscapeUnescapeFileName(String fileName, String escapedFileName) {
|
||||
assertThat(escapeFileName(fileName)).isEqualTo(escapedFileName);
|
||||
assertThat(unescapeFileName(escapedFileName)).isEqualTo(fileName);
|
||||
|
@ -54,6 +54,7 @@ dependencies {
|
||||
api project(modulePrefix + 'library-extractor')
|
||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||
compileOnly 'com.google.code.findbugs:jsr305:' + jsr305Version
|
||||
compileOnly 'com.google.guava:guava:' + guavaVersion
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||
|
@ -41,6 +41,7 @@ import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -323,7 +324,7 @@ public final class DefaultMediaSourceFactory implements MediaSourceFactory {
|
||||
.setPlayClearSamplesWithoutKeys(
|
||||
mediaItem.playbackProperties.drmConfiguration.playClearContentWithoutKey)
|
||||
.setUseDrmSessionsForClearContent(
|
||||
Util.toArray(mediaItem.playbackProperties.drmConfiguration.sessionForClearTypes))
|
||||
Ints.toArray(mediaItem.playbackProperties.drmConfiguration.sessionForClearTypes))
|
||||
.build(createHttpMediaDrmCallback(mediaItem.playbackProperties.drmConfiguration));
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -1822,7 +1823,7 @@ public class DefaultTrackSelector extends MappingTrackSelector {
|
||||
maxVideoBitrate,
|
||||
selectedTrackIndices);
|
||||
|
||||
return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
|
||||
return selectedTrackIndices.size() < 2 ? NO_TRACKS : Ints.toArray(selectedTrackIndices);
|
||||
}
|
||||
|
||||
private static int getAdaptiveVideoTrackCountForMimeType(
|
||||
|
@ -40,6 +40,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation project(modulePrefix + 'library-core')
|
||||
compileOnly 'com.google.guava:guava:' + guavaVersion
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||
|
@ -51,6 +51,7 @@ import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
|
||||
import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -604,7 +605,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||
|
||||
int[][] groupedAdaptationSetIndices = new int[adaptationSetGroupedIndices.size()][];
|
||||
for (int i = 0; i < groupedAdaptationSetIndices.length; i++) {
|
||||
groupedAdaptationSetIndices[i] = Util.toArray(adaptationSetGroupedIndices.get(i));
|
||||
groupedAdaptationSetIndices[i] = Ints.toArray(adaptationSetGroupedIndices.get(i));
|
||||
// Restore the original adaptation set order within each group.
|
||||
Arrays.sort(groupedAdaptationSetIndices[i]);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
|
||||
compileOnly 'com.google.guava:guava:' + guavaVersion
|
||||
compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.checkerframework:checker-compat-qual:' + checkerframeworkVersion
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-annotations-jvm:' + kotlinAnnotationsVersion
|
||||
|
@ -46,6 +46,7 @@ import com.google.android.exoplayer2.upstream.TransferListener;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -719,7 +720,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
/* muxedCaptionFormats= */ Collections.emptyList(),
|
||||
overridingDrmInitData,
|
||||
positionUs);
|
||||
manifestUrlsIndicesPerWrapper.add(Util.toArray(scratchIndicesList));
|
||||
manifestUrlsIndicesPerWrapper.add(Ints.toArray(scratchIndicesList));
|
||||
sampleStreamWrappers.add(sampleStreamWrapper);
|
||||
|
||||
if (allowChunklessPreparation && renditionsHaveCodecs) {
|
||||
|
@ -56,6 +56,7 @@ import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import com.google.android.exoplayer2.util.Log;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -444,7 +445,7 @@ import java.util.List;
|
||||
}
|
||||
}
|
||||
|
||||
int[] trackIndicesArray = Util.toArray(trackIndices);
|
||||
int[] trackIndicesArray = Ints.toArray(trackIndices);
|
||||
Arrays.sort(trackIndicesArray);
|
||||
return trackIndicesArray;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user