| Index: webrtc/voice_engine/voe_base_impl.cc
|
| diff --git a/webrtc/voice_engine/voe_base_impl.cc b/webrtc/voice_engine/voe_base_impl.cc
|
| index d1981a4a3a72a55495009f4e9dbcff4c004d7d15..8072cc86d91fed6ffbe8f99598266c4b40b8580c 100644
|
| --- a/webrtc/voice_engine/voe_base_impl.cc
|
| +++ b/webrtc/voice_engine/voe_base_impl.cc
|
| @@ -77,19 +77,66 @@ void VoEBaseImpl::OnWarningIsReported(const WarningCode warning) {
|
| }
|
| }
|
|
|
| -int32_t VoEBaseImpl::RecordedDataIsAvailable(const void* audioSamples,
|
| - const size_t nSamples,
|
| - const size_t nBytesPerSample,
|
| - const size_t nChannels,
|
| - const uint32_t samplesPerSec,
|
| - const uint32_t totalDelayMS,
|
| - const int32_t clockDrift,
|
| - const uint32_t currentMicLevel,
|
| - const bool keyPressed,
|
| - uint32_t& newMicLevel) {
|
| - newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM(
|
| - nullptr, 0, audioSamples, samplesPerSec, nChannels, nSamples,
|
| - totalDelayMS, clockDrift, currentMicLevel, keyPressed));
|
| +int32_t VoEBaseImpl::RecordedDataIsAvailable(
|
| + const void* audio_data,
|
| + const size_t number_of_frames,
|
| + const size_t bytes_per_sample,
|
| + const size_t number_of_channels,
|
| + const uint32_t sample_rate,
|
| + const uint32_t audio_delay_milliseconds,
|
| + const int32_t clock_drift,
|
| + const uint32_t volume,
|
| + const bool key_pressed,
|
| + uint32_t& new_mic_volume) {
|
| + RTC_DCHECK_EQ(2 * number_of_channels, bytes_per_sample);
|
| + RTC_DCHECK(shared_->transmit_mixer() != nullptr);
|
| + RTC_DCHECK(shared_->audio_device() != nullptr);
|
| +
|
| + uint32_t max_volume = 0;
|
| + uint16_t voe_mic_level = 0;
|
| + // Check for zero to skip this calculation; the consumer may use this to
|
| + // indicate no volume is available.
|
| + if (volume != 0) {
|
| + // Scale from ADM to VoE level range
|
| + if (shared_->audio_device()->MaxMicrophoneVolume(&max_volume) == 0) {
|
| + if (max_volume) {
|
| + voe_mic_level = static_cast<uint16_t>(
|
| + (volume * kMaxVolumeLevel + static_cast<int>(max_volume / 2)) /
|
| + max_volume);
|
| + }
|
| + }
|
| + // We learned that on certain systems (e.g Linux) the voe_mic_level
|
| + // can be greater than the maxVolumeLevel therefore
|
| + // we are going to cap the voe_mic_level to the maxVolumeLevel
|
| + // and change the maxVolume to volume if it turns out that
|
| + // the voe_mic_level is indeed greater than the maxVolumeLevel.
|
| + if (voe_mic_level > kMaxVolumeLevel) {
|
| + voe_mic_level = kMaxVolumeLevel;
|
| + max_volume = volume;
|
| + }
|
| + }
|
| +
|
| + // Perform channel-independent operations
|
| + // (APM, mix with file, record to file, mute, etc.)
|
| + shared_->transmit_mixer()->PrepareDemux(
|
| + audio_data, number_of_frames, number_of_channels, sample_rate,
|
| + static_cast<uint16_t>(audio_delay_milliseconds), clock_drift,
|
| + voe_mic_level, key_pressed);
|
| +
|
| + // Copy the audio frame to each sending channel and perform
|
| + // channel-dependent operations (file mixing, mute, etc.), encode and
|
| + // packetize+transmit the RTP packet.
|
| + shared_->transmit_mixer()->ProcessAndEncodeAudio();
|
| +
|
| + // Scale from VoE to ADM level range.
|
| + uint32_t new_voe_mic_level = shared_->transmit_mixer()->CaptureLevel();
|
| + if (new_voe_mic_level != voe_mic_level) {
|
| + // Return the new volume if AGC has changed the volume.
|
| + return static_cast<int>((new_voe_mic_level * max_volume +
|
| + static_cast<int>(kMaxVolumeLevel / 2)) /
|
| + kMaxVolumeLevel);
|
| + }
|
| +
|
| return 0;
|
| }
|
|
|
| @@ -112,14 +159,15 @@ void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data,
|
| size_t number_of_channels,
|
| size_t number_of_frames) {
|
| voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel);
|
| - voe::Channel* channel_ptr = ch.channel();
|
| - if (!channel_ptr) return;
|
| -
|
| - if (channel_ptr->Sending()) {
|
| - channel_ptr->Demultiplex(static_cast<const int16_t*>(audio_data),
|
| - sample_rate, number_of_frames, number_of_channels);
|
| - channel_ptr->PrepareEncodeAndSend(sample_rate);
|
| - channel_ptr->EncodeAndSend();
|
| + voe::Channel* channel = ch.channel();
|
| + if (!channel)
|
| + return;
|
| + if (channel->Sending()) {
|
| + // Send the audio to each channel directly without using the APM in the
|
| + // transmit mixer.
|
| + channel->ProcessAndEncodeAudio(static_cast<const int16_t*>(audio_data),
|
| + sample_rate, number_of_frames,
|
| + number_of_channels);
|
| }
|
| }
|
|
|
| @@ -377,7 +425,8 @@ int VoEBaseImpl::InitializeChannel(voe::ChannelOwner* channel_owner) {
|
| if (channel_owner->channel()->SetEngineInformation(
|
| shared_->statistics(), *shared_->output_mixer(),
|
| *shared_->process_thread(), *shared_->audio_device(),
|
| - voiceEngineObserverPtr_, &callbackCritSect_) != 0) {
|
| + voiceEngineObserverPtr_, &callbackCritSect_,
|
| + shared_->encoder_queue()) != 0) {
|
| shared_->SetLastError(
|
| VE_CHANNEL_NOT_CREATED, kTraceError,
|
| "CreateChannel() failed to associate engine and channel."
|
| @@ -521,10 +570,7 @@ int VoEBaseImpl::StopSend(int channel) {
|
| "StopSend() failed to locate channel");
|
| return -1;
|
| }
|
| - if (channelPtr->StopSend() != 0) {
|
| - LOG_F(LS_WARNING) << "StopSend() failed to stop sending for channel "
|
| - << channel;
|
| - }
|
| + channelPtr->StopSend();
|
| return StopSend();
|
| }
|
|
|
| @@ -648,73 +694,6 @@ int32_t VoEBaseImpl::TerminateInternal() {
|
| return shared_->statistics().SetUnInitialized();
|
| }
|
|
|
| -int VoEBaseImpl::ProcessRecordedDataWithAPM(
|
| - const int voe_channels[], size_t number_of_voe_channels,
|
| - const void* audio_data, uint32_t sample_rate, size_t number_of_channels,
|
| - size_t number_of_frames, uint32_t audio_delay_milliseconds,
|
| - int32_t clock_drift, uint32_t volume, bool key_pressed) {
|
| - assert(shared_->transmit_mixer() != nullptr);
|
| - assert(shared_->audio_device() != nullptr);
|
| -
|
| - uint32_t max_volume = 0;
|
| - uint16_t voe_mic_level = 0;
|
| - // Check for zero to skip this calculation; the consumer may use this to
|
| - // indicate no volume is available.
|
| - if (volume != 0) {
|
| - // Scale from ADM to VoE level range
|
| - if (shared_->audio_device()->MaxMicrophoneVolume(&max_volume) == 0) {
|
| - if (max_volume) {
|
| - voe_mic_level = static_cast<uint16_t>(
|
| - (volume * kMaxVolumeLevel + static_cast<int>(max_volume / 2)) /
|
| - max_volume);
|
| - }
|
| - }
|
| - // We learned that on certain systems (e.g Linux) the voe_mic_level
|
| - // can be greater than the maxVolumeLevel therefore
|
| - // we are going to cap the voe_mic_level to the maxVolumeLevel
|
| - // and change the maxVolume to volume if it turns out that
|
| - // the voe_mic_level is indeed greater than the maxVolumeLevel.
|
| - if (voe_mic_level > kMaxVolumeLevel) {
|
| - voe_mic_level = kMaxVolumeLevel;
|
| - max_volume = volume;
|
| - }
|
| - }
|
| -
|
| - // Perform channel-independent operations
|
| - // (APM, mix with file, record to file, mute, etc.)
|
| - shared_->transmit_mixer()->PrepareDemux(
|
| - audio_data, number_of_frames, number_of_channels, sample_rate,
|
| - static_cast<uint16_t>(audio_delay_milliseconds), clock_drift,
|
| - voe_mic_level, key_pressed);
|
| -
|
| - // Copy the audio frame to each sending channel and perform
|
| - // channel-dependent operations (file mixing, mute, etc.), encode and
|
| - // packetize+transmit the RTP packet. When |number_of_voe_channels| == 0,
|
| - // do the operations on all the existing VoE channels; otherwise the
|
| - // operations will be done on specific channels.
|
| - if (number_of_voe_channels == 0) {
|
| - shared_->transmit_mixer()->DemuxAndMix();
|
| - shared_->transmit_mixer()->EncodeAndSend();
|
| - } else {
|
| - shared_->transmit_mixer()->DemuxAndMix(voe_channels,
|
| - number_of_voe_channels);
|
| - shared_->transmit_mixer()->EncodeAndSend(voe_channels,
|
| - number_of_voe_channels);
|
| - }
|
| -
|
| - // Scale from VoE to ADM level range.
|
| - uint32_t new_voe_mic_level = shared_->transmit_mixer()->CaptureLevel();
|
| - if (new_voe_mic_level != voe_mic_level) {
|
| - // Return the new volume if AGC has changed the volume.
|
| - return static_cast<int>((new_voe_mic_level * max_volume +
|
| - static_cast<int>(kMaxVolumeLevel / 2)) /
|
| - kMaxVolumeLevel);
|
| - }
|
| -
|
| - // Return 0 to indicate no change on the volume.
|
| - return 0;
|
| -}
|
| -
|
| void VoEBaseImpl::GetPlayoutData(int sample_rate, size_t number_of_channels,
|
| size_t number_of_frames, bool feed_data_to_apm,
|
| void* audio_data, int64_t* elapsed_time_ms,
|
|
|