Merge "VIS : SoundTriggerService: fix fake AudioRecord creation" into rvc-qpr-dev
This commit is contained in:
@@ -1284,32 +1284,25 @@ public class SoundTriggerService extends SystemService {
|
|||||||
* @return The initialized AudioRecord
|
* @return The initialized AudioRecord
|
||||||
*/
|
*/
|
||||||
private @NonNull AudioRecord createAudioRecordForEvent(
|
private @NonNull AudioRecord createAudioRecordForEvent(
|
||||||
@NonNull SoundTrigger.GenericRecognitionEvent event) {
|
@NonNull SoundTrigger.GenericRecognitionEvent event)
|
||||||
|
throws IllegalArgumentException, UnsupportedOperationException {
|
||||||
AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder();
|
AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder();
|
||||||
attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD);
|
attributesBuilder.setInternalCapturePreset(MediaRecorder.AudioSource.HOTWORD);
|
||||||
AudioAttributes attributes = attributesBuilder.build();
|
AudioAttributes attributes = attributesBuilder.build();
|
||||||
|
|
||||||
// Use same AudioFormat processing as in RecognitionEvent.fromParcel
|
|
||||||
AudioFormat originalFormat = event.getCaptureFormat();
|
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"));
|
sEventLogger.log(new SoundTriggerLogger.StringEvent("createAudioRecordForEvent"));
|
||||||
|
|
||||||
return new AudioRecord(attributes, captureFormat, bufferSize,
|
return (new AudioRecord.Builder())
|
||||||
event.getCaptureSession());
|
.setAudioAttributes(attributes)
|
||||||
|
.setAudioFormat((new AudioFormat.Builder())
|
||||||
|
.setChannelMask(originalFormat.getChannelMask())
|
||||||
|
.setEncoding(originalFormat.getEncoding())
|
||||||
|
.setSampleRate(originalFormat.getSampleRate())
|
||||||
|
.build())
|
||||||
|
.setSessionId(event.getCaptureSession())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1335,12 +1328,16 @@ public class SoundTriggerService extends SystemService {
|
|||||||
// execute if throttled:
|
// execute if throttled:
|
||||||
() -> {
|
() -> {
|
||||||
if (event.isCaptureAvailable()) {
|
if (event.isCaptureAvailable()) {
|
||||||
AudioRecord capturedData = createAudioRecordForEvent(event);
|
try {
|
||||||
|
// Currently we need to start and release the audio record to reset
|
||||||
// Currently we need to start and release the audio record to reset
|
// the DSP even if we don't want to process the eve
|
||||||
// the DSP even if we don't want to process the event
|
AudioRecord capturedData = createAudioRecordForEvent(event);
|
||||||
capturedData.startRecording();
|
capturedData.startRecording();
|
||||||
capturedData.release();
|
capturedData.release();
|
||||||
|
} catch (IllegalArgumentException | UnsupportedOperationException e) {
|
||||||
|
Slog.w(TAG, mPuuid + ": createAudioRecordForEvent(" + event
|
||||||
|
+ "), failed to create AudioRecord");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user