From 246a25ef4c32c8835d8cb8e62f69f037248dd642 Mon Sep 17 00:00:00 2001 From: Jay Aliomer Date: Tue, 26 May 2020 22:57:34 -0400 Subject: [PATCH] Screen recorder video and ui polish Fixes: 154532785 Fixes: 156742385 Test: manual Change-Id: Idc3b7ad496abb587247bd77d9763fe8ce5e7178b --- .../screen_record_dialog_audio_source.xml | 9 ++++----- .../screenrecord/RecordingService.java | 4 ++-- .../ScreenInternalAudioRecorder.java | 18 ++++++++++++++++++ .../screenrecord/ScreenMediaRecorder.java | 13 ++++++++----- .../screenrecord/ScreenRecordDialog.java | 5 +---- .../screenrecord/ScreenRecordingAdapter.java | 6 ------ 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/res/layout/screen_record_dialog_audio_source.xml b/packages/SystemUI/res/layout/screen_record_dialog_audio_source.xml index af6f9bb827f66..0c4d5a26f95b2 100644 --- a/packages/SystemUI/res/layout/screen_record_dialog_audio_source.xml +++ b/packages/SystemUI/res/layout/screen_record_dialog_audio_source.xml @@ -16,21 +16,20 @@ --> + android:padding="13dp"> diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java index 960c50129a561..3e268f63d65ee 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/RecordingService.java @@ -225,8 +225,8 @@ public class RecordingService extends Service implements MediaRecorder.OnInfoLis res.getString(R.string.screenrecord_name)); String notificationTitle = mAudioSource == ScreenRecordingAudioSource.NONE - ? res.getString(R.string.screenrecord_ongoing_screen_and_audio) - : res.getString(R.string.screenrecord_ongoing_screen_only); + ? res.getString(R.string.screenrecord_ongoing_screen_only) + : res.getString(R.string.screenrecord_ongoing_screen_and_audio); mRecordingNotificationBuilder = new Notification.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_screenrecord) diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java index 752f4fddf24bd..edbc3cfdece5d 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenInternalAudioRecorder.java @@ -38,6 +38,7 @@ import java.nio.ByteBuffer; public class ScreenInternalAudioRecorder { private static String TAG = "ScreenAudioRecorder"; private static final int TIMEOUT = 500; + private static final float MIC_VOLUME_SCALE = 1.4f; private final Context mContext; private AudioRecord mAudioRecord; private AudioRecord mAudioRecordMic; @@ -148,6 +149,10 @@ public class ScreenInternalAudioRecorder { readShortsInternal = mAudioRecord.read(bufferInternal, 0, bufferInternal.length); readShortsMic = mAudioRecordMic.read(bufferMic, 0, bufferMic.length); + + // modify the volume + bufferMic = scaleValues(bufferMic, + readShortsMic, MIC_VOLUME_SCALE); readBytes = Math.min(readShortsInternal, readShortsMic) * 2; buffer = addAndConvertBuffers(bufferInternal, readShortsInternal, bufferMic, readShortsMic); @@ -168,6 +173,19 @@ public class ScreenInternalAudioRecorder { }); } + private short[] scaleValues(short[] buff, int len, float scale) { + for (int i = 0; i < len; i++) { + int oldValue = buff[i]; + int newValue = (int) (buff[i] * scale); + if (newValue > Short.MAX_VALUE) { + newValue = Short.MAX_VALUE; + } else if (newValue < Short.MIN_VALUE) { + newValue = Short.MIN_VALUE; + } + buff[i] = (short) (newValue); + } + return buff; + } private byte[] addAndConvertBuffers(short[] a1, int a1Limit, short[] a2, int a2Limit) { int size = Math.max(a1Limit, a2Limit); if (size < 0) return new byte[0]; diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java index c967648c544eb..8551c88d133a3 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenMediaRecorder.java @@ -55,9 +55,9 @@ import java.util.Date; */ public class ScreenMediaRecorder { private static final int TOTAL_NUM_TRACKS = 1; - private static final int VIDEO_BIT_RATE = 10000000; private static final int VIDEO_FRAME_RATE = 30; - private static final int AUDIO_BIT_RATE = 16; + private static final int VIDEO_FRAME_RATE_TO_RESOLUTION_RATIO = 6; + private static final int AUDIO_BIT_RATE = 196000; private static final int AUDIO_SAMPLE_RATE = 44100; private static final int MAX_DURATION_MS = 60 * 60 * 1000; private static final long MAX_FILESIZE_BYTES = 5000000000L; @@ -108,7 +108,7 @@ public class ScreenMediaRecorder { // Set up audio source if (mAudioSource == MIC) { - mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); + mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); } mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); @@ -121,10 +121,13 @@ public class ScreenMediaRecorder { wm.getDefaultDisplay().getRealMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; + int refereshRate = (int) wm.getDefaultDisplay().getRefreshRate(); + int vidBitRate = screenHeight * screenWidth * refereshRate / VIDEO_FRAME_RATE + * VIDEO_FRAME_RATE_TO_RESOLUTION_RATIO; mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setVideoSize(screenWidth, screenHeight); - mMediaRecorder.setVideoFrameRate(VIDEO_FRAME_RATE); - mMediaRecorder.setVideoEncodingBitRate(VIDEO_BIT_RATE); + mMediaRecorder.setVideoFrameRate(refereshRate); + mMediaRecorder.setVideoEncodingBitRate(vidBitRate); mMediaRecorder.setMaxDuration(MAX_DURATION_MS); mMediaRecorder.setMaxFileSize(MAX_FILESIZE_BYTES); diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordDialog.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordDialog.java index abd7e7159260d..d057a8a43c43c 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordDialog.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordDialog.java @@ -24,12 +24,9 @@ import static com.android.systemui.screenrecord.ScreenRecordingAudioSource.NONE; import android.app.Activity; import android.app.PendingIntent; import android.os.Bundle; -import android.util.Log; import android.view.Gravity; -import android.view.View; import android.view.ViewGroup; import android.view.Window; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.Spinner; @@ -88,8 +85,8 @@ public class ScreenRecordDialog extends Activity { }); mModes = new ArrayList<>(); - mModes.add(INTERNAL); mModes.add(MIC); + mModes.add(INTERNAL); mModes.add(MIC_AND_INTERNAL); mAudioSwitch = findViewById(R.id.screenrecord_audio_switch); diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingAdapter.java b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingAdapter.java index 2e0e746594b4d..3e78489e57072 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordingAdapter.java @@ -88,12 +88,6 @@ public class ScreenRecordingAdapter extends ArrayAdapter