summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Beth Thibodeau <ethibodeau@google.com> 2021-09-23 22:00:54 -0400
committer Beth Thibodeau <ethibodeau@google.com> 2021-09-23 22:09:35 -0400
commit00d3edc97d33dee860057ef84f53bbdc63aa07d2 (patch)
tree0ed9eaca48d5d79eea18df5e68da4dc4cfadff35
parent72afe9d68249eff3ed2f68b59bf6029c564ba002 (diff)
Use decoder values for screen recording size
Some lower end devices were recording videos at a resolution that could not be played back on device. Using the decoder for the video format, instead of querying all codecs, should result in a size that will be playable on the device as is Fixes: 167978946 Test: manual Change-Id: Ib3ad7863c9399ba81c010943b2f8a39a27be84af
-rw-r--r--packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java106
1 files changed, 46 insertions, 60 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java
index 26781f4ccf09..2133cf63d1c3 100644
--- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java
+++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java
@@ -29,8 +29,8 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
+import android.media.MediaCodec;
import android.media.MediaCodecInfo;
-import android.media.MediaCodecList;
import android.media.MediaFormat;
import android.media.MediaMuxer;
import android.media.MediaRecorder;
@@ -187,77 +187,63 @@ public class ScreenMediaRecorder {
* @param refreshRate Desired refresh rate
* @return array with supported width, height, and refresh rate
*/
- private int[] getSupportedSize(final int screenWidth, final int screenHeight, int refreshRate) {
- double maxScale = 0;
-
- MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
- MediaCodecInfo.VideoCapabilities maxInfo = null;
- for (MediaCodecInfo codec : codecList.getCodecInfos()) {
- String videoType = MediaFormat.MIMETYPE_VIDEO_AVC;
- String[] types = codec.getSupportedTypes();
- for (String t : types) {
- if (!t.equalsIgnoreCase(videoType)) {
- continue;
- }
- MediaCodecInfo.CodecCapabilities capabilities =
- codec.getCapabilitiesForType(videoType);
- if (capabilities != null && capabilities.getVideoCapabilities() != null) {
- MediaCodecInfo.VideoCapabilities vc = capabilities.getVideoCapabilities();
-
- int width = vc.getSupportedWidths().getUpper();
- int height = vc.getSupportedHeights().getUpper();
-
- int screenWidthAligned = screenWidth;
- if (screenWidthAligned % vc.getWidthAlignment() != 0) {
- screenWidthAligned -= (screenWidthAligned % vc.getWidthAlignment());
- }
- int screenHeightAligned = screenHeight;
- if (screenHeightAligned % vc.getHeightAlignment() != 0) {
- screenHeightAligned -= (screenHeightAligned % vc.getHeightAlignment());
- }
-
- if (width >= screenWidthAligned && height >= screenHeightAligned
- && vc.isSizeSupported(screenWidthAligned, screenHeightAligned)) {
- // Desired size is supported, now get the rate
- int maxRate = vc.getSupportedFrameRatesFor(screenWidthAligned,
- screenHeightAligned).getUpper().intValue();
-
- if (maxRate < refreshRate) {
- refreshRate = maxRate;
- }
- Log.d(TAG, "Screen size supported at rate " + refreshRate);
- return new int[]{screenWidthAligned, screenHeightAligned, refreshRate};
- }
-
- // Otherwise, continue searching
- double scale = Math.min(((double) width / screenWidth),
- ((double) height / screenHeight));
- if (scale > maxScale) {
- maxScale = Math.min(1, scale);
- maxInfo = vc;
- }
- }
+ private int[] getSupportedSize(final int screenWidth, final int screenHeight, int refreshRate)
+ throws IOException {
+ String videoType = MediaFormat.MIMETYPE_VIDEO_AVC;
+
+ // Get max size from the decoder, to ensure recordings will be playable on device
+ MediaCodec decoder = MediaCodec.createDecoderByType(videoType);
+ MediaCodecInfo.VideoCapabilities vc = decoder.getCodecInfo()
+ .getCapabilitiesForType(videoType).getVideoCapabilities();
+ decoder.release();
+
+ // Check if we can support screen size as-is
+ int width = vc.getSupportedWidths().getUpper();
+ int height = vc.getSupportedHeights().getUpper();
+
+ int screenWidthAligned = screenWidth;
+ if (screenWidthAligned % vc.getWidthAlignment() != 0) {
+ screenWidthAligned -= (screenWidthAligned % vc.getWidthAlignment());
+ }
+ int screenHeightAligned = screenHeight;
+ if (screenHeightAligned % vc.getHeightAlignment() != 0) {
+ screenHeightAligned -= (screenHeightAligned % vc.getHeightAlignment());
+ }
+
+ if (width >= screenWidthAligned && height >= screenHeightAligned
+ && vc.isSizeSupported(screenWidthAligned, screenHeightAligned)) {
+ // Desired size is supported, now get the rate
+ int maxRate = vc.getSupportedFrameRatesFor(screenWidthAligned,
+ screenHeightAligned).getUpper().intValue();
+
+ if (maxRate < refreshRate) {
+ refreshRate = maxRate;
}
+ Log.d(TAG, "Screen size supported at rate " + refreshRate);
+ return new int[]{screenWidthAligned, screenHeightAligned, refreshRate};
}
- // Resize for max supported size
- int scaledWidth = (int) (screenWidth * maxScale);
- int scaledHeight = (int) (screenHeight * maxScale);
- if (scaledWidth % maxInfo.getWidthAlignment() != 0) {
- scaledWidth -= (scaledWidth % maxInfo.getWidthAlignment());
+ // Otherwise, resize for max supported size
+ double scale = Math.min(((double) width / screenWidth),
+ ((double) height / screenHeight));
+
+ int scaledWidth = (int) (screenWidth * scale);
+ int scaledHeight = (int) (screenHeight * scale);
+ if (scaledWidth % vc.getWidthAlignment() != 0) {
+ scaledWidth -= (scaledWidth % vc.getWidthAlignment());
}
- if (scaledHeight % maxInfo.getHeightAlignment() != 0) {
- scaledHeight -= (scaledHeight % maxInfo.getHeightAlignment());
+ if (scaledHeight % vc.getHeightAlignment() != 0) {
+ scaledHeight -= (scaledHeight % vc.getHeightAlignment());
}
// Find max supported rate for size
- int maxRate = maxInfo.getSupportedFrameRatesFor(scaledWidth, scaledHeight)
+ int maxRate = vc.getSupportedFrameRatesFor(scaledWidth, scaledHeight)
.getUpper().intValue();
if (maxRate < refreshRate) {
refreshRate = maxRate;
}
- Log.d(TAG, "Resized by " + maxScale + ": " + scaledWidth + ", " + scaledHeight
+ Log.d(TAG, "Resized by " + scale + ": " + scaledWidth + ", " + scaledHeight
+ ", " + refreshRate);
return new int[]{scaledWidth, scaledHeight, refreshRate};
}