Index: media/audio/linux/pulse_output.h |
diff --git a/media/audio/linux/pulse_output.h b/media/audio/linux/pulse_output.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5b31edd1dda49cd36b5688e268224bcb425befb5 |
--- /dev/null |
+++ b/media/audio/linux/pulse_output.h |
@@ -0,0 +1,106 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_ |
+#define MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_ |
+ |
+#include <pulse/pulseaudio.h> |
+ |
+#include <string> |
+ |
+#include "base/message_loop.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "media/audio/audio_io.h" |
+#include "media/audio/audio_parameters.h" |
+ |
+namespace media { |
+class SeekableBuffer; |
+} |
+ |
+class AudioManagerLinux; |
+ |
+class PulseAudioOutputStream : public AudioOutputStream { |
vrk (LEFT CHROMIUM)
2011/08/12 23:16:51
Comment on what this class does.
Things to includ
slock
2011/08/15 20:35:06
Done.
|
+ public: |
+ PulseAudioOutputStream(const AudioParameters& params, |
+ AudioManagerLinux* manager, |
+ MessageLoop* message_loop); |
+ |
+ virtual ~PulseAudioOutputStream(); |
+ |
+ // Implementation of AudioOutputStream. |
+ virtual bool Open(); |
+ virtual void Close(); |
+ virtual void Start(AudioSourceCallback* callback); |
+ virtual void Stop(); |
+ virtual void SetVolume(double volume); |
+ virtual void GetVolume(double* volume); |
+ |
+ private: |
+ // PulseAudio mainloop iteration loop task function; used to avoid blocking |
+ // the audio thread. |
+ void MainloopIterateTask(); |
+ |
+ // PulseAudio Callbacks. |
+ static void ContextStateCallback(pa_context* context, void* userdata); |
+ static void WriteCallback(pa_stream* stream, size_t length, void* userdata); |
+ |
+ // Function to get another packet from the data source and write it into the |
+ // client buffer. |
+ void BufferPacketInClient(); |
+ |
+ // API for Proxying calls to the AudioSourceCallback provided during Start(). |
+ uint32 RunDataCallback(uint8* dest, uint32 max_size, |
+ AudioBuffersState buffers_state); |
+ |
+ // Configuration constants from the constructor. Referencable by all threads |
+ // since they are constants. |
+ const ChannelLayout channel_layout_; |
+ const pa_sample_format_t sample_format_; |
+ const uint32 sample_rate_; |
+ const uint32 bytes_per_frame_; |
+ |
+ // Device configuration data. Populated after OpenTask() completes. |
+ uint32 packet_size_; |
+ uint32 frames_per_packet_; |
+ |
+ // 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_; |
+ |
+ // Audio manager that created us. Used to report that we've closed. |
+ AudioManagerLinux* manager_; |
+ |
+ // PulseAudio API structs. |
+ pa_context* pa_context_; |
+ pa_mainloop* pa_mainloop_; |
+ pa_mainloop_api* pa_mainloop_api_; // Owned by pa_mainloop_. |
+ |
+ // PulseAudio attribute and specification structs. |
+ pa_sample_spec pa_sample_specs_; |
+ pa_buffer_attr pa_buffer_attributes_; |
+ |
+ // Handle to the actual PulseAudio playback stream. |
+ pa_stream* playback_handle_; |
+ |
+ // Whether or not PulseAudio has called the WriteCallback for the most recent |
+ // set of pa_mainloop iterations. |
+ bool pa_write_has_calledback_; |
+ |
+ // Internal buffer. |
+ scoped_ptr<media::SeekableBuffer> client_buffer_; |
+ bool source_exhausted_; |
vrk (LEFT CHROMIUM)
2011/08/12 23:16:51
nit: comment this field and ones below (don't forg
slock
2011/08/15 20:35:06
Done.
|
+ |
+ float volume_; |
+ |
+ AudioSourceCallback* source_callback_; |
+ |
+ MessageLoop* message_loop_; |
+ |
+ ScopedRunnableMethodFactory<PulseAudioOutputStream> method_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream); |
+}; |
+ |
+#endif // MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_ |