use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderTest method recordVideoWithPara.
private boolean recordVideoWithPara(VideoEncoderCap videoCap, AudioEncoderCap audioCap, boolean highQuality) {
boolean recordSuccess = false;
int videoEncoder = videoCap.mCodec;
int audioEncoder = audioCap.mCodec;
int videoWidth = highQuality ? videoCap.mMaxFrameWidth : videoCap.mMinFrameWidth;
int videoHeight = highQuality ? videoCap.mMaxFrameHeight : videoCap.mMinFrameHeight;
int videoFps = highQuality ? videoCap.mMaxFrameRate : videoCap.mMinFrameRate;
int videoBitrate = highQuality ? videoCap.mMaxBitRate : videoCap.mMinBitRate;
int audioBitrate = highQuality ? audioCap.mMaxBitRate : audioCap.mMinBitRate;
int audioChannels = highQuality ? audioCap.mMaxChannels : audioCap.mMinChannels;
int audioSamplingRate = highQuality ? audioCap.mMaxSampleRate : audioCap.mMinSampleRate;
//Overide the fps if the min_camera_fps is set
if (MediaFrameworkTestRunner.mMinCameraFps != 0 && MediaFrameworkTestRunner.mMinCameraFps > videoFps) {
videoFps = MediaFrameworkTestRunner.mMinCameraFps;
}
if (videoFps < MIN_VIDEO_FPS) {
videoFps = MIN_VIDEO_FPS;
}
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
String filename = ("/sdcard/" + videoEncoder + "_" + audioEncoder + "_" + highQuality + ".3gp");
try {
Log.v(TAG, "video encoder : " + videoEncoder);
Log.v(TAG, "audio encoder : " + audioEncoder);
Log.v(TAG, "quality : " + (highQuality ? "high" : "low"));
Log.v(TAG, "encoder : " + MediaProfileReader.getVideoCodecName(videoEncoder));
Log.v(TAG, "audio : " + MediaProfileReader.getAudioCodecName(audioEncoder));
Log.v(TAG, "videoWidth : " + videoWidth);
Log.v(TAG, "videoHeight : " + videoHeight);
Log.v(TAG, "videoFPS : " + videoFps);
Log.v(TAG, "videobitrate : " + videoBitrate);
Log.v(TAG, "audioBitrate : " + audioBitrate);
Log.v(TAG, "audioChannel : " + audioChannels);
Log.v(TAG, "AudioSampleRate : " + audioSamplingRate);
MediaRecorder mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setOutputFile(filename);
mMediaRecorder.setVideoFrameRate(videoFps);
mMediaRecorder.setVideoSize(videoWidth, videoHeight);
mMediaRecorder.setVideoEncodingBitRate(videoBitrate);
mMediaRecorder.setAudioEncodingBitRate(audioBitrate);
mMediaRecorder.setAudioChannels(audioChannels);
mMediaRecorder.setAudioSamplingRate(audioSamplingRate);
mMediaRecorder.setVideoEncoder(videoEncoder);
mMediaRecorder.setAudioEncoder(audioEncoder);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();
Thread.sleep(MediaNames.RECORDED_TIME);
mMediaRecorder.stop();
mMediaRecorder.release();
recordSuccess = validateVideo(filename, videoWidth, videoHeight);
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return recordSuccess;
}
use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderTest method recordVideoFromSurface.
private boolean recordVideoFromSurface(int frameRate, int captureRate, int width, int height, int videoFormat, int outFormat, String outFile, boolean videoOnly, Surface persistentSurface) {
Log.v(TAG, "recordVideoFromSurface");
MediaRecorder recorder = new MediaRecorder();
// normal capture at 33ms / frame
int sleepTime = 33;
Surface surface = null;
try {
if (!videoOnly) {
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
}
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(outFormat);
recorder.setOutputFile(outFile);
recorder.setVideoFrameRate(frameRate);
if (captureRate > 0) {
recorder.setCaptureRate(captureRate);
sleepTime = 1000 / captureRate;
}
recorder.setVideoSize(width, height);
recorder.setVideoEncoder(videoFormat);
if (!videoOnly) {
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
if (persistentSurface != null) {
Log.v(TAG, "using persistent surface");
surface = persistentSurface;
recorder.setInputSurface(surface);
}
recorder.prepare();
if (persistentSurface == null) {
surface = recorder.getSurface();
}
Paint paint = new Paint();
paint.setTextSize(16);
paint.setColor(Color.RED);
int i;
/* Test: draw 10 frames at 30fps before start
* these should be dropped and not causing malformed stream.
*/
for (i = 0; i < 10; i++) {
Canvas canvas = surface.lockCanvas(null);
int background = (i * 255 / 99);
canvas.drawARGB(255, background, background, background);
String text = "Frame #" + i;
canvas.drawText(text, 100, 100, paint);
surface.unlockCanvasAndPost(canvas);
Thread.sleep(sleepTime);
}
Log.v(TAG, "start");
recorder.start();
/* Test: draw another 90 frames at 30fps after start */
for (i = 10; i < 100; i++) {
Canvas canvas = surface.lockCanvas(null);
int background = (i * 255 / 99);
canvas.drawARGB(255, background, background, background);
String text = "Frame #" + i;
canvas.drawText(text, 100, 100, paint);
surface.unlockCanvasAndPost(canvas);
Thread.sleep(sleepTime);
}
Log.v(TAG, "stop");
recorder.stop();
} catch (Exception e) {
Log.v(TAG, "record video failed: " + e.toString());
return false;
} finally {
recorder.release();
// release surface if not using persistent surface
if (persistentSurface == null && surface != null) {
surface.release();
}
}
return true;
}
use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderTest method validateGetSurface.
private boolean validateGetSurface(boolean useSurface) {
Log.v(TAG, "validateGetSurface, useSurface=" + useSurface);
MediaRecorder recorder = new MediaRecorder();
Surface surface;
boolean success = true;
try {
/* initialization */
if (!useSurface) {
mCamera = Camera.open(CAMERA_ID);
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(352, 288);
parameters.set("orientation", "portrait");
mCamera.setParameters(parameters);
mCamera.unlock();
recorder.setCamera(mCamera);
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
recorder.setPreviewDisplay(mSurfaceHolder.getSurface());
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
int videoSource = useSurface ? MediaRecorder.VideoSource.SURFACE : MediaRecorder.VideoSource.CAMERA;
recorder.setVideoSource(videoSource);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(MediaNames.RECORDED_SURFACE_3GP);
recorder.setVideoFrameRate(30);
recorder.setVideoSize(352, 288);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
/* Test: getSurface() before prepare()
* should throw IllegalStateException
*/
try {
surface = recorder.getSurface();
throw new Exception("getSurface failed to throw IllegalStateException");
} catch (IllegalStateException e) {
// OK
}
recorder.prepare();
/* Test: getSurface() after prepare()
* should succeed for surface source
* should fail for camera source
*/
try {
surface = recorder.getSurface();
if (!useSurface) {
throw new Exception("getSurface failed to throw IllegalStateException");
}
} catch (IllegalStateException e) {
if (useSurface) {
throw new Exception("getSurface failed to throw IllegalStateException");
}
}
recorder.start();
/* Test: getSurface() after start()
* should succeed for surface source
* should fail for camera source
*/
try {
surface = recorder.getSurface();
if (!useSurface) {
throw new Exception("getSurface failed to throw IllegalStateException");
}
} catch (IllegalStateException e) {
if (useSurface) {
throw new Exception("getSurface failed to throw IllegalStateException");
}
}
try {
recorder.stop();
} catch (Exception e) {
// stop() could fail if the recording is empty, as we didn't render anything.
// ignore any failure in stop, we just want it stopped.
}
/* Test: getSurface() after stop()
* should throw IllegalStateException
*/
try {
surface = recorder.getSurface();
throw new Exception("getSurface failed to throw IllegalStateException");
} catch (IllegalStateException e) {
// OK
}
} catch (Exception e) {
// fail
success = false;
}
try {
if (mCamera != null) {
mCamera.lock();
mCamera.release();
mCamera = null;
}
recorder.release();
} catch (Exception e) {
success = false;
}
return success;
}
use of android.media.MediaRecorder in project android_frameworks_base by DirtyUnicorns.
the class MediaRecorderTest method setUp.
protected void setUp() throws Exception {
getActivity();
mRecorder = new MediaRecorder();
super.setUp();
}
use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
the class Camera2RecordingTest method constrainedHighSpeedRecording.
private void constrainedHighSpeedRecording() throws Exception {
for (String id : mCameraIds) {
try {
Log.i(TAG, "Testing constrained high speed recording for camera " + id);
// Re-use the MediaRecorder object for the same camera device.
mMediaRecorder = new MediaRecorder();
openDevice(id);
if (!mStaticInfo.isConstrainedHighSpeedVideoSupported()) {
Log.i(TAG, "Camera " + id + " doesn't support high speed recording, skipping.");
continue;
}
// Test iteration starts...
for (int iteration = 0; iteration < getIterationCount(); ++iteration) {
Log.v(TAG, String.format("Constrained high speed recording: %d/%d", iteration + 1, getIterationCount()));
StreamConfigurationMap config = mStaticInfo.getValueFromKeyNonNull(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] highSpeedVideoSizes = config.getHighSpeedVideoSizes();
for (Size size : highSpeedVideoSizes) {
List<Range<Integer>> fixedFpsRanges = getHighSpeedFixedFpsRangeForSize(config, size);
mCollector.expectTrue("Unable to find the fixed frame rate fps range for " + "size " + size, fixedFpsRanges.size() > 0);
// Test recording for each FPS range
for (Range<Integer> fpsRange : fixedFpsRanges) {
int captureRate = fpsRange.getLower();
final int VIDEO_FRAME_RATE = 30;
// Skip the test if the highest recording FPS supported by CamcorderProfile
if (fpsRange.getUpper() > getFpsFromHighSpeedProfileForSize(size)) {
Log.w(TAG, "high speed recording " + size + "@" + captureRate + "fps" + " is not supported by CamcorderProfile");
continue;
}
mOutMediaFileName = VIDEO_FILE_PATH + "/test_cslowMo_video_" + captureRate + "fps_" + id + "_" + size.toString() + ".mp4";
prepareRecording(size, VIDEO_FRAME_RATE, captureRate);
// prepare preview surface by using video size.
updatePreviewSurfaceWithVideo(size, captureRate);
// Start recording
SimpleCaptureCallback resultListener = new SimpleCaptureCallback();
startSlowMotionRecording(/*useMediaRecorder*/
true, VIDEO_FRAME_RATE, captureRate, fpsRange, resultListener, /*useHighSpeedSession*/
true);
// Record certain duration.
SystemClock.sleep(RECORDING_DURATION_MS);
// Stop recording and preview
stopRecording(/*useMediaRecorder*/
true);
// Convert number of frames camera produced into the duration in unit of ms.
int durationMs = (int) (resultListener.getTotalNumFrames() * 1000.0f / VIDEO_FRAME_RATE);
// Validation.
validateRecording(size, durationMs);
}
getResultPrinter().printStatus(getIterationCount(), iteration + 1, id);
Thread.sleep(getTestWaitIntervalMs());
}
}
} finally {
closeDevice();
releaseRecorder();
}
}
}
Aggregations