CTS: Change to allow device-recommended VideoCodec setting
- Allow testConstrainedHighSpeedRecording to use video codec
setting from profile to prepare recording
Test: RecordingTest#testConstrainedHighSpeedRecording[1]
Bug: 209932476
Change-Id: I7d39c9ade2e69ba8424d4e6fe2a8b816c9cea2cb
diff --git a/tests/camera/src/android/hardware/camera2/cts/RecordingTest.java b/tests/camera/src/android/hardware/camera2/cts/RecordingTest.java
index ca5bb4f..7669b13 100644
--- a/tests/camera/src/android/hardware/camera2/cts/RecordingTest.java
+++ b/tests/camera/src/android/hardware/camera2/cts/RecordingTest.java
@@ -906,7 +906,26 @@
mOutMediaFileName = mDebugFileNameBase + "/test_cslowMo_video_" +
captureRate + "fps_" + id + "_" + size.toString() + ".mp4";
- prepareRecording(size, VIDEO_FRAME_RATE, captureRate);
+ int cameraId = Integer.valueOf(mCamera.getId());
+ int videoEncoder = MediaRecorder.VideoEncoder.H264;
+ for (int profileId : mCamcorderProfileList) {
+ if (CamcorderProfile.hasProfile(cameraId, profileId)) {
+ CamcorderProfile profile =
+ CamcorderProfile.get(cameraId, profileId);
+
+ if (profile.videoFrameHeight == size.getHeight() &&
+ profile.videoFrameWidth == size.getWidth() &&
+ profile.videoFrameRate == VIDEO_FRAME_RATE) {
+ videoEncoder = profile.videoCodec;
+ // Since mCamcorderProfileList is a list representing different
+ // resolutions, we can break when a profile with the same
+ // dimensions as size is found
+ break;
+ }
+ }
+ }
+
+ prepareRecording(size, VIDEO_FRAME_RATE, captureRate, videoEncoder);
SystemClock.sleep(PREVIEW_DURATION_MS);
@@ -938,7 +957,8 @@
stopCameraStreaming();
}
}
-
+ } catch (NumberFormatException e) {
+ fail("Cannot convert cameraId " + mCamera.getId() + " to int");
} finally {
closeDevice();
releaseRecorder();
@@ -1739,6 +1759,17 @@
private void prepareRecording(Size sz, int videoFrameRate, int captureRate)
throws Exception {
// Prepare MediaRecorder.
+ prepareRecording(sz, videoFrameRate, captureRate, MediaRecorder.VideoEncoder.H264);
+ }
+
+ /**
+ * Configure MediaRecorder recording session with CamcorderProfile, prepare
+ * the recording surface. Use AAC for audio compression as required for
+ * android devices by android CDD.
+ */
+ private void prepareRecording(Size sz, int videoFrameRate, int captureRate,
+ int videoEncoder) throws Exception {
+ // Prepare MediaRecorder.
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
@@ -1747,7 +1778,7 @@
mMediaRecorder.setVideoFrameRate(videoFrameRate);
mMediaRecorder.setCaptureRate(captureRate);
mMediaRecorder.setVideoSize(sz.getWidth(), sz.getHeight());
- mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
+ mMediaRecorder.setVideoEncoder(videoEncoder);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
if (mPersistentSurface != null) {
mMediaRecorder.setInputSurface(mPersistentSurface);