Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: webrtc/voice_engine/transmit_mixer.cc

Issue 2984473002: Move total audio energy and duration tracking to AudioLevel and protect with existing critial secti… (Closed)
Patch Set: rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/voice_engine/transmit_mixer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 { 306 {
307 rtc::CritScope cs(&_critSect); 307 rtc::CritScope cs(&_critSect);
308 file_recording = _fileRecording; 308 file_recording = _fileRecording;
309 } 309 }
310 if (file_recording) 310 if (file_recording)
311 { 311 {
312 RecordAudioToFile(_audioFrame.sample_rate_hz_); 312 RecordAudioToFile(_audioFrame.sample_rate_hz_);
313 } 313 }
314 314
315 // --- Measure audio level of speech after all processing. 315 // --- Measure audio level of speech after all processing.
316 _audioLevel.ComputeLevel(_audioFrame);
317
318 // See the description for "totalAudioEnergy" in the WebRTC stats spec
319 // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalau dioenergy)
320 // for an explanation of these formulas. In short, we need a value that can
321 // be used to compute RMS audio levels over different time intervals, by
322 // taking the difference between the results from two getStats calls. To do
323 // this, the value needs to be of units "squared sample value * time".
324 double additional_energy =
325 static_cast<double>(_audioLevel.LevelFullRange()) / INT16_MAX;
326 additional_energy *= additional_energy;
327 double sample_duration = static_cast<double>(nSamples) / samplesPerSec; 316 double sample_duration = static_cast<double>(nSamples) / samplesPerSec;
328 totalInputEnergy_ += additional_energy * sample_duration; 317 _audioLevel.ComputeLevel(_audioFrame, sample_duration);
329 totalInputDuration_ += sample_duration;
330 318
331 return 0; 319 return 0;
332 } 320 }
333 321
334 void TransmitMixer::ProcessAndEncodeAudio() { 322 void TransmitMixer::ProcessAndEncodeAudio() {
335 RTC_DCHECK_GT(_audioFrame.samples_per_channel_, 0); 323 RTC_DCHECK_GT(_audioFrame.samples_per_channel_, 0);
336 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid(); 324 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid();
337 it.Increment()) { 325 it.Increment()) {
338 Channel* const channel = it.GetChannel(); 326 Channel* const channel = it.GetChannel();
339 if (channel->Sending()) { 327 if (channel->Sending()) {
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 return _audioLevel.Level(); 853 return _audioLevel.Level();
866 } 854 }
867 855
868 int16_t TransmitMixer::AudioLevelFullRange() const 856 int16_t TransmitMixer::AudioLevelFullRange() const
869 { 857 {
870 // Speech + file level [0,32767] 858 // Speech + file level [0,32767]
871 return _audioLevel.LevelFullRange(); 859 return _audioLevel.LevelFullRange();
872 } 860 }
873 861
874 double TransmitMixer::GetTotalInputEnergy() const { 862 double TransmitMixer::GetTotalInputEnergy() const {
875 return totalInputEnergy_; 863 return _audioLevel.TotalEnergy();
876 } 864 }
877 865
878 double TransmitMixer::GetTotalInputDuration() const { 866 double TransmitMixer::GetTotalInputDuration() const {
879 return totalInputDuration_; 867 return _audioLevel.TotalDuration();
880 } 868 }
881 869
882 bool TransmitMixer::IsRecordingCall() 870 bool TransmitMixer::IsRecordingCall()
883 { 871 {
884 return _fileCallRecording; 872 return _fileCallRecording;
885 } 873 }
886 874
887 bool TransmitMixer::IsRecordingMic() 875 bool TransmitMixer::IsRecordingMic()
888 { 876 {
889 rtc::CritScope cs(&_critSect); 877 rtc::CritScope cs(&_critSect);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { 1032 void TransmitMixer::EnableStereoChannelSwapping(bool enable) {
1045 swap_stereo_channels_ = enable; 1033 swap_stereo_channels_ = enable;
1046 } 1034 }
1047 1035
1048 bool TransmitMixer::IsStereoChannelSwappingEnabled() { 1036 bool TransmitMixer::IsStereoChannelSwappingEnabled() {
1049 return swap_stereo_channels_; 1037 return swap_stereo_channels_;
1050 } 1038 }
1051 1039
1052 } // namespace voe 1040 } // namespace voe
1053 } // namespace webrtc 1041 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/voice_engine/transmit_mixer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698