Compare commits
2 Commits
loewy/fix-
...
bump-react
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e7b295546a | ||
|
|
d87ed8ced2 |
@@ -15,7 +15,6 @@ import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.Surface
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.WindowManager
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.mlkit.vision.barcode.common.Barcode
|
||||
import com.mrousavy.camera.core.capture.RepeatingCaptureRequest
|
||||
@@ -426,19 +425,6 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
|
||||
|
||||
val fps = configuration?.fps ?: 30
|
||||
|
||||
// Get actual device rotation from WindowManager instead of relying on
|
||||
// the orientation prop from React, which may not update on Android when
|
||||
// rotating between landscape-left and landscape-right.
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val deviceRotation = windowManager.defaultDisplay.rotation
|
||||
val actualOrientation = when (deviceRotation) {
|
||||
Surface.ROTATION_0 -> Orientation.PORTRAIT
|
||||
Surface.ROTATION_90 -> Orientation.LANDSCAPE_LEFT
|
||||
Surface.ROTATION_180 -> Orientation.PORTRAIT_UPSIDE_DOWN
|
||||
Surface.ROTATION_270 -> Orientation.LANDSCAPE_RIGHT
|
||||
else -> Orientation.PORTRAIT
|
||||
}
|
||||
|
||||
val recording = RecordingSession(
|
||||
context,
|
||||
cameraId,
|
||||
|
||||
@@ -105,6 +105,12 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
||||
muxerContext?.finish()
|
||||
chunkIndex++
|
||||
|
||||
val format = this.encodedFormat
|
||||
if (format == null) {
|
||||
Log.e(TAG, "Cannot create muxer: encodedFormat is null (onOutputFormatChanged not called yet)")
|
||||
return
|
||||
}
|
||||
|
||||
val newFileName = "$chunkIndex.mp4"
|
||||
val newOutputFile = File(this.outputDirectory, newFileName)
|
||||
Log.i(TAG, "Creating new muxer for file: $newFileName")
|
||||
@@ -114,7 +120,7 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
||||
)
|
||||
muxer.setOrientationHint(orientationHint)
|
||||
muxerContext = MuxerContext(
|
||||
muxer, newOutputFile, chunkIndex, bufferInfo.presentationTimeUs, this.encodedFormat!!, this.callbacks
|
||||
muxer, newOutputFile, chunkIndex, bufferInfo.presentationTimeUs, format, this.callbacks
|
||||
)
|
||||
}
|
||||
|
||||
@@ -123,7 +129,8 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
||||
}
|
||||
|
||||
private fun chunkLengthUs(bufferInfo: BufferInfo): Long {
|
||||
return bufferInfo.presentationTimeUs - muxerContext!!.startTimeUs
|
||||
val context = muxerContext ?: return 0L
|
||||
return bufferInfo.presentationTimeUs - context.startTimeUs
|
||||
}
|
||||
|
||||
fun start() {
|
||||
@@ -155,7 +162,13 @@ class ChunkedRecordingManager(private val encoder: MediaCodec, private val outpu
|
||||
if (muxerContext == null || (atKeyframe(bufferInfo) && chunkLengthUs(bufferInfo) >= targetDurationUs)) {
|
||||
this.createNextMuxer(bufferInfo)
|
||||
}
|
||||
muxerContext!!.muxer.writeSampleData(muxerContext!!.videoTrack, encodedData, bufferInfo)
|
||||
val context = muxerContext
|
||||
if (context == null) {
|
||||
Log.e(TAG, "Cannot write sample data: muxerContext is null")
|
||||
encoder.releaseOutputBuffer(index, false)
|
||||
return
|
||||
}
|
||||
context.muxer.writeSampleData(context.videoTrack, encodedData, bufferInfo)
|
||||
encoder.releaseOutputBuffer(index, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,8 @@ import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.PixelCopy
|
||||
import android.view.Surface
|
||||
import android.view.SurfaceHolder
|
||||
import android.view.SurfaceView
|
||||
import android.view.WindowManager
|
||||
import com.facebook.react.bridge.UiThreadUtil
|
||||
import com.mrousavy.camera.extensions.resize
|
||||
import com.mrousavy.camera.extensions.rotatedBy
|
||||
@@ -152,8 +150,6 @@ class PreviewView(context: Context, callback: SurfaceHolder.Callback) :
|
||||
val width = frame.width()
|
||||
val height = frame.height()
|
||||
|
||||
// Create bitmap matching surface frame dimensions for PixelCopy
|
||||
// The original code swapped dimensions assuming landscape input - keep that for consistency
|
||||
val bitmap = Bitmap.createBitmap(height, width, Bitmap.Config.ARGB_8888)
|
||||
|
||||
// Use a coroutine to suspend until the PixelCopy request is complete
|
||||
@@ -163,23 +159,7 @@ class PreviewView(context: Context, callback: SurfaceHolder.Callback) :
|
||||
bitmap,
|
||||
{ copyResult ->
|
||||
if (copyResult == PixelCopy.SUCCESS) {
|
||||
// Get actual device rotation from WindowManager instead of relying on
|
||||
// the orientation prop, which may not update on Android when rotating
|
||||
// between landscape-left and landscape-right.
|
||||
val windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
val deviceRotation = windowManager.defaultDisplay.rotation
|
||||
|
||||
val actualOrientation = when (deviceRotation) {
|
||||
Surface.ROTATION_0 -> Orientation.PORTRAIT
|
||||
Surface.ROTATION_90 -> Orientation.LANDSCAPE_LEFT
|
||||
Surface.ROTATION_180 -> Orientation.PORTRAIT_UPSIDE_DOWN
|
||||
Surface.ROTATION_270 -> Orientation.LANDSCAPE_RIGHT
|
||||
else -> Orientation.PORTRAIT
|
||||
}
|
||||
|
||||
Log.i(TAG, "getBitmap: orientation prop = $orientation, deviceRotation = $deviceRotation, actualOrientation = $actualOrientation")
|
||||
|
||||
continuation.resume(bitmap.transformBitmap(actualOrientation))
|
||||
continuation.resume(rotateBitmap90CounterClockwise(bitmap))
|
||||
} else {
|
||||
continuation.resumeWithException(
|
||||
RuntimeException("PixelCopy failed with error code $copyResult")
|
||||
|
||||
@@ -11,6 +11,6 @@ inline fun withPromise(promise: Promise, closure: () -> Any?) {
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
val error = if (e is CameraError) e else UnknownCameraError(e)
|
||||
promise.reject("${error.domain}/${error.id}", error.message, error.cause)
|
||||
promise.reject("${error.domain}/${error.id}", error.message ?: "Unknown error", error.cause)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user