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

Side by Side Diff: webrtc/modules/audio_device/audio_device_buffer.h

Issue 2445363003: Improvements in how WebRTC.Audio.RecordedOnlyZeros is added as histogram (Closed)
Patch Set: nits Created 4 years, 1 month 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
11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ 11 #ifndef WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_
12 #define WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ 12 #define WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_
13 13
14 #include "webrtc/base/buffer.h" 14 #include "webrtc/base/buffer.h"
15 #include "webrtc/base/criticalsection.h" 15 #include "webrtc/base/criticalsection.h"
16 #include "webrtc/base/task_queue.h" 16 #include "webrtc/base/task_queue.h"
17 #include "webrtc/base/thread_checker.h" 17 #include "webrtc/base/thread_checker.h"
18 #include "webrtc/modules/audio_device/include/audio_device.h" 18 #include "webrtc/modules/audio_device/include/audio_device.h"
19 #include "webrtc/system_wrappers/include/file_wrapper.h" 19 #include "webrtc/system_wrappers/include/file_wrapper.h"
20 #include "webrtc/typedefs.h" 20 #include "webrtc/typedefs.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 // Delta times between two successive playout callbacks are limited to this 23 // Delta times between two successive playout callbacks are limited to this
24 // value before added to an internal array. 24 // value before added to an internal array.
25 const size_t kMaxDeltaTimeInMs = 500; 25 const size_t kMaxDeltaTimeInMs = 500;
26 // TODO(henrika): remove when no longer used by external client. 26 // TODO(henrika): remove when no longer used by external client.
27 const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz 27 const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
28 28
29 enum LogState {
30 kLogStart = 0,
tommi 2016/10/27 17:38:24 LOG_START, LOG_STOP, LOG_ACTIVE, What about movin
henrika_webrtc 2016/10/31 12:23:06 Will fix. It was actually not clear to me that we
31 kLogStop,
32 kLogActive,
33 };
34
29 class AudioDeviceObserver; 35 class AudioDeviceObserver;
30 36
31 class AudioDeviceBuffer { 37 class AudioDeviceBuffer {
32 public: 38 public:
33 AudioDeviceBuffer(); 39 AudioDeviceBuffer();
34 virtual ~AudioDeviceBuffer(); 40 virtual ~AudioDeviceBuffer();
35 41
36 void SetId(uint32_t id) {}; 42 void SetId(uint32_t id) {};
37 int32_t RegisterAudioCallback(AudioTransport* audio_callback); 43 int32_t RegisterAudioCallback(AudioTransport* audio_callback);
38 44
39 int32_t InitPlayout(); 45 void StartPlayout();
40 int32_t InitRecording(); 46 void StartRecording();
47 void StopPlayout();
48 void StopRecording();
41 49
42 int32_t SetRecordingSampleRate(uint32_t fsHz); 50 int32_t SetRecordingSampleRate(uint32_t fsHz);
43 int32_t SetPlayoutSampleRate(uint32_t fsHz); 51 int32_t SetPlayoutSampleRate(uint32_t fsHz);
44 int32_t RecordingSampleRate() const; 52 int32_t RecordingSampleRate() const;
45 int32_t PlayoutSampleRate() const; 53 int32_t PlayoutSampleRate() const;
46 54
47 int32_t SetRecordingChannels(size_t channels); 55 int32_t SetRecordingChannels(size_t channels);
48 int32_t SetPlayoutChannels(size_t channels); 56 int32_t SetPlayoutChannels(size_t channels);
49 size_t RecordingChannels() const; 57 size_t RecordingChannels() const;
50 size_t PlayoutChannels() const; 58 size_t PlayoutChannels() const;
(...skipping 14 matching lines...) Expand all
65 // valid implementation. Investigate the possibility to either remove them 73 // valid implementation. Investigate the possibility to either remove them
66 // or add a proper implementation if needed. 74 // or add a proper implementation if needed.
67 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); 75 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]);
68 int32_t StopInputFileRecording(); 76 int32_t StopInputFileRecording();
69 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); 77 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]);
70 int32_t StopOutputFileRecording(); 78 int32_t StopOutputFileRecording();
71 79
72 int32_t SetTypingStatus(bool typing_status); 80 int32_t SetTypingStatus(bool typing_status);
73 81
74 private: 82 private:
75 // Posts the first delayed task in the task queue and starts the periodic 83 // Starts/stops periodic logging of audio stats.
76 // timer. 84 void StartPeriodicLogging();
77 void StartTimer(); 85 void StopPeriodicLogging();
78 86
79 // Called periodically on the internal thread created by the TaskQueue. 87 // Called periodically on the internal thread created by the TaskQueue.
80 void LogStats(); 88 // Updates some stats but dooes it on the task queue to ensure that access of
81 89 // members is serialized hence avoiding usage of locks.
82 // Clears all members tracking stats for recording and playout. 90 // state = |kLogStart| => members are initialized and the timer starts.
tommi 2016/10/27 17:38:24 and update documentation to ALL_CAPS style
henrika_webrtc 2016/10/31 12:23:06 Done.
83 void ResetRecStats(); 91 // state = |kLogStop| => no logs are printed and the timer stops.
84 void ResetPlayStats(); 92 // state = |kLogActive| => logs are printed and the timer is kept alive.
93 void LogStats(LogState state);
85 94
86 // Updates counters in each play/record callback but does it on the task 95 // Updates counters in each play/record callback but does it on the task
87 // queue to ensure that they can be read by LogStats() without any locks since 96 // queue to ensure that they can be read by LogStats() without any locks since
88 // each task is serialized by the task queue. 97 // each task is serialized by the task queue.
89 void UpdateRecStats(int16_t max_abs, size_t num_samples); 98 void UpdateRecStats(int16_t max_abs, size_t num_samples);
90 void UpdatePlayStats(int16_t max_abs, size_t num_samples); 99 void UpdatePlayStats(int16_t max_abs, size_t num_samples);
91 100
101 // Clears all members tracking stats for recording and playout.
102 // These methods both run on the task queue.
103 void ResetRecStats();
104 void ResetPlayStats();
105
92 // Ensures that methods are called on the same thread as the thread that 106 // Ensures that methods are called on the same thread as the thread that
93 // creates this object. 107 // creates this object.
94 rtc::ThreadChecker thread_checker_; 108 rtc::ThreadChecker thread_checker_;
95 109
96 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() 110 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback()
97 // and it must outlive this object. 111 // and it must outlive this object.
98 AudioTransport* audio_transport_cb_; 112 AudioTransport* audio_transport_cb_;
99 113
100 // TODO(henrika): given usage of thread checker, it should be possible to 114 // TODO(henrika): given usage of thread checker, it should be possible to
101 // remove all locks in this class. 115 // remove all locks in this class.
102 rtc::CriticalSection lock_; 116 rtc::CriticalSection lock_;
103 rtc::CriticalSection lock_cb_; 117 rtc::CriticalSection lock_cb_;
104 118
105 // Task queue used to invoke LogStats() periodically. Tasks are executed on a 119 // Task queue used to invoke LogStats() periodically. Tasks are executed on a
106 // worker thread but it does not necessarily have to be the same thread for 120 // worker thread but it does not necessarily have to be the same thread for
107 // each task. 121 // each task.
108 rtc::TaskQueue task_queue_; 122 rtc::TaskQueue task_queue_;
109 123
110 // Ensures that the timer is only started once. 124 // Keeps track of if playout/recording are active or not. A combination
111 bool timer_has_started_; 125 // of these states are used to determine when to start and stop the timer.
126 // Only used on the creating thread and not used to control any media flow.
127 bool playing_;
128 bool recording_;
112 129
113 // Sample rate in Hertz. 130 // Sample rate in Hertz.
114 uint32_t rec_sample_rate_; 131 uint32_t rec_sample_rate_;
115 uint32_t play_sample_rate_; 132 uint32_t play_sample_rate_;
116 133
117 // Number of audio channels. 134 // Number of audio channels.
118 size_t rec_channels_; 135 size_t rec_channels_;
119 size_t play_channels_; 136 size_t play_channels_;
120 137
121 // Number of bytes per audio sample (2 or 4). 138 // Number of bytes per audio sample (2 or 4).
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 183
167 // Total number of recorded samples stored at the previous timer task. 184 // Total number of recorded samples stored at the previous timer task.
168 uint64_t last_rec_samples_; 185 uint64_t last_rec_samples_;
169 186
170 // Total number of played audio samples. 187 // Total number of played audio samples.
171 uint64_t play_samples_; 188 uint64_t play_samples_;
172 189
173 // Total number of played samples stored at the previous timer task. 190 // Total number of played samples stored at the previous timer task.
174 uint64_t last_play_samples_; 191 uint64_t last_play_samples_;
175 192
176 // Time stamp of last stat report. 193 // Time stamp of last timer task (drives logging).
177 uint64_t last_log_stat_time_; 194 uint64_t last_timer_task_time_;
178 195
179 // Time stamp of last playout callback. 196 // Time stamp of last playout callback.
180 uint64_t last_playout_time_; 197 uint64_t last_playout_time_;
181 198
182 // An array where the position corresponds to time differences (in 199 // An array where the position corresponds to time differences (in
183 // milliseconds) between two successive playout callbacks, and the stored 200 // milliseconds) between two successive playout callbacks, and the stored
184 // value is the number of times a given time difference was found. 201 // value is the number of times a given time difference was found.
185 // Writing to the array is done without a lock since it is only read once at 202 // Writing to the array is done without a lock since it is only read once at
186 // destruction when no audio is running. 203 // destruction when no audio is running.
187 uint32_t playout_diff_times_[kMaxDeltaTimeInMs + 1] = {0}; 204 uint32_t playout_diff_times_[kMaxDeltaTimeInMs + 1] = {0};
188 205
189 // Contains max level (max(abs(x))) of recorded audio packets over the last 206 // Contains max level (max(abs(x))) of recorded audio packets over the last
190 // 10 seconds where a new measurement is done twice per second. The level 207 // 10 seconds where a new measurement is done twice per second. The level
191 // is reset to zero at each call to LogStats(). Only modified on the task 208 // is reset to zero at each call to LogStats(). Only modified on the task
192 // queue thread. 209 // queue thread.
193 int16_t max_rec_level_; 210 int16_t max_rec_level_;
194 211
195 // Contains max level of recorded audio packets over the last 10 seconds 212 // Contains max level of recorded audio packets over the last 10 seconds
196 // where a new measurement is done twice per second. 213 // where a new measurement is done twice per second.
197 int16_t max_play_level_; 214 int16_t max_play_level_;
198 215
199 // Counts number of times we detect "no audio" corresponding to a case where
200 // all level measurements since the last log has been exactly zero.
201 // In other words: this counter is incremented only if 20 measurements
202 // (two per second) in a row equals zero. The member is only incremented on
203 // the task queue and max once every 10th second.
204 size_t num_rec_level_is_zero_;
205
206 // Counts number of audio callbacks modulo 50 to create a signal when 216 // Counts number of audio callbacks modulo 50 to create a signal when
207 // a new storage of audio stats shall be done. 217 // a new storage of audio stats shall be done.
208 // Only updated on the OS-specific audio thread that drives audio. 218 // Only updated on the OS-specific audio thread that drives audio.
209 int16_t rec_stat_count_; 219 int16_t rec_stat_count_;
210 int16_t play_stat_count_; 220 int16_t play_stat_count_;
221
222 // Time stamps of when playout and recording starts.
223 uint64_t play_start_time_;
224 uint64_t rec_start_time_;
225
226 // Set to true at construction and modified to false as soon as one audio-
227 // level estimate larger than zero is detected.
228 bool only_silence_recorded_;
211 }; 229 };
212 230
213 } // namespace webrtc 231 } // namespace webrtc
214 232
215 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ 233 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/modules/audio_device/audio_device_buffer.cc » ('j') | webrtc/modules/audio_device/audio_device_buffer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698