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