From 9fc981fee81815c61aa1afbea0cf0bf249f729a6 Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 8 May 2023 21:30:38 +0200 Subject: [PATCH] Fix rotation when rebinding camera use cases --- app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt | 7 ++++++- app/src/main/native/libmux.c | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt index 1b2c8cb..f3f27c5 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/CameraActivity.kt @@ -77,6 +77,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { } } private lateinit var sensorOrientationListener: SensorOrientationListener + private var currentRotation = 0 private var previousOrientation: Float = 0f private lateinit var orientedIcons: List private lateinit var encryptedVolume: EncryptedVolume @@ -390,6 +391,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { } supportedSizes }.build()) + .setTargetRotation(currentRotation) .build() } @@ -401,7 +403,9 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { recorderBuilder.setQualitySelector(QualitySelector.from(qualities!![currentQualityIndex])) } videoRecorder = recorderBuilder.build() - videoCapture = VideoCapture.withOutput(videoRecorder!!) + videoCapture = VideoCapture.withOutput(videoRecorder!!).apply { + targetRotation = currentRotation + } } private fun rebindUseCases(): UseCase { @@ -598,6 +602,7 @@ class CameraActivity : BaseActivity(), SensorOrientationListener.Listener { previousOrientation = realOrientation imageCapture?.targetRotation = newOrientation videoCapture?.targetRotation = newOrientation + currentRotation = newOrientation } } diff --git a/app/src/main/native/libmux.c b/app/src/main/native/libmux.c index d8b63ec..eb5c0d5 100644 --- a/app/src/main/native/libmux.c +++ b/app/src/main/native/libmux.c @@ -154,6 +154,7 @@ JNIEXPORT void JNICALL Java_sushi_hardcore_droidfs_video_1recording_FFmpegMuxer_release(JNIEnv *env, jobject thiz, jlong format_context) { AVFormatContext* fc = (AVFormatContext *) format_context; av_free(fc->pb->buffer); + (*env)->DeleteGlobalRef(env, ((struct Muxer*)fc->pb->opaque)->thiz); free(fc->pb->opaque); avio_context_free(&fc->pb); avformat_free_context(fc);