Merge "Correctly initialize recognition events" into tm-dev

This commit is contained in:
Ytai Ben-tsvi
2022-03-15 16:43:10 +00:00
committed by Android (Google) Code Review

View File

@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.media.permission.SafeCloseable;
import android.media.soundtrigger.ModelParameterRange;
import android.media.soundtrigger.PhraseRecognitionEvent;
import android.media.soundtrigger.PhraseRecognitionExtra;
import android.media.soundtrigger.PhraseSoundModel;
import android.media.soundtrigger.Properties;
import android.media.soundtrigger.RecognitionConfig;
@@ -392,7 +393,7 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
private static void notifyAbort(int modelHandle, LoadedModel model) {
switch (model.type) {
case SoundModelType.GENERIC: {
RecognitionEvent event = new RecognitionEvent();
RecognitionEvent event = newEmptyRecognitionEvent();
event.status = RecognitionStatus.ABORTED;
event.type = SoundModelType.GENERIC;
model.callback.recognitionCallback(modelHandle, event);
@@ -400,7 +401,7 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
break;
case SoundModelType.KEYPHRASE: {
PhraseRecognitionEvent event = new PhraseRecognitionEvent();
PhraseRecognitionEvent event = newEmptyPhraseRecognitionEvent();
event.common.status = RecognitionStatus.ABORTED;
event.common.type = SoundModelType.KEYPHRASE;
model.callback.phraseRecognitionCallback(modelHandle, event);
@@ -415,6 +416,19 @@ public class SoundTriggerHalConcurrentCaptureHandler implements ISoundTriggerHal
mNotifier.unregisterListener(this);
}
private static PhraseRecognitionEvent newEmptyPhraseRecognitionEvent() {
PhraseRecognitionEvent result = new PhraseRecognitionEvent();
result.common = newEmptyRecognitionEvent();
result.phraseExtras = new PhraseRecognitionExtra[0];
return result;
}
private static RecognitionEvent newEmptyRecognitionEvent() {
RecognitionEvent result = new RecognitionEvent();
result.data = new byte[0];
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// All methods below do trivial delegation - no interesting logic.
@Override