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..79b475b17f653ee29cad6bc54687b775e703fd24 |
--- /dev/null |
+++ b/chromecast/media/audio/chromecast_device_audio_output_stream.cc |
@@ -0,0 +1,78 @@ |
+// 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) { |
+} |
+ |
+ChromecastDeviceAudioOutputStream::~ChromecastDeviceAudioOutputStream() { |
+} |
+ |
+bool ChromecastDeviceAudioOutputStream::Open() { |
+ return output_stream_->Open(); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::Start( |
+ media::AudioOutputStream::AudioSourceCallback* callback) { |
+ callback_ = callback; |
+ output_stream_->Start(this); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::Stop() { |
+ output_stream_->Stop(); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::SetVolume(double volume) { |
+ output_stream_->SetVolume(volume); |
+} |
+ |
+void ChromecastDeviceAudioOutputStream::GetVolume(double* volume) { |
+ output_stream_->GetVolume(volume); |
+} |
+ |
+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; |
halliwell
2015/04/24 15:04:47
Other comment on bits/8 applies here (actually loo
slan
2015/04/24 16:19:39
Yup, please see my response to your other comment,
|
+ 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."; |
+} |
+ |
+} // namespace chromecast |