Chromium Code Reviews| 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/chromecast_device_audio_output_stream.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace chromecast { | |
| 10 | |
| 11 ChromecastDeviceAudioOutputStream::ChromecastDeviceAudioOutputStream( | |
| 12 chromecast::CastAudioOutputStream* output_stream, | |
| 13 const chromecast::AudioParameters& params) | |
| 14 : 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.
| |
| 15 } | |
| 16 | |
| 17 ChromecastDeviceAudioOutputStream::~ChromecastDeviceAudioOutputStream() { | |
| 18 } | |
| 19 | |
| 20 bool ChromecastDeviceAudioOutputStream::Open() { | |
| 21 return output_stream_->Open(); | |
| 22 } | |
| 23 | |
| 24 void ChromecastDeviceAudioOutputStream::Start( | |
| 25 media::AudioOutputStream::AudioSourceCallback* callback) { | |
| 26 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.
| |
| 27 output_stream_->Start(this); | |
| 28 } | |
| 29 | |
| 30 void ChromecastDeviceAudioOutputStream::Stop() { | |
| 31 output_stream_->Stop(); | |
| 32 } | |
|
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
| |
| 33 | |
| 34 void ChromecastDeviceAudioOutputStream::SetVolume(double volume) { | |
| 35 output_stream_->SetVolume(volume); | |
| 36 } | |
| 37 | |
| 38 void ChromecastDeviceAudioOutputStream::GetVolume(double* volume) { | |
| 39 CHECK(volume); | |
|
byungchul
2015/04/27 17:38:06
DCHECK() should be enough.
slan
2015/04/28 00:11:38
Done.
| |
| 40 *volume = output_stream_->GetVolume(); | |
| 41 } | |
| 42 | |
| 43 void ChromecastDeviceAudioOutputStream::Close() { | |
| 44 output_stream_->Close(); | |
| 45 } | |
| 46 | |
| 47 int ChromecastDeviceAudioOutputStream::OnMoreData(void* dest, | |
| 48 uint32_t len, | |
| 49 int32_t frames, | |
| 50 uint32_t total_bytes_delay) { | |
| 51 CHECK(dest); | |
| 52 CHECK_GE(frames, 0); | |
| 53 uint32_t bytes_needed = | |
| 54 frames * params_.channels * params_.bits_per_sample / 8; | |
| 55 CHECK_GE(len, bytes_needed); | |
| 56 | |
| 57 // Pass an empty audio bus of the right size to the source to be filled. | |
| 58 scoped_ptr<media::AudioBus> bus = | |
| 59 media::AudioBus::Create(params_.channels, frames); | |
| 60 int frames_filled = callback_->OnMoreData(bus.get(), total_bytes_delay); | |
| 61 DCHECK_GE(frames_filled, 0); | |
| 62 DCHECK_LE(frames_filled, frames); | |
| 63 | |
| 64 // Populate |dest| with interleaved data. | |
| 65 bus->ToInterleaved(frames_filled, params_.bits_per_sample / 8, dest); | |
| 66 return frames_filled; | |
| 67 } | |
| 68 | |
| 69 void ChromecastDeviceAudioOutputStream::OnError( | |
| 70 chromecast::CastAudioOutputStream* stream) { | |
| 71 callback_->OnError(this); | |
| 72 } | |
| 73 | |
| 74 void ChromecastDeviceAudioOutputStream::OnClose() { | |
| 75 // TODO(slan): Does anything need to be done here? | |
| 76 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.
| |
| 77 } | |
| 78 | |
| 79 } // namespace chromecast | |
| OLD | NEW |