Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "media/audio/audio_output_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "media/audio/audio_io.h" | 9 #include "media/audio/audio_io.h" |
| 10 | 10 |
| 11 AudioOutputDispatcher::AudioOutputDispatcher( | 11 AudioOutputDispatcher::AudioOutputDispatcher( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 | 54 |
| 55 // Schedule task to allocate streams for other proxies if we need to. | 55 // Schedule task to allocate streams for other proxies if we need to. |
| 56 message_loop_->PostTask(FROM_HERE, NewRunnableMethod( | 56 message_loop_->PostTask(FROM_HERE, NewRunnableMethod( |
| 57 this, &AudioOutputDispatcher::OpenTask)); | 57 this, &AudioOutputDispatcher::OpenTask)); |
| 58 | 58 |
| 59 return stream; | 59 return stream; |
| 60 } | 60 } |
| 61 | 61 |
| 62 void AudioOutputDispatcher::StreamStopped(AudioOutputStream* stream) { | 62 void AudioOutputDispatcher::StreamStopped(AudioOutputStream* stream) { |
| 63 DCHECK_EQ(MessageLoop::current(), message_loop_); | 63 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 64 | |
| 64 paused_proxies_++; | 65 paused_proxies_++; |
| 66 | |
| 67 idle_streams_.push_front(stream); | |
|
Sergey Ulanov
2011/04/09 07:02:05
Looks to me that we may leak streams that are in i
| |
| 68 | |
| 69 // Don't recycle stream until two buffers worth of time has elapsed | |
|
Sergey Ulanov
2011/04/09 07:02:05
nit: period at the end of the comment.
| |
| 70 message_loop_->PostDelayedTask(FROM_HERE, NewRunnableMethod( | |
| 71 this, &AudioOutputDispatcher::StopStreamTask), | |
| 72 2 * params_.samples_per_packet * 1000 / params_.sample_rate); | |
|
Sergey Ulanov
2011/04/09 07:02:05
nit: This line is not indented properly. I would m
Sergey Ulanov
2011/04/09 07:02:05
nit: replace 1000 with Time::kMillisecondsPerSecon
scherkus (not reviewing)
2011/04/11 22:32:33
it looks like you can pre-calculate this since par
| |
| 73 } | |
| 74 | |
| 75 void AudioOutputDispatcher::StopStreamTask() { | |
| 76 if (idle_streams_.empty()) | |
| 77 return; | |
| 78 AudioOutputStream* stream = idle_streams_.back(); | |
| 79 idle_streams_.pop_back(); | |
| 65 streams_.push_back(stream); | 80 streams_.push_back(stream); |
| 66 close_timer_.Reset(); | 81 close_timer_.Reset(); |
| 67 } | 82 } |
| 68 | 83 |
| 69 void AudioOutputDispatcher::StreamClosed() { | 84 void AudioOutputDispatcher::StreamClosed() { |
| 70 DCHECK_EQ(MessageLoop::current(), message_loop_); | 85 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 71 | 86 |
| 72 DCHECK_GT(paused_proxies_, 0u); | 87 DCHECK_GT(paused_proxies_, 0u); |
| 73 paused_proxies_--; | 88 paused_proxies_--; |
| 74 | 89 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 close_timer_.Reset(); | 121 close_timer_.Reset(); |
| 107 } | 122 } |
| 108 | 123 |
| 109 // This method is called by |close_timer_|. | 124 // This method is called by |close_timer_|. |
| 110 void AudioOutputDispatcher::ClosePendingStreams() { | 125 void AudioOutputDispatcher::ClosePendingStreams() { |
| 111 while (!streams_.empty()) { | 126 while (!streams_.empty()) { |
| 112 streams_.back()->Close(); | 127 streams_.back()->Close(); |
| 113 streams_.pop_back(); | 128 streams_.pop_back(); |
| 114 } | 129 } |
| 115 } | 130 } |
| OLD | NEW |