diff options
| author | 2020-09-10 15:53:14 +0000 | |
|---|---|---|
| committer | 2020-09-10 15:53:14 +0000 | |
| commit | 6d9d01bde6f14c21a6ff23e2be32d651994df2e3 (patch) | |
| tree | 80e2ab698d8d6c3542121e1a419b109a99fa0a8d | |
| parent | cf38e32ef4ff1becb6af756f40dd35f2bac817d6 (diff) | |
| parent | 4db6ccaaa3f67d65c340c5d3a4bffa0f5ebcd2b5 (diff) | |
Merge "VIS : SoundTriggerService: fix fake AudioRecord creation" into rvc-qpr-dev am: 4db6ccaaa3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12371311
Change-Id: I98cf883b5b4826c3d11c834d7b24d9efd318be82
| -rw-r--r-- | services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 534fe036ba87..fe0f7b80997e 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -1284,32 +1284,25 @@ public class SoundTriggerService extends SystemService { * @return The initialized AudioRecord */ private @NonNull AudioRecord createAudioRecordForEvent( - @NonNull SoundTrigger.GenericRecognitionEvent event) { + @NonNull SoundTrigger.GenericRecognitionEvent event) + throws IllegalArgumentException, UnsupportedOperationException { AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder(); attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD); AudioAttributes attributes = attributesBuilder.build(); - // Use same AudioFormat processing as in RecognitionEvent.fromParcel AudioFormat originalFormat = event.getCaptureFormat(); - AudioFormat captureFormat = (new AudioFormat.Builder()) - .setChannelMask(originalFormat.getChannelMask()) - .setEncoding(originalFormat.getEncoding()) - .setSampleRate(originalFormat.getSampleRate()) - .build(); - - int bufferSize = AudioRecord.getMinBufferSize( - captureFormat.getSampleRate() == AudioFormat.SAMPLE_RATE_UNSPECIFIED - ? AudioFormat.SAMPLE_RATE_HZ_MAX - : captureFormat.getSampleRate(), - captureFormat.getChannelCount() == 2 - ? AudioFormat.CHANNEL_IN_STEREO - : AudioFormat.CHANNEL_IN_MONO, - captureFormat.getEncoding()); sEventLogger.log(new SoundTriggerLogger.StringEvent("createAudioRecordForEvent")); - return new AudioRecord(attributes, captureFormat, bufferSize, - event.getCaptureSession()); + return (new AudioRecord.Builder()) + .setAudioAttributes(attributes) + .setAudioFormat((new AudioFormat.Builder()) + .setChannelMask(originalFormat.getChannelMask()) + .setEncoding(originalFormat.getEncoding()) + .setSampleRate(originalFormat.getSampleRate()) + .build()) + .setSessionId(event.getCaptureSession()) + .build(); } @Override @@ -1335,12 +1328,16 @@ public class SoundTriggerService extends SystemService { // execute if throttled: () -> { if (event.isCaptureAvailable()) { - AudioRecord capturedData = createAudioRecordForEvent(event); - - // Currently we need to start and release the audio record to reset - // the DSP even if we don't want to process the event - capturedData.startRecording(); - capturedData.release(); + try { + // Currently we need to start and release the audio record to reset + // the DSP even if we don't want to process the eve + AudioRecord capturedData = createAudioRecordForEvent(event); + capturedData.startRecording(); + capturedData.release(); + } catch (IllegalArgumentException | UnsupportedOperationException e) { + Slog.w(TAG, mPuuid + ": createAudioRecordForEvent(" + event + + "), failed to create AudioRecord"); + } } })); } |