Chromium Code Reviews| 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 |
| 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" |
|
tommi
2016/10/25 16:43:23
can you fwd declare TaskQueue now instead of inclu
henrika_webrtc
2016/10/26 12:42:41
Done.
| |
| 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 class AudioDeviceObserver; | 29 class AudioDeviceObserver; |
| 30 | 30 |
| 31 class AudioDeviceBuffer { | 31 class AudioDeviceBuffer { |
| 32 public: | 32 public: |
| 33 AudioDeviceBuffer(); | 33 AudioDeviceBuffer(); |
| 34 virtual ~AudioDeviceBuffer(); | 34 virtual ~AudioDeviceBuffer(); |
| 35 | 35 |
| 36 void SetId(uint32_t id) {}; | 36 void SetId(uint32_t id) {}; |
| 37 int32_t RegisterAudioCallback(AudioTransport* audio_callback); | 37 int32_t RegisterAudioCallback(AudioTransport* audio_callback); |
| 38 | 38 |
| 39 int32_t InitPlayout(); | 39 int32_t InitPlayout(); |
| 40 int32_t InitRecording(); | 40 int32_t InitRecording(); |
| 41 void StartPlayout(); | |
|
tommi
2016/10/25 16:43:23
we have the following three states:
construct / d
henrika_webrtc
2016/10/26 12:42:41
Good point. Calls to init have been around for a l
| |
| 42 void StartRecording(); | |
| 43 void StopPlayout(); | |
| 44 void StopRecording(); | |
| 41 | 45 |
| 42 int32_t SetRecordingSampleRate(uint32_t fsHz); | 46 int32_t SetRecordingSampleRate(uint32_t fsHz); |
| 43 int32_t SetPlayoutSampleRate(uint32_t fsHz); | 47 int32_t SetPlayoutSampleRate(uint32_t fsHz); |
| 44 int32_t RecordingSampleRate() const; | 48 int32_t RecordingSampleRate() const; |
| 45 int32_t PlayoutSampleRate() const; | 49 int32_t PlayoutSampleRate() const; |
| 46 | 50 |
| 47 int32_t SetRecordingChannels(size_t channels); | 51 int32_t SetRecordingChannels(size_t channels); |
| 48 int32_t SetPlayoutChannels(size_t channels); | 52 int32_t SetPlayoutChannels(size_t channels); |
| 49 size_t RecordingChannels() const; | 53 size_t RecordingChannels() const; |
| 50 size_t PlayoutChannels() const; | 54 size_t PlayoutChannels() const; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 69 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); | 73 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
| 70 int32_t StopOutputFileRecording(); | 74 int32_t StopOutputFileRecording(); |
| 71 | 75 |
| 72 int32_t SetTypingStatus(bool typing_status); | 76 int32_t SetTypingStatus(bool typing_status); |
| 73 | 77 |
| 74 private: | 78 private: |
| 75 // Posts the first delayed task in the task queue and starts the periodic | 79 // Posts the first delayed task in the task queue and starts the periodic |
| 76 // timer. | 80 // timer. |
| 77 void StartTimer(); | 81 void StartTimer(); |
| 78 | 82 |
| 83 // Stops the timer by releasing the unique TaskQueue instance. | |
| 84 void StopTimer(); | |
| 85 | |
| 79 // Called periodically on the internal thread created by the TaskQueue. | 86 // Called periodically on the internal thread created by the TaskQueue. |
| 80 void LogStats(); | 87 void LogStats(); |
| 81 | 88 |
| 82 // Clears all members tracking stats for recording and playout. | 89 // Clears all members tracking stats for recording and playout. |
| 83 void ResetRecStats(); | 90 void ResetRecStats(); |
| 84 void ResetPlayStats(); | 91 void ResetPlayStats(); |
| 85 | 92 |
| 86 // Updates counters in each play/record callback but does it on the task | 93 // 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 | 94 // queue to ensure that they can be read by LogStats() without any locks since |
| 88 // each task is serialized by the task queue. | 95 // each task is serialized by the task queue. |
| 89 void UpdateRecStats(int16_t max_abs, size_t num_samples); | 96 void UpdateRecStats(int16_t max_abs, size_t num_samples); |
| 90 void UpdatePlayStats(int16_t max_abs, size_t num_samples); | 97 void UpdatePlayStats(int16_t max_abs, size_t num_samples); |
| 91 | 98 |
| 92 // Ensures that methods are called on the same thread as the thread that | 99 // Ensures that methods are called on the same thread as the thread that |
| 93 // creates this object. | 100 // creates this object. |
| 94 rtc::ThreadChecker thread_checker_; | 101 rtc::ThreadChecker thread_checker_; |
| 95 | 102 |
| 96 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() | 103 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() |
| 97 // and it must outlive this object. | 104 // and it must outlive this object. |
| 98 AudioTransport* audio_transport_cb_; | 105 AudioTransport* audio_transport_cb_; |
| 99 | 106 |
| 100 // TODO(henrika): given usage of thread checker, it should be possible to | 107 // TODO(henrika): given usage of thread checker, it should be possible to |
| 101 // remove all locks in this class. | 108 // remove all locks in this class. |
| 102 rtc::CriticalSection lock_; | 109 rtc::CriticalSection lock_; |
| 103 rtc::CriticalSection lock_cb_; | 110 rtc::CriticalSection lock_cb_; |
| 104 | 111 |
| 105 // Task queue used to invoke LogStats() periodically. Tasks are executed on a | 112 // 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 | 113 // worker thread but it does not necessarily have to be the same thread for |
| 107 // each task. | 114 // each task. |
| 108 rtc::TaskQueue task_queue_; | 115 std::unique_ptr<rtc::TaskQueue> task_queue_; |
| 109 | 116 |
| 110 // Ensures that the timer is only started once. | 117 // Keeps track of if playout/recording are active or not. A combination |
| 111 bool timer_has_started_; | 118 // of these states are used to determine when to start and stop the timer. |
| 119 // Only used on the creating thread and not used to control any media flow. | |
| 120 bool playing_; | |
| 121 bool recording_; | |
| 112 | 122 |
| 113 // Sample rate in Hertz. | 123 // Sample rate in Hertz. |
| 114 uint32_t rec_sample_rate_; | 124 uint32_t rec_sample_rate_; |
| 115 uint32_t play_sample_rate_; | 125 uint32_t play_sample_rate_; |
| 116 | 126 |
| 117 // Number of audio channels. | 127 // Number of audio channels. |
| 118 size_t rec_channels_; | 128 size_t rec_channels_; |
| 119 size_t play_channels_; | 129 size_t play_channels_; |
| 120 | 130 |
| 121 // Number of bytes per audio sample (2 or 4). | 131 // Number of bytes per audio sample (2 or 4). |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 // Contains max level (max(abs(x))) of recorded audio packets over the last | 199 // 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 | 200 // 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 | 201 // is reset to zero at each call to LogStats(). Only modified on the task |
| 192 // queue thread. | 202 // queue thread. |
| 193 int16_t max_rec_level_; | 203 int16_t max_rec_level_; |
| 194 | 204 |
| 195 // Contains max level of recorded audio packets over the last 10 seconds | 205 // Contains max level of recorded audio packets over the last 10 seconds |
| 196 // where a new measurement is done twice per second. | 206 // where a new measurement is done twice per second. |
| 197 int16_t max_play_level_; | 207 int16_t max_play_level_; |
| 198 | 208 |
| 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 | 209 // Counts number of audio callbacks modulo 50 to create a signal when |
| 207 // a new storage of audio stats shall be done. | 210 // a new storage of audio stats shall be done. |
| 208 // Only updated on the OS-specific audio thread that drives audio. | 211 // Only updated on the OS-specific audio thread that drives audio. |
| 209 int16_t rec_stat_count_; | 212 int16_t rec_stat_count_; |
| 210 int16_t play_stat_count_; | 213 int16_t play_stat_count_; |
| 214 | |
| 215 // Time stamps of when playout and recording starts. | |
| 216 uint64_t play_start_time_; | |
| 217 uint64_t rec_start_time_; | |
| 218 | |
| 219 // Set to true at construction and modified to false as soon as one audio- | |
| 220 // level estimate larger than zero is detected. | |
| 221 bool only_silence_recorded_; | |
| 211 }; | 222 }; |
| 212 | 223 |
| 213 } // namespace webrtc | 224 } // namespace webrtc |
| 214 | 225 |
| 215 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ | 226 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ |
| OLD | NEW |