Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: media/audio/mac/audio_low_latency_input_mac.h

Issue 8234009: Adding input and output delay estimation for mac. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: remove the deprecated AudioHardwareGetProperty and update comments Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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:
31 // 1, Hardware latency, which includes Audio Unit latency, audio device
henrika (OOO until Aug 14) 2011/10/21 07:27:23 I would use 1) and 2)
no longer working on chromium 2011/10/21 12:21:46 Done.
32 // latency and audio stream latency;
33 // 2, The delay between now and the scheduled time stamp that tells when the
henrika (OOO until Aug 14) 2011/10/21 07:27:23 Please rewrite this comment from scratch since it
no longer working on chromium 2011/10/21 12:21:46 Done.
34 // data we are providing is going to reach the hardware.
30 // 35 //
31 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_
32 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_
33 38
34 #include <AudioUnit/AudioUnit.h> 39 #include <AudioUnit/AudioUnit.h>
35 40
36 #include "base/memory/scoped_ptr.h" 41 #include "base/memory/scoped_ptr.h"
37 #include "base/synchronization/lock.h" 42 #include "base/synchronization/lock.h"
38 #include "media/audio/audio_io.h" 43 #include "media/audio/audio_io.h"
39 #include "media/audio/audio_parameters.h" 44 #include "media/audio/audio_parameters.h"
(...skipping 26 matching lines...) Expand all
66 private: 71 private:
67 // AudioOutputUnit callback. 72 // AudioOutputUnit callback.
68 static OSStatus InputProc(void* user_data, 73 static OSStatus InputProc(void* user_data,
69 AudioUnitRenderActionFlags* flags, 74 AudioUnitRenderActionFlags* flags,
70 const AudioTimeStamp* time_stamp, 75 const AudioTimeStamp* time_stamp,
71 UInt32 bus_number, 76 UInt32 bus_number,
72 UInt32 number_of_frames, 77 UInt32 number_of_frames,
73 AudioBufferList* io_data); 78 AudioBufferList* io_data);
74 79
75 // Pushes recorded data to consumer of the input audio stream. 80 // Pushes recorded data to consumer of the input audio stream.
76 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data); 81 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data,
82 const AudioTimeStamp* time_stamp);
83
84 // Gets the fixed capture hardware latency and store it during initialization.
85 // Returns 0 if not available.
86 double GetHardwareLatency();
87
88 // Gets the current capture delay value.
89 double GetCaptureLatency(const AudioTimeStamp* input_time_stamp);
77 90
78 // Issues the OnError() callback to the |sink_|. 91 // Issues the OnError() callback to the |sink_|.
79 void HandleError(OSStatus err); 92 void HandleError(OSStatus err);
80 93
81 // Our creator, the audio manager needs to be notified when we close. 94 // Our creator, the audio manager needs to be notified when we close.
82 AudioManagerMac* manager_; 95 AudioManagerMac* manager_;
83 96
84 // Contains the desired number of audio frames in each callback. 97 // Contains the desired number of audio frames in each callback.
85 size_t number_of_frames_; 98 size_t number_of_frames_;
86 99
87 // Pointer to the object that will receive the recorded audio samples. 100 // Pointer to the object that will receive the recorded audio samples.
88 AudioInputCallback* sink_; 101 AudioInputCallback* sink_;
89 102
90 // Structure that holds the desired output format of the stream. 103 // Structure that holds the desired output format of the stream.
91 // Note that, this format can differ from the device(=input) format. 104 // Note that, this format can differ from the device(=input) format.
92 AudioStreamBasicDescription format_; 105 AudioStreamBasicDescription format_;
93 106
94 // The special Audio Unit called AUHAL, which allows us to pass audio data 107 // 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. 108 // directly from a microphone, through the HAL, and to our application.
96 // The AUHAL also enables selection of non default devices. 109 // The AUHAL also enables selection of non default devices.
97 AudioUnit audio_unit_; 110 AudioUnit audio_unit_;
98 111
112 // The UID refers to the current input audio device.
113 AudioDeviceID input_device_id_;
114
99 // Provides a mechanism for encapsulating one or more buffers of audio data. 115 // Provides a mechanism for encapsulating one or more buffers of audio data.
100 AudioBufferList audio_buffer_list_; 116 AudioBufferList audio_buffer_list_;
101 117
102 // Temporary storage for recorded data. The InputProc() renders into this 118 // 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. 119 // array as soon as a frame of the desired buffer size has been recorded.
104 scoped_array<uint8> audio_data_buffer_; 120 scoped_array<uint8> audio_data_buffer_;
105 121
106 // True after successfull Start(), false after successful Stop(). 122 // True after successfull Start(), false after successful Stop().
107 bool started_; 123 bool started_;
108 124
125 // Fixed capture hardware latency in frames.
126 double hardware_latency_frames_;
127
109 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); 128 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream);
110 }; 129 };
111 130
112 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 131 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | media/audio/mac/audio_low_latency_input_mac.cc » ('j') | media/audio/mac/audio_low_latency_input_mac.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698