| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/render_audiosourceprovider.h" | 5 #include "content/renderer/media/render_audiosourceprovider.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/renderer/media/audio_device_factory.h" | 9 #include "content/renderer/media/audio_device_factory.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide
rClient.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAudioSourceProvide
rClient.h" |
| 11 | 11 |
| 12 using content::AudioDeviceFactory; | 12 using content::AudioDeviceFactory; |
| 13 using std::vector; | 13 using std::vector; |
| 14 using WebKit::WebVector; | 14 using WebKit::WebVector; |
| 15 | 15 |
| 16 RenderAudioSourceProvider::RenderAudioSourceProvider() | 16 RenderAudioSourceProvider::RenderAudioSourceProvider() |
| 17 : is_initialized_(false), | 17 : is_initialized_(false), |
| 18 channels_(0), | 18 channels_(0), |
| 19 sample_rate_(0), | 19 sample_rate_(0), |
| 20 is_running_(false), | 20 is_running_(false), |
| 21 volume_(1.0), | |
| 22 renderer_(NULL), | 21 renderer_(NULL), |
| 23 client_(NULL) { | 22 client_(NULL) { |
| 24 // We create the AudioDevice here using the factory. But we don't yet know | 23 // We create the AudioDevice here using the factory. But we don't yet know |
| 25 // the audio format (sample-rate, etc.) at this point. Later, when | 24 // the audio format (sample-rate, etc.) at this point. Later, when |
| 26 // Initialize() is called, we have the audio format information and call | 25 // Initialize() is called, we have the audio format information and call |
| 27 // the AudioDevice::Initialize() method to fully initialize it. | 26 // the AudioDevice::Initialize() method to fully initialize it. |
| 28 default_sink_ = AudioDeviceFactory::Create(); | 27 default_sink_ = AudioDeviceFactory::Create(); |
| 29 } | 28 } |
| 30 | 29 |
| 31 void RenderAudioSourceProvider::setClient( | 30 void RenderAudioSourceProvider::setClient( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void RenderAudioSourceProvider::SetPlaybackRate(float rate) { | 106 void RenderAudioSourceProvider::SetPlaybackRate(float rate) { |
| 108 base::AutoLock auto_lock(sink_lock_); | 107 base::AutoLock auto_lock(sink_lock_); |
| 109 if (!client_) | 108 if (!client_) |
| 110 default_sink_->SetPlaybackRate(rate); | 109 default_sink_->SetPlaybackRate(rate); |
| 111 } | 110 } |
| 112 | 111 |
| 113 bool RenderAudioSourceProvider::SetVolume(double volume) { | 112 bool RenderAudioSourceProvider::SetVolume(double volume) { |
| 114 base::AutoLock auto_lock(sink_lock_); | 113 base::AutoLock auto_lock(sink_lock_); |
| 115 if (!client_) | 114 if (!client_) |
| 116 default_sink_->SetVolume(volume); | 115 default_sink_->SetVolume(volume); |
| 117 volume_ = volume; | |
| 118 return true; | 116 return true; |
| 119 } | 117 } |
| 120 | 118 |
| 121 void RenderAudioSourceProvider::GetVolume(double* volume) { | |
| 122 if (!client_) | |
| 123 default_sink_->GetVolume(volume); | |
| 124 else if (volume) | |
| 125 *volume = volume_; | |
| 126 } | |
| 127 | |
| 128 void RenderAudioSourceProvider::Initialize( | 119 void RenderAudioSourceProvider::Initialize( |
| 129 const media::AudioParameters& params, | 120 const media::AudioParameters& params, |
| 130 RenderCallback* renderer) { | 121 RenderCallback* renderer) { |
| 131 base::AutoLock auto_lock(sink_lock_); | 122 base::AutoLock auto_lock(sink_lock_); |
| 132 CHECK(!is_initialized_); | 123 CHECK(!is_initialized_); |
| 133 renderer_ = renderer; | 124 renderer_ = renderer; |
| 134 | 125 |
| 135 default_sink_->Initialize(params, renderer); | 126 default_sink_->Initialize(params, renderer); |
| 136 | 127 |
| 137 // Keep track of the format in case the client hasn't yet been set. | 128 // Keep track of the format in case the client hasn't yet been set. |
| 138 channels_ = params.channels(); | 129 channels_ = params.channels(); |
| 139 sample_rate_ = params.sample_rate(); | 130 sample_rate_ = params.sample_rate(); |
| 140 | 131 |
| 141 if (client_) { | 132 if (client_) { |
| 142 // Inform WebKit about the audio stream format. | 133 // Inform WebKit about the audio stream format. |
| 143 client_->setFormat(channels_, sample_rate_); | 134 client_->setFormat(channels_, sample_rate_); |
| 144 } | 135 } |
| 145 | 136 |
| 146 is_initialized_ = true; | 137 is_initialized_ = true; |
| 147 } | 138 } |
| 148 | 139 |
| 149 RenderAudioSourceProvider::~RenderAudioSourceProvider() {} | 140 RenderAudioSourceProvider::~RenderAudioSourceProvider() {} |
| OLD | NEW |