| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 #include "webrtc/voice_engine/output_mixer.h" | 11 #include "webrtc/voice_engine/output_mixer.h" |
| 12 | 12 |
| 13 #include "webrtc/audio/utility/audio_frame_operations.h" | |
| 14 #include "webrtc/base/format_macros.h" | 13 #include "webrtc/base/format_macros.h" |
| 15 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 14 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 16 #include "webrtc/system_wrappers/include/file_wrapper.h" | 15 #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 17 #include "webrtc/system_wrappers/include/trace.h" | 16 #include "webrtc/system_wrappers/include/trace.h" |
| 18 #include "webrtc/voice_engine/statistics.h" | 17 #include "webrtc/voice_engine/statistics.h" |
| 19 #include "webrtc/voice_engine/utility.h" | 18 #include "webrtc/voice_engine/utility.h" |
| 20 | 19 |
| 21 namespace webrtc { | 20 namespace webrtc { |
| 22 namespace voe { | 21 namespace voe { |
| 23 | 22 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, | 83 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, |
| 85 "OutputMixer::Create() unable to allocate memory for" | 84 "OutputMixer::Create() unable to allocate memory for" |
| 86 "mixer"); | 85 "mixer"); |
| 87 return -1; | 86 return -1; |
| 88 } | 87 } |
| 89 return 0; | 88 return 0; |
| 90 } | 89 } |
| 91 | 90 |
| 92 OutputMixer::OutputMixer(uint32_t instanceId) : | 91 OutputMixer::OutputMixer(uint32_t instanceId) : |
| 93 _mixerModule(*AudioConferenceMixer::Create(instanceId)), | 92 _mixerModule(*AudioConferenceMixer::Create(instanceId)), |
| 94 _audioLevel(), | |
| 95 _instanceId(instanceId), | 93 _instanceId(instanceId), |
| 96 _panLeft(1.0f), | |
| 97 _panRight(1.0f), | |
| 98 _mixingFrequencyHz(8000), | 94 _mixingFrequencyHz(8000), |
| 99 _outputFileRecording(false) | 95 _outputFileRecording(false) |
| 100 { | 96 { |
| 101 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), | 97 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), |
| 102 "OutputMixer::OutputMixer() - ctor"); | 98 "OutputMixer::OutputMixer() - ctor"); |
| 103 | 99 |
| 104 if (_mixerModule.RegisterMixedStreamCallback(this) == -1) | 100 if (_mixerModule.RegisterMixedStreamCallback(this) == -1) |
| 105 { | 101 { |
| 106 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), | 102 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), |
| 107 "OutputMixer::OutputMixer() failed to register mixer" | 103 "OutputMixer::OutputMixer() failed to register mixer" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 return _mixerModule.SetAnonymousMixabilityStatus(&participant, mixable); | 163 return _mixerModule.SetAnonymousMixabilityStatus(&participant, mixable); |
| 168 } | 164 } |
| 169 | 165 |
| 170 int32_t | 166 int32_t |
| 171 OutputMixer::MixActiveChannels() | 167 OutputMixer::MixActiveChannels() |
| 172 { | 168 { |
| 173 _mixerModule.Process(); | 169 _mixerModule.Process(); |
| 174 return 0; | 170 return 0; |
| 175 } | 171 } |
| 176 | 172 |
| 177 int | |
| 178 OutputMixer::GetSpeechOutputLevel(uint32_t& level) | |
| 179 { | |
| 180 int8_t currentLevel = _audioLevel.Level(); | |
| 181 level = static_cast<uint32_t> (currentLevel); | |
| 182 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 183 "GetSpeechOutputLevel() => level=%u", level); | |
| 184 return 0; | |
| 185 } | |
| 186 | |
| 187 int | |
| 188 OutputMixer::GetSpeechOutputLevelFullRange(uint32_t& level) | |
| 189 { | |
| 190 int16_t currentLevel = _audioLevel.LevelFullRange(); | |
| 191 level = static_cast<uint32_t> (currentLevel); | |
| 192 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 193 "GetSpeechOutputLevelFullRange() => level=%u", level); | |
| 194 return 0; | |
| 195 } | |
| 196 | |
| 197 int | |
| 198 OutputMixer::SetOutputVolumePan(float left, float right) | |
| 199 { | |
| 200 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 201 "OutputMixer::SetOutputVolumePan()"); | |
| 202 _panLeft = left; | |
| 203 _panRight = right; | |
| 204 return 0; | |
| 205 } | |
| 206 | |
| 207 int | |
| 208 OutputMixer::GetOutputVolumePan(float& left, float& right) | |
| 209 { | |
| 210 left = _panLeft; | |
| 211 right = _panRight; | |
| 212 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 213 "GetOutputVolumePan() => left=%2.1f, right=%2.1f", | |
| 214 left, right); | |
| 215 return 0; | |
| 216 } | |
| 217 | |
| 218 int OutputMixer::StartRecordingPlayout(const char* fileName, | 173 int OutputMixer::StartRecordingPlayout(const char* fileName, |
| 219 const CodecInst* codecInst) | 174 const CodecInst* codecInst) |
| 220 { | 175 { |
| 221 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), | 176 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 222 "OutputMixer::StartRecordingPlayout(fileName=%s)", fileName); | 177 "OutputMixer::StartRecordingPlayout(fileName=%s)", fileName); |
| 223 | 178 |
| 224 if (_outputFileRecording) | 179 if (_outputFileRecording) |
| 225 { | 180 { |
| 226 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), | 181 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), |
| 227 "StartRecordingPlayout() is already recording"); | 182 "StartRecordingPlayout() is already recording"); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) | 370 OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) |
| 416 { | 371 { |
| 417 if (_audioFrame.sample_rate_hz_ != _mixingFrequencyHz) | 372 if (_audioFrame.sample_rate_hz_ != _mixingFrequencyHz) |
| 418 { | 373 { |
| 419 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), | 374 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 420 "OutputMixer::DoOperationsOnCombinedSignal() => " | 375 "OutputMixer::DoOperationsOnCombinedSignal() => " |
| 421 "mixing frequency = %d", _audioFrame.sample_rate_hz_); | 376 "mixing frequency = %d", _audioFrame.sample_rate_hz_); |
| 422 _mixingFrequencyHz = _audioFrame.sample_rate_hz_; | 377 _mixingFrequencyHz = _audioFrame.sample_rate_hz_; |
| 423 } | 378 } |
| 424 | 379 |
| 425 // Scale left and/or right channel(s) if balance is active | |
| 426 if (_panLeft != 1.0 || _panRight != 1.0) | |
| 427 { | |
| 428 if (_audioFrame.num_channels_ == 1) | |
| 429 { | |
| 430 AudioFrameOperations::MonoToStereo(&_audioFrame); | |
| 431 } | |
| 432 else | |
| 433 { | |
| 434 // Pure stereo mode (we are receiving a stereo signal). | |
| 435 } | |
| 436 | |
| 437 assert(_audioFrame.num_channels_ == 2); | |
| 438 AudioFrameOperations::Scale(_panLeft, _panRight, _audioFrame); | |
| 439 } | |
| 440 | |
| 441 // --- Far-end Voice Quality Enhancement (AudioProcessing Module) | 380 // --- Far-end Voice Quality Enhancement (AudioProcessing Module) |
| 442 if (feed_data_to_apm) { | 381 if (feed_data_to_apm) { |
| 443 if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { | 382 if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { |
| 444 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), | 383 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
| 445 "AudioProcessingModule::ProcessReverseStream() => error"); | 384 "AudioProcessingModule::ProcessReverseStream() => error"); |
| 446 RTC_NOTREACHED(); | 385 RTC_NOTREACHED(); |
| 447 } | 386 } |
| 448 } | 387 } |
| 449 | 388 |
| 450 // --- Measure audio level (0-9) for the combined signal | |
| 451 _audioLevel.ComputeLevel(_audioFrame); | |
| 452 | |
| 453 return 0; | 389 return 0; |
| 454 } | 390 } |
| 455 } // namespace voe | 391 } // namespace voe |
| 456 } // namespace webrtc | 392 } // namespace webrtc |
| OLD | NEW |