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

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

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: adds StopPhysicalStream 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_) {
38 StopPhysicalStream(iter.second);
39 }
40
37 // Close all idle streams immediately. The |close_timer_| will handle 41 // Close all idle streams immediately. The |close_timer_| will handle
38 // invalidating any outstanding tasks upon its destruction. 42 // invalidating any outstanding tasks upon its destruction.
39 CloseAllIdleStreams(); 43 CloseAllIdleStreams();
40 44
41 // There must be no idle proxy streams.
42 CHECK_EQ(idle_proxies_, 0u);
43
44 // There must be no active proxy streams.
45 CHECK(proxy_to_physical_map_.empty());
46
47 // All idle physical streams must have been closed during shutdown. 45 // All idle physical streams must have been closed during shutdown.
48 CHECK(idle_streams_.empty()); 46 CHECK(idle_streams_.empty());
49 } 47 }
50 48
49 AudioOutputProxy* AudioOutputDispatcherImpl::CreateStreamProxy() {
50 DCHECK(task_runner_->BelongsToCurrentThread());
51 return new AudioOutputProxy(weak_factory_.GetWeakPtr());
52 }
53
51 bool AudioOutputDispatcherImpl::OpenStream() { 54 bool AudioOutputDispatcherImpl::OpenStream() {
52 DCHECK(task_runner_->BelongsToCurrentThread()); 55 DCHECK(task_runner_->BelongsToCurrentThread());
53 56
54 // Ensure that there is at least one open stream. 57 // Ensure that there is at least one open stream.
55 if (idle_streams_.empty() && !CreateAndOpenStream()) 58 if (idle_streams_.empty() && !CreateAndOpenStream())
56 return false; 59 return false;
57 60
58 ++idle_proxies_; 61 ++idle_proxies_;
59 close_timer_.Reset(); 62 close_timer_.Reset();
60 return true; 63 return true;
(...skipping 26 matching lines...) Expand all
87 90
88 close_timer_.Reset(); 91 close_timer_.Reset();
89 return true; 92 return true;
90 } 93 }
91 94
92 void AudioOutputDispatcherImpl::StopStream(AudioOutputProxy* stream_proxy) { 95 void AudioOutputDispatcherImpl::StopStream(AudioOutputProxy* stream_proxy) {
93 DCHECK(task_runner_->BelongsToCurrentThread()); 96 DCHECK(task_runner_->BelongsToCurrentThread());
94 97
95 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy); 98 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy);
96 DCHECK(it != proxy_to_physical_map_.end()); 99 DCHECK(it != proxy_to_physical_map_.end());
97 AudioOutputStream* physical_stream = it->second; 100 StopPhysicalStream(it->second);
98 proxy_to_physical_map_.erase(it); 101 proxy_to_physical_map_.erase(it);
99
100 physical_stream->Stop();
101 audio_log_->OnStopped(audio_stream_ids_[physical_stream]);
102 ++idle_proxies_; 102 ++idle_proxies_;
103 idle_streams_.push_back(physical_stream);
104
105 close_timer_.Reset();
106 } 103 }
107 104
108 void AudioOutputDispatcherImpl::StreamVolumeSet(AudioOutputProxy* stream_proxy, 105 void AudioOutputDispatcherImpl::StreamVolumeSet(AudioOutputProxy* stream_proxy,
109 double volume) { 106 double volume) {
110 DCHECK(task_runner_->BelongsToCurrentThread()); 107 DCHECK(task_runner_->BelongsToCurrentThread());
111 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy); 108 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy);
112 if (it != proxy_to_physical_map_.end()) { 109 if (it != proxy_to_physical_map_.end()) {
113 AudioOutputStream* physical_stream = it->second; 110 AudioOutputStream* physical_stream = it->second;
114 physical_stream->SetVolume(volume); 111 physical_stream->SetVolume(volume);
115 audio_log_->OnSetVolume(audio_stream_ids_[physical_stream], volume); 112 audio_log_->OnSetVolume(audio_stream_ids_[physical_stream], volume);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 stream->Close(); 167 stream->Close();
171 168
172 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream); 169 AudioStreamIDMap::iterator it = audio_stream_ids_.find(stream);
173 DCHECK(it != audio_stream_ids_.end()); 170 DCHECK(it != audio_stream_ids_.end());
174 audio_log_->OnClosed(it->second); 171 audio_log_->OnClosed(it->second);
175 audio_stream_ids_.erase(it); 172 audio_stream_ids_.erase(it);
176 } 173 }
177 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end()); 174 idle_streams_.erase(idle_streams_.begin() + keep_alive, idle_streams_.end());
178 } 175 }
179 176
177 void AudioOutputDispatcherImpl::StopPhysicalStream(AudioOutputStream* stream) {
178 DCHECK(task_runner_->BelongsToCurrentThread());
179 stream->Stop();
180 audio_log_->OnStopped(audio_stream_ids_[stream]);
181 idle_streams_.push_back(stream);
182 close_timer_.Reset();
183 }
184
180 } // namespace media 185 } // 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