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/race_checker.h" | |
| 16 #include "webrtc/base/task_queue.h" | 17 #include "webrtc/base/task_queue.h" |
| 18 #include "webrtc/base/thread_annotations.h" | |
| 17 #include "webrtc/base/thread_checker.h" | 19 #include "webrtc/base/thread_checker.h" |
| 18 #include "webrtc/modules/audio_device/include/audio_device.h" | 20 #include "webrtc/modules/audio_device/include/audio_device.h" |
| 19 #include "webrtc/system_wrappers/include/file_wrapper.h" | 21 #include "webrtc/system_wrappers/include/file_wrapper.h" |
| 20 #include "webrtc/typedefs.h" | 22 #include "webrtc/typedefs.h" |
| 21 | 23 |
| 22 namespace webrtc { | 24 namespace webrtc { |
| 23 // Delta times between two successive playout callbacks are limited to this | 25 // Delta times between two successive playout callbacks are limited to this |
| 24 // value before added to an internal array. | 26 // value before added to an internal array. |
| 25 const size_t kMaxDeltaTimeInMs = 500; | 27 const size_t kMaxDeltaTimeInMs = 500; |
| 26 // TODO(henrika): remove when no longer used by external client. | 28 // TODO(henrika): remove when no longer used by external client. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 40 virtual ~AudioDeviceBuffer(); | 42 virtual ~AudioDeviceBuffer(); |
| 41 | 43 |
| 42 void SetId(uint32_t id) {}; | 44 void SetId(uint32_t id) {}; |
| 43 int32_t RegisterAudioCallback(AudioTransport* audio_callback); | 45 int32_t RegisterAudioCallback(AudioTransport* audio_callback); |
| 44 | 46 |
| 45 void StartPlayout(); | 47 void StartPlayout(); |
| 46 void StartRecording(); | 48 void StartRecording(); |
| 47 void StopPlayout(); | 49 void StopPlayout(); |
| 48 void StopRecording(); | 50 void StopRecording(); |
| 49 | 51 |
| 50 int32_t SetRecordingSampleRate(uint32_t fsHz); | 52 int32_t SetRecordingSampleRate(uint32_t fsHz) LOCKS_EXCLUDED(lock_); |
| 51 int32_t SetPlayoutSampleRate(uint32_t fsHz); | 53 int32_t SetPlayoutSampleRate(uint32_t fsHz) LOCKS_EXCLUDED(lock_); |
| 52 int32_t RecordingSampleRate() const; | 54 int32_t RecordingSampleRate() const; |
| 53 int32_t PlayoutSampleRate() const; | 55 int32_t PlayoutSampleRate() const; |
| 54 | 56 |
| 55 int32_t SetRecordingChannels(size_t channels); | 57 int32_t SetRecordingChannels(size_t channels) LOCKS_EXCLUDED(lock_); |
| 56 int32_t SetPlayoutChannels(size_t channels); | 58 int32_t SetPlayoutChannels(size_t channels) LOCKS_EXCLUDED(lock_); |
| 57 size_t RecordingChannels() const; | 59 size_t RecordingChannels() const; |
| 58 size_t PlayoutChannels() const; | 60 size_t PlayoutChannels() const; |
| 59 int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel); | 61 int32_t SetRecordingChannel(const AudioDeviceModule::ChannelType channel); |
| 60 int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const; | 62 int32_t RecordingChannel(AudioDeviceModule::ChannelType& channel) const; |
| 61 | 63 |
| 62 virtual int32_t SetRecordedBuffer(const void* audio_buffer, | 64 virtual int32_t SetRecordedBuffer(const void* audio_buffer, |
| 63 size_t num_samples); | 65 size_t num_samples) LOCKS_EXCLUDED(lock_); |
| 64 int32_t SetCurrentMicLevel(uint32_t level); | 66 int32_t SetCurrentMicLevel(uint32_t level); |
| 65 virtual void SetVQEData(int play_delay_ms, int rec_delay_ms, int clock_drift); | 67 virtual void SetVQEData(int play_delay_ms, int rec_delay_ms, int clock_drift); |
| 66 virtual int32_t DeliverRecordedData(); | 68 virtual int32_t DeliverRecordedData() LOCKS_EXCLUDED(lock_); |
| 67 uint32_t NewMicLevel() const; | 69 uint32_t NewMicLevel() const; |
| 68 | 70 |
| 69 virtual int32_t RequestPlayoutData(size_t num_samples); | 71 virtual int32_t RequestPlayoutData(size_t num_samples) LOCKS_EXCLUDED(lock_); |
| 70 virtual int32_t GetPlayoutData(void* audio_buffer); | 72 virtual int32_t GetPlayoutData(void* audio_buffer) LOCKS_EXCLUDED(lock_); |
| 71 | 73 |
| 72 // TODO(henrika): these methods should not be used and does not contain any | 74 // TODO(henrika): these methods should not be used and does not contain any |
| 73 // valid implementation. Investigate the possibility to either remove them | 75 // valid implementation. Investigate the possibility to either remove them |
| 74 // or add a proper implementation if needed. | 76 // or add a proper implementation if needed. |
| 75 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); | 77 int32_t StartInputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
| 76 int32_t StopInputFileRecording(); | 78 int32_t StopInputFileRecording(); |
| 77 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); | 79 int32_t StartOutputFileRecording(const char fileName[kAdmMaxFileNameSize]); |
| 78 int32_t StopOutputFileRecording(); | 80 int32_t StopOutputFileRecording(); |
| 79 | 81 |
| 80 int32_t SetTypingStatus(bool typing_status); | 82 int32_t SetTypingStatus(bool typing_status); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 98 void UpdateRecStats(int16_t max_abs, size_t num_samples); | 100 void UpdateRecStats(int16_t max_abs, size_t num_samples); |
| 99 void UpdatePlayStats(int16_t max_abs, size_t num_samples); | 101 void UpdatePlayStats(int16_t max_abs, size_t num_samples); |
| 100 | 102 |
| 101 // Clears all members tracking stats for recording and playout. | 103 // Clears all members tracking stats for recording and playout. |
| 102 // These methods both run on the task queue. | 104 // These methods both run on the task queue. |
| 103 void ResetRecStats(); | 105 void ResetRecStats(); |
| 104 void ResetPlayStats(); | 106 void ResetPlayStats(); |
| 105 | 107 |
| 106 // Ensures that methods are called on the same thread as the thread that | 108 // Ensures that methods are called on the same thread as the thread that |
| 107 // creates this object. | 109 // creates this object. |
| 108 rtc::ThreadChecker thread_checker_; | 110 rtc::ThreadChecker thread_checker_; |
|
kwiberg-webrtc
2016/11/01 15:53:50
No member variable is annotated as being protected
henrika_webrtc
2016/11/02 10:29:18
As we discussed. Will try to fix that.
| |
| 109 | 111 |
| 112 // Verifies that access to some members are serialized. | |
| 113 rtc::RaceChecker race_checker_; | |
| 114 | |
| 115 rtc::CriticalSection lock_; | |
| 116 | |
| 110 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() | 117 // Raw pointer to AudioTransport instance. Supplied to RegisterAudioCallback() |
| 111 // and it must outlive this object. | 118 // and it must outlive this object. It is not possible to change this member |
| 112 AudioTransport* audio_transport_cb_; | 119 // while any media is active. It is possible to start media without calling |
| 113 | 120 // RegisterAudioCallback() but that will lead to ignored audio callbacks in |
| 114 // TODO(henrika): given usage of thread checker, it should be possible to | 121 // both directions where native audio will be acive but no audio samples will |
| 115 // remove all locks in this class. | 122 // be transported. |
| 116 rtc::CriticalSection lock_; | 123 AudioTransport* audio_transport_cb_ GUARDED_BY(race_checker_); |
| 117 rtc::CriticalSection lock_cb_; | |
| 118 | 124 |
| 119 // Task queue used to invoke LogStats() periodically. Tasks are executed on a | 125 // Task queue used to invoke LogStats() periodically. Tasks are executed on a |
| 120 // worker thread but it does not necessarily have to be the same thread for | 126 // worker thread but it does not necessarily have to be the same thread for |
| 121 // each task. | 127 // each task. |
| 122 rtc::TaskQueue task_queue_; | 128 rtc::TaskQueue task_queue_; |
|
kwiberg-webrtc
2016/11/01 15:53:50
I presume this object is itself thread safe, so th
henrika_webrtc
2016/11/02 10:29:18
Yes, dtor and ctor are thread checked and I can't
| |
| 123 | 129 |
| 124 // Keeps track of if playout/recording are active or not. A combination | 130 // Keeps track of if playout/recording are active or not. A combination |
| 125 // of these states are used to determine when to start and stop the timer. | 131 // 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. | 132 // Only used on the creating thread and not used to control any media flow. |
| 127 bool playing_; | 133 bool playing_; |
| 128 bool recording_; | 134 bool recording_; |
|
kwiberg-webrtc
2016/11/01 15:53:50
These are not annotated. It's usually good to make
henrika_webrtc
2016/11/02 10:29:18
Acknowledged.
| |
| 129 | 135 |
| 130 // Sample rate in Hertz. | 136 // Sample rate in Hertz. |
| 131 uint32_t rec_sample_rate_; | 137 uint32_t rec_sample_rate_ GUARDED_BY(lock_); |
| 132 uint32_t play_sample_rate_; | 138 uint32_t play_sample_rate_ GUARDED_BY(lock_); |
| 133 | 139 |
| 134 // Number of audio channels. | 140 // Number of audio channels. |
| 135 size_t rec_channels_; | 141 size_t rec_channels_ GUARDED_BY(lock_); |
| 136 size_t play_channels_; | 142 size_t play_channels_ GUARDED_BY(lock_); |
| 137 | |
| 138 // Number of bytes per audio sample (2 or 4). | |
| 139 size_t rec_bytes_per_sample_; | |
| 140 size_t play_bytes_per_sample_; | |
| 141 | 143 |
| 142 // Byte buffer used for recorded audio samples. Size can be changed | 144 // Byte buffer used for recorded audio samples. Size can be changed |
| 143 // dynamically. | 145 // dynamically. |
| 144 rtc::Buffer rec_buffer_; | 146 rtc::Buffer rec_buffer_ GUARDED_BY(race_checker_); |
| 145 | 147 |
| 146 // Buffer used for audio samples to be played out. Size can be changed | 148 // Buffer used for audio samples to be played out. Size can be changed |
| 147 // dynamically. | 149 // dynamically. |
| 148 rtc::Buffer play_buffer_; | 150 rtc::Buffer play_buffer_ GUARDED_BY(race_checker_); |
| 149 | 151 |
| 150 // AGC parameters. | 152 // AGC parameters. |
| 151 uint32_t current_mic_level_; | 153 uint32_t current_mic_level_; |
| 152 uint32_t new_mic_level_; | 154 uint32_t new_mic_level_; |
|
kwiberg-webrtc
2016/11/01 15:53:50
More unannotated variables. Please annotate all of
henrika_webrtc
2016/11/02 10:29:18
Acknowledged.
| |
| 153 | 155 |
| 154 // Contains true of a key-press has been detected. | 156 // Contains true of a key-press has been detected. |
| 155 bool typing_status_; | 157 bool typing_status_; |
| 156 | 158 |
| 157 // Delay values used by the AEC. | 159 // Delay values used by the AEC. |
| 158 int play_delay_ms_; | 160 int play_delay_ms_; |
| 159 int rec_delay_ms_; | 161 int rec_delay_ms_; |
| 160 | 162 |
| 161 // Contains a clock-drift measurement. | 163 // Contains a clock-drift measurement. |
| 162 int clock_drift_; | 164 int clock_drift_; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 uint64_t rec_start_time_; | 226 uint64_t rec_start_time_; |
| 225 | 227 |
| 226 // Set to true at construction and modified to false as soon as one audio- | 228 // Set to true at construction and modified to false as soon as one audio- |
| 227 // level estimate larger than zero is detected. | 229 // level estimate larger than zero is detected. |
| 228 bool only_silence_recorded_; | 230 bool only_silence_recorded_; |
| 229 }; | 231 }; |
| 230 | 232 |
| 231 } // namespace webrtc | 233 } // namespace webrtc |
| 232 | 234 |
| 233 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ | 235 #endif // WEBRTC_MODULES_AUDIO_DEVICE_AUDIO_DEVICE_BUFFER_H_ |
| OLD | NEW |