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 10 matching lines...) Expand all Loading... |
21 #include <CoreAudio/CoreAudio.h> | 21 #include <CoreAudio/CoreAudio.h> |
22 | 22 |
23 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
24 #include "base/synchronization/lock.h" | 24 #include "base/synchronization/lock.h" |
25 #include "media/audio/audio_io.h" | 25 #include "media/audio/audio_io.h" |
26 #include "media/audio/audio_parameters.h" | 26 #include "media/audio/audio_parameters.h" |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 | 29 |
30 class AudioManagerMac; | 30 class AudioManagerMac; |
| 31 class AudioPullFifo; |
31 | 32 |
32 // Implementation of AudioOuputStream for Mac OS X using the | 33 // Implementation of AudioOuputStream for Mac OS X using the |
33 // AUHAL Audio Unit present in OS 10.4 and later. | 34 // AUHAL Audio Unit present in OS 10.4 and later. |
34 // It is useful for low-latency output with optional synchronized | 35 // It is useful for low-latency output with optional synchronized |
35 // input. | 36 // input. |
36 // | 37 // |
37 // Overview of operation: | 38 // Overview of operation: |
38 // 1) An object of AUHALStream is created by the AudioManager | 39 // 1) An object of AUHALStream is created by the AudioManager |
39 // factory: audio_man->MakeAudioStream(). | 40 // factory: audio_man->MakeAudioStream(). |
40 // 2) Next some thread will call Open(), at that point the underlying | 41 // 2) Next some thread will call Open(), at that point the underlying |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 UInt32 bus_number, | 77 UInt32 bus_number, |
77 UInt32 number_of_frames, | 78 UInt32 number_of_frames, |
78 AudioBufferList* io_data); | 79 AudioBufferList* io_data); |
79 | 80 |
80 OSStatus Render(AudioUnitRenderActionFlags* flags, | 81 OSStatus Render(AudioUnitRenderActionFlags* flags, |
81 const AudioTimeStamp* output_time_stamp, | 82 const AudioTimeStamp* output_time_stamp, |
82 UInt32 bus_number, | 83 UInt32 bus_number, |
83 UInt32 number_of_frames, | 84 UInt32 number_of_frames, |
84 AudioBufferList* io_data); | 85 AudioBufferList* io_data); |
85 | 86 |
| 87 // Called by either |audio_fifo_| or Render() to provide audio data. |
| 88 void ProvideInput(int frame_delay, AudioBus* dest); |
| 89 |
86 // Helper method to enable input and output. | 90 // Helper method to enable input and output. |
87 bool EnableIO(bool enable, UInt32 scope); | 91 bool EnableIO(bool enable, UInt32 scope); |
88 | 92 |
89 // Sets the stream format on the AUHAL to PCM Float32 non-interleaved | 93 // Sets the stream format on the AUHAL to PCM Float32 non-interleaved |
90 // for the given number of channels on the given scope and element. | 94 // for the given number of channels on the given scope and element. |
91 // The created stream description will be stored in |desc|. | 95 // The created stream description will be stored in |desc|. |
92 bool SetStreamFormat(AudioStreamBasicDescription* desc, | 96 bool SetStreamFormat(AudioStreamBasicDescription* desc, |
93 int channels, | 97 int channels, |
94 UInt32 scope, | 98 UInt32 scope, |
95 UInt32 element); | 99 UInt32 element); |
96 | 100 |
97 // Creates the AUHAL, sets its stream format, buffer-size, etc. | 101 // Creates the AUHAL, sets its stream format, buffer-size, etc. |
98 bool ConfigureAUHAL(); | 102 bool ConfigureAUHAL(); |
99 | 103 |
100 // Creates the input and output busses. | 104 // Creates the input and output busses. |
101 void CreateIOBusses(); | 105 void CreateIOBusses(); |
102 | 106 |
103 // Gets the fixed playout device hardware latency and stores it. Returns 0 | 107 // Gets the fixed playout device hardware latency and stores it. Returns 0 |
104 // if not available. | 108 // if not available. |
105 double GetHardwareLatency(); | 109 double GetHardwareLatency(); |
106 | 110 |
107 // Gets the current playout latency value. | 111 // Gets the current playout latency value. |
108 double GetPlayoutLatency(const AudioTimeStamp* output_time_stamp); | 112 double GetPlayoutLatency(const AudioTimeStamp* output_time_stamp); |
109 | 113 |
110 // Our creator, the audio manager needs to be notified when we close. | 114 // Our creator, the audio manager needs to be notified when we close. |
111 AudioManagerMac* manager_; | 115 AudioManagerMac* const manager_; |
112 | 116 |
113 AudioParameters params_; | 117 const AudioParameters params_; |
114 // For convenience - same as in params_. | 118 // For convenience - same as in params_. |
115 int input_channels_; | 119 const int input_channels_; |
116 int output_channels_; | 120 const int output_channels_; |
117 | 121 |
118 // Buffer-size. | 122 // Buffer-size. |
119 size_t number_of_frames_; | 123 const size_t number_of_frames_; |
120 | 124 |
121 // Pointer to the object that will provide the audio samples. | 125 // Pointer to the object that will provide the audio samples. |
122 AudioSourceCallback* source_; | 126 AudioSourceCallback* source_; |
123 | 127 |
124 // Protects |source_|. Necessary since Render() calls seem to be in flight | 128 // Protects |source_|. Necessary since Render() calls seem to be in flight |
125 // when |audio_unit_| is supposedly stopped. See http://crbug.com/178765. | 129 // when |audio_unit_| is supposedly stopped. See http://crbug.com/178765. |
126 base::Lock source_lock_; | 130 base::Lock source_lock_; |
127 | 131 |
128 // Holds the stream format details such as bitrate. | 132 // Holds the stream format details such as bitrate. |
129 AudioStreamBasicDescription input_format_; | 133 AudioStreamBasicDescription input_format_; |
130 AudioStreamBasicDescription output_format_; | 134 AudioStreamBasicDescription output_format_; |
131 | 135 |
132 // The audio device to use with the AUHAL. | 136 // The audio device to use with the AUHAL. |
133 // We can potentially handle both input and output with this device. | 137 // We can potentially handle both input and output with this device. |
134 AudioDeviceID device_; | 138 const AudioDeviceID device_; |
135 | 139 |
136 // The AUHAL Audio Unit which talks to |device_|. | 140 // The AUHAL Audio Unit which talks to |device_|. |
137 AudioUnit audio_unit_; | 141 AudioUnit audio_unit_; |
138 | 142 |
139 // Volume level from 0 to 1. | 143 // Volume level from 0 to 1. |
140 float volume_; | 144 float volume_; |
141 | 145 |
142 // Fixed playout hardware latency in frames. | 146 // Fixed playout hardware latency in frames. |
143 double hardware_latency_frames_; | 147 double hardware_latency_frames_; |
144 | 148 |
145 // The flag used to stop the streaming. | 149 // The flag used to stop the streaming. |
146 bool stopped_; | 150 bool stopped_; |
147 | 151 |
148 // The flag used to indicate if the AudioManager has been notified of a | |
149 // potential device change. Reset to false during Start(). | |
150 bool notified_for_possible_device_change_; | |
151 | |
152 // The input AudioUnit renders its data here. | 152 // The input AudioUnit renders its data here. |
153 scoped_ptr<uint8[]> input_buffer_list_storage_; | 153 scoped_ptr<uint8[]> input_buffer_list_storage_; |
154 AudioBufferList* input_buffer_list_; | 154 AudioBufferList* input_buffer_list_; |
155 | 155 |
156 // Holds the actual data for |input_buffer_list_|. | 156 // Holds the actual data for |input_buffer_list_|. |
157 scoped_ptr<AudioBus> input_bus_; | 157 scoped_ptr<AudioBus> input_bus_; |
158 | 158 |
159 // Container for retrieving data from AudioSourceCallback::OnMoreIOData(). | 159 // Container for retrieving data from AudioSourceCallback::OnMoreIOData(). |
160 scoped_ptr<AudioBus> output_bus_; | 160 scoped_ptr<AudioBus> output_bus_; |
161 | 161 |
| 162 // Dynamically allocated FIFO used when CoreAudio asks for unexpected frame |
| 163 // sizes. |
| 164 scoped_ptr<AudioPullFifo> audio_fifo_; |
| 165 |
| 166 // Current buffer delay. Set by Render(). |
| 167 uint32 current_hardware_pending_bytes_; |
| 168 |
162 DISALLOW_COPY_AND_ASSIGN(AUHALStream); | 169 DISALLOW_COPY_AND_ASSIGN(AUHALStream); |
163 }; | 170 }; |
164 | 171 |
165 } // namespace media | 172 } // namespace media |
166 | 173 |
167 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ | 174 #endif // MEDIA_AUDIO_MAC_AUDIO_AUHAL_MAC_H_ |
OLD | NEW |