OSDN Git Service

AudioRecord: add HW hotword capture flag
authorEric Laurent <elaurent@google.com>
Sat, 20 Sep 2014 00:43:29 +0000 (17:43 -0700)
committerEric Laurent <elaurent@google.com>
Sat, 20 Sep 2014 00:43:29 +0000 (17:43 -0700)
Bug: 17575019.
Change-Id: Ifa8b8342dffa12e1943b8f9105f6ab1fa4a2b1a6

core/jni/android_media_AudioRecord.cpp
media/java/android/media/AudioAttributes.java

index 09c5f3a..e38f3d4 100644 (file)
@@ -45,6 +45,7 @@ struct audio_record_fields_t {
 };
 struct audio_attributes_fields_t {
     jfieldID  fieldRecSource;    // AudioAttributes.mSource
+    jfieldID  fieldFlags;        // AudioAttributes.mFlags
     jfieldID  fieldFormattedTags;// AudioAttributes.mFormattedTags
 };
 static audio_attributes_fields_t javaAudioAttrFields;
@@ -212,9 +213,13 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
     strncpy(paa->tags, tags, AUDIO_ATTRIBUTES_TAGS_MAX_SIZE - 1);
     env->ReleaseStringUTFChars(jtags, tags);
     paa->source = (audio_source_t) env->GetIntField(jaa, javaAudioAttrFields.fieldRecSource);
+    paa->flags = (audio_flags_mask_t)env->GetIntField(jaa, javaAudioAttrFields.fieldFlags);
+    ALOGV("AudioRecord_setup for source=%d tags=%s flags=%08x", paa->source, paa->tags, paa->flags);
 
-    ALOGV("AudioRecord_setup for source=%d tags=%s", paa->source, paa->tags);
-
+    audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE;
+    if (paa->flags & AUDIO_FLAG_HW_HOTWORD) {
+        flags = AUDIO_INPUT_FLAG_HW_HOTWORD;
+    }
     // create the callback information:
     // this data will be passed with every AudioRecord callback
     audiorecord_callback_cookie *lpCallbackData = new audiorecord_callback_cookie;
@@ -232,7 +237,9 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
         lpCallbackData,// void* user
         0,             // notificationFrames,
         true,          // threadCanCallJava
-        sessionId);
+        sessionId,
+        AudioRecord::TRANSFER_DEFAULT,
+        flags);
 
     if (status != NO_ERROR) {
         ALOGE("Error creating AudioRecord instance: initialization check failed with status %d.",
@@ -638,10 +645,12 @@ int register_android_media_AudioRecord(JNIEnv *env)
     }
     jclass audioAttributesClassRef = (jclass)env->NewGlobalRef(audioAttrClass);
     javaAudioAttrFields.fieldRecSource = env->GetFieldID(audioAttributesClassRef, "mSource", "I");
+    javaAudioAttrFields.fieldFlags = env->GetFieldID(audioAttributesClassRef, "mFlags", "I");
     javaAudioAttrFields.fieldFormattedTags =
             env->GetFieldID(audioAttributesClassRef, "mFormattedTags", "Ljava/lang/String;");
     env->DeleteGlobalRef(audioAttributesClassRef);
     if (javaAudioAttrFields.fieldRecSource == NULL
+            || javaAudioAttrFields.fieldFlags == NULL
             || javaAudioAttrFields.fieldFormattedTags == NULL) {
         ALOGE("Can't initialize AudioAttributes fields");
         return -1;
index 56fa546..25dfee6 100644 (file)
@@ -194,8 +194,17 @@ public final class AudioAttributes implements Parcelable {
      */
     public final static int FLAG_HW_AV_SYNC = 0x1 << 4;
 
+    /**
+     * @hide
+     * Flag requesting capture from the source used for hardware hotword detection.
+     * To be used with capture preset MediaRecorder.AudioSource.HOTWORD or
+     * MediaRecorder.AudioSource.VOICE_RECOGNITION.
+     */
+    @SystemApi
+    public final static int FLAG_HW_HOTWORD = 0x1 << 5;
+
     private final static int FLAG_ALL = FLAG_AUDIBILITY_ENFORCED | FLAG_SECURE | FLAG_SCO |
-            FLAG_BEACON | FLAG_HW_AV_SYNC;
+            FLAG_BEACON | FLAG_HW_AV_SYNC | FLAG_HW_HOTWORD;
     private final static int FLAG_ALL_PUBLIC = FLAG_AUDIBILITY_ENFORCED | FLAG_HW_AV_SYNC;
 
     private int mUsage = USAGE_UNKNOWN;