use of android.media.MediaRecorder in project android_frameworks_base by crdroidandroid.
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 crdroidandroid.
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 MediaEncoderFilter method startRecording.
private void startRecording(FilterContext context) {
if (mLogVerbose)
Log.v(TAG, "Starting recording");
// Create a frame representing the screen
MutableFrameFormat screenFormat = new MutableFrameFormat(FrameFormat.TYPE_BYTE, FrameFormat.TARGET_GPU);
screenFormat.setBytesPerSample(4);
int width, height;
boolean widthHeightSpecified = mWidth > 0 && mHeight > 0;
// of that in the profile.
if (mProfile != null && !widthHeightSpecified) {
width = mProfile.videoFrameWidth;
height = mProfile.videoFrameHeight;
} else {
width = mWidth;
height = mHeight;
}
screenFormat.setDimensions(width, height);
mScreen = (GLFrame) context.getFrameManager().newBoundFrame(screenFormat, GLFrame.EXISTING_FBO_BINDING, 0);
// Initialize the media recorder
mMediaRecorder = new MediaRecorder();
updateMediaRecorderParams();
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
throw e;
} catch (IOException e) {
throw new RuntimeException("IOException in" + "MediaRecorder.prepare()!", e);
} catch (Exception e) {
throw new RuntimeException("Unknown Exception in" + "MediaRecorder.prepare()!", e);
}
// Make sure start() is called before trying to
// register the surface. The native window handle needed to create
// the surface is initiated in start()
mMediaRecorder.start();
if (mLogVerbose)
Log.v(TAG, "Open: registering surface from Mediarecorder");
mSurfaceId = context.getGLEnvironment().registerSurfaceFromMediaRecorder(mMediaRecorder);
mNumFramesEncoded = 0;
mRecordingActive = true;
}
use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
the class Camera2SwitchPreviewTest method recordingPreviewPreparer.
private void recordingPreviewPreparer(String id) throws Exception {
// Re-use the MediaRecorder object for the same camera device.
mMediaRecorder = new MediaRecorder();
initSupportedVideoSize(id);
// preview Setup:
basicRecordingPreviewTestByCamera(mCamcorderProfileList);
Thread.sleep(getTestWaitIntervalMs());
}
use of android.media.MediaRecorder in project android_frameworks_base by AOSPA.
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;
}
Aggregations