| 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/base/audio_timestamp_helper.h" | 5 #include "media/base/audio_timestamp_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "media/base/buffers.h" | 8 #include "media/base/buffers.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 AudioTimestampHelper::AudioTimestampHelper(int samples_per_second) | 12 AudioTimestampHelper::AudioTimestampHelper(int samples_per_second) |
| 13 : base_timestamp_(kNoTimestamp()), | 13 : base_timestamp_(kNoTimestamp()), |
| 14 frame_count_(0) { | 14 frame_count_(0) { |
| 15 DCHECK_GT(samples_per_second, 0); | 15 DCHECK_GT(samples_per_second, 0); |
| 16 double fps = samples_per_second; | 16 double fps = samples_per_second; |
| 17 microseconds_per_frame_ = base::Time::kMicrosecondsPerSecond / fps; | 17 microseconds_per_frame_ = base::Time::kMicrosecondsPerSecond / fps; |
| 18 } | 18 } |
| 19 | 19 |
| 20 void AudioTimestampHelper::SetBaseTimestamp(base::TimeDelta base_timestamp) { | 20 void AudioTimestampHelper::SetBaseTimestamp(base::TimeDelta base_timestamp) { |
| 21 base_timestamp_ = base_timestamp; | 21 base_timestamp_ = base_timestamp; |
| 22 frame_count_ = 0; | 22 frame_count_ = 0; |
| 23 } | 23 } |
| 24 | 24 |
| 25 base::TimeDelta AudioTimestampHelper::base_timestamp() const { | |
| 26 return base_timestamp_; | |
| 27 } | |
| 28 | |
| 29 void AudioTimestampHelper::AddFrames(int frame_count) { | 25 void AudioTimestampHelper::AddFrames(int frame_count) { |
| 30 DCHECK_GE(frame_count, 0); | 26 DCHECK_GE(frame_count, 0); |
| 31 DCHECK(base_timestamp_ != kNoTimestamp()); | 27 DCHECK(base_timestamp_ != kNoTimestamp()); |
| 32 frame_count_ += frame_count; | 28 frame_count_ += frame_count; |
| 33 } | 29 } |
| 34 | 30 |
| 35 base::TimeDelta AudioTimestampHelper::GetTimestamp() const { | 31 base::TimeDelta AudioTimestampHelper::GetTimestamp() const { |
| 36 return ComputeTimestamp(frame_count_); | 32 return ComputeTimestamp(frame_count_); |
| 37 } | 33 } |
| 38 | 34 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 | 62 |
| 67 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( | 63 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( |
| 68 int64 frame_count) const { | 64 int64 frame_count) const { |
| 69 DCHECK_GE(frame_count, 0); | 65 DCHECK_GE(frame_count, 0); |
| 70 DCHECK(base_timestamp_ != kNoTimestamp()); | 66 DCHECK(base_timestamp_ != kNoTimestamp()); |
| 71 double frames_us = microseconds_per_frame_ * frame_count; | 67 double frames_us = microseconds_per_frame_ * frame_count; |
| 72 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); | 68 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); |
| 73 } | 69 } |
| 74 | 70 |
| 75 } // namespace media | 71 } // namespace media |
| OLD | NEW |