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_); | |
39 } | 37 } |
40 | 38 |
41 PulseAudioInputStream::~PulseAudioInputStream() { | 39 PulseAudioInputStream::~PulseAudioInputStream() { |
42 // All internal structures should already have been freed in Close(), | 40 // All internal structures should already have been freed in Close(), |
43 // which calls AudioManagerPulse::Release which deletes this object. | 41 // which calls AudioManagerPulse::Release which deletes this object. |
44 DCHECK(!handle_); | 42 DCHECK(!handle_); |
45 } | 43 } |
46 | 44 |
47 bool PulseAudioInputStream::Open() { | 45 bool PulseAudioInputStream::Open() { |
48 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 265 |
268 buffer_->Append(reinterpret_cast<const uint8*>(data), length); | 266 buffer_->Append(reinterpret_cast<const uint8*>(data), length); |
269 | 267 |
270 // Checks if we still have data. | 268 // Checks if we still have data. |
271 pa_stream_drop(handle_); | 269 pa_stream_drop(handle_); |
272 } while (pa_stream_readable_size(handle_) > 0); | 270 } while (pa_stream_readable_size(handle_) > 0); |
273 | 271 |
274 int packet_size = params_.GetBytesPerBuffer(); | 272 int packet_size = params_.GetBytesPerBuffer(); |
275 while (buffer_->forward_bytes() >= packet_size) { | 273 while (buffer_->forward_bytes() >= packet_size) { |
276 buffer_->Read(audio_data_buffer_.get(), packet_size); | 274 buffer_->Read(audio_data_buffer_.get(), packet_size); |
277 audio_bus_->FromInterleaved(audio_data_buffer_.get(), | 275 callback_->OnData(this, audio_data_buffer_.get(), packet_size, |
278 audio_bus_->frames(), | 276 hardware_delay, normalized_volume); |
279 params_.bits_per_sample() / 8); | |
280 callback_->OnData( | |
281 this, audio_bus_.get(), hardware_delay, normalized_volume); | |
282 | 277 |
283 if (buffer_->forward_bytes() < packet_size) | 278 if (buffer_->forward_bytes() < packet_size) |
284 break; | 279 break; |
285 | 280 |
286 // TODO(xians): Remove once PPAPI is using circular buffers. | 281 // TODO(xians): Remove once PPAPI is using circular buffers. |
287 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " | 282 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " |
288 << "wait until render consumes the data"; | 283 << "wait until render consumes the data"; |
289 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); | 284 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); |
290 } | 285 } |
291 | 286 |
292 pa_threaded_mainloop_signal(pa_mainloop_, 0); | 287 pa_threaded_mainloop_signal(pa_mainloop_, 0); |
293 } | 288 } |
294 | 289 |
295 } // namespace media | 290 } // namespace media |
OLD | NEW |