| 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/timestamp_constants.h" | 8 #include "media/base/timestamp_constants.h" |
| 9 | 9 |
| 10 namespace media { | 10 namespace media { |
| 11 | 11 |
| 12 // static |
| 13 base::TimeDelta AudioTimestampHelper::FramesToTime(int64_t frames, |
| 14 int samples_per_second) { |
| 15 DCHECK_GE(samples_per_second, 0); |
| 16 return base::TimeDelta::FromMicroseconds( |
| 17 frames * base::Time::kMicrosecondsPerSecond / samples_per_second); |
| 18 } |
| 19 |
| 20 // static |
| 21 int64_t AudioTimestampHelper::TimeToFrames(base::TimeDelta time, |
| 22 int samples_per_second) { |
| 23 return time.InSecondsF() * samples_per_second; |
| 24 } |
| 25 |
| 12 AudioTimestampHelper::AudioTimestampHelper(int samples_per_second) | 26 AudioTimestampHelper::AudioTimestampHelper(int samples_per_second) |
| 13 : base_timestamp_(kNoTimestamp), frame_count_(0) { | 27 : base_timestamp_(kNoTimestamp), frame_count_(0) { |
| 14 DCHECK_GT(samples_per_second, 0); | 28 DCHECK_GT(samples_per_second, 0); |
| 15 double fps = samples_per_second; | 29 double fps = samples_per_second; |
| 16 microseconds_per_frame_ = base::Time::kMicrosecondsPerSecond / fps; | 30 microseconds_per_frame_ = base::Time::kMicrosecondsPerSecond / fps; |
| 17 } | 31 } |
| 18 | 32 |
| 19 void AudioTimestampHelper::SetBaseTimestamp(base::TimeDelta base_timestamp) { | 33 void AudioTimestampHelper::SetBaseTimestamp(base::TimeDelta base_timestamp) { |
| 20 base_timestamp_ = base_timestamp; | 34 base_timestamp_ = base_timestamp; |
| 21 frame_count_ = 0; | 35 frame_count_ = 0; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 79 |
| 66 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( | 80 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( |
| 67 int64_t frame_count) const { | 81 int64_t frame_count) const { |
| 68 DCHECK_GE(frame_count, 0); | 82 DCHECK_GE(frame_count, 0); |
| 69 DCHECK(base_timestamp_ != kNoTimestamp); | 83 DCHECK(base_timestamp_ != kNoTimestamp); |
| 70 double frames_us = microseconds_per_frame_ * frame_count; | 84 double frames_us = microseconds_per_frame_ * frame_count; |
| 71 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); | 85 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); |
| 72 } | 86 } |
| 73 | 87 |
| 74 } // namespace media | 88 } // namespace media |
| OLD | NEW |