| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ | 12 #define WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ |
| 13 | 13 |
| 14 #include <android/log.h> |
| 15 |
| 14 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 15 #include "webrtc/base/thread_checker.h" | 17 #include "webrtc/base/thread_checker.h" |
| 16 #include "webrtc/modules/audio_device/android/audio_manager.h" | 18 #include "webrtc/modules/audio_device/android/audio_manager.h" |
| 17 #include "webrtc/modules/audio_device/audio_device_generic.h" | 19 #include "webrtc/modules/audio_device/audio_device_generic.h" |
| 18 #include "webrtc/system_wrappers/interface/trace.h" | 20 #include "webrtc/system_wrappers/interface/trace.h" |
| 19 | 21 |
| 22 #define TAG "AudioDeviceTemplate" |
| 23 #define ALOGW(...) __android_log_print(ANDROID_LOG_WARN, TAG, __VA_ARGS__) |
| 24 |
| 20 namespace webrtc { | 25 namespace webrtc { |
| 21 | 26 |
| 22 // InputType/OutputType can be any class that implements the capturing/rendering | 27 // InputType/OutputType can be any class that implements the capturing/rendering |
| 23 // part of the AudioDeviceGeneric API. | 28 // part of the AudioDeviceGeneric API. |
| 24 // Construction and destruction must be done on one and the same thread. Each | 29 // Construction and destruction must be done on one and the same thread. Each |
| 25 // internal implementation of InputType and OutputType will DCHECK if that is | 30 // internal implementation of InputType and OutputType will DCHECK if that is |
| 26 // not the case. All implemented methods must also be called on the same thread. | 31 // not the case. All implemented methods must also be called on the same thread. |
| 27 // See comments in each InputType/OutputType class for more | 32 // See comments in each InputType/OutputType class for more |
| 28 // It is possible to call the two static methods (SetAndroidAudioDeviceObjects | 33 // It is possible to call the two static methods (SetAndroidAudioDeviceObjects |
| 29 // and ClearAndroidAudioDeviceObjects) from a different thread but both will | 34 // and ClearAndroidAudioDeviceObjects) from a different thread but both will |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 FATAL() << "Should never be called"; | 123 FATAL() << "Should never be called"; |
| 119 return -1; | 124 return -1; |
| 120 } | 125 } |
| 121 | 126 |
| 122 int32_t PlayoutIsAvailable(bool& available) override { | 127 int32_t PlayoutIsAvailable(bool& available) override { |
| 123 available = true; | 128 available = true; |
| 124 return 0; | 129 return 0; |
| 125 } | 130 } |
| 126 | 131 |
| 127 int32_t InitPlayout() override { | 132 int32_t InitPlayout() override { |
| 128 // Switches the Android audio mode to MODE_IN_COMMUNICATION to ensure that | |
| 129 // audio routing, volume control and echo performance are the best possible | |
| 130 // for VoIP. InitRecording() does the same type of call but only the first | |
| 131 // call has any effect. | |
| 132 // This call does nothing if MODE_IN_COMMUNICATION was already set. | |
| 133 audio_manager_->SetCommunicationMode(true); | |
| 134 return output_.InitPlayout(); | 133 return output_.InitPlayout(); |
| 135 } | 134 } |
| 136 | 135 |
| 137 bool PlayoutIsInitialized() const override { | 136 bool PlayoutIsInitialized() const override { |
| 138 return output_.PlayoutIsInitialized(); | 137 return output_.PlayoutIsInitialized(); |
| 139 } | 138 } |
| 140 | 139 |
| 141 int32_t RecordingIsAvailable(bool& available) override { | 140 int32_t RecordingIsAvailable(bool& available) override { |
| 142 available = true; | 141 available = true; |
| 143 return 0; | 142 return 0; |
| 144 } | 143 } |
| 145 | 144 |
| 146 int32_t InitRecording() override { | 145 int32_t InitRecording() override { |
| 147 // Switches the Android audio mode to MODE_IN_COMMUNICATION to ensure that | |
| 148 // audio routing, volume control and echo performance are the best possible | |
| 149 // for VoIP. InitRecording() does the same type of call but only the first | |
| 150 // call has any effect. | |
| 151 // This call does nothing if MODE_IN_COMMUNICATION was already set. | |
| 152 audio_manager_->SetCommunicationMode(true); | |
| 153 return input_.InitRecording(); | 146 return input_.InitRecording(); |
| 154 } | 147 } |
| 155 | 148 |
| 156 bool RecordingIsInitialized() const override { | 149 bool RecordingIsInitialized() const override { |
| 157 return input_.RecordingIsInitialized(); | 150 return input_.RecordingIsInitialized(); |
| 158 } | 151 } |
| 159 | 152 |
| 160 int32_t StartPlayout() override { | 153 int32_t StartPlayout() override { |
| 154 if (!audio_manager_->IsCommunicationModeEnabled()) { |
| 155 ALOGW("The application should use MODE_IN_COMMUNICATION audio mode!"); |
| 156 } |
| 161 return output_.StartPlayout(); | 157 return output_.StartPlayout(); |
| 162 } | 158 } |
| 163 | 159 |
| 164 int32_t StopPlayout() override { | 160 int32_t StopPlayout() override { |
| 165 // Avoid using audio manger (JNI/Java cost) if playout was inactive. | 161 // Avoid using audio manger (JNI/Java cost) if playout was inactive. |
| 166 if (!Playing()) | 162 if (!Playing()) |
| 167 return 0; | 163 return 0; |
| 168 int32_t err = output_.StopPlayout(); | 164 int32_t err = output_.StopPlayout(); |
| 169 if (!Recording()) { | |
| 170 // Restore initial audio mode since all audio streaming is disabled. | |
| 171 // The default mode was stored in Init(). | |
| 172 audio_manager_->SetCommunicationMode(false); | |
| 173 } | |
| 174 return err; | 165 return err; |
| 175 } | 166 } |
| 176 | 167 |
| 177 bool Playing() const override { | 168 bool Playing() const override { |
| 178 return output_.Playing(); | 169 return output_.Playing(); |
| 179 } | 170 } |
| 180 | 171 |
| 181 int32_t StartRecording() override { | 172 int32_t StartRecording() override { |
| 173 if (!audio_manager_->IsCommunicationModeEnabled()) { |
| 174 ALOGW("The application should use MODE_IN_COMMUNICATION audio mode!"); |
| 175 } |
| 182 return input_.StartRecording(); | 176 return input_.StartRecording(); |
| 183 } | 177 } |
| 184 | 178 |
| 185 int32_t StopRecording() override { | 179 int32_t StopRecording() override { |
| 186 // Avoid using audio manger (JNI/Java cost) if recording was inactive. | 180 // Avoid using audio manger (JNI/Java cost) if recording was inactive. |
| 187 if (!Recording()) | 181 if (!Recording()) |
| 188 return 0; | 182 return 0; |
| 189 int32_t err = input_.StopRecording(); | 183 int32_t err = input_.StopRecording(); |
| 190 if (!Playing()) { | |
| 191 // Restore initial audio mode since all audio streaming is disabled. | |
| 192 // The default mode was is stored in Init(). | |
| 193 audio_manager_->SetCommunicationMode(false); | |
| 194 } | |
| 195 return err; | 184 return err; |
| 196 } | 185 } |
| 197 | 186 |
| 198 bool Recording() const override { | 187 bool Recording() const override { |
| 199 return input_.Recording() ; | 188 return input_.Recording() ; |
| 200 } | 189 } |
| 201 | 190 |
| 202 int32_t SetAGC(bool enable) override { | 191 int32_t SetAGC(bool enable) override { |
| 203 if (enable) { | 192 if (enable) { |
| 204 FATAL() << "Should never be called"; | 193 FATAL() << "Should never be called"; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 OutputType output_; | 462 OutputType output_; |
| 474 | 463 |
| 475 InputType input_; | 464 InputType input_; |
| 476 | 465 |
| 477 bool initialized_; | 466 bool initialized_; |
| 478 }; | 467 }; |
| 479 | 468 |
| 480 } // namespace webrtc | 469 } // namespace webrtc |
| 481 | 470 |
| 482 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ | 471 #endif // WEBRTC_MODULES_AUDIO_DEVICE_ANDROID_AUDIO_DEVICE_TEMPLATE_H_ |
| OLD | NEW |