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..03b805bab81cb1956ae120d3bd670c73eb0f4f2a |
| --- /dev/null |
| +++ b/chromecast/media/audio/cast_audio_manager.cc |
| @@ -0,0 +1,141 @@ |
| +// 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/cast_audio_output_stream.h" |
| +#include "chromecast/public/cast_audio_stream.h" |
| +#include "chromecast/public/cast_audio_stream_provider.h" |
| + |
| +namespace media { |
| + |
| +namespace { |
| + |
| +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 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. |
| +AudioParameters FromChromecastParams( |
| + const chromecast::AudioParameters& in_params) { |
| + return AudioParameters(media::AudioParameters::AUDIO_PCM_LINEAR, |
| + GuessChannelLayout(in_params.channels), |
| + in_params.sample_rate, in_params.bits_per_sample, |
| + in_params.frames_per_buffer); |
| +} |
| + |
| +} // namespace |
| +CastAudioManager::CastAudioManager( |
|
lcwu1
2015/04/24 02:18:24
Leave a vertical space above this line.
slan
2015/04/24 05:34:26
Done.
|
| + AudioLogFactory* audio_log_factory, |
| + chromecast::CastAudioStreamProvider* stream_provider) |
| + : AudioManagerBase(audio_log_factory), |
| + audio_stream_provider_(stream_provider) { |
| + CHECK(audio_stream_provider_); |
| + SetMaxOutputStreamsAllowed( |
| + audio_stream_provider_->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( |
| + AudioDeviceNames* device_names) { |
| + DCHECK(device_names->empty()); |
| + LOG(WARNING) << "No support for input audio devices."; |
| +} |
| + |
| +AudioParameters CastAudioManager::GetInputStreamParameters( |
| + const std::string& device_id) { |
| + // TODO(damienv): Providing the default AudioParameters |
| + // (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 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| + CHANNEL_LAYOUT_STEREO, kDefaultSampleRate, |
| + kDefaultBitsPerSample, kDefaultInputBufferSize); |
| +} |
| + |
| +AudioInputStream* CastAudioManager::MakeLinearInputStream( |
| + const AudioParameters& params, |
| + const std::string& device_id) { |
| + LOG(WARNING) << "No support for input audio devices"; |
| + return nullptr; |
| +} |
| + |
| +AudioInputStream* CastAudioManager::MakeLowLatencyInputStream( |
| + const AudioParameters& params, |
| + const std::string& device_id) { |
| + LOG(WARNING) << "No support for input audio devices"; |
| + return nullptr; |
| +} |
| + |
| +AudioOutputStream* CastAudioManager::MakeLinearOutputStream( |
| + const AudioParameters& params) { |
| + DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| + return MakeCastOutputStream(params); |
| +} |
| + |
| +AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( |
| + const AudioParameters& params, |
| + const std::string& device_id) { |
| + DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| + return MakeCastOutputStream(params); |
| +} |
| + |
| +AudioParameters CastAudioManager::GetPreferredOutputStreamParameters( |
| + const std::string& output_device_id, |
| + const 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_stream_provider_->GetPreferredOutputStreamParameters(params); |
| + return FromChromecastParams(params); |
| +} |
| + |
| +AudioOutputStream* CastAudioManager::MakeCastOutputStream( |
| + const AudioParameters& params) { |
| + // Get the Cast output stream. |
| + chromecast::AudioParameters chromecast_params = FromChromiumParams(params); |
| + chromecast::AudioOutputStream* stream = |
| + audio_stream_provider_->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 CastAudioOutputStream(stream, chromecast_params))); |
| + return streams_.back().get(); |
| +} |
| + |
| +} // namespace media |