Store the speed provider in timestamp adjustment

PiperOrigin-RevId: 655928480
This commit is contained in:
tofunmi 2024-07-25 06:06:36 -07:00 committed by Copybara-Service
parent aaa6561aa9
commit 043de45763
3 changed files with 19 additions and 27 deletions

View File

@ -27,6 +27,7 @@ import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.TypefaceSpan; import android.text.style.TypefaceSpan;
import androidx.media3.common.util.Consumer; import androidx.media3.common.util.Consumer;
import androidx.media3.test.utils.TestSpeedProvider;
import androidx.media3.test.utils.TextureBitmapReader; import androidx.media3.test.utils.TextureBitmapReader;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -67,7 +68,8 @@ public class TimestampAdjustmentTest {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
callback.onTimestamp(inputTimeUs / 2); callback.onTimestamp(inputTimeUs / 2);
}); },
TestSpeedProvider.createWithStartTimes(new long[] {0}, new float[] {2f}));
ImmutableList<Long> actualPresentationTimesUs = ImmutableList<Long> actualPresentationTimesUs =
generateAndProcessBlackTimeStampedFrames(frameTimesUs, timestampAdjustment); generateAndProcessBlackTimeStampedFrames(frameTimesUs, timestampAdjustment);

View File

@ -16,6 +16,8 @@
package androidx.media3.effect; package androidx.media3.effect;
import android.content.Context; 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.TimestampConsumer;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
@ -44,21 +46,22 @@ public final class TimestampAdjustment implements GlEffect {
* on any thread. * on any thread.
*/ */
void calculateOutputTimeUs(long inputTimeUs, TimestampConsumer outputTimeConsumer); 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 final SpeedProvider speedProvider;
public TimestampAdjustment(TimestampMap timestampMap) {
/**
* 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.timestampMap = timestampMap;
this.speedProvider = speedProvider;
} }
@Override @Override
@ -68,6 +71,6 @@ public final class TimestampAdjustment implements GlEffect {
@Override @Override
public long getDurationAfterEffectApplied(long durationUs) { public long getDurationAfterEffectApplied(long durationUs) {
return timestampMap.getDurationUsAfterTimestampsMapped(durationUs); return SpeedProviderUtil.getDurationAfterSpeedProviderApplied(speedProvider, durationUs);
} }
} }

View File

@ -21,7 +21,6 @@ import androidx.media3.common.MediaItem;
import androidx.media3.common.audio.AudioProcessor; import androidx.media3.common.audio.AudioProcessor;
import androidx.media3.common.audio.SpeedChangingAudioProcessor; import androidx.media3.common.audio.SpeedChangingAudioProcessor;
import androidx.media3.common.audio.SpeedProvider; import androidx.media3.common.audio.SpeedProvider;
import androidx.media3.common.util.TimestampConsumer;
import androidx.media3.common.util.UnstableApi; import androidx.media3.common.util.UnstableApi;
import androidx.media3.effect.SpeedChangeEffect; import androidx.media3.effect.SpeedChangeEffect;
import androidx.media3.effect.TimestampAdjustment; import androidx.media3.effect.TimestampAdjustment;
@ -82,19 +81,7 @@ public final class Effects {
new SpeedChangingAudioProcessor(speedProvider); new SpeedChangingAudioProcessor(speedProvider);
Effect audioDrivenVideoEffect = Effect audioDrivenVideoEffect =
new TimestampAdjustment( new TimestampAdjustment(
new TimestampAdjustment.TimestampMap() { speedChangingAudioProcessor::getSpeedAdjustedTimeAsync, speedProvider);
@Override
public void calculateOutputTimeUs(
long inputTimeUs, TimestampConsumer outputTimeConsumer) {
speedChangingAudioProcessor.getSpeedAdjustedTimeAsync(
inputTimeUs, outputTimeConsumer);
}
@Override
public long getDurationUsAfterTimestampsMapped(long durationUs) {
return speedChangingAudioProcessor.getDurationAfterProcessorApplied(durationUs);
}
});
return Pair.create(speedChangingAudioProcessor, audioDrivenVideoEffect); return Pair.create(speedChangingAudioProcessor, audioDrivenVideoEffect);
} }
} }