| OLD | NEW |
| 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() |
| 11 // will return false, and Start() will call OnError() immediately on the | 11 // will return false, and Start() will call OnError() immediately on the |
| 12 // provided callback. | 12 // provided callback. |
| 13 // | 13 // |
| 14 // If the stream is successfully opened, Close() must be called. After Close | 14 // If the stream is successfully opened, Close() must be called. After Close |
| 15 // has been called, the object should be regarded as deleted and not touched. | 15 // has been called, the object should be regarded as deleted and not touched. |
| 16 // | 16 // |
| 17 // AlsaPcmOutputStream is a single threaded class that should only be used from | 17 // AlsaPcmOutputStream is a single threaded class that should only be used from |
| 18 // the audio thread. When modifying the code in this class, please read the | 18 // the audio thread. When modifying the code in this class, please read the |
| 19 // threading assumptions at the top of the implementation. | 19 // threading assumptions at the top of the implementation. |
| 20 | 20 |
| 21 #ifndef MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ | 21 #ifndef MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ |
| 22 #define MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ | 22 #define MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ |
| 23 | 23 |
| 24 #include <alsa/asoundlib.h> | 24 #include <alsa/asoundlib.h> |
| 25 #include <stdint.h> | 25 #include <stdint.h> |
| 26 | 26 |
| 27 #include <memory> |
| 27 #include <string> | 28 #include <string> |
| 28 | 29 |
| 29 #include "base/compiler_specific.h" | 30 #include "base/compiler_specific.h" |
| 30 #include "base/gtest_prod_util.h" | 31 #include "base/gtest_prod_util.h" |
| 31 #include "base/macros.h" | 32 #include "base/macros.h" |
| 32 #include "base/memory/scoped_ptr.h" | |
| 33 #include "base/memory/weak_ptr.h" | 33 #include "base/memory/weak_ptr.h" |
| 34 #include "base/time/time.h" | 34 #include "base/time/time.h" |
| 35 #include "media/audio/audio_io.h" | 35 #include "media/audio/audio_io.h" |
| 36 #include "media/audio/audio_parameters.h" | 36 #include "media/audio/audio_parameters.h" |
| 37 | 37 |
| 38 namespace base { | 38 namespace base { |
| 39 class MessageLoop; | 39 class MessageLoop; |
| 40 } | 40 } |
| 41 | 41 |
| 42 namespace media { | 42 namespace media { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // Message loop to use for polling. The object is owned by the AudioManager. | 194 // Message loop to use for polling. The object is owned by the AudioManager. |
| 195 // We hold a reference to the audio thread message loop since | 195 // We hold a reference to the audio thread message loop since |
| 196 // AudioManagerBase::ShutDown() can invalidate the message loop pointer | 196 // AudioManagerBase::ShutDown() can invalidate the message loop pointer |
| 197 // before the stream gets deleted. | 197 // before the stream gets deleted. |
| 198 base::MessageLoop* message_loop_; | 198 base::MessageLoop* message_loop_; |
| 199 | 199 |
| 200 // Handle to the actual PCM playback device. | 200 // Handle to the actual PCM playback device. |
| 201 snd_pcm_t* playback_handle_; | 201 snd_pcm_t* playback_handle_; |
| 202 | 202 |
| 203 scoped_ptr<media::SeekableBuffer> buffer_; | 203 std::unique_ptr<media::SeekableBuffer> buffer_; |
| 204 uint32_t frames_per_packet_; | 204 uint32_t frames_per_packet_; |
| 205 | 205 |
| 206 InternalState state_; | 206 InternalState state_; |
| 207 float volume_; // Volume level from 0.0 to 1.0. | 207 float volume_; // Volume level from 0.0 to 1.0. |
| 208 | 208 |
| 209 AudioSourceCallback* source_callback_; | 209 AudioSourceCallback* source_callback_; |
| 210 | 210 |
| 211 // Container for retrieving data from AudioSourceCallback::OnMoreData(). | 211 // Container for retrieving data from AudioSourceCallback::OnMoreData(). |
| 212 scoped_ptr<AudioBus> audio_bus_; | 212 std::unique_ptr<AudioBus> audio_bus_; |
| 213 | 213 |
| 214 // Channel mixer and temporary bus for the final mixed channel data. | 214 // Channel mixer and temporary bus for the final mixed channel data. |
| 215 scoped_ptr<ChannelMixer> channel_mixer_; | 215 std::unique_ptr<ChannelMixer> channel_mixer_; |
| 216 scoped_ptr<AudioBus> mixed_audio_bus_; | 216 std::unique_ptr<AudioBus> mixed_audio_bus_; |
| 217 | 217 |
| 218 // Allows us to run tasks on the AlsaPcmOutputStream instance which are | 218 // Allows us to run tasks on the AlsaPcmOutputStream instance which are |
| 219 // bound by its lifetime. | 219 // bound by its lifetime. |
| 220 // NOTE: Weak pointers must be invalidated before all other member variables. | 220 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 221 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_; | 221 base::WeakPtrFactory<AlsaPcmOutputStream> weak_factory_; |
| 222 | 222 |
| 223 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); | 223 DISALLOW_COPY_AND_ASSIGN(AlsaPcmOutputStream); |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os, | 226 MEDIA_EXPORT std::ostream& operator<<(std::ostream& os, |
| 227 AlsaPcmOutputStream::InternalState); | 227 AlsaPcmOutputStream::InternalState); |
| 228 | 228 |
| 229 }; // namespace media | 229 }; // namespace media |
| 230 | 230 |
| 231 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ | 231 #endif // MEDIA_AUDIO_ALSA_ALSA_OUTPUT_H_ |
| OLD | NEW |