Index: chromecast/media/audio/cast_audio_output_stream.cc |
diff --git a/chromecast/media/audio/cast_audio_output_stream.cc b/chromecast/media/audio/cast_audio_output_stream.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6372aa5c22edc8d31c9e5f9c6ce5a2c4d93bf23a |
--- /dev/null |
+++ b/chromecast/media/audio/cast_audio_output_stream.cc |
@@ -0,0 +1,76 @@ |
+// 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/cast_audio_output_stream.h" |
+ |
+#include "base/logging.h" |
+ |
+namespace media { |
+ |
+CastAudioOutputStream::CastAudioOutputStream( |
+ chromecast::AudioOutputStream* output_stream, |
+ const chromecast::AudioParameters& params) |
+ : output_stream_(output_stream), params_(params) { |
+} |
+ |
+CastAudioOutputStream::~CastAudioOutputStream() { |
+} |
+ |
+bool CastAudioOutputStream::Open() { |
+ return output_stream_->Open(); |
+} |
+ |
+void CastAudioOutputStream::Start( |
+ media::AudioOutputStream::AudioSourceCallback* callback) { |
+ callback_ = callback; |
+ output_stream_->Start(this); |
+} |
+ |
+void CastAudioOutputStream::Stop() { |
+ output_stream_->Stop(); |
+} |
+ |
+void CastAudioOutputStream::SetVolume(double volume) { |
+ output_stream_->SetVolume(volume); |
+} |
+ |
+void CastAudioOutputStream::GetVolume(double* volume) { |
+ output_stream_->GetVolume(volume); |
+} |
+ |
+void CastAudioOutputStream::Close() { |
+ output_stream_->Close(); |
+} |
+ |
+int CastAudioOutputStream::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 = 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 CastAudioOutputStream::OnError(chromecast::AudioOutputStream* stream) { |
+ callback_->OnError(this); |
+} |
+ |
+void CastAudioOutputStream::OnClose() { |
+ // TODO(slan): Does anything need to be done here? |
+ DVLOG(1) << "Ouput stream has been closed."; |
+} |
+ |
+} // namespace media |