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..6bbbeb3a1c39ffd60751045ea5d4f000577204a9 |
| --- /dev/null |
| +++ b/chromecast/media/audio/cast_audio_manager.cc |
| @@ -0,0 +1,125 @@ |
| +// 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/base/task_runner_impl.h" |
| +#include "chromecast/media/audio/chromecast_device_audio_output_stream.h" |
| +#include "chromecast/media/base/converters.h" |
| +#include "chromecast/public/cast_audio_output_device.h" |
| +#include "chromecast/public/cast_audio_output_stream.h" |
| + |
| +namespace chromecast { |
| +namespace media { |
| + |
| +namespace { |
| + |
| +// Default parameters to provide for input stream. |
| +const int kDefaultBitsPerSample = 16; |
| +const int kDefaultInputBufferSize = 1024; |
| +const int kDefaultSampleRate = 32000; |
| + |
| +} // 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) { |
| + LOG(WARNING) << "No support for input audio devices."; |
| +} |
| + |
| +::media::AudioParameters CastAudioManager::GetInputStreamParameters( |
| + const std::string& device_id) { |
| + // TODO(slan): Providing the invalid parameters impacts also the output |
| + // parameter selection during WebAudio playback (and it fails). (b/20630187). |
| + LOG(WARNING) << "No support for input audio devices."; |
| + return ::media::AudioParameters( |
| + ::media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| + ::media::CHANNEL_LAYOUT_STEREO, |
| + kDefaultSampleRate, |
| + kDefaultBitsPerSample, |
| + 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. |
| + 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. |
| + AudioParameters chromecast_params = FromChromiumParams(params); |
| + CastAudioOutputStream* stream = audio_output_device_->MakeOutputStream( |
| + chromecast_params, new chromecast::TaskRunnerImpl()); |
|
halliwell
2015/07/29 15:06:57
nit: chromecast:: unnecessary.
slan
2015/07/29 19:51:55
Removed.
|
| + if (!stream) |
| + return nullptr; |
| + |
| + // Note: The caller of this method does not own the returned instance of the |
| + // stream. The stream MUST call AudioManagerBase::ReleaseOutputStream() as |
| + // the last line of its Close() method to avoid a leak. This pattern is not |
| + // favorable, but is currently required by AudioManagerBase. Please see |
| + // ChromecastDeviceAudioOutputStream::Close() before changing this behavior. |
| + return new ChromecastDeviceAudioOutputStream(stream, chromecast_params, this); |
| +} |
| + |
| +} // namespace media |
| +} // namespace chromecast |