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

Side by Side Diff: media/audio/linux/alsa_input.cc

Issue 16823003: Replace erroneous use of base::Time with base::TimeTicks throughout media code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: s/PresubmitPromptWarning/PresubmitPromptOrNotify/ Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « media/audio/linux/alsa_input.h ('k') | media/audio/mac/audio_input_mac.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/linux/alsa_input.h" 5 #include "media/audio/linux/alsa_input.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 HandleError("PcmStart", error); 112 HandleError("PcmStart", error);
113 } 113 }
114 114
115 if (error < 0) { 115 if (error < 0) {
116 callback_ = NULL; 116 callback_ = NULL;
117 } else { 117 } else {
118 // We start reading data half |buffer_duration_| later than when the 118 // We start reading data half |buffer_duration_| later than when the
119 // buffer might have got filled, to accommodate some delays in the audio 119 // buffer might have got filled, to accommodate some delays in the audio
120 // driver. This could also give us a smooth read sequence going forward. 120 // driver. This could also give us a smooth read sequence going forward.
121 base::TimeDelta delay = buffer_duration_ + buffer_duration_ / 2; 121 base::TimeDelta delay = buffer_duration_ + buffer_duration_ / 2;
122 next_read_time_ = base::Time::Now() + delay; 122 next_read_time_ = base::TimeTicks::Now() + delay;
123 base::MessageLoop::current()->PostDelayedTask( 123 base::MessageLoop::current()->PostDelayedTask(
124 FROM_HERE, 124 FROM_HERE,
125 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), 125 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
126 delay); 126 delay);
127 } 127 }
128 } 128 }
129 129
130 bool AlsaPcmInputStream::Recover(int original_error) { 130 bool AlsaPcmInputStream::Recover(int original_error) {
131 int error = wrapper_->PcmRecover(device_handle_, original_error, 1); 131 int error = wrapper_->PcmRecover(device_handle_, original_error, 1);
132 if (error < 0) { 132 if (error < 0) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 LOG(WARNING) << "PcmAvailUpdate(): " << wrapper_->StrError(frames); 175 LOG(WARNING) << "PcmAvailUpdate(): " << wrapper_->StrError(frames);
176 Recover(frames); 176 Recover(frames);
177 } 177 }
178 178
179 if (frames < params_.frames_per_buffer()) { 179 if (frames < params_.frames_per_buffer()) {
180 // Not enough data yet or error happened. In both cases wait for a very 180 // Not enough data yet or error happened. In both cases wait for a very
181 // small duration before checking again. 181 // small duration before checking again.
182 // Even Though read callback was behind schedule, there is no data, so 182 // Even Though read callback was behind schedule, there is no data, so
183 // reset the next_read_time_. 183 // reset the next_read_time_.
184 if (read_callback_behind_schedule_) { 184 if (read_callback_behind_schedule_) {
185 next_read_time_ = base::Time::Now(); 185 next_read_time_ = base::TimeTicks::Now();
186 read_callback_behind_schedule_ = false; 186 read_callback_behind_schedule_ = false;
187 } 187 }
188 188
189 base::TimeDelta next_check_time = buffer_duration_ / 2; 189 base::TimeDelta next_check_time = buffer_duration_ / 2;
190 base::MessageLoop::current()->PostDelayedTask( 190 base::MessageLoop::current()->PostDelayedTask(
191 FROM_HERE, 191 FROM_HERE,
192 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()), 192 base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
193 next_check_time); 193 next_check_time);
194 return; 194 return;
195 } 195 }
(...skipping 15 matching lines...) Expand all
211 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_, 211 callback_->OnData(this, audio_buffer_.get(), bytes_per_buffer_,
212 hardware_delay_bytes, normalized_volume); 212 hardware_delay_bytes, normalized_volume);
213 } else { 213 } else {
214 LOG(WARNING) << "PcmReadi returning less than expected frames: " 214 LOG(WARNING) << "PcmReadi returning less than expected frames: "
215 << frames_read << " vs. " << params_.frames_per_buffer() 215 << frames_read << " vs. " << params_.frames_per_buffer()
216 << ". Dropping this buffer."; 216 << ". Dropping this buffer.";
217 } 217 }
218 } 218 }
219 219
220 next_read_time_ += buffer_duration_; 220 next_read_time_ += buffer_duration_;
221 base::TimeDelta delay = next_read_time_ - base::Time::Now(); 221 base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now();
222 if (delay < base::TimeDelta()) { 222 if (delay < base::TimeDelta()) {
223 DVLOG(1) << "Audio read callback behind schedule by " 223 DVLOG(1) << "Audio read callback behind schedule by "
224 << (buffer_duration_ - delay).InMicroseconds() 224 << (buffer_duration_ - delay).InMicroseconds()
225 << " (us)."; 225 << " (us).";
226 // Read callback is behind schedule. Assuming there is data pending in 226 // Read callback is behind schedule. Assuming there is data pending in
227 // the soundcard, invoke the read callback immediate in order to catch up. 227 // the soundcard, invoke the read callback immediate in order to catch up.
228 read_callback_behind_schedule_ = true; 228 read_callback_behind_schedule_ = true;
229 delay = base::TimeDelta(); 229 delay = base::TimeDelta();
230 } 230 }
231 231
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 331
332 return static_cast<double>(current_volume); 332 return static_cast<double>(current_volume);
333 } 333 }
334 334
335 void AlsaPcmInputStream::HandleError(const char* method, int error) { 335 void AlsaPcmInputStream::HandleError(const char* method, int error) {
336 LOG(WARNING) << method << ": " << wrapper_->StrError(error); 336 LOG(WARNING) << method << ": " << wrapper_->StrError(error);
337 callback_->OnError(this); 337 callback_->OnError(this);
338 } 338 }
339 339
340 } // namespace media 340 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/linux/alsa_input.h ('k') | media/audio/mac/audio_input_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698