Commit 2e5a616f by olly Committed by Oliver Woodman

Core/UI decoupling: Move spherical back to core

A subsequent change will make the UI module access
SphericalGLSurfaceView and VideoDecoderGLSurfaceView
using reflection, now we're at the point where we only
need to reflect the constructors.

PiperOrigin-RevId: 369630102
parent a78b1829
Showing with 82 additions and 205 deletions
......@@ -74,8 +74,6 @@
cache.
* Library restructuring:
* `DebugTextViewHelper` moved from `ui` package to `util` package.
* Spherical UI components moved from `video.spherical` package to
`ui.spherical` package, and made package private.
* Remove deprecated symbols:
* Remove `ExoPlayerFactory` methods. Use `SimpleExoPlayer.Builder`
instead.
......
......@@ -48,8 +48,6 @@ import com.google.android.exoplayer2.util.ListenerSet;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
import com.google.android.gms.cast.CastStatusCodes;
import com.google.android.gms.cast.MediaInfo;
import com.google.android.gms.cast.MediaQueueItem;
......@@ -655,22 +653,6 @@ public final class CastPlayer extends BasePlayer {
/** This method is not supported and does nothing. */
@Override
public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void setCameraMotionListener(CameraMotionListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearCameraMotionListener(CameraMotionListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearVideoSurface() {}
/** This method is not supported and does nothing. */
......
......@@ -35,9 +35,7 @@ import com.google.android.exoplayer2.text.TextOutput;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.util.ExoFlags;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.VideoListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
import com.google.common.base.Objects;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
......@@ -1687,40 +1685,6 @@ public interface Player {
float getVolume();
/**
* Sets a listener to receive video frame metadata events.
*
* <p>This method is intended to be called by the same component that sets the {@link Surface}
* onto which video will be rendered. If using ExoPlayer's standard UI components, this method
* should not be called directly from application code.
*
* @param listener The listener.
*/
void setVideoFrameMetadataListener(VideoFrameMetadataListener listener);
/**
* Clears the listener which receives video frame metadata events if it matches the one passed.
* Else does nothing.
*
* @param listener The listener to clear.
*/
void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener);
/**
* Sets a listener of camera motion events.
*
* @param listener The listener.
*/
void setCameraMotionListener(CameraMotionListener listener);
/**
* Clears the listener which receives camera motion events if it matches the one passed. Else does
* nothing.
*
* @param listener The listener to clear.
*/
void clearCameraMotionListener(CameraMotionListener listener);
/**
* Clears any {@link Surface}, {@link SurfaceHolder}, {@link SurfaceView} or {@link TextureView}
* currently set on the player.
*/
......
......@@ -52,8 +52,6 @@ import com.google.android.exoplayer2.util.HandlerWrapper;
import com.google.android.exoplayer2.util.ListenerSet;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Collections;
......@@ -1012,22 +1010,6 @@ import java.util.concurrent.CopyOnWriteArraySet;
/** This method is not supported and does nothing. */
@Override
public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void setCameraMotionListener(CameraMotionListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearCameraMotionListener(CameraMotionListener listener) {}
/** This method is not supported and does nothing. */
@Override
public void clearVideoSurface() {}
/** This method is not supported and does nothing. */
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import android.opengl.Matrix;
import com.google.android.exoplayer2.util.TimedValueQueue;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import androidx.annotation.IntDef;
import com.google.android.exoplayer2.C;
......
......@@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ui.spherical.Projection.Mesh;
import com.google.android.exoplayer2.ui.spherical.Projection.SubMesh;
import com.google.android.exoplayer2.util.ParsableBitArray;
import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.spherical.Projection.Mesh;
import com.google.android.exoplayer2.video.spherical.Projection.SubMesh;
import java.util.ArrayList;
import java.util.zip.Inflater;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.android.exoplayer2.util.GlUtil.checkGlError;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.android.exoplayer2.util.GlUtil.checkGlError;
......@@ -28,7 +28,6 @@ import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.TimedValueQueue;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import android.content.Context;
import android.graphics.PointF;
......@@ -36,9 +36,10 @@ import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
......@@ -54,6 +55,16 @@ import javax.microedition.khronos.opengles.GL10;
*/
public final class SphericalGLSurfaceView extends GLSurfaceView {
/** Listener for the {@link Surface} to which video frames should be rendered. */
public interface VideoSurfaceListener {
/** Called when the {@link Surface} to which video frames should be rendered is created. */
void onVideoSurfaceCreated(Surface surface);
/** Called when the {@link Surface} to which video frames should be rendered is destroyed. */
void onVideoSurfaceDestroyed(Surface surface);
}
// Arbitrary vertical field of view.
private static final int FIELD_OF_VIEW_DEGREES = 90;
private static final float Z_NEAR = 0.1f;
......@@ -64,6 +75,7 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
/* package */ static final float UPRIGHT_ROLL = (float) Math.PI;
private final CopyOnWriteArrayList<VideoSurfaceListener> videoSurfaceListeners;
private final SensorManager sensorManager;
@Nullable private final Sensor orientationSensor;
private final OrientationListener orientationListener;
......@@ -72,7 +84,6 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
private final SceneRenderer scene;
@Nullable private SurfaceTexture surfaceTexture;
@Nullable private Surface surface;
@Nullable private Player player;
private boolean useSensorRotation;
private boolean isStarted;
private boolean isOrientationListenerRegistered;
......@@ -83,6 +94,7 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
public SphericalGLSurfaceView(Context context, @Nullable AttributeSet attributeSet) {
super(context, attributeSet);
videoSurfaceListeners = new CopyOnWriteArrayList<>();
mainHandler = new Handler(Looper.getMainLooper());
// Configure sensors and touch.
......@@ -116,6 +128,43 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
}
/**
* Adds a {@link VideoSurfaceListener}.
*
* @param listener The listener to add.
*/
public void addVideoSurfaceListener(VideoSurfaceListener listener) {
videoSurfaceListeners.add(listener);
}
/**
* Removes a {@link VideoSurfaceListener}.
*
* @param listener The listener to remove.
*/
public void removeVideoSurfaceListener(VideoSurfaceListener listener) {
videoSurfaceListeners.remove(listener);
}
/**
* Returns the {@link Surface} to which video frames should be rendered, or {@code null} if it has
* not been created.
*/
@Nullable
public Surface getVideoSurface() {
return surface;
}
/** Returns the {@link VideoFrameMetadataListener} that should be registered during playback. */
public VideoFrameMetadataListener getVideoFrameMetadataListener() {
return scene;
}
/** Returns the {@link CameraMotionListener} that should be registered during playback. */
public CameraMotionListener getCameraMotionListener() {
return scene;
}
/**
* Sets the default stereo mode. If the played video doesn't contain a stereo mode the default one
* is used.
*
......@@ -125,26 +174,6 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
scene.setDefaultStereoMode(stereoMode);
}
/** Sets the {@link Player} to use. */
public void setPlayer(@Nullable Player newPlayer) {
if (newPlayer == player) {
return;
}
if (player != null) {
if (surface != null) {
player.clearVideoSurface(surface);
}
player.clearVideoFrameMetadataListener(scene);
player.clearCameraMotionListener(scene);
}
player = newPlayer;
if (this.player != null) {
player.setVideoFrameMetadataListener(scene);
player.setCameraMotionListener(scene);
player.setVideoSurface(surface);
}
}
/** Sets whether to use the orientation sensor for rotation (if available). */
public void setUseSensorRotation(boolean useSensorRotation) {
this.useSensorRotation = useSensorRotation;
......@@ -173,14 +202,15 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
// Post to make sure we occur in order with any onSurfaceTextureAvailable calls.
mainHandler.post(
() -> {
if (surface != null) {
if (player != null) {
player.clearVideoSurface(surface);
@Nullable Surface oldSurface = surface;
if (oldSurface != null) {
for (VideoSurfaceListener videoSurfaceListener : videoSurfaceListeners) {
videoSurfaceListener.onVideoSurfaceDestroyed(oldSurface);
}
releaseSurface(surfaceTexture, surface);
surfaceTexture = null;
surface = null;
}
releaseSurface(surfaceTexture, oldSurface);
surfaceTexture = null;
surface = null;
});
}
......@@ -199,15 +229,16 @@ public final class SphericalGLSurfaceView extends GLSurfaceView {
}
// Called on GL thread.
private void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture) {
private void onSurfaceTextureAvailable(SurfaceTexture newSurfaceTexture) {
mainHandler.post(
() -> {
SurfaceTexture oldSurfaceTexture = this.surfaceTexture;
Surface oldSurface = this.surface;
this.surfaceTexture = surfaceTexture;
this.surface = new Surface(surfaceTexture);
if (player != null) {
player.setVideoSurface(surface);
@Nullable SurfaceTexture oldSurfaceTexture = surfaceTexture;
@Nullable Surface oldSurface = surface;
Surface newSurface = new Surface(newSurfaceTexture);
surfaceTexture = newSurfaceTexture;
surface = newSurface;
for (VideoSurfaceListener videoSurfaceListener : videoSurfaceListeners) {
videoSurfaceListener.onVideoSurfaceCreated(newSurface);
}
releaseSurface(oldSurfaceTexture, oldSurface);
});
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import android.content.Context;
import android.graphics.PointF;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.common.truth.Truth.assertThat;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.common.truth.Truth.assertThat;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
......
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
package com.google.android.exoplayer2.video.spherical;
import static com.google.common.truth.Truth.assertThat;
......
......@@ -62,12 +62,12 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ErrorMessageProvider;
import com.google.android.exoplayer2.util.RepeatModeUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView;
import com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView;
import com.google.common.collect.ImmutableList;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
......@@ -566,8 +566,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
if (oldPlayer.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
if (surfaceView instanceof TextureView) {
oldPlayer.clearVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setPlayer(null);
} else if (surfaceView instanceof SurfaceView) {
oldPlayer.clearVideoSurfaceView((SurfaceView) surfaceView);
}
......@@ -587,8 +585,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
if (player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
if (surfaceView instanceof TextureView) {
player.setVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setPlayer(player);
} else if (surfaceView instanceof SurfaceView) {
player.setVideoSurfaceView((SurfaceView) surfaceView);
}
......
......@@ -63,12 +63,12 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout.ResizeMode;
import com.google.android.exoplayer2.ui.spherical.SphericalGLSurfaceView;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.ErrorMessageProvider;
import com.google.android.exoplayer2.util.RepeatModeUtil;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoDecoderGLSurfaceView;
import com.google.android.exoplayer2.video.spherical.SphericalGLSurfaceView;
import com.google.common.collect.ImmutableList;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
......@@ -570,11 +570,8 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
}
@Nullable Player oldPlayer = this.player;
if (oldPlayer != null) {
oldPlayer.removeListener(componentListener);
if (surfaceView instanceof TextureView) {
oldPlayer.clearVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setPlayer(null);
} else if (surfaceView instanceof SurfaceView) {
oldPlayer.clearVideoSurfaceView((SurfaceView) surfaceView);
}
......@@ -593,8 +590,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
if (player.isCommandAvailable(COMMAND_SET_VIDEO_SURFACE)) {
if (surfaceView instanceof TextureView) {
player.setVideoTextureView((TextureView) surfaceView);
} else if (surfaceView instanceof SphericalGLSurfaceView) {
((SphericalGLSurfaceView) surfaceView).setPlayer(player);
} else if (surfaceView instanceof SurfaceView) {
player.setVideoSurfaceView((SurfaceView) surfaceView);
}
......
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ui.spherical;
import android.view.MotionEvent;
/** Listens tap events on a {@link android.view.View}. */
public interface SingleTapListener {
/**
* Notified when a tap occurs with the up {@link MotionEvent} that triggered it.
*
* @param e The up motion event that completed the first tap.
* @return Whether the event is consumed.
*/
boolean onSingleTapUp(MotionEvent e);
}
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.ui.spherical;
import com.google.android.exoplayer2.util.NonNullApi;
......@@ -41,8 +41,6 @@ import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
import com.google.android.exoplayer2.trackselection.TrackSelector;
import com.google.android.exoplayer2.util.Clock;
import com.google.android.exoplayer2.video.VideoFrameMetadataListener;
import com.google.android.exoplayer2.video.spherical.CameraMotionListener;
import java.util.List;
/**
......@@ -447,26 +445,6 @@ public class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
@Override
public void setVideoFrameMetadataListener(VideoFrameMetadataListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void clearVideoFrameMetadataListener(VideoFrameMetadataListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void setCameraMotionListener(CameraMotionListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void clearCameraMotionListener(CameraMotionListener listener) {
throw new UnsupportedOperationException();
}
@Override
public void clearVideoSurface() {
throw new UnsupportedOperationException();
}
......
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