| 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 21 matching lines...) Expand all Loading... |
| 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 <map> | 41 #include <map> |
| 42 #include <vector> |
| 42 | 43 |
| 43 #include "base/atomicops.h" | 44 #include "base/atomicops.h" |
| 44 #include "base/cancelable_callback.h" | 45 #include "base/cancelable_callback.h" |
| 45 #include "base/macros.h" | 46 #include "base/macros.h" |
| 46 #include "base/memory/scoped_ptr.h" | 47 #include "base/memory/scoped_ptr.h" |
| 48 #include "base/memory/weak_ptr.h" |
| 47 #include "base/threading/thread_checker.h" | 49 #include "base/threading/thread_checker.h" |
| 48 #include "base/time/time.h" | 50 #include "base/time/time.h" |
| 49 #include "base/timer/timer.h" | 51 #include "base/timer/timer.h" |
| 50 #include "media/audio/agc_audio_stream.h" | 52 #include "media/audio/agc_audio_stream.h" |
| 51 #include "media/audio/audio_io.h" | 53 #include "media/audio/audio_io.h" |
| 52 #include "media/audio/audio_parameters.h" | 54 #include "media/audio/audio_parameters.h" |
| 53 #include "media/base/audio_block_fifo.h" | 55 #include "media/base/audio_block_fifo.h" |
| 54 | 56 |
| 55 namespace media { | 57 namespace media { |
| 56 | 58 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // framework. These methods are called when device properties are changed. | 117 // framework. These methods are called when device properties are changed. |
| 116 static OSStatus OnDevicePropertyChanged( | 118 static OSStatus OnDevicePropertyChanged( |
| 117 AudioObjectID object_id, | 119 AudioObjectID object_id, |
| 118 UInt32 num_addresses, | 120 UInt32 num_addresses, |
| 119 const AudioObjectPropertyAddress addresses[], | 121 const AudioObjectPropertyAddress addresses[], |
| 120 void* context); | 122 void* context); |
| 121 OSStatus DevicePropertyChanged(AudioObjectID object_id, | 123 OSStatus DevicePropertyChanged(AudioObjectID object_id, |
| 122 UInt32 num_addresses, | 124 UInt32 num_addresses, |
| 123 const AudioObjectPropertyAddress addresses[]); | 125 const AudioObjectPropertyAddress addresses[]); |
| 124 | 126 |
| 127 // Updates the |device_property_changes_map_| on the main browser thread, |
| 128 // (CrBrowserMain) which is the same thread as this instance is created on. |
| 129 void DevicePropertyChangedOnMainThread(const std::vector<UInt32>& properties); |
| 130 |
| 125 // Registers OnDevicePropertyChanged() to receive notifications when device | 131 // Registers OnDevicePropertyChanged() to receive notifications when device |
| 126 // properties changes. | 132 // properties changes. |
| 127 void RegisterDeviceChangeListener(); | 133 void RegisterDeviceChangeListener(); |
| 128 // Stop listening for changes in device properties. | 134 // Stop listening for changes in device properties. |
| 129 void DeRegisterDeviceChangeListener(); | 135 void DeRegisterDeviceChangeListener(); |
| 130 | 136 |
| 131 // Gets the fixed capture hardware latency and store it during initialization. | 137 // Gets the fixed capture hardware latency and store it during initialization. |
| 132 // Returns 0 if not available. | 138 // Returns 0 if not available. |
| 133 double GetHardwareLatency(); | 139 double GetHardwareLatency(); |
| 134 | 140 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // callback audio thread. | 282 // callback audio thread. |
| 277 // These variables are only touched on the callback thread and then read | 283 // These variables are only touched on the callback thread and then read |
| 278 // in the dtor (when no longer receiving callbacks). | 284 // in the dtor (when no longer receiving callbacks). |
| 279 // NOTE: Float64 and UInt32 types are used for native API compatibility. | 285 // NOTE: Float64 and UInt32 types are used for native API compatibility. |
| 280 Float64 last_sample_time_; | 286 Float64 last_sample_time_; |
| 281 UInt32 last_number_of_frames_; | 287 UInt32 last_number_of_frames_; |
| 282 UInt32 total_lost_frames_; | 288 UInt32 total_lost_frames_; |
| 283 UInt32 largest_glitch_frames_; | 289 UInt32 largest_glitch_frames_; |
| 284 int glitches_detected_; | 290 int glitches_detected_; |
| 285 | 291 |
| 292 // Used to ensure DevicePropertyChangedOnMainThread() is not called when |
| 293 // this object is destroyed. |
| 294 // Note that, all member variables should appear before the WeakPtrFactory. |
| 295 base::WeakPtrFactory<AUAudioInputStream> weak_factory_; |
| 296 |
| 286 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); | 297 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); |
| 287 }; | 298 }; |
| 288 | 299 |
| 289 } // namespace media | 300 } // namespace media |
| 290 | 301 |
| 291 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ | 302 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ |
| OLD | NEW |