Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 26 matching lines...) Expand all Loading... | |
| 37 DCHECK(idle_streams_.empty()); | 37 DCHECK(idle_streams_.empty()); |
| 38 DCHECK(pausing_streams_.empty()); | 38 DCHECK(pausing_streams_.empty()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool AudioOutputDispatcherImpl::OpenStream() { | 41 bool AudioOutputDispatcherImpl::OpenStream() { |
| 42 DCHECK_EQ(MessageLoop::current(), message_loop_); | 42 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 43 | 43 |
| 44 paused_proxies_++; | 44 paused_proxies_++; |
| 45 | 45 |
| 46 // Ensure that there is at least one open stream. | 46 // Ensure that there is at least one open stream. |
| 47 if (idle_streams_.empty() && !CreateAndOpenStream()) | 47 if (idle_streams_.empty() && !CreateAndOpenStream()) { |
| 48 paused_proxies_--; | |
|
tommi (sloooow) - chröme
2012/09/21 08:46:27
I'm curious - why not move the ++ below the if ins
DaleCurtis
2012/09/21 17:07:59
That would have made too much sense for this class
| |
| 48 return false; | 49 return false; |
| 50 } | |
| 49 | 51 |
| 50 close_timer_.Reset(); | 52 close_timer_.Reset(); |
| 51 return true; | 53 return true; |
| 52 } | 54 } |
| 53 | 55 |
| 54 bool AudioOutputDispatcherImpl::StartStream( | 56 bool AudioOutputDispatcherImpl::StartStream( |
| 55 AudioOutputStream::AudioSourceCallback* callback, | 57 AudioOutputStream::AudioSourceCallback* callback, |
| 56 AudioOutputProxy* stream_proxy) { | 58 AudioOutputProxy* stream_proxy) { |
| 57 DCHECK_EQ(MessageLoop::current(), message_loop_); | 59 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 58 | 60 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 77 physical_stream->SetVolume(volume); | 79 physical_stream->SetVolume(volume); |
| 78 physical_stream->Start(callback); | 80 physical_stream->Start(callback); |
| 79 proxy_to_physical_map_[stream_proxy] = physical_stream; | 81 proxy_to_physical_map_[stream_proxy] = physical_stream; |
| 80 return true; | 82 return true; |
| 81 } | 83 } |
| 82 | 84 |
| 83 void AudioOutputDispatcherImpl::StopStream(AudioOutputProxy* stream_proxy) { | 85 void AudioOutputDispatcherImpl::StopStream(AudioOutputProxy* stream_proxy) { |
| 84 DCHECK_EQ(MessageLoop::current(), message_loop_); | 86 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 85 | 87 |
| 86 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy); | 88 AudioStreamMap::iterator it = proxy_to_physical_map_.find(stream_proxy); |
| 87 // StopStream() may have already been called. | 89 DCHECK(it != proxy_to_physical_map_.end()); |
| 88 // TODO(dalecurtis): StopStream() shouldn't be called twice! See: | |
| 89 // http://crbug.com/149815 and http://crbug.com/150619 | |
| 90 if (it == proxy_to_physical_map_.end()) | |
| 91 return; | |
| 92 AudioOutputStream* physical_stream = it->second; | 90 AudioOutputStream* physical_stream = it->second; |
| 93 proxy_to_physical_map_.erase(it); | 91 proxy_to_physical_map_.erase(it); |
| 94 | 92 |
| 95 physical_stream->Stop(); | 93 physical_stream->Stop(); |
| 96 | 94 |
| 97 ++paused_proxies_; | 95 ++paused_proxies_; |
| 98 | 96 |
| 99 pausing_streams_.push_front(physical_stream); | 97 pausing_streams_.push_front(physical_stream); |
| 100 | 98 |
| 101 // Don't recycle stream until two buffers worth of time has elapsed. | 99 // Don't recycle stream until two buffers worth of time has elapsed. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // This method is called by |close_timer_|. | 193 // This method is called by |close_timer_|. |
| 196 void AudioOutputDispatcherImpl::ClosePendingStreams() { | 194 void AudioOutputDispatcherImpl::ClosePendingStreams() { |
| 197 DCHECK_EQ(MessageLoop::current(), message_loop_); | 195 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 198 while (!idle_streams_.empty()) { | 196 while (!idle_streams_.empty()) { |
| 199 idle_streams_.back()->Close(); | 197 idle_streams_.back()->Close(); |
| 200 idle_streams_.pop_back(); | 198 idle_streams_.pop_back(); |
| 201 } | 199 } |
| 202 } | 200 } |
| 203 | 201 |
| 204 } // namespace media | 202 } // namespace media |
| OLD | NEW |