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/modules/audio_mixer/audio_mixer.h" | 11 #include "webrtc/modules/audio_mixer/audio_mixer.h" |
12 | 12 |
13 #include "webrtc/base/format_macros.h" | 13 #include "webrtc/base/format_macros.h" |
14 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 14 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
15 #include "webrtc/modules/utility/include/audio_frame_operations.h" | 15 #include "webrtc/modules/utility/include/audio_frame_operations.h" |
16 #include "webrtc/system_wrappers/include/file_wrapper.h" | 16 #include "webrtc/system_wrappers/include/file_wrapper.h" |
17 #include "webrtc/system_wrappers/include/trace.h" | 17 #include "webrtc/system_wrappers/include/trace.h" |
18 #include "webrtc/voice_engine/include/voe_external_media.h" | 18 #include "webrtc/voice_engine/include/voe_external_media.h" |
19 #include "webrtc/voice_engine/statistics.h" | 19 #include "webrtc/voice_engine/statistics.h" |
20 #include "webrtc/voice_engine/utility.h" | 20 #include "webrtc/voice_engine/utility.h" |
21 | 21 |
22 namespace webrtc { | 22 namespace webrtc { |
23 namespace voe { | 23 namespace voe { |
24 | 24 |
25 void AudioMixer::NewMixedAudio(int32_t id, | |
26 const AudioFrame& generalAudioFrame, | |
27 const AudioFrame** uniqueAudioFrames, | |
28 uint32_t size) { | |
29 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | |
30 "AudioMixer::NewMixedAudio(id=%d, size=%u)", id, size); | |
31 | |
32 _audioFrame.CopyFrom(generalAudioFrame); | |
33 _audioFrame.id_ = id; | |
34 } | |
35 | |
36 void AudioMixer::PlayNotification(int32_t id, uint32_t durationMs) { | 25 void AudioMixer::PlayNotification(int32_t id, uint32_t durationMs) { |
37 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 26 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
38 "AudioMixer::PlayNotification(id=%d, durationMs=%d)", id, | 27 "AudioMixer::PlayNotification(id=%d, durationMs=%d)", id, |
39 durationMs); | 28 durationMs); |
40 // Not implement yet | 29 // Not implement yet |
41 } | 30 } |
42 | 31 |
43 void AudioMixer::RecordNotification(int32_t id, uint32_t durationMs) { | 32 void AudioMixer::RecordNotification(int32_t id, uint32_t durationMs) { |
44 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 33 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
45 "AudioMixer::RecordNotification(id=%d, durationMs=%d)", id, | 34 "AudioMixer::RecordNotification(id=%d, durationMs=%d)", id, |
46 durationMs); | 35 durationMs); |
47 | 36 |
48 // Not implement yet | 37 // Not implement yet |
49 } | 38 } |
50 | 39 |
51 void AudioMixer::PlayFileEnded(int32_t id) { | 40 void AudioMixer::PlayFileEnded(int32_t id) { |
52 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 41 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
53 "AudioMixer::PlayFileEnded(id=%d)", id); | 42 "AudioMixer::PlayFileEnded(id=%d)", id); |
54 | 43 |
55 // not needed | 44 // not needed |
56 } | 45 } |
57 | 46 |
58 void AudioMixer::RecordFileEnded(int32_t id) { | 47 void AudioMixer::RecordFileEnded(int32_t id) { |
59 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 48 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
60 "AudioMixer::RecordFileEnded(id=%d)", id); | 49 "AudioMixer::RecordFileEnded(id=%d)", id); |
61 assert(id == _instanceId); | 50 RTC_DCHECK_EQ(id, _instanceId); |
62 | 51 |
63 rtc::CritScope cs(&_fileCritSect); | 52 rtc::CritScope cs(&_fileCritSect); |
64 _outputFileRecording = false; | 53 _outputFileRecording = false; |
65 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), | 54 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), |
66 "AudioMixer::RecordFileEnded() =>" | 55 "AudioMixer::RecordFileEnded() =>" |
67 "output file recorder module is shutdown"); | 56 "output file recorder module is shutdown"); |
68 } | 57 } |
69 | 58 |
70 int32_t AudioMixer::Create(AudioMixer*& mixer, uint32_t instanceId) { | 59 int32_t AudioMixer::Create(AudioMixer*& mixer, uint32_t instanceId) { |
71 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, | 60 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, |
(...skipping 14 matching lines...) Expand all Loading... |
86 _instanceId(instanceId), | 75 _instanceId(instanceId), |
87 _externalMediaCallbackPtr(NULL), | 76 _externalMediaCallbackPtr(NULL), |
88 _externalMedia(false), | 77 _externalMedia(false), |
89 _panLeft(1.0f), | 78 _panLeft(1.0f), |
90 _panRight(1.0f), | 79 _panRight(1.0f), |
91 _mixingFrequencyHz(8000), | 80 _mixingFrequencyHz(8000), |
92 _outputFileRecorderPtr(NULL), | 81 _outputFileRecorderPtr(NULL), |
93 _outputFileRecording(false) { | 82 _outputFileRecording(false) { |
94 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 83 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
95 "AudioMixer::AudioMixer() - ctor"); | 84 "AudioMixer::AudioMixer() - ctor"); |
96 | |
97 if (_mixerModule.RegisterMixedStreamCallback(this) == -1) { | |
98 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), | |
99 "AudioMixer::AudioMixer() failed to register mixer" | |
100 "callbacks"); | |
101 } | |
102 } | 85 } |
103 | 86 |
104 void AudioMixer::Destroy(AudioMixer*& mixer) { | 87 void AudioMixer::Destroy(AudioMixer*& mixer) { |
105 if (mixer) { | 88 if (mixer) { |
106 delete mixer; | 89 delete mixer; |
107 mixer = NULL; | 90 mixer = NULL; |
108 } | 91 } |
109 } | 92 } |
110 | 93 |
111 AudioMixer::~AudioMixer() { | 94 AudioMixer::~AudioMixer() { |
112 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 95 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
113 "AudioMixer::~AudioMixer() - dtor"); | 96 "AudioMixer::~AudioMixer() - dtor"); |
114 if (_externalMedia) { | 97 if (_externalMedia) { |
115 DeRegisterExternalMediaProcessing(); | 98 DeRegisterExternalMediaProcessing(); |
116 } | 99 } |
117 { | 100 { |
118 rtc::CritScope cs(&_fileCritSect); | 101 rtc::CritScope cs(&_fileCritSect); |
119 if (_outputFileRecorderPtr) { | 102 if (_outputFileRecorderPtr) { |
120 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); | 103 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
121 _outputFileRecorderPtr->StopRecording(); | 104 _outputFileRecorderPtr->StopRecording(); |
122 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | 105 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); |
123 _outputFileRecorderPtr = NULL; | 106 _outputFileRecorderPtr = NULL; |
124 } | 107 } |
125 } | 108 } |
126 _mixerModule.UnRegisterMixedStreamCallback(); | |
127 delete &_mixerModule; | 109 delete &_mixerModule; |
128 } | 110 } |
129 | 111 |
130 int32_t AudioMixer::SetEngineInformation(voe::Statistics& engineStatistics) { | 112 int32_t AudioMixer::SetEngineInformation(voe::Statistics& engineStatistics) { |
131 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 113 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
132 "AudioMixer::SetEngineInformation()"); | 114 "AudioMixer::SetEngineInformation()"); |
133 _engineStatisticsPtr = &engineStatistics; | 115 _engineStatisticsPtr = &engineStatistics; |
134 return 0; | 116 return 0; |
135 } | 117 } |
136 | 118 |
(...skipping 23 matching lines...) Expand all Loading... |
160 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 142 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
161 "AudioMixer::DeRegisterExternalMediaProcessing()"); | 143 "AudioMixer::DeRegisterExternalMediaProcessing()"); |
162 | 144 |
163 rtc::CritScope cs(&_callbackCritSect); | 145 rtc::CritScope cs(&_callbackCritSect); |
164 _externalMedia = false; | 146 _externalMedia = false; |
165 _externalMediaCallbackPtr = NULL; | 147 _externalMediaCallbackPtr = NULL; |
166 | 148 |
167 return 0; | 149 return 0; |
168 } | 150 } |
169 | 151 |
170 int32_t AudioMixer::SetMixabilityStatus(MixerAudioSource& participant, | 152 int32_t AudioMixer::SetMixabilityStatus(MixerAudioSource& audio_source, |
171 bool mixable) { | 153 bool mixable) { |
172 return _mixerModule.SetMixabilityStatus(&participant, mixable); | 154 return _mixerModule.SetMixabilityStatus(&audio_source, mixable); |
173 } | 155 } |
174 | 156 |
175 int32_t AudioMixer::SetAnonymousMixabilityStatus(MixerAudioSource& participant, | 157 int32_t AudioMixer::SetAnonymousMixabilityStatus(MixerAudioSource& audio_source, |
176 bool mixable) { | 158 bool mixable) { |
177 return _mixerModule.SetAnonymousMixabilityStatus(&participant, mixable); | 159 return _mixerModule.SetAnonymousMixabilityStatus(&audio_source, mixable); |
178 } | 160 } |
179 | 161 |
180 int32_t AudioMixer::MixActiveChannels() { | 162 int32_t AudioMixer::MixActiveChannels() { |
181 _mixerModule.Process(); | 163 _mixerModule.Mix(&_audioFrame); |
182 return 0; | 164 return 0; |
183 } | 165 } |
184 | 166 |
185 int AudioMixer::GetSpeechOutputLevel(uint32_t& level) { | 167 int AudioMixer::GetSpeechOutputLevel(uint32_t& level) { |
186 int8_t currentLevel = _audioLevel.Level(); | 168 int8_t currentLevel = _audioLevel.Level(); |
187 level = static_cast<uint32_t>(currentLevel); | 169 level = static_cast<uint32_t>(currentLevel); |
188 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), | 170 WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId, -1), |
189 "GetSpeechOutputLevel() => level=%u", level); | 171 "GetSpeechOutputLevel() => level=%u", level); |
190 return 0; | 172 return 0; |
191 } | 173 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 } | 389 } |
408 | 390 |
409 // Scale left and/or right channel(s) if balance is active | 391 // Scale left and/or right channel(s) if balance is active |
410 if (_panLeft != 1.0 || _panRight != 1.0) { | 392 if (_panLeft != 1.0 || _panRight != 1.0) { |
411 if (_audioFrame.num_channels_ == 1) { | 393 if (_audioFrame.num_channels_ == 1) { |
412 AudioFrameOperations::MonoToStereo(&_audioFrame); | 394 AudioFrameOperations::MonoToStereo(&_audioFrame); |
413 } else { | 395 } else { |
414 // Pure stereo mode (we are receiving a stereo signal). | 396 // Pure stereo mode (we are receiving a stereo signal). |
415 } | 397 } |
416 | 398 |
417 assert(_audioFrame.num_channels_ == 2); | 399 RTC_DCHECK_EQ(_audioFrame.num_channels_, static_cast<size_t>(2)); |
418 AudioFrameOperations::Scale(_panLeft, _panRight, _audioFrame); | 400 AudioFrameOperations::Scale(_panLeft, _panRight, _audioFrame); |
419 } | 401 } |
420 | 402 |
421 // --- Far-end Voice Quality Enhancement (AudioProcessing Module) | 403 // --- Far-end Voice Quality Enhancement (AudioProcessing Module) |
422 if (feed_data_to_apm) { | 404 if (feed_data_to_apm) { |
423 if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { | 405 if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { |
424 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), | 406 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
425 "AudioProcessingModule::ProcessReverseStream() => error"); | 407 "AudioProcessingModule::ProcessReverseStream() => error"); |
426 RTC_DCHECK(false); | 408 RTC_DCHECK(false); |
427 } | 409 } |
(...skipping 14 matching lines...) Expand all Loading... |
442 } | 424 } |
443 } | 425 } |
444 | 426 |
445 // --- Measure audio level (0-9) for the combined signal | 427 // --- Measure audio level (0-9) for the combined signal |
446 _audioLevel.ComputeLevel(_audioFrame); | 428 _audioLevel.ComputeLevel(_audioFrame); |
447 | 429 |
448 return 0; | 430 return 0; |
449 } | 431 } |
450 } // namespace voe | 432 } // namespace voe |
451 } // namespace webrtc | 433 } // namespace webrtc |
OLD | NEW |