| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Implementation notes: | 5 // Implementation notes: |
| 6 // | 6 // |
| 7 // - It is recommended to first acquire the native sample rate of the default | 7 // - It is recommended to first acquire the native sample rate of the default |
| 8 // output device and then use the same rate when creating this object. | 8 // output device and then use the same rate when creating this object. |
| 9 // Use AudioManagerMac::HardwareSampleRate() to retrieve the sample rate. | 9 // Use AudioManagerMac::HardwareSampleRate() to retrieve the sample rate. |
| 10 // - Calling Close() also leads to self destruction. | 10 // - Calling Close() also leads to self destruction. |
| 11 // - The latency consists of two parts: | 11 // - The latency consists of two parts: |
| 12 // 1) Hardware latency, which includes Audio Unit latency, audio device | 12 // 1) Hardware latency, which includes Audio Unit latency, audio device |
| 13 // latency; | 13 // latency; |
| 14 // 2) The delay between the moment getting the callback and the scheduled time | 14 // 2) The delay between the moment getting the callback and the scheduled time |
| 15 // stamp that tells when the data is going to be played out. | 15 // stamp that tells when the data is going to be played out. |
| 16 // | 16 // |
| 17 #ifndef MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ | 17 #ifndef MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ |
| 18 #define MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ | 18 #define MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ |
| 19 | 19 |
| 20 #include <AudioUnit/AudioUnit.h> | 20 #include <AudioUnit/AudioUnit.h> |
| 21 #include <CoreAudio/CoreAudio.h> | 21 #include <CoreAudio/CoreAudio.h> |
| 22 #include <stddef.h> | 22 #include <stddef.h> |
| 23 #include <stdint.h> | 23 #include <stdint.h> |
| 24 | 24 |
| 25 #include <memory> | 25 #include <memory> |
| 26 | 26 |
| 27 #include "base/atomicops.h" |
| 27 #include "base/cancelable_callback.h" | 28 #include "base/cancelable_callback.h" |
| 28 #include "base/compiler_specific.h" | 29 #include "base/compiler_specific.h" |
| 29 #include "base/macros.h" | 30 #include "base/macros.h" |
| 30 #include "base/synchronization/lock.h" | 31 #include "base/synchronization/lock.h" |
| 31 #include "base/threading/thread_checker.h" | 32 #include "base/threading/thread_checker.h" |
| 32 #include "media/audio/audio_io.h" | 33 #include "media/audio/audio_io.h" |
| 33 #include "media/base/audio_parameters.h" | 34 #include "media/base/audio_parameters.h" |
| 34 | 35 |
| 35 namespace media { | 36 namespace media { |
| 36 | 37 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 // Implementation of AudioOutputStream. | 82 // Implementation of AudioOutputStream. |
| 82 bool Open() override; | 83 bool Open() override; |
| 83 void Close() override; | 84 void Close() override; |
| 84 void Start(AudioSourceCallback* callback) override; | 85 void Start(AudioSourceCallback* callback) override; |
| 85 void Stop() override; | 86 void Stop() override; |
| 86 void SetVolume(double volume) override; | 87 void SetVolume(double volume) override; |
| 87 void GetVolume(double* volume) override; | 88 void GetVolume(double* volume) override; |
| 88 | 89 |
| 89 AudioDeviceID device_id() const { return device_; } | 90 AudioDeviceID device_id() const { return device_; } |
| 90 size_t requested_buffer_size() const { return number_of_frames_; } | 91 size_t requested_buffer_size() const { return number_of_frames_; } |
| 92 size_t actual_buffer_size() const { |
| 93 return base::subtle::Acquire_Load(&actual_io_buffer_frame_size_); |
| 94 } |
| 95 AudioUnit audio_unit() const { return audio_unit_; } |
| 91 | 96 |
| 92 private: | 97 private: |
| 93 // AUHAL callback. | 98 // AUHAL callback. |
| 94 static OSStatus InputProc(void* user_data, | 99 static OSStatus InputProc(void* user_data, |
| 95 AudioUnitRenderActionFlags* flags, | 100 AudioUnitRenderActionFlags* flags, |
| 96 const AudioTimeStamp* time_stamp, | 101 const AudioTimeStamp* time_stamp, |
| 97 UInt32 bus_number, | 102 UInt32 bus_number, |
| 98 UInt32 number_of_frames, | 103 UInt32 number_of_frames, |
| 99 AudioBufferList* io_data); | 104 AudioBufferList* io_data); |
| 100 | 105 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 // Called from the dtor and when the stream is reset. | 143 // Called from the dtor and when the stream is reset. |
| 139 void ReportAndResetStats(); | 144 void ReportAndResetStats(); |
| 140 | 145 |
| 141 // Our creator, the audio manager needs to be notified when we close. | 146 // Our creator, the audio manager needs to be notified when we close. |
| 142 AudioManagerMac* const manager_; | 147 AudioManagerMac* const manager_; |
| 143 | 148 |
| 144 const AudioParameters params_; | 149 const AudioParameters params_; |
| 145 // For convenience - same as in params_. | 150 // For convenience - same as in params_. |
| 146 const int output_channels_; | 151 const int output_channels_; |
| 147 | 152 |
| 148 // Buffer-size. | 153 // Size of audio buffer requested at construction. The actual buffer size |
| 154 // is given by |actual_io_buffer_frame_size_| and it can differ from the |
| 155 // requested size. |
| 149 const size_t number_of_frames_; | 156 const size_t number_of_frames_; |
| 150 | 157 |
| 158 // Size of I/O buffers measured in number of audio frames. Default value is |
| 159 // 512 but we always try to set it to a vaule as close as possible to |
| 160 // |number_of_frames_|. It might not be possible to match the requested size, |
| 161 // especially not if the utilized device is used by other streams as well. |
| 162 // This value will be the same as |number_of_frames_requested_| but they are |
| 163 // used for different purpuses and updated at different times. |
| 164 // The member is read by the audio manager on the main browser thread |
| 165 // (CrBrowserMain) and modified by this class on the Core Audio I/O thread. |
| 166 base::subtle::Atomic32 actual_io_buffer_frame_size_; |
| 167 |
| 151 // Stores the number of frames that we actually get callbacks for. | 168 // Stores the number of frames that we actually get callbacks for. |
| 152 // This may be different from what we ask for, so we use this for stats in | 169 // This may be different from what we ask for, so we use this for stats in |
| 153 // order to understand how often this happens and what are the typical values. | 170 // order to understand how often this happens and what are the typical values. |
| 154 size_t number_of_frames_requested_; | 171 size_t number_of_frames_requested_; |
| 155 | 172 |
| 156 // Pointer to the object that will provide the audio samples. | 173 // Pointer to the object that will provide the audio samples. |
| 157 AudioSourceCallback* source_; | 174 AudioSourceCallback* source_; |
| 158 | 175 |
| 159 // Protects |source_|. Necessary since Render() calls seem to be in flight | 176 // Protects |source_|. Necessary since Render() calls seem to be in flight |
| 160 // when |audio_unit_| is supposedly stopped. See http://crbug.com/178765. | 177 // when |audio_unit_| is supposedly stopped. See http://crbug.com/178765. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // Used to make sure control functions (Start(), Stop() etc) are called on the | 231 // Used to make sure control functions (Start(), Stop() etc) are called on the |
| 215 // right thread. | 232 // right thread. |
| 216 base::ThreadChecker thread_checker_; | 233 base::ThreadChecker thread_checker_; |
| 217 | 234 |
| 218 DISALLOW_COPY_AND_ASSIGN(AUHALStream); | 235 DISALLOW_COPY_AND_ASSIGN(AUHALStream); |
| 219 }; | 236 }; |
| 220 | 237 |
| 221 } // namespace media | 238 } // namespace media |
| 222 | 239 |
| 223 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ | 240 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ |
| OLD | NEW |