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/criticalsection.h" | 15 #include "webrtc/base/criticalsection.h" |
15 #include "webrtc/base/task_queue.h" | 16 #include "webrtc/base/task_queue.h" |
16 #include "webrtc/base/thread_checker.h" | 17 #include "webrtc/base/thread_checker.h" |
17 #include "webrtc/modules/audio_device/include/audio_device.h" | 18 #include "webrtc/modules/audio_device/include/audio_device.h" |
18 #include "webrtc/system_wrappers/include/file_wrapper.h" | 19 #include "webrtc/system_wrappers/include/file_wrapper.h" |
19 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
20 | 21 |
21 namespace webrtc { | 22 namespace webrtc { |
22 class CriticalSectionWrapper; | |
23 | |
24 // Delta times between two successive playout callbacks are limited to this | 23 // Delta times between two successive playout callbacks are limited to this |
25 // value before added to an internal array. | 24 // value before added to an internal array. |
26 const size_t kMaxDeltaTimeInMs = 500; | 25 const size_t kMaxDeltaTimeInMs = 500; |
27 // TODO(henrika): remove when no longer used by external client. | 26 // TODO(henrika): remove when no longer used by external client. |
28 const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz | 27 const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz |
29 | 28 |
30 class AudioDeviceObserver; | 29 class AudioDeviceObserver; |
31 | 30 |
32 class AudioDeviceBuffer { | 31 class AudioDeviceBuffer { |
33 public: | 32 public: |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 // valid implementation. Investigate the possibility to either remove them | 65 // valid implementation. Investigate the possibility to either remove them |
67 // or add a proper implementation if needed. | 66 // or add a proper implementation if needed. |
68 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); | 67 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
69 int32_t StopInputFileRecording(); | 68 int32_t StopInputFileRecording(); |
70 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); | 69 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
71 int32_t StopOutputFileRecording(); | 70 int32_t StopOutputFileRecording(); |
72 | 71 |
73 int32_t SetTypingStatus(bool typing_status); | 72 int32_t SetTypingStatus(bool typing_status); |
74 | 73 |
75 private: | 74 private: |
76 // Playout and recording parameters can change on the fly. e.g. at device | |
77 // switch. These methods ensures that the callback methods always use the | |
78 // latest parameters. | |
79 void UpdatePlayoutParameters(); | |
80 void UpdateRecordingParameters(); | |
81 | |
82 // Posts the first delayed task in the task queue and starts the periodic | 75 // Posts the first delayed task in the task queue and starts the periodic |
83 // timer. | 76 // timer. |
84 void StartTimer(); | 77 void StartTimer(); |
85 | 78 |
86 // Called periodically on the internal thread created by the TaskQueue. | 79 // Called periodically on the internal thread created by the TaskQueue. |
87 void LogStats(); | 80 void LogStats(); |
88 | 81 |
89 // Clears all members tracking stats for recording and playout. | 82 // Clears all members tracking stats for recording and playout. |
90 void ResetRecStats(); | 83 void ResetRecStats(); |
91 void ResetPlayStats(); | 84 void ResetPlayStats(); |
92 | 85 |
93 // Updates counters in each play/record callback but does it on the task | 86 // Updates counters in each play/record callback but does it on the task |
94 // queue to ensure that they can be read by LogStats() without any locks since | 87 // queue to ensure that they can be read by LogStats() without any locks since |
95 // each task is serialized by the task queue. | 88 // each task is serialized by the task queue. |
96 void UpdateRecStats(const void* audio_buffer, size_t num_samples); | 89 void UpdateRecStats(const void* audio_buffer, size_t num_samples); |
97 void UpdatePlayStats(const void* audio_buffer, size_t num_samples); | 90 void UpdatePlayStats(const void* audio_buffer, size_t num_samples); |
98 | 91 |
99 // Ensures that methods are called on the same thread as the thread that | 92 // Ensures that methods are called on the same thread as the thread that |
100 // creates this object. | 93 // creates this object. |
101 rtc::ThreadChecker thread_checker_; | 94 rtc::ThreadChecker thread_checker_; |
102 | 95 |
103 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() | 96 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() |
104 // and it must outlive this object. | 97 // and it must outlive this object. |
105 AudioTransport* audio_transport_cb_; | 98 AudioTransport* audio_transport_cb_; |
106 | 99 |
107 // TODO(henrika): given usage of thread checker, it should be possible to | 100 // TODO(henrika): given usage of thread checker, it should be possible to |
108 // remove all locks in this class. | 101 // remove all locks in this class. |
109 rtc::CriticalSection _critSect; | 102 rtc::CriticalSection lock_; |
110 rtc::CriticalSection _critSectCb; | 103 rtc::CriticalSection lock_cb_; |
kwiberg-webrtc
2016/09/14 08:39:05
This class uses none of our very cool and very han
henrika_webrtc
2016/09/14 10:26:54
Would love to improve this area. Hope you are OK w
kwiberg-webrtc
2016/09/14 11:17:17
Acknowledged.
| |
111 | 104 |
112 // Task queue used to invoke LogStats() periodically. Tasks are executed on a | 105 // Task queue used to invoke LogStats() periodically. Tasks are executed on a |
113 // worker thread but it does not necessarily have to be the same thread for | 106 // worker thread but it does not necessarily have to be the same thread for |
114 // each task. | 107 // each task. |
115 rtc::TaskQueue task_queue_; | 108 rtc::TaskQueue task_queue_; |
116 | 109 |
117 // Ensures that the timer is only started once. | 110 // Ensures that the timer is only started once. |
118 bool timer_has_started_; | 111 bool timer_has_started_; |
119 | 112 |
120 // Sample rate in Hertz. | 113 // Sample rate in Hertz. |
121 uint32_t rec_sample_rate_; | 114 uint32_t rec_sample_rate_; |
122 uint32_t play_sample_rate_; | 115 uint32_t play_sample_rate_; |
123 | 116 |
124 // Number of audio channels. | 117 // Number of audio channels. |
125 size_t rec_channels_; | 118 size_t rec_channels_; |
126 size_t play_channels_; | 119 size_t play_channels_; |
127 | 120 |
128 // selected recording channel (left/right/both) | |
129 AudioDeviceModule::ChannelType rec_channel_; | |
130 | |
131 // Number of bytes per audio sample (2 or 4). | 121 // Number of bytes per audio sample (2 or 4). |
132 size_t rec_bytes_per_sample_; | 122 size_t rec_bytes_per_sample_; |
133 size_t play_bytes_per_sample_; | 123 size_t play_bytes_per_sample_; |
134 | 124 |
135 // Number of audio samples/bytes per 10ms. | 125 // Byte buffer used for recorded audio samples. Size can be changed |
136 size_t rec_samples_per_10ms_; | 126 // dynamically. |
137 size_t rec_bytes_per_10ms_; | 127 rtc::Buffer rec_buffer_; |
138 size_t play_samples_per_10ms_; | |
139 size_t play_bytes_per_10ms_; | |
140 | 128 |
141 // Buffer used for recorded audio samples. Size is currently fixed | 129 // Buffer used for audio samples to be played out. Size can be changed |
142 // but it should be changed to be dynamic and correspond to | 130 // dynamically. |
143 // |play_bytes_per_10ms_|. TODO(henrika): avoid using fixed (max) size. | 131 rtc::Buffer play_buffer_; |
kwiberg-webrtc
2016/09/14 08:39:05
The dynamic resizing is obvious from the type, so
henrika_webrtc
2016/09/14 10:26:54
This class has always worked with bytes but I must
kwiberg-webrtc
2016/09/14 11:17:17
Acknowledged.
henrika_webrtc
2016/10/17 09:31:10
Tried it but it is rather tricky actually since se
| |
144 std::unique_ptr<int8_t[]> rec_buffer_; | |
145 | |
146 // Buffer used for audio samples to be played out. Size is currently fixed | |
147 // but it should be changed to be dynamic and correspond to | |
148 // |play_bytes_per_10ms_|. TODO(henrika): avoid using fixed (max) size. | |
149 std::unique_ptr<int8_t[]> play_buffer_; | |
150 | 132 |
151 // AGC parameters. | 133 // AGC parameters. |
152 uint32_t current_mic_level_; | 134 uint32_t current_mic_level_; |
153 uint32_t new_mic_level_; | 135 uint32_t new_mic_level_; |
154 | 136 |
155 // Contains true of a key-press has been detected. | 137 // Contains true of a key-press has been detected. |
156 bool typing_status_; | 138 bool typing_status_; |
157 | 139 |
158 // Delay values used by the AEC. | 140 // Delay values used by the AEC. |
159 int play_delay_ms_; | 141 int play_delay_ms_; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 // all level measurements since the last log has been exactly zero. | 200 // all level measurements since the last log has been exactly zero. |
219 // In other words: this counter is incremented only if 20 measurements | 201 // In other words: this counter is incremented only if 20 measurements |
220 // (two per second) in a row equals zero. The member is only incremented on | 202 // (two per second) in a row equals zero. The member is only incremented on |
221 // the task queue and max once every 10th second. | 203 // the task queue and max once every 10th second. |
222 size_t num_rec_level_is_zero_; | 204 size_t num_rec_level_is_zero_; |
223 }; | 205 }; |
224 | 206 |
225 } // namespace webrtc | 207 } // namespace webrtc |
226 | 208 |
227 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ | 209 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ |
OLD | NEW |