| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2012 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 #include "voice_engine/output_mixer.h" | |
| 12 | |
| 13 #include "modules/audio_processing/include/audio_processing.h" | |
| 14 #include "rtc_base/format_macros.h" | |
| 15 #include "system_wrappers/include/trace.h" | |
| 16 #include "voice_engine/statistics.h" | |
| 17 #include "voice_engine/utility.h" | |
| 18 | |
| 19 namespace webrtc { | |
| 20 namespace voe { | |
| 21 | |
| 22 void | |
| 23 OutputMixer::NewMixedAudio(int32_t id, | |
| 24 const AudioFrame& generalAudioFrame, | |
| 25 const AudioFrame** uniqueAudioFrames, | |
| 26 uint32_t size) | |
| 27 { | |
| 28 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), | |
| 29 "OutputMixer::NewMixedAudio(id=%d, size=%u)", id, size); | |
| 30 | |
| 31 _audioFrame.CopyFrom(generalAudioFrame); | |
| 32 _audioFrame.id_ = id; | |
| 33 } | |
| 34 | |
| 35 int32_t | |
| 36 OutputMixer::Create(OutputMixer*& mixer, uint32_t instanceId) | |
| 37 { | |
| 38 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, | |
| 39 "OutputMixer::Create(instanceId=%d)", instanceId); | |
| 40 mixer = new OutputMixer(instanceId); | |
| 41 if (mixer == NULL) | |
| 42 { | |
| 43 WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, | |
| 44 "OutputMixer::Create() unable to allocate memory for" | |
| 45 "mixer"); | |
| 46 return -1; | |
| 47 } | |
| 48 return 0; | |
| 49 } | |
| 50 | |
| 51 OutputMixer::OutputMixer(uint32_t instanceId) : | |
| 52 _mixerModule(*AudioConferenceMixer::Create(instanceId)), | |
| 53 _instanceId(instanceId), | |
| 54 _mixingFrequencyHz(8000) | |
| 55 { | |
| 56 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), | |
| 57 "OutputMixer::OutputMixer() - ctor"); | |
| 58 | |
| 59 if (_mixerModule.RegisterMixedStreamCallback(this) == -1) | |
| 60 { | |
| 61 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), | |
| 62 "OutputMixer::OutputMixer() failed to register mixer" | |
| 63 "callbacks"); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void | |
| 68 OutputMixer::Destroy(OutputMixer*& mixer) | |
| 69 { | |
| 70 if (mixer) | |
| 71 { | |
| 72 delete mixer; | |
| 73 mixer = NULL; | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 OutputMixer::~OutputMixer() | |
| 78 { | |
| 79 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), | |
| 80 "OutputMixer::~OutputMixer() - dtor"); | |
| 81 _mixerModule.UnRegisterMixedStreamCallback(); | |
| 82 delete &_mixerModule; | |
| 83 } | |
| 84 | |
| 85 int32_t | |
| 86 OutputMixer::SetEngineInformation(voe::Statistics& engineStatistics) | |
| 87 { | |
| 88 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 89 "OutputMixer::SetEngineInformation()"); | |
| 90 _engineStatisticsPtr = &engineStatistics; | |
| 91 return 0; | |
| 92 } | |
| 93 | |
| 94 int32_t | |
| 95 OutputMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) | |
| 96 { | |
| 97 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), | |
| 98 "OutputMixer::SetAudioProcessingModule(" | |
| 99 "audioProcessingModule=0x%x)", audioProcessingModule); | |
| 100 _audioProcessingModulePtr = audioProcessingModule; | |
| 101 return 0; | |
| 102 } | |
| 103 | |
| 104 int32_t | |
| 105 OutputMixer::SetMixabilityStatus(MixerParticipant& participant, | |
| 106 bool mixable) | |
| 107 { | |
| 108 return _mixerModule.SetMixabilityStatus(&participant, mixable); | |
| 109 } | |
| 110 | |
| 111 int32_t | |
| 112 OutputMixer::MixActiveChannels() | |
| 113 { | |
| 114 _mixerModule.Process(); | |
| 115 return 0; | |
| 116 } | |
| 117 | |
| 118 int OutputMixer::GetMixedAudio(int sample_rate_hz, | |
| 119 size_t num_channels, | |
| 120 AudioFrame* frame) { | |
| 121 WEBRTC_TRACE( | |
| 122 kTraceStream, kTraceVoice, VoEId(_instanceId,-1), | |
| 123 "OutputMixer::GetMixedAudio(sample_rate_hz=%d, num_channels=%" PRIuS ")", | |
| 124 sample_rate_hz, num_channels); | |
| 125 | |
| 126 frame->num_channels_ = num_channels; | |
| 127 frame->sample_rate_hz_ = sample_rate_hz; | |
| 128 // TODO(andrew): Ideally the downmixing would occur much earlier, in | |
| 129 // AudioCodingModule. | |
| 130 RemixAndResample(_audioFrame, &resampler_, frame); | |
| 131 return 0; | |
| 132 } | |
| 133 | |
| 134 int32_t | |
| 135 OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) | |
| 136 { | |
| 137 if (_audioFrame.sample_rate_hz_ != _mixingFrequencyHz) | |
| 138 { | |
| 139 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), | |
| 140 "OutputMixer::DoOperationsOnCombinedSignal() => " | |
| 141 "mixing frequency = %d", _audioFrame.sample_rate_hz_); | |
| 142 _mixingFrequencyHz = _audioFrame.sample_rate_hz_; | |
| 143 } | |
| 144 | |
| 145 // --- Far-end Voice Quality Enhancement (AudioProcessing Module) | |
| 146 if (feed_data_to_apm) { | |
| 147 if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { | |
| 148 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), | |
| 149 "AudioProcessingModule::ProcessReverseStream() => error"); | |
| 150 RTC_NOTREACHED(); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 return 0; | |
| 155 } | |
| 156 } // namespace voe | |
| 157 } // namespace webrtc | |
| OLD | NEW |