OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "media/audio/linux/pulse_output.h" | 5 #include "media/audio/pulse/pulse_output.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/audio/audio_util.h" | 10 #include "media/audio/audio_util.h" |
| 11 #if defined(OS_LINUX) |
11 #include "media/audio/linux/audio_manager_linux.h" | 12 #include "media/audio/linux/audio_manager_linux.h" |
| 13 #elif defined(OS_OPENBSD) |
| 14 #include "media/audio/openbsd/audio_manager_openbsd.h" |
| 15 #endif |
12 #include "media/base/data_buffer.h" | 16 #include "media/base/data_buffer.h" |
13 #include "media/base/seekable_buffer.h" | 17 #include "media/base/seekable_buffer.h" |
14 | 18 |
15 static pa_sample_format_t BitsToPASampleFormat(int bits_per_sample) { | 19 static pa_sample_format_t BitsToPASampleFormat(int bits_per_sample) { |
16 switch (bits_per_sample) { | 20 switch (bits_per_sample) { |
17 // Unsupported sample formats shown for reference. I am assuming we want | 21 // Unsupported sample formats shown for reference. I am assuming we want |
18 // signed and little endian because that is what we gave to ALSA. | 22 // signed and little endian because that is what we gave to ALSA. |
19 case 8: | 23 case 8: |
20 return PA_SAMPLE_U8; | 24 return PA_SAMPLE_U8; |
21 // Also 8-bits: PA_SAMPLE_ALAW and PA_SAMPLE_ULAW | 25 // Also 8-bits: PA_SAMPLE_ALAW and PA_SAMPLE_ULAW |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 125 |
122 DCHECK_EQ(stream->message_loop_, MessageLoop::current()); | 126 DCHECK_EQ(stream->message_loop_, MessageLoop::current()); |
123 | 127 |
124 stream->write_callback_handled_ = true; | 128 stream->write_callback_handled_ = true; |
125 | 129 |
126 // Fulfill write request. | 130 // Fulfill write request. |
127 stream->FulfillWriteRequest(length); | 131 stream->FulfillWriteRequest(length); |
128 } | 132 } |
129 | 133 |
130 PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params, | 134 PulseAudioOutputStream::PulseAudioOutputStream(const AudioParameters& params, |
131 AudioManagerLinux* manager, | 135 AudioManagerPulse* manager, |
132 MessageLoop* message_loop) | 136 MessageLoop* message_loop) |
133 : channel_layout_(params.channel_layout), | 137 : channel_layout_(params.channel_layout), |
134 channel_count_(ChannelLayoutToChannelCount(channel_layout_)), | 138 channel_count_(ChannelLayoutToChannelCount(channel_layout_)), |
135 sample_format_(BitsToPASampleFormat(params.bits_per_sample)), | 139 sample_format_(BitsToPASampleFormat(params.bits_per_sample)), |
136 sample_rate_(params.sample_rate), | 140 sample_rate_(params.sample_rate), |
137 bytes_per_frame_(params.channels * params.bits_per_sample / 8), | 141 bytes_per_frame_(params.channels * params.bits_per_sample / 8), |
138 manager_(manager), | 142 manager_(manager), |
139 pa_context_(NULL), | 143 pa_context_(NULL), |
140 pa_mainloop_(NULL), | 144 pa_mainloop_(NULL), |
141 playback_handle_(NULL), | 145 playback_handle_(NULL), |
142 packet_size_(params.GetPacketSize()), | 146 packet_size_(params.GetPacketSize()), |
143 frames_per_packet_(packet_size_ / bytes_per_frame_), | 147 frames_per_packet_(packet_size_ / bytes_per_frame_), |
144 client_buffer_(NULL), | 148 client_buffer_(NULL), |
145 volume_(1.0f), | 149 volume_(1.0f), |
146 stream_stopped_(true), | 150 stream_stopped_(true), |
147 write_callback_handled_(false), | 151 write_callback_handled_(false), |
148 message_loop_(message_loop), | 152 message_loop_(message_loop), |
149 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
150 source_callback_(NULL) { | 154 source_callback_(NULL) { |
151 DCHECK_EQ(message_loop_, MessageLoop::current()); | 155 DCHECK_EQ(message_loop_, MessageLoop::current()); |
152 DCHECK(manager_); | 156 DCHECK(manager_); |
153 | 157 |
154 // TODO(slock): Sanity check input values. | 158 // TODO(slock): Sanity check input values. |
155 } | 159 } |
156 | 160 |
157 PulseAudioOutputStream::~PulseAudioOutputStream() { | 161 PulseAudioOutputStream::~PulseAudioOutputStream() { |
158 // All internal structures should already have been freed in Close(), | 162 // All internal structures should already have been freed in Close(), |
159 // which calls AudioManagerLinux::Release which deletes this object. | 163 // which calls AudioManagerPulse::Release which deletes this object. |
160 DCHECK(!playback_handle_); | 164 DCHECK(!playback_handle_); |
161 DCHECK(!pa_context_); | 165 DCHECK(!pa_context_); |
162 DCHECK(!pa_mainloop_); | 166 DCHECK(!pa_mainloop_); |
163 } | 167 } |
164 | 168 |
165 bool PulseAudioOutputStream::Open() { | 169 bool PulseAudioOutputStream::Open() { |
166 DCHECK_EQ(message_loop_, MessageLoop::current()); | 170 DCHECK_EQ(message_loop_, MessageLoop::current()); |
167 | 171 |
168 // TODO(slock): Possibly move most of this to an OpenPlaybackDevice function | 172 // TODO(slock): Possibly move most of this to an OpenPlaybackDevice function |
169 // in a new class 'pulse_util', like alsa_util. | 173 // in a new class 'pulse_util', like alsa_util. |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 *volume = volume_; | 415 *volume = volume_; |
412 } | 416 } |
413 | 417 |
414 uint32 PulseAudioOutputStream::RunDataCallback( | 418 uint32 PulseAudioOutputStream::RunDataCallback( |
415 uint8* dest, uint32 max_size, AudioBuffersState buffers_state) { | 419 uint8* dest, uint32 max_size, AudioBuffersState buffers_state) { |
416 if (source_callback_) | 420 if (source_callback_) |
417 return source_callback_->OnMoreData(this, dest, max_size, buffers_state); | 421 return source_callback_->OnMoreData(this, dest, max_size, buffers_state); |
418 | 422 |
419 return 0; | 423 return 0; |
420 } | 424 } |
OLD | NEW |