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

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: "Gyp and command line flag added, pausing/stopping/restarting works" 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/memory/scoped_ptr.h"
13 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_parameters.h"
15
16 namespace media {
17 class SeekableBuffer;
18 }
19
20 class AudioManagerLinux;
21
22 class PulseAudioOutputStream : public AudioOutputStream {
23 public:
24 PulseAudioOutputStream(const AudioParameters& params,
25 AudioManagerLinux* manager);
26
27 virtual ~PulseAudioOutputStream();
28
29 // Implementation of AudioOutputStream.
30 virtual bool Open();
31 virtual void Close();
32 virtual void Start(AudioSourceCallback* callback);
33 virtual void Stop();
34 virtual void SetVolume(double volume);
35 virtual void GetVolume(double* volume);
36
37 void BufferPacketInClient();
vrk (LEFT CHROMIUM) 2011/08/05 15:02:26 As I note in the .cc file, I think you can make th
slock 2011/08/08 20:30:15 Done.
38 media::SeekableBuffer* client_buffer_;
vrk (LEFT CHROMIUM) 2011/08/05 15:02:26 Make these fields private
vrk (LEFT CHROMIUM) 2011/08/05 15:02:26 scoped_ptr instead?
slock 2011/08/08 20:30:15 Done.
slock 2011/08/08 20:30:15 Done.
39 bool source_exhausted_;
40
41 private:
42 // Flags indicating the state of the stream.
43 enum InternalState {
vrk (LEFT CHROMIUM) 2011/08/05 15:02:26 Please delete all unused/unimplemented private fie
slock 2011/08/08 20:30:15 Done. Pretty sure I got them all.
44 kInError = 0,
45 kCreated,
46 kIsOpened,
47 kIsPlaying,
48 kIsStopped,
49 kIsClosed
50 };
51
52 friend std::ostream& operator<<(std::ostream& os, InternalState);
53
54 // Functions to get another packet from the data source and write it into the
55 // PulseAudio device.
56 void ClientBufferLoop();
57
58 // Functions to safeguard state transitions. All changes to the object state
59 // should go through these functions.
60 bool CanTransitionTo(InternalState to);
61 InternalState TransitionTo(InternalState to);
62 InternalState state();
63
64 // API for Proxying calls to the AudioSourceCallback provided during Start().
65 uint32 RunDataCallback(uint8* dest,
66 uint32 max_size,
67 AudioBuffersState buffers_state);
68 void RunErrorCallback(int code);
69
70 // Changes the AudioSourceCallback to proxy calls to. Pass in NULL to release
71 // ownership of the currently registered callback.
72 void set_source_callback(AudioSourceCallback* callback);
73
74 // Configuration constants from the constructor. Referencable by all threads
75 // since they are constants.
76 const ChannelLayout channel_layout_;
77 const pa_sample_format_t sample_format_;
78 const uint32 sample_rate_;
79 const uint32 bytes_per_sample_;
80 const uint32 bytes_per_frame_;
81
82 // Device configuration data. Populated after OpenTask() completes.
83 bool should_downmix_;
84 bool should_swizzle_;
85 uint32 packet_size_;
86 uint32 micros_per_packet_;
87 uint32 latency_micros_;
88 uint32 bytes_per_output_frame_;
89 uint32 server_buffer_frames_;
90
91 // Flag indicating the code should stop reading from the data source or
92 // writing to the PulseAudio server. This is set because the device has
93 // entered an unrecoverable error state, or the Close() has executed.
94 bool stop_stream_;
95
96 // Flag indicating that the there is no more data available to buffer.
97
98 // Audio manager that created us. Used to report that we've closed.
99 AudioManagerLinux* manager_;
100
101 // PulseAudio API structs.
102 pa_mainloop* pa_mainloop_;
103 pa_mainloop_api* pa_mainloop_api_;
104 pa_context* pa_context_;
105
106 // PulseAudio attribute and specification structs.
107 pa_sample_spec* pa_sample_specs_;
108 pa_buffer_attr* pa_buffer_attributes_;
109
110 // Handle to the actual PulseAudio playback stream.
111 pa_stream* playback_handle_;
112
113 uint32 frames_per_packet_;
114
115 InternalState state_;
116 float volume_; // Volume level from 0.0 to 1.0.
117
118 size_t MicrosToBytes(uint32 micros, uint32 sample_rate,
119 size_t bytes_per_sample);
120
121 AudioSourceCallback* source_callback_;
122
123 DISALLOW_COPY_AND_ASSIGN(PulseAudioOutputStream);
124 };
125
126 #endif // MEDIA_AUDIO_LINUX_PULSE_OUTPUT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698