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.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<Long> actualPresentationTimesUs =
generateAndProcessBlackTimeStampedFrames(frameTimesUs, timestampAdjustment);

View File

@ -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);
}
}

View File

@ -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);
}
}