use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
the class MediaPlayerPerformance method stressVideoRecord.
// Note: This test is to assume the mediaserver's pid is 34
private boolean stressVideoRecord(int frameRate, int width, int height, int videoFormat, int outFormat, String outFile, boolean videoOnly) {
// Video recording
boolean doesTestFail = false;
for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
MediaRecorder mRecorder = new MediaRecorder();
try {
if (!videoOnly) {
Log.v(TAG, "setAudioSource");
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
}
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setOutputFormat(outFormat);
Log.v(TAG, "output format " + outFormat);
mRecorder.setOutputFile(outFile);
mRecorder.setVideoFrameRate(frameRate);
mRecorder.setVideoSize(width, height);
Log.v(TAG, "setEncoder");
mRecorder.setVideoEncoder(videoFormat);
if (!videoOnly) {
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(MEDIA_STRESS_WAIT_TIME);
mRecorder.stop();
mRecorder.release();
//Insert 2 seconds to make sure the camera released.
Thread.sleep(SHORT_WAIT);
} catch (Exception e) {
Log.v("record video failed ", e.toString());
mRecorder.release();
doesTestFail = true;
break;
}
}
return !doesTestFail;
}
use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
the class MediaPlayerPerformance method stressAudioRecord.
public void stressAudioRecord(String filePath) {
// This test is only for the short media file
for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
MediaRecorder mRecorder = new MediaRecorder();
try {
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(filePath);
mRecorder.prepare();
mRecorder.start();
Thread.sleep(MEDIA_STRESS_WAIT_TIME);
mRecorder.stop();
mRecorder.release();
} catch (Exception e) {
Log.v(TAG, e.toString());
mRecorder.release();
}
}
}
use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
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 AOSPA.
the class CodecTest method mediaRecorderRecord.
public static boolean mediaRecorderRecord(String filePath) {
Log.v(TAG, "SoundRecording - " + filePath);
//This test is only for the short media file
int duration = 0;
try {
MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(filePath);
mRecorder.prepare();
mRecorder.start();
Thread.sleep(500);
mRecorder.stop();
Log.v(TAG, "sound recorded");
mRecorder.release();
} catch (Exception e) {
Log.v(TAG, e.toString());
}
//Verify the recorded file
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
duration = mp.getDuration();
Log.v(TAG, "Duration " + duration);
mp.release();
} catch (Exception e) {
}
//Check the record media file length is greate than zero
if (duration > 0)
return true;
else
return false;
}
use of android.media.MediaRecorder in project CameraView by CJT2325.
the class CameraInterface method startRecord.
void startRecord(Surface surface, ErrorCallback callback) {
if (isRecorder) {
return;
}
int nowAngle = (angle + 90) % 360;
if (mCamera == null) {
openCamera(SELECTED_CAMERA);
}
if (mediaRecorder == null) {
mediaRecorder = new MediaRecorder();
}
if (mParams == null) {
mParams = mCamera.getParameters();
}
List<String> focusModes = mParams.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
mParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
}
mCamera.setParameters(mParams);
mCamera.unlock();
mediaRecorder.reset();
mediaRecorder.setCamera(mCamera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
Camera.Size videoSize = null;
if (mParams.getSupportedVideoSizes() == null) {
videoSize = CameraParamUtil.getInstance().getPictureSize(mParams.getSupportedPreviewSizes(), 1000, screenProp);
} else {
videoSize = CameraParamUtil.getInstance().getPictureSize(mParams.getSupportedVideoSizes(), 1000, screenProp);
}
// Log.i(TAG, "setVideoSize width = " + videoSize.width + "height = " + videoSize.height);
if (videoSize.width == videoSize.height) {
mediaRecorder.setVideoSize(preview_width, preview_height);
} else {
mediaRecorder.setVideoSize(videoSize.width, videoSize.height);
}
if (SELECTED_CAMERA == CAMERA_FRONT_POSITION) {
mediaRecorder.setOrientationHint(270);
} else {
mediaRecorder.setOrientationHint(nowAngle);
// mediaRecorder.setOrientationHint(90);
}
mediaRecorder.setVideoEncodingBitRate(1600000);
mediaRecorder.setPreviewDisplay(surface);
videoFileName = "video_" + System.currentTimeMillis() + ".mp4";
if (saveVideoPath.equals("")) {
saveVideoPath = Environment.getExternalStorageDirectory().getPath();
}
videoFileAbsPath = saveVideoPath + File.separator + videoFileName;
mediaRecorder.setOutputFile(videoFileAbsPath);
try {
mediaRecorder.prepare();
mediaRecorder.start();
isRecorder = true;
} catch (IOException e) {
e.printStackTrace();
callback.onError();
} catch (Exception e) {
e.printStackTrace();
callback.onError();
}
}
Aggregations