Chromium Code Reviews| Index: media/audio/pulse/pulse_output.h |
| diff --git a/media/audio/pulse/pulse_output.h b/media/audio/pulse/pulse_output.h |
| index 1d39af47f4598022f338a273984856199e1c3ea2..9511d062520252569cef3cbbc48f63474d239365 100644 |
| --- a/media/audio/pulse/pulse_output.h |
| +++ b/media/audio/pulse/pulse_output.h |
| @@ -2,7 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // |
| -// Creates an audio output stream based on the PulseAudio asynchronous API. |
| +// Creates an audio output stream based on the PulseAudio asynchronous API; |
| +// specifically using the pa_threaded_mainloop model. |
| // |
| // If the stream is successfully opened, Close() must be called before the |
| // stream is deleted as Close() is responsible for ensuring resource cleanup |
| @@ -19,32 +20,22 @@ |
| #ifndef MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
| #define MEDIA_AUDIO_PULSE_PULSE_OUTPUT_H_ |
| -#include <pulse/pulseaudio.h> |
| - |
| #include "base/memory/scoped_ptr.h" |
| -#include "base/memory/weak_ptr.h" |
| #include "media/audio/audio_io.h" |
| -#include "media/base/channel_layout.h" |
| - |
| -namespace media { |
| +#include "media/audio/audio_parameters.h" |
| -#if defined(OS_LINUX) |
| -class AudioManagerLinux; |
| -typedef AudioManagerLinux AudioManagerPulse; |
| -#elif defined(OS_OPENBSD) |
| -class AudioManagerOpenBSD; |
| -typedef AudioManagerOpenBSD AudioManagerPulse; |
| -#else |
| -#error Unsupported platform |
| -#endif |
| +struct pa_context; |
| +struct pa_operation; |
| +struct pa_stream; |
| +struct pa_threaded_mainloop; |
| -class AudioParameters; |
| -class SeekableBuffer; |
| +namespace media { |
| +class AudioManagerBase; |
| class PulseAudioOutputStream : public AudioOutputStream { |
| public: |
| PulseAudioOutputStream(const AudioParameters& params, |
| - AudioManagerPulse* manager); |
| + AudioManagerBase* manager); |
| virtual ~PulseAudioOutputStream(); |
| @@ -57,72 +48,47 @@ class PulseAudioOutputStream : public AudioOutputStream { |
| virtual void GetVolume(double* volume) OVERRIDE; |
| private: |
| - // PulseAudio Callbacks. |
| - static void ContextStateCallback(pa_context* context, void* state_addr); |
| - static void WriteRequestCallback(pa_stream* playback_handle, size_t length, |
| - void* stream_addr); |
| + // Called by PulseAudio when |pa_context_| and |pa_stream_| change state. If |
| + // an unexpected failure state change happens and |source_callback_| is set |
| + // these methods will forward the error via OnError(). |
| + static void ContextNotifyCallback(pa_context* c, void* p_this); |
| + static void StreamNotifyCallback(pa_stream* s, void* p_this); |
| - // Iterate the PulseAudio mainloop to get write requests. |
| - void WaitForWriteRequest(); |
| + // Used simply to trigger pa_threaded_mainloop_signal() and avoid dead locks. |
|
scherkus (not reviewing)
2012/11/14 22:31:31
Wording suggestions:
s/Used simple to trigger/Tri
DaleCurtis
2012/11/14 23:49:43
Done.
|
| + static void StreamSuccessCallback(pa_stream* s, int success, void* p_this); |
| - // Get another packet from the data source and write it to the client buffer. |
| - bool BufferPacketFromSource(); |
| + // Called by PulseAudio when it needs more audio data. |
| + static void StreamRequestCallback(pa_stream* s, size_t len, void* p_this); |
| - // Fulfill a write request from the write request callback. If the write |
| - // can't be finished a first, post a new attempt to the message loop. |
| + // Fulfill a write request from the write request callback. Outputs silence |
| + // if the request could not be fulfilled. |
| void FulfillWriteRequest(size_t requested_bytes); |
| - // Write data from the client buffer to the PulseAudio stream. |
| - void WriteToStream(size_t bytes_to_write, size_t* bytes_written); |
| - |
| - // API for Proxying calls to the AudioSourceCallback provided during Start(). |
| - int RunDataCallback(AudioBus* audio_bus, AudioBuffersState buffers_state); |
| - |
| // Close() helper function to free internal structs. |
| void Reset(); |
| - // Configuration constants from the constructor. Referencable by all threads |
| - // since they are constants. |
| - const ChannelLayout channel_layout_; |
| - const uint32 channel_count_; |
| - const pa_sample_format_t sample_format_; |
| - const uint32 sample_rate_; |
| - const uint32 bytes_per_frame_; |
| + // Returns the current hardware latency value in bytes. |
| + int GetHardwareLatencyInBytes(); |
| + |
| + // Helper method for waiting on Pulse Audio operations to complete. |
| + void WaitForPulseOperation(pa_operation* op); |
| + |
| + // AudioParameters from the constructor. |
| + const AudioParameters params_; |
| // Audio manager that created us. Used to report that we've closed. |
| - AudioManagerPulse* manager_; |
| + AudioManagerBase* manager_; |
| // PulseAudio API structs. |
| pa_context* pa_context_; |
| - pa_mainloop* pa_mainloop_; |
| - |
| - // Handle to the actual PulseAudio playback stream. |
| - pa_stream* playback_handle_; |
| - |
| - // Device configuration data. Populated after Open() completes. |
| - uint32 packet_size_; |
| - uint32 frames_per_packet_; |
| - |
| - // Client side audio buffer feeding pulse audio's server side buffer. |
| - scoped_ptr<media::SeekableBuffer> client_buffer_; |
| + pa_threaded_mainloop* pa_mainloop_; |
| + pa_stream* pa_stream_; |
| // Float representation of volume from 0.0 to 1.0. |
| float volume_; |
| - // Flag indicating the code should stop reading from the data source or |
| - // writing to the PulseAudio server. This is set because the device has |
| - // entered an unrecoverable error state, or the Close() has executed. |
| - bool stream_stopped_; |
| - |
| - // Whether or not PulseAudio has called the WriteCallback for the most recent |
| - // set of pa_mainloop iterations. |
| - bool write_callback_handled_; |
| - |
| - // Allows us to run tasks on the PulseAudioOutputStream instance which are |
| - // bound by its lifetime. |
| - base::WeakPtrFactory<PulseAudioOutputStream> weak_factory_; |
| - |
| - // Callback to audio data source. |
| + // Callback to audio data source. Must only be modified while holding a lock |
| + // on |pa_mainloop_| via pa_threaded_mainloop_lock(). |
| AudioSourceCallback* source_callback_; |
| // Container for retrieving data from AudioSourceCallback::OnMoreData(). |