• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SDK_ANDROID_SRC_JNI_AUDIO_DEVICE_AUDIO_DEVICE_MODULE_H_
12 #define SDK_ANDROID_SRC_JNI_AUDIO_DEVICE_AUDIO_DEVICE_MODULE_H_
13 
14 #include <memory>
15 
16 #include "absl/types/optional.h"
17 #include "modules/audio_device/include/audio_device.h"
18 #include "sdk/android/native_api/jni/scoped_java_ref.h"
19 
20 namespace webrtc {
21 
22 class AudioDeviceBuffer;
23 
24 namespace jni {
25 
26 class AudioInput {
27  public:
~AudioInput()28   virtual ~AudioInput() {}
29 
30   virtual int32_t Init() = 0;
31   virtual int32_t Terminate() = 0;
32 
33   virtual int32_t InitRecording() = 0;
34   virtual bool RecordingIsInitialized() const = 0;
35 
36   virtual int32_t StartRecording() = 0;
37   virtual int32_t StopRecording() = 0;
38   virtual bool Recording() const = 0;
39 
40   virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) = 0;
41 
42   // Returns true if the audio input supports built-in audio effects for AEC and
43   // NS.
44   virtual bool IsAcousticEchoCancelerSupported() const = 0;
45   virtual bool IsNoiseSuppressorSupported() const = 0;
46 
47   virtual int32_t EnableBuiltInAEC(bool enable) = 0;
48   virtual int32_t EnableBuiltInNS(bool enable) = 0;
49 };
50 
51 class AudioOutput {
52  public:
~AudioOutput()53   virtual ~AudioOutput() {}
54 
55   virtual int32_t Init() = 0;
56   virtual int32_t Terminate() = 0;
57   virtual int32_t InitPlayout() = 0;
58   virtual bool PlayoutIsInitialized() const = 0;
59   virtual int32_t StartPlayout() = 0;
60   virtual int32_t StopPlayout() = 0;
61   virtual bool Playing() const = 0;
62   virtual bool SpeakerVolumeIsAvailable() = 0;
63   virtual int SetSpeakerVolume(uint32_t volume) = 0;
64   virtual absl::optional<uint32_t> SpeakerVolume() const = 0;
65   virtual absl::optional<uint32_t> MaxSpeakerVolume() const = 0;
66   virtual absl::optional<uint32_t> MinSpeakerVolume() const = 0;
67   virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) = 0;
68   virtual int GetPlayoutUnderrunCount() = 0;
69 };
70 
71 // Extract an android.media.AudioManager from an android.content.Context.
72 ScopedJavaLocalRef<jobject> GetAudioManager(JNIEnv* env,
73                                             const JavaRef<jobject>& j_context);
74 
75 // Get default audio sample rate by querying an android.media.AudioManager.
76 int GetDefaultSampleRate(JNIEnv* env, const JavaRef<jobject>& j_audio_manager);
77 
78 // Get audio input and output parameters based on a number of settings.
79 void GetAudioParameters(JNIEnv* env,
80                         const JavaRef<jobject>& j_context,
81                         const JavaRef<jobject>& j_audio_manager,
82                         int input_sample_rate,
83                         int output_sample_rate,
84                         bool use_stereo_input,
85                         bool use_stereo_output,
86                         AudioParameters* input_parameters,
87                         AudioParameters* output_parameters);
88 
89 // Glue together an audio input and audio output to get an AudioDeviceModule.
90 rtc::scoped_refptr<AudioDeviceModule> CreateAudioDeviceModuleFromInputAndOutput(
91     AudioDeviceModule::AudioLayer audio_layer,
92     bool is_stereo_playout_supported,
93     bool is_stereo_record_supported,
94     uint16_t playout_delay_ms,
95     std::unique_ptr<AudioInput> audio_input,
96     std::unique_ptr<AudioOutput> audio_output);
97 
98 }  // namespace jni
99 
100 }  // namespace webrtc
101 
102 #endif  // SDK_ANDROID_SRC_JNI_AUDIO_DEVICE_AUDIO_DEVICE_MODULE_H_
103