Skip to content

Commit 7a473e8

Browse files
Googlercopybara-github
authored andcommitted
Rollback of d011c27
PiperOrigin-RevId: 787283924
1 parent b2d49be commit 7a473e8

File tree

3 files changed

+97
-73
lines changed

3 files changed

+97
-73
lines changed

libraries/transformer/src/main/java/androidx/media3/transformer/CompositionPlayer.java

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import static androidx.media3.common.util.Assertions.checkState;
2222
import static androidx.media3.common.util.Assertions.checkStateNotNull;
2323
import static androidx.media3.common.util.Util.usToMs;
24+
import static androidx.media3.transformer.CompositionUtil.shouldRePreparePlayerForSequence;
2425
import static com.google.common.util.concurrent.Futures.immediateFuture;
2526
import static java.lang.Math.max;
2627
import static java.lang.Math.min;
@@ -83,7 +84,6 @@
8384
import androidx.media3.exoplayer.video.VideoFrameMetadataListener;
8485
import androidx.media3.exoplayer.video.VideoFrameReleaseControl;
8586
import com.google.common.collect.ImmutableList;
86-
import com.google.common.collect.Iterables;
8787
import com.google.common.util.concurrent.Futures;
8888
import com.google.common.util.concurrent.ListenableFuture;
8989
import com.google.errorprone.annotations.CanIgnoreReturnValue;
@@ -1483,75 +1483,6 @@ private static boolean shouldRePreparePlayerForComposition(
14831483
return false;
14841484
}
14851485

1486-
/**
1487-
* Returns whether the player should be re-prepared after switching {@link
1488-
* EditedMediaItemSequence} to the new one.
1489-
*
1490-
* <p>It returns {@code true} if the {@code oldSequence} is {@code null}.
1491-
*
1492-
* <p>Currently this method returns {@code false} when
1493-
*
1494-
* <ul>
1495-
* <li>All the {@link MediaItem mediaItems} in the {@code oldSequence} match with those in the
1496-
* {@code newSequence}.
1497-
* <li>Changes in {@link EditedMediaItem}:
1498-
* <ul>
1499-
* <li>{@linkplain EditedMediaItem#effects Video effects} changed. Except when there are
1500-
* speed adjustments ({@link InactiveTimestampAdjustment}).
1501-
* </ul>
1502-
* </ul>
1503-
*/
1504-
@VisibleForTesting
1505-
/* package */ static boolean shouldRePreparePlayerForSequence(
1506-
@Nullable EditedMediaItemSequence oldSequence, EditedMediaItemSequence newSequence) {
1507-
if (oldSequence == null) {
1508-
return true;
1509-
}
1510-
1511-
if (oldSequence.editedMediaItems.size() != newSequence.editedMediaItems.size()) {
1512-
return true;
1513-
}
1514-
1515-
for (int i = 0; i < oldSequence.editedMediaItems.size(); i++) {
1516-
EditedMediaItem oldEditedMediaItem = oldSequence.editedMediaItems.get(i);
1517-
EditedMediaItem newEditedMediaItem = newSequence.editedMediaItems.get(i);
1518-
if (!oldEditedMediaItem.mediaItem.equals(newEditedMediaItem.mediaItem)) {
1519-
// All MediaItems must match - this checks the URI and the clipping.
1520-
return true;
1521-
}
1522-
1523-
if (oldEditedMediaItem.flattenForSlowMotion != newEditedMediaItem.flattenForSlowMotion) {
1524-
return true;
1525-
}
1526-
1527-
if (oldEditedMediaItem.removeVideo != newEditedMediaItem.removeVideo) {
1528-
return true;
1529-
}
1530-
1531-
if (oldEditedMediaItem.removeAudio != newEditedMediaItem.removeAudio) {
1532-
return true;
1533-
}
1534-
1535-
if (!oldEditedMediaItem.effects.audioProcessors.equals(
1536-
newEditedMediaItem.effects.audioProcessors)) {
1537-
return true;
1538-
}
1539-
1540-
// TimestampAdjustment change needs to be handled separately. Player needs to be re-prepared
1541-
// if the timestamp adjustments change.
1542-
if (!Iterables.elementsEqual(
1543-
// Old timestamp adjustments
1544-
Iterables.filter(
1545-
oldEditedMediaItem.effects.videoEffects, InactiveTimestampAdjustment.class),
1546-
// New timestamp adjustments
1547-
Iterables.filter(
1548-
newEditedMediaItem.effects.videoEffects, InactiveTimestampAdjustment.class))) {
1549-
return true;
1550-
}
1551-
}
1552-
return false;
1553-
}
1554-
15551486
private static final class GapHandlingDecoderFactory implements ImageDecoder.Factory {
15561487
private static final String BLANK_FRAMES_MEDIA_SOURCE_TYPE = "composition_player_blank_frames";
15571488
private static final int BLANK_IMAGE_BITMAP_WIDTH = 1;
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package androidx.media3.transformer;
18+
19+
import androidx.annotation.Nullable;
20+
import androidx.media3.common.MediaItem;
21+
import com.google.common.collect.Iterables;
22+
23+
/* package */ final class CompositionUtil {
24+
25+
/**
26+
* Returns whether the player should be re-prepared after switching {@link
27+
* EditedMediaItemSequence} to the new one.
28+
*
29+
* <p>It returns {@code true} if the {@code oldSequence} is {@code null}.
30+
*
31+
* <p>Currently this method returns {@code false} when
32+
*
33+
* <ul>
34+
* <li>All the {@link MediaItem mediaItems} in the {@code oldSequence} match with those in the
35+
* {@code newSequence}.
36+
* <li>Changes in {@link EditedMediaItem}:
37+
* <ul>
38+
* <li>{@linkplain EditedMediaItem#effects Video effects} changed.
39+
* </ul>
40+
* </ul>
41+
*/
42+
public static boolean shouldRePreparePlayerForSequence(
43+
@Nullable EditedMediaItemSequence oldSequence, EditedMediaItemSequence newSequence) {
44+
if (oldSequence == null) {
45+
return true;
46+
}
47+
48+
if (oldSequence.editedMediaItems.size() != newSequence.editedMediaItems.size()) {
49+
return true;
50+
}
51+
52+
for (int i = 0; i < oldSequence.editedMediaItems.size(); i++) {
53+
EditedMediaItem oldEditedMediaItem = oldSequence.editedMediaItems.get(i);
54+
EditedMediaItem newEditedMediaItem = newSequence.editedMediaItems.get(i);
55+
if (!oldEditedMediaItem.mediaItem.equals(newEditedMediaItem.mediaItem)) {
56+
// All MediaItems must match - this checks the URI and the clipping.
57+
return true;
58+
}
59+
60+
if (oldEditedMediaItem.flattenForSlowMotion != newEditedMediaItem.flattenForSlowMotion) {
61+
return true;
62+
}
63+
64+
if (oldEditedMediaItem.removeVideo != newEditedMediaItem.removeVideo) {
65+
return true;
66+
}
67+
68+
if (oldEditedMediaItem.removeAudio != newEditedMediaItem.removeAudio) {
69+
return true;
70+
}
71+
72+
if (!oldEditedMediaItem.effects.audioProcessors.equals(
73+
newEditedMediaItem.effects.audioProcessors)) {
74+
return true;
75+
}
76+
77+
// TimestampAdjustment change needs to be handled separately. Player needs to be re-prepared
78+
// if the timestamp adjustments change.
79+
if (!Iterables.elementsEqual(
80+
// Old timestamp adjustments
81+
Iterables.filter(
82+
oldEditedMediaItem.effects.videoEffects, InactiveTimestampAdjustment.class),
83+
// New timestamp adjustments
84+
Iterables.filter(
85+
newEditedMediaItem.effects.videoEffects, InactiveTimestampAdjustment.class))) {
86+
return true;
87+
}
88+
}
89+
return false;
90+
}
91+
92+
private CompositionUtil() {}
93+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package androidx.media3.transformer;
1818

19-
import static androidx.media3.transformer.CompositionPlayer.shouldRePreparePlayerForSequence;
19+
import static androidx.media3.transformer.CompositionUtil.shouldRePreparePlayerForSequence;
2020
import static com.google.common.truth.Truth.assertThat;
2121

2222
import androidx.media3.common.MediaItem;
@@ -29,9 +29,9 @@
2929
import org.junit.Test;
3030
import org.junit.runner.RunWith;
3131

32-
/** Unit test for util methods in {@link CompositionPlayer}. */
32+
/** Unit test for {@link CompositionUtil}. */
3333
@RunWith(AndroidJUnit4.class)
34-
public class CompositionPlayerUtilTest {
34+
public class CompositionUtilTest {
3535

3636
private static final String URI_0 = "CompositionUtilTest_0";
3737
private static final String URI_1 = "CompositionUtilTest_1";

0 commit comments

Comments
 (0)