From d1f6dea146570af1889a4bbb32bd2d16019dfef5 Mon Sep 17 00:00:00 2001 From: Mattia Iavarone Date: Sat, 5 Oct 2019 12:38:17 +0200 Subject: [PATCH] Reorder operations in FullVideoRecorder --- .../cameraview/video/FullVideoRecorder.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java index 074d147d..bed7a1d0 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java @@ -100,7 +100,13 @@ public abstract class FullVideoRecorder extends VideoRecorder { } mMediaRecorder.setOutputFormat(mProfile.fileFormat); - // 4. Update the VideoResult stub with DeviceEncoders constraints + // 4. Update the VideoResult stub with information from the profile, if the + // stub values are absent or incomplete + if (stub.videoFrameRate <= 0) stub.videoFrameRate = mProfile.videoFrameRate; + if (stub.videoBitRate <= 0) stub.videoBitRate = mProfile.videoBitRate; + if (stub.audioBitRate <= 0 && hasAudio) stub.audioBitRate = mProfile.audioBitRate; + + // 5. Update the VideoResult stub with DeviceEncoders constraints if (applyEncodersConstraints) { // A. Get the audio mime type // https://android.googlesource.com/platform/frameworks/av/+/master/media/libmediaplayerservice/StagefrightRecorder.cpp#1096 @@ -166,15 +172,6 @@ public abstract class FullVideoRecorder extends VideoRecorder { if (flip) stub.size = stub.size.flip(); } - // 5. Update the VideoResult stub with information from the profile, if the - // stub values are absent or incomplete - stub.videoFrameRate = stub.videoFrameRate > 0 ? stub.videoFrameRate - : mProfile.videoFrameRate; - stub.videoBitRate = stub.videoBitRate > 0 ? stub.videoBitRate : mProfile.videoBitRate; - if (hasAudio) { - stub.audioBitRate = stub.audioBitRate > 0 ? stub.audioBitRate : mProfile.audioBitRate; - } - // 6A. Configure MediaRecorder from stub and from profile (video) boolean flip = stub.rotation % 180 != 0; mMediaRecorder.setVideoSize( @@ -264,13 +261,15 @@ public abstract class FullVideoRecorder extends VideoRecorder { try { mMediaRecorder.stop(); } catch (Exception e) { - LOG.w("stop:", "Error while closing media recorder.", e); // This can happen if stopVideo() is called right after takeVideo() // (in which case we don't care). Or when prepare()/start() have failed for // some reason and we are not allowed to call stop. // Make sure we don't override the error if one exists already. mResult = null; - if (mError == null) mError = e; + if (mError == null) { + LOG.w("stop:", "Error while closing media recorder.", e); + mError = e; + } } mMediaRecorder.release(); }