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/fake_audio_input_stream.h" | 5 #include "media/audio/fake_audio_input_stream.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "media/audio/audio_manager_base.h" | 9 #include "media/audio/audio_manager_base.h" |
10 | 10 |
11 using base::Time; | 11 using base::TimeTicks; |
12 using base::TimeDelta; | 12 using base::TimeDelta; |
13 | 13 |
14 namespace media { | 14 namespace media { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // These values are based on experiments for local-to-local | 18 // These values are based on experiments for local-to-local |
19 // PeerConnection to demonstrate audio/video synchronization. | 19 // PeerConnection to demonstrate audio/video synchronization. |
20 const int kBeepDurationMilliseconds = 20; | 20 const int kBeepDurationMilliseconds = 20; |
21 const int kBeepFrequency = 400; | 21 const int kBeepFrequency = 400; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 bool FakeAudioInputStream::Open() { | 60 bool FakeAudioInputStream::Open() { |
61 buffer_.reset(new uint8[buffer_size_]); | 61 buffer_.reset(new uint8[buffer_size_]); |
62 memset(buffer_.get(), 0, buffer_size_); | 62 memset(buffer_.get(), 0, buffer_size_); |
63 return true; | 63 return true; |
64 } | 64 } |
65 | 65 |
66 void FakeAudioInputStream::Start(AudioInputCallback* callback) { | 66 void FakeAudioInputStream::Start(AudioInputCallback* callback) { |
67 DCHECK(!thread_.IsRunning()); | 67 DCHECK(!thread_.IsRunning()); |
68 callback_ = callback; | 68 callback_ = callback; |
69 last_callback_time_ = Time::Now(); | 69 last_callback_time_ = TimeTicks::Now(); |
70 thread_.Start(); | 70 thread_.Start(); |
71 thread_.message_loop()->PostDelayedTask( | 71 thread_.message_loop()->PostDelayedTask( |
72 FROM_HERE, | 72 FROM_HERE, |
73 base::Bind(&FakeAudioInputStream::DoCallback, base::Unretained(this)), | 73 base::Bind(&FakeAudioInputStream::DoCallback, base::Unretained(this)), |
74 callback_interval_); | 74 callback_interval_); |
75 } | 75 } |
76 | 76 |
77 void FakeAudioInputStream::DoCallback() { | 77 void FakeAudioInputStream::DoCallback() { |
78 DCHECK(callback_); | 78 DCHECK(callback_); |
79 | 79 |
(...skipping 28 matching lines...) Expand all Loading... |
108 } | 108 } |
109 | 109 |
110 ++beep_generated_in_buffers_; | 110 ++beep_generated_in_buffers_; |
111 if (beep_generated_in_buffers_ >= beep_duration_in_buffers_) | 111 if (beep_generated_in_buffers_ >= beep_duration_in_buffers_) |
112 beep_generated_in_buffers_ = 0; | 112 beep_generated_in_buffers_ = 0; |
113 } | 113 } |
114 | 114 |
115 callback_->OnData(this, buffer_.get(), buffer_size_, buffer_size_, 1.0); | 115 callback_->OnData(this, buffer_.get(), buffer_size_, buffer_size_, 1.0); |
116 frames_elapsed_ += params_.frames_per_buffer(); | 116 frames_elapsed_ += params_.frames_per_buffer(); |
117 | 117 |
118 Time now = Time::Now(); | 118 const TimeTicks now = TimeTicks::Now(); |
119 base::TimeDelta next_callback_time = | 119 base::TimeDelta next_callback_time = |
120 last_callback_time_ + callback_interval_ * 2 - now; | 120 last_callback_time_ + callback_interval_ * 2 - now; |
121 | 121 |
122 // If we are falling behind, try to catch up as much as we can in the next | 122 // If we are falling behind, try to catch up as much as we can in the next |
123 // callback. | 123 // callback. |
124 if (next_callback_time < base::TimeDelta()) | 124 if (next_callback_time < base::TimeDelta()) |
125 next_callback_time = base::TimeDelta(); | 125 next_callback_time = base::TimeDelta(); |
126 | 126 |
127 last_callback_time_ = now; | 127 last_callback_time_ = now; |
128 thread_.message_loop()->PostDelayedTask( | 128 thread_.message_loop()->PostDelayedTask( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 } | 161 } |
162 | 162 |
163 // static | 163 // static |
164 void FakeAudioInputStream::BeepOnce() { | 164 void FakeAudioInputStream::BeepOnce() { |
165 BeepContext* beep_context = g_beep_context.Pointer(); | 165 BeepContext* beep_context = g_beep_context.Pointer(); |
166 base::AutoLock auto_lock(beep_context->beep_lock); | 166 base::AutoLock auto_lock(beep_context->beep_lock); |
167 beep_context->beep_once = true; | 167 beep_context->beep_once = true; |
168 } | 168 } |
169 | 169 |
170 } // namespace media | 170 } // namespace media |
OLD | NEW |