From d6a87e7f43750c1f6c0c39d1f0354823e8c6fdd5 Mon Sep 17 00:00:00 2001 From: pedro Date: Sat, 2 Mar 2024 23:11:00 +0100 Subject: [PATCH] expose all methods in Camera1 and Camera2 sources --- .../util/sources/video/Camera1Source.kt | 39 +++++++++++--- .../util/sources/video/Camera2Source.kt | 51 ++++++++++++++++--- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/com/pedro/library/util/sources/video/Camera1Source.kt b/library/src/main/java/com/pedro/library/util/sources/video/Camera1Source.kt index e655fa8ef..56b546503 100644 --- a/library/src/main/java/com/pedro/library/util/sources/video/Camera1Source.kt +++ b/library/src/main/java/com/pedro/library/util/sources/video/Camera1Source.kt @@ -23,9 +23,11 @@ import android.os.Build import android.util.Range import android.util.Size import android.view.MotionEvent +import android.view.View import androidx.annotation.RequiresApi import com.pedro.encoder.input.video.Camera1ApiManager import com.pedro.encoder.input.video.CameraHelper +import com.pedro.encoder.input.video.facedetector.FaceDetectorCallback /** * Created by pedro on 11/1/24. @@ -115,8 +117,7 @@ class Camera1Source(context: Context): VideoSource() { } fun getExposure(): Int { - return if (isRunning()) camera.exposure - else 0 + return if (isRunning()) camera.exposure else 0 } fun enableLantern() { @@ -128,8 +129,7 @@ class Camera1Source(context: Context): VideoSource() { } fun isLanternEnabled(): Boolean { - return if (isRunning()) camera.isLanternEnabled - else false + return if (isRunning()) camera.isLanternEnabled else false } fun enableAutoFocus() { @@ -143,8 +143,11 @@ class Camera1Source(context: Context): VideoSource() { } fun isAutoFocusEnabled(): Boolean { - return if (isRunning()) camera.isAutoFocusEnabled - else false + return if (isRunning()) camera.isAutoFocusEnabled else false + } + + fun tapToFocus(view: View, event: MotionEvent) { + camera.tapToFocus(view, event) } fun setZoom(event: MotionEvent) { @@ -158,4 +161,28 @@ class Camera1Source(context: Context): VideoSource() { fun getZoomRange(): Range = Range(camera.minZoom, camera.maxZoom) fun getZoom(): Int = camera.zoom + + fun enableFaceDetection(callback: FaceDetectorCallback): Boolean { + return if (isRunning()) camera.enableFaceDetection(callback) else false + } + + fun disableFaceDetection() { + if (isRunning()) camera.disableFaceDetection() + } + + fun isFaceDetectionEnabled() = camera.isFaceDetectionEnabled + + fun openCameraId(id: Int) { + camera.switchCamera(id) + } + + fun enableVideoStabilization(): Boolean { + return if (isRunning()) camera.enableVideoStabilization() else false + } + + fun disableVideoStabilization() { + if (isRunning()) camera.disableVideoStabilization() + } + + fun isVideoStabilizationEnabled() = camera.isVideoStabilizationEnabled } \ No newline at end of file diff --git a/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt b/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt index 4c4925910..4ccfa8802 100644 --- a/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt +++ b/library/src/main/java/com/pedro/library/util/sources/video/Camera2Source.kt @@ -26,6 +26,7 @@ import android.view.MotionEvent import androidx.annotation.RequiresApi import com.pedro.encoder.input.video.Camera2ApiManager import com.pedro.encoder.input.video.CameraHelper +import com.pedro.encoder.input.video.facedetector.FaceDetectorCallback /** * Created by pedro on 11/1/24. @@ -117,8 +118,7 @@ class Camera2Source(context: Context): VideoSource() { } fun getExposure(): Int { - return if (isRunning()) camera.exposure - else 0 + return if (isRunning()) camera.exposure else 0 } fun enableLantern() { @@ -130,8 +130,7 @@ class Camera2Source(context: Context): VideoSource() { } fun isLanternEnabled(): Boolean { - return if (isRunning()) camera.isLanternEnabled - else false + return if (isRunning()) camera.isLanternEnabled else false } fun enableAutoFocus() { @@ -145,8 +144,11 @@ class Camera2Source(context: Context): VideoSource() { } fun isAutoFocusEnabled(): Boolean { - return if (isRunning()) camera.isAutoFocusEnabled - else false + return if (isRunning()) camera.isAutoFocusEnabled else false + } + + fun tapToFocus(event: MotionEvent) { + camera.tapToFocus(event) } fun setZoom(event: MotionEvent) { @@ -160,4 +162,41 @@ class Camera2Source(context: Context): VideoSource() { fun getZoomRange(): Range = camera.zoomRange fun getZoom(): Float = camera.zoom + + fun enableFaceDetection(callback: FaceDetectorCallback): Boolean { + return if (isRunning()) camera.enableFaceDetection(callback) else false + } + + fun disableFaceDetection() { + if (isRunning()) camera.disableFaceDetection() + } + + fun isFaceDetectionEnabled() = camera.isFaceDetectionEnabled + + fun camerasAvailable(): Array? = camera.camerasAvailable + + fun openCameraId(id: String) { + if (isRunning()) stop() + camera.openCameraId(id) + } + + fun enableOpticalVideoStabilization(): Boolean { + return if (isRunning()) camera.enableOpticalVideoStabilization() else false + } + + fun disableOpticalVideoStabilization() { + if (isRunning()) camera.disableOpticalVideoStabilization() + } + + fun isOpticalVideoStabilizationEnabled() = camera.isOpticalStabilizationEnabled + + fun enableVideoStabilization(): Boolean { + return if (isRunning()) camera.enableVideoStabilization() else false + } + + fun disableVideoStabilization() { + if (isRunning()) camera.disableVideoStabilization() + } + + fun isVideoStabilizationEnabled() = camera.isVideoStabilizationEnabled } \ No newline at end of file