OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 of AudioInputStream for Mac OS X using the special AUHAL | 5 // Implementation of AudioInputStream for Mac OS X using the special AUHAL |
6 // input Audio Unit present in OS 10.4 and later. | 6 // input Audio Unit present in OS 10.4 and later. |
7 // The AUHAL input Audio Unit is for low-latency audio I/O. | 7 // The AUHAL input Audio Unit is for low-latency audio I/O. |
8 // | 8 // |
9 // Overview of operation: | 9 // Overview of operation: |
10 // | 10 // |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 #include <AudioUnit/AudioUnit.h> | 39 #include <AudioUnit/AudioUnit.h> |
40 #include <CoreAudio/CoreAudio.h> | 40 #include <CoreAudio/CoreAudio.h> |
41 | 41 |
42 #include "base/cancelable_callback.h" | 42 #include "base/cancelable_callback.h" |
43 #include "base/memory/scoped_ptr.h" | 43 #include "base/memory/scoped_ptr.h" |
44 #include "base/synchronization/lock.h" | 44 #include "base/synchronization/lock.h" |
45 #include "media/audio/agc_audio_stream.h" | 45 #include "media/audio/agc_audio_stream.h" |
46 #include "media/audio/audio_io.h" | 46 #include "media/audio/audio_io.h" |
47 #include "media/audio/audio_parameters.h" | 47 #include "media/audio/audio_parameters.h" |
48 #include "media/base/seekable_buffer.h" | |
49 | 48 |
50 namespace media { | 49 namespace media { |
51 | 50 |
52 class AudioBus; | 51 class AudioBus; |
| 52 class AudioFifo; |
53 class AudioManagerMac; | 53 class AudioManagerMac; |
54 class DataBuffer; | 54 class DataBuffer; |
55 | 55 |
56 class AUAudioInputStream : public AgcAudioStream<AudioInputStream> { | 56 class AUAudioInputStream : public AgcAudioStream<AudioInputStream> { |
57 public: | 57 public: |
58 // The ctor takes all the usual parameters, plus |manager| which is the | 58 // The ctor takes all the usual parameters, plus |manager| which is the |
59 // the audio manager who is creating this object. | 59 // the audio manager who is creating this object. |
60 AUAudioInputStream(AudioManagerMac* manager, | 60 AUAudioInputStream(AudioManagerMac* manager, |
61 const AudioParameters& input_params, | 61 const AudioParameters& input_params, |
62 const AudioParameters& output_params, | |
63 AudioDeviceID audio_device_id); | 62 AudioDeviceID audio_device_id); |
64 // The dtor is typically called by the AudioManager only and it is usually | 63 // The dtor is typically called by the AudioManager only and it is usually |
65 // triggered by calling AudioInputStream::Close(). | 64 // triggered by calling AudioInputStream::Close(). |
66 virtual ~AUAudioInputStream(); | 65 virtual ~AUAudioInputStream(); |
67 | 66 |
68 // Implementation of AudioInputStream. | 67 // Implementation of AudioInputStream. |
69 virtual bool Open() OVERRIDE; | 68 virtual bool Open() OVERRIDE; |
70 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 69 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
71 virtual void Stop() OVERRIDE; | 70 virtual void Stop() OVERRIDE; |
72 virtual void Close() OVERRIDE; | 71 virtual void Close() OVERRIDE; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 void HandleError(OSStatus err); | 107 void HandleError(OSStatus err); |
109 | 108 |
110 // Helper function to check if the volume control is avialable on specific | 109 // Helper function to check if the volume control is avialable on specific |
111 // channel. | 110 // channel. |
112 bool IsVolumeSettableOnChannel(int channel); | 111 bool IsVolumeSettableOnChannel(int channel); |
113 | 112 |
114 // Our creator, the audio manager needs to be notified when we close. | 113 // Our creator, the audio manager needs to be notified when we close. |
115 AudioManagerMac* manager_; | 114 AudioManagerMac* manager_; |
116 | 115 |
117 // Contains the desired number of audio frames in each callback. | 116 // Contains the desired number of audio frames in each callback. |
118 size_t number_of_frames_; | 117 const size_t number_of_frames_; |
119 | 118 |
120 // Pointer to the object that will receive the recorded audio samples. | 119 // Pointer to the object that will receive the recorded audio samples. |
121 AudioInputCallback* sink_; | 120 AudioInputCallback* sink_; |
122 | 121 |
123 // Structure that holds the desired output format of the stream. | 122 // Structure that holds the desired output format of the stream. |
124 // Note that, this format can differ from the device(=input) format. | 123 // Note that, this format can differ from the device(=input) format. |
125 AudioStreamBasicDescription format_; | 124 AudioStreamBasicDescription format_; |
126 | 125 |
127 // The special Audio Unit called AUHAL, which allows us to pass audio data | 126 // The special Audio Unit called AUHAL, which allows us to pass audio data |
128 // directly from a microphone, through the HAL, and to our application. | 127 // directly from a microphone, through the HAL, and to our application. |
129 // The AUHAL also enables selection of non default devices. | 128 // The AUHAL also enables selection of non default devices. |
130 AudioUnit audio_unit_; | 129 AudioUnit audio_unit_; |
131 | 130 |
132 // The UID refers to the current input audio device. | 131 // The UID refers to the current input audio device. |
133 AudioDeviceID input_device_id_; | 132 AudioDeviceID input_device_id_; |
134 | 133 |
135 // Provides a mechanism for encapsulating one or more buffers of audio data. | 134 // Provides a mechanism for encapsulating one or more buffers of audio data. |
136 AudioBufferList audio_buffer_list_; | 135 AudioBufferList audio_buffer_list_; |
137 | 136 |
138 // Temporary storage for recorded data. The InputProc() renders into this | 137 // Temporary storage for recorded data. The InputProc() renders into this |
139 // array as soon as a frame of the desired buffer size has been recorded. | 138 // array as soon as a frame of the desired buffer size has been recorded. |
140 scoped_ptr<uint8[]> audio_data_buffer_; | 139 scoped_ptr<uint8[]> audio_data_buffer_; |
141 | 140 |
142 // True after successfull Start(), false after successful Stop(). | 141 // True after successfull Start(), false after successful Stop(). |
143 bool started_; | 142 bool started_; |
144 | 143 |
145 // Fixed capture hardware latency in frames. | 144 // Fixed capture hardware latency in frames. |
146 double hardware_latency_frames_; | 145 double hardware_latency_frames_; |
147 | 146 |
148 // Delay due to the FIFO in bytes. | |
149 int fifo_delay_bytes_; | |
150 | |
151 // The number of channels in each frame of audio data, which is used | 147 // The number of channels in each frame of audio data, which is used |
152 // when querying the volume of each channel. | 148 // when querying the volume of each channel. |
153 int number_of_channels_in_frame_; | 149 int number_of_channels_in_frame_; |
154 | 150 |
155 // Accumulates recorded data packets until the requested size has been stored. | 151 // Dynamically allocated FIFO used to accumulates recorded data when |
156 scoped_ptr<media::SeekableBuffer> fifo_; | 152 // CoreAudio delivers non-requested frame size of data. |
157 | 153 scoped_ptr<media::AudioFifo> fifo_; |
158 // Intermediate storage of data from the FIFO before sending it to the | |
159 // client using the OnData() callback. | |
160 scoped_refptr<media::DataBuffer> data_; | |
161 | |
162 // The client requests that the recorded data shall be delivered using | |
163 // OnData() callbacks where each callback contains this amount of bytes. | |
164 int requested_size_bytes_; | |
165 | 154 |
166 // Used to defer Start() to workaround http://crbug.com/160920. | 155 // Used to defer Start() to workaround http://crbug.com/160920. |
167 base::CancelableClosure deferred_start_cb_; | 156 base::CancelableClosure deferred_start_cb_; |
168 | 157 |
169 // Extra audio bus used for storage of deinterleaved data for the OnData | 158 // Audio bus used for storage of deinterleaved data for the OnData callback. |
170 // callback. | |
171 scoped_ptr<media::AudioBus> audio_bus_; | 159 scoped_ptr<media::AudioBus> audio_bus_; |
172 | 160 |
| 161 // Audio bus used to convert interleaved data to deinterleaved data before |
| 162 // storing data to FIFO or delivering data via OnData callback. |
| 163 scoped_ptr<media::AudioBus> audio_wrapper_; |
| 164 |
173 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); | 165 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); |
174 }; | 166 }; |
175 | 167 |
176 } // namespace media | 168 } // namespace media |
177 | 169 |
178 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 170 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
OLD | NEW |