Chromium Code Reviews| 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/cast_audio_output_stream.h" | |
| 9 #include "chromecast/public/cast_audio_stream.h" | |
| 10 #include "chromecast/public/cast_audio_stream_provider.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const int kDefaultBitsPerSample = 16; | |
| 17 const int kDefaultInputBufferSize = 1024; | |
| 18 const int kDefaultSampleRate = 32000; | |
| 19 | |
| 20 // Utility to convert media::AudioParameters to chromecast::AudioParameters. | |
| 21 // TODO(slan): Move these utilties to a central location. | |
| 22 chromecast::AudioParameters FromChromiumParams( | |
| 23 const AudioParameters& in_params) { | |
| 24 chromecast::AudioParameters out_params; | |
| 25 out_params.sample_rate = in_params.sample_rate(); | |
| 26 out_params.bits_per_sample = in_params.bits_per_sample(); | |
| 27 out_params.frames_per_buffer = in_params.frames_per_buffer(); | |
| 28 out_params.channels = in_params.channels(); | |
| 29 return out_params; | |
| 30 } | |
| 31 | |
| 32 // Utility to convert chromecast::AudioParameters to media::AudioParameters. | |
| 33 // TODO(slan): Move these utilties to a central location. | |
| 34 AudioParameters FromChromecastParams( | |
| 35 const chromecast::AudioParameters& in_params) { | |
| 36 return AudioParameters(media::AudioParameters::AUDIO_PCM_LINEAR, | |
| 37 GuessChannelLayout(in_params.channels), | |
| 38 in_params.sample_rate, in_params.bits_per_sample, | |
| 39 in_params.frames_per_buffer); | |
| 40 } | |
| 41 | |
| 42 } // namespace | |
| 43 CastAudioManager::CastAudioManager( | |
| 
 
lcwu1
2015/04/24 02:18:24
Leave a vertical space above this line.
 
slan
2015/04/24 05:34:26
Done.
 
 | |
| 44 AudioLogFactory* audio_log_factory, | |
| 45 chromecast::CastAudioStreamProvider* stream_provider) | |
| 46 : AudioManagerBase(audio_log_factory), | |
| 47 audio_stream_provider_(stream_provider) { | |
| 48 CHECK(audio_stream_provider_); | |
| 49 SetMaxOutputStreamsAllowed( | |
| 50 audio_stream_provider_->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 AudioDeviceNames* device_names) { | |
| 71 DCHECK(device_names->empty()); | |
| 72 LOG(WARNING) << "No support for input audio devices."; | |
| 73 } | |
| 74 | |
| 75 AudioParameters CastAudioManager::GetInputStreamParameters( | |
| 76 const std::string& device_id) { | |
| 77 // TODO(damienv): Providing the default AudioParameters | |
| 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 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
| 83 CHANNEL_LAYOUT_STEREO, kDefaultSampleRate, | |
| 84 kDefaultBitsPerSample, kDefaultInputBufferSize); | |
| 85 } | |
| 86 | |
| 87 AudioInputStream* CastAudioManager::MakeLinearInputStream( | |
| 88 const AudioParameters& params, | |
| 89 const std::string& device_id) { | |
| 90 LOG(WARNING) << "No support for input audio devices"; | |
| 91 return nullptr; | |
| 92 } | |
| 93 | |
| 94 AudioInputStream* CastAudioManager::MakeLowLatencyInputStream( | |
| 95 const AudioParameters& params, | |
| 96 const std::string& device_id) { | |
| 97 LOG(WARNING) << "No support for input audio devices"; | |
| 98 return nullptr; | |
| 99 } | |
| 100 | |
| 101 AudioOutputStream* CastAudioManager::MakeLinearOutputStream( | |
| 102 const AudioParameters& params) { | |
| 103 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | |
| 104 return MakeCastOutputStream(params); | |
| 105 } | |
| 106 | |
| 107 AudioOutputStream* CastAudioManager::MakeLowLatencyOutputStream( | |
| 108 const AudioParameters& params, | |
| 109 const std::string& device_id) { | |
| 110 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | |
| 111 return MakeCastOutputStream(params); | |
| 112 } | |
| 113 | |
| 114 AudioParameters CastAudioManager::GetPreferredOutputStreamParameters( | |
| 115 const std::string& output_device_id, | |
| 116 const AudioParameters& suggested) { | |
| 117 // Convert the suggested params into the chromecast variety. | |
| 118 chromecast::AudioParameters params = FromChromiumParams(suggested); | |
| 119 | |
| 120 // Get the preferences. Convert them back to Chromium params and return. | |
| 121 params = audio_stream_provider_->GetPreferredOutputStreamParameters(params); | |
| 122 return FromChromecastParams(params); | |
| 123 } | |
| 124 | |
| 125 AudioOutputStream* CastAudioManager::MakeCastOutputStream( | |
| 126 const AudioParameters& params) { | |
| 127 // Get the Cast output stream. | |
| 128 chromecast::AudioParameters chromecast_params = FromChromiumParams(params); | |
| 129 chromecast::AudioOutputStream* stream = | |
| 130 audio_stream_provider_->MakeOutputStream(chromecast_params); | |
| 131 if (!stream) | |
| 132 return nullptr; | |
| 133 | |
| 134 // Host a pass thru interface to translate calls between the stream and the | |
| 135 // consumer. | |
| 136 streams_.push_back( | |
| 137 make_linked_ptr(new CastAudioOutputStream(stream, chromecast_params))); | |
| 138 return streams_.back().get(); | |
| 139 } | |
| 140 | |
| 141 } // namespace media | |
| OLD | NEW |