OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/pulse/pulse_input.h" | 5 #include "media/audio/pulse/pulse_input.h" |
6 | 6 |
7 #include <pulse/pulseaudio.h> | 7 #include <pulse/pulseaudio.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/audio/pulse/audio_manager_pulse.h" | 10 #include "media/audio/pulse/audio_manager_pulse.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 params_(params), | 27 params_(params), |
28 channels_(0), | 28 channels_(0), |
29 volume_(0.0), | 29 volume_(0.0), |
30 stream_started_(false), | 30 stream_started_(false), |
31 pa_mainloop_(mainloop), | 31 pa_mainloop_(mainloop), |
32 pa_context_(context), | 32 pa_context_(context), |
33 handle_(NULL), | 33 handle_(NULL), |
34 context_state_changed_(false) { | 34 context_state_changed_(false) { |
35 DCHECK(mainloop); | 35 DCHECK(mainloop); |
36 DCHECK(context); | 36 DCHECK(context); |
| 37 CHECK(params_.IsValid()); |
| 38 audio_bus_ = AudioBus::Create(params_); |
37 } | 39 } |
38 | 40 |
39 PulseAudioInputStream::~PulseAudioInputStream() { | 41 PulseAudioInputStream::~PulseAudioInputStream() { |
40 // All internal structures should already have been freed in Close(), | 42 // All internal structures should already have been freed in Close(), |
41 // which calls AudioManagerPulse::Release which deletes this object. | 43 // which calls AudioManagerPulse::Release which deletes this object. |
42 DCHECK(!handle_); | 44 DCHECK(!handle_); |
43 } | 45 } |
44 | 46 |
45 bool PulseAudioInputStream::Open() { | 47 bool PulseAudioInputStream::Open() { |
46 DCHECK(thread_checker_.CalledOnValidThread()); | 48 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 267 |
266 buffer_->Append(reinterpret_cast<const uint8*>(data), length); | 268 buffer_->Append(reinterpret_cast<const uint8*>(data), length); |
267 | 269 |
268 // Checks if we still have data. | 270 // Checks if we still have data. |
269 pa_stream_drop(handle_); | 271 pa_stream_drop(handle_); |
270 } while (pa_stream_readable_size(handle_) > 0); | 272 } while (pa_stream_readable_size(handle_) > 0); |
271 | 273 |
272 int packet_size = params_.GetBytesPerBuffer(); | 274 int packet_size = params_.GetBytesPerBuffer(); |
273 while (buffer_->forward_bytes() >= packet_size) { | 275 while (buffer_->forward_bytes() >= packet_size) { |
274 buffer_->Read(audio_data_buffer_.get(), packet_size); | 276 buffer_->Read(audio_data_buffer_.get(), packet_size); |
275 callback_->OnData(this, audio_data_buffer_.get(), packet_size, | 277 audio_bus_->FromInterleaved(audio_data_buffer_.get(), |
276 hardware_delay, normalized_volume); | 278 audio_bus_->frames(), |
| 279 params_.bits_per_sample() / 8); |
| 280 callback_->OnData( |
| 281 this, audio_bus_.get(), hardware_delay, normalized_volume); |
277 | 282 |
278 if (buffer_->forward_bytes() < packet_size) | 283 if (buffer_->forward_bytes() < packet_size) |
279 break; | 284 break; |
280 | 285 |
281 // TODO(xians): Remove once PPAPI is using circular buffers. | 286 // TODO(xians): Remove once PPAPI is using circular buffers. |
282 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " | 287 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " |
283 << "wait until render consumes the data"; | 288 << "wait until render consumes the data"; |
284 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); | 289 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); |
285 } | 290 } |
286 | 291 |
287 pa_threaded_mainloop_signal(pa_mainloop_, 0); | 292 pa_threaded_mainloop_signal(pa_mainloop_, 0); |
288 } | 293 } |
289 | 294 |
290 } // namespace media | 295 } // namespace media |
OLD | NEW |