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

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

Issue 1695303002: Adds Media.Audio.InputDevicePropertyChangedMac UMA stat on Mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Device notifier now alive for complete session Created 4 years, 10 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
OLDNEW
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 20 matching lines...) Expand all
31 // 1) Hardware latency, which includes Audio Unit latency, audio device 31 // 1) Hardware latency, which includes Audio Unit latency, audio device
32 // latency; 32 // latency;
33 // 2) The delay between the actual recording instant and the time when the 33 // 2) The delay between the actual recording instant and the time when the
34 // data packet is provided as a callback. 34 // data packet is provided as a callback.
35 // 35 //
36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 36 #ifndef MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_
37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 37 #define MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_
38 38
39 #include <AudioUnit/AudioUnit.h> 39 #include <AudioUnit/AudioUnit.h>
40 #include <CoreAudio/CoreAudio.h> 40 #include <CoreAudio/CoreAudio.h>
41 #include <stddef.h> 41 #include <map>
42 #include <stdint.h>
43 42
44 #include "base/atomicops.h" 43 #include "base/atomicops.h"
45 #include "base/cancelable_callback.h" 44 #include "base/cancelable_callback.h"
46 #include "base/macros.h" 45 #include "base/macros.h"
47 #include "base/memory/scoped_ptr.h" 46 #include "base/memory/scoped_ptr.h"
48 #include "base/synchronization/lock.h" 47 #include "base/synchronization/lock.h"
49 #include "base/threading/thread_checker.h" 48 #include "base/threading/thread_checker.h"
50 #include "base/time/time.h" 49 #include "base/time/time.h"
51 #include "base/timer/timer.h" 50 #include "base/timer/timer.h"
52 #include "media/audio/agc_audio_stream.h" 51 #include "media/audio/agc_audio_stream.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 86
88 // Returns true if the audio unit is active/running. 87 // Returns true if the audio unit is active/running.
89 // The result is based on the kAudioOutputUnitProperty_IsRunning property 88 // The result is based on the kAudioOutputUnitProperty_IsRunning property
90 // which exists for output units. 89 // which exists for output units.
91 bool IsRunning(); 90 bool IsRunning();
92 91
93 AudioDeviceID device_id() const { return input_device_id_; } 92 AudioDeviceID device_id() const { return input_device_id_; }
94 size_t requested_buffer_size() const { return number_of_frames_; } 93 size_t requested_buffer_size() const { return number_of_frames_; }
95 94
96 private: 95 private:
96 static const AudioObjectPropertyAddress kDeviceChangePropertyAddress;
97
97 // Callback functions called on a real-time priority I/O thread from the audio 98 // Callback functions called on a real-time priority I/O thread from the audio
98 // unit. These methods are called when recorded audio is available. 99 // unit. These methods are called when recorded audio is available.
99 static OSStatus DataIsAvailable(void* context, 100 static OSStatus DataIsAvailable(void* context,
100 AudioUnitRenderActionFlags* flags, 101 AudioUnitRenderActionFlags* flags,
101 const AudioTimeStamp* time_stamp, 102 const AudioTimeStamp* time_stamp,
102 UInt32 bus_number, 103 UInt32 bus_number,
103 UInt32 number_of_frames, 104 UInt32 number_of_frames,
104 AudioBufferList* io_data); 105 AudioBufferList* io_data);
105 OSStatus OnDataIsAvailable(AudioUnitRenderActionFlags* flags, 106 OSStatus OnDataIsAvailable(AudioUnitRenderActionFlags* flags,
106 const AudioTimeStamp* time_stamp, 107 const AudioTimeStamp* time_stamp,
107 UInt32 bus_number, 108 UInt32 bus_number,
108 UInt32 number_of_frames); 109 UInt32 number_of_frames);
109 110
110 // Pushes recorded data to consumer of the input audio stream. 111 // Pushes recorded data to consumer of the input audio stream.
111 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data, 112 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data,
112 const AudioTimeStamp* time_stamp); 113 const AudioTimeStamp* time_stamp);
113 114
115 // Callback functions called on different system threads from the Core Audio
116 // framework. These methods are called when device properties are changed.
117 static OSStatus OnDevicePropertyChanged(
118 AudioObjectID object_id,
119 UInt32 num_addresses,
120 const AudioObjectPropertyAddress addresses[],
121 void* context);
122 OSStatus DevicePropertyChanged(AudioObjectID object_id,
123 UInt32 num_addresses,
124 const AudioObjectPropertyAddress addresses[]);
125
126 // Registers OnDevicePropertyChanged() to receive notifications when device
127 // properties changes.
128 void RegisterDeviceChangeListener();
129 // Stop listening for changes in device properties.
130 void DeRegisterDeviceChangeListener();
131
114 // Gets the fixed capture hardware latency and store it during initialization. 132 // Gets the fixed capture hardware latency and store it during initialization.
115 // Returns 0 if not available. 133 // Returns 0 if not available.
116 double GetHardwareLatency(); 134 double GetHardwareLatency();
117 135
118 // Gets the current capture delay value. 136 // Gets the current capture delay value.
119 double GetCaptureLatency(const AudioTimeStamp* input_time_stamp); 137 double GetCaptureLatency(const AudioTimeStamp* input_time_stamp);
120 138
121 // Gets the number of channels for a stream of audio data. 139 // Gets the number of channels for a stream of audio data.
122 int GetNumberOfChannelsFromStream(); 140 int GetNumberOfChannelsFromStream();
123 141
(...skipping 12 matching lines...) Expand all
136 // to call InputProc() as it should. This method is called once when a timer 154 // to call InputProc() as it should. This method is called once when a timer
137 // expires 5 seconds after calling Start(). 155 // expires 5 seconds after calling Start().
138 void CheckInputStartupSuccess(); 156 void CheckInputStartupSuccess();
139 157
140 // Uninitializes the audio unit if needed. 158 // Uninitializes the audio unit if needed.
141 void CloseAudioUnit(); 159 void CloseAudioUnit();
142 160
143 // Adds extra UMA stats when it has been detected that startup failed. 161 // Adds extra UMA stats when it has been detected that startup failed.
144 void AddHistogramsForFailedStartup(); 162 void AddHistogramsForFailedStartup();
145 163
164 // Scans the map of all available property changes (notification types) and
165 // filters out some that make sense to add to UMA stats.
166 void AddDevicePropertyChangesToUMA(const std::string& name);
167
146 // Verifies that Open(), Start(), Stop() and Close() are all called on the 168 // Verifies that Open(), Start(), Stop() and Close() are all called on the
147 // creating thread which is the main browser thread (CrBrowserMain) on Mac. 169 // creating thread which is the main browser thread (CrBrowserMain) on Mac.
148 base::ThreadChecker thread_checker_; 170 base::ThreadChecker thread_checker_;
149 171
150 // Our creator, the audio manager needs to be notified when we close. 172 // Our creator, the audio manager needs to be notified when we close.
151 AudioManagerMac* const manager_; 173 AudioManagerMac* const manager_;
152 174
153 // Contains the desired number of audio frames in each callback. 175 // Contains the desired number of audio frames in each callback.
154 const size_t number_of_frames_; 176 const size_t number_of_frames_;
155 177
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // See AudioManagerMac::ShouldDeferStreamStart() for details. 233 // See AudioManagerMac::ShouldDeferStreamStart() for details.
212 bool start_was_deferred_; 234 bool start_was_deferred_;
213 235
214 // Set to true if the audio unit's IO buffer was changed when Open() was 236 // Set to true if the audio unit's IO buffer was changed when Open() was
215 // called. 237 // called.
216 bool buffer_size_was_changed_; 238 bool buffer_size_was_changed_;
217 239
218 // Set to true once when AudioUnitRender() succeeds for the first time. 240 // Set to true once when AudioUnitRender() succeeds for the first time.
219 bool audio_unit_render_has_worked_; 241 bool audio_unit_render_has_worked_;
220 242
243 // Maps unique representations of device property notification types and
244 // number of times we have been notified about a change in such a type.
tommi (sloooow) - chröme 2016/02/19 15:17:33 can you add a note about what thread is allowed to
henrika (OOO until Aug 14) 2016/02/22 12:32:52 Tommi, FYI, each callback can come from "any" thre
tommi (sloooow) - chröme 2016/02/22 14:16:43 If we don't need a lock, I'd prefer to not have a
245 std::map<UInt32, int> device_property_changes_map_;
246
247 // Set to true when we are listening for changes in device properties.
248 bool device_listener_is_active_;
tommi (sloooow) - chröme 2016/02/19 15:17:33 modified/checked on what threads?
henrika (OOO until Aug 14) 2016/02/22 12:32:52 Done, also uses DCHECK to ensure proper calling.
249
221 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); 250 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream);
222 }; 251 };
223 252
224 } // namespace media 253 } // namespace media
225 254
226 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 255 #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