Create base Camera2 class

pull/493/head
Mattia Iavarone 5 years ago
parent e2e3054a77
commit 3c345826cc
  1. 3
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraOptions1Test.java
  2. 3
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/Mapper1Test.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraOptions.java
  4. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraUtils.java
  5. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  6. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera1Engine.java
  7. 151
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Camera2Engine.java
  8. 70
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/Mapper.java

@ -4,6 +4,7 @@ package com.otaliastudios.cameraview;
import android.hardware.Camera;
import com.otaliastudios.cameraview.controls.Audio;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.Flash;
import com.otaliastudios.cameraview.engine.Mapper;
@ -249,7 +250,7 @@ public class CameraOptions1Test extends BaseTest {
}
CameraOptions o = new CameraOptions(mock(Camera.Parameters.class), false);
Mapper m = Mapper.get();
Mapper m = Mapper.get(Engine.CAMERA1);
Collection<Facing> s = o.getSupportedControls(Facing.class);
assertEquals(s.size(), supported.size());
for (Facing facing : s) {

@ -4,6 +4,7 @@ package com.otaliastudios.cameraview.engine;
import android.hardware.Camera;
import com.otaliastudios.cameraview.BaseTest;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.Flash;
import com.otaliastudios.cameraview.controls.Hdr;
@ -22,7 +23,7 @@ import static org.junit.Assert.*;
@SmallTest
public class Mapper1Test extends BaseTest {
private Mapper mapper = Mapper.get();
private Mapper mapper = Mapper.get(Engine.CAMERA1);
@Test
public void testMap() {

@ -52,7 +52,7 @@ public class CameraOptions {
@SuppressWarnings("deprecation")
public CameraOptions(@NonNull Camera.Parameters params, boolean flipSizes) {
List<String> strings;
Mapper mapper = Mapper.get();
Mapper mapper = Mapper.get(Engine.CAMERA1);
// Facing
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

@ -9,6 +9,7 @@ import android.graphics.Matrix;
import android.hardware.Camera;
import android.os.Handler;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.engine.Mapper;
import com.otaliastudios.cameraview.internal.utils.ExifHelper;
@ -60,7 +61,7 @@ public class CameraUtils {
*/
public static boolean hasCameraFacing(@SuppressWarnings("unused") @NonNull Context context,
@NonNull Facing facing) {
int internal = Mapper.get().map(facing);
int internal = Mapper.get(Engine.CAMERA1).map(facing);
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
for (int i = 0, count = Camera.getNumberOfCameras(); i < count; i++) {
Camera.getCameraInfo(i, cameraInfo);

@ -36,6 +36,7 @@ import com.otaliastudios.cameraview.controls.ControlParser;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.Flash;
import com.otaliastudios.cameraview.engine.Camera2Engine;
import com.otaliastudios.cameraview.markers.MarkerLayout;
import com.otaliastudios.cameraview.engine.Camera1Engine;
import com.otaliastudios.cameraview.engine.CameraEngine;
@ -233,8 +234,8 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
*/
@NonNull
protected CameraEngine instantiateCameraEngine(@NonNull Engine engine, @NonNull CameraEngine.Callback callback) {
if (mExperimental && engine == Engine.CAMERA2) {
throw new RuntimeException("TODO");
if (mExperimental && engine == Engine.CAMERA2 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return new Camera2Engine(callback);
} else {
mEngine = Engine.CAMERA1;
return new Camera1Engine(callback);

@ -17,6 +17,7 @@ import android.view.SurfaceHolder;
import com.otaliastudios.cameraview.CameraException;
import com.otaliastudios.cameraview.CameraLogger;
import com.otaliastudios.cameraview.CameraOptions;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.frame.Frame;
import com.otaliastudios.cameraview.PictureResult;
import com.otaliastudios.cameraview.VideoResult;
@ -75,7 +76,7 @@ public class Camera1Engine extends CameraEngine implements Camera.PreviewCallbac
public Camera1Engine(@NonNull Callback callback) {
super(callback);
mMapper = Mapper.get();
mMapper = Mapper.get(Engine.CAMERA1);
}
private void schedule(@Nullable final Task<Void> task, final boolean ensureAvailable, final Runnable action) {

@ -0,0 +1,151 @@
package com.otaliastudios.cameraview.engine;
import android.graphics.PointF;
import android.location.Location;
import android.os.Build;
import android.view.SurfaceHolder;
import com.otaliastudios.cameraview.CameraException;
import com.otaliastudios.cameraview.CameraLogger;
import com.otaliastudios.cameraview.CameraOptions;
import com.otaliastudios.cameraview.PictureResult;
import com.otaliastudios.cameraview.VideoResult;
import com.otaliastudios.cameraview.controls.Audio;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.Flash;
import com.otaliastudios.cameraview.controls.Hdr;
import com.otaliastudios.cameraview.controls.Mode;
import com.otaliastudios.cameraview.controls.WhiteBalance;
import com.otaliastudios.cameraview.gesture.Gesture;
import com.otaliastudios.cameraview.size.AspectRatio;
import java.io.File;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public class Camera2Engine extends CameraEngine {
private static final String TAG = Camera2Engine.class.getSimpleName();
private static final CameraLogger LOG = CameraLogger.create(TAG);
public Camera2Engine(Callback callback) {
super(callback);
mMapper = Mapper.get(Engine.CAMERA2);
}
@Override
public void onSurfaceAvailable() {
}
@Override
public void onSurfaceChanged() {
}
@Override
public void onSurfaceDestroyed() {
}
@Override
protected void onStart() {
}
@Override
protected void onStop() {
}
@Override
public void onBufferAvailable(@NonNull byte[] buffer) {
}
@Override
public void setMode(@NonNull Mode mode) {
}
@Override
public void setFacing(@NonNull Facing facing) {
}
@Override
public void setZoom(float zoom, @Nullable PointF[] points, boolean notify) {
}
@Override
public void setExposureCorrection(float EVvalue, @NonNull float[] bounds, @Nullable PointF[] points, boolean notify) {
}
@Override
public void setFlash(@NonNull Flash flash) {
}
@Override
public void setWhiteBalance(@NonNull WhiteBalance whiteBalance) {
}
@Override
public void setHdr(@NonNull Hdr hdr) {
}
@Override
public void setLocation(@Nullable Location location) {
}
@Override
public void setAudio(@NonNull Audio audio) {
}
@Override
public void takePicture(@NonNull PictureResult.Stub stub) {
}
@Override
public void takePictureSnapshot(@NonNull PictureResult.Stub stub, @NonNull AspectRatio viewAspectRatio) {
}
@Override
public void takeVideo(@NonNull VideoResult.Stub stub, @NonNull File file) {
}
@Override
public void takeVideoSnapshot(@NonNull VideoResult.Stub stub, @NonNull File file, @NonNull AspectRatio viewAspectRatio) {
}
@Override
public void stopVideo() {
}
@Override
public void startAutoFocus(@Nullable Gesture gesture, @NonNull PointF point) {
}
@Override
public void setPlaySounds(boolean playSounds) {
}
}

@ -3,6 +3,7 @@ package com.otaliastudios.cameraview.engine;
import android.hardware.Camera;
import android.os.Build;
import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.controls.Facing;
import com.otaliastudios.cameraview.controls.Flash;
import com.otaliastudios.cameraview.controls.Hdr;
@ -10,11 +11,28 @@ import com.otaliastudios.cameraview.controls.WhiteBalance;
import java.util.HashMap;
import androidx.annotation.NonNull;
/**
* A Mapper maps camera engine constants to CameraView constants.
*/
public abstract class Mapper {
private static Mapper CAMERA1;
private static Mapper CAMERA2;
public static Mapper get(@NonNull Engine engine) {
if (engine == Engine.CAMERA1) {
if (CAMERA1 == null) CAMERA1 = new Camera1Mapper();
return CAMERA1;
} else if (engine == Engine.CAMERA2) {
if (CAMERA2 == null) CAMERA2 = new Camera2Mapper();
return CAMERA2;
} else {
throw new IllegalArgumentException("Unknown engine.");
}
}
private Mapper() {}
public abstract <T> T map(Flash flash);
@ -43,15 +61,6 @@ public abstract class Mapper {
return null;
}
private static Mapper CAMERA1;
public static Mapper get() {
if (CAMERA1 == null) {
CAMERA1 = new Camera1Mapper();
}
return CAMERA1;
}
@SuppressWarnings("unchecked")
private static class Camera1Mapper extends Mapper {
@ -120,4 +129,47 @@ public abstract class Mapper {
return reverseLookup(HDR, cameraConstant);
}
}
private static class Camera2Mapper extends Mapper {
@Override
public <T> T map(Flash flash) {
return null;
}
@Override
public <T> T map(Facing facing) {
return null;
}
@Override
public <T> T map(WhiteBalance whiteBalance) {
return null;
}
@Override
public <T> T map(Hdr hdr) {
return null;
}
@Override
public <T> Flash unmapFlash(T cameraConstant) {
return null;
}
@Override
public <T> Facing unmapFacing(T cameraConstant) {
return null;
}
@Override
public <T> WhiteBalance unmapWhiteBalance(T cameraConstant) {
return null;
}
@Override
public <T> Hdr unmapHdr(T cameraConstant) {
return null;
}
}
}

Loading…
Cancel
Save