Chromium Code Reviews| Index: chromecast/media/audio/cast_audio_manager.cc |
| diff --git a/chromecast/media/audio/cast_audio_manager.cc b/chromecast/media/audio/cast_audio_manager.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..26a2c6caaf4b40ed67956f6c9f7f0bd66ee72b2c |
| --- /dev/null |
| +++ b/chromecast/media/audio/cast_audio_manager.cc |
| @@ -0,0 +1,142 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromecast/media/audio/cast_audio_manager.h" |
| + |
| +#include "base/logging.h" |
| +#include "chromecast/media/audio/chromecast_device_audio_output_stream.h" |
| +#include "chromecast/public/cast_audio_output_device.h" |
| +#include "chromecast/public/cast_audio_stream.h" |
| + |
| +namespace chromecast { |
| + |
| +namespace { |
| + |
| +// Default parameters to provide for input stream. |
| +const int kDefaultBitsPerSample = 16; |
| +const int kDefaultInputBufferSize = 1024; |
| +const int kDefaultSampleRate = 32000; |
| + |
| +// Utility to convert media::AudioParameters to chromecast::AudioParameters. |
| +// TODO(slan): Move these utilties to a central location. |
| +chromecast::AudioParameters FromChromiumParams( |
| + const media::AudioParameters& in_params) { |
| + chromecast::AudioParameters out_params; |
| + out_params.sample_rate = in_params.sample_rate(); |
| + out_params.bits_per_sample = in_params.bits_per_sample(); |
| + out_params.frames_per_buffer = in_params.frames_per_buffer(); |
| + out_params.channels = in_params.channels(); |
| + return out_params; |
| +} |
| + |
| +// Utility to convert chromecast::AudioParameters to media::AudioParameters. |
| +// TODO(slan): Move these utilties to a central location. |
| +media::AudioParameters FromChromecastParams( |
| + const chromecast::AudioParameters& in_params) { |
| + return media::AudioParameters( |
| + media::AudioParameters::AUDIO_PCM_LINEAR, |
| + media::GuessChannelLayout(in_params.channels), in_params.sample_rate, |
| + in_params.bits_per_sample, in_params.frames_per_buffer); |
| +} |
|
byungchul
2015/04/27 17:38:05
a blank line below here please.
slan
2015/04/28 00:11:38
Done.
|
| +} // namespace |
| + |
| +CastAudioManager::CastAudioManager(media::AudioLogFactory* audio_log_factory, |
| + CastAudioOutputDevice* output_device) |
| + : media::AudioManagerBase(audio_log_factory), |
| + audio_output_device_(output_device) { |
| + CHECK(audio_output_device_); |
| + SetMaxOutputStreamsAllowed( |
| + audio_output_device_->GetMaximumOutputStreamsAllowed()); |
| +} |
| + |
| +CastAudioManager::~CastAudioManager() { |
| + Shutdown(); |
| +} |
| + |
| +bool CastAudioManager::HasAudioOutputDevices() { |
| + return true; |
| +} |
| + |
| +bool CastAudioManager::HasAudioInputDevices() { |
| + return false; |
| +} |
| + |
| +void CastAudioManager::ShowAudioInputSettings() { |
| + LOG(WARNING) << "No support for input audio devices."; |
| +} |
| + |
| +void CastAudioManager::GetAudioInputDeviceNames( |
| + media::AudioDeviceNames* device_names) { |
| + DCHECK(device_names->empty()); |
|
byungchul
2015/04/27 17:38:05
Is this necessary?
slan
2015/04/28 00:11:38
No. Removed.
|
| + LOG(WARNING) << "No support for input audio devices."; |
| +} |
| + |
| +media::AudioParameters CastAudioManager::GetInputStreamParameters( |
| + const std::string& device_id) { |
| + // 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
|
| + // (i.e. invalid parameters) impacts also the output parameter selection |
| + // during WebAudio playback (and it fails). |
| + // Figure out why. |
| + LOG(WARNING) << "No support for input audio devices."; |
| + return media::AudioParameters(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| + media::CHANNEL_LAYOUT_STEREO, |
| + 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.
|
| + kDefaultInputBufferSize); |
| +} |
| + |
| +media::AudioInputStream* CastAudioManager::MakeLinearInputStream( |
| + const media::AudioParameters& params, |
| + const std::string& device_id) { |
| + LOG(WARNING) << "No support for input audio devices"; |
| + return nullptr; |
| +} |
| + |
| +media::AudioInputStream* CastAudioManager::MakeLowLatencyInputStream( |
| + const media::AudioParameters& params, |
| + const std::string& device_id) { |
| + LOG(WARNING) << "No support for input audio devices"; |
| + return nullptr; |
| +} |
| + |
| +media::AudioOutputStream* CastAudioManager::MakeLinearOutputStream( |
| + const media::AudioParameters& params) { |
| + DCHECK_EQ(media::AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| + return MakeCastOutputStream(params); |
| +} |
| + |
| +media::AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( |
| + const media::AudioParameters& params, |
| + const std::string& device_id) { |
| + DCHECK_EQ(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| + return MakeCastOutputStream(params); |
| +} |
| + |
| +media::AudioParameters CastAudioManager::GetPreferredOutputStreamParameters( |
| + const std::string& output_device_id, |
| + const media::AudioParameters& suggested) { |
| + // Convert the suggested params into the chromecast variety. |
| + chromecast::AudioParameters params = FromChromiumParams(suggested); |
| + |
| + // Get the preferences. Convert them back to Chromium params and return. |
| + params = audio_output_device_->GetPreferredOutputStreamParameters(params); |
| + return FromChromecastParams(params); |
| +} |
| + |
| +media::AudioOutputStream* CastAudioManager::MakeCastOutputStream( |
| + const media::AudioParameters& params) { |
| + // Get the Cast output stream. |
| + chromecast::AudioParameters chromecast_params = FromChromiumParams(params); |
| + chromecast::CastAudioOutputStream* stream = |
| + audio_output_device_->MakeOutputStream(chromecast_params); |
| + if (!stream) |
| + return nullptr; |
| + |
| + // Host a pass thru interface to translate calls between the stream and the |
| + // consumer. |
| + streams_.push_back(make_linked_ptr( |
| + 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
|
| + return streams_.back().get(); |
| +} |
| + |
| +} // namespace chromecast |