Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: content/renderer/media/webaudiosourceprovider_impl.cc

Issue 193303002: WeakPtr destruction order cleanup: media edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/media/webaudiosourceprovider_impl.h ('k') | media/audio/alsa/alsa_input.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/renderer/media/webaudiosourceprovider_impl.h" 5 #include "content/renderer/media/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 30 matching lines...) Expand all
41 private: 41 private:
42 base::Lock& lock_; 42 base::Lock& lock_;
43 const bool acquired_; 43 const bool acquired_;
44 DISALLOW_COPY_AND_ASSIGN(AutoTryLock); 44 DISALLOW_COPY_AND_ASSIGN(AutoTryLock);
45 }; 45 };
46 46
47 } // namespace 47 } // namespace
48 48
49 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl( 49 WebAudioSourceProviderImpl::WebAudioSourceProviderImpl(
50 const scoped_refptr<media::AudioRendererSink>& sink) 50 const scoped_refptr<media::AudioRendererSink>& sink)
51 : weak_this_(this), 51 : channels_(0),
52 channels_(0),
53 sample_rate_(0), 52 sample_rate_(0),
54 volume_(1.0), 53 volume_(1.0),
55 state_(kStopped), 54 state_(kStopped),
56 renderer_(NULL), 55 renderer_(NULL),
57 client_(NULL), 56 client_(NULL),
58 sink_(sink) { 57 sink_(sink),
59 } 58 weak_factory_(this) {}
60 59
61 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() { 60 WebAudioSourceProviderImpl::~WebAudioSourceProviderImpl() {
62 } 61 }
63 62
64 void WebAudioSourceProviderImpl::setClient( 63 void WebAudioSourceProviderImpl::setClient(
65 blink::WebAudioSourceProviderClient* client) { 64 blink::WebAudioSourceProviderClient* client) {
66 base::AutoLock auto_lock(sink_lock_); 65 base::AutoLock auto_lock(sink_lock_);
67 if (client && client != client_) { 66 if (client && client != client_) {
68 // Detach the audio renderer from normal playback. 67 // Detach the audio renderer from normal playback.
69 sink_->Stop(); 68 sink_->Stop();
70 69
71 // The client will now take control by calling provideInput() periodically. 70 // The client will now take control by calling provideInput() periodically.
72 client_ = client; 71 client_ = client;
73 72
74 set_format_cb_ = media::BindToCurrentLoop( 73 set_format_cb_ = media::BindToCurrentLoop(base::Bind(
75 base::Bind(&WebAudioSourceProviderImpl::OnSetFormat, 74 &WebAudioSourceProviderImpl::OnSetFormat, weak_factory_.GetWeakPtr()));
76 weak_this_.GetWeakPtr()));
77 75
78 // 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_|
79 // 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_|
80 // will get called when Initialize() is called. 78 // will get called when Initialize() is called.
81 // Note: Always using |set_format_cb_| ensures we have the same 79 // Note: Always using |set_format_cb_| ensures we have the same
82 // locking order when calling into |client_|. 80 // locking order when calling into |client_|.
83 if (renderer_) 81 if (renderer_)
84 base::ResetAndReturn(&set_format_cb_).Run(); 82 base::ResetAndReturn(&set_format_cb_).Run();
85 } else if (!client && client_) { 83 } else if (!client && client_) {
86 // Restore normal playback. 84 // Restore normal playback.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 void WebAudioSourceProviderImpl::OnSetFormat() { 178 void WebAudioSourceProviderImpl::OnSetFormat() {
181 base::AutoLock auto_lock(sink_lock_); 179 base::AutoLock auto_lock(sink_lock_);
182 if (!client_) 180 if (!client_)
183 return; 181 return;
184 182
185 // Inform Blink about the audio stream format. 183 // Inform Blink about the audio stream format.
186 client_->setFormat(channels_, sample_rate_); 184 client_->setFormat(channels_, sample_rate_);
187 } 185 }
188 186
189 } // namespace content 187 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webaudiosourceprovider_impl.h ('k') | media/audio/alsa/alsa_input.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698