Skip to content

Commit

Permalink
Disable enhanced Java 8 desugaring
Browse files Browse the repository at this point in the history
This avoids that apps have to depend on this additional config

Issue: #1312
PiperOrigin-RevId: 631447767
  • Loading branch information
tonihei authored and Copybara-Service committed May 7, 2024
1 parent 0969043 commit 6ac60c6
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 34 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 0 additions & 2 deletions common_library_config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ android {
}

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand All @@ -44,5 +43,4 @@ android {

dependencies {
androidTestImplementation 'androidx.multidex:multidex:' + androidxMultidexVersion
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
}
2 changes: 0 additions & 2 deletions demos/cast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
3 changes: 0 additions & 3 deletions demos/compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
2 changes: 0 additions & 2 deletions demos/gl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
2 changes: 0 additions & 2 deletions demos/main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
2 changes: 0 additions & 2 deletions demos/session/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
2 changes: 0 additions & 2 deletions demos/session_automotive/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
2 changes: 0 additions & 2 deletions demos/shortform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
2 changes: 0 additions & 2 deletions demos/surface/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
}
3 changes: 0 additions & 3 deletions demos/transformer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ android {
compileSdk project.ext.compileSdkVersion

compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -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'
Expand Down
16 changes: 13 additions & 3 deletions libraries/common/src/main/java/androidx/media3/common/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,18 @@ public Format build() {
// 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);
Expand All @@ -977,9 +989,7 @@ private Format(Builder builder) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -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<LongConsumer> pendingCallbacks;
private final Queue<TimestampConsumer> pendingCallbacks;

// Elements in the same positions in the arrays are associated.
private final LongArray inputSegmentStartTimesUs;
Expand Down Expand Up @@ -204,13 +205,13 @@ protected void onReset() {
* @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);
Expand Down Expand Up @@ -261,7 +262,7 @@ private void processPendingCallbacks() {
&& (pendingCallbackInputTimesUs.element() <= lastProcessedInputTimeUs || isEnded())) {
pendingCallbacks
.remove()
.accept(calculateSpeedAdjustedTime(pendingCallbackInputTimesUs.remove()));
.onTimestamp(calculateSpeedAdjustedTime(pendingCallbackInputTimesUs.remove()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void timestampAdjustmentTest_outputsFramesAtTheCorrectPresentationTimesUs
Thread.currentThread().interrupt();
throw new IllegalStateException(e);
}
callback.accept(inputTimeUs / 2);
callback.onTimestamp(inputTimeUs / 2);
});

ImmutableList<Long> actualPresentationTimesUs =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand All @@ -43,7 +43,7 @@ public interface TimestampMap {
* <p>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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,15 @@ public void writeSampleData(TrackToken trackToken, ByteBuffer data, BufferInfo b
}

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,
Expand Down

0 comments on commit 6ac60c6

Please sign in to comment.