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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 if(_timeScheduler.TimeToNextUpdate(timeUntilNextProcess) != 0) { | 182 if(_timeScheduler.TimeToNextUpdate(timeUntilNextProcess) != 0) { |
183 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id, | 183 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id, |
184 "failed in TimeToNextUpdate() call"); | 184 "failed in TimeToNextUpdate() call"); |
185 // Sanity check | 185 // Sanity check |
186 assert(false); | 186 assert(false); |
187 return -1; | 187 return -1; |
188 } | 188 } |
189 return timeUntilNextProcess; | 189 return timeUntilNextProcess; |
190 } | 190 } |
191 | 191 |
192 void AudioConferenceMixerImpl::Process() { | 192 int32_t AudioConferenceMixerImpl::Process() { |
193 size_t remainingParticipantsAllowedToMix = | 193 size_t remainingParticipantsAllowedToMix = |
194 kMaximumAmountOfMixedParticipants; | 194 kMaximumAmountOfMixedParticipants; |
195 { | 195 { |
196 CriticalSectionScoped cs(_crit.get()); | 196 CriticalSectionScoped cs(_crit.get()); |
197 assert(_processCalls == 0); | 197 assert(_processCalls == 0); |
198 _processCalls++; | 198 _processCalls++; |
199 | 199 |
200 // Let the scheduler know that we are running one iteration. | 200 // Let the scheduler know that we are running one iteration. |
201 _timeScheduler.UpdateScheduler(); | 201 _timeScheduler.UpdateScheduler(); |
202 } | 202 } |
(...skipping 12 matching lines...) Expand all Loading... |
215 // TODO(henrike): this is probably more appropriate to do in | 215 // TODO(henrike): this is probably more appropriate to do in |
216 // GetLowestMixingFrequency(). | 216 // GetLowestMixingFrequency(). |
217 if (lowFreq == 12000) { | 217 if (lowFreq == 12000) { |
218 lowFreq = 16000; | 218 lowFreq = 16000; |
219 } else if (lowFreq == 24000) { | 219 } else if (lowFreq == 24000) { |
220 lowFreq = 32000; | 220 lowFreq = 32000; |
221 } | 221 } |
222 if(lowFreq <= 0) { | 222 if(lowFreq <= 0) { |
223 CriticalSectionScoped cs(_crit.get()); | 223 CriticalSectionScoped cs(_crit.get()); |
224 _processCalls--; | 224 _processCalls--; |
225 return; | 225 return 0; |
226 } else { | 226 } else { |
227 switch(lowFreq) { | 227 switch(lowFreq) { |
228 case 8000: | 228 case 8000: |
229 if(OutputFrequency() != kNbInHz) { | 229 if(OutputFrequency() != kNbInHz) { |
230 SetOutputFrequency(kNbInHz); | 230 SetOutputFrequency(kNbInHz); |
231 } | 231 } |
232 break; | 232 break; |
233 case 16000: | 233 case 16000: |
234 if(OutputFrequency() != kWbInHz) { | 234 if(OutputFrequency() != kWbInHz) { |
235 SetOutputFrequency(kWbInHz); | 235 SetOutputFrequency(kWbInHz); |
236 } | 236 } |
237 break; | 237 break; |
238 case 32000: | 238 case 32000: |
239 if(OutputFrequency() != kSwbInHz) { | 239 if(OutputFrequency() != kSwbInHz) { |
240 SetOutputFrequency(kSwbInHz); | 240 SetOutputFrequency(kSwbInHz); |
241 } | 241 } |
242 break; | 242 break; |
243 case 48000: | 243 case 48000: |
244 if(OutputFrequency() != kFbInHz) { | 244 if(OutputFrequency() != kFbInHz) { |
245 SetOutputFrequency(kFbInHz); | 245 SetOutputFrequency(kFbInHz); |
246 } | 246 } |
247 break; | 247 break; |
248 default: | 248 default: |
249 assert(false); | 249 assert(false); |
250 | 250 |
251 CriticalSectionScoped cs(_crit.get()); | 251 CriticalSectionScoped cs(_crit.get()); |
252 _processCalls--; | 252 _processCalls--; |
253 return; | 253 return -1; |
254 } | 254 } |
255 } | 255 } |
256 | 256 |
257 UpdateToMix(&mixList, &rampOutList, &mixedParticipantsMap, | 257 UpdateToMix(&mixList, &rampOutList, &mixedParticipantsMap, |
258 &remainingParticipantsAllowedToMix); | 258 &remainingParticipantsAllowedToMix); |
259 | 259 |
260 GetAdditionalAudio(&additionalFramesList); | 260 GetAdditionalAudio(&additionalFramesList); |
261 UpdateMixedStatus(mixedParticipantsMap); | 261 UpdateMixedStatus(mixedParticipantsMap); |
262 } | 262 } |
263 | 263 |
264 // Get an AudioFrame for mixing from the memory pool. | 264 // Get an AudioFrame for mixing from the memory pool. |
265 AudioFrame* mixedAudio = NULL; | 265 AudioFrame* mixedAudio = NULL; |
266 if(_audioFramePool->PopMemory(mixedAudio) == -1) { | 266 if(_audioFramePool->PopMemory(mixedAudio) == -1) { |
267 WEBRTC_TRACE(kTraceMemory, kTraceAudioMixerServer, _id, | 267 WEBRTC_TRACE(kTraceMemory, kTraceAudioMixerServer, _id, |
268 "failed PopMemory() call"); | 268 "failed PopMemory() call"); |
269 assert(false); | 269 assert(false); |
270 return; | 270 return -1; |
271 } | 271 } |
272 | 272 |
| 273 int retval = 0; |
273 { | 274 { |
274 CriticalSectionScoped cs(_crit.get()); | 275 CriticalSectionScoped cs(_crit.get()); |
275 | 276 |
276 // TODO(henrike): it might be better to decide the number of channels | 277 // TODO(henrike): it might be better to decide the number of channels |
277 // with an API instead of dynamically. | 278 // with an API instead of dynamically. |
278 | 279 |
279 // Find the max channels over all mixing lists. | 280 // Find the max channels over all mixing lists. |
280 const size_t num_mixed_channels = std::max(MaxNumChannels(&mixList), | 281 const size_t num_mixed_channels = std::max(MaxNumChannels(&mixList), |
281 std::max(MaxNumChannels(&additionalFramesList), | 282 std::max(MaxNumChannels(&additionalFramesList), |
282 MaxNumChannels(&rampOutList))); | 283 MaxNumChannels(&rampOutList))); |
(...skipping 13 matching lines...) Expand all Loading... |
296 MixFromList(mixedAudio, mixList); | 297 MixFromList(mixedAudio, mixList); |
297 MixAnonomouslyFromList(mixedAudio, additionalFramesList); | 298 MixAnonomouslyFromList(mixedAudio, additionalFramesList); |
298 MixAnonomouslyFromList(mixedAudio, rampOutList); | 299 MixAnonomouslyFromList(mixedAudio, rampOutList); |
299 | 300 |
300 if(mixedAudio->samples_per_channel_ == 0) { | 301 if(mixedAudio->samples_per_channel_ == 0) { |
301 // Nothing was mixed, set the audio samples to silence. | 302 // Nothing was mixed, set the audio samples to silence. |
302 mixedAudio->samples_per_channel_ = _sampleSize; | 303 mixedAudio->samples_per_channel_ = _sampleSize; |
303 mixedAudio->Mute(); | 304 mixedAudio->Mute(); |
304 } else { | 305 } else { |
305 // Only call the limiter if we have something to mix. | 306 // Only call the limiter if we have something to mix. |
306 LimitMixedAudio(mixedAudio); | 307 if(!LimitMixedAudio(mixedAudio)) |
| 308 retval = -1; |
307 } | 309 } |
308 } | 310 } |
309 | 311 |
310 { | 312 { |
311 CriticalSectionScoped cs(_cbCrit.get()); | 313 CriticalSectionScoped cs(_cbCrit.get()); |
312 if(_mixReceiver != NULL) { | 314 if(_mixReceiver != NULL) { |
313 const AudioFrame** dummy = NULL; | 315 const AudioFrame** dummy = NULL; |
314 _mixReceiver->NewMixedAudio( | 316 _mixReceiver->NewMixedAudio( |
315 _id, | 317 _id, |
316 *mixedAudio, | 318 *mixedAudio, |
317 dummy, | 319 dummy, |
318 0); | 320 0); |
319 } | 321 } |
320 } | 322 } |
321 | 323 |
322 // Reclaim all outstanding memory. | 324 // Reclaim all outstanding memory. |
323 _audioFramePool->PushMemory(mixedAudio); | 325 _audioFramePool->PushMemory(mixedAudio); |
324 ClearAudioFrameList(&mixList); | 326 ClearAudioFrameList(&mixList); |
325 ClearAudioFrameList(&rampOutList); | 327 ClearAudioFrameList(&rampOutList); |
326 ClearAudioFrameList(&additionalFramesList); | 328 ClearAudioFrameList(&additionalFramesList); |
327 { | 329 { |
328 CriticalSectionScoped cs(_crit.get()); | 330 CriticalSectionScoped cs(_crit.get()); |
329 _processCalls--; | 331 _processCalls--; |
330 } | 332 } |
331 return; | 333 return retval; |
332 } | 334 } |
333 | 335 |
334 int32_t AudioConferenceMixerImpl::RegisterMixedStreamCallback( | 336 int32_t AudioConferenceMixerImpl::RegisterMixedStreamCallback( |
335 AudioMixerOutputReceiver* mixReceiver) { | 337 AudioMixerOutputReceiver* mixReceiver) { |
336 CriticalSectionScoped cs(_cbCrit.get()); | 338 CriticalSectionScoped cs(_cbCrit.get()); |
337 if(_mixReceiver != NULL) { | 339 if(_mixReceiver != NULL) { |
338 return -1; | 340 return -1; |
339 } | 341 } |
340 _mixReceiver = mixReceiver; | 342 _mixReceiver = mixReceiver; |
341 return 0; | 343 return 0; |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 | 906 |
905 if(error != _limiter->kNoError) { | 907 if(error != _limiter->kNoError) { |
906 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id, | 908 WEBRTC_TRACE(kTraceError, kTraceAudioMixerServer, _id, |
907 "Error from AudioProcessing: %d", error); | 909 "Error from AudioProcessing: %d", error); |
908 assert(false); | 910 assert(false); |
909 return false; | 911 return false; |
910 } | 912 } |
911 return true; | 913 return true; |
912 } | 914 } |
913 } // namespace webrtc | 915 } // namespace webrtc |
OLD | NEW |