use of android.media.CamcorderProfile in project android_frameworks_base by crdroidandroid.
the class Camera2SwitchPreviewTest method basicRecordingPreviewTestByCamera.
/**
* Test camera recording preview by using each available CamcorderProfile for a
* given camera. preview size is set to the video size.
*/
private void basicRecordingPreviewTestByCamera(int[] camcorderProfileList) throws Exception {
Size maxPreviewSize = mOrderedPreviewSizes.get(0);
List<Range<Integer>> fpsRanges = Arrays.asList(mStaticInfo.getAeAvailableTargetFpsRangesChecked());
int cameraId = Integer.parseInt(mCamera.getId());
int maxVideoFrameRate = -1;
int profileId = camcorderProfileList[0];
if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
return;
}
CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
Range<Integer> fpsRange = new Range(profile.videoFrameRate, profile.videoFrameRate);
if (maxVideoFrameRate < profile.videoFrameRate) {
maxVideoFrameRate = profile.videoFrameRate;
}
if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
// Skip. Legacy mode can only do recording up to max preview size
return;
}
assertTrue("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!", mSupportedVideoSizes.contains(videoSz));
assertTrue("Frame rate range " + fpsRange + " (for profile ID " + profileId + ") must be one of the camera device available FPS range!", fpsRanges.contains(fpsRange));
if (VERBOSE) {
Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
}
// Configure preview and recording surfaces.
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
if (DEBUG_DUMP) {
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
}
prepareRecordingWithProfile(profile);
// prepare preview surface by using video size.
updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
CaptureRequest.Builder previewRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
CaptureRequest.Builder recordingRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
prepareVideoPreview(previewRequest, recordingRequest, resultListener, imageListener);
// Can reuse the MediaRecorder object after reset.
mMediaRecorder.reset();
if (maxVideoFrameRate != -1) {
// At least one CamcorderProfile is present, check FPS
assertTrue("At least one CamcorderProfile must support >= 24 FPS", maxVideoFrameRate >= 24);
}
}
use of android.media.CamcorderProfile in project android_frameworks_base by crdroidandroid.
the class MediaRecorderStressTest method testStressTimeLapse.
// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
SurfaceHolder mSurfaceHolder;
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
Log.v(TAG, "Start camera time lapse stress:");
mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
try {
for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
mOutput.write("No of loop: camera " + i);
for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
// Set callback
mRecorder.setOnErrorListener(mRecorderErrorCallback);
// Set video source
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set camcorder profile for time lapse
CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
mRecorder.setProfile(profile);
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
mRecorder.setCaptureRate(captureRate);
// Set output file
mRecorder.setOutputFile(fileName);
// Set the preview display
Log.v(TAG, "mediaRecorder setPreviewDisplay");
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
// Start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(mSurfaceHolder);
mp.prepare();
mp.start();
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (j == 0) {
mOutput.write(j + 1);
} else {
mOutput.write(String.format(", %d", (j + 1)));
}
}
}
} catch (IllegalStateException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IllegalStateException");
} catch (IOException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IOException");
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test Exception");
}
}
use of android.media.CamcorderProfile in project android_packages_apps_Camera by CyanogenMod.
the class CameraSettings method getSupportedVideoQuality.
private ArrayList<String> getSupportedVideoQuality() {
ArrayList<String> supported = new ArrayList<String>();
// Check for supported quality
if (ApiHelper.HAS_FINE_RESOLUTION_QUALITY_LEVELS) {
getFineResolutionQuality(supported);
} else {
supported.add(Integer.toString(CamcorderProfile.QUALITY_HIGH));
CamcorderProfile high = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
CamcorderProfile low = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
if (high.videoFrameHeight * high.videoFrameWidth > low.videoFrameHeight * low.videoFrameWidth) {
supported.add(Integer.toString(CamcorderProfile.QUALITY_LOW));
}
}
return supported;
}
use of android.media.CamcorderProfile in project android_frameworks_base by AOSPA.
the class Camera2SwitchPreviewTest method basicRecordingPreviewTestByCamera.
/**
* Test camera recording preview by using each available CamcorderProfile for a
* given camera. preview size is set to the video size.
*/
private void basicRecordingPreviewTestByCamera(int[] camcorderProfileList) throws Exception {
Size maxPreviewSize = mOrderedPreviewSizes.get(0);
List<Range<Integer>> fpsRanges = Arrays.asList(mStaticInfo.getAeAvailableTargetFpsRangesChecked());
int cameraId = Integer.parseInt(mCamera.getId());
int maxVideoFrameRate = -1;
int profileId = camcorderProfileList[0];
if (!CamcorderProfile.hasProfile(cameraId, profileId) || allowedUnsupported(cameraId, profileId)) {
return;
}
CamcorderProfile profile = CamcorderProfile.get(cameraId, profileId);
Size videoSz = new Size(profile.videoFrameWidth, profile.videoFrameHeight);
Range<Integer> fpsRange = new Range(profile.videoFrameRate, profile.videoFrameRate);
if (maxVideoFrameRate < profile.videoFrameRate) {
maxVideoFrameRate = profile.videoFrameRate;
}
if (mStaticInfo.isHardwareLevelLegacy() && (videoSz.getWidth() > maxPreviewSize.getWidth() || videoSz.getHeight() > maxPreviewSize.getHeight())) {
// Skip. Legacy mode can only do recording up to max preview size
return;
}
assertTrue("Video size " + videoSz.toString() + " for profile ID " + profileId + " must be one of the camera device supported video size!", mSupportedVideoSizes.contains(videoSz));
assertTrue("Frame rate range " + fpsRange + " (for profile ID " + profileId + ") must be one of the camera device available FPS range!", fpsRanges.contains(fpsRange));
if (VERBOSE) {
Log.v(TAG, "Testing camera recording with video size " + videoSz.toString());
}
// Configure preview and recording surfaces.
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video.mp4";
if (DEBUG_DUMP) {
mOutMediaFileName = VIDEO_FILE_PATH + "/test_video_" + cameraId + "_" + videoSz.toString() + ".mp4";
}
prepareRecordingWithProfile(profile);
// prepare preview surface by using video size.
updatePreviewSurfaceWithVideo(videoSz, profile.videoFrameRate);
CaptureRequest.Builder previewRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
CaptureRequest.Builder recordingRequest = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
SimpleImageReaderListener imageListener = new SimpleImageReaderListener();
prepareVideoPreview(previewRequest, recordingRequest, resultListener, imageListener);
// Can reuse the MediaRecorder object after reset.
mMediaRecorder.reset();
if (maxVideoFrameRate != -1) {
// At least one CamcorderProfile is present, check FPS
assertTrue("At least one CamcorderProfile must support >= 24 FPS", maxVideoFrameRate >= 24);
}
}
use of android.media.CamcorderProfile in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderStressTest method testStressTimeLapse.
// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
SurfaceHolder mSurfaceHolder;
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
Log.v(TAG, "Start camera time lapse stress:");
mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
try {
for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
mOutput.write("No of loop: camera " + i);
for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, OUTPUT_FILE_EXT);
Log.v(TAG, fileName);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
// Set callback
mRecorder.setOnErrorListener(mRecorderErrorCallback);
// Set video source
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set camcorder profile for time lapse
CamcorderProfile profile = CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
mRecorder.setProfile(profile);
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
mRecorder.setCaptureRate(captureRate);
// Set output file
mRecorder.setOutputFile(fileName);
// Set the preview display
Log.v(TAG, "mediaRecorder setPreviewDisplay");
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(recordDuration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
// Start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(fileName);
mp.setDisplay(mSurfaceHolder);
mp.prepare();
mp.start();
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
mp.release();
validateRecordedVideo(fileName);
if (removeVideo) {
removeRecordedVideo(fileName);
}
if (j == 0) {
mOutput.write(j + 1);
} else {
mOutput.write(String.format(", %d", (j + 1)));
}
}
}
} catch (IllegalStateException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IllegalStateException");
} catch (IOException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IOException");
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test Exception");
}
}
Aggregations