Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: chromecast/media/audio/chromecast_device_audio_output_stream.cc

Issue 1105803002: Exposes a shlib interface for media/audio path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment out streaming test until the default implementation is improved. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 namespace media {
11
12 ChromecastDeviceAudioOutputStream::ChromecastDeviceAudioOutputStream(
13 CastAudioOutputStream* output_stream,
14 const AudioParameters& params,
15 CastAudioManager* manager)
16 : output_stream_(output_stream),
17 callback_(nullptr),
18 params_(params),
19 audio_manager_(manager) {
20 // Verify validity of parameters.
21 DCHECK(output_stream_);
22 DCHECK(params_.bits_per_sample == 8 || params_.bits_per_sample == 16 ||
23 params_.bits_per_sample == 32);
24 }
25
26 ChromecastDeviceAudioOutputStream::~ChromecastDeviceAudioOutputStream() {
27 }
28
29 bool ChromecastDeviceAudioOutputStream::Open() {
30 DCHECK(output_stream_);
31 return output_stream_->Open();
32 }
33
34 void ChromecastDeviceAudioOutputStream::Start(
35 ::media::AudioOutputStream::AudioSourceCallback* callback) {
36 DCHECK(output_stream_);
37 DCHECK(callback);
38 callback_ = callback;
39 output_stream_->Start(this);
40 }
41
42 void ChromecastDeviceAudioOutputStream::Stop() {
43 DCHECK(output_stream_);
44 // Note that Stop() may generate AudioSourceCallback events. Ignore these by
45 // setting the callback to NULL before calling stop.
46 callback_ = nullptr;
47 output_stream_->Stop();
48 }
49
50 void ChromecastDeviceAudioOutputStream::SetVolume(double volume) {
51 DCHECK(output_stream_);
52 output_stream_->SetVolume(volume);
53 }
54
55 void ChromecastDeviceAudioOutputStream::GetVolume(double* volume) {
56 DCHECK(output_stream_);
57 DCHECK(volume);
58 *volume = output_stream_->GetVolume();
59 }
60
61 void ChromecastDeviceAudioOutputStream::Close() {
62 DCHECK(output_stream_);
63 DCHECK(audio_manager_);
64
65 // Close the underlying stream.
66 output_stream_->Close();
67 output_stream_ = nullptr;
68
69 // Note: This method must be called to avoid a leak. |this| will be deleted
70 // in this call, so this must be the last line, and this object must not be
71 // used after this function returns. Please see
72 // CastAudioManager::MakeCastOutputStream before changing this behavaior.
73 // TODO(slan): m43 does not have the below API, so commit suicide instead.
74 audio_manager_->ReleaseOutputStream(this);
75 }
76
77 int ChromecastDeviceAudioOutputStream::GetMoreData(void* dest,
78 uint32_t len,
79 int32_t frames,
80 uint32_t total_bytes_delay) {
81 CHECK(dest);
82 CHECK_GE(frames, 0);
83 uint32_t bytes_needed =
84 frames * params_.channels * params_.bits_per_sample / 8;
85 CHECK_GE(len, bytes_needed);
86
87 // If the stream has been Stop()ped, return no frames filled.
88 if (!callback_)
89 return 0;
90
91 // Pass an empty audio bus of the right size to the source to be filled.
92 scoped_ptr< ::media::AudioBus> bus =
93 ::media::AudioBus::Create(params_.channels, frames);
94 int frames_filled = callback_->OnMoreData(bus.get(), total_bytes_delay);
95 DCHECK_GE(frames_filled, 0);
96 DCHECK_LE(frames_filled, frames);
97
98 // Populate |dest| with interleaved data.
99 bus->ToInterleaved(frames_filled, params_.bits_per_sample / 8, dest);
100 return frames_filled;
101 }
102
103 void ChromecastDeviceAudioOutputStream::OnError(CastAudioOutputStream* stream) {
104 if (callback_)
105 callback_->OnError(this);
106 }
107
108 } // namespace media
109 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698