OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // |
11 // - An object of AUAudioInputStream is created by the AudioManager | 11 // - An object of AUAudioInputStream is created by the AudioManager |
12 // factory: audio_man->MakeAudioInputStream(). | 12 // factory: audio_man->MakeAudioInputStream(). |
13 // - Next some thread will call Open(), at that point the underlying | 13 // - Next some thread will call Open(), at that point the underlying |
14 // AUHAL output Audio Unit is created and configured. | 14 // AUHAL output Audio Unit is created and configured. |
15 // - Then some thread will call Start(sink). | 15 // - Then some thread will call Start(sink). |
16 // Then the Audio Unit is started which creates its own thread which | 16 // Then the Audio Unit is started which creates its own thread which |
17 // periodically will provide the sink with more data as buffers are being | 17 // periodically will provide the sink with more data as buffers are being |
18 // produced/recorded. | 18 // produced/recorded. |
19 // - At some point some thread will call Stop(), which we handle by directly | 19 // - At some point some thread will call Stop(), which we handle by directly |
20 // stopping the AUHAL output Audio Unit. | 20 // stopping the AUHAL output Audio Unit. |
21 // - The same thread that called stop will call Close() where we cleanup | 21 // - The same thread that called stop will call Close() where we cleanup |
22 // and notify the audio manager, which likely will destroy this object. | 22 // and notify the audio manager, which likely will destroy this object. |
23 // | 23 // |
24 // Implementation notes: | 24 // Implementation notes: |
25 // | 25 // |
26 // - It is recommended to first acquire the native sample rate of the default | 26 // - It is recommended to first acquire the native sample rate of the default |
27 // input device and then use the same rate when creating this object. | 27 // input device and then use the same rate when creating this object. |
28 // Use AUAudioInputStream::HardwareSampleRate() to retrieve the sample rate. | 28 // Use AUAudioInputStream::HardwareSampleRate() to retrieve the sample rate. |
29 // - Calling Close() also leads to self destruction. | 29 // - Calling Close() also leads to self destruction. |
30 // - The latency consists of two parts: 1, hardware latency, which includes | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
Can be cleaned up. Thanks.
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
31 // Audio Unit latency, audio device latency and audio stream latency; 2, | |
32 // the delay between now and the scheduled time stamp that tells when the | |
33 // data we are providing is going to hit the hardware. | |
30 // | 34 // |
31 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 35 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
32 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 36 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
33 | 37 |
34 #include <AudioUnit/AudioUnit.h> | 38 #include <AudioUnit/AudioUnit.h> |
35 | 39 |
36 #include "base/memory/scoped_ptr.h" | 40 #include "base/memory/scoped_ptr.h" |
37 #include "base/synchronization/lock.h" | 41 #include "base/synchronization/lock.h" |
38 #include "media/audio/audio_io.h" | 42 #include "media/audio/audio_io.h" |
39 #include "media/audio/audio_parameters.h" | 43 #include "media/audio/audio_parameters.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
60 static double HardwareSampleRate(); | 64 static double HardwareSampleRate(); |
61 | 65 |
62 bool started() const { return started_; } | 66 bool started() const { return started_; } |
63 AudioUnit audio_unit() { return audio_unit_; } | 67 AudioUnit audio_unit() { return audio_unit_; } |
64 AudioBufferList* audio_buffer_list() { return &audio_buffer_list_; } | 68 AudioBufferList* audio_buffer_list() { return &audio_buffer_list_; } |
65 | 69 |
66 private: | 70 private: |
67 // AudioOutputUnit callback. | 71 // AudioOutputUnit callback. |
68 static OSStatus InputProc(void* user_data, | 72 static OSStatus InputProc(void* user_data, |
69 AudioUnitRenderActionFlags* flags, | 73 AudioUnitRenderActionFlags* flags, |
70 const AudioTimeStamp* time_stamp, | 74 const AudioTimeStamp* output_time_stamp, |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
remove output
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
71 UInt32 bus_number, | 75 UInt32 bus_number, |
72 UInt32 number_of_frames, | 76 UInt32 number_of_frames, |
73 AudioBufferList* io_data); | 77 AudioBufferList* io_data); |
74 | 78 |
75 // Pushes recorded data to consumer of the input audio stream. | 79 // Pushes recorded data to consumer of the input audio stream. |
76 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data); | 80 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data, |
81 const AudioTimeStamp* time_stamp); | |
82 | |
83 // Get capture hardware latency, this is called only when initiating | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
"Gets the fixed capture hardware latency and store
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
84 // the input Audio Unit. | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
I would remove 'input' and call the method StoreHa
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
85 void UpdateHardwareLatency(); | |
86 | |
87 // Update capture delay value. | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
Updates the current capture delay value.
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
88 void UpdateCaptureLatency(const AudioTimeStamp* input_time_stamp); | |
77 | 89 |
78 // Issues the OnError() callback to the |sink_|. | 90 // Issues the OnError() callback to the |sink_|. |
79 void HandleError(OSStatus err); | 91 void HandleError(OSStatus err); |
80 | 92 |
81 // Our creator, the audio manager needs to be notified when we close. | 93 // Our creator, the audio manager needs to be notified when we close. |
82 AudioManagerMac* manager_; | 94 AudioManagerMac* manager_; |
83 | 95 |
84 // Contains the desired number of audio frames in each callback. | 96 // Contains the desired number of audio frames in each callback. |
85 size_t number_of_frames_; | 97 size_t number_of_frames_; |
86 | 98 |
87 // Pointer to the object that will receive the recorded audio samples. | 99 // Pointer to the object that will receive the recorded audio samples. |
88 AudioInputCallback* sink_; | 100 AudioInputCallback* sink_; |
89 | 101 |
90 // Structure that holds the desired output format of the stream. | 102 // Structure that holds the desired output format of the stream. |
91 // Note that, this format can differ from the device(=input) format. | 103 // Note that, this format can differ from the device(=input) format. |
92 AudioStreamBasicDescription format_; | 104 AudioStreamBasicDescription format_; |
93 | 105 |
94 // The special Audio Unit called AUHAL, which allows us to pass audio data | 106 // The special Audio Unit called AUHAL, which allows us to pass audio data |
95 // directly from a microphone, through the HAL, and to our application. | 107 // directly from a microphone, through the HAL, and to our application. |
96 // The AUHAL also enables selection of non default devices. | 108 // The AUHAL also enables selection of non default devices. |
97 AudioUnit audio_unit_; | 109 AudioUnit audio_unit_; |
98 | 110 |
111 // The UID refers to the input audio device. | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
Which device?
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
112 AudioDeviceID input_device_id_; | |
113 | |
99 // Provides a mechanism for encapsulating one or more buffers of audio data. | 114 // Provides a mechanism for encapsulating one or more buffers of audio data. |
100 AudioBufferList audio_buffer_list_; | 115 AudioBufferList audio_buffer_list_; |
101 | 116 |
102 // Temporary storage for recorded data. The InputProc() renders into this | 117 // Temporary storage for recorded data. The InputProc() renders into this |
103 // array as soon as a frame of the desired buffer size has been recorded. | 118 // array as soon as a frame of the desired buffer size has been recorded. |
104 scoped_array<uint8> audio_data_buffer_; | 119 scoped_array<uint8> audio_data_buffer_; |
105 | 120 |
106 // True after successfull Start(), false after successful Stop(). | 121 // True after successfull Start(), false after successful Stop(). |
107 bool started_; | 122 bool started_; |
108 | 123 |
124 // Capture hardware latency in millisecond, the value is updated when | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
Remove last part (, the value). Add 'fixed'.
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
125 // initiating the input Audio Unit. | |
126 uint32 hardware_latency_ms_; | |
127 | |
128 // Capture latency in millisecond. | |
henrika (OOO until Aug 14)
2011/10/12 12:10:11
Current ..
no longer working on chromium
2011/10/12 15:28:47
Done.
| |
129 uint32 capture_latency_ms_; | |
130 | |
109 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); | 131 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); |
110 }; | 132 }; |
111 | 133 |
112 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 134 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
OLD | NEW |