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

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

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: adds CreateStreamProxy Created 3 years, 11 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
« 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"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "media/audio/audio_output_proxy.h" 13 #include "media/audio/audio_output_proxy.h"
14 14
15 namespace media { 15 namespace media {
16 16
17 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl( 17 AudioOutputDispatcherImpl::AudioOutputDispatcherImpl(
18 AudioManager* audio_manager, 18 AudioManager* audio_manager,
19 const AudioParameters& params, 19 const AudioParameters& params,
20 const std::string& output_device_id, 20 const std::string& output_device_id,
21 const base::TimeDelta& close_delay) 21 const base::TimeDelta& close_delay)
22 : AudioOutputDispatcher(audio_manager, 22 : AudioOutputDispatcher(audio_manager, params, output_device_id),
23 params,
24 output_device_id),
25 idle_proxies_(0), 23 idle_proxies_(0),
26 close_timer_(FROM_HERE, 24 close_timer_(FROM_HERE,
27 close_delay, 25 close_delay,
28 this, 26 this,
29 &AudioOutputDispatcherImpl::CloseAllIdleStreams), 27 &AudioOutputDispatcherImpl::CloseAllIdleStreams),
30 audio_log_( 28 audio_log_(
31 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)), 29 audio_manager->CreateAudioLog(AudioLogFactory::AUDIO_OUTPUT_STREAM)),
32 audio_stream_id_(0) {} 30 audio_stream_id_(0),
31 weak_factory_(this) {}
33 32
34 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() { 33 AudioOutputDispatcherImpl::~AudioOutputDispatcherImpl() {
35 CHECK(task_runner_->BelongsToCurrentThread()); 34 CHECK(task_runner_->BelongsToCurrentThread());
36 35
36 // Stop all active streams.
37 for (auto iter = proxy_to_physical_map_.begin();
38 iter != proxy_to_physical_map_.end();) {
39 // Note: Stopping the stream will invalidate the iterator.
40 // Increment the iterator before stopping the stream.
41 AudioOutputProxy* stream_proxy = iter->first;
42 ++iter;
43 StopStream(stream_proxy);
DaleCurtis 2017/01/10 23:46:34 Note this call does a search over the proxy map, s
alokp 2017/01/11 00:12:50 Done.
44 }
45
37 // Close all idle streams immediately. The |close_timer_| will handle 46 // Close all idle streams immediately. The |close_timer_| will handle
38 // invalidating any outstanding tasks upon its destruction. 47 // invalidating any outstanding tasks upon its destruction.
39 CloseAllIdleStreams(); 48 CloseAllIdleStreams();
40 49
41 // There must be no idle proxy streams.
42 CHECK_EQ(idle_proxies_, 0u);
43
44 // There must be no active proxy streams. 50 // There must be no active proxy streams.
45 CHECK(proxy_to_physical_map_.empty()); 51 CHECK(proxy_to_physical_map_.empty());
46 52
47 // All idle physical streams must have been closed during shutdown. 53 // All idle physical streams must have been closed during shutdown.
48 CHECK(idle_streams_.empty()); 54 CHECK(idle_streams_.empty());
49 } 55 }
50 56
57 AudioOutputProxy* AudioOutputDispatcherImpl::CreateStreamProxy() {
58 DCHECK(task_runner_->BelongsToCurrentThread());
59 return new AudioOutputProxy(weak_factory_.GetWeakPtr());
60 }
61
51 bool AudioOutputDispatcherImpl::OpenStream() { 62 bool AudioOutputDispatcherImpl::OpenStream() {
52 DCHECK(task_runner_->BelongsToCurrentThread()); 63 DCHECK(task_runner_->BelongsToCurrentThread());
53 64
54 // Ensure that there is at least one open stream. 65 // Ensure that there is at least one open stream.
55 if (idle_streams_.empty() && !CreateAndOpenStream()) 66 if (idle_streams_.empty() && !CreateAndOpenStream())
56 return false; 67 return false;
57 68
58 ++idle_proxies_; 69 ++idle_proxies_;
59 close_timer_.Reset(); 70 close_timer_.Reset();
60 return true; 71 return true;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 182
172 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream); 183 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream);
173 DCHECK(it != audio_stream_ids_.end()); 184 DCHECK(it != audio_stream_ids_.end());
174 audio_log_->OnClosed(it->second); 185 audio_log_->OnClosed(it->second);
175 audio_stream_ids_.erase(it); 186 audio_stream_ids_.erase(it);
176 } 187 }
177 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end()); 188 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end());
178 } 189 }
179 190
180 } // namespace media 191 } // 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