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 282 matching lines...) Loading... |
293 TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) | 293 TransmitMixer::SetAudioProcessingModule(AudioProcessing* audioProcessingModule) |
294 { | 294 { |
295 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), | 295 WEBRTC_TRACE(kTraceInfo, kTraceVoice, VoEId(_instanceId, -1), |
296 "TransmitMixer::SetAudioProcessingModule(" | 296 "TransmitMixer::SetAudioProcessingModule(" |
297 "audioProcessingModule=0x%x)", | 297 "audioProcessingModule=0x%x)", |
298 audioProcessingModule); | 298 audioProcessingModule); |
299 audioproc_ = audioProcessingModule; | 299 audioproc_ = audioProcessingModule; |
300 return 0; | 300 return 0; |
301 } | 301 } |
302 | 302 |
303 void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, int* max_channels) { | 303 void TransmitMixer::GetSendCodecInfo(int* max_sample_rate, |
| 304 size_t* max_channels) { |
304 *max_sample_rate = 8000; | 305 *max_sample_rate = 8000; |
305 *max_channels = 1; | 306 *max_channels = 1; |
306 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid(); | 307 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid(); |
307 it.Increment()) { | 308 it.Increment()) { |
308 Channel* channel = it.GetChannel(); | 309 Channel* channel = it.GetChannel(); |
309 if (channel->Sending()) { | 310 if (channel->Sending()) { |
310 CodecInst codec; | 311 CodecInst codec; |
311 channel->GetSendCodec(codec); | 312 channel->GetSendCodec(codec); |
312 *max_sample_rate = std::max(*max_sample_rate, codec.plfreq); | 313 *max_sample_rate = std::max(*max_sample_rate, codec.plfreq); |
313 *max_channels = std::max(*max_channels, codec.channels); | 314 *max_channels = std::max(*max_channels, codec.channels); |
314 } | 315 } |
315 } | 316 } |
316 } | 317 } |
317 | 318 |
318 int32_t | 319 int32_t |
319 TransmitMixer::PrepareDemux(const void* audioSamples, | 320 TransmitMixer::PrepareDemux(const void* audioSamples, |
320 size_t nSamples, | 321 size_t nSamples, |
321 uint8_t nChannels, | 322 size_t nChannels, |
322 uint32_t samplesPerSec, | 323 uint32_t samplesPerSec, |
323 uint16_t totalDelayMS, | 324 uint16_t totalDelayMS, |
324 int32_t clockDrift, | 325 int32_t clockDrift, |
325 uint16_t currentMicLevel, | 326 uint16_t currentMicLevel, |
326 bool keyPressed) | 327 bool keyPressed) |
327 { | 328 { |
328 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), | 329 WEBRTC_TRACE(kTraceStream, kTraceVoice, VoEId(_instanceId, -1), |
329 "TransmitMixer::PrepareDemux(nSamples=%" PRIuS ", " | 330 "TransmitMixer::PrepareDemux(nSamples=%" PRIuS ", " |
330 "nChannels=%u, samplesPerSec=%u, totalDelayMS=%u, " | 331 "nChannels=%" PRIuS ", samplesPerSec=%u, totalDelayMS=%u, " |
331 "clockDrift=%d, currentMicLevel=%u)", | 332 "clockDrift=%d, currentMicLevel=%u)", |
332 nSamples, nChannels, samplesPerSec, totalDelayMS, clockDrift, | 333 nSamples, nChannels, samplesPerSec, totalDelayMS, clockDrift, |
333 currentMicLevel); | 334 currentMicLevel); |
334 | 335 |
335 // --- Resample input audio and create/store the initial audio frame | 336 // --- Resample input audio and create/store the initial audio frame |
336 GenerateAudioFrame(static_cast<const int16_t*>(audioSamples), | 337 GenerateAudioFrame(static_cast<const int16_t*>(audioSamples), |
337 nSamples, | 338 nSamples, |
338 nChannels, | 339 nChannels, |
339 samplesPerSec); | 340 samplesPerSec); |
340 | 341 |
(...skipping 84 matching lines...) Loading... |
425 { | 426 { |
426 // Demultiplex makes a copy of its input. | 427 // Demultiplex makes a copy of its input. |
427 channelPtr->Demultiplex(_audioFrame); | 428 channelPtr->Demultiplex(_audioFrame); |
428 channelPtr->PrepareEncodeAndSend(_audioFrame.sample_rate_hz_); | 429 channelPtr->PrepareEncodeAndSend(_audioFrame.sample_rate_hz_); |
429 } | 430 } |
430 } | 431 } |
431 return 0; | 432 return 0; |
432 } | 433 } |
433 | 434 |
434 void TransmitMixer::DemuxAndMix(const int voe_channels[], | 435 void TransmitMixer::DemuxAndMix(const int voe_channels[], |
435 int number_of_voe_channels) { | 436 size_t number_of_voe_channels) { |
436 for (int i = 0; i < number_of_voe_channels; ++i) { | 437 for (size_t i = 0; i < number_of_voe_channels; ++i) { |
437 voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); | 438 voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); |
438 voe::Channel* channel_ptr = ch.channel(); | 439 voe::Channel* channel_ptr = ch.channel(); |
439 if (channel_ptr) { | 440 if (channel_ptr) { |
440 if (channel_ptr->Sending()) { | 441 if (channel_ptr->Sending()) { |
441 // Demultiplex makes a copy of its input. | 442 // Demultiplex makes a copy of its input. |
442 channel_ptr->Demultiplex(_audioFrame); | 443 channel_ptr->Demultiplex(_audioFrame); |
443 channel_ptr->PrepareEncodeAndSend(_audioFrame.sample_rate_hz_); | 444 channel_ptr->PrepareEncodeAndSend(_audioFrame.sample_rate_hz_); |
444 } | 445 } |
445 } | 446 } |
446 } | 447 } |
(...skipping 11 matching lines...) Loading... |
458 Channel* channelPtr = it.GetChannel(); | 459 Channel* channelPtr = it.GetChannel(); |
459 if (channelPtr->Sending()) | 460 if (channelPtr->Sending()) |
460 { | 461 { |
461 channelPtr->EncodeAndSend(); | 462 channelPtr->EncodeAndSend(); |
462 } | 463 } |
463 } | 464 } |
464 return 0; | 465 return 0; |
465 } | 466 } |
466 | 467 |
467 void TransmitMixer::EncodeAndSend(const int voe_channels[], | 468 void TransmitMixer::EncodeAndSend(const int voe_channels[], |
468 int number_of_voe_channels) { | 469 size_t number_of_voe_channels) { |
469 for (int i = 0; i < number_of_voe_channels; ++i) { | 470 for (size_t i = 0; i < number_of_voe_channels; ++i) { |
470 voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); | 471 voe::ChannelOwner ch = _channelManagerPtr->GetChannel(voe_channels[i]); |
471 voe::Channel* channel_ptr = ch.channel(); | 472 voe::Channel* channel_ptr = ch.channel(); |
472 if (channel_ptr && channel_ptr->Sending()) | 473 if (channel_ptr && channel_ptr->Sending()) |
473 channel_ptr->EncodeAndSend(); | 474 channel_ptr->EncodeAndSend(); |
474 } | 475 } |
475 } | 476 } |
476 | 477 |
477 uint32_t TransmitMixer::CaptureLevel() const | 478 uint32_t TransmitMixer::CaptureLevel() const |
478 { | 479 { |
479 return _captureLevel; | 480 return _captureLevel; |
(...skipping 211 matching lines...) Loading... |
691 { | 692 { |
692 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), | 693 WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_instanceId, -1), |
693 "StartRecordingMicrophone() is already recording"); | 694 "StartRecordingMicrophone() is already recording"); |
694 return 0; | 695 return 0; |
695 } | 696 } |
696 | 697 |
697 FileFormats format; | 698 FileFormats format; |
698 const uint32_t notificationTime(0); // Not supported in VoE | 699 const uint32_t notificationTime(0); // Not supported in VoE |
699 CodecInst dummyCodec = { 100, "L16", 16000, 320, 1, 320000 }; | 700 CodecInst dummyCodec = { 100, "L16", 16000, 320, 1, 320000 }; |
700 | 701 |
701 if (codecInst != NULL && | 702 if (codecInst != NULL && codecInst->channels > 2) |
702 (codecInst->channels < 0 || codecInst->channels > 2)) | |
703 { | 703 { |
704 _engineStatisticsPtr->SetLastError( | 704 _engineStatisticsPtr->SetLastError( |
705 VE_BAD_ARGUMENT, kTraceError, | 705 VE_BAD_ARGUMENT, kTraceError, |
706 "StartRecordingMicrophone() invalid compression"); | 706 "StartRecordingMicrophone() invalid compression"); |
707 return (-1); | 707 return (-1); |
708 } | 708 } |
709 if (codecInst == NULL) | 709 if (codecInst == NULL) |
710 { | 710 { |
711 format = kFileFormatPcm16kHzFile; | 711 format = kFileFormatPcm16kHzFile; |
712 codecInst = &dummyCodec; | 712 codecInst = &dummyCodec; |
(...skipping 413 matching lines...) Loading... |
1126 } | 1126 } |
1127 | 1127 |
1128 bool TransmitMixer::IsRecordingMic() | 1128 bool TransmitMixer::IsRecordingMic() |
1129 { | 1129 { |
1130 CriticalSectionScoped cs(&_critSect); | 1130 CriticalSectionScoped cs(&_critSect); |
1131 return _fileRecording; | 1131 return _fileRecording; |
1132 } | 1132 } |
1133 | 1133 |
1134 void TransmitMixer::GenerateAudioFrame(const int16_t* audio, | 1134 void TransmitMixer::GenerateAudioFrame(const int16_t* audio, |
1135 size_t samples_per_channel, | 1135 size_t samples_per_channel, |
1136 int num_channels, | 1136 size_t num_channels, |
1137 int sample_rate_hz) { | 1137 int sample_rate_hz) { |
1138 int codec_rate; | 1138 int codec_rate; |
1139 int num_codec_channels; | 1139 size_t num_codec_channels; |
1140 GetSendCodecInfo(&codec_rate, &num_codec_channels); | 1140 GetSendCodecInfo(&codec_rate, &num_codec_channels); |
1141 stereo_codec_ = num_codec_channels == 2; | 1141 stereo_codec_ = num_codec_channels == 2; |
1142 | 1142 |
1143 // We want to process at the lowest rate possible without losing information. | 1143 // We want to process at the lowest rate possible without losing information. |
1144 // Choose the lowest native rate at least equal to the input and codec rates. | 1144 // Choose the lowest native rate at least equal to the input and codec rates. |
1145 const int min_processing_rate = std::min(sample_rate_hz, codec_rate); | 1145 const int min_processing_rate = std::min(sample_rate_hz, codec_rate); |
1146 for (size_t i = 0; i < AudioProcessing::kNumNativeSampleRates; ++i) { | 1146 for (size_t i = 0; i < AudioProcessing::kNumNativeSampleRates; ++i) { |
1147 _audioFrame.sample_rate_hz_ = AudioProcessing::kNativeSampleRatesHz[i]; | 1147 _audioFrame.sample_rate_hz_ = AudioProcessing::kNativeSampleRatesHz[i]; |
1148 if (_audioFrame.sample_rate_hz_ >= min_processing_rate) { | 1148 if (_audioFrame.sample_rate_hz_ >= min_processing_rate) { |
1149 break; | 1149 break; |
(...skipping 183 matching lines...) Loading... |
1333 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { | 1333 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { |
1334 swap_stereo_channels_ = enable; | 1334 swap_stereo_channels_ = enable; |
1335 } | 1335 } |
1336 | 1336 |
1337 bool TransmitMixer::IsStereoChannelSwappingEnabled() { | 1337 bool TransmitMixer::IsStereoChannelSwappingEnabled() { |
1338 return swap_stereo_channels_; | 1338 return swap_stereo_channels_; |
1339 } | 1339 } |
1340 | 1340 |
1341 } // namespace voe | 1341 } // namespace voe |
1342 } // namespace webrtc | 1342 } // namespace webrtc |
OLD | NEW |