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

Side by Side Diff: media/audio/audio_output_dispatcher_impl.cc

Issue 2570923002: Makes AudioOutputDispatcher non-ref-counted. (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « media/audio/audio_output_dispatcher_impl.h ('k') | media/audio/audio_output_proxy.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 (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 "media/audio/audio_output_dispatcher_impl.h" 5 #include "media/audio/audio_output_dispatcher_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 14 matching lines...) Expand all
25 idle_proxies_(0), 25 idle_proxies_(0),
26 close_timer_(FROM_HERE, 26 close_timer_(FROM_HERE,
27 close_delay, 27 close_delay,
28 this, 28 this,
29 &AudioOutputDispatcherImpl::CloseAllIdleStreams), 29 &AudioOutputDispatcherImpl::CloseAllIdleStreams),
30 audio_log_( 30 audio_log_(
31 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)), 31 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)),
32 audio_stream_id_(0) {} 32 audio_stream_id_(0) {}
33 33
34 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() { 34 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() {
35 CHECK(task_runner_->BelongsToCurrentThread());
36
37 // Close all idle streams immediately. The |close_timer_| will handle
38 // invalidating any outstanding tasks upon its destruction.
39 CloseAllIdleStreams();
40
35 // There must be no idle proxy streams. 41 // There must be no idle proxy streams.
36 CHECK_EQ(idle_proxies_, 0u); 42 CHECK_EQ(idle_proxies_, 0u);
37 43
38 // There must be no active proxy streams. 44 // There must be no active proxy streams.
39 CHECK(proxy_to_physical_map_.empty()); 45 CHECK(proxy_to_physical_map_.empty());
DaleCurtis 2016/12/13 20:27:55 Probably this will cause the CHECK() failures we'r
alokp 2016/12/13 20:29:32 Yes
40 46
41 // All idle physical streams must have been closed during shutdown. 47 // All idle physical streams must have been closed during shutdown.
42 CHECK(idle_streams_.empty()); 48 CHECK(idle_streams_.empty());
43 } 49 }
44 50
45 bool AudioOutputDispatcherImpl::OpenStream() { 51 bool AudioOutputDispatcherImpl::OpenStream() {
46 DCHECK(task_runner_->BelongsToCurrentThread()); 52 DCHECK(task_runner_->BelongsToCurrentThread());
47 53
48 // Ensure that there is at least one open stream. 54 // Ensure that there is at least one open stream.
49 if (idle_streams_.empty() && !CreateAndOpenStream()) 55 if (idle_streams_.empty() && !CreateAndOpenStream())
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 121
116 DCHECK_GT(idle_proxies_, 0u); 122 DCHECK_GT(idle_proxies_, 0u);
117 --idle_proxies_; 123 --idle_proxies_;
118 124
119 // Leave at least a single stream running until the close timer fires to help 125 // Leave at least a single stream running until the close timer fires to help
120 // cycle time when streams are opened and closed repeatedly. 126 // cycle time when streams are opened and closed repeatedly.
121 CloseIdleStreams(std::max(idle_proxies_, static_cast<size_t>(1))); 127 CloseIdleStreams(std::max(idle_proxies_, static_cast<size_t>(1)));
122 close_timer_.Reset(); 128 close_timer_.Reset();
123 } 129 }
124 130
125 void AudioOutputDispatcherImpl::Shutdown() {
126 DCHECK(task_runner_->BelongsToCurrentThread());
127
128 // Close all idle streams immediately. The |close_timer_| will handle
129 // invalidating any outstanding tasks upon its destruction.
130 CloseAllIdleStreams();
131
132 // No AudioOutputProxy objects should hold a reference to us when we get
133 // to this stage.
134 DCHECK(HasOneRef()) << "Only the AudioManager should hold a reference";
135
136 LOG_IF(WARNING, idle_proxies_ > 0u) << "Idle proxy streams during shutdown: "
137 << idle_proxies_;
138 LOG_IF(WARNING, !proxy_to_physical_map_.empty())
139 << "Active proxy streams during shutdown: "
140 << proxy_to_physical_map_.size();
141 }
142
143 bool AudioOutputDispatcherImpl::HasOutputProxies() const { 131 bool AudioOutputDispatcherImpl::HasOutputProxies() const {
144 return idle_proxies_ || !proxy_to_physical_map_.empty(); 132 return idle_proxies_ || !proxy_to_physical_map_.empty();
145 } 133 }
146 134
147 bool AudioOutputDispatcherImpl::CreateAndOpenStream() { 135 bool AudioOutputDispatcherImpl::CreateAndOpenStream() {
148 DCHECK(task_runner_->BelongsToCurrentThread()); 136 DCHECK(task_runner_->BelongsToCurrentThread());
149 137
150 const int stream_id = audio_stream_id_++; 138 const int stream_id = audio_stream_id_++;
151 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream( 139 AudioOutputStream* stream = audio_manager_->MakeAudioOutputStream(
152 params_, device_id_, 140 params_, device_id_,
(...skipping 30 matching lines...) Expand all
183 171
184 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream); 172 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream);
185 DCHECK(it != audio_stream_ids_.end()); 173 DCHECK(it != audio_stream_ids_.end());
186 audio_log_->OnClosed(it->second); 174 audio_log_->OnClosed(it->second);
187 audio_stream_ids_.erase(it); 175 audio_stream_ids_.erase(it);
188 } 176 }
189 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end()); 177 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end());
190 } 178 }
191 179
192 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_output_dispatcher_impl.h ('k') | media/audio/audio_output_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698