Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6d9d01bd authored by Eric Laurent's avatar Eric Laurent Committed by Automerger Merge Worker
Browse files

Merge "VIS : SoundTriggerService: fix fake AudioRecord creation" into rvc-qpr-dev am: 4db6ccaa

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12371311

Change-Id: I98cf883b5b4826c3d11c834d7b24d9efd318be82
parents cf38e32e 4db6ccaa
Loading
Loading
Loading
Loading
+21 −24
Original line number Diff line number Diff line
@@ -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())

            sEventLogger.log(new SoundTriggerLogger.StringEvent("createAudioRecordForEvent"));

            return (new AudioRecord.Builder())
                        .setAudioAttributes(attributes)
                        .setAudioFormat((new AudioFormat.Builder())
                            .setChannelMask(originalFormat.getChannelMask())
                            .setEncoding(originalFormat.getEncoding())
                            .setSampleRate(originalFormat.getSampleRate())
                            .build())
                        .setSessionId(event.getCaptureSession())
                        .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());
        }

        @Override
@@ -1335,12 +1328,16 @@ public class SoundTriggerService extends SystemService {
                    // execute if throttled:
                    () -> {
                        if (event.isCaptureAvailable()) {
                            AudioRecord capturedData = createAudioRecordForEvent(event);

                            try {
                                // Currently we need to start and release the audio record to reset
                            // the DSP even if we don't want to process the event
                                // 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");
                            }
                        }
                    }));
        }