| 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. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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/cancelable_callback.h" | 27 #include "base/cancelable_callback.h" |
| 28 #include "base/compiler_specific.h" | 28 #include "base/compiler_specific.h" |
| 29 #include "base/macros.h" | 29 #include "base/macros.h" |
| 30 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 31 #include "base/threading/thread_checker.h" | 31 #include "base/threading/thread_checker.h" |
| 32 #include "base/time/time.h" |
| 32 #include "media/audio/audio_io.h" | 33 #include "media/audio/audio_io.h" |
| 33 #include "media/audio/audio_manager.h" | 34 #include "media/audio/audio_manager.h" |
| 34 #include "media/base/audio_parameters.h" | 35 #include "media/base/audio_parameters.h" |
| 35 | 36 |
| 36 namespace media { | 37 namespace media { |
| 37 | 38 |
| 38 class AudioManagerMac; | 39 class AudioManagerMac; |
| 39 class AudioPullFifo; | 40 class AudioPullFifo; |
| 40 | 41 |
| 41 // Implementation of AudioOuputStream for Mac OS X using the | 42 // Implementation of AudioOuputStream for Mac OS X using the |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 121 |
| 121 // Creates the AUHAL, sets its stream format, buffer-size, etc. | 122 // Creates the AUHAL, sets its stream format, buffer-size, etc. |
| 122 bool ConfigureAUHAL(); | 123 bool ConfigureAUHAL(); |
| 123 | 124 |
| 124 // Uninitializes audio_unit_ if needed. | 125 // Uninitializes audio_unit_ if needed. |
| 125 void CloseAudioUnit(); | 126 void CloseAudioUnit(); |
| 126 | 127 |
| 127 // Creates the input and output busses. | 128 // Creates the input and output busses. |
| 128 void CreateIOBusses(); | 129 void CreateIOBusses(); |
| 129 | 130 |
| 130 // Gets the fixed playout device hardware latency and stores it. Returns 0 | 131 // Returns the fixed hardware latency, or zero if not available. |
| 131 // if not available. | 132 base::TimeDelta GetHardwareLatency(); |
| 132 double GetHardwareLatency(); | |
| 133 | 133 |
| 134 // Gets the current playout latency value. | 134 // Returns the playout time for a given AudioTimeStamp. |
| 135 double GetPlayoutLatency(const AudioTimeStamp* output_time_stamp); | 135 base::TimeTicks GetPlayoutTime(const AudioTimeStamp* output_time_stamp); |
| 136 | 136 |
| 137 // Updates playout timestamp, current lost frames, and total lost frames and | 137 // Updates playout timestamp, current lost frames, and total lost frames and |
| 138 // glitches. | 138 // glitches. |
| 139 void UpdatePlayoutTimestamp(const AudioTimeStamp* timestamp); | 139 void UpdatePlayoutTimestamp(const AudioTimeStamp* timestamp); |
| 140 | 140 |
| 141 // Called from the dtor and when the stream is reset. | 141 // Called from the dtor and when the stream is reset. |
| 142 void ReportAndResetStats(); | 142 void ReportAndResetStats(); |
| 143 | 143 |
| 144 // Our creator, the audio manager needs to be notified when we close. | 144 // Our creator, the audio manager needs to be notified when we close. |
| 145 AudioManagerMac* const manager_; | 145 AudioManagerMac* const manager_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 // The audio device to use with the AUHAL. | 171 // The audio device to use with the AUHAL. |
| 172 // We can potentially handle both input and output with this device. | 172 // We can potentially handle both input and output with this device. |
| 173 const AudioDeviceID device_; | 173 const AudioDeviceID device_; |
| 174 | 174 |
| 175 // The AUHAL Audio Unit which talks to |device_|. | 175 // The AUHAL Audio Unit which talks to |device_|. |
| 176 AudioUnit audio_unit_; | 176 AudioUnit audio_unit_; |
| 177 | 177 |
| 178 // Volume level from 0 to 1. | 178 // Volume level from 0 to 1. |
| 179 float volume_; | 179 float volume_; |
| 180 | 180 |
| 181 // Fixed playout hardware latency in frames. | 181 // Fixed playout hardware latency. |
| 182 double hardware_latency_frames_; | 182 base::TimeDelta hardware_latency_; |
| 183 | 183 |
| 184 // This flag will be set to false while we're actively receiving callbacks. | 184 // This flag will be set to false while we're actively receiving callbacks. |
| 185 bool stopped_; | 185 bool stopped_; |
| 186 | 186 |
| 187 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 187 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 188 std::unique_ptr<AudioBus> output_bus_; | 188 std::unique_ptr<AudioBus> output_bus_; |
| 189 | 189 |
| 190 // Dynamically allocated FIFO used when CoreAudio asks for unexpected frame | 190 // Dynamically allocated FIFO used when CoreAudio asks for unexpected frame |
| 191 // sizes. | 191 // sizes. |
| 192 std::unique_ptr<AudioPullFifo> audio_fifo_; | 192 std::unique_ptr<AudioPullFifo> audio_fifo_; |
| 193 | 193 |
| 194 // Current buffer delay. Set by Render(). | 194 // Current playout time. Set by Render(). |
| 195 uint32_t current_hardware_pending_bytes_; | 195 base::TimeTicks current_playout_time_; |
| 196 | 196 |
| 197 // Lost frames not yet reported to the provider. Increased in | 197 // Lost frames not yet reported to the provider. Increased in |
| 198 // UpdatePlayoutTimestamp() if any lost frame since last time. Forwarded to | 198 // UpdatePlayoutTimestamp() if any lost frame since last time. Forwarded to |
| 199 // the provider and reset in ProvideInput(). | 199 // the provider and reset in ProvideInput(). |
| 200 uint32_t current_lost_frames_; | 200 uint32_t current_lost_frames_; |
| 201 | 201 |
| 202 // Stores the timestamp of the previous audio buffer requested by the OS. | 202 // Stores the timestamp of the previous audio buffer requested by the OS. |
| 203 // We use this in combination with |last_number_of_frames_| to detect when | 203 // We use this in combination with |last_number_of_frames_| to detect when |
| 204 // the OS has decided to skip rendering frames (i.e. a glitch). | 204 // the OS has decided to skip rendering frames (i.e. a glitch). |
| 205 // This can happen in case of high CPU load or excessive blocking on the | 205 // This can happen in case of high CPU load or excessive blocking on the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 222 // Used to make sure control functions (Start(), Stop() etc) are called on the | 222 // Used to make sure control functions (Start(), Stop() etc) are called on the |
| 223 // right thread. | 223 // right thread. |
| 224 base::ThreadChecker thread_checker_; | 224 base::ThreadChecker thread_checker_; |
| 225 | 225 |
| 226 DISALLOW_COPY_AND_ASSIGN(AUHALStream); | 226 DISALLOW_COPY_AND_ASSIGN(AUHALStream); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 } // namespace media | 229 } // namespace media |
| 230 | 230 |
| 231 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ | 231 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ |
| OLD | NEW |