diff --git a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java index dff186e5..f643e522 100644 --- a/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java +++ b/cameraview/src/androidTest/java/com/otaliastudios/cameraview/VideoResultTest.java @@ -31,6 +31,7 @@ public class VideoResultTest extends BaseTest { boolean isSnapshot = true; int maxDuration = 1234; long maxFileSize = 500000; + int reason = VideoResult.REASON_MAX_DURATION_REACHED; result.file = file; result.rotation = rotation; @@ -40,6 +41,7 @@ public class VideoResultTest extends BaseTest { result.isSnapshot = isSnapshot; result.maxDuration = maxDuration; result.maxSize = maxFileSize; + result.endReason = reason; assertEquals(result.getFile(), file); assertEquals(result.getRotation(), rotation); @@ -49,5 +51,6 @@ public class VideoResultTest extends BaseTest { assertEquals(result.isSnapshot(), isSnapshot); assertEquals(result.getMaxSize(), maxFileSize); assertEquals(result.getMaxDuration(), maxDuration); + assertEquals(result.getTerminationReason(), reason); } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaCodecVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaCodecVideoRecorder.java new file mode 100644 index 00000000..0849d955 --- /dev/null +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaCodecVideoRecorder.java @@ -0,0 +1,27 @@ +package com.otaliastudios.cameraview; + +import android.hardware.Camera; +import android.media.CamcorderProfile; +import android.media.MediaRecorder; + +/** + * A {@link VideoRecorder} that uses {@link android.media.MediaCodec} APIs. + */ +class MediaCodecVideoRecorder extends VideoRecorder { + + private static final String TAG = MediaCodecVideoRecorder.class.getSimpleName(); + private static final CameraLogger LOG = CameraLogger.create(TAG); + + MediaCodecVideoRecorder(VideoResult stub, VideoResultListener listener, Camera camera, int cameraId) { + super(stub, listener); + } + + @Override + void start() { + } + + @Override + void close() { + + } +} diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java index e6f1539b..fbf27b7e 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/MediaRecorderVideoRecorder.java @@ -14,9 +14,11 @@ class MediaRecorderVideoRecorder extends VideoRecorder { private MediaRecorder mMediaRecorder; private CamcorderProfile mProfile; + private Mapper mMapper; MediaRecorderVideoRecorder(VideoResult stub, VideoResultListener listener, Camera camera, int cameraId) { super(stub, listener); + mMapper = new Mapper1(); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setCamera(camera); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); @@ -24,6 +26,8 @@ class MediaRecorderVideoRecorder extends VideoRecorder { // TODO: should get a profile of a quality compatible with the chosen size. } + // Camera2 constructor here... + @Override void start() { if (mResult.getAudio() == Audio.ON) { @@ -38,7 +42,7 @@ class MediaRecorderVideoRecorder extends VideoRecorder { if (mResult.getCodec() == VideoCodec.DEFAULT) { mMediaRecorder.setVideoEncoder(mProfile.videoCodec); } else { - mMediaRecorder.setVideoEncoder(new Mapper1().map(mResult.getCodec())); + mMediaRecorder.setVideoEncoder(mMapper.map(mResult.getCodec())); } mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate); if (mResult.getAudio() == Audio.ON) { @@ -61,7 +65,11 @@ class MediaRecorderVideoRecorder extends VideoRecorder { public void onInfo(MediaRecorder mediaRecorder, int what, int extra) { switch (what) { case MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED: + mResult.endReason = VideoResult.REASON_MAX_DURATION_REACHED; + stop(); + break; case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED: + mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED; stop(); break; } @@ -91,5 +99,6 @@ class MediaRecorderVideoRecorder extends VideoRecorder { } mProfile = null; mMediaRecorder = null; + mMapper = null; } } diff --git a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java index 21a1bb2d..e376bc64 100644 --- a/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java +++ b/cameraview/src/main/java/com/otaliastudios/cameraview/VideoResult.java @@ -11,6 +11,10 @@ import java.io.File; */ public class VideoResult { + public static final int REASON_USER = 0; + public static final int REASON_MAX_SIZE_REACHED = 1; + public static final int REASON_MAX_DURATION_REACHED = 2; + boolean isSnapshot; Location location; int rotation; @@ -20,6 +24,7 @@ public class VideoResult { Audio audio; long maxSize; int maxDuration; + int endReason; VideoResult() {} @@ -113,4 +118,12 @@ public class VideoResult { public Audio getAudio() { return audio; } + + /** + * Returns the reason why the recording was stopped. + * @return one of {@link #REASON_USER}, {@link #REASON_MAX_DURATION_REACHED} or {@link #REASON_MAX_SIZE_REACHED}. + */ + public int getTerminationReason() { + return endReason; + } }