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

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: increase the delay precision 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
32 // latency and audio stream latency;
33 // 2, The delay between now and the scheduled time stamp that tells when the
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 // Get the fixed capture hardware latency and store it during initialization.
85 void StoreHardwareLatency();
86
87 // Updates the current capture delay value.
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 current input audio device.
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 // Fixed capture hardware latency in frames.
125 double hardware_latency_frames_;
scherkus (not reviewing) 2011/10/19 16:35:15 frames are typically integers -- any reason why we
126
127 // Current capture latency in frames.
128 double capture_latency_frames_;
129
109 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); 130 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream);
110 }; 131 };
111 132
112 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 133 #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