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

Side by Side Diff: media/audio/linux/pulse_output.h

Issue 7473021: PulseAudio Sound Playback on Linux (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: "Volume adjustment works now" Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_
6 #define MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_
7
8 #include <pulse/pulseaudio.h>
9
10 #include <string>
11
12 #include "base/message_loop.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_parameters.h"
16
17 namespace media {
18 class SeekableBuffer;
19 }
20
21 class AudioManagerLinux;
22
23 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.
24 public:
25 PulseAudioOutputStream(const AudioParameters& params,
26 AudioManagerLinux* manager,
27 MessageLoop* message_loop);
28
29 virtual ~PulseAudioOutputStream();
30
31 // Implementation of AudioOutputStream.
32 virtual bool Open();
33 virtual void Close();
34 virtual void Start(AudioSourceCallback* callback);
35 virtual void Stop();
36 virtual void SetVolume(double volume);
37 virtual void GetVolume(double* volume);
38
39 private:
40 // PulseAudio mainloop iteration loop task function; used to avoid blocking
41 // the audio thread.
42 void MainloopIterateTask();
43
44 // PulseAudio Callbacks.
45 static void ContextStateCallback(pa_context* context, void* userdata);
46 static void WriteCallback(pa_stream* stream, size_t length, void* userdata);
47
48 // Function to get another packet from the data source and write it into the
49 // client buffer.
50 void BufferPacketInClient();
51
52 // API for Proxying calls to the AudioSourceCallback provided during Start().
53 uint32 RunDataCallback(uint8* dest, uint32 max_size,
54 AudioBuffersState buffers_state);
55
56 // Configuration constants from the constructor. Referencable by all threads
57 // since they are constants.
58 const ChannelLayout channel_layout_;
59 const pa_sample_format_t sample_format_;
60 const uint32 sample_rate_;
61 const uint32 bytes_per_frame_;
62
63 // Device configuration data. Populated after OpenTask() completes.
64 uint32 packet_size_;
65 uint32 frames_per_packet_;
66
67 // Flag indicating the code should stop reading from the data source or
68 // writing to the PulseAudio server. This is set because the device has
69 // entered an unrecoverable error state, or the Close() has executed.
70 bool stream_stopped_;
71
72 // Audio manager that created us. Used to report that we've closed.
73 AudioManagerLinux* manager_;
74
75 // PulseAudio API structs.
76 pa_context* pa_context_;
77 pa_mainloop* pa_mainloop_;
78 pa_mainloop_api* pa_mainloop_api_; // Owned by pa_mainloop_.
79
80 // PulseAudio attribute and specification structs.
81 pa_sample_spec pa_sample_specs_;
82 pa_buffer_attr pa_buffer_attributes_;
83
84 // Handle to the actual PulseAudio playback stream.
85 pa_stream* playback_handle_;
86
87 // Whether or not PulseAudio has called the WriteCallback for the most recent
88 // set of pa_mainloop iterations.
89 bool pa_write_has_calledback_;
90
91 // Internal buffer.
92 scoped_ptr<media::SeekableBuffer> client_buffer_;
93 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.
94
95 float volume_;
96
97 AudioSourceCallback* source_callback_;
98
99 MessageLoop* message_loop_;
100
101 ScopedRunnableMethodFactory<PulseAudioOutputStream> method_factory_;
102
103 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream);
104 };
105
106 #endif // MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698