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

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

Issue 2260183002: Revert of Cleanup of the AudioDeviceBuffer class (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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 | « no previous file | webrtc/modules/audio_device/audio_device_buffer.cc » ('j') | 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
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/criticalsection.h" 14 #include "webrtc/base/criticalsection.h"
15 #include "webrtc/base/task_queue.h" 15 #include "webrtc/base/task_queue.h"
16 #include "webrtc/base/thread_checker.h" 16 #include "webrtc/base/thread_checker.h"
17 #include "webrtc/modules/audio_device/include/audio_device.h" 17 #include "webrtc/modules/audio_device/include/audio_device.h"
18 #include "webrtc/system_wrappers/include/file_wrapper.h" 18 #include "webrtc/system_wrappers/include/file_wrapper.h"
19 #include "webrtc/typedefs.h" 19 #include "webrtc/typedefs.h"
20 20
21 namespace webrtc { 21 namespace webrtc {
22 class CriticalSectionWrapper; 22 class CriticalSectionWrapper;
23 23
24 const uint32_t kPulsePeriodMs = 1000;
25 const size_t kMaxBufferSizeBytes = 3840; // 10ms in stereo @ 96kHz
24 // Delta times between two successive playout callbacks are limited to this 26 // Delta times between two successive playout callbacks are limited to this
25 // value before added to an internal array. 27 // value before added to an internal array.
26 const size_t kMaxDeltaTimeInMs = 500; 28 const size_t kMaxDeltaTimeInMs = 500;
27 29
28 class AudioDeviceObserver; 30 class AudioDeviceObserver;
29 31
30 class AudioDeviceBuffer { 32 class AudioDeviceBuffer {
31 public: 33 public:
32 AudioDeviceBuffer(); 34 AudioDeviceBuffer();
33 virtual ~AudioDeviceBuffer(); 35 virtual ~AudioDeviceBuffer();
34 36
35 void SetId(uint32_t id) {}; 37 void SetId(uint32_t id) {};
36 int32_t RegisterAudioCallback(AudioTransport* audio_callback); 38 int32_t RegisterAudioCallback(AudioTransport* audioCallback);
37 39
38 int32_t InitPlayout(); 40 int32_t InitPlayout();
39 int32_t InitRecording(); 41 int32_t InitRecording();
40 42
41 int32_t SetRecordingSampleRate(uint32_t fsHz); 43 virtual int32_t SetRecordingSampleRate(uint32_t fsHz);
42 int32_t SetPlayoutSampleRate(uint32_t fsHz); 44 virtual int32_t SetPlayoutSampleRate(uint32_t fsHz);
43 int32_t RecordingSampleRate() const; 45 int32_t RecordingSampleRate() const;
44 int32_t PlayoutSampleRate() const; 46 int32_t PlayoutSampleRate() const;
45 47
46 int32_t SetRecordingChannels(size_t channels); 48 virtual int32_t SetRecordingChannels(size_t channels);
47 int32_t SetPlayoutChannels(size_t channels); 49 virtual int32_t SetPlayoutChannels(size_t channels);
48 size_t RecordingChannels() const; 50 size_t RecordingChannels() const;
49 size_t PlayoutChannels() const; 51 size_t PlayoutChannels() const;
50 int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel); 52 int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel);
51 int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const; 53 int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const;
52 54
53 virtual int32_t SetRecordedBuffer(const void* audio_buffer, 55 virtual int32_t SetRecordedBuffer(const void* audioBuffer, size_t nSamples);
54 size_t num_samples);
55 int32_t SetCurrentMicLevel(uint32_t level); 56 int32_t SetCurrentMicLevel(uint32_t level);
56 virtual void SetVQEData(int play_delay_ms, int rec_delay_ms, int clock_drift); 57 virtual void SetVQEData(int playDelayMS, int recDelayMS, int clockDrift);
57 virtual int32_t DeliverRecordedData(); 58 virtual int32_t DeliverRecordedData();
58 uint32_t NewMicLevel() const; 59 uint32_t NewMicLevel() const;
59 60
60 virtual int32_t RequestPlayoutData(size_t num_samples); 61 virtual int32_t RequestPlayoutData(size_t nSamples);
61 virtual int32_t GetPlayoutData(void* audio_buffer); 62 virtual int32_t GetPlayoutData(void* audioBuffer);
62 63
63 // TODO(henrika): these methods should not be used and does not contain any
64 // valid implementation. Investigate the possibility to either remove them
65 // or add a proper implementation if needed.
66 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); 64 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]);
67 int32_t StopInputFileRecording(); 65 int32_t StopInputFileRecording();
68 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); 66 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]);
69 int32_t StopOutputFileRecording(); 67 int32_t StopOutputFileRecording();
70 68
71 int32_t SetTypingStatus(bool typing_status); 69 int32_t SetTypingStatus(bool typingStatus);
72 70
73 private: 71 private:
74 void AllocatePlayoutBufferIfNeeded();
75 void AllocateRecordingBufferIfNeeded();
76
77 // Posts the first delayed task in the task queue and starts the periodic 72 // Posts the first delayed task in the task queue and starts the periodic
78 // timer. 73 // timer.
79 void StartTimer(); 74 void StartTimer();
80 75
81 // Called periodically on the internal thread created by the TaskQueue. 76 // Called periodically on the internal thread created by the TaskQueue.
82 void LogStats(); 77 void LogStats();
83 78
84 // Updates counters in each play/record callback but does it on the task 79 // Updates counters in each play/record callback but does it on the task
85 // queue to ensure that they can be read by LogStats() without any locks since 80 // queue to ensure that they can be read by LogStats() without any locks since
86 // each task is serialized by the task queue. 81 // each task is serialized by the task queue.
87 void UpdateRecStats(size_t num_samples); 82 void UpdateRecStats(size_t num_samples);
88 void UpdatePlayStats(size_t num_samples); 83 void UpdatePlayStats(size_t num_samples);
89 84
90 // Ensures that methods are called on the same thread as the thread that 85 // Ensures that methods are called on the same thread as the thread that
91 // creates this object. 86 // creates this object.
92 rtc::ThreadChecker thread_checker_; 87 rtc::ThreadChecker thread_checker_;
93 88
94 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback()
95 // and it must outlive this object.
96 AudioTransport* audio_transport_cb_;
97
98 // TODO(henrika): given usage of thread checker, it should be possible to
99 // remove all locks in this class.
100 rtc::CriticalSection _critSect; 89 rtc::CriticalSection _critSect;
101 rtc::CriticalSection _critSectCb; 90 rtc::CriticalSection _critSectCb;
102 91
92 AudioTransport* _ptrCbAudioTransport;
93
103 // Task queue used to invoke LogStats() periodically. Tasks are executed on a 94 // Task queue used to invoke LogStats() periodically. Tasks are executed on a
104 // worker thread but it does not necessarily have to be the same thread for 95 // worker thread but it does not necessarily have to be the same thread for
105 // each task. 96 // each task.
106 rtc::TaskQueue task_queue_; 97 rtc::TaskQueue task_queue_;
107 98
108 // Ensures that the timer is only started once. 99 // Ensures that the timer is only started once.
109 bool timer_has_started_; 100 bool timer_has_started_;
110 101
111 // Sample rate in Hertz. 102 uint32_t _recSampleRate;
112 uint32_t rec_sample_rate_; 103 uint32_t _playSampleRate;
113 uint32_t play_sample_rate_;
114 104
115 // Number of audio channels. 105 size_t _recChannels;
116 size_t rec_channels_; 106 size_t _playChannels;
117 size_t play_channels_;
118 107
119 // selected recording channel (left/right/both) 108 // selected recording channel (left/right/both)
120 AudioDeviceModule::ChannelType rec_channel_; 109 AudioDeviceModule::ChannelType _recChannel;
121 110
122 // Number of bytes per audio sample (2 or 4). 111 // 2 or 4 depending on mono or stereo
123 size_t rec_bytes_per_sample_; 112 size_t _recBytesPerSample;
124 size_t play_bytes_per_sample_; 113 size_t _playBytesPerSample;
125 114
126 // Number of audio samples/bytes per 10ms. 115 // 10ms in stereo @ 96kHz
127 size_t rec_samples_per_10ms_; 116 int8_t _recBuffer[kMaxBufferSizeBytes];
128 size_t rec_bytes_per_10ms_;
129 size_t play_samples_per_10ms_;
130 size_t play_bytes_per_10ms_;
131 117
132 // Buffer used for recorded audio samples. Size is given by 118 // one sample <=> 2 or 4 bytes
133 // |rec_bytes_per_10ms_| and the buffer is allocated in InitRecording() on the 119 size_t _recSamples;
134 // main/creating thread. 120 size_t _recSize; // in bytes
135 std::unique_ptr<int8_t[]> rec_buffer_;
136 121
137 // Buffer used for audio samples to be played out. Size is given by 122 // 10ms in stereo @ 96kHz
138 // |play_bytes_per_10ms_| and the buffer is allocated in InitPlayout() on the 123 int8_t _playBuffer[kMaxBufferSizeBytes];
139 // main/creating thread.
140 std::unique_ptr<int8_t[]> play_buffer_;
141 124
142 // AGC parameters. 125 // one sample <=> 2 or 4 bytes
143 uint32_t current_mic_level_; 126 size_t _playSamples;
144 uint32_t new_mic_level_; 127 size_t _playSize; // in bytes
145 128
146 // Contains true of a key-press has been detected. 129 FileWrapper& _recFile;
147 bool typing_status_; 130 FileWrapper& _playFile;
148 131
149 // Delay values used by the AEC. 132 uint32_t _currentMicLevel;
150 int play_delay_ms_; 133 uint32_t _newMicLevel;
151 int rec_delay_ms_;
152 134
153 // Contains a clock-drift measurement. 135 bool _typingStatus;
154 int clock_drift_; 136
137 int _playDelayMS;
138 int _recDelayMS;
139 int _clockDrift;
140 int high_delay_counter_;
155 141
156 // Counts number of times LogStats() has been called. 142 // Counts number of times LogStats() has been called.
157 size_t num_stat_reports_; 143 size_t num_stat_reports_;
158 144
159 // Total number of recording callbacks where the source provides 10ms audio 145 // Total number of recording callbacks where the source provides 10ms audio
160 // data each time. 146 // data each time.
161 uint64_t rec_callbacks_; 147 uint64_t rec_callbacks_;
162 148
163 // Total number of recording callbacks stored at the last timer task. 149 // Total number of recording callbacks stored at the last timer task.
164 uint64_t last_rec_callbacks_; 150 uint64_t last_rec_callbacks_;
(...skipping 27 matching lines...) Expand all
192 // milliseconds) between two successive playout callbacks, and the stored 178 // milliseconds) between two successive playout callbacks, and the stored
193 // value is the number of times a given time difference was found. 179 // value is the number of times a given time difference was found.
194 // Writing to the array is done without a lock since it is only read once at 180 // Writing to the array is done without a lock since it is only read once at
195 // destruction when no audio is running. 181 // destruction when no audio is running.
196 uint32_t playout_diff_times_[kMaxDeltaTimeInMs + 1] = {0}; 182 uint32_t playout_diff_times_[kMaxDeltaTimeInMs + 1] = {0};
197 }; 183 };
198 184
199 } // namespace webrtc 185 } // namespace webrtc
200 186
201 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ 187 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698