Track presentation timestamps in FrameEditor.

PiperOrigin-RevId: 428763554
This commit is contained in:
hschlueter 2022-02-15 14:19:21 +00:00 committed by Ian Baker
parent 238d9ca57b
commit 33afc4760b
2 changed files with 11 additions and 3 deletions

View File

@ -18,6 +18,7 @@ package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import android.media.MediaCodec;
import android.media.MediaCodec.BufferInfo;
@ -27,6 +28,7 @@ import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.decoder.DecoderInputBuffer;
import com.google.common.collect.ImmutableList;
@ -314,7 +316,13 @@ public final class Codec {
public void releaseOutputBuffer(boolean render) throws TransformationException {
outputBuffer = null;
try {
mediaCodec.releaseOutputBuffer(outputBufferIndex, render);
if (render) {
mediaCodec.releaseOutputBuffer(
outputBufferIndex,
/* renderTimestampNs= */ checkStateNotNull(outputBufferInfo).presentationTimeUs * 1000);
} else {
mediaCodec.releaseOutputBuffer(outputBufferIndex, /* render= */ false);
}
} catch (RuntimeException e) {
throw createTransformationException(e);
}

View File

@ -325,8 +325,8 @@ import java.util.concurrent.atomic.AtomicInteger;
glProgram.bindAttributesAndUniforms();
focusAndDrawQuad(eglSurface, outputWidth, outputHeight);
long surfaceTextureTimestampNs = inputSurfaceTexture.getTimestamp();
EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, surfaceTextureTimestampNs);
long presentationTimeNs = inputSurfaceTexture.getTimestamp();
EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, presentationTimeNs);
EGL14.eglSwapBuffers(eglDisplay, eglSurface);
if (debugPreviewEglSurface != null) {