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) { | |
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; | |
27 output_stream_->Start(this); | |
28 } | |
29 | |
30 void ChromecastDeviceAudioOutputStream::Stop() { | |
31 output_stream_->Stop(); | |
32 } | |
33 | |
34 void ChromecastDeviceAudioOutputStream::SetVolume(double volume) { | |
35 output_stream_->SetVolume(volume); | |
36 } | |
37 | |
38 void ChromecastDeviceAudioOutputStream::GetVolume(double* volume) { | |
39 output_stream_->GetVolume(volume); | |
40 } | |
41 | |
42 void ChromecastDeviceAudioOutputStream::Close() { | |
43 output_stream_->Close(); | |
44 } | |
45 | |
46 int ChromecastDeviceAudioOutputStream::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; | |
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,
| |
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 = | |
58 media::AudioBus::Create(params_.channels, frames); | |
59 int frames_filled = callback_->OnMoreData(bus.get(), total_bytes_delay); | |
60 DCHECK_GE(frames_filled, 0); | |
61 DCHECK_LE(frames_filled, frames); | |
62 | |
63 // Populate |dest| with interleaved data. | |
64 bus->ToInterleaved(frames_filled, params_.bits_per_sample / 8, dest); | |
65 return frames_filled; | |
66 } | |
67 | |
68 void ChromecastDeviceAudioOutputStream::OnError( | |
69 chromecast::CastAudioOutputStream* stream) { | |
70 callback_->OnError(this); | |
71 } | |
72 | |
73 void ChromecastDeviceAudioOutputStream::OnClose() { | |
74 // TODO(slan): Does anything need to be done here? | |
75 DVLOG(1) << "Ouput stream has been closed."; | |
76 } | |
77 | |
78 } // namespace chromecast | |
OLD | NEW |