OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/fake_audio_consumer.h" | 5 #include "media/audio/fake_audio_consumer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 DCHECK(message_loop_->BelongsToCurrentThread()); | 43 DCHECK(message_loop_->BelongsToCurrentThread()); |
44 read_cb_.Reset(); | 44 read_cb_.Reset(); |
45 read_task_cb_.Cancel(); | 45 read_task_cb_.Cancel(); |
46 } | 46 } |
47 | 47 |
48 void FakeAudioConsumer::DoRead() { | 48 void FakeAudioConsumer::DoRead() { |
49 DCHECK(message_loop_->BelongsToCurrentThread()); | 49 DCHECK(message_loop_->BelongsToCurrentThread()); |
50 DCHECK(!read_cb_.is_null()); | 50 DCHECK(!read_cb_.is_null()); |
51 | 51 |
52 read_cb_.Run(audio_bus_.get()); | 52 read_cb_.Run(audio_bus_.get()); |
| 53 if (read_cb_.is_null()) |
| 54 return; |
53 | 55 |
54 // Need to account for time spent here due to the cost of |read_cb_| as well | 56 // Need to account for time spent here due to the cost of |read_cb_| as well |
55 // as the imprecision of PostDelayedTask(). | 57 // as the imprecision of PostDelayedTask(). |
56 base::Time now = base::Time::Now(); | 58 base::Time now = base::Time::Now(); |
57 base::TimeDelta delay = next_read_time_ + buffer_duration_ - now; | 59 base::TimeDelta delay = next_read_time_ + buffer_duration_ - now; |
58 | 60 |
59 // If we're behind, find the next nearest ontime interval. | 61 // If we're behind, find the next nearest ontime interval. |
60 if (delay < base::TimeDelta()) | 62 if (delay < base::TimeDelta()) |
61 delay += buffer_duration_ * (-delay / buffer_duration_ + 1); | 63 delay += buffer_duration_ * (-delay / buffer_duration_ + 1); |
62 next_read_time_ = now + delay; | 64 next_read_time_ = now + delay; |
63 | 65 |
64 message_loop_->PostDelayedTask(FROM_HERE, read_task_cb_.callback(), delay); | 66 message_loop_->PostDelayedTask(FROM_HERE, read_task_cb_.callback(), delay); |
65 } | 67 } |
66 | 68 |
67 } // namespace media | 69 } // namespace media |
OLD | NEW |