• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cassert>
18 #include <cstring>
19 #include <jni.h>
20 #include <stdint.h>
21 
22 // If the NDK is before O then define this in your build
23 // so that AAudio.h will not be included.
24 // #define OBOE_NO_INCLUDE_AAUDIO
25 
26 // Oboe Includes
27 //#include <oboe/Oboe.h>
28 #include <AAudioExtensions.h>
29 
30 #include "NativeAudioAnalyzer.h"
31 
32 extern "C" {
33 
34 //
35 // com.android.cts.verifier.audio.NativeAnalyzerThread
36 //
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_openAudio(JNIEnv *,jobject,jint inputDeviceId,jint outputDeviceId)37 JNIEXPORT jlong JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_openAudio
38   (JNIEnv * /*env */, jobject /* obj */, jint inputDeviceId, jint outputDeviceId) {
39     // It is OK to use a raw pointer here because the pointer will be passed back
40     // to Java and only used from one thread.
41     // Java then deletes it from that same thread by calling _closeAudio() below.
42     NativeAudioAnalyzer * analyzer = new NativeAudioAnalyzer();
43     aaudio_result_t result = analyzer->openAudio(inputDeviceId, outputDeviceId);
44     if (result != AAUDIO_OK) {
45         delete analyzer;
46         analyzer = nullptr;
47     }
48     return (jlong) analyzer;
49 }
50 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_startAudio(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)51 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_startAudio
52   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
53     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
54     int result = AAUDIO_ERROR_NULL;
55     if (analyzer != nullptr) {
56         result = analyzer->startAudio();
57     }
58     return result;
59 }
60 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_stopAudio(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)61 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_stopAudio
62   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
63     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
64     if (analyzer != nullptr) {
65         return analyzer->stopAudio();
66     }
67     return AAUDIO_ERROR_NULL;
68 }
69 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_closeAudio(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)70 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_closeAudio
71   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
72     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
73     int result = AAUDIO_ERROR_NULL;
74     if (analyzer != nullptr) {
75         result = analyzer->closeAudio();
76         delete analyzer;
77     }
78     return result;
79 }
80 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_isRecordingComplete(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)81 JNIEXPORT jboolean JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_isRecordingComplete
82   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
83     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
84     if (analyzer != nullptr) {
85         return analyzer->isRecordingComplete();
86     }
87     return false;
88 }
89 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_isLowlatency(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)90 JNIEXPORT jboolean JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_isLowlatency
91   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
92     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
93     if (analyzer != nullptr) {
94         return analyzer->isLowLatencyStream();
95     }
96     return false;
97 }
98 
99 JNIEXPORT jboolean JNICALL
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_has24BitHardwareSupport(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)100     Java_com_android_cts_verifier_audio_NativeAnalyzerThread_has24BitHardwareSupport
101         (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
102     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
103     if (analyzer != nullptr) {
104         return analyzer->has24BitHardwareSupport();
105     }
106     return false;
107 }
108 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getError(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)109 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getError
110   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
111     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
112     if (analyzer != nullptr) {
113         return (jint) analyzer->getError();
114     }
115     return (jint) AAUDIO_ERROR_NULL;
116 }
117 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_analyze(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)118 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_analyze
119   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
120     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
121     if (analyzer != nullptr) {
122         return analyzer->analyze();
123     }
124     return AAUDIO_ERROR_NULL;
125 }
126 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getLatencyMillis(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)127 JNIEXPORT jdouble JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getLatencyMillis
128   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
129     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
130     if (analyzer != nullptr) {
131         return analyzer->getLatencyMillis();
132     }
133     return -1.0;
134 }
135 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getConfidence(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)136 JNIEXPORT jdouble JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getConfidence
137   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
138     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
139     if (analyzer != nullptr) {
140         return analyzer->getConfidence();
141     }
142     return 0.0;
143 }
144 
Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getSampleRate(JNIEnv * env __unused,jobject obj __unused,jlong pAnalyzer)145 JNIEXPORT jint JNICALL Java_com_android_cts_verifier_audio_NativeAnalyzerThread_getSampleRate
146   (JNIEnv *env __unused, jobject obj __unused, jlong pAnalyzer) {
147     NativeAudioAnalyzer * analyzer = (NativeAudioAnalyzer *) pAnalyzer;
148     if (analyzer != nullptr) {
149         return analyzer->getSampleRate();
150     }
151     return 0;
152 }
153 
154 //
155 // com.android.cts.verifier.audio.audiolib.AudioUtils
156 //
157 JNIEXPORT jboolean JNICALL
Java_com_android_cts_verifier_audio_audiolib_AudioUtils_isMMapSupported(JNIEnv * env __unused)158     Java_com_android_cts_verifier_audio_audiolib_AudioUtils_isMMapSupported(JNIEnv *env __unused) {
159 
160     return oboe::AAudioExtensions().isMMapSupported();
161 }
162 
163 JNIEXPORT jboolean JNICALL
Java_com_android_cts_verifier_audio_audiolib_AudioUtils_isMMapExclusiveSupported(JNIEnv * env __unused)164     Java_com_android_cts_verifier_audio_audiolib_AudioUtils_isMMapExclusiveSupported(
165         JNIEnv *env __unused) {
166 
167     return oboe::AAudioExtensions().isMMapExclusiveSupported();
168 }
169 
170 }
171