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/bind_to_current_loop.h" |
10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "media/base/bind_to_current_loop.h" | |
13 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" | 13 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" |
14 | 14 |
15 using blink::WebVector; | 15 using blink::WebVector; |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // Simple helper class for Try() locks. Lock is Try()'d on construction and | 21 // Simple helper class for Try() locks. Lock is Try()'d on construction and |
22 // must be checked via the locked() attribute. If acquisition was successful | 22 // must be checked via the locked() attribute. If acquisition was successful |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 void WebAudioSourceProviderImpl::setClient( | 63 void WebAudioSourceProviderImpl::setClient( |
64 blink::WebAudioSourceProviderClient* client) { | 64 blink::WebAudioSourceProviderClient* client) { |
65 base::AutoLock auto_lock(sink_lock_); | 65 base::AutoLock auto_lock(sink_lock_); |
66 if (client && client != client_) { | 66 if (client && client != client_) { |
67 // Detach the audio renderer from normal playback. | 67 // Detach the audio renderer from normal playback. |
68 sink_->Stop(); | 68 sink_->Stop(); |
69 | 69 |
70 // The client will now take control by calling provideInput() periodically. | 70 // The client will now take control by calling provideInput() periodically. |
71 client_ = client; | 71 client_ = client; |
72 | 72 |
73 set_format_cb_ = BindToCurrentLoop(base::Bind( | 73 set_format_cb_ = base::BindToCurrentLoop(base::Bind( |
74 &WebAudioSourceProviderImpl::OnSetFormat, weak_factory_.GetWeakPtr())); | 74 &WebAudioSourceProviderImpl::OnSetFormat, weak_factory_.GetWeakPtr())); |
75 | 75 |
76 // If |renderer_| is set, then run |set_format_cb_| to send |client_| | 76 // If |renderer_| is set, then run |set_format_cb_| to send |client_| |
77 // the current format info. If |renderer_| is not set, then |set_format_cb_| | 77 // the current format info. If |renderer_| is not set, then |set_format_cb_| |
78 // will get called when Initialize() is called. | 78 // will get called when Initialize() is called. |
79 // Note: Always using |set_format_cb_| ensures we have the same | 79 // Note: Always using |set_format_cb_| ensures we have the same |
80 // locking order when calling into |client_|. | 80 // locking order when calling into |client_|. |
81 if (renderer_) | 81 if (renderer_) |
82 base::ResetAndReturn(&set_format_cb_).Run(); | 82 base::ResetAndReturn(&set_format_cb_).Run(); |
83 } else if (!client && client_) { | 83 } else if (!client && client_) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void WebAudioSourceProviderImpl::OnSetFormat() { | 184 void WebAudioSourceProviderImpl::OnSetFormat() { |
185 base::AutoLock auto_lock(sink_lock_); | 185 base::AutoLock auto_lock(sink_lock_); |
186 if (!client_) | 186 if (!client_) |
187 return; | 187 return; |
188 | 188 |
189 // Inform Blink about the audio stream format. | 189 // Inform Blink about the audio stream format. |
190 client_->setFormat(channels_, sample_rate_); | 190 client_->setFormat(channels_, sample_rate_); |
191 } | 191 } |
192 | 192 |
193 } // namespace media | 193 } // namespace media |
OLD | NEW |