1 /*
2 * Copyright (C) 2016 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 #include <android/log.h>
17
18 #include "AudioRecorder.h"
19
20 using namespace ndkaudio;
21
22 static const char* TAG = "AudioRecorder_jni";
23
24 static int numChannels = 2;
25
26 static AudioRecorder* nativeRecorder;
27
28 static SLresult lastSLResult = 0;
29 extern "C" {
30
Java_android_media_audio_cts_AudioRecorder_Create(JNIEnv *,jobject)31 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_Create(JNIEnv*, jobject) {
32 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioRecorder_Create() ...");
33 if (nativeRecorder == 0) {
34 nativeRecorder = new AudioRecorder();
35 }
36 nativeRecorder->Open(numChannels, 0);
37 }
38
Java_android_media_audio_cts_AudioRecorder_Destroy(JNIEnv *,jobject)39 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_Destroy(JNIEnv*, jobject) {
40 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioRecorder_Destroy() ...");
41 nativeRecorder->Close();
42 delete nativeRecorder;
43 nativeRecorder = 0;
44 }
45
Java_android_media_audio_cts_AudioRecorder_RealizeRecorder(JNIEnv *,jobject)46 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_RealizeRecorder(JNIEnv*, jobject) {
47 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioRecorder_RealizePlayer() ...");
48 nativeRecorder->RealizeRecorder();
49 }
50
Java_android_media_audio_cts_AudioRecorder_RealizeRoutingProxy(JNIEnv *,jobject)51 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_RealizeRoutingProxy(JNIEnv*, jobject) {
52 __android_log_print(ANDROID_LOG_INFO, TAG, "RealizeRoutingProxy ...");
53 nativeRecorder->RealizeRoutingProxy();
54 }
55
Java_android_media_audio_cts_AudioRecorder_Start(JNIEnv *,jobject)56 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_Start(JNIEnv *, jobject) {
57 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioRecorder_Start() ...");
58 nativeRecorder->Start();
59 }
60
Java_android_media_audio_cts_AudioRecorder_Stop(JNIEnv *,jobject)61 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_Stop(JNIEnv *, jobject) {
62 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioRecorder_Stop() ...");
63 nativeRecorder->Stop();
64 }
65
Java_android_media_audio_cts_AudioRecorder_GetRoutingInterface(JNIEnv *,jobject)66 JNIEXPORT jobject JNICALL Java_android_media_audio_cts_AudioRecorder_GetRoutingInterface(JNIEnv*, jobject) {
67 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioPlayer_GetRoutingObj() ...");
68
69 SLAndroidConfigurationItf configItf = nativeRecorder->getConfigItf();
70 jobject routingObj = 0;
71 lastSLResult = (*configItf)->AcquireJavaProxy(configItf, SL_ANDROID_JAVA_PROXY_ROUTING, &routingObj);
72 __android_log_print(ANDROID_LOG_INFO, TAG, " routingObj:%p", routingObj);
73 return routingObj;
74 }
75
Java_android_media_audio_cts_AudioRecorder_ReleaseRoutingInterface(JNIEnv *,jobject,jobject)76 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_ReleaseRoutingInterface(JNIEnv*, jobject, jobject /*proxyObj*/) {
77 __android_log_print(ANDROID_LOG_INFO, TAG, "AudioPlayer_ReleaseRoutingInterface() ...");
78
79 SLAndroidConfigurationItf configItf = nativeRecorder->getConfigItf();
80 lastSLResult = (*configItf)->ReleaseJavaProxy(configItf, SL_ANDROID_JAVA_PROXY_ROUTING/*, proxyObj*/);
81 }
82
Java_android_media_audio_cts_AudioRecorder_GetNumBufferSamples(JNIEnv *,jobject)83 JNIEXPORT jint JNICALL Java_android_media_audio_cts_AudioRecorder_GetNumBufferSamples(JNIEnv*, jobject) {
84 return nativeRecorder->GetNumBufferSamples();
85 }
86
Java_android_media_audio_cts_AudioRecorder_GetBufferData(JNIEnv * jEnv,jobject,jfloatArray j_data)87 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_GetBufferData(JNIEnv* jEnv, jobject, jfloatArray j_data) {
88 float* dataBuffer = nativeRecorder->GetRecordBuffer();
89 if (dataBuffer != 0) {
90 jEnv->SetFloatArrayRegion(j_data, 0, nativeRecorder->GetNumBufferSamples(), dataBuffer);
91 }
92 }
93
Java_android_media_audio_cts_AudioRecorder_GetLastSLResult(JNIEnv *,jobject)94 JNIEXPORT jlong JNICALL Java_android_media_audio_cts_AudioRecorder_GetLastSLResult(JNIEnv*, jobject) {
95 return lastSLResult;
96 }
97
Java_android_media_audio_cts_AudioRecorder_ClearLastSLResult(JNIEnv *,jobject)98 JNIEXPORT void JNICALL Java_android_media_audio_cts_AudioRecorder_ClearLastSLResult(JNIEnv*, jobject) {
99 lastSLResult = 0;
100 }
101
102 } // extern "C"
103