mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
CameraMotionRenderer: Cleanup + respect decode-only flag
PiperOrigin-RevId: 320149613
This commit is contained in:
parent
8748646cb8
commit
90c17fbe84
1 changed files with 15 additions and 11 deletions
|
|
@ -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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
@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 {
|
||||||
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 {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetListener() {
|
private void resetListener() {
|
||||||
lastTimestampUs = 0;
|
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onCameraMotionReset();
|
listener.onCameraMotionReset();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue