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

Side by Side Diff: media/audio/alsa/alsa_output.h

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // Creates an output stream based on the ALSA PCM interface. 5 // Creates an output stream based on the ALSA PCM interface.
6 // 6 //
7 // On device write failure, the stream will move itself to an invalid state. 7 // On device write failure, the stream will move itself to an invalid state.
8 // No more data will be pulled from the data source, or written to the device. 8 // No more data will be pulled from the data source, or written to the device.
9 // All calls to public API functions will either no-op themselves, or return an 9 // All calls to public API functions will either no-op themselves, or return an
10 // error if possible. Specifically, If the stream is in an error state, Open() 10 // error if possible. Specifically, If the stream is in an error state, Open()
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 static const char kDefaultDevice[]; 51 static const char kDefaultDevice[];
52 52
53 // Pass this to the AlsaPcmOutputStream if you want to attempt auto-selection 53 // Pass this to the AlsaPcmOutputStream if you want to attempt auto-selection
54 // of the audio device. 54 // of the audio device.
55 static const char kAutoSelectDevice[]; 55 static const char kAutoSelectDevice[];
56 56
57 // Prefix for device names to enable ALSA library resampling. 57 // Prefix for device names to enable ALSA library resampling.
58 static const char kPlugPrefix[]; 58 static const char kPlugPrefix[];
59 59
60 // The minimum latency that is accepted by the device. 60 // The minimum latency that is accepted by the device.
61 static const uint32 kMinLatencyMicros; 61 static const uint32_t kMinLatencyMicros;
62 62
63 // Create a PCM Output stream for the ALSA device identified by 63 // Create a PCM Output stream for the ALSA device identified by
64 // |device_name|. The AlsaPcmOutputStream uses |wrapper| to communicate with 64 // |device_name|. The AlsaPcmOutputStream uses |wrapper| to communicate with
65 // the alsa libraries, allowing for dependency injection during testing. All 65 // the alsa libraries, allowing for dependency injection during testing. All
66 // requesting of data, and writing to the alsa device will be done on 66 // requesting of data, and writing to the alsa device will be done on
67 // |message_loop|. 67 // |message_loop|.
68 // 68 //
69 // If unsure of what to use for |device_name|, use |kAutoSelectDevice|. 69 // If unsure of what to use for |device_name|, use |kAutoSelectDevice|.
70 AlsaPcmOutputStream(const std::string& device_name, 70 AlsaPcmOutputStream(const std::string& device_name,
71 const AudioParameters& params, 71 const AudioParameters& params,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 121
122 // Functions to get another packet from the data source and write it into the 122 // Functions to get another packet from the data source and write it into the
123 // ALSA device. 123 // ALSA device.
124 void BufferPacket(bool* source_exhausted); 124 void BufferPacket(bool* source_exhausted);
125 void WritePacket(); 125 void WritePacket();
126 void WriteTask(); 126 void WriteTask();
127 void ScheduleNextWrite(bool source_exhausted); 127 void ScheduleNextWrite(bool source_exhausted);
128 128
129 // Utility functions for talking with the ALSA API. 129 // Utility functions for talking with the ALSA API.
130 static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate); 130 static base::TimeDelta FramesToTimeDelta(int frames, double sample_rate);
131 std::string FindDeviceForChannels(uint32 channels); 131 std::string FindDeviceForChannels(uint32_t channels);
132 snd_pcm_sframes_t GetAvailableFrames(); 132 snd_pcm_sframes_t GetAvailableFrames();
133 snd_pcm_sframes_t GetCurrentDelay(); 133 snd_pcm_sframes_t GetCurrentDelay();
134 134
135 // Attempts to find the best matching linux audio device for the given number 135 // Attempts to find the best matching linux audio device for the given number
136 // of channels. This function will set |device_name_| and |channel_mixer_|. 136 // of channels. This function will set |device_name_| and |channel_mixer_|.
137 snd_pcm_t* AutoSelectDevice(uint32 latency); 137 snd_pcm_t* AutoSelectDevice(uint32_t latency);
138 138
139 // Functions to safeguard state transitions. All changes to the object state 139 // Functions to safeguard state transitions. All changes to the object state
140 // should go through these functions. 140 // should go through these functions.
141 bool CanTransitionTo(InternalState to); 141 bool CanTransitionTo(InternalState to);
142 InternalState TransitionTo(InternalState to); 142 InternalState TransitionTo(InternalState to);
143 InternalState state(); 143 InternalState state();
144 144
145 // Returns true when we're on the audio thread or if the audio thread's 145 // Returns true when we're on the audio thread or if the audio thread's
146 // message loop is NULL (which will happen during shutdown). 146 // message loop is NULL (which will happen during shutdown).
147 bool IsOnAudioThread() const; 147 bool IsOnAudioThread() const;
148 148
149 // API for Proxying calls to the AudioSourceCallback provided during 149 // API for Proxying calls to the AudioSourceCallback provided during
150 // Start(). 150 // Start().
151 // 151 //
152 // TODO(ajwong): This is necessary because the ownership semantics for the 152 // TODO(ajwong): This is necessary because the ownership semantics for the
153 // |source_callback_| object are incorrect in AudioRenderHost. The callback 153 // |source_callback_| object are incorrect in AudioRenderHost. The callback
154 // is passed into the output stream, but ownership is not transfered which 154 // is passed into the output stream, but ownership is not transfered which
155 // requires a synchronization on access of the |source_callback_| to avoid 155 // requires a synchronization on access of the |source_callback_| to avoid
156 // using a deleted callback. 156 // using a deleted callback.
157 int RunDataCallback(AudioBus* audio_bus, uint32 total_bytes_delay); 157 int RunDataCallback(AudioBus* audio_bus, uint32_t total_bytes_delay);
158 void RunErrorCallback(int code); 158 void RunErrorCallback(int code);
159 159
160 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to 160 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to
161 // release ownership of the currently registered callback. 161 // release ownership of the currently registered callback.
162 void set_source_callback(AudioSourceCallback* callback); 162 void set_source_callback(AudioSourceCallback* callback);
163 163
164 // Configuration constants from the constructor. Referenceable by all threads 164 // Configuration constants from the constructor. Referenceable by all threads
165 // since they are constants. 165 // since they are constants.
166 const std::string requested_device_name_; 166 const std::string requested_device_name_;
167 const snd_pcm_format_t pcm_format_; 167 const snd_pcm_format_t pcm_format_;
168 const uint32 channels_; 168 const uint32_t channels_;
169 const ChannelLayout channel_layout_; 169 const ChannelLayout channel_layout_;
170 const uint32 sample_rate_; 170 const uint32_t sample_rate_;
171 const uint32 bytes_per_sample_; 171 const uint32_t bytes_per_sample_;
172 const uint32 bytes_per_frame_; 172 const uint32_t bytes_per_frame_;
173 173
174 // Device configuration data. Populated after OpenTask() completes. 174 // Device configuration data. Populated after OpenTask() completes.
175 std::string device_name_; 175 std::string device_name_;
176 uint32 packet_size_; 176 uint32_t packet_size_;
177 base::TimeDelta latency_; 177 base::TimeDelta latency_;
178 uint32 bytes_per_output_frame_; 178 uint32_t bytes_per_output_frame_;
179 uint32 alsa_buffer_frames_; 179 uint32_t alsa_buffer_frames_;
180 180
181 // Flag indicating the code should stop reading from the data source or 181 // Flag indicating the code should stop reading from the data source or
182 // writing to the ALSA device. This is set because the device has entered 182 // writing to the ALSA device. This is set because the device has entered
183 // an unrecoverable error state, or the ClosedTask() has executed. 183 // an unrecoverable error state, or the ClosedTask() has executed.
184 bool stop_stream_; 184 bool stop_stream_;
185 185
186 // Wrapper class to invoke all the ALSA functions. 186 // Wrapper class to invoke all the ALSA functions.
187 AlsaWrapper* wrapper_; 187 AlsaWrapper* wrapper_;
188 188
189 // Audio manager that created us. Used to report that we've been closed. 189 // Audio manager that created us. Used to report that we've been closed.
190 AudioManagerBase* manager_; 190 AudioManagerBase* manager_;
191 191
192 // Message loop to use for polling. The object is owned by the AudioManager. 192 // Message loop to use for polling. The object is owned by the AudioManager.
193 // We hold a reference to the audio thread message loop since 193 // We hold a reference to the audio thread message loop since
194 // AudioManagerBase::ShutDown() can invalidate the message loop pointer 194 // AudioManagerBase::ShutDown() can invalidate the message loop pointer
195 // before the stream gets deleted. 195 // before the stream gets deleted.
196 base::MessageLoop* message_loop_; 196 base::MessageLoop* message_loop_;
197 197
198 // Handle to the actual PCM playback device. 198 // Handle to the actual PCM playback device.
199 snd_pcm_t* playback_handle_; 199 snd_pcm_t* playback_handle_;
200 200
201 scoped_ptr<media::SeekableBuffer> buffer_; 201 scoped_ptr<media::SeekableBuffer> buffer_;
202 uint32 frames_per_packet_; 202 uint32_t frames_per_packet_;
203 203
204 InternalState state_; 204 InternalState state_;
205 float volume_; // Volume level from 0.0 to 1.0. 205 float volume_; // Volume level from 0.0 to 1.0.
206 206
207 AudioSourceCallback* source_callback_; 207 AudioSourceCallback* source_callback_;
208 208
209 // Container for retrieving data from AudioSourceCallback::OnMoreData(). 209 // Container for retrieving data from AudioSourceCallback::OnMoreData().
210 scoped_ptr<AudioBus> audio_bus_; 210 scoped_ptr<AudioBus> audio_bus_;
211 211
212 // Channel mixer and temporary bus for the final mixed channel data. 212 // Channel mixer and temporary bus for the final mixed channel data.
213 scoped_ptr<ChannelMixer> channel_mixer_; 213 scoped_ptr<ChannelMixer> channel_mixer_;
214 scoped_ptr<AudioBus> mixed_audio_bus_; 214 scoped_ptr<AudioBus> mixed_audio_bus_;
215 215
216 // Allows us to run tasks on the AlsaPcmOutputStream instance which are 216 // Allows us to run tasks on the AlsaPcmOutputStream instance which are
217 // bound by its lifetime. 217 // bound by its lifetime.
218 // NOTE: Weak pointers must be invalidated before all other member variables. 218 // NOTE: Weak pointers must be invalidated before all other member variables.
219 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_; 219 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_;
220 220
221 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); 221 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream);
222 }; 222 };
223 223
224 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os, 224 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os,
225 AlsaPcmOutputStream::InternalState); 225 AlsaPcmOutputStream::InternalState);
226 226
227 }; // namespace media 227 }; // namespace media
228 228
229 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ 229 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698