Rename CameraController to CameraEngine

pull/482/head
Mattia Iavarone 6 years ago
parent 7603a0f11b
commit 46d03c0555
  1. 6
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewCallbacksTest.java
  2. 8
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  3. 10
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/IntegrationTest.java
  4. 4
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/MockCameraEngine.java
  5. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  6. 14
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraEngine.java
  7. 148
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  8. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/SnapshotPictureRecorder.java
  9. 4
      cameraview/src/main/views/com/otaliastudios/cameraview/CameraPreview.java

@ -40,7 +40,7 @@ public class CameraViewCallbacksTest extends BaseTest {
private CameraView camera; private CameraView camera;
private CameraListener listener; private CameraListener listener;
private FrameProcessor processor; private FrameProcessor processor;
private MockCameraController mockController; private MockCameraEngine mockController;
private MockCameraPreview mockPreview; private MockCameraPreview mockPreview;
private Task<Boolean> task; private Task<Boolean> task;
@ -54,8 +54,8 @@ public class CameraViewCallbacksTest extends BaseTest {
processor = mock(FrameProcessor.class); processor = mock(FrameProcessor.class);
camera = new CameraView(context) { camera = new CameraView(context) {
@Override @Override
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { protected CameraEngine instantiateCameraController(CameraCallbacks callbacks) {
mockController = new MockCameraController(callbacks); mockController = new MockCameraEngine(callbacks);
return mockController; return mockController;
} }

@ -46,7 +46,7 @@ import static android.view.ViewGroup.LayoutParams.*;
public class CameraViewTest extends BaseTest { public class CameraViewTest extends BaseTest {
private CameraView cameraView; private CameraView cameraView;
private MockCameraController mockController; private MockCameraEngine mockController;
private CameraPreview mockPreview; private CameraPreview mockPreview;
private boolean hasPermissions; private boolean hasPermissions;
@ -58,8 +58,8 @@ public class CameraViewTest extends BaseTest {
Context context = context(); Context context = context();
cameraView = new CameraView(context) { cameraView = new CameraView(context) {
@Override @Override
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { protected CameraEngine instantiateCameraController(CameraCallbacks callbacks) {
mockController = spy(new MockCameraController(callbacks)); mockController = spy(new MockCameraEngine(callbacks));
return mockController; return mockController;
} }
@ -125,7 +125,7 @@ public class CameraViewTest extends BaseTest {
@Test @Test
public void testDefaults() { public void testDefaults() {
// CameraController // CameraEngine
TypedArray empty = context().obtainStyledAttributes(new int[]{}); TypedArray empty = context().obtainStyledAttributes(new int[]{});
ControlParser controls = new ControlParser(context(), empty); ControlParser controls = new ControlParser(context(), empty);
assertEquals(cameraView.getFlash(), controls.getFlash()); assertEquals(cameraView.getFlash(), controls.getFlash());

@ -41,7 +41,7 @@ import static org.mockito.Mockito.spy;
/** /**
* These tests work great on real devices, and are the only way to test actual CameraController * These tests work great on real devices, and are the only way to test actual CameraEngine
* implementation - we really need to open the camera device. * implementation - we really need to open the camera device.
* Unfortunately they fail unreliably on emulated devices, due to some bug with the * Unfortunately they fail unreliably on emulated devices, due to some bug with the
* emulated camera controller. Waiting for it to be fixed. * emulated camera controller. Waiting for it to be fixed.
@ -73,7 +73,7 @@ public class IntegrationTest extends BaseTest {
public void run() { public void run() {
camera = new CameraView(rule.getActivity()) { camera = new CameraView(rule.getActivity()) {
@Override @Override
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { protected CameraEngine instantiateCameraController(CameraCallbacks callbacks) {
controller = new Camera1(callbacks); controller = new Camera1(callbacks);
return controller; return controller;
} }
@ -169,13 +169,13 @@ public class IntegrationTest extends BaseTest {
@Test @Test
public void testOpenClose() throws Exception { public void testOpenClose() throws Exception {
// Starting and stopping are hard to get since they happen on another thread. // Starting and stopping are hard to get since they happen on another thread.
assertEquals(controller.getState(), CameraController.STATE_STOPPED); assertEquals(controller.getState(), CameraEngine.STATE_STOPPED);
waitForOpen(true); waitForOpen(true);
assertEquals(controller.getState(), CameraController.STATE_STARTED); assertEquals(controller.getState(), CameraEngine.STATE_STARTED);
waitForClose(true); waitForClose(true);
assertEquals(controller.getState(), CameraController.STATE_STOPPED); assertEquals(controller.getState(), CameraEngine.STATE_STOPPED);
} }
@Test @Test

@ -19,14 +19,14 @@ import androidx.annotation.Nullable;
import java.io.File; import java.io.File;
public class MockCameraController extends CameraController { public class MockCameraEngine extends CameraEngine {
boolean mPictureCaptured; boolean mPictureCaptured;
boolean mFocusStarted; boolean mFocusStarted;
boolean mZoomChanged; boolean mZoomChanged;
boolean mExposureCorrectionChanged; boolean mExposureCorrectionChanged;
MockCameraController(CameraView.CameraCallbacks callback) { MockCameraEngine(CameraView.CameraCallbacks callback) {
super(callback); super(callback);
} }

@ -31,7 +31,7 @@ import java.util.List;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
class Camera1 extends CameraController implements Camera.PreviewCallback, Camera.ErrorCallback, class Camera1 extends CameraEngine implements Camera.PreviewCallback, Camera.ErrorCallback,
VideoRecorder.VideoResultListener, VideoRecorder.VideoResultListener,
PictureRecorder.PictureResultListener { PictureRecorder.PictureResultListener {

@ -30,12 +30,12 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
abstract class CameraController implements abstract class CameraEngine implements
CameraPreview.SurfaceCallback, CameraPreview.SurfaceCallback,
FrameManager.BufferCallback, FrameManager.BufferCallback,
Thread.UncaughtExceptionHandler { Thread.UncaughtExceptionHandler {
private static final String TAG = CameraController.class.getSimpleName(); private static final String TAG = CameraEngine.class.getSimpleName();
private static final CameraLogger LOG = CameraLogger.create(TAG); private static final CameraLogger LOG = CameraLogger.create(TAG);
static final int STATE_STOPPING = -1; // Camera is about to be stopped. static final int STATE_STOPPING = -1; // Camera is about to be stopped.
@ -104,7 +104,7 @@ abstract class CameraController implements
Task<Void> mStartVideoTask = new Task<>(); Task<Void> mStartVideoTask = new Task<>();
Task<Void> mPlaySoundsTask = new Task<>(); Task<Void> mPlaySoundsTask = new Task<>();
CameraController(CameraView.CameraCallbacks callback) { CameraEngine(CameraView.CameraCallbacks callback) {
mCameraCallbacks = callback; mCameraCallbacks = callback;
mCrashHandler = new Handler(Looper.getMainLooper()); mCrashHandler = new Handler(Looper.getMainLooper());
mHandler = WorkerHandler.get("CameraViewController"); mHandler = WorkerHandler.get("CameraViewController");
@ -169,7 +169,7 @@ abstract class CameraController implements
// Public & not final so we can verify with mockito in CameraViewTest // Public & not final so we can verify with mockito in CameraViewTest
public void destroy() { public void destroy() {
LOG.i("destroy:", "state:", ss()); LOG.i("destroy:", "state:", ss());
// Prevent CameraController leaks. Don't set to null, or exceptions // Prevent CameraEngine leaks. Don't set to null, or exceptions
// inside the standard stop() method might crash the main thread. // inside the standard stop() method might crash the main thread.
mHandler.getThread().setUncaughtExceptionHandler(new NoOpExceptionHandler()); mHandler.getThread().setUncaughtExceptionHandler(new NoOpExceptionHandler());
// Stop if needed. // Stop if needed.
@ -632,6 +632,9 @@ abstract class CameraController implements
selector = SizeSelectors.or(selector, SizeSelectors.biggest()); selector = SizeSelectors.or(selector, SizeSelectors.biggest());
List<Size> list = new ArrayList<>(sizes); List<Size> list = new ArrayList<>(sizes);
Size result = selector.select(list).get(0); Size result = selector.select(list).get(0);
if (!list.contains(result)) {
throw new RuntimeException("SizeSelectors must not return Sizes other than those in the input list.");
}
LOG.i("computeCaptureSize:", "result:", result, "flip:", flip, "mode:", mode); LOG.i("computeCaptureSize:", "result:", result, "flip:", flip, "mode:", mode);
if (flip) result = result.flip(); // Go back to REF_SENSOR if (flip) result = result.flip(); // Go back to REF_SENSOR
return result; return result;
@ -677,6 +680,9 @@ abstract class CameraController implements
selector = matchAll; selector = matchAll;
} }
Size result = selector.select(sizes).get(0); Size result = selector.select(sizes).get(0);
if (!sizes.contains(result)) {
throw new RuntimeException("SizeSelectors must not return Sizes other than those in the input list.");
}
if (flip) result = result.flip(); if (flip) result = result.flip();
LOG.i("computePreviewStreamSize:", "result:", result, "flip:", flip); LOG.i("computePreviewStreamSize:", "result:", result, "flip:", flip);
return result; return result;

@ -84,7 +84,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
/* for tests */ CameraCallbacks mCameraCallbacks; /* for tests */ CameraCallbacks mCameraCallbacks;
private CameraPreview mCameraPreview; private CameraPreview mCameraPreview;
private OrientationHelper mOrientationHelper; private OrientationHelper mOrientationHelper;
private CameraController mCameraController; private CameraEngine mCameraEngine;
private MediaActionSound mSound; private MediaActionSound mSound;
/* for tests */ List<CameraListener> mListeners = new CopyOnWriteArrayList<>(); /* for tests */ List<CameraListener> mListeners = new CopyOnWriteArrayList<>();
/* for tests */ List<FrameProcessor> mFrameProcessors = new CopyOnWriteArrayList<>(); /* for tests */ List<FrameProcessor> mFrameProcessors = new CopyOnWriteArrayList<>();
@ -149,7 +149,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
// Components // Components
mCameraCallbacks = new Callbacks(); mCameraCallbacks = new Callbacks();
mCameraController = instantiateCameraController(mCameraCallbacks); mCameraEngine = instantiateCameraController(mCameraCallbacks);
mUiHandler = new Handler(Looper.getMainLooper()); mUiHandler = new Handler(Looper.getMainLooper());
mFrameProcessorsHandler = WorkerHandler.get("FrameProcessorsWorker"); mFrameProcessorsHandler = WorkerHandler.get("FrameProcessorsWorker");
@ -196,7 +196,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
} }
} }
protected CameraController instantiateCameraController(CameraCallbacks callbacks) { protected CameraEngine instantiateCameraController(CameraCallbacks callbacks) {
return new Camera1(callbacks); return new Camera1(callbacks);
} }
@ -220,7 +220,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
/* for tests */ void instantiatePreview() { /* for tests */ void instantiatePreview() {
mCameraPreview = instantiatePreview(getContext(), this); mCameraPreview = instantiatePreview(getContext(), this);
mCameraController.setPreview(mCameraPreview); mCameraEngine.setPreview(mCameraPreview);
} }
@Override @Override
@ -275,7 +275,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Size previewSize = mCameraController.getPreviewStreamSize(CameraController.REF_VIEW); Size previewSize = mCameraEngine.getPreviewStreamSize(CameraEngine.REF_VIEW);
if (previewSize == null) { if (previewSize == null) {
LOG.w("onMeasure:", "surface is not ready. Calling default behavior."); LOG.w("onMeasure:", "surface is not ready. Calling default behavior.");
super.onMeasure(widthMeasureSpec, heightMeasureSpec); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@ -474,7 +474,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (!isOpened()) return true; if (!isOpened()) return true;
// Pass to our own GestureLayouts // Pass to our own GestureLayouts
CameraOptions options = mCameraController.getCameraOptions(); // Non null CameraOptions options = mCameraEngine.getCameraOptions(); // Non null
if (mPinchGestureLayout.onTouchEvent(event)) { if (mPinchGestureLayout.onTouchEvent(event)) {
LOG.i("onTouchEvent", "pinch!"); LOG.i("onTouchEvent", "pinch!");
onGesture(mPinchGestureLayout, options); onGesture(mPinchGestureLayout, options);
@ -491,7 +491,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
// Some gesture layout detected a gesture. It's not known at this moment: // Some gesture layout detected a gesture. It's not known at this moment:
// (1) if it was mapped to some action (we check here) // (1) if it was mapped to some action (we check here)
// (2) if it's supported by the camera (CameraController checks) // (2) if it's supported by the camera (CameraEngine checks)
private void onGesture(GestureLayout source, @NonNull CameraOptions options) { private void onGesture(GestureLayout source, @NonNull CameraOptions options) {
Gesture gesture = source.getGesture(); Gesture gesture = source.getGesture();
GestureAction action = mGestureMap.get(gesture); GestureAction action = mGestureMap.get(gesture);
@ -500,30 +500,30 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
switch (action) { switch (action) {
case CAPTURE: case CAPTURE:
mCameraController.takePicture(); mCameraEngine.takePicture();
break; break;
case FOCUS: case FOCUS:
case FOCUS_WITH_MARKER: case FOCUS_WITH_MARKER:
mCameraController.startAutoFocus(gesture, points[0]); mCameraEngine.startAutoFocus(gesture, points[0]);
break; break;
case ZOOM: case ZOOM:
oldValue = mCameraController.getZoomValue(); oldValue = mCameraEngine.getZoomValue();
newValue = source.computeValue(oldValue, 0, 1); newValue = source.computeValue(oldValue, 0, 1);
if (newValue != oldValue) { if (newValue != oldValue) {
mCameraController.setZoom(newValue, points, true); mCameraEngine.setZoom(newValue, points, true);
} }
break; break;
case EXPOSURE_CORRECTION: case EXPOSURE_CORRECTION:
oldValue = mCameraController.getExposureCorrectionValue(); oldValue = mCameraEngine.getExposureCorrectionValue();
float minValue = options.getExposureCorrectionMinValue(); float minValue = options.getExposureCorrectionMinValue();
float maxValue = options.getExposureCorrectionMaxValue(); float maxValue = options.getExposureCorrectionMaxValue();
newValue = source.computeValue(oldValue, minValue, maxValue); newValue = source.computeValue(oldValue, minValue, maxValue);
if (newValue != oldValue) { if (newValue != oldValue) {
float[] bounds = new float[]{minValue, maxValue}; float[] bounds = new float[]{minValue, maxValue};
mCameraController.setExposureCorrection(newValue, bounds, points, true); mCameraEngine.setExposureCorrection(newValue, bounds, points, true);
} }
break; break;
} }
@ -538,11 +538,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return whether the camera has started * @return whether the camera has started
*/ */
public boolean isOpened() { public boolean isOpened() {
return mCameraController.getState() >= CameraController.STATE_STARTED; return mCameraEngine.getState() >= CameraEngine.STATE_STARTED;
} }
private boolean isClosed() { private boolean isClosed() {
return mCameraController.getState() == CameraController.STATE_STOPPED; return mCameraEngine.getState() == CameraEngine.STATE_STOPPED;
} }
/** /**
@ -567,10 +567,10 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (!isEnabled()) return; if (!isEnabled()) return;
if (mCameraPreview != null) mCameraPreview.onResume(); if (mCameraPreview != null) mCameraPreview.onResume();
if (checkPermissions(getAudio())) { if (checkPermissions(getAudio())) {
// Update display orientation for current CameraController // Update display orientation for current CameraEngine
mOrientationHelper.enable(getContext()); mOrientationHelper.enable(getContext());
mCameraController.setDisplayOffset(mOrientationHelper.getDisplayOffset()); mCameraEngine.setDisplayOffset(mOrientationHelper.getDisplayOffset());
mCameraController.start(); mCameraEngine.start();
} }
} }
@ -633,7 +633,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
public void close() { public void close() {
mCameraController.stop(); mCameraEngine.stop();
if (mCameraPreview != null) mCameraPreview.onPause(); if (mCameraPreview != null) mCameraPreview.onPause();
} }
@ -646,7 +646,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public void destroy() { public void destroy() {
clearCameraListeners(); clearCameraListeners();
clearFrameProcessors(); clearFrameProcessors();
mCameraController.destroy(); mCameraEngine.destroy();
if (mCameraPreview != null) mCameraPreview.onDestroy(); if (mCameraPreview != null) mCameraPreview.onDestroy();
} }
@ -693,7 +693,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@Nullable @Nullable
public CameraOptions getCameraOptions() { public CameraOptions getCameraOptions() {
return mCameraController.getCameraOptions(); return mCameraEngine.getCameraOptions();
} }
@ -718,7 +718,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (EVvalue < min) EVvalue = min; if (EVvalue < min) EVvalue = min;
if (EVvalue > max) EVvalue = max; if (EVvalue > max) EVvalue = max;
float[] bounds = new float[]{min, max}; float[] bounds = new float[]{min, max};
mCameraController.setExposureCorrection(EVvalue, bounds, null, false); mCameraEngine.setExposureCorrection(EVvalue, bounds, null, false);
} }
} }
@ -729,7 +729,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return the current exposure correction value * @return the current exposure correction value
*/ */
public float getExposureCorrection() { public float getExposureCorrection() {
return mCameraController.getExposureCorrectionValue(); return mCameraEngine.getExposureCorrectionValue();
} }
@ -746,7 +746,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public void setZoom(float zoom) { public void setZoom(float zoom) {
if (zoom < 0) zoom = 0; if (zoom < 0) zoom = 0;
if (zoom > 1) zoom = 1; if (zoom > 1) zoom = 1;
mCameraController.setZoom(zoom, null, false); mCameraEngine.setZoom(zoom, null, false);
} }
@ -755,7 +755,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return the current zoom value * @return the current zoom value
*/ */
public float getZoom() { public float getZoom() {
return mCameraController.getZoomValue(); return mCameraEngine.getZoomValue();
} }
@ -811,7 +811,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param hdr desired hdr value * @param hdr desired hdr value
*/ */
public void setHdr(@NonNull Hdr hdr) { public void setHdr(@NonNull Hdr hdr) {
mCameraController.setHdr(hdr); mCameraEngine.setHdr(hdr);
} }
@ -838,7 +838,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public Hdr getHdr() { public Hdr getHdr() {
return mCameraController.getHdr(); return mCameraEngine.getHdr();
} }
@ -854,7 +854,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
location.setAltitude(0); location.setAltitude(0);
location.setLatitude(latitude); location.setLatitude(latitude);
location.setLongitude(longitude); location.setLongitude(longitude);
mCameraController.setLocation(location); mCameraEngine.setLocation(location);
} }
@ -864,7 +864,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param location current location * @param location current location
*/ */
public void setLocation(@Nullable Location location) { public void setLocation(@Nullable Location location) {
mCameraController.setLocation(location); mCameraEngine.setLocation(location);
} }
@ -875,7 +875,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@Nullable @Nullable
public Location getLocation() { public Location getLocation() {
return mCameraController.getLocation(); return mCameraEngine.getLocation();
} }
@ -891,7 +891,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param whiteBalance desired white balance behavior. * @param whiteBalance desired white balance behavior.
*/ */
public void setWhiteBalance(@NonNull WhiteBalance whiteBalance) { public void setWhiteBalance(@NonNull WhiteBalance whiteBalance) {
mCameraController.setWhiteBalance(whiteBalance); mCameraEngine.setWhiteBalance(whiteBalance);
} }
@ -901,7 +901,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public WhiteBalance getWhiteBalance() { public WhiteBalance getWhiteBalance() {
return mCameraController.getWhiteBalance(); return mCameraEngine.getWhiteBalance();
} }
@ -914,7 +914,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param facing a facing value. * @param facing a facing value.
*/ */
public void setFacing(@NonNull Facing facing) { public void setFacing(@NonNull Facing facing) {
mCameraController.setFacing(facing); mCameraEngine.setFacing(facing);
} }
@ -924,7 +924,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public Facing getFacing() { public Facing getFacing() {
return mCameraController.getFacing(); return mCameraEngine.getFacing();
} }
@ -935,7 +935,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return the new facing value * @return the new facing value
*/ */
public Facing toggleFacing() { public Facing toggleFacing() {
Facing facing = mCameraController.getFacing(); Facing facing = mCameraEngine.getFacing();
switch (facing) { switch (facing) {
case BACK: case BACK:
setFacing(Facing.FRONT); setFacing(Facing.FRONT);
@ -946,7 +946,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
break; break;
} }
return mCameraController.getFacing(); return mCameraEngine.getFacing();
} }
@ -961,7 +961,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param flash desired flash mode. * @param flash desired flash mode.
*/ */
public void setFlash(@NonNull Flash flash) { public void setFlash(@NonNull Flash flash) {
mCameraController.setFlash(flash); mCameraEngine.setFlash(flash);
} }
@ -971,7 +971,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public Flash getFlash() { public Flash getFlash() {
return mCameraController.getFlash(); return mCameraEngine.getFlash();
} }
@ -987,11 +987,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
if (audio == getAudio() || isClosed()) { if (audio == getAudio() || isClosed()) {
// Check did took place, or will happen on start(). // Check did took place, or will happen on start().
mCameraController.setAudio(audio); mCameraEngine.setAudio(audio);
} else if (checkPermissions(audio)) { } else if (checkPermissions(audio)) {
// Camera is running. Pass. // Camera is running. Pass.
mCameraController.setAudio(audio); mCameraEngine.setAudio(audio);
} else { } else {
// This means that the audio permission is being asked. // This means that the audio permission is being asked.
@ -1009,7 +1009,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public Audio getAudio() { public Audio getAudio() {
return mCameraController.getAudio(); return mCameraEngine.getAudio();
} }
@ -1021,14 +1021,14 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* the autofocus will not be reset. * the autofocus will not be reset.
*/ */
public void setAutoFocusResetDelay(long delayMillis) { public void setAutoFocusResetDelay(long delayMillis) {
mCameraController.setAutoFocusResetDelay(delayMillis); mCameraEngine.setAutoFocusResetDelay(delayMillis);
} }
/** /**
* Returns the current delay in milliseconds to reset the focus after an autofocus process. * Returns the current delay in milliseconds to reset the focus after an autofocus process.
* @return the current autofocus reset delay in milliseconds. * @return the current autofocus reset delay in milliseconds.
*/ */
public long getAutoFocusResetDelay() { return mCameraController.getAutoFocusResetDelay(); } public long getAutoFocusResetDelay() { return mCameraEngine.getAutoFocusResetDelay(); }
/** /**
@ -1041,7 +1041,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
public void startAutoFocus(float x, float y) { public void startAutoFocus(float x, float y) {
if (x < 0 || x > getWidth()) throw new IllegalArgumentException("x should be >= 0 and <= getWidth()"); if (x < 0 || x > getWidth()) throw new IllegalArgumentException("x should be >= 0 and <= getWidth()");
if (y < 0 || y > getHeight()) throw new IllegalArgumentException("y should be >= 0 and <= getHeight()"); if (y < 0 || y > getHeight()) throw new IllegalArgumentException("y should be >= 0 and <= getHeight()");
mCameraController.startAutoFocus(null, new PointF(x, y)); mCameraEngine.startAutoFocus(null, new PointF(x, y));
} }
@ -1063,7 +1063,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param selector a size selector * @param selector a size selector
*/ */
public void setPreviewStreamSize(@NonNull SizeSelector selector) { public void setPreviewStreamSize(@NonNull SizeSelector selector) {
mCameraController.setPreviewStreamSizeSelector(selector); mCameraEngine.setPreviewStreamSizeSelector(selector);
} }
@ -1076,7 +1076,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param mode desired session type. * @param mode desired session type.
*/ */
public void setMode(@NonNull Mode mode) { public void setMode(@NonNull Mode mode) {
mCameraController.setMode(mode); mCameraEngine.setMode(mode);
} }
@ -1086,7 +1086,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public Mode getMode() { public Mode getMode() {
return mCameraController.getMode(); return mCameraEngine.getMode();
} }
@ -1099,7 +1099,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param selector a size selector * @param selector a size selector
*/ */
public void setPictureSize(@NonNull SizeSelector selector) { public void setPictureSize(@NonNull SizeSelector selector) {
mCameraController.setPictureSizeSelector(selector); mCameraEngine.setPictureSizeSelector(selector);
} }
@ -1112,7 +1112,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param selector a size selector * @param selector a size selector
*/ */
public void setVideoSize(@NonNull SizeSelector selector) { public void setVideoSize(@NonNull SizeSelector selector) {
mCameraController.setVideoSizeSelector(selector); mCameraEngine.setVideoSizeSelector(selector);
} }
/** /**
@ -1122,7 +1122,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param bitRate desired bit rate * @param bitRate desired bit rate
*/ */
public void setVideoBitRate(int bitRate) { public void setVideoBitRate(int bitRate) {
mCameraController.setVideoBitRate(bitRate); mCameraEngine.setVideoBitRate(bitRate);
} }
/** /**
@ -1130,7 +1130,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return current bit rate * @return current bit rate
*/ */
public int getVideoBitRate() { public int getVideoBitRate() {
return mCameraController.getVideoBitRate(); return mCameraEngine.getVideoBitRate();
} }
/** /**
@ -1140,7 +1140,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param bitRate desired bit rate * @param bitRate desired bit rate
*/ */
public void setAudioBitRate(int bitRate) { public void setAudioBitRate(int bitRate) {
mCameraController.setAudioBitRate(bitRate); mCameraEngine.setAudioBitRate(bitRate);
} }
/** /**
@ -1148,7 +1148,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return current bit rate * @return current bit rate
*/ */
public int getAudioBitRate() { public int getAudioBitRate() {
return mCameraController.getAudioBitRate(); return mCameraEngine.getAudioBitRate();
} }
/** /**
@ -1226,7 +1226,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @see #takePictureSnapshot() * @see #takePictureSnapshot()
*/ */
public void takePicture() { public void takePicture() {
mCameraController.takePicture(); mCameraEngine.takePicture();
} }
@ -1242,7 +1242,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
public void takePictureSnapshot() { public void takePictureSnapshot() {
if (getWidth() == 0 || getHeight() == 0) return; if (getWidth() == 0 || getHeight() == 0) return;
mCameraController.takePictureSnapshot(AspectRatio.of(getWidth(), getHeight())); mCameraEngine.takePictureSnapshot(AspectRatio.of(getWidth(), getHeight()));
} }
@ -1253,7 +1253,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param file a file where the video will be saved * @param file a file where the video will be saved
*/ */
public void takeVideo(@NonNull File file) { public void takeVideo(@NonNull File file) {
mCameraController.takeVideo(file); mCameraEngine.takeVideo(file);
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1274,7 +1274,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
public void takeVideoSnapshot(@NonNull File file) { public void takeVideoSnapshot(@NonNull File file) {
if (getWidth() == 0 || getHeight() == 0) return; if (getWidth() == 0 || getHeight() == 0) return;
mCameraController.takeVideoSnapshot(file, AspectRatio.of(getWidth(), getHeight())); mCameraEngine.takeVideoSnapshot(file, AspectRatio.of(getWidth(), getHeight()));
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1361,7 +1361,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* This will fire {@link CameraListener#onVideoTaken(VideoResult)}. * This will fire {@link CameraListener#onVideoTaken(VideoResult)}.
*/ */
public void stopVideo() { public void stopVideo() {
mCameraController.stopVideo(); mCameraEngine.stopVideo();
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1378,7 +1378,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param maxWidth max width for snapshots * @param maxWidth max width for snapshots
*/ */
public void setSnapshotMaxWidth(int maxWidth) { public void setSnapshotMaxWidth(int maxWidth) {
mCameraController.setSnapshotMaxWidth(maxWidth); mCameraEngine.setSnapshotMaxWidth(maxWidth);
} }
/** /**
@ -1389,7 +1389,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param maxHeight max height for snapshots * @param maxHeight max height for snapshots
*/ */
public void setSnapshotMaxHeight(int maxHeight) { public void setSnapshotMaxHeight(int maxHeight) {
mCameraController.setSnapshotMaxHeight(maxHeight); mCameraEngine.setSnapshotMaxHeight(maxHeight);
} }
/** /**
@ -1405,11 +1405,11 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
// Get the preview size and crop according to the current view size. // Get the preview size and crop according to the current view size.
// It's better to do calculations in the REF_VIEW reference, and then flip if needed. // It's better to do calculations in the REF_VIEW reference, and then flip if needed.
Size preview = mCameraController.getUncroppedSnapshotSize(CameraController.REF_VIEW); Size preview = mCameraEngine.getUncroppedSnapshotSize(CameraEngine.REF_VIEW);
AspectRatio viewRatio = AspectRatio.of(getWidth(), getHeight()); AspectRatio viewRatio = AspectRatio.of(getWidth(), getHeight());
Rect crop = CropHelper.computeCrop(preview, viewRatio); Rect crop = CropHelper.computeCrop(preview, viewRatio);
Size cropSize = new Size(crop.width(), crop.height()); Size cropSize = new Size(crop.width(), crop.height());
if (mCameraController.flip(CameraController.REF_VIEW, CameraController.REF_OUTPUT)) { if (mCameraEngine.flip(CameraEngine.REF_VIEW, CameraEngine.REF_OUTPUT)) {
return cropSize.flip(); return cropSize.flip();
} else { } else {
return cropSize; return cropSize;
@ -1428,7 +1428,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@Nullable @Nullable
public Size getPictureSize() { public Size getPictureSize() {
return mCameraController.getPictureSize(CameraController.REF_OUTPUT); return mCameraEngine.getPictureSize(CameraEngine.REF_OUTPUT);
} }
@ -1443,7 +1443,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@Nullable @Nullable
public Size getVideoSize() { public Size getVideoSize() {
return mCameraController.getVideoSize(CameraController.REF_OUTPUT); return mCameraEngine.getVideoSize(CameraEngine.REF_OUTPUT);
} }
@ -1488,7 +1488,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
public void setPlaySounds(boolean playSounds) { public void setPlaySounds(boolean playSounds) {
mPlaySounds = playSounds && Build.VERSION.SDK_INT >= 16; mPlaySounds = playSounds && Build.VERSION.SDK_INT >= 16;
mCameraController.setPlaySounds(playSounds); mCameraEngine.setPlaySounds(playSounds);
} }
@ -1514,7 +1514,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param codec requested video codec * @param codec requested video codec
*/ */
public void setVideoCodec(@NonNull VideoCodec codec) { public void setVideoCodec(@NonNull VideoCodec codec) {
mCameraController.setVideoCodec(codec); mCameraEngine.setVideoCodec(codec);
} }
@ -1524,7 +1524,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/ */
@NonNull @NonNull
public VideoCodec getVideoCodec() { public VideoCodec getVideoCodec() {
return mCameraController.getVideoCodec(); return mCameraEngine.getVideoCodec();
} }
@ -1536,7 +1536,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param videoMaxSizeInBytes The maximum video size in bytes * @param videoMaxSizeInBytes The maximum video size in bytes
*/ */
public void setVideoMaxSize(long videoMaxSizeInBytes) { public void setVideoMaxSize(long videoMaxSizeInBytes) {
mCameraController.setVideoMaxSize(videoMaxSizeInBytes); mCameraEngine.setVideoMaxSize(videoMaxSizeInBytes);
} }
@ -1548,7 +1548,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return the maximum size in bytes * @return the maximum size in bytes
*/ */
public long getVideoMaxSize() { public long getVideoMaxSize() {
return mCameraController.getVideoMaxSize(); return mCameraEngine.getVideoMaxSize();
} }
@ -1560,7 +1560,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @param videoMaxDurationMillis The maximum video duration in milliseconds * @param videoMaxDurationMillis The maximum video duration in milliseconds
*/ */
public void setVideoMaxDuration(int videoMaxDurationMillis) { public void setVideoMaxDuration(int videoMaxDurationMillis) {
mCameraController.setVideoMaxDuration(videoMaxDurationMillis); mCameraEngine.setVideoMaxDuration(videoMaxDurationMillis);
} }
@ -1572,7 +1572,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return the maximum duration in milliseconds * @return the maximum duration in milliseconds
*/ */
public int getVideoMaxDuration() { public int getVideoMaxDuration() {
return mCameraController.getVideoMaxDuration(); return mCameraEngine.getVideoMaxDuration();
} }
@ -1581,7 +1581,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return boolean indicating if the camera is recording a video * @return boolean indicating if the camera is recording a video
*/ */
public boolean isTakingVideo() { public boolean isTakingVideo() {
return mCameraController.isTakingVideo(); return mCameraEngine.isTakingVideo();
} }
@ -1590,7 +1590,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
* @return boolean indicating if the camera is capturing a picture * @return boolean indicating if the camera is capturing a picture
*/ */
public boolean isTakingPicture() { public boolean isTakingPicture() {
return mCameraController.isTakingPicture(); return mCameraEngine.isTakingPicture();
} }
//endregion //endregion
@ -1736,7 +1736,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@Override @Override
public void onDeviceOrientationChanged(int deviceOrientation) { public void onDeviceOrientationChanged(int deviceOrientation) {
mLogger.i("onDeviceOrientationChanged", deviceOrientation); mLogger.i("onDeviceOrientationChanged", deviceOrientation);
mCameraController.setDeviceOrientation(deviceOrientation); mCameraEngine.setDeviceOrientation(deviceOrientation);
int displayOffset = mOrientationHelper.getDisplayOffset(); int displayOffset = mOrientationHelper.getDisplayOffset();
final int value = (deviceOrientation + displayOffset) % 360; final int value = (deviceOrientation + displayOffset) % 360;
mUiHandler.post(new Runnable() { mUiHandler.post(new Runnable() {

@ -111,7 +111,7 @@ class SnapshotPictureRecorder extends PictureRecorder {
// Apply scale and crop: // Apply scale and crop:
// NOTE: scaleX and scaleY are in REF_VIEW, while our input appears to be in REF_SENSOR. // NOTE: scaleX and scaleY are in REF_VIEW, while our input appears to be in REF_SENSOR.
boolean flip = mController.flip(CameraController.REF_VIEW, CameraController.REF_SENSOR); boolean flip = mController.flip(CameraEngine.REF_VIEW, CameraEngine.REF_SENSOR);
float realScaleX = flip ? scaleY : scaleX; float realScaleX = flip ? scaleY : scaleX;
float realScaleY = flip ? scaleX : scaleY; float realScaleY = flip ? scaleX : scaleY;
float scaleTranslX = (1F - realScaleX) / 2F; float scaleTranslX = (1F - realScaleX) / 2F;

@ -9,7 +9,7 @@ import android.view.ViewGroup;
import com.otaliastudios.cameraview.size.Size; import com.otaliastudios.cameraview.size.Size;
/** /**
* A CameraPreview takes in input stream from the {@link CameraController}, and streams it * A CameraPreview takes in input stream from the {@link CameraEngine}, and streams it
* into an output surface that belongs to the view hierarchy. * into an output surface that belongs to the view hierarchy.
* *
* @param <T> the type of view which hosts the content surface * @param <T> the type of view which hosts the content surface
@ -22,7 +22,7 @@ abstract class CameraPreview<T extends View, Output> {
// Used for testing. // Used for testing.
Task<Void> mCropTask = new Task<>(); Task<Void> mCropTask = new Task<>();
// This is used to notify CameraController to recompute its camera Preview size. // This is used to notify CameraEngine to recompute its camera Preview size.
// After that, CameraView will need a new layout pass to adapt to the Preview size. // After that, CameraView will need a new layout pass to adapt to the Preview size.
interface SurfaceCallback { interface SurfaceCallback {
void onSurfaceAvailable(); void onSurfaceAvailable();

Loading…
Cancel
Save