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