diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 546a454d21..7a8201de89 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -7,6 +7,8 @@ and `SimpleBasePlayer.handleSeek` methods instead of ignoring them. If you are implementing these methods in a custom player, you may need to handle these additional calls with `mediaItemIndex == C.INDEX_UNSET`. + * Remove compile dependency on enhanced Java 8 desugaring + ([#1312](https://github.com/androidx/media/issues/1312)). * ExoPlayer: * Add `reset` to `BasePreloadManager` to release all the holding sources while keep the preload manager instance. diff --git a/common_library_config.gradle b/common_library_config.gradle index 7dee4b3d20..9d398d292a 100644 --- a/common_library_config.gradle +++ b/common_library_config.gradle @@ -29,7 +29,6 @@ android { } compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -44,5 +43,4 @@ android { dependencies { androidTestImplementation 'androidx.multidex:multidex:' + androidxMultidexVersion - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/cast/build.gradle b/demos/cast/build.gradle index 4fb1177a59..de067a5708 100644 --- a/demos/cast/build.gradle +++ b/demos/cast/build.gradle @@ -20,7 +20,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -66,7 +65,6 @@ dependencies { implementation 'androidx.multidex:multidex:' + androidxMultidexVersion implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion implementation 'com.google.android.material:material:' + androidxMaterialVersion - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } apply plugin: 'com.google.android.gms.strict-version-matcher-plugin' diff --git a/demos/compose/build.gradle b/demos/compose/build.gradle index 0a778ffa03..0a0fea0ce4 100644 --- a/demos/compose/build.gradle +++ b/demos/compose/build.gradle @@ -21,7 +21,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -74,6 +73,4 @@ dependencies { // For detecting and debugging leaks only. LeakCanary is not needed for demo app to work. debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.10' - - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/gl/build.gradle b/demos/gl/build.gradle index fac5b80155..5a19c6e796 100644 --- a/demos/gl/build.gradle +++ b/demos/gl/build.gradle @@ -20,7 +20,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -58,5 +57,4 @@ dependencies { implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion implementation 'androidx.multidex:multidex:' + androidxMultidexVersion compileOnly 'org.checkerframework:checker-qual:' + checkerframeworkVersion - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/main/build.gradle b/demos/main/build.gradle index 581e34799c..853cff33fc 100644 --- a/demos/main/build.gradle +++ b/demos/main/build.gradle @@ -22,7 +22,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -91,7 +90,6 @@ dependencies { withDecoderExtensionsImplementation project(modulePrefix + 'lib-decoder-vp9') withDecoderExtensionsImplementation project(modulePrefix + 'lib-decoder-midi') withDecoderExtensionsImplementation project(modulePrefix + 'lib-datasource-rtmp') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } apply plugin: 'com.google.android.gms.strict-version-matcher-plugin' diff --git a/demos/session/build.gradle b/demos/session/build.gradle index a46a3d20a8..41509bea4a 100644 --- a/demos/session/build.gradle +++ b/demos/session/build.gradle @@ -21,7 +21,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -69,5 +68,4 @@ dependencies { implementation project(modulePrefix + 'lib-ui') implementation project(modulePrefix + 'lib-session') implementation project(modulePrefix + 'demo-session-service') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/session_automotive/build.gradle b/demos/session_automotive/build.gradle index 73ec33e2c1..d745bfeedb 100644 --- a/demos/session_automotive/build.gradle +++ b/demos/session_automotive/build.gradle @@ -21,7 +21,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -65,5 +64,4 @@ dependencies { implementation 'com.google.android.material:material:' + androidxMaterialVersion implementation project(modulePrefix + 'lib-session') implementation project(modulePrefix + 'demo-session-service') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/shortform/build.gradle b/demos/shortform/build.gradle index ebb249166f..47ad2cd736 100644 --- a/demos/shortform/build.gradle +++ b/demos/shortform/build.gradle @@ -21,7 +21,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -94,5 +93,4 @@ dependencies { testImplementation 'com.google.truth:truth:' + truthVersion testImplementation 'org.robolectric:robolectric:' + robolectricVersion testImplementation 'org.robolectric:robolectric:' + robolectricVersion - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/surface/build.gradle b/demos/surface/build.gradle index 4dc2eeaef0..ea62cc84d1 100644 --- a/demos/surface/build.gradle +++ b/demos/surface/build.gradle @@ -20,7 +20,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -55,5 +54,4 @@ dependencies { implementation project(modulePrefix + 'lib-exoplayer-smoothstreaming') implementation project(modulePrefix + 'lib-ui') implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' } diff --git a/demos/transformer/build.gradle b/demos/transformer/build.gradle index 877fc8d873..279fcc7476 100644 --- a/demos/transformer/build.gradle +++ b/demos/transformer/build.gradle @@ -22,7 +22,6 @@ android { compileSdk project.ext.compileSdkVersion compileOptions { - coreLibraryDesugaringEnabled true sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } @@ -86,8 +85,6 @@ dependencies { implementation project(modulePrefix + 'lib-transformer') implementation project(modulePrefix + 'lib-ui') - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' - // For MediaPipe and its dependencies: withMediaPipeImplementation fileTree(dir: 'libs', include: ['*.aar']) withMediaPipeImplementation 'com.google.flogger:flogger:latest.release' diff --git a/libraries/common/src/main/java/androidx/media3/common/Format.java b/libraries/common/src/main/java/androidx/media3/common/Format.java index cda7ac23e9..3f6ea8052e 100644 --- a/libraries/common/src/main/java/androidx/media3/common/Format.java +++ b/libraries/common/src/main/java/androidx/media3/common/Format.java @@ -967,6 +967,18 @@ public final class Format implements Bundleable { // Lazily initialized hashcode. private int hashCode; + private static boolean isLabelPartOfLabels(Builder builder) { + if (builder.labels.isEmpty() && builder.label == null) { + return true; + } + for (int i = 0; i < builder.labels.size(); i++) { + if (builder.labels.get(i).value.equals(builder.label)) { + return true; + } + } + return false; + } + private Format(Builder builder) { id = builder.id; language = Util.normalizeLanguageCode(builder.language); @@ -977,9 +989,7 @@ public final class Format implements Bundleable { labels = builder.labels; label = getDefaultLabel(builder.labels, language); } else { - checkState( - (builder.labels.isEmpty() && builder.label == null) - || (builder.labels.stream().anyMatch(l -> l.value.equals(builder.label)))); + checkState(isLabelPartOfLabels(builder)); labels = builder.labels; label = builder.label; } diff --git a/libraries/common/src/main/java/androidx/media3/common/audio/SpeedChangingAudioProcessor.java b/libraries/common/src/main/java/androidx/media3/common/audio/SpeedChangingAudioProcessor.java index 987c30849a..3a20d58d90 100644 --- a/libraries/common/src/main/java/androidx/media3/common/audio/SpeedChangingAudioProcessor.java +++ b/libraries/common/src/main/java/androidx/media3/common/audio/SpeedChangingAudioProcessor.java @@ -24,6 +24,7 @@ import androidx.media3.common.C; import androidx.media3.common.util.LongArray; import androidx.media3.common.util.LongArrayQueue; import androidx.media3.common.util.SpeedProviderUtil; +import androidx.media3.common.util.TimestampConsumer; import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.Util; import java.nio.ByteBuffer; @@ -53,7 +54,7 @@ public final class SpeedChangingAudioProcessor extends BaseAudioProcessor { // Elements in the same positions in the queues are associated. private final LongArrayQueue pendingCallbackInputTimesUs; - private final Queue pendingCallbacks; + private final Queue pendingCallbacks; // Elements in the same positions in the arrays are associated. private final LongArray inputSegmentStartTimesUs; @@ -204,13 +205,13 @@ public final class SpeedChangingAudioProcessor extends BaseAudioProcessor { * @param callback The callback called with the output time. May be called on a different thread * from the caller of this method. */ - public void getSpeedAdjustedTimeAsync(long inputTimeUs, LongConsumer callback) { + public void getSpeedAdjustedTimeAsync(long inputTimeUs, TimestampConsumer callback) { checkArgument(speedAdjustedTimeAsyncInputTimeUs < inputTimeUs); speedAdjustedTimeAsyncInputTimeUs = inputTimeUs; synchronized (pendingCallbacksLock) { if ((inputTimeUs <= lastProcessedInputTimeUs && pendingCallbackInputTimesUs.isEmpty()) || isEnded()) { - callback.accept(calculateSpeedAdjustedTime(inputTimeUs)); + callback.onTimestamp(calculateSpeedAdjustedTime(inputTimeUs)); return; } pendingCallbackInputTimesUs.add(inputTimeUs); @@ -261,7 +262,7 @@ public final class SpeedChangingAudioProcessor extends BaseAudioProcessor { && (pendingCallbackInputTimesUs.element() <= lastProcessedInputTimeUs || isEnded())) { pendingCallbacks .remove() - .accept(calculateSpeedAdjustedTime(pendingCallbackInputTimesUs.remove())); + .onTimestamp(calculateSpeedAdjustedTime(pendingCallbackInputTimesUs.remove())); } } } diff --git a/libraries/common/src/main/java/androidx/media3/common/util/TimestampConsumer.java b/libraries/common/src/main/java/androidx/media3/common/util/TimestampConsumer.java new file mode 100644 index 0000000000..eeb3c36070 --- /dev/null +++ b/libraries/common/src/main/java/androidx/media3/common/util/TimestampConsumer.java @@ -0,0 +1,28 @@ +/* + * Copyright 2024 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 androidx.media3.common.util; + +/** A consumer for long timestamp values. */ +@UnstableApi +public interface TimestampConsumer { + + /** + * Consumes a timestamp. + * + * @param timestampUs The timestamp, in microseconds. + */ + public void onTimestamp(long timestampUs); +} diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java index d15075fb4b..9c4c5a0704 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java @@ -66,7 +66,7 @@ public class TimestampAdjustmentTest { Thread.currentThread().interrupt(); throw new IllegalStateException(e); } - callback.accept(inputTimeUs / 2); + callback.onTimestamp(inputTimeUs / 2); }); ImmutableList actualPresentationTimesUs = diff --git a/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java b/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java index 2539d375b7..05967fa41f 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java @@ -16,8 +16,8 @@ package androidx.media3.effect; import android.content.Context; +import androidx.media3.common.util.TimestampConsumer; import androidx.media3.common.util.UnstableApi; -import java.util.function.LongConsumer; /** * Changes the frame timestamps using the {@link TimestampMap}. @@ -43,7 +43,7 @@ public final class TimestampAdjustment implements GlEffect { *

The implementation should invoke the {@code outputTimeConsumer} with the output timestamp, * on any thread. */ - void calculateOutputTimeUs(long inputTimeUs, LongConsumer outputTimeConsumer); + void calculateOutputTimeUs(long inputTimeUs, TimestampConsumer outputTimeConsumer); } private final TimestampMap timestampMap; diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java index 65d78166fd..1d2aed93f4 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/FrameworkMuxer.java @@ -149,11 +149,15 @@ import java.util.Map; } long presentationTimeOffsetUs = - trackTokenToPresentationTimeOffsetUs.getOrDefault(trackToken, 0L); + trackTokenToPresentationTimeOffsetUs.containsKey(trackToken) + ? trackTokenToPresentationTimeOffsetUs.get(trackToken) + : 0; presentationTimeUs += presentationTimeOffsetUs; long lastSamplePresentationTimeUs = - trackTokenToLastPresentationTimeUs.getOrDefault(trackToken, 0L); + trackTokenToLastPresentationTimeUs.containsKey(trackToken) + ? trackTokenToLastPresentationTimeUs.get(trackToken) + : 0; // writeSampleData blocks on old API versions, so check here to avoid calling the method. checkState( Util.SDK_INT > 24 || presentationTimeUs >= lastSamplePresentationTimeUs,