Search in sources :

Example 76 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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;
}
Also used : MediaRecorder(android.media.MediaRecorder) Paint(android.graphics.Paint)

Example 77 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

the class MediaRecorderTest method setUp.

protected void setUp() throws Exception {
    getActivity();
    mRecorder = new MediaRecorder();
    super.setUp();
}
Also used : MediaRecorder(android.media.MediaRecorder)

Example 78 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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;
}
Also used : MediaRecorder(android.media.MediaRecorder) Camera(android.hardware.Camera) Paint(android.graphics.Paint) Surface(android.view.Surface)

Example 79 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

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;
}
Also used : MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException)

Example 80 with MediaRecorder

use of android.media.MediaRecorder in project platform_frameworks_base by android.

the class MediaRecorderStressTest method recordVideoAndPlayback.

// Helper method for record & playback testing with different camcorder profiles
private void recordVideoAndPlayback(int profile) throws Exception {
    int iterations;
    int recordDuration;
    boolean removeVideo;
    int videoEncoder;
    int audioEncoder;
    int frameRate;
    int videoWidth;
    int videoHeight;
    int bitRate;
    if (profile != USE_TEST_RUNNER_PROFILE) {
        assertTrue(String.format("Camera doesn't support profile %d", profile), CamcorderProfile.hasProfile(CAMERA_ID, profile));
        CamcorderProfile camcorderProfile = CamcorderProfile.get(CAMERA_ID, profile);
        videoEncoder = camcorderProfile.videoCodec;
        audioEncoder = camcorderProfile.audioCodec;
        frameRate = camcorderProfile.videoFrameRate;
        videoWidth = camcorderProfile.videoFrameWidth;
        videoHeight = camcorderProfile.videoFrameHeight;
        bitRate = camcorderProfile.videoBitRate;
    } else {
        videoEncoder = MediaRecorderStressTestRunner.mVideoEncoder;
        audioEncoder = MediaRecorderStressTestRunner.mAudioEncoder;
        frameRate = MediaRecorderStressTestRunner.mFrameRate;
        videoWidth = MediaRecorderStressTestRunner.mVideoWidth;
        videoHeight = MediaRecorderStressTestRunner.mVideoHeight;
        bitRate = MediaRecorderStressTestRunner.mBitRate;
    }
    iterations = MediaRecorderStressTestRunner.mIterations;
    recordDuration = MediaRecorderStressTestRunner.mDuration;
    removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
    SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
    mOutput.write("Total number of loops: " + iterations + "\n");
    try {
        mOutput.write("No of loop: ");
        for (int i = 0; i < iterations; i++) {
            String fileName = String.format("%s/temp%d%s", Environment.getExternalStorageDirectory(), i, OUTPUT_FILE_EXT);
            Log.v(TAG, fileName);
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mRecorder = new MediaRecorder();
                }
            });
            Log.v(TAG, "iterations : " + iterations);
            Log.v(TAG, "video encoder : " + videoEncoder);
            Log.v(TAG, "audio encoder : " + audioEncoder);
            Log.v(TAG, "frame rate : " + frameRate);
            Log.v(TAG, "video width : " + videoWidth);
            Log.v(TAG, "video height : " + videoHeight);
            Log.v(TAG, "bit rate : " + bitRate);
            Log.v(TAG, "record duration : " + recordDuration);
            mRecorder.setOnErrorListener(mRecorderErrorCallback);
            mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
            mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mRecorder.setOutputFile(fileName);
            mRecorder.setVideoFrameRate(frameRate);
            mRecorder.setVideoSize(videoWidth, videoHeight);
            mRecorder.setVideoEncoder(videoEncoder);
            mRecorder.setAudioEncoder(audioEncoder);
            mRecorder.setVideoEncodingBitRate(bitRate);
            Log.v(TAG, "mediaRecorder setPreview");
            mRecorder.setPreviewDisplay(surfaceHolder.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(MediaFrameworkTest.mSurfaceView.getHolder());
            mp.prepare();
            mp.start();
            Thread.sleep(recordDuration);
            mp.release();
            validateRecordedVideo(fileName);
            if (removeVideo) {
                removeRecordedVideo(fileName);
            }
            if (i == 0) {
                mOutput.write(i + 1);
            } else {
                mOutput.write(String.format(", %d", (i + 1)));
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Record and playback");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CamcorderProfile(android.media.CamcorderProfile) MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) MediaPlayer(android.media.MediaPlayer)

Aggregations

MediaRecorder (android.media.MediaRecorder)107 IOException (java.io.IOException)58 MediaPlayer (android.media.MediaPlayer)18 Paint (android.graphics.Paint)15 CamcorderProfile (android.media.CamcorderProfile)15 SurfaceHolder (android.view.SurfaceHolder)12 Surface (android.view.Surface)11 File (java.io.File)9 Camera (android.hardware.Camera)8 MutableFrameFormat (android.filterfw.core.MutableFrameFormat)6 Point (android.filterfw.geometry.Point)6 StreamConfigurationMap (android.hardware.camera2.params.StreamConfigurationMap)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 Size (android.util.Size)6 Canvas (android.graphics.Canvas)5 Range (android.util.Range)5 SimpleCaptureCallback (com.android.mediaframeworktest.helpers.CameraTestUtils.SimpleCaptureCallback)5 Activity (android.app.Activity)4 Point (android.graphics.Point)4 Uri (android.net.Uri)3