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

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

Issue 2964593002: Adding stats that can be used to compute output audio levels. (Closed)
Patch Set: Dynamically compute sample_duration in transmit_mixer, add w3c links, and use a named constant in c… 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
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h" 43 #include "webrtc/voice_engine/include/voe_rtp_rtcp.h"
44 #include "webrtc/voice_engine/output_mixer.h" 44 #include "webrtc/voice_engine/output_mixer.h"
45 #include "webrtc/voice_engine/statistics.h" 45 #include "webrtc/voice_engine/statistics.h"
46 #include "webrtc/voice_engine/utility.h" 46 #include "webrtc/voice_engine/utility.h"
47 47
48 namespace webrtc { 48 namespace webrtc {
49 namespace voe { 49 namespace voe {
50 50
51 namespace { 51 namespace {
52 52
53 constexpr double kAudioSampleDurationSeconds = 0.01;
53 constexpr int64_t kMaxRetransmissionWindowMs = 1000; 54 constexpr int64_t kMaxRetransmissionWindowMs = 1000;
54 constexpr int64_t kMinRetransmissionWindowMs = 30; 55 constexpr int64_t kMinRetransmissionWindowMs = 30;
55 56
56 } // namespace 57 } // namespace
57 58
58 const int kTelephoneEventAttenuationdB = 10; 59 const int kTelephoneEventAttenuationdB = 10;
59 60
60 class RtcEventLogProxy final : public webrtc::RtcEventLog { 61 class RtcEventLogProxy final : public webrtc::RtcEventLog {
61 public: 62 public:
62 RtcEventLogProxy() : event_log_(nullptr) {} 63 RtcEventLogProxy() : event_log_(nullptr) {}
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 { 690 {
690 rtc::CritScope cs(&_fileCritSect); 691 rtc::CritScope cs(&_fileCritSect);
691 692
692 if (_outputFileRecording && output_file_recorder_) { 693 if (_outputFileRecording && output_file_recorder_) {
693 output_file_recorder_->RecordAudioToFile(*audioFrame); 694 output_file_recorder_->RecordAudioToFile(*audioFrame);
694 } 695 }
695 } 696 }
696 697
697 // Measure audio level (0-9) 698 // Measure audio level (0-9)
698 // TODO(henrik.lundin) Use the |muted| information here too. 699 // TODO(henrik.lundin) Use the |muted| information here too.
700 // TODO(deadbeef): Use RmsLevel for |_outputAudioLevel| as well.
699 _outputAudioLevel.ComputeLevel(*audioFrame); 701 _outputAudioLevel.ComputeLevel(*audioFrame);
702 // See the description for "totalAudioEnergy" in the WebRTC stats spec
703 // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudi oenergy)
704 // for an explanation of these formulas. In short, we need a value that can
705 // be used to compute RMS audio levels over different time intervals, by
706 // taking the difference between the results from two getStats calls. To do
707 // this, the value needs to be of units "squared sample value * time".
708 double additional_energy =
709 static_cast<double>(_outputAudioLevel.LevelFullRange()) / INT16_MAX;
710 additional_energy *= additional_energy;
711 _totalOutputEnergy += additional_energy * kAudioSampleDurationSeconds;
712 _totalOutputDuration += kAudioSampleDurationSeconds;
700 713
701 if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) { 714 if (capture_start_rtp_time_stamp_ < 0 && audioFrame->timestamp_ != 0) {
702 // The first frame with a valid rtp timestamp. 715 // The first frame with a valid rtp timestamp.
703 capture_start_rtp_time_stamp_ = audioFrame->timestamp_; 716 capture_start_rtp_time_stamp_ = audioFrame->timestamp_;
704 } 717 }
705 718
706 if (capture_start_rtp_time_stamp_ >= 0) { 719 if (capture_start_rtp_time_stamp_ >= 0) {
707 // audioFrame.timestamp_ should be valid from now on. 720 // audioFrame.timestamp_ should be valid from now on.
708 721
709 // Compute elapsed time. 722 // Compute elapsed time.
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 } 2376 }
2364 2377
2365 int Channel::GetSpeechOutputLevel() const { 2378 int Channel::GetSpeechOutputLevel() const {
2366 return _outputAudioLevel.Level(); 2379 return _outputAudioLevel.Level();
2367 } 2380 }
2368 2381
2369 int Channel::GetSpeechOutputLevelFullRange() const { 2382 int Channel::GetSpeechOutputLevelFullRange() const {
2370 return _outputAudioLevel.LevelFullRange(); 2383 return _outputAudioLevel.LevelFullRange();
2371 } 2384 }
2372 2385
2386 double Channel::GetTotalOutputEnergy() const {
2387 return _totalOutputEnergy;
2388 }
2389
2390 double Channel::GetTotalOutputDuration() const {
2391 return _totalOutputDuration;
2392 }
2393
2373 void Channel::SetInputMute(bool enable) { 2394 void Channel::SetInputMute(bool enable) {
2374 rtc::CritScope cs(&volume_settings_critsect_); 2395 rtc::CritScope cs(&volume_settings_critsect_);
2375 input_mute_ = enable; 2396 input_mute_ = enable;
2376 } 2397 }
2377 2398
2378 bool Channel::InputMute() const { 2399 bool Channel::InputMute() const {
2379 rtc::CritScope cs(&volume_settings_critsect_); 2400 rtc::CritScope cs(&volume_settings_critsect_);
2380 return input_mute_; 2401 return input_mute_;
2381 } 2402 }
2382 2403
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
3140 int64_t min_rtt = 0; 3161 int64_t min_rtt = 0;
3141 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) != 3162 if (_rtpRtcpModule->RTT(remoteSSRC, &rtt, &avg_rtt, &min_rtt, &max_rtt) !=
3142 0) { 3163 0) {
3143 return 0; 3164 return 0;
3144 } 3165 }
3145 return rtt; 3166 return rtt;
3146 } 3167 }
3147 3168
3148 } // namespace voe 3169 } // namespace voe
3149 } // namespace webrtc 3170 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698