Search in sources :

Example 6 with VideoEncoderCap

use of android.media.EncoderCapabilities.VideoEncoderCap in project android_packages_apps_Snap by LineageOS.

the class VideoModule method isSessionSupportedByEncoder.

private boolean isSessionSupportedByEncoder(int w, int h, int fps) {
    int expectedMBsPerSec = w * h * fps;
    List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders();
    for (VideoEncoderCap videoEncoder : videoEncoders) {
        if (videoEncoder.mCodec == mVideoEncoder) {
            int maxMBsPerSec = (videoEncoder.mMaxFrameWidth * videoEncoder.mMaxFrameHeight * videoEncoder.mMaxFrameRate);
            if (expectedMBsPerSec > maxMBsPerSec) {
                Log.e(TAG, "Selected codec " + mVideoEncoder + " does not support width(" + w + ") X height (" + h + "@ " + fps + " fps");
                Log.e(TAG, "Max capabilities: " + "MaxFrameWidth = " + videoEncoder.mMaxFrameWidth + " , " + "MaxFrameHeight = " + videoEncoder.mMaxFrameHeight + " , " + "MaxFrameRate = " + videoEncoder.mMaxFrameRate);
                return false;
            } else {
                return true;
            }
        }
    }
    return false;
}
Also used : VideoEncoderCap(android.media.EncoderCapabilities.VideoEncoderCap)

Example 7 with VideoEncoderCap

use of android.media.EncoderCapabilities.VideoEncoderCap in project platform_frameworks_base by android.

the class MediaRecorderTest method testDeviceSpecificCodec.

@LargeTest
public //test cases for the new codec
void testDeviceSpecificCodec() throws Exception {
    int noOfFailure = 0;
    boolean recordSuccess = false;
    String deviceType = MediaProfileReader.getDeviceType();
    Log.v(TAG, "deviceType = " + deviceType);
    List<VideoEncoderCap> videoEncoders = MediaProfileReader.getVideoEncoders();
    List<AudioEncoderCap> audioEncoders = MediaProfileReader.getAudioEncoders();
    for (int k = 0; k < 2; k++) {
        for (VideoEncoderCap videoEncoder : videoEncoders) {
            for (AudioEncoderCap audioEncoder : audioEncoders) {
                if (k == 0) {
                    recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, true);
                } else {
                    recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, false);
                }
                if (!recordSuccess) {
                    Log.v(TAG, "testDeviceSpecificCodec failed");
                    Log.v(TAG, "Encoder = " + videoEncoder.mCodec + "Audio Encoder = " + audioEncoder.mCodec);
                    noOfFailure++;
                }
            }
        }
    }
    if (noOfFailure != 0) {
        assertTrue("testDeviceSpecificCodec", false);
    }
}
Also used : AudioEncoderCap(android.media.EncoderCapabilities.AudioEncoderCap) Paint(android.graphics.Paint) VideoEncoderCap(android.media.EncoderCapabilities.VideoEncoderCap) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 8 with VideoEncoderCap

use of android.media.EncoderCapabilities.VideoEncoderCap in project android_frameworks_base by DirtyUnicorns.

the class MediaRecorderTest method testDeviceSpecificCodec.

@LargeTest
public //test cases for the new codec
void testDeviceSpecificCodec() throws Exception {
    int noOfFailure = 0;
    boolean recordSuccess = false;
    String deviceType = MediaProfileReader.getDeviceType();
    Log.v(TAG, "deviceType = " + deviceType);
    List<VideoEncoderCap> videoEncoders = MediaProfileReader.getVideoEncoders();
    List<AudioEncoderCap> audioEncoders = MediaProfileReader.getAudioEncoders();
    for (int k = 0; k < 2; k++) {
        for (VideoEncoderCap videoEncoder : videoEncoders) {
            for (AudioEncoderCap audioEncoder : audioEncoders) {
                if (k == 0) {
                    recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, true);
                } else {
                    recordSuccess = recordVideoWithPara(videoEncoder, audioEncoder, false);
                }
                if (!recordSuccess) {
                    Log.v(TAG, "testDeviceSpecificCodec failed");
                    Log.v(TAG, "Encoder = " + videoEncoder.mCodec + "Audio Encoder = " + audioEncoder.mCodec);
                    noOfFailure++;
                }
            }
        }
    }
    if (noOfFailure != 0) {
        assertTrue("testDeviceSpecificCodec", false);
    }
}
Also used : AudioEncoderCap(android.media.EncoderCapabilities.AudioEncoderCap) Paint(android.graphics.Paint) VideoEncoderCap(android.media.EncoderCapabilities.VideoEncoderCap) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 9 with VideoEncoderCap

use of android.media.EncoderCapabilities.VideoEncoderCap in project android_packages_apps_Snap by LineageOS.

the class CameraSettings method getSupportedVideoEncoders.

private static List<String> getSupportedVideoEncoders() {
    ArrayList<String> supported = new ArrayList<String>();
    String str = null;
    List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders();
    for (VideoEncoderCap videoEncoder : videoEncoders) {
        str = VIDEO_ENCODER_TABLE.get(videoEncoder.mCodec);
        if (str != null) {
            supported.add(str);
        }
    }
    return supported;
}
Also used : ArrayList(java.util.ArrayList) VideoEncoderCap(android.media.EncoderCapabilities.VideoEncoderCap)

Example 10 with VideoEncoderCap

use of android.media.EncoderCapabilities.VideoEncoderCap in project android_packages_apps_Snap by LineageOS.

the class Camera2GraphView method setUpMediaRecorder.

private void setUpMediaRecorder(int cameraId) throws IOException {
    Log.d(TAG, "setUpMediaRecorder");
    String videoSize = mSettingsManager.getValue(SettingsManager.KEY_VIDEO_QUALITY);
    int size = CameraSettings.VIDEO_QUALITY_TABLE.get(videoSize);
    Intent intent = mActivity.getIntent();
    if (intent.hasExtra(MediaStore.EXTRA_VIDEO_QUALITY)) {
        int extraVideoQuality = intent.getIntExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
        if (extraVideoQuality > 0) {
            size = CamcorderProfile.QUALITY_HIGH;
        } else {
            // 0 is mms.
            size = CamcorderProfile.QUALITY_LOW;
        }
    }
    if (mCaptureTimeLapse) {
        size = CameraSettings.getTimeLapseQualityFor(size);
    }
    Bundle myExtras = intent.getExtras();
    if (mMediaRecorder == null)
        mMediaRecorder = new MediaRecorder();
    updateHFRSetting();
    boolean hfr = mHighSpeedCapture && !mHighSpeedRecordingMode;
    if (CamcorderProfile.hasProfile(cameraId, size)) {
        mProfile = CamcorderProfile.get(cameraId, size);
    } else {
        if (!"-1".equals(mSettingsManager.getValue(SettingsManager.KEY_SWITCH_CAMERA))) {
            mProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
        } else {
            RotateTextToast.makeText(mActivity, R.string.error_app_unsupported_profile, Toast.LENGTH_LONG).show();
            return;
        }
    }
    int videoWidth = mProfile.videoFrameWidth;
    int videoHeight = mProfile.videoFrameHeight;
    mUnsupportedResolution = false;
    int videoEncoder = SettingTranslation.getVideoEncoder(mSettingsManager.getValue(SettingsManager.KEY_VIDEO_ENCODER));
    int audioEncoder = SettingTranslation.getAudioEncoder(mSettingsManager.getValue(SettingsManager.KEY_AUDIO_ENCODER));
    mProfile.videoCodec = videoEncoder;
    if (!mCaptureTimeLapse && !hfr) {
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mProfile.audioCodec = audioEncoder;
        if (mProfile.audioCodec == MediaRecorder.AudioEncoder.AMR_NB) {
            mProfile.fileFormat = MediaRecorder.OutputFormat.THREE_GPP;
        }
    }
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(mProfile.fileFormat);
    closeVideoFileDescriptor();
    if (mIntentMode == CaptureModule.INTENT_MODE_VIDEO && myExtras != null) {
        Uri saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT);
        if (saveUri != null) {
            try {
                mCurrentVideoUri = saveUri;
                mVideoFileDescriptor = mContentResolver.openFileDescriptor(saveUri, "rw");
                mCurrentVideoUri = saveUri;
            } catch (java.io.FileNotFoundException ex) {
                // invalid uri
                Log.e(TAG, ex.toString());
            }
        }
        mMediaRecorder.setOutputFile(mVideoFileDescriptor.getFileDescriptor());
    } else {
        String fileName = generateVideoFilename(mProfile.fileFormat);
        Log.v(TAG, "New video filename: " + fileName);
        mMediaRecorder.setOutputFile(fileName);
    }
    mMediaRecorder.setVideoFrameRate(mProfile.videoFrameRate);
    mMediaRecorder.setVideoEncodingBitRate(mProfile.videoBitRate);
    if (mFrameProcessor.isFrameFilterEnabled()) {
        mMediaRecorder.setVideoSize(mProfile.videoFrameHeight, mProfile.videoFrameWidth);
    } else {
        mMediaRecorder.setVideoSize(mProfile.videoFrameWidth, mProfile.videoFrameHeight);
    }
    mMediaRecorder.setVideoEncoder(videoEncoder);
    if (!mCaptureTimeLapse && !hfr) {
        mMediaRecorder.setAudioEncodingBitRate(mProfile.audioBitRate);
        mMediaRecorder.setAudioChannels(mProfile.audioChannels);
        mMediaRecorder.setAudioSamplingRate(mProfile.audioSampleRate);
        mMediaRecorder.setAudioEncoder(audioEncoder);
    }
    mMediaRecorder.setMaxDuration(mMaxVideoDurationInMs);
    Log.i(TAG, "Profile video bitrate: " + mProfile.videoBitRate);
    Log.i(TAG, "Profile video frame rate: " + mProfile.videoFrameRate);
    if (mCaptureTimeLapse) {
        double fps = 1000 / (double) mTimeBetweenTimeLapseFrameCaptureMs;
        mMediaRecorder.setCaptureRate(fps);
    } else if (mHighSpeedCapture) {
        mHighSpeedFPSRange = new Range(mHighSpeedCaptureRate, mHighSpeedCaptureRate);
        int fps = (int) mHighSpeedFPSRange.getUpper();
        mMediaRecorder.setCaptureRate(fps);
        int targetRate = mHighSpeedRecordingMode ? fps : 30;
        mMediaRecorder.setVideoFrameRate(targetRate);
        Log.i(TAG, "Capture rate: " + fps + ", Target rate: " + targetRate);
        int scaledBitrate = mSettingsManager.getHighSpeedVideoEncoderBitRate(mProfile, targetRate);
        Log.i(TAG, "Scaled video bitrate : " + scaledBitrate);
        mMediaRecorder.setVideoEncodingBitRate(scaledBitrate);
    }
    long requestedSizeLimit = 0;
    if (isVideoCaptureIntent() && myExtras != null) {
        requestedSizeLimit = myExtras.getLong(MediaStore.EXTRA_SIZE_LIMIT);
    }
    // check if codec supports the resolution, otherwise throw toast
    List<VideoEncoderCap> videoEncoders = EncoderCapabilities.getVideoEncoders();
    for (VideoEncoderCap videoEnc : videoEncoders) {
        if (videoEnc.mCodec == videoEncoder) {
            if (videoWidth > videoEnc.mMaxFrameWidth || videoWidth < videoEnc.mMinFrameWidth || videoHeight > videoEnc.mMaxFrameHeight || videoHeight < videoEnc.mMinFrameHeight) {
                Log.e(TAG, "Selected codec " + videoEncoder + " does not support " + videoWidth + "x" + videoHeight + " resolution");
                Log.e(TAG, "Codec capabilities: " + "mMinFrameWidth = " + videoEnc.mMinFrameWidth + " , " + "mMinFrameHeight = " + videoEnc.mMinFrameHeight + " , " + "mMaxFrameWidth = " + videoEnc.mMaxFrameWidth + " , " + "mMaxFrameHeight = " + videoEnc.mMaxFrameHeight);
                mUnsupportedResolution = true;
                RotateTextToast.makeText(mActivity, R.string.error_app_unsupported, Toast.LENGTH_LONG).show();
                return;
            }
            break;
        }
    }
    // Set maximum file size.
    long maxFileSize = mActivity.getStorageSpaceBytes() - Storage.LOW_STORAGE_THRESHOLD_BYTES;
    if (requestedSizeLimit > 0 && requestedSizeLimit < maxFileSize) {
        maxFileSize = requestedSizeLimit;
    }
    if (Storage.isSaveSDCard() && maxFileSize > SDCARD_SIZE_LIMIT) {
        maxFileSize = SDCARD_SIZE_LIMIT;
    }
    Log.i(TAG, "MediaRecorder setMaxFileSize: " + maxFileSize);
    try {
        mMediaRecorder.setMaxFileSize(maxFileSize);
    } catch (RuntimeException exception) {
    // We are going to ignore failure of setMaxFileSize here, as
    // a) The composer selected may simply not support it, or
    // b) The underlying media framework may not handle 64-bit range
    // on the size restriction.
    }
    Location loc = mLocationManager.getCurrentLocation();
    if (loc != null) {
        mMediaRecorder.setLocation((float) loc.getLatitude(), (float) loc.getLongitude());
    }
    int rotation = CameraUtil.getJpegRotation(cameraId, mOrientation);
    String videoRotation = mSettingsManager.getValue(SettingsManager.KEY_VIDEO_ROTATION);
    if (videoRotation != null) {
        rotation += Integer.parseInt(videoRotation);
        rotation = rotation % 360;
    }
    if (mFrameProcessor.isFrameFilterEnabled()) {
        mMediaRecorder.setOrientationHint(0);
    } else {
        mMediaRecorder.setOrientationHint(rotation);
    }
    try {
        mMediaRecorder.prepare();
    } catch (IOException e) {
        Log.e(TAG, "prepare failed for " + mVideoFilename, e);
        releaseMediaRecorder();
        throw new RuntimeException(e);
    }
    mMediaRecorder.setOnErrorListener(this);
    mMediaRecorder.setOnInfoListener(this);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) IOException(java.io.IOException) Range(android.util.Range) Uri(android.net.Uri) Paint(android.graphics.Paint) Point(android.graphics.Point) FileNotFoundException(java.io.FileNotFoundException) VideoEncoderCap(android.media.EncoderCapabilities.VideoEncoderCap) MediaRecorder(android.media.MediaRecorder) Location(android.location.Location)

Aggregations

VideoEncoderCap (android.media.EncoderCapabilities.VideoEncoderCap)11 Paint (android.graphics.Paint)6 AudioEncoderCap (android.media.EncoderCapabilities.AudioEncoderCap)6 LargeTest (android.test.suitebuilder.annotation.LargeTest)6 Intent (android.content.Intent)2 MediaRecorder (android.media.MediaRecorder)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Point (android.graphics.Point)1 CameraInfo (android.hardware.Camera.CameraInfo)1 Location (android.location.Location)1 Range (android.util.Range)1 FileNotFoundException (java.io.FileNotFoundException)1