OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromecast/media/audio/cast_audio_output_stream.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 |
| 9 namespace media { |
| 10 |
| 11 CastAudioOutputStream::CastAudioOutputStream( |
| 12 chromecast::AudioOutputStream* output_stream, |
| 13 const chromecast::AudioParameters& params) |
| 14 : output_stream_(output_stream), params_(params) { |
| 15 } |
| 16 |
| 17 CastAudioOutputStream::~CastAudioOutputStream() { |
| 18 } |
| 19 |
| 20 bool CastAudioOutputStream::Open() { |
| 21 return output_stream_->Open(); |
| 22 } |
| 23 |
| 24 void CastAudioOutputStream::Start( |
| 25 media::AudioOutputStream::AudioSourceCallback* callback) { |
| 26 callback_ = callback; |
| 27 output_stream_->Start(this); |
| 28 } |
| 29 |
| 30 void CastAudioOutputStream::Stop() { |
| 31 output_stream_->Stop(); |
| 32 } |
| 33 |
| 34 void CastAudioOutputStream::SetVolume(double volume) { |
| 35 output_stream_->SetVolume(volume); |
| 36 } |
| 37 |
| 38 void CastAudioOutputStream::GetVolume(double* volume) { |
| 39 output_stream_->GetVolume(volume); |
| 40 } |
| 41 |
| 42 void CastAudioOutputStream::Close() { |
| 43 output_stream_->Close(); |
| 44 } |
| 45 |
| 46 int CastAudioOutputStream::OnMoreData(void* dest, |
| 47 uint32_t len, |
| 48 int32_t frames, |
| 49 uint32_t total_bytes_delay) { |
| 50 CHECK(dest); |
| 51 CHECK_GE(frames, 0); |
| 52 uint32_t bytes_needed = |
| 53 frames * params_.channels * params_.bits_per_sample / 8; |
| 54 CHECK_GE(len, bytes_needed); |
| 55 |
| 56 // Pass an empty audio bus of the right size to the source to be filled. |
| 57 scoped_ptr<media::AudioBus> bus = AudioBus::Create(params_.channels, frames); |
| 58 int frames_filled = callback_->OnMoreData(bus.get(), total_bytes_delay); |
| 59 DCHECK_GE(frames_filled, 0); |
| 60 DCHECK_LE(frames_filled, frames); |
| 61 |
| 62 // Populate |dest| with interleaved data. |
| 63 bus->ToInterleaved(frames_filled, params_.bits_per_sample / 8, dest); |
| 64 return frames_filled; |
| 65 } |
| 66 |
| 67 void CastAudioOutputStream::OnError(chromecast::AudioOutputStream* stream) { |
| 68 callback_->OnError(this); |
| 69 } |
| 70 |
| 71 void CastAudioOutputStream::OnClose() { |
| 72 // TODO(slan): Does anything need to be done here? |
| 73 DVLOG(1) << "Ouput stream has been closed."; |
| 74 } |
| 75 |
| 76 } // namespace media |
OLD | NEW |