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 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 AudioMixer::AudioMixer(uint32_t instanceId) | 72 AudioMixer::AudioMixer(uint32_t instanceId) |
73 : _mixerModule(*NewAudioConferenceMixer::Create(instanceId)), | 73 : _mixerModule(*NewAudioConferenceMixer::Create(instanceId)), |
74 _audioLevel(), | 74 _audioLevel(), |
75 _instanceId(instanceId), | 75 _instanceId(instanceId), |
76 _externalMediaCallbackPtr(NULL), | 76 _externalMediaCallbackPtr(NULL), |
77 _externalMedia(false), | 77 _externalMedia(false), |
78 _panLeft(1.0f), | 78 _panLeft(1.0f), |
79 _panRight(1.0f), | 79 _panRight(1.0f), |
80 _mixingFrequencyHz(8000), | 80 _mixingFrequencyHz(8000), |
81 _outputFileRecorderPtr(NULL), | |
82 _outputFileRecording(false) { | 81 _outputFileRecording(false) { |
83 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 82 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
84 "AudioMixer::AudioMixer() - ctor"); | 83 "AudioMixer::AudioMixer() - ctor"); |
85 } | 84 } |
86 | 85 |
87 void AudioMixer::Destroy(AudioMixer*& mixer) { | 86 void AudioMixer::Destroy(AudioMixer*& mixer) { |
88 if (mixer) { | 87 if (mixer) { |
89 delete mixer; | 88 delete mixer; |
90 mixer = NULL; | 89 mixer = NULL; |
91 } | 90 } |
92 } | 91 } |
93 | 92 |
94 AudioMixer::~AudioMixer() { | 93 AudioMixer::~AudioMixer() { |
95 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), | 94 WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, -1), |
96 "AudioMixer::~AudioMixer() - dtor"); | 95 "AudioMixer::~AudioMixer() - dtor"); |
97 if (_externalMedia) { | 96 if (_externalMedia) { |
98 DeRegisterExternalMediaProcessing(); | 97 DeRegisterExternalMediaProcessing(); |
99 } | 98 } |
100 { | 99 { |
101 rtc::CritScope cs(&_fileCritSect); | 100 rtc::CritScope cs(&_fileCritSect); |
102 if (_outputFileRecorderPtr) { | 101 if (_outputFileRecorderPtr) { |
103 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); | 102 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
104 _outputFileRecorderPtr->StopRecording(); | 103 _outputFileRecorderPtr->StopRecording(); |
105 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | |
106 _outputFileRecorderPtr = NULL; | |
107 } | 104 } |
108 } | 105 } |
109 delete &_mixerModule; | 106 delete &_mixerModule; |
110 } | 107 } |
111 | 108 |
112 int32_t AudioMixer::SetEngineInformation(voe::Statistics& engineStatistics) { | 109 int32_t AudioMixer::SetEngineInformation(voe::Statistics& engineStatistics) { |
113 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 110 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
114 "AudioMixer::SetEngineInformation()"); | 111 "AudioMixer::SetEngineInformation()"); |
115 _engineStatisticsPtr = &engineStatistics; | 112 _engineStatisticsPtr = &engineStatistics; |
116 return 0; | 113 return 0; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || | 216 } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || |
220 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || | 217 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || |
221 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { | 218 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { |
222 format = kFileFormatWavFile; | 219 format = kFileFormatWavFile; |
223 } else { | 220 } else { |
224 format = kFileFormatCompressedFile; | 221 format = kFileFormatCompressedFile; |
225 } | 222 } |
226 | 223 |
227 rtc::CritScope cs(&_fileCritSect); | 224 rtc::CritScope cs(&_fileCritSect); |
228 | 225 |
229 // Destroy the old instance | |
230 if (_outputFileRecorderPtr) { | 226 if (_outputFileRecorderPtr) { |
231 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); | 227 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
232 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | |
233 _outputFileRecorderPtr = NULL; | |
234 } | 228 } |
235 | 229 |
236 _outputFileRecorderPtr = | 230 _outputFileRecorderPtr = |
237 FileRecorder::CreateFileRecorder(_instanceId, (const FileFormats)format); | 231 FileRecorder::CreateFileRecorder(_instanceId, (const FileFormats)format); |
238 if (_outputFileRecorderPtr == NULL) { | 232 if (_outputFileRecorderPtr == NULL) { |
239 _engineStatisticsPtr->SetLastError( | 233 _engineStatisticsPtr->SetLastError( |
240 VE_INVALID_ARGUMENT, kTraceError, | 234 VE_INVALID_ARGUMENT, kTraceError, |
241 "StartRecordingPlayout() fileRecorder format isnot correct"); | 235 "StartRecordingPlayout() fileRecorder format isnot correct"); |
242 return -1; | 236 return -1; |
243 } | 237 } |
244 | 238 |
245 if (_outputFileRecorderPtr->StartRecordingAudioFile( | 239 if (_outputFileRecorderPtr->StartRecordingAudioFile( |
246 fileName, (const CodecInst&)*codecInst, notificationTime) != 0) { | 240 fileName, (const CodecInst&)*codecInst, notificationTime) != 0) { |
247 _engineStatisticsPtr->SetLastError( | 241 _engineStatisticsPtr->SetLastError( |
248 VE_BAD_FILE, kTraceError, | 242 VE_BAD_FILE, kTraceError, |
249 "StartRecordingAudioFile() failed to start file recording"); | 243 "StartRecordingAudioFile() failed to start file recording"); |
250 _outputFileRecorderPtr->StopRecording(); | 244 _outputFileRecorderPtr->StopRecording(); |
251 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | 245 _outputFileRecorderPtr.reset(); |
252 _outputFileRecorderPtr = NULL; | |
253 return -1; | 246 return -1; |
254 } | 247 } |
255 _outputFileRecorderPtr->RegisterModuleFileCallback(this); | 248 _outputFileRecorderPtr->RegisterModuleFileCallback(this); |
256 _outputFileRecording = true; | 249 _outputFileRecording = true; |
257 | 250 |
258 return 0; | 251 return 0; |
259 } | 252 } |
260 | 253 |
261 int AudioMixer::StartRecordingPlayout(OutStream* stream, | 254 int AudioMixer::StartRecordingPlayout(OutStream* stream, |
262 const CodecInst* codecInst) { | 255 const CodecInst* codecInst) { |
(...skipping 22 matching lines...) Expand all Loading... |
285 } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || | 278 } else if ((STR_CASE_CMP(codecInst->plname, "L16") == 0) || |
286 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || | 279 (STR_CASE_CMP(codecInst->plname, "PCMU") == 0) || |
287 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { | 280 (STR_CASE_CMP(codecInst->plname, "PCMA") == 0)) { |
288 format = kFileFormatWavFile; | 281 format = kFileFormatWavFile; |
289 } else { | 282 } else { |
290 format = kFileFormatCompressedFile; | 283 format = kFileFormatCompressedFile; |
291 } | 284 } |
292 | 285 |
293 rtc::CritScope cs(&_fileCritSect); | 286 rtc::CritScope cs(&_fileCritSect); |
294 | 287 |
295 // Destroy the old instance | |
296 if (_outputFileRecorderPtr) { | 288 if (_outputFileRecorderPtr) { |
297 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); | 289 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
298 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | |
299 _outputFileRecorderPtr = NULL; | |
300 } | 290 } |
301 | 291 |
302 _outputFileRecorderPtr = | 292 _outputFileRecorderPtr = |
303 FileRecorder::CreateFileRecorder(_instanceId, (const FileFormats)format); | 293 FileRecorder::CreateFileRecorder(_instanceId, (const FileFormats)format); |
304 if (_outputFileRecorderPtr == NULL) { | 294 if (_outputFileRecorderPtr == NULL) { |
305 _engineStatisticsPtr->SetLastError( | 295 _engineStatisticsPtr->SetLastError( |
306 VE_INVALID_ARGUMENT, kTraceError, | 296 VE_INVALID_ARGUMENT, kTraceError, |
307 "StartRecordingPlayout() fileRecorder format isnot correct"); | 297 "StartRecordingPlayout() fileRecorder format isnot correct"); |
308 return -1; | 298 return -1; |
309 } | 299 } |
310 | 300 |
311 if (_outputFileRecorderPtr->StartRecordingAudioFile(*stream, *codecInst, | 301 if (_outputFileRecorderPtr->StartRecordingAudioFile(*stream, *codecInst, |
312 notificationTime) != 0) { | 302 notificationTime) != 0) { |
313 _engineStatisticsPtr->SetLastError( | 303 _engineStatisticsPtr->SetLastError( |
314 VE_BAD_FILE, kTraceError, | 304 VE_BAD_FILE, kTraceError, |
315 "StartRecordingAudioFile() failed to start file recording"); | 305 "StartRecordingAudioFile() failed to start file recording"); |
316 _outputFileRecorderPtr->StopRecording(); | 306 _outputFileRecorderPtr->StopRecording(); |
317 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | 307 _outputFileRecorderPtr.reset(); |
318 _outputFileRecorderPtr = NULL; | |
319 return -1; | 308 return -1; |
320 } | 309 } |
321 | 310 |
322 _outputFileRecorderPtr->RegisterModuleFileCallback(this); | 311 _outputFileRecorderPtr->RegisterModuleFileCallback(this); |
323 _outputFileRecording = true; | 312 _outputFileRecording = true; |
324 | 313 |
325 return 0; | 314 return 0; |
326 } | 315 } |
327 | 316 |
328 int AudioMixer::StopRecordingPlayout() { | 317 int AudioMixer::StopRecordingPlayout() { |
329 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 318 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
330 "AudioMixer::StopRecordingPlayout()"); | 319 "AudioMixer::StopRecordingPlayout()"); |
331 | 320 |
332 if (!_outputFileRecording) { | 321 if (!_outputFileRecording) { |
333 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), | 322 WEBRTC_TRACE(kTraceError, kTraceVoice, VoEId(_instanceId, -1), |
334 "StopRecordingPlayout() file isnot recording"); | 323 "StopRecordingPlayout() file isnot recording"); |
335 return -1; | 324 return -1; |
336 } | 325 } |
337 | 326 |
338 rtc::CritScope cs(&_fileCritSect); | 327 rtc::CritScope cs(&_fileCritSect); |
339 | 328 |
340 if (_outputFileRecorderPtr->StopRecording() != 0) { | 329 if (_outputFileRecorderPtr->StopRecording() != 0) { |
341 _engineStatisticsPtr->SetLastError( | 330 _engineStatisticsPtr->SetLastError( |
342 VE_STOP_RECORDING_FAILED, kTraceError, | 331 VE_STOP_RECORDING_FAILED, kTraceError, |
343 "StopRecording(), could not stop recording"); | 332 "StopRecording(), could not stop recording"); |
344 return -1; | 333 return -1; |
345 } | 334 } |
346 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); | 335 _outputFileRecorderPtr->RegisterModuleFileCallback(NULL); |
347 FileRecorder::DestroyFileRecorder(_outputFileRecorderPtr); | 336 _outputFileRecorderPtr.reset(); |
348 _outputFileRecorderPtr = NULL; | |
349 _outputFileRecording = false; | 337 _outputFileRecording = false; |
350 | 338 |
351 return 0; | 339 return 0; |
352 } | 340 } |
353 | 341 |
354 int AudioMixer::GetMixedAudio(int sample_rate_hz, | 342 int AudioMixer::GetMixedAudio(int sample_rate_hz, |
355 size_t num_channels, | 343 size_t num_channels, |
356 AudioFrame* frame) { | 344 AudioFrame* frame) { |
357 WEBRTC_TRACE( | 345 WEBRTC_TRACE( |
358 kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 346 kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } | 404 } |
417 } | 405 } |
418 | 406 |
419 // --- Measure audio level (0-9) for the combined signal | 407 // --- Measure audio level (0-9) for the combined signal |
420 _audioLevel.ComputeLevel(_audioFrame); | 408 _audioLevel.ComputeLevel(_audioFrame); |
421 | 409 |
422 return 0; | 410 return 0; |
423 } | 411 } |
424 } // namespace voe | 412 } // namespace voe |
425 } // namespace webrtc | 413 } // namespace webrtc |
OLD | NEW |