1 /*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12
13 #include "sdk/android/generated_java_audio_jni/JavaAudioDeviceModule_jni.h"
14 #include "sdk/android/src/jni/audio_device/audio_record_jni.h"
15 #include "sdk/android/src/jni/audio_device/audio_track_jni.h"
16 #include "sdk/android/src/jni/jni_helpers.h"
17
18 namespace webrtc {
19 namespace jni {
20
JNI_JavaAudioDeviceModule_CreateAudioDeviceModule(JNIEnv * env,const JavaParamRef<jobject> & j_context,const JavaParamRef<jobject> & j_audio_manager,const JavaParamRef<jobject> & j_webrtc_audio_record,const JavaParamRef<jobject> & j_webrtc_audio_track,int input_sample_rate,int output_sample_rate,jboolean j_use_stereo_input,jboolean j_use_stereo_output)21 static jlong JNI_JavaAudioDeviceModule_CreateAudioDeviceModule(
22 JNIEnv* env,
23 const JavaParamRef<jobject>& j_context,
24 const JavaParamRef<jobject>& j_audio_manager,
25 const JavaParamRef<jobject>& j_webrtc_audio_record,
26 const JavaParamRef<jobject>& j_webrtc_audio_track,
27 int input_sample_rate,
28 int output_sample_rate,
29 jboolean j_use_stereo_input,
30 jboolean j_use_stereo_output) {
31 AudioParameters input_parameters;
32 AudioParameters output_parameters;
33 GetAudioParameters(env, j_context, j_audio_manager, input_sample_rate,
34 output_sample_rate, j_use_stereo_input,
35 j_use_stereo_output, &input_parameters,
36 &output_parameters);
37 auto audio_input = std::make_unique<AudioRecordJni>(
38 env, input_parameters, kHighLatencyModeDelayEstimateInMilliseconds,
39 j_webrtc_audio_record);
40 auto audio_output = std::make_unique<AudioTrackJni>(env, output_parameters,
41 j_webrtc_audio_track);
42 return jlongFromPointer(CreateAudioDeviceModuleFromInputAndOutput(
43 AudioDeviceModule::kAndroidJavaAudio,
44 j_use_stereo_input, j_use_stereo_output,
45 kHighLatencyModeDelayEstimateInMilliseconds,
46 std::move(audio_input), std::move(audio_output))
47 .release());
48 }
49
50 } // namespace jni
51 } // namespace webrtc
52