2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
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.
11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_
14 #include "webrtc/modules/audio_device/audio_device_generic.h"
16 #include "webrtc/system_wrappers/interface/trace.h"
20 // InputType/OutputType can be any class that implements the capturing/rendering
21 // part of the AudioDeviceGeneric API.
22 template <class InputType, class OutputType>
23 class AudioDeviceTemplate : public AudioDeviceGeneric {
25 static int32_t SetAndroidAudioDeviceObjects(void* javaVM,
28 if (OutputType::SetAndroidAudioDeviceObjects(javaVM, env, context) == -1) {
31 return InputType::SetAndroidAudioDeviceObjects(javaVM, env, context);
34 static void ClearAndroidAudioDeviceObjects() {
35 OutputType::ClearAndroidAudioDeviceObjects();
36 InputType::ClearAndroidAudioDeviceObjects();
39 explicit AudioDeviceTemplate(const int32_t id)
41 input_(id, &output_) {
44 virtual ~AudioDeviceTemplate() {
47 int32_t ActiveAudioLayer(
48 AudioDeviceModule::AudioLayer& audioLayer) const { // NOLINT
49 audioLayer = AudioDeviceModule::kPlatformDefaultAudio;
54 return output_.Init() | input_.Init();
58 return output_.Terminate() | input_.Terminate();
61 bool Initialized() const {
62 return output_.Initialized() && input_.Initialized();
65 int16_t PlayoutDevices() {
66 return output_.PlayoutDevices();
69 int16_t RecordingDevices() {
70 return input_.RecordingDevices();
73 int32_t PlayoutDeviceName(
75 char name[kAdmMaxDeviceNameSize],
76 char guid[kAdmMaxGuidSize]) {
77 return output_.PlayoutDeviceName(index, name, guid);
80 int32_t RecordingDeviceName(
82 char name[kAdmMaxDeviceNameSize],
83 char guid[kAdmMaxGuidSize]) {
84 return input_.RecordingDeviceName(index, name, guid);
87 int32_t SetPlayoutDevice(uint16_t index) {
88 return output_.SetPlayoutDevice(index);
91 int32_t SetPlayoutDevice(
92 AudioDeviceModule::WindowsDeviceType device) {
93 return output_.SetPlayoutDevice(device);
96 int32_t SetRecordingDevice(uint16_t index) {
97 return input_.SetRecordingDevice(index);
100 int32_t SetRecordingDevice(
101 AudioDeviceModule::WindowsDeviceType device) {
102 return input_.SetRecordingDevice(device);
105 int32_t PlayoutIsAvailable(
106 bool& available) { // NOLINT
107 return output_.PlayoutIsAvailable(available);
110 int32_t InitPlayout() {
111 return output_.InitPlayout();
114 bool PlayoutIsInitialized() const {
115 return output_.PlayoutIsInitialized();
118 int32_t RecordingIsAvailable(
119 bool& available) { // NOLINT
120 return input_.RecordingIsAvailable(available);
123 int32_t InitRecording() {
124 return input_.InitRecording();
127 bool RecordingIsInitialized() const {
128 return input_.RecordingIsInitialized();
131 int32_t StartPlayout() {
132 return output_.StartPlayout();
135 int32_t StopPlayout() {
136 return output_.StopPlayout();
139 bool Playing() const {
140 return output_.Playing();
143 int32_t StartRecording() {
144 return input_.StartRecording();
147 int32_t StopRecording() {
148 return input_.StopRecording();
151 bool Recording() const {
152 return input_.Recording() ;
155 int32_t SetAGC(bool enable) {
156 return input_.SetAGC(enable);
163 int32_t SetWaveOutVolume(uint16_t volumeLeft,
164 uint16_t volumeRight) {
165 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
166 " API call not supported on this platform");
170 int32_t WaveOutVolume(
171 uint16_t& volumeLeft, // NOLINT
172 uint16_t& volumeRight) const { // NOLINT
173 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
174 " API call not supported on this platform");
178 int32_t InitSpeaker() {
179 return output_.InitSpeaker();
182 bool SpeakerIsInitialized() const {
183 return output_.SpeakerIsInitialized();
186 int32_t InitMicrophone() {
187 return input_.InitMicrophone();
190 bool MicrophoneIsInitialized() const {
191 return input_.MicrophoneIsInitialized();
194 int32_t SpeakerVolumeIsAvailable(
195 bool& available) { // NOLINT
196 return output_.SpeakerVolumeIsAvailable(available);
199 int32_t SetSpeakerVolume(uint32_t volume) {
200 return output_.SetSpeakerVolume(volume);
203 int32_t SpeakerVolume(
204 uint32_t& volume) const { // NOLINT
205 return output_.SpeakerVolume(volume);
208 int32_t MaxSpeakerVolume(
209 uint32_t& maxVolume) const { // NOLINT
210 return output_.MaxSpeakerVolume(maxVolume);
213 int32_t MinSpeakerVolume(
214 uint32_t& minVolume) const { // NOLINT
215 return output_.MinSpeakerVolume(minVolume);
218 int32_t SpeakerVolumeStepSize(
219 uint16_t& stepSize) const { // NOLINT
220 return output_.SpeakerVolumeStepSize(stepSize);
223 int32_t MicrophoneVolumeIsAvailable(
224 bool& available) { // NOLINT
225 return input_.MicrophoneVolumeIsAvailable(available);
228 int32_t SetMicrophoneVolume(uint32_t volume) {
229 return input_.SetMicrophoneVolume(volume);
232 int32_t MicrophoneVolume(
233 uint32_t& volume) const { // NOLINT
234 return input_.MicrophoneVolume(volume);
237 int32_t MaxMicrophoneVolume(
238 uint32_t& maxVolume) const { // NOLINT
239 return input_.MaxMicrophoneVolume(maxVolume);
242 int32_t MinMicrophoneVolume(
243 uint32_t& minVolume) const { // NOLINT
244 return input_.MinMicrophoneVolume(minVolume);
247 int32_t MicrophoneVolumeStepSize(
248 uint16_t& stepSize) const { // NOLINT
249 return input_.MicrophoneVolumeStepSize(stepSize);
252 int32_t SpeakerMuteIsAvailable(
253 bool& available) { // NOLINT
254 return output_.SpeakerMuteIsAvailable(available);
257 int32_t SetSpeakerMute(bool enable) {
258 return output_.SetSpeakerMute(enable);
262 bool& enabled) const { // NOLINT
263 return output_.SpeakerMute(enabled);
266 int32_t MicrophoneMuteIsAvailable(
267 bool& available) { // NOLINT
268 return input_.MicrophoneMuteIsAvailable(available);
271 int32_t SetMicrophoneMute(bool enable) {
272 return input_.SetMicrophoneMute(enable);
275 int32_t MicrophoneMute(
276 bool& enabled) const { // NOLINT
277 return input_.MicrophoneMute(enabled);
280 int32_t MicrophoneBoostIsAvailable(
281 bool& available) { // NOLINT
282 return input_.MicrophoneBoostIsAvailable(available);
285 int32_t SetMicrophoneBoost(bool enable) {
286 return input_.SetMicrophoneBoost(enable);
289 int32_t MicrophoneBoost(
290 bool& enabled) const { // NOLINT
291 return input_.MicrophoneBoost(enabled);
294 int32_t StereoPlayoutIsAvailable(
295 bool& available) { // NOLINT
296 return output_.StereoPlayoutIsAvailable(available);
299 int32_t SetStereoPlayout(bool enable) {
300 return output_.SetStereoPlayout(enable);
303 int32_t StereoPlayout(
304 bool& enabled) const { // NOLINT
305 return output_.StereoPlayout(enabled);
308 int32_t StereoRecordingIsAvailable(
309 bool& available) { // NOLINT
310 return input_.StereoRecordingIsAvailable(available);
313 int32_t SetStereoRecording(bool enable) {
314 return input_.SetStereoRecording(enable);
317 int32_t StereoRecording(
318 bool& enabled) const { // NOLINT
319 return input_.StereoRecording(enabled);
322 int32_t SetPlayoutBuffer(
323 const AudioDeviceModule::BufferType type,
325 return output_.SetPlayoutBuffer(type, sizeMS);
328 int32_t PlayoutBuffer(
329 AudioDeviceModule::BufferType& type,
330 uint16_t& sizeMS) const { // NOLINT
331 return output_.PlayoutBuffer(type, sizeMS);
334 int32_t PlayoutDelay(
335 uint16_t& delayMS) const { // NOLINT
336 return output_.PlayoutDelay(delayMS);
339 int32_t RecordingDelay(
340 uint16_t& delayMS) const { // NOLINT
341 return input_.RecordingDelay(delayMS);
345 uint16_t& load) const { // NOLINT
346 WEBRTC_TRACE(kTraceWarning, kTraceAudioDevice, 0,
347 " API call not supported on this platform");
351 bool PlayoutWarning() const {
352 return output_.PlayoutWarning();
355 bool PlayoutError() const {
356 return output_.PlayoutError();
359 bool RecordingWarning() const {
360 return input_.RecordingWarning();
363 bool RecordingError() const {
364 return input_.RecordingError();
367 void ClearPlayoutWarning() {
368 return output_.ClearPlayoutWarning();
371 void ClearPlayoutError() {
372 return output_.ClearPlayoutError();
375 void ClearRecordingWarning() {
376 return input_.ClearRecordingWarning();
379 void ClearRecordingError() {
380 return input_.ClearRecordingError();
383 void AttachAudioBuffer(
384 AudioDeviceBuffer* audioBuffer) {
385 output_.AttachAudioBuffer(audioBuffer);
386 input_.AttachAudioBuffer(audioBuffer);
389 int32_t SetRecordingSampleRate(
390 const uint32_t samplesPerSec) {
391 return input_.SetRecordingSampleRate(samplesPerSec);
394 int32_t SetPlayoutSampleRate(
395 const uint32_t samplesPerSec) {
396 return output_.SetPlayoutSampleRate(samplesPerSec);
399 int32_t SetLoudspeakerStatus(bool enable) {
400 return output_.SetLoudspeakerStatus(enable);
403 int32_t GetLoudspeakerStatus(
404 bool& enable) const { // NOLINT
405 return output_.GetLoudspeakerStatus(enable);
413 } // namespace webrtc
415 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_