Reorder operations in FullVideoRecorder

pull/617/head
Mattia Iavarone 6 years ago
parent 19277c6ddb
commit d1f6dea146
  1. 23
      cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java

@ -100,7 +100,13 @@ public abstract class FullVideoRecorder extends VideoRecorder {
} }
mMediaRecorder.setOutputFormat(mProfile.fileFormat); 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) { if (applyEncodersConstraints) {
// A. Get the audio mime type // A. Get the audio mime type
// https://android.googlesource.com/platform/frameworks/av/+/master/media/libmediaplayerservice/StagefrightRecorder.cpp#1096 // 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(); 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) // 6A. Configure MediaRecorder from stub and from profile (video)
boolean flip = stub.rotation % 180 != 0; boolean flip = stub.rotation % 180 != 0;
mMediaRecorder.setVideoSize( mMediaRecorder.setVideoSize(
@ -264,13 +261,15 @@ public abstract class FullVideoRecorder extends VideoRecorder {
try { try {
mMediaRecorder.stop(); mMediaRecorder.stop();
} catch (Exception e) { } catch (Exception e) {
LOG.w("stop:", "Error while closing media recorder.", e);
// This can happen if stopVideo() is called right after takeVideo() // This can happen if stopVideo() is called right after takeVideo()
// (in which case we don't care). Or when prepare()/start() have failed for // (in which case we don't care). Or when prepare()/start() have failed for
// some reason and we are not allowed to call stop. // some reason and we are not allowed to call stop.
// Make sure we don't override the error if one exists already. // Make sure we don't override the error if one exists already.
mResult = null; mResult = null;
if (mError == null) mError = e; if (mError == null) {
LOG.w("stop:", "Error while closing media recorder.", e);
mError = e;
}
} }
mMediaRecorder.release(); mMediaRecorder.release();
} }

Loading…
Cancel
Save