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

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

Issue 2964593002: Adding stats that can be used to compute output audio levels. (Closed)
Patch Set: Add test coverage in AudioSendStreamTest. 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 rtc::CritScope cs(&_critSect); 301 rtc::CritScope cs(&_critSect);
302 file_recording = _fileRecording; 302 file_recording = _fileRecording;
303 } 303 }
304 if (file_recording) 304 if (file_recording)
305 { 305 {
306 RecordAudioToFile(_audioFrame.sample_rate_hz_); 306 RecordAudioToFile(_audioFrame.sample_rate_hz_);
307 } 307 }
308 308
309 // --- Measure audio level of speech after all processing. 309 // --- Measure audio level of speech after all processing.
310 _audioLevel.ComputeLevel(_audioFrame); 310 _audioLevel.ComputeLevel(_audioFrame);
311
312 // See the description for "totalAudioEnergy" in the WebRTC stats spec
313 // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalau dioenergy)
314 // for an explanation of these formulas. In short, we need a value that can
315 // be used to compute RMS audio levels over different time intervals, by
316 // taking the difference between the results from two getStats calls. To do
317 // this, the value needs to be of units "squared sample value * time".
318 double additional_energy =
319 static_cast<double>(_audioLevel.LevelFullRange()) / INT16_MAX;
320 additional_energy *= additional_energy;
321 double sample_duration = static_cast<double>(nSamples) / samplesPerSec;
322 totalInputEnergy_ += additional_energy * sample_duration;
323 totalInputDuration_ += sample_duration;
324
311 return 0; 325 return 0;
312 } 326 }
313 327
314 void TransmitMixer::ProcessAndEncodeAudio() { 328 void TransmitMixer::ProcessAndEncodeAudio() {
315 RTC_DCHECK_GT(_audioFrame.samples_per_channel_, 0); 329 RTC_DCHECK_GT(_audioFrame.samples_per_channel_, 0);
316 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid(); 330 for (ChannelManager::Iterator it(_channelManagerPtr); it.IsValid();
317 it.Increment()) { 331 it.Increment()) {
318 Channel* const channel = it.GetChannel(); 332 Channel* const channel = it.GetChannel();
319 if (channel->Sending()) { 333 if (channel->Sending()) {
320 channel->ProcessAndEncodeAudio(_audioFrame); 334 channel->ProcessAndEncodeAudio(_audioFrame);
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 // Speech + file level [0,9] 858 // Speech + file level [0,9]
845 return _audioLevel.Level(); 859 return _audioLevel.Level();
846 } 860 }
847 861
848 int16_t TransmitMixer::AudioLevelFullRange() const 862 int16_t TransmitMixer::AudioLevelFullRange() const
849 { 863 {
850 // Speech + file level [0,32767] 864 // Speech + file level [0,32767]
851 return _audioLevel.LevelFullRange(); 865 return _audioLevel.LevelFullRange();
852 } 866 }
853 867
868 double TransmitMixer::GetTotalInputEnergy() const {
869 return totalInputEnergy_;
870 }
871
872 double TransmitMixer::GetTotalInputDuration() const {
873 return totalInputDuration_;
874 }
875
854 bool TransmitMixer::IsRecordingCall() 876 bool TransmitMixer::IsRecordingCall()
855 { 877 {
856 return _fileCallRecording; 878 return _fileCallRecording;
857 } 879 }
858 880
859 bool TransmitMixer::IsRecordingMic() 881 bool TransmitMixer::IsRecordingMic()
860 { 882 {
861 rtc::CritScope cs(&_critSect); 883 rtc::CritScope cs(&_critSect);
862 return _fileRecording; 884 return _fileRecording;
863 } 885 }
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 void TransmitMixer::EnableStereoChannelSwapping(bool enable) { 1038 void TransmitMixer::EnableStereoChannelSwapping(bool enable) {
1017 swap_stereo_channels_ = enable; 1039 swap_stereo_channels_ = enable;
1018 } 1040 }
1019 1041
1020 bool TransmitMixer::IsStereoChannelSwappingEnabled() { 1042 bool TransmitMixer::IsStereoChannelSwappingEnabled() {
1021 return swap_stereo_channels_; 1043 return swap_stereo_channels_;
1022 } 1044 }
1023 1045
1024 } // namespace voe 1046 } // namespace voe
1025 } // namespace webrtc 1047 } // 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