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