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

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

Issue 510073002: Reland 501823002: Used native deinterleaved and float point format for the input streams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uint8 -> float Created 6 years, 3 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
« no previous file with comments | « no previous file | media/audio/mac/audio_low_latency_input_mac.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 27 matching lines...) Expand all
38 38
39 #include <AudioUnit/AudioUnit.h> 39 #include <AudioUnit/AudioUnit.h>
40 #include <CoreAudio/CoreAudio.h> 40 #include <CoreAudio/CoreAudio.h>
41 41
42 #include "base/cancelable_callback.h" 42 #include "base/cancelable_callback.h"
43 #include "base/memory/scoped_ptr.h" 43 #include "base/memory/scoped_ptr.h"
44 #include "base/synchronization/lock.h" 44 #include "base/synchronization/lock.h"
45 #include "media/audio/agc_audio_stream.h" 45 #include "media/audio/agc_audio_stream.h"
46 #include "media/audio/audio_io.h" 46 #include "media/audio/audio_io.h"
47 #include "media/audio/audio_parameters.h" 47 #include "media/audio/audio_parameters.h"
48 #include "media/base/audio_block_fifo.h"
49 48
50 namespace media { 49 namespace media {
51 50
51 class AudioBlockFifo;
52 class AudioBus; 52 class AudioBus;
53 class AudioManagerMac; 53 class AudioManagerMac;
54 class DataBuffer; 54 class DataBuffer;
55 55
56 class AUAudioInputStream : public AgcAudioStream<AudioInputStream> { 56 class AUAudioInputStream : public AgcAudioStream<AudioInputStream> {
57 public: 57 public:
58 // The ctor takes all the usual parameters, plus |manager| which is the 58 // The ctor takes all the usual parameters, plus |manager| which is the
59 // the audio manager who is creating this object. 59 // the audio manager who is creating this object.
60 AUAudioInputStream(AudioManagerMac* manager, 60 AUAudioInputStream(AudioManagerMac* manager,
61 const AudioParameters& input_params, 61 const AudioParameters& input_params,
62 AudioDeviceID audio_device_id); 62 AudioDeviceID audio_device_id);
63 // The dtor is typically called by the AudioManager only and it is usually 63 // The dtor is typically called by the AudioManager only and it is usually
64 // triggered by calling AudioInputStream::Close(). 64 // triggered by calling AudioInputStream::Close().
65 virtual ~AUAudioInputStream(); 65 virtual ~AUAudioInputStream();
66 66
67 // Implementation of AudioInputStream. 67 // Implementation of AudioInputStream.
68 virtual bool Open() OVERRIDE; 68 virtual bool Open() OVERRIDE;
69 virtual void Start(AudioInputCallback* callback) OVERRIDE; 69 virtual void Start(AudioInputCallback* callback) OVERRIDE;
70 virtual void Stop() OVERRIDE; 70 virtual void Stop() OVERRIDE;
71 virtual void Close() OVERRIDE; 71 virtual void Close() OVERRIDE;
72 virtual double GetMaxVolume() OVERRIDE; 72 virtual double GetMaxVolume() OVERRIDE;
73 virtual void SetVolume(double volume) OVERRIDE; 73 virtual void SetVolume(double volume) OVERRIDE;
74 virtual double GetVolume() OVERRIDE; 74 virtual double GetVolume() OVERRIDE;
75 75
76 // Returns the current hardware sample rate for the default input device. 76 // Returns the current hardware sample rate for the default input device.
77 MEDIA_EXPORT static int HardwareSampleRate(); 77 MEDIA_EXPORT static int HardwareSampleRate();
78 78
79 bool started() const { return started_; } 79 bool started() const { return started_; }
80 AudioUnit audio_unit() { return audio_unit_; } 80 AudioUnit audio_unit() { return audio_unit_; }
81 AudioBufferList* audio_buffer_list() { return &audio_buffer_list_; } 81 AudioBufferList* audio_buffer_list() { return audio_buffer_list_.get(); }
82 82
83 private: 83 private:
84 // AudioOutputUnit callback. 84 // AudioOutputUnit callback.
85 static OSStatus InputProc(void* user_data, 85 static OSStatus InputProc(void* user_data,
86 AudioUnitRenderActionFlags* flags, 86 AudioUnitRenderActionFlags* flags,
87 const AudioTimeStamp* time_stamp, 87 const AudioTimeStamp* time_stamp,
88 UInt32 bus_number, 88 UInt32 bus_number,
89 UInt32 number_of_frames, 89 UInt32 number_of_frames,
90 AudioBufferList* io_data); 90 AudioBufferList* io_data);
91 91
92 // Pushes recorded data to consumer of the input audio stream. 92 // Pushes recorded data to consumer of the input audio stream.
93 OSStatus Provide(UInt32 number_of_frames, AudioBufferList* io_data, 93 OSStatus Provide(UInt32 number_of_frames,
94 AudioBufferList* io_data,
94 const AudioTimeStamp* time_stamp); 95 const AudioTimeStamp* time_stamp);
95 96
96 // Gets the fixed capture hardware latency and store it during initialization. 97 // Gets the fixed capture hardware latency and store it during initialization.
97 // Returns 0 if not available. 98 // Returns 0 if not available.
98 double GetHardwareLatency(); 99 double GetHardwareLatency();
99 100
100 // Gets the current capture delay value. 101 // Gets the current capture delay value.
101 double GetCaptureLatency(const AudioTimeStamp* input_time_stamp); 102 double GetCaptureLatency(const AudioTimeStamp* input_time_stamp);
102 103
103 // Gets the number of channels for a stream of audio data. 104 // Gets the number of channels for a stream of audio data.
(...skipping 21 matching lines...) Expand all
125 126
126 // The special Audio Unit called AUHAL, which allows us to pass audio data 127 // The special Audio Unit called AUHAL, which allows us to pass audio data
127 // directly from a microphone, through the HAL, and to our application. 128 // directly from a microphone, through the HAL, and to our application.
128 // The AUHAL also enables selection of non default devices. 129 // The AUHAL also enables selection of non default devices.
129 AudioUnit audio_unit_; 130 AudioUnit audio_unit_;
130 131
131 // The UID refers to the current input audio device. 132 // The UID refers to the current input audio device.
132 AudioDeviceID input_device_id_; 133 AudioDeviceID input_device_id_;
133 134
134 // Provides a mechanism for encapsulating one or more buffers of audio data. 135 // Provides a mechanism for encapsulating one or more buffers of audio data.
135 AudioBufferList audio_buffer_list_; 136 scoped_ptr<AudioBufferList, base::FreeDeleter> audio_buffer_list_;
136 137
137 // Temporary storage for recorded data. The InputProc() renders into this 138 // Temporary storage for recorded data. The InputProc() renders into this
138 // array as soon as a frame of the desired buffer size has been recorded. 139 // array as soon as a frame of the desired buffer size has been recorded.
139 scoped_ptr<uint8[]> audio_data_buffer_; 140 scoped_ptr<float, base::AlignedFreeDeleter> audio_data_buffer_;
140 141
141 // True after successfull Start(), false after successful Stop(). 142 // True after successfull Start(), false after successful Stop().
142 bool started_; 143 bool started_;
143 144
144 // Fixed capture hardware latency in frames. 145 // Fixed capture hardware latency in frames.
145 double hardware_latency_frames_; 146 double hardware_latency_frames_;
146 147
147 // The number of channels in each frame of audio data, which is used 148 // The number of channels in each frame of audio data, which is used
148 // when querying the volume of each channel. 149 // when querying the volume of each channel.
149 int number_of_channels_in_frame_; 150 int number_of_channels_in_frame_;
150 151
151 // FIFO used to accumulates recorded data. 152 // Dynamically allocated FIFO used when CoreAudio asks for unexpected frame
152 media::AudioBlockFifo fifo_; 153 // sizes.
154 scoped_ptr<AudioBlockFifo> fifo_;
155
156 // AudioBus wrapper for delievering data via AudioSourceCallback::OnData().
157 scoped_ptr<AudioBus> audio_wrapper_;
153 158
154 // Used to defer Start() to workaround http://crbug.com/160920. 159 // Used to defer Start() to workaround http://crbug.com/160920.
155 base::CancelableClosure deferred_start_cb_; 160 base::CancelableClosure deferred_start_cb_;
156 161
157 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream); 162 DISALLOW_COPY_AND_ASSIGN(AUAudioInputStream);
158 }; 163 };
159 164
160 } // namespace media 165 } // namespace media
161 166
162 #endif // MEDIA_AUDIO_MAC_AUDIO_LOW_LATENCY_INPUT_MAC_H_ 167 #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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698