niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
mflodman@webrtc.org | 9a065d1 | 2012-03-07 08:12:21 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 11 | #include "webrtc/voice_engine/output_mixer.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 13 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 14 | #include "webrtc/rtc_base/format_macros.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 15 | #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 16 | #include "webrtc/system_wrappers/include/trace.h" |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 17 | #include "webrtc/voice_engine/statistics.h" |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 18 | #include "webrtc/voice_engine/utility.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 21 | namespace voe { |
| 22 | |
| 23 | void |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 24 | OutputMixer::NewMixedAudio(int32_t id, |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | const AudioFrame& generalAudioFrame, |
| 26 | const AudioFrame** uniqueAudioFrames, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 27 | uint32_t size) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 28 | { |
| 29 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 30 | "OutputMixer::NewMixedAudio(id=%d, size=%u)", id, size); |
| 31 | |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 32 | _audioFrame.CopyFrom(generalAudioFrame); |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 33 | _audioFrame.id_ = id; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | } |
| 35 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 36 | void OutputMixer::PlayNotification(int32_t id, uint32_t durationMs) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 37 | { |
| 38 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 39 | "OutputMixer::PlayNotification(id=%d, durationMs=%d)", |
| 40 | id, durationMs); |
| 41 | // Not implement yet |
| 42 | } |
| 43 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 44 | void OutputMixer::RecordNotification(int32_t id, |
| 45 | uint32_t durationMs) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 46 | { |
| 47 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 48 | "OutputMixer::RecordNotification(id=%d, durationMs=%d)", |
| 49 | id, durationMs); |
| 50 | |
| 51 | // Not implement yet |
| 52 | } |
| 53 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 54 | void OutputMixer::PlayFileEnded(int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | { |
| 56 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 57 | "OutputMixer::PlayFileEnded(id=%d)", id); |
| 58 | |
| 59 | // not needed |
| 60 | } |
| 61 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 62 | void OutputMixer::RecordFileEnded(int32_t id) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 63 | { |
| 64 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 65 | "OutputMixer::RecordFileEnded(id=%d)", id); |
| 66 | assert(id == _instanceId); |
| 67 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 68 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 69 | _outputFileRecording = false; |
| 70 | WEBRTC_TRACE(kTraceStateInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 71 | "OutputMixer::RecordFileEnded() =>" |
| 72 | "output file recorder module is shutdown"); |
| 73 | } |
| 74 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 75 | int32_t |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 76 | OutputMixer::Create(OutputMixer*& mixer, uint32_t instanceId) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 77 | { |
| 78 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, |
| 79 | "OutputMixer::Create(instanceId=%d)", instanceId); |
| 80 | mixer = new OutputMixer(instanceId); |
| 81 | if (mixer == NULL) |
| 82 | { |
| 83 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, instanceId, |
| 84 | "OutputMixer::Create() unable to allocate memory for" |
| 85 | "mixer"); |
| 86 | return -1; |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 91 | OutputMixer::OutputMixer(uint32_t instanceId) : |
andrew@webrtc.org | c4f129f | 2011-11-10 03:41:22 +0000 | [diff] [blame] | 92 | _mixerModule(*AudioConferenceMixer::Create(instanceId)), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 93 | _instanceId(instanceId), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 94 | _mixingFrequencyHz(8000), |
xians@google.com | 22963ab | 2011-08-03 12:40:23 +0000 | [diff] [blame] | 95 | _outputFileRecording(false) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 96 | { |
| 97 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), |
| 98 | "OutputMixer::OutputMixer() - ctor"); |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 99 | |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 100 | if (_mixerModule.RegisterMixedStreamCallback(this) == -1) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 101 | { |
| 102 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), |
| 103 | "OutputMixer::OutputMixer() failed to register mixer" |
| 104 | "callbacks"); |
| 105 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void |
| 109 | OutputMixer::Destroy(OutputMixer*& mixer) |
| 110 | { |
| 111 | if (mixer) |
| 112 | { |
| 113 | delete mixer; |
| 114 | mixer = NULL; |
| 115 | } |
| 116 | } |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 117 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 118 | OutputMixer::~OutputMixer() |
| 119 | { |
| 120 | WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId,-1), |
| 121 | "OutputMixer::~OutputMixer() - dtor"); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 123 | rtc::CritScope cs(&_fileCritSect); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 124 | if (output_file_recorder_) { |
| 125 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 126 | output_file_recorder_->StopRecording(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | _mixerModule.UnRegisterMixedStreamCallback(); |
| 130 | delete &_mixerModule; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 131 | } |
| 132 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 133 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 134 | OutputMixer::SetEngineInformation(voe::Statistics& engineStatistics) |
| 135 | { |
| 136 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 137 | "OutputMixer::SetEngineInformation()"); |
| 138 | _engineStatisticsPtr = &engineStatistics; |
| 139 | return 0; |
| 140 | } |
| 141 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 142 | int32_t |
| 143 | OutputMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 144 | { |
| 145 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 146 | "OutputMixer::SetAudioProcessingModule(" |
| 147 | "audioProcessingModule=0x%x)", audioProcessingModule); |
| 148 | _audioProcessingModulePtr = audioProcessingModule; |
| 149 | return 0; |
| 150 | } |
| 151 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 152 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 153 | OutputMixer::SetMixabilityStatus(MixerParticipant& participant, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 154 | bool mixable) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 155 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 156 | return _mixerModule.SetMixabilityStatus(&participant, mixable); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 157 | } |
| 158 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 159 | int32_t |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 160 | OutputMixer::SetAnonymousMixabilityStatus(MixerParticipant& participant, |
pbos@webrtc.org | 9213521 | 2013-05-14 08:31:39 +0000 | [diff] [blame] | 161 | bool mixable) |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 162 | { |
minyuel | 0f4b373 | 2015-08-31 16:04:32 +0200 | [diff] [blame] | 163 | return _mixerModule.SetAnonymousMixabilityStatus(&participant, mixable); |
henrike@webrtc.org | 066f9e5 | 2011-10-28 23:15:47 +0000 | [diff] [blame] | 164 | } |
| 165 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 166 | int32_t |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 167 | OutputMixer::MixActiveChannels() |
| 168 | { |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 169 | _mixerModule.Process(); |
| 170 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 171 | } |
| 172 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 173 | int OutputMixer::StartRecordingPlayout(const char* fileName, |
| 174 | const CodecInst* codecInst) |
| 175 | { |
| 176 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 177 | "OutputMixer::StartRecordingPlayout(fileName=%s)", fileName); |
| 178 | |
| 179 | if (_outputFileRecording) |
| 180 | { |
| 181 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), |
| 182 | "StartRecordingPlayout() is already recording"); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | FileFormats format; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 187 | const uint32_t notificationTime(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 188 | CodecInst dummyCodec={100,"L16",16000,320,1,320000}; |
| 189 | |
niklas.enbom@webrtc.org | 40197d7 | 2012-03-26 08:45:47 +0000 | [diff] [blame] | 190 | if ((codecInst != NULL) && |
| 191 | ((codecInst->channels < 1) || (codecInst->channels > 2))) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | { |
| 193 | _engineStatisticsPtr->SetLastError( |
| 194 | VE_BAD_ARGUMENT, kTraceError, |
| 195 | "StartRecordingPlayout() invalid compression"); |
| 196 | return(-1); |
| 197 | } |
| 198 | if(codecInst == NULL) |
| 199 | { |
| 200 | format = kFileFormatPcm16kHzFile; |
| 201 | codecInst=&dummyCodec; |
| 202 | } |
| 203 | else if((STR_CASE_CMP(codecInst->plname,"L16") == 0) || |
| 204 | (STR_CASE_CMP(codecInst->plname,"PCMU") == 0) || |
| 205 | (STR_CASE_CMP(codecInst->plname,"PCMA") == 0)) |
| 206 | { |
| 207 | format = kFileFormatWavFile; |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | format = kFileFormatCompressedFile; |
| 212 | } |
| 213 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 214 | rtc::CritScope cs(&_fileCritSect); |
andrew@webrtc.org | ae1a58b | 2013-01-22 04:44:30 +0000 | [diff] [blame] | 215 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 216 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 217 | if (output_file_recorder_) { |
| 218 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 219 | output_file_recorder_.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 220 | } |
| 221 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 222 | output_file_recorder_ = FileRecorder::CreateFileRecorder( |
| 223 | _instanceId, (const FileFormats)format); |
| 224 | if (!output_file_recorder_) { |
| 225 | _engineStatisticsPtr->SetLastError( |
| 226 | VE_INVALID_ARGUMENT, kTraceError, |
| 227 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 228 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 229 | } |
| 230 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 231 | if (output_file_recorder_->StartRecordingAudioFile( |
| 232 | fileName, (const CodecInst&)*codecInst, notificationTime) != 0) { |
| 233 | _engineStatisticsPtr->SetLastError( |
| 234 | VE_BAD_FILE, kTraceError, |
| 235 | "StartRecordingAudioFile() failed to start file recording"); |
| 236 | output_file_recorder_->StopRecording(); |
| 237 | output_file_recorder_.reset(); |
| 238 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 239 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 240 | output_file_recorder_->RegisterModuleFileCallback(this); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 241 | _outputFileRecording = true; |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
| 246 | int OutputMixer::StartRecordingPlayout(OutStream* stream, |
| 247 | const CodecInst* codecInst) |
| 248 | { |
| 249 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 250 | "OutputMixer::StartRecordingPlayout()"); |
| 251 | |
| 252 | if (_outputFileRecording) |
| 253 | { |
| 254 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId,-1), |
| 255 | "StartRecordingPlayout() is already recording"); |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | FileFormats format; |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 260 | const uint32_t notificationTime(0); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 261 | CodecInst dummyCodec={100,"L16",16000,320,1,320000}; |
| 262 | |
| 263 | if (codecInst != NULL && codecInst->channels != 1) |
| 264 | { |
| 265 | _engineStatisticsPtr->SetLastError( |
| 266 | VE_BAD_ARGUMENT, kTraceError, |
| 267 | "StartRecordingPlayout() invalid compression"); |
| 268 | return(-1); |
| 269 | } |
| 270 | if(codecInst == NULL) |
| 271 | { |
| 272 | format = kFileFormatPcm16kHzFile; |
| 273 | codecInst=&dummyCodec; |
| 274 | } |
| 275 | else if((STR_CASE_CMP(codecInst->plname,"L16") == 0) || |
| 276 | (STR_CASE_CMP(codecInst->plname,"PCMU") == 0) || |
| 277 | (STR_CASE_CMP(codecInst->plname,"PCMA") == 0)) |
| 278 | { |
| 279 | format = kFileFormatWavFile; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | format = kFileFormatCompressedFile; |
| 284 | } |
| 285 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 286 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 287 | |
| 288 | // Destroy the old instance |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 289 | if (output_file_recorder_) { |
| 290 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 291 | output_file_recorder_.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 292 | } |
| 293 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 294 | output_file_recorder_ = FileRecorder::CreateFileRecorder( |
| 295 | _instanceId, (const FileFormats)format); |
| 296 | if (!output_file_recorder_) { |
| 297 | _engineStatisticsPtr->SetLastError( |
| 298 | VE_INVALID_ARGUMENT, kTraceError, |
| 299 | "StartRecordingPlayout() fileRecorder format isnot correct"); |
| 300 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 301 | } |
| 302 | |
kwiberg | 4ec01d9 | 2016-08-22 08:43:54 -0700 | [diff] [blame] | 303 | if (output_file_recorder_->StartRecordingAudioFile(stream, *codecInst, |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 304 | notificationTime) != 0) { |
| 305 | _engineStatisticsPtr->SetLastError( |
| 306 | VE_BAD_FILE, kTraceError, |
| 307 | "StartRecordingAudioFile() failed to start file recording"); |
| 308 | output_file_recorder_->StopRecording(); |
| 309 | output_file_recorder_.reset(); |
| 310 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 311 | } |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 312 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 313 | output_file_recorder_->RegisterModuleFileCallback(this); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 314 | _outputFileRecording = true; |
| 315 | |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | int OutputMixer::StopRecordingPlayout() |
| 320 | { |
| 321 | WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId,-1), |
| 322 | "OutputMixer::StopRecordingPlayout()"); |
| 323 | |
| 324 | if (!_outputFileRecording) |
| 325 | { |
| 326 | WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId,-1), |
| 327 | "StopRecordingPlayout() file isnot recording"); |
| 328 | return -1; |
| 329 | } |
| 330 | |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 331 | rtc::CritScope cs(&_fileCritSect); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 332 | |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 333 | if (output_file_recorder_->StopRecording() != 0) { |
| 334 | _engineStatisticsPtr->SetLastError( |
| 335 | VE_STOP_RECORDING_FAILED, kTraceError, |
| 336 | "StopRecording(), could not stop recording"); |
| 337 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 338 | } |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 339 | output_file_recorder_->RegisterModuleFileCallback(NULL); |
| 340 | output_file_recorder_.reset(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 341 | _outputFileRecording = false; |
| 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 346 | int OutputMixer::GetMixedAudio(int sample_rate_hz, |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 347 | size_t num_channels, |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 348 | AudioFrame* frame) { |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 349 | WEBRTC_TRACE( |
| 350 | kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 351 | "OutputMixer::GetMixedAudio(sample_rate_hz=%d, num_channels=%" PRIuS ")", |
| 352 | sample_rate_hz, num_channels); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 353 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 354 | // --- Record playout if enabled |
| 355 | { |
tommi | 31fc21f | 2016-01-21 10:37:37 -0800 | [diff] [blame] | 356 | rtc::CritScope cs(&_fileCritSect); |
kwiberg | 5a25d95 | 2016-08-17 07:31:12 -0700 | [diff] [blame] | 357 | if (_outputFileRecording && output_file_recorder_) |
| 358 | output_file_recorder_->RecordAudioToFile(_audioFrame); |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 359 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 360 | |
andrew@webrtc.org | 4ecea3e | 2012-06-27 03:25:31 +0000 | [diff] [blame] | 361 | frame->num_channels_ = num_channels; |
| 362 | frame->sample_rate_hz_ = sample_rate_hz; |
| 363 | // TODO(andrew): Ideally the downmixing would occur much earlier, in |
| 364 | // AudioCodingModule. |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 365 | RemixAndResample(_audioFrame, &resampler_, frame); |
| 366 | return 0; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 367 | } |
| 368 | |
pbos@webrtc.org | 6141e13 | 2013-04-09 10:09:10 +0000 | [diff] [blame] | 369 | int32_t |
xians@webrtc.org | 5692531 | 2014-04-14 10:50:37 +0000 | [diff] [blame] | 370 | OutputMixer::DoOperationsOnCombinedSignal(bool feed_data_to_apm) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 371 | { |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 372 | if (_audioFrame.sample_rate_hz_ != _mixingFrequencyHz) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 373 | { |
| 374 | WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId,-1), |
| 375 | "OutputMixer::DoOperationsOnCombinedSignal() => " |
andrew@webrtc.org | 63a5098 | 2012-05-02 23:56:37 +0000 | [diff] [blame] | 376 | "mixing frequency = %d", _audioFrame.sample_rate_hz_); |
| 377 | _mixingFrequencyHz = _audioFrame.sample_rate_hz_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 378 | } |
| 379 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 380 | // --- Far-end Voice Quality Enhancement (AudioProcessing Module) |
peah | 66085be | 2015-12-16 02:02:20 -0800 | [diff] [blame] | 381 | if (feed_data_to_apm) { |
aluebs | da116c4 | 2016-03-17 16:43:29 -0700 | [diff] [blame] | 382 | if (_audioProcessingModulePtr->ProcessReverseStream(&_audioFrame) != 0) { |
peah | 66085be | 2015-12-16 02:02:20 -0800 | [diff] [blame] | 383 | WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
aluebs | b031955 | 2016-03-17 20:39:53 -0700 | [diff] [blame] | 384 | "AudioProcessingModule::ProcessReverseStream() => error"); |
nisse | eb4ca4e | 2017-01-12 02:24:27 -0800 | [diff] [blame] | 385 | RTC_NOTREACHED(); |
peah | 66085be | 2015-12-16 02:02:20 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 388 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 389 | return 0; |
| 390 | } |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 391 | } // namespace voe |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 392 | } // namespace webrtc |