Commit 90c17fbe by olly Committed by kim-vde

CameraMotionRenderer: Cleanup + respect decode-only flag

PiperOrigin-RevId: 320149613
parent 8748646c
...@@ -31,7 +31,7 @@ import com.google.android.exoplayer2.util.Util; ...@@ -31,7 +31,7 @@ import com.google.android.exoplayer2.util.Util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** A {@link Renderer} that parses the camera motion track. */ /** A {@link Renderer} that parses the camera motion track. */
public class CameraMotionRenderer extends BaseRenderer { public final class CameraMotionRenderer extends BaseRenderer {
private static final String TAG = "CameraMotionRenderer"; private static final String TAG = "CameraMotionRenderer";
// The amount of time to read samples ahead of the current time. // The amount of time to read samples ahead of the current time.
...@@ -73,12 +73,13 @@ public class CameraMotionRenderer extends BaseRenderer { ...@@ -73,12 +73,13 @@ public class CameraMotionRenderer extends BaseRenderer {
} }
@Override @Override
protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException { protected void onStreamChanged(Format[] formats, long offsetUs) {
this.offsetUs = offsetUs; this.offsetUs = offsetUs;
} }
@Override @Override
protected void onPositionReset(long positionUs, boolean joining) throws ExoPlaybackException { protected void onPositionReset(long positionUs, boolean joining) {
lastTimestampUs = Long.MIN_VALUE;
resetListener(); resetListener();
} }
...@@ -88,7 +89,7 @@ public class CameraMotionRenderer extends BaseRenderer { ...@@ -88,7 +89,7 @@ public class CameraMotionRenderer extends BaseRenderer {
} }
@Override @Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { public void render(long positionUs, long elapsedRealtimeUs) {
// Keep reading available samples as long as the sample time is not too far into the future. // Keep reading available samples as long as the sample time is not too far into the future.
while (!hasReadStreamToEnd() && lastTimestampUs < positionUs + SAMPLE_WINDOW_DURATION_US) { while (!hasReadStreamToEnd() && lastTimestampUs < positionUs + SAMPLE_WINDOW_DURATION_US) {
buffer.clear(); buffer.clear();
...@@ -99,14 +100,18 @@ public class CameraMotionRenderer extends BaseRenderer { ...@@ -99,14 +100,18 @@ public class CameraMotionRenderer extends BaseRenderer {
return; return;
} }
buffer.flip();
lastTimestampUs = buffer.timeUs; lastTimestampUs = buffer.timeUs;
if (listener != null) { if (listener == null || buffer.isDecodeOnly()) {
float[] rotation = parseMetadata(Util.castNonNull(buffer.data)); continue;
if (rotation != null) {
Util.castNonNull(listener).onCameraMotion(lastTimestampUs - offsetUs, rotation);
}
} }
buffer.flip();
@Nullable float[] rotation = parseMetadata(Util.castNonNull(buffer.data));
if (rotation == null) {
continue;
}
Util.castNonNull(listener).onCameraMotion(lastTimestampUs - offsetUs, rotation);
} }
} }
...@@ -135,7 +140,6 @@ public class CameraMotionRenderer extends BaseRenderer { ...@@ -135,7 +140,6 @@ public class CameraMotionRenderer extends BaseRenderer {
} }
private void resetListener() { private void resetListener() {
lastTimestampUs = 0;
if (listener != null) { if (listener != null) {
listener.onCameraMotionReset(); listener.onCameraMotionReset();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment