OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "media/blink/webaudiosourceprovider_impl.h" | 5 #include "media/blink/webaudiosourceprovider_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl( | 50 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl( |
51 const scoped_refptr<RestartableAudioRendererSink>& sink) | 51 const scoped_refptr<RestartableAudioRendererSink>& sink) |
52 : channels_(0), | 52 : channels_(0), |
53 sample_rate_(0), | 53 sample_rate_(0), |
54 volume_(1.0), | 54 volume_(1.0), |
55 state_(kStopped), | 55 state_(kStopped), |
56 renderer_(NULL), | 56 renderer_(NULL), |
57 client_(NULL), | 57 client_(NULL), |
58 sink_(sink), | 58 sink_(sink), |
| 59 enable_audio_focus_(false), |
59 weak_factory_(this) {} | 60 weak_factory_(this) {} |
60 | 61 |
61 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() { | 62 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() { |
62 } | 63 } |
63 | 64 |
64 void WebAudioSourceProviderImpl::setClient( | 65 void WebAudioSourceProviderImpl::setClient( |
65 blink::WebAudioSourceProviderClient* client) { | 66 blink::WebAudioSourceProviderClient* client) { |
66 base::AutoLock auto_lock(sink_lock_); | 67 base::AutoLock auto_lock(sink_lock_); |
67 if (client && client != client_) { | 68 if (client && client != client_) { |
68 // Detach the audio renderer from normal playback. | 69 // Detach the audio renderer from normal playback. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 return sink_->GetOutputDevice(); | 171 return sink_->GetOutputDevice(); |
171 } | 172 } |
172 | 173 |
173 void WebAudioSourceProviderImpl::Initialize( | 174 void WebAudioSourceProviderImpl::Initialize( |
174 const AudioParameters& params, | 175 const AudioParameters& params, |
175 RenderCallback* renderer) { | 176 RenderCallback* renderer) { |
176 base::AutoLock auto_lock(sink_lock_); | 177 base::AutoLock auto_lock(sink_lock_); |
177 renderer_ = renderer; | 178 renderer_ = renderer; |
178 | 179 |
179 DCHECK_EQ(state_, kStopped); | 180 DCHECK_EQ(state_, kStopped); |
180 sink_->Initialize(params, renderer); | 181 |
| 182 if (enable_audio_focus_) { |
| 183 AudioParameters new_params = params; |
| 184 new_params.set_effects(params.effects() | AudioParameters::FOCUSABLE); |
| 185 sink_->Initialize(new_params, renderer); |
| 186 } else { |
| 187 sink_->Initialize(params, renderer); |
| 188 } |
181 | 189 |
182 // Keep track of the format in case the client hasn't yet been set. | 190 // Keep track of the format in case the client hasn't yet been set. |
183 channels_ = params.channels(); | 191 channels_ = params.channels(); |
184 sample_rate_ = params.sample_rate(); | 192 sample_rate_ = params.sample_rate(); |
185 | 193 |
186 if (!set_format_cb_.is_null()) | 194 if (!set_format_cb_.is_null()) |
187 base::ResetAndReturn(&set_format_cb_).Run(); | 195 base::ResetAndReturn(&set_format_cb_).Run(); |
188 } | 196 } |
189 | 197 |
190 void WebAudioSourceProviderImpl::OnSetFormat() { | 198 void WebAudioSourceProviderImpl::OnSetFormat() { |
191 base::AutoLock auto_lock(sink_lock_); | 199 base::AutoLock auto_lock(sink_lock_); |
192 if (!client_) | 200 if (!client_) |
193 return; | 201 return; |
194 | 202 |
195 // Inform Blink about the audio stream format. | 203 // Inform Blink about the audio stream format. |
196 client_->setFormat(channels_, sample_rate_); | 204 client_->setFormat(channels_, sample_rate_); |
197 } | 205 } |
198 | 206 |
199 } // namespace media | 207 } // namespace media |
OLD | NEW |