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 9c4c5a0704..aee23bc56a 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/TimestampAdjustmentTest.java @@ -27,6 +27,7 @@ import android.text.style.AbsoluteSizeSpan; import android.text.style.ForegroundColorSpan; import android.text.style.TypefaceSpan; import androidx.media3.common.util.Consumer; +import androidx.media3.test.utils.TestSpeedProvider; import androidx.media3.test.utils.TextureBitmapReader; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.common.collect.ImmutableList; @@ -67,7 +68,8 @@ public class TimestampAdjustmentTest { throw new IllegalStateException(e); } callback.onTimestamp(inputTimeUs / 2); - }); + }, + TestSpeedProvider.createWithStartTimes(new long[] {0}, new float[] {2f})); ImmutableList actualPresentationTimesUs = generateAndProcessBlackTimeStampedFrames(frameTimesUs, timestampAdjustment); 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 46269544b1..53f2d5c59f 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/TimestampAdjustment.java @@ -16,6 +16,8 @@ package androidx.media3.effect; import android.content.Context; +import androidx.media3.common.audio.SpeedProvider; +import androidx.media3.common.util.SpeedProviderUtil; import androidx.media3.common.util.TimestampConsumer; import androidx.media3.common.util.UnstableApi; @@ -44,21 +46,22 @@ public final class TimestampAdjustment implements GlEffect { * on any thread. */ void calculateOutputTimeUs(long inputTimeUs, TimestampConsumer outputTimeConsumer); - - /** - * Returns the expected duration of the output stream when the map is applied given a input - * {@code durationUs}. - */ - default long getDurationUsAfterTimestampsMapped(long durationUs) { - return durationUs; - } } - private final TimestampMap timestampMap; + public final TimestampMap timestampMap; - /** Creates an instance. */ - public TimestampAdjustment(TimestampMap timestampMap) { + public final SpeedProvider speedProvider; + + /** + * Creates an instance. + * + * @param timestampMap The {@link TimestampMap} + * @param speedProvider The {@link SpeedProvider} specifying the approximate speed adjustments the + * {@link TimestampMap} should be applying. + */ + public TimestampAdjustment(TimestampMap timestampMap, SpeedProvider speedProvider) { this.timestampMap = timestampMap; + this.speedProvider = speedProvider; } @Override @@ -68,6 +71,6 @@ public final class TimestampAdjustment implements GlEffect { @Override public long getDurationAfterEffectApplied(long durationUs) { - return timestampMap.getDurationUsAfterTimestampsMapped(durationUs); + return SpeedProviderUtil.getDurationAfterSpeedProviderApplied(speedProvider, durationUs); } } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/Effects.java b/libraries/transformer/src/main/java/androidx/media3/transformer/Effects.java index c358d1b080..2920d006ba 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/Effects.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/Effects.java @@ -21,7 +21,6 @@ import androidx.media3.common.MediaItem; import androidx.media3.common.audio.AudioProcessor; import androidx.media3.common.audio.SpeedChangingAudioProcessor; import androidx.media3.common.audio.SpeedProvider; -import androidx.media3.common.util.TimestampConsumer; import androidx.media3.common.util.UnstableApi; import androidx.media3.effect.SpeedChangeEffect; import androidx.media3.effect.TimestampAdjustment; @@ -82,19 +81,7 @@ public final class Effects { new SpeedChangingAudioProcessor(speedProvider); Effect audioDrivenVideoEffect = new TimestampAdjustment( - new TimestampAdjustment.TimestampMap() { - @Override - public void calculateOutputTimeUs( - long inputTimeUs, TimestampConsumer outputTimeConsumer) { - speedChangingAudioProcessor.getSpeedAdjustedTimeAsync( - inputTimeUs, outputTimeConsumer); - } - - @Override - public long getDurationUsAfterTimestampsMapped(long durationUs) { - return speedChangingAudioProcessor.getDurationAfterProcessorApplied(durationUs); - } - }); + speedChangingAudioProcessor::getSpeedAdjustedTimeAsync, speedProvider); return Pair.create(speedChangingAudioProcessor, audioDrivenVideoEffect); } }