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_manager.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chromecast/media/audio/chromecast_device_audio_output_stream.h" | |
9 #include "chromecast/public/cast_audio_output_device.h" | |
10 #include "chromecast/public/cast_audio_stream.h" | |
11 | |
12 namespace chromecast { | |
13 | |
14 namespace { | |
15 | |
16 // Default parameters to provide for input stream. | |
17 const int kDefaultBitsPerSample = 16; | |
18 const int kDefaultInputBufferSize = 1024; | |
19 const int kDefaultSampleRate = 32000; | |
20 | |
21 // Utility to convert media::AudioParameters to chromecast::AudioParameters. | |
22 // TODO(slan): Move these utilties to a central location. | |
23 chromecast::AudioParameters FromChromiumParams( | |
24 const media::AudioParameters& in_params) { | |
25 chromecast::AudioParameters out_params; | |
26 out_params.sample_rate = in_params.sample_rate(); | |
27 out_params.bits_per_sample = in_params.bits_per_sample(); | |
28 out_params.frames_per_buffer = in_params.frames_per_buffer(); | |
29 out_params.channels = in_params.channels(); | |
30 return out_params; | |
31 } | |
32 | |
33 // Utility to convert chromecast::AudioParameters to media::AudioParameters. | |
34 // TODO(slan): Move these utilties to a central location. | |
35 media::AudioParameters FromChromecastParams( | |
36 const chromecast::AudioParameters& in_params) { | |
37 return media::AudioParameters( | |
38 media::AudioParameters::AUDIO_PCM_LINEAR, | |
39 media::GuessChannelLayout(in_params.channels), in_params.sample_rate, | |
40 in_params.bits_per_sample, in_params.frames_per_buffer); | |
41 } | |
byungchul
2015/04/27 17:38:05
a blank line below here please.
slan
2015/04/28 00:11:38
Done.
| |
42 } // namespace | |
43 | |
44 CastAudioManager::CastAudioManager(media::AudioLogFactory* audio_log_factory, | |
45 CastAudioOutputDevice* output_device) | |
46 : media::AudioManagerBase(audio_log_factory), | |
47 audio_output_device_(output_device) { | |
48 CHECK(audio_output_device_); | |
49 SetMaxOutputStreamsAllowed( | |
50 audio_output_device_->GetMaximumOutputStreamsAllowed()); | |
51 } | |
52 | |
53 CastAudioManager::~CastAudioManager() { | |
54 Shutdown(); | |
55 } | |
56 | |
57 bool CastAudioManager::HasAudioOutputDevices() { | |
58 return true; | |
59 } | |
60 | |
61 bool CastAudioManager::HasAudioInputDevices() { | |
62 return false; | |
63 } | |
64 | |
65 void CastAudioManager::ShowAudioInputSettings() { | |
66 LOG(WARNING) << "No support for input audio devices."; | |
67 } | |
68 | |
69 void CastAudioManager::GetAudioInputDeviceNames( | |
70 media::AudioDeviceNames* device_names) { | |
71 DCHECK(device_names->empty()); | |
byungchul
2015/04/27 17:38:05
Is this necessary?
slan
2015/04/28 00:11:38
No. Removed.
| |
72 LOG(WARNING) << "No support for input audio devices."; | |
73 } | |
74 | |
75 media::AudioParameters CastAudioManager::GetInputStreamParameters( | |
76 const std::string& device_id) { | |
77 // TODO(damienv): Providing the default AudioParameters | |
erickung1
2015/04/25 08:38:31
This can be someone else name who will make the ch
slan
2015/04/28 00:11:38
Done. + bug assigned b/20630187
| |
78 // (i.e. invalid parameters) impacts also the output parameter selection | |
79 // during WebAudio playback (and it fails). | |
80 // Figure out why. | |
81 LOG(WARNING) << "No support for input audio devices."; | |
82 return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
83 media::CHANNEL_LAYOUT_STEREO, | |
84 kDefaultSampleRate, kDefaultBitsPerSample, | |
byungchul
2015/04/27 17:38:05
wrap line after , then one argument per line
slan
2015/04/28 00:11:38
Done.
| |
85 kDefaultInputBufferSize); | |
86 } | |
87 | |
88 media::AudioInputStream* CastAudioManager::MakeLinearInputStream( | |
89 const media::AudioParameters& params, | |
90 const std::string& device_id) { | |
91 LOG(WARNING) << "No support for input audio devices"; | |
92 return nullptr; | |
93 } | |
94 | |
95 media::AudioInputStream* CastAudioManager::MakeLowLatencyInputStream( | |
96 const media::AudioParameters& params, | |
97 const std::string& device_id) { | |
98 LOG(WARNING) << "No support for input audio devices"; | |
99 return nullptr; | |
100 } | |
101 | |
102 media::AudioOutputStream* CastAudioManager::MakeLinearOutputStream( | |
103 const media::AudioParameters& params) { | |
104 DCHECK_EQ(media::AudioParameters::AUDIO_PCM_LINEAR, params.format()); | |
105 return MakeCastOutputStream(params); | |
106 } | |
107 | |
108 media::AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( | |
109 const media::AudioParameters& params, | |
110 const std::string& device_id) { | |
111 DCHECK_EQ(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | |
112 return MakeCastOutputStream(params); | |
113 } | |
114 | |
115 media::AudioParameters CastAudioManager::GetPreferredOutputStreamParameters( | |
116 const std::string& output_device_id, | |
117 const media::AudioParameters& suggested) { | |
118 // Convert the suggested params into the chromecast variety. | |
119 chromecast::AudioParameters params = FromChromiumParams(suggested); | |
120 | |
121 // Get the preferences. Convert them back to Chromium params and return. | |
122 params = audio_output_device_->GetPreferredOutputStreamParameters(params); | |
123 return FromChromecastParams(params); | |
124 } | |
125 | |
126 media::AudioOutputStream* CastAudioManager::MakeCastOutputStream( | |
127 const media::AudioParameters& params) { | |
128 // Get the Cast output stream. | |
129 chromecast::AudioParameters chromecast_params = FromChromiumParams(params); | |
130 chromecast::CastAudioOutputStream* stream = | |
131 audio_output_device_->MakeOutputStream(chromecast_params); | |
132 if (!stream) | |
133 return nullptr; | |
134 | |
135 // Host a pass thru interface to translate calls between the stream and the | |
136 // consumer. | |
137 streams_.push_back(make_linked_ptr( | |
138 new ChromecastDeviceAudioOutputStream(stream, chromecast_params))); | |
byungchul
2015/04/27 17:38:05
It is not correct since this function returns a ra
slan
2015/04/28 00:11:38
We need to return a raw pointer to satisfy the ::m
| |
139 return streams_.back().get(); | |
140 } | |
141 | |
142 } // namespace chromecast | |
OLD | NEW |