Skip to content

Commit

Permalink
expose all methods in Camera1 and Camera2 sources
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Mar 2, 2024
1 parent 89be60e commit d6a87e7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -158,4 +161,28 @@ class Camera1Source(context: Context): VideoSource() {
fun getZoomRange(): Range<Int> = 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -160,4 +162,41 @@ class Camera2Source(context: Context): VideoSource() {
fun getZoomRange(): Range<Float> = 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<String>? = 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
}

0 comments on commit d6a87e7

Please sign in to comment.