| 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 |
| 11 #include "webrtc/voice_engine/voe_base_impl.h" | 11 #include "webrtc/voice_engine/voe_base_impl.h" |
| 12 | 12 |
| 13 #include "webrtc/base/format_macros.h" |
| 13 #include "webrtc/common.h" | 14 #include "webrtc/common.h" |
| 14 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 15 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
| 15 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" | 16 #include "webrtc/modules/audio_coding/main/interface/audio_coding_module.h" |
| 16 #include "webrtc/modules/audio_device/audio_device_impl.h" | 17 #include "webrtc/modules/audio_device/audio_device_impl.h" |
| 17 #include "webrtc/modules/audio_processing/include/audio_processing.h" | 18 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 19 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 19 #include "webrtc/system_wrappers/interface/file_wrapper.h" | 20 #include "webrtc/system_wrappers/interface/file_wrapper.h" |
| 20 #include "webrtc/system_wrappers/interface/logging.h" | 21 #include "webrtc/system_wrappers/interface/logging.h" |
| 21 #include "webrtc/voice_engine/channel.h" | 22 #include "webrtc/voice_engine/channel.h" |
| 22 #include "webrtc/voice_engine/include/voe_errors.h" | 23 #include "webrtc/voice_engine/include/voe_errors.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 warningCode = VE_RUNTIME_PLAY_WARNING; | 73 warningCode = VE_RUNTIME_PLAY_WARNING; |
| 73 LOG_F(LS_WARNING) << "VE_RUNTIME_PLAY_WARNING"; | 74 LOG_F(LS_WARNING) << "VE_RUNTIME_PLAY_WARNING"; |
| 74 } | 75 } |
| 75 if (voiceEngineObserverPtr_) { | 76 if (voiceEngineObserverPtr_) { |
| 76 // Deliver callback (-1 <=> no channel dependency) | 77 // Deliver callback (-1 <=> no channel dependency) |
| 77 voiceEngineObserverPtr_->CallbackOnError(-1, warningCode); | 78 voiceEngineObserverPtr_->CallbackOnError(-1, warningCode); |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 | 81 |
| 81 int32_t VoEBaseImpl::RecordedDataIsAvailable( | 82 int32_t VoEBaseImpl::RecordedDataIsAvailable( |
| 82 const void* audioSamples, uint32_t nSamples, uint8_t nBytesPerSample, | 83 const void* audioSamples, size_t nSamples, size_t nBytesPerSample, |
| 83 uint8_t nChannels, uint32_t samplesPerSec, uint32_t totalDelayMS, | 84 uint8_t nChannels, uint32_t samplesPerSec, uint32_t totalDelayMS, |
| 84 int32_t clockDrift, uint32_t micLevel, bool keyPressed, | 85 int32_t clockDrift, uint32_t micLevel, bool keyPressed, |
| 85 uint32_t& newMicLevel) { | 86 uint32_t& newMicLevel) { |
| 86 newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM( | 87 newMicLevel = static_cast<uint32_t>(ProcessRecordedDataWithAPM( |
| 87 nullptr, 0, audioSamples, samplesPerSec, nChannels, nSamples, | 88 nullptr, 0, audioSamples, samplesPerSec, nChannels, nSamples, |
| 88 totalDelayMS, clockDrift, micLevel, keyPressed)); | 89 totalDelayMS, clockDrift, micLevel, keyPressed)); |
| 89 return 0; | 90 return 0; |
| 90 } | 91 } |
| 91 | 92 |
| 92 int32_t VoEBaseImpl::NeedMorePlayData(uint32_t nSamples, | 93 int32_t VoEBaseImpl::NeedMorePlayData(size_t nSamples, |
| 93 uint8_t nBytesPerSample, | 94 size_t nBytesPerSample, |
| 94 uint8_t nChannels, uint32_t samplesPerSec, | 95 uint8_t nChannels, uint32_t samplesPerSec, |
| 95 void* audioSamples, uint32_t& nSamplesOut, | 96 void* audioSamples, size_t& nSamplesOut, |
| 96 int64_t* elapsed_time_ms, | 97 int64_t* elapsed_time_ms, |
| 97 int64_t* ntp_time_ms) { | 98 int64_t* ntp_time_ms) { |
| 98 GetPlayoutData(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), | 99 GetPlayoutData(static_cast<int>(samplesPerSec), static_cast<int>(nChannels), |
| 99 static_cast<int>(nSamples), true, audioSamples, | 100 nSamples, true, audioSamples, |
| 100 elapsed_time_ms, ntp_time_ms); | 101 elapsed_time_ms, ntp_time_ms); |
| 101 nSamplesOut = audioFrame_.samples_per_channel_; | 102 nSamplesOut = audioFrame_.samples_per_channel_; |
| 102 return 0; | 103 return 0; |
| 103 } | 104 } |
| 104 | 105 |
| 105 int VoEBaseImpl::OnDataAvailable(const int voe_channels[], | 106 int VoEBaseImpl::OnDataAvailable(const int voe_channels[], |
| 106 int number_of_voe_channels, | 107 int number_of_voe_channels, |
| 107 const int16_t* audio_data, int sample_rate, | 108 const int16_t* audio_data, int sample_rate, |
| 108 int number_of_channels, int number_of_frames, | 109 int number_of_channels, |
| 110 size_t number_of_frames, |
| 109 int audio_delay_milliseconds, int volume, | 111 int audio_delay_milliseconds, int volume, |
| 110 bool key_pressed, bool need_audio_processing) { | 112 bool key_pressed, bool need_audio_processing) { |
| 111 if (number_of_voe_channels == 0) return 0; | 113 if (number_of_voe_channels == 0) return 0; |
| 112 | 114 |
| 113 if (need_audio_processing) { | 115 if (need_audio_processing) { |
| 114 return ProcessRecordedDataWithAPM( | 116 return ProcessRecordedDataWithAPM( |
| 115 voe_channels, number_of_voe_channels, audio_data, sample_rate, | 117 voe_channels, number_of_voe_channels, audio_data, sample_rate, |
| 116 number_of_channels, number_of_frames, audio_delay_milliseconds, 0, | 118 number_of_channels, number_of_frames, audio_delay_milliseconds, 0, |
| 117 volume, key_pressed); | 119 volume, key_pressed); |
| 118 } | 120 } |
| 119 | 121 |
| 120 // No need to go through the APM, demultiplex the data to each VoE channel, | 122 // No need to go through the APM, demultiplex the data to each VoE channel, |
| 121 // encode and send to the network. | 123 // encode and send to the network. |
| 122 for (int i = 0; i < number_of_voe_channels; ++i) { | 124 for (int i = 0; i < number_of_voe_channels; ++i) { |
| 123 // TODO(ajm): In the case where multiple channels are using the same codec | 125 // TODO(ajm): In the case where multiple channels are using the same codec |
| 124 // rate, this path needlessly does extra conversions. We should convert once | 126 // rate, this path needlessly does extra conversions. We should convert once |
| 125 // and share between channels. | 127 // and share between channels. |
| 126 PushCaptureData(voe_channels[i], audio_data, 16, sample_rate, | 128 PushCaptureData(voe_channels[i], audio_data, 16, sample_rate, |
| 127 number_of_channels, number_of_frames); | 129 number_of_channels, number_of_frames); |
| 128 } | 130 } |
| 129 | 131 |
| 130 // Return 0 to indicate no need to change the volume. | 132 // Return 0 to indicate no need to change the volume. |
| 131 return 0; | 133 return 0; |
| 132 } | 134 } |
| 133 | 135 |
| 134 void VoEBaseImpl::OnData(int voe_channel, const void* audio_data, | 136 void VoEBaseImpl::OnData(int voe_channel, const void* audio_data, |
| 135 int bits_per_sample, int sample_rate, | 137 int bits_per_sample, int sample_rate, |
| 136 int number_of_channels, int number_of_frames) { | 138 int number_of_channels, size_t number_of_frames) { |
| 137 PushCaptureData(voe_channel, audio_data, bits_per_sample, sample_rate, | 139 PushCaptureData(voe_channel, audio_data, bits_per_sample, sample_rate, |
| 138 number_of_channels, number_of_frames); | 140 number_of_channels, number_of_frames); |
| 139 } | 141 } |
| 140 | 142 |
| 141 void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, | 143 void VoEBaseImpl::PushCaptureData(int voe_channel, const void* audio_data, |
| 142 int bits_per_sample, int sample_rate, | 144 int bits_per_sample, int sample_rate, |
| 143 int number_of_channels, | 145 int number_of_channels, |
| 144 int number_of_frames) { | 146 size_t number_of_frames) { |
| 145 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); | 147 voe::ChannelOwner ch = shared_->channel_manager().GetChannel(voe_channel); |
| 146 voe::Channel* channel_ptr = ch.channel(); | 148 voe::Channel* channel_ptr = ch.channel(); |
| 147 if (!channel_ptr) return; | 149 if (!channel_ptr) return; |
| 148 | 150 |
| 149 if (channel_ptr->Sending()) { | 151 if (channel_ptr->Sending()) { |
| 150 channel_ptr->Demultiplex(static_cast<const int16_t*>(audio_data), | 152 channel_ptr->Demultiplex(static_cast<const int16_t*>(audio_data), |
| 151 sample_rate, number_of_frames, number_of_channels); | 153 sample_rate, number_of_frames, number_of_channels); |
| 152 channel_ptr->PrepareEncodeAndSend(sample_rate); | 154 channel_ptr->PrepareEncodeAndSend(sample_rate); |
| 153 channel_ptr->EncodeAndSend(); | 155 channel_ptr->EncodeAndSend(); |
| 154 } | 156 } |
| 155 } | 157 } |
| 156 | 158 |
| 157 void VoEBaseImpl::PullRenderData(int bits_per_sample, int sample_rate, | 159 void VoEBaseImpl::PullRenderData(int bits_per_sample, |
| 158 int number_of_channels, int number_of_frames, | 160 int sample_rate, |
| 161 int number_of_channels, |
| 162 size_t number_of_frames, |
| 159 void* audio_data, int64_t* elapsed_time_ms, | 163 void* audio_data, int64_t* elapsed_time_ms, |
| 160 int64_t* ntp_time_ms) { | 164 int64_t* ntp_time_ms) { |
| 161 assert(bits_per_sample == 16); | 165 assert(bits_per_sample == 16); |
| 162 assert(number_of_frames == static_cast<int>(sample_rate / 100)); | 166 assert(number_of_frames == static_cast<size_t>(sample_rate / 100)); |
| 163 | 167 |
| 164 GetPlayoutData(sample_rate, number_of_channels, number_of_frames, false, | 168 GetPlayoutData(sample_rate, number_of_channels, number_of_frames, false, |
| 165 audio_data, elapsed_time_ms, ntp_time_ms); | 169 audio_data, elapsed_time_ms, ntp_time_ms); |
| 166 } | 170 } |
| 167 | 171 |
| 168 int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { | 172 int VoEBaseImpl::RegisterVoiceEngineObserver(VoiceEngineObserver& observer) { |
| 169 CriticalSectionScoped cs(&callbackCritSect_); | 173 CriticalSectionScoped cs(&callbackCritSect_); |
| 170 if (voiceEngineObserverPtr_) { | 174 if (voiceEngineObserverPtr_) { |
| 171 shared_->SetLastError( | 175 shared_->SetLastError( |
| 172 VE_INVALID_OPERATION, kTraceError, | 176 VE_INVALID_OPERATION, kTraceError, |
| (...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 if (shared_->audio_processing()) { | 745 if (shared_->audio_processing()) { |
| 742 shared_->set_audio_processing(nullptr); | 746 shared_->set_audio_processing(nullptr); |
| 743 } | 747 } |
| 744 | 748 |
| 745 return shared_->statistics().SetUnInitialized(); | 749 return shared_->statistics().SetUnInitialized(); |
| 746 } | 750 } |
| 747 | 751 |
| 748 int VoEBaseImpl::ProcessRecordedDataWithAPM( | 752 int VoEBaseImpl::ProcessRecordedDataWithAPM( |
| 749 const int voe_channels[], int number_of_voe_channels, | 753 const int voe_channels[], int number_of_voe_channels, |
| 750 const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, | 754 const void* audio_data, uint32_t sample_rate, uint8_t number_of_channels, |
| 751 uint32_t number_of_frames, uint32_t audio_delay_milliseconds, | 755 size_t number_of_frames, uint32_t audio_delay_milliseconds, |
| 752 int32_t clock_drift, uint32_t volume, bool key_pressed) { | 756 int32_t clock_drift, uint32_t volume, bool key_pressed) { |
| 753 assert(shared_->transmit_mixer() != nullptr); | 757 assert(shared_->transmit_mixer() != nullptr); |
| 754 assert(shared_->audio_device() != nullptr); | 758 assert(shared_->audio_device() != nullptr); |
| 755 | 759 |
| 756 uint32_t max_volume = 0; | 760 uint32_t max_volume = 0; |
| 757 uint16_t voe_mic_level = 0; | 761 uint16_t voe_mic_level = 0; |
| 758 // Check for zero to skip this calculation; the consumer may use this to | 762 // Check for zero to skip this calculation; the consumer may use this to |
| 759 // indicate no volume is available. | 763 // indicate no volume is available. |
| 760 if (volume != 0) { | 764 if (volume != 0) { |
| 761 // Scale from ADM to VoE level range | 765 // Scale from ADM to VoE level range |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 return static_cast<int>((new_voe_mic_level * max_volume + | 810 return static_cast<int>((new_voe_mic_level * max_volume + |
| 807 static_cast<int>(kMaxVolumeLevel / 2)) / | 811 static_cast<int>(kMaxVolumeLevel / 2)) / |
| 808 kMaxVolumeLevel); | 812 kMaxVolumeLevel); |
| 809 } | 813 } |
| 810 | 814 |
| 811 // Return 0 to indicate no change on the volume. | 815 // Return 0 to indicate no change on the volume. |
| 812 return 0; | 816 return 0; |
| 813 } | 817 } |
| 814 | 818 |
| 815 void VoEBaseImpl::GetPlayoutData(int sample_rate, int number_of_channels, | 819 void VoEBaseImpl::GetPlayoutData(int sample_rate, int number_of_channels, |
| 816 int number_of_frames, bool feed_data_to_apm, | 820 size_t number_of_frames, bool feed_data_to_apm, |
| 817 void* audio_data, int64_t* elapsed_time_ms, | 821 void* audio_data, int64_t* elapsed_time_ms, |
| 818 int64_t* ntp_time_ms) { | 822 int64_t* ntp_time_ms) { |
| 819 assert(shared_->output_mixer() != nullptr); | 823 assert(shared_->output_mixer() != nullptr); |
| 820 | 824 |
| 821 // TODO(andrew): if the device is running in mono, we should tell the mixer | 825 // TODO(andrew): if the device is running in mono, we should tell the mixer |
| 822 // here so that it will only request mono from AudioCodingModule. | 826 // here so that it will only request mono from AudioCodingModule. |
| 823 // Perform mixing of all active participants (channel-based mixing) | 827 // Perform mixing of all active participants (channel-based mixing) |
| 824 shared_->output_mixer()->MixActiveChannels(); | 828 shared_->output_mixer()->MixActiveChannels(); |
| 825 | 829 |
| 826 // Additional operations on the combined signal | 830 // Additional operations on the combined signal |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, | 868 shared_->SetLastError(VE_CHANNEL_NOT_VALID, kTraceError, |
| 865 "AssociateSendChannel() failed to locate accociate_send_channel"); | 869 "AssociateSendChannel() failed to locate accociate_send_channel"); |
| 866 return -1; | 870 return -1; |
| 867 } | 871 } |
| 868 | 872 |
| 869 channel_ptr->set_associate_send_channel(ch); | 873 channel_ptr->set_associate_send_channel(ch); |
| 870 return 0; | 874 return 0; |
| 871 } | 875 } |
| 872 | 876 |
| 873 } // namespace webrtc | 877 } // namespace webrtc |
| OLD | NEW |