summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authormiu@chromium.org <miu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 23:20:45 +0000
committermiu@chromium.org <miu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-13 23:20:45 +0000
commit1bd38bd28cbb8daa623541dcdeee55ad33e4bd15 (patch)
tree932b934243d5d9707c9bc4d5c6b87c30ba7beeee /media/audio
parentf805162421d58615a6b6e9b2ebe4872bc208bc38 (diff)
downloadchromium_src-1bd38bd28cbb8daa623541dcdeee55ad33e4bd15.zip
chromium_src-1bd38bd28cbb8daa623541dcdeee55ad33e4bd15.tar.gz
chromium_src-1bd38bd28cbb8daa623541dcdeee55ad33e4bd15.tar.bz2
Replace erroneous use of base::Time with base::TimeTicks throughout media code.
This change corrects all the "low-hanging fruit," leaving the VideoCaptureDevice interface and MediaLog (?) as separate changes; as they are referenced throughout other components. Added a PRESUBMIT.py script for media/ code that will scan future code changes for use of base::Time (or base::Clock/DefaultClock) and prompt the developer with a warning explaining that clock skew is a serious and subtle source of bugs. Testing: Ran all media_unittests and content_unittests. Manually ran through demo sites that utilize all of the following (on all of Win/Mac/Linux): 1. HTML5 audio and video; 2. PPAPI Flash video; 3. WebAudio API; 4. WebRTC; 5. Tab Capture API. BUG=247881 TEST=media_unittests, content_unittests, manual confirmation of major media use cases Review URL: https://chromiumcodereview.appspot.com/16823003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/audio_low_latency_input_output_unittest.cc8
-rw-r--r--media/audio/fake_audio_consumer.cc4
-rw-r--r--media/audio/fake_audio_consumer.h2
-rw-r--r--media/audio/fake_audio_consumer_unittest.cc8
-rw-r--r--media/audio/fake_audio_input_stream.cc6
-rw-r--r--media/audio/fake_audio_input_stream.h2
-rw-r--r--media/audio/linux/alsa_input.cc6
-rw-r--r--media/audio/linux/alsa_input.h2
-rw-r--r--media/audio/mac/audio_input_mac.cc4
-rw-r--r--media/audio/mac/audio_input_mac.h2
-rw-r--r--media/audio/win/audio_low_latency_output_win_unittest.cc9
-rw-r--r--media/audio/win/audio_unified_win_unittest.cc9
12 files changed, 32 insertions, 30 deletions
diff --git a/media/audio/audio_low_latency_input_output_unittest.cc b/media/audio/audio_low_latency_input_output_unittest.cc
index f4aeab4..0b0733b 100644
--- a/media/audio/audio_low_latency_input_output_unittest.cc
+++ b/media/audio/audio_low_latency_input_output_unittest.cc
@@ -136,7 +136,7 @@ class FullDuplexAudioSinkSource
channels_(channels),
input_elements_to_write_(0),
output_elements_to_write_(0),
- previous_write_time_(base::Time::Now()) {
+ previous_write_time_(base::TimeTicks::Now()) {
// Size in bytes of each audio frame (4 bytes for 16-bit stereo PCM).
frame_size_ = (16 / 8) * channels_;
@@ -186,8 +186,8 @@ class FullDuplexAudioSinkSource
// Update three components in the AudioDelayState for this recorded
// audio packet.
- base::Time now_time = base::Time::Now();
- int diff = (now_time - previous_write_time_).InMilliseconds();
+ const base::TimeTicks now_time = base::TimeTicks::Now();
+ const int diff = (now_time - previous_write_time_).InMilliseconds();
previous_write_time_ = now_time;
if (input_elements_to_write_ < kMaxDelayMeasurements) {
delay_states_[input_elements_to_write_].delta_time_ms = diff;
@@ -277,7 +277,7 @@ class FullDuplexAudioSinkSource
scoped_ptr<AudioDelayState[]> delay_states_;
size_t input_elements_to_write_;
size_t output_elements_to_write_;
- base::Time previous_write_time_;
+ base::TimeTicks previous_write_time_;
};
class AudioInputStreamTraits {
diff --git a/media/audio/fake_audio_consumer.cc b/media/audio/fake_audio_consumer.cc
index e70a74a..5232170 100644
--- a/media/audio/fake_audio_consumer.cc
+++ b/media/audio/fake_audio_consumer.cc
@@ -33,7 +33,7 @@ void FakeAudioConsumer::Start(const ReadCB& read_cb) {
DCHECK(read_cb_.is_null());
DCHECK(!read_cb.is_null());
read_cb_ = read_cb;
- next_read_time_ = base::Time::Now();
+ next_read_time_ = base::TimeTicks::Now();
read_task_cb_.Reset(base::Bind(
&FakeAudioConsumer::DoRead, base::Unretained(this)));
message_loop_->PostTask(FROM_HERE, read_task_cb_.callback());
@@ -53,7 +53,7 @@ void FakeAudioConsumer::DoRead() {
// Need to account for time spent here due to the cost of |read_cb_| as well
// as the imprecision of PostDelayedTask().
- base::Time now = base::Time::Now();
+ const base::TimeTicks now = base::TimeTicks::Now();
base::TimeDelta delay = next_read_time_ + buffer_duration_ - now;
// If we're behind, find the next nearest ontime interval.
diff --git a/media/audio/fake_audio_consumer.h b/media/audio/fake_audio_consumer.h
index 793e553..57da74f 100644
--- a/media/audio/fake_audio_consumer.h
+++ b/media/audio/fake_audio_consumer.h
@@ -48,7 +48,7 @@ class MEDIA_EXPORT FakeAudioConsumer {
ReadCB read_cb_;
scoped_ptr<AudioBus> audio_bus_;
base::TimeDelta buffer_duration_;
- base::Time next_read_time_;
+ base::TimeTicks next_read_time_;
// Used to post delayed tasks to the AudioThread that we can cancel.
base::CancelableClosure read_task_cb_;
diff --git a/media/audio/fake_audio_consumer_unittest.cc b/media/audio/fake_audio_consumer_unittest.cc
index 362686c..9ffc149 100644
--- a/media/audio/fake_audio_consumer_unittest.cc
+++ b/media/audio/fake_audio_consumer_unittest.cc
@@ -58,7 +58,7 @@ class FakeAudioConsumerTest : public testing::Test {
if (source_.callbacks() == 0) {
RunOnAudioThread();
- start_time_ = base::Time::Now();
+ start_time_ = base::TimeTicks::Now();
}
// Keep going until we've seen the requested number of callbacks.
@@ -67,7 +67,7 @@ class FakeAudioConsumerTest : public testing::Test {
&FakeAudioConsumerTest::TimeCallbacksOnAudioThread,
base::Unretained(this), callbacks), time_between_callbacks_ / 2);
} else {
- end_time_ = base::Time::Now();
+ end_time_ = base::TimeTicks::Now();
EndTest(callbacks);
}
}
@@ -84,8 +84,8 @@ class FakeAudioConsumerTest : public testing::Test {
AudioParameters params_;
FakeAudioConsumer fake_consumer_;
SineWaveAudioSource source_;
- base::Time start_time_;
- base::Time end_time_;
+ base::TimeTicks start_time_;
+ base::TimeTicks end_time_;
base::TimeDelta time_between_callbacks_;
private:
diff --git a/media/audio/fake_audio_input_stream.cc b/media/audio/fake_audio_input_stream.cc
index d2b1ce9..a00a9b6 100644
--- a/media/audio/fake_audio_input_stream.cc
+++ b/media/audio/fake_audio_input_stream.cc
@@ -8,7 +8,7 @@
#include "base/lazy_instance.h"
#include "media/audio/audio_manager_base.h"
-using base::Time;
+using base::TimeTicks;
using base::TimeDelta;
namespace media {
@@ -66,7 +66,7 @@ bool FakeAudioInputStream::Open() {
void FakeAudioInputStream::Start(AudioInputCallback* callback) {
DCHECK(!thread_.IsRunning());
callback_ = callback;
- last_callback_time_ = Time::Now();
+ last_callback_time_ = TimeTicks::Now();
thread_.Start();
thread_.message_loop()->PostDelayedTask(
FROM_HERE,
@@ -115,7 +115,7 @@ void FakeAudioInputStream::DoCallback() {
callback_->OnData(this, buffer_.get(), buffer_size_, buffer_size_, 1.0);
frames_elapsed_ += params_.frames_per_buffer();
- Time now = Time::Now();
+ const TimeTicks now = TimeTicks::Now();
base::TimeDelta next_callback_time =
last_callback_time_ + callback_interval_ * 2 - now;
diff --git a/media/audio/fake_audio_input_stream.h b/media/audio/fake_audio_input_stream.h
index 169405b..2de192f 100644
--- a/media/audio/fake_audio_input_stream.h
+++ b/media/audio/fake_audio_input_stream.h
@@ -61,7 +61,7 @@ class MEDIA_EXPORT FakeAudioInputStream
int buffer_size_;
AudioParameters params_;
base::Thread thread_;
- base::Time last_callback_time_;
+ base::TimeTicks last_callback_time_;
base::TimeDelta callback_interval_;
int beep_duration_in_buffers_;
int beep_generated_in_buffers_;
diff --git a/media/audio/linux/alsa_input.cc b/media/audio/linux/alsa_input.cc
index bbbee05..3f20158 100644
--- a/media/audio/linux/alsa_input.cc
+++ b/media/audio/linux/alsa_input.cc
@@ -119,7 +119,7 @@ void AlsaPcmInputStream::Start(AudioInputCallback* callback) {
// buffer might have got filled, to accommodate some delays in the audio
// driver. This could also give us a smooth read sequence going forward.
base::TimeDelta delay = buffer_duration_ + buffer_duration_ / 2;
- next_read_time_ = base::Time::Now() + delay;
+ next_read_time_ = base::TimeTicks::Now() + delay;
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&AlsaPcmInputStream::ReadAudio, weak_factory_.GetWeakPtr()),
@@ -182,7 +182,7 @@ void AlsaPcmInputStream::ReadAudio() {
// Even Though read callback was behind schedule, there is no data, so
// reset the next_read_time_.
if (read_callback_behind_schedule_) {
- next_read_time_ = base::Time::Now();
+ next_read_time_ = base::TimeTicks::Now();
read_callback_behind_schedule_ = false;
}
@@ -218,7 +218,7 @@ void AlsaPcmInputStream::ReadAudio() {
}
next_read_time_ += buffer_duration_;
- base::TimeDelta delay = next_read_time_ - base::Time::Now();
+ base::TimeDelta delay = next_read_time_ - base::TimeTicks::Now();
if (delay < base::TimeDelta()) {
DVLOG(1) << "Audio read callback behind schedule by "
<< (buffer_duration_ - delay).InMicroseconds()
diff --git a/media/audio/linux/alsa_input.h b/media/audio/linux/alsa_input.h
index 57092eb..974e36b 100644
--- a/media/audio/linux/alsa_input.h
+++ b/media/audio/linux/alsa_input.h
@@ -76,7 +76,7 @@ class AlsaPcmInputStream : public AgcAudioStream<AudioInputStream> {
AlsaWrapper* wrapper_;
base::TimeDelta buffer_duration_; // Length of each recorded buffer.
AudioInputCallback* callback_; // Valid during a recording session.
- base::Time next_read_time_; // Scheduled time for the next read callback.
+ base::TimeTicks next_read_time_; // Scheduled time for next read callback.
snd_pcm_t* device_handle_; // Handle to the ALSA PCM recording device.
snd_mixer_t* mixer_handle_; // Handle to the ALSA microphone mixer.
snd_mixer_elem_t* mixer_element_handle_; // Handle to the capture element.
diff --git a/media/audio/mac/audio_input_mac.cc b/media/audio/mac/audio_input_mac.cc
index c2a3696..06af6d1 100644
--- a/media/audio/mac/audio_input_mac.cc
+++ b/media/audio/mac/audio_input_mac.cc
@@ -197,7 +197,7 @@ void PCMQueueInAudioInputStream::HandleInputBuffer(
// TODO(dalecurtis): This is a HACK. Long term the AudioQueue path is going
// away in favor of the AudioUnit based AUAudioInputStream(). Tracked by
// http://crbug.com/161383.
- base::TimeDelta elapsed = base::Time::Now() - last_fill_;
+ base::TimeDelta elapsed = base::TimeTicks::Now() - last_fill_;
const base::TimeDelta kMinDelay = base::TimeDelta::FromMilliseconds(5);
if (elapsed < kMinDelay)
base::PlatformThread::Sleep(kMinDelay - elapsed);
@@ -208,7 +208,7 @@ void PCMQueueInAudioInputStream::HandleInputBuffer(
audio_buffer->mAudioDataByteSize,
0.0);
- last_fill_ = base::Time::Now();
+ last_fill_ = base::TimeTicks::Now();
}
// Recycle the buffer.
OSStatus err = QueueNextBuffer(audio_buffer);
diff --git a/media/audio/mac/audio_input_mac.h b/media/audio/mac/audio_input_mac.h
index 1f9856f1..d49fed8 100644
--- a/media/audio/mac/audio_input_mac.h
+++ b/media/audio/mac/audio_input_mac.h
@@ -78,7 +78,7 @@ class PCMQueueInAudioInputStream : public AudioInputStream {
// True iff Start() has been called successfully.
bool started_;
// Used to determine if we need to slow down |callback_| calls.
- base::Time last_fill_;
+ base::TimeTicks last_fill_;
DISALLOW_COPY_AND_ASSIGN(PCMQueueInAudioInputStream);
};
diff --git a/media/audio/win/audio_low_latency_output_win_unittest.cc b/media/audio/win/audio_low_latency_output_win_unittest.cc
index af60be6..4fb09de 100644
--- a/media/audio/win/audio_low_latency_output_win_unittest.cc
+++ b/media/audio/win/audio_low_latency_output_win_unittest.cc
@@ -77,7 +77,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
public:
explicit ReadFromFileAudioSource(const std::string& name)
: pos_(0),
- previous_call_time_(base::Time::Now()),
+ previous_call_time_(base::TimeTicks::Now()),
text_file_(NULL),
elements_to_write_(0) {
// Reads a test file from media/test/data directory.
@@ -116,8 +116,9 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
AudioBuffersState buffers_state) {
// Store time difference between two successive callbacks in an array.
// These values will be written to a file in the destructor.
- int diff = (base::Time::Now() - previous_call_time_).InMilliseconds();
- previous_call_time_ = base::Time::Now();
+ const base::TimeTicks now_time = base::TimeTicks::Now();
+ const int diff = (now_time - previous_call_time_).InMilliseconds();
+ previous_call_time_ = now_time;
if (elements_to_write_ < kMaxDeltaSamples) {
delta_times_[elements_to_write_] = diff;
++elements_to_write_;
@@ -154,7 +155,7 @@ class ReadFromFileAudioSource : public AudioOutputStream::AudioSourceCallback {
scoped_refptr<DecoderBuffer> file_;
scoped_ptr<int[]> delta_times_;
int pos_;
- base::Time previous_call_time_;
+ base::TimeTicks previous_call_time_;
FILE* text_file_;
size_t elements_to_write_;
};
diff --git a/media/audio/win/audio_unified_win_unittest.cc b/media/audio/win/audio_unified_win_unittest.cc
index 6fad0b7..807ca7f 100644
--- a/media/audio/win/audio_unified_win_unittest.cc
+++ b/media/audio/win/audio_unified_win_unittest.cc
@@ -63,7 +63,7 @@ class MockUnifiedSourceCallback
class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback {
public:
explicit UnifiedSourceCallback()
- : previous_call_time_(base::Time::Now()),
+ : previous_call_time_(base::TimeTicks::Now()),
text_file_(NULL),
elements_to_write_(0) {
delta_times_.reset(new int[kMaxDeltaSamples]);
@@ -98,8 +98,9 @@ class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback {
AudioBus* dest,
AudioBuffersState buffers_state) {
// Store time between this callback and the previous callback.
- int diff = (base::Time::Now() - previous_call_time_).InMilliseconds();
- previous_call_time_ = base::Time::Now();
+ const base::TimeTicks now_time = base::TimeTicks::Now();
+ const int diff = (now_time - previous_call_time_).InMilliseconds();
+ previous_call_time_ = now_time;
if (elements_to_write_ < kMaxDeltaSamples) {
delta_times_[elements_to_write_] = diff;
++elements_to_write_;
@@ -134,7 +135,7 @@ class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback {
}
private:
- base::Time previous_call_time_;
+ base::TimeTicks previous_call_time_;
scoped_ptr<int[]> delta_times_;
FILE* text_file_;
size_t elements_to_write_;