Index: chromecast/media/audio/chromecast_device_audio_output_stream.cc |
diff --git a/chromecast/media/audio/chromecast_device_audio_output_stream.cc b/chromecast/media/audio/chromecast_device_audio_output_stream.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0b9c1e9a60200650992ab51befbd7fbbb87593ba |
--- /dev/null |
+++ b/chromecast/media/audio/chromecast_device_audio_output_stream.cc |
@@ -0,0 +1,79 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromecast/media/audio/chromecast_device_audio_output_stream.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace chromecast { |
+ |
+ChromecastDeviceAudioOutputStream::ChromecastDeviceAudioOutputStream( |
+ chromecast::CastAudioOutputStream* output_stream, |
+ const chromecast::AudioParameters& params) |
+ : output_stream_(output_stream), params_(params) { |
erickung1
2015/04/25 08:38:31
Add DCHECK(output_stream) ?
Also set |callback_| t
slan
2015/04/28 00:11:38
Done.
|
+} |
+ |
+ChromecastDeviceAudioOutputStream::~ChromecastDeviceAudioOutputStream() { |
+} |
+ |
+bool ChromecastDeviceAudioOutputStream::Open() { |
+ return output_stream_->Open(); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::Start( |
+ media::AudioOutputStream::AudioSourceCallback* callback) { |
+ callback_ = callback; |
erickung1
2015/04/25 08:38:31
We may want to add DCHECK on |callback| here.
Othe
slan
2015/04/28 00:11:38
Done.
|
+ output_stream_->Start(this); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::Stop() { |
+ output_stream_->Stop(); |
+} |
gunsch
2015/04/27 16:09:11
Is Stop() parallel/opposite to Start()? If so, sho
slan
2015/04/28 00:11:38
Really good catch. Done. We now ignore OnError and
|
+ |
+void ChromecastDeviceAudioOutputStream::SetVolume(double volume) { |
+ output_stream_->SetVolume(volume); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::GetVolume(double* volume) { |
+ CHECK(volume); |
byungchul
2015/04/27 17:38:06
DCHECK() should be enough.
slan
2015/04/28 00:11:38
Done.
|
+ *volume = output_stream_->GetVolume(); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::Close() { |
+ output_stream_->Close(); |
+} |
+ |
+int ChromecastDeviceAudioOutputStream::OnMoreData(void* dest, |
+ uint32_t len, |
+ int32_t frames, |
+ uint32_t total_bytes_delay) { |
+ CHECK(dest); |
+ CHECK_GE(frames, 0); |
+ uint32_t bytes_needed = |
+ frames * params_.channels * params_.bits_per_sample / 8; |
+ CHECK_GE(len, bytes_needed); |
+ |
+ // Pass an empty audio bus of the right size to the source to be filled. |
+ scoped_ptr<media::AudioBus> bus = |
+ media::AudioBus::Create(params_.channels, frames); |
+ int frames_filled = callback_->OnMoreData(bus.get(), total_bytes_delay); |
+ DCHECK_GE(frames_filled, 0); |
+ DCHECK_LE(frames_filled, frames); |
+ |
+ // Populate |dest| with interleaved data. |
+ bus->ToInterleaved(frames_filled, params_.bits_per_sample / 8, dest); |
+ return frames_filled; |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::OnError( |
+ chromecast::CastAudioOutputStream* stream) { |
+ callback_->OnError(this); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::OnClose() { |
+ // TODO(slan): Does anything need to be done here? |
+ DVLOG(1) << "Ouput stream has been closed."; |
byungchul
2015/04/27 17:38:06
Why not just VLOG(1)?
slan
2015/04/28 00:11:38
Done.
|
+} |
+ |
+} // namespace chromecast |