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 { |
(...skipping 24 matching lines...) Expand all Loading... |
35 base::TimeDelta AudioTimestampHelper::GetTimestamp() const { | 35 base::TimeDelta AudioTimestampHelper::GetTimestamp() const { |
36 return ComputeTimestamp(frame_count_); | 36 return ComputeTimestamp(frame_count_); |
37 } | 37 } |
38 | 38 |
39 base::TimeDelta AudioTimestampHelper::GetFrameDuration(int frame_count) const { | 39 base::TimeDelta AudioTimestampHelper::GetFrameDuration(int frame_count) const { |
40 DCHECK_GE(frame_count, 0); | 40 DCHECK_GE(frame_count, 0); |
41 base::TimeDelta end_timestamp = ComputeTimestamp(frame_count_ + frame_count); | 41 base::TimeDelta end_timestamp = ComputeTimestamp(frame_count_ + frame_count); |
42 return end_timestamp - GetTimestamp(); | 42 return end_timestamp - GetTimestamp(); |
43 } | 43 } |
44 | 44 |
45 int64 AudioTimestampHelper::GetFramesToTarget(base::TimeDelta target) const { | 45 int64_t AudioTimestampHelper::GetFramesToTarget(base::TimeDelta target) const { |
46 DCHECK(base_timestamp_ != kNoTimestamp()); | 46 DCHECK(base_timestamp_ != kNoTimestamp()); |
47 DCHECK(target >= base_timestamp_); | 47 DCHECK(target >= base_timestamp_); |
48 | 48 |
49 int64 delta_in_us = (target - GetTimestamp()).InMicroseconds(); | 49 int64_t delta_in_us = (target - GetTimestamp()).InMicroseconds(); |
50 if (delta_in_us == 0) | 50 if (delta_in_us == 0) |
51 return 0; | 51 return 0; |
52 | 52 |
53 // Compute a timestamp relative to |base_timestamp_| since timestamps | 53 // Compute a timestamp relative to |base_timestamp_| since timestamps |
54 // created from |frame_count_| are computed relative to this base. | 54 // created from |frame_count_| are computed relative to this base. |
55 // This ensures that the time to frame computation here is the proper inverse | 55 // This ensures that the time to frame computation here is the proper inverse |
56 // of the frame to time computation in ComputeTimestamp(). | 56 // of the frame to time computation in ComputeTimestamp(). |
57 base::TimeDelta delta_from_base = target - base_timestamp_; | 57 base::TimeDelta delta_from_base = target - base_timestamp_; |
58 | 58 |
59 // Compute frame count for the time delta. This computation rounds to | 59 // Compute frame count for the time delta. This computation rounds to |
60 // the nearest whole number of frames. | 60 // the nearest whole number of frames. |
61 double threshold = microseconds_per_frame_ / 2; | 61 double threshold = microseconds_per_frame_ / 2; |
62 int64 target_frame_count = | 62 int64_t target_frame_count = |
63 (delta_from_base.InMicroseconds() + threshold) / microseconds_per_frame_; | 63 (delta_from_base.InMicroseconds() + threshold) / microseconds_per_frame_; |
64 return target_frame_count - frame_count_; | 64 return target_frame_count - frame_count_; |
65 } | 65 } |
66 | 66 |
67 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( | 67 base::TimeDelta AudioTimestampHelper::ComputeTimestamp( |
68 int64 frame_count) const { | 68 int64_t frame_count) const { |
69 DCHECK_GE(frame_count, 0); | 69 DCHECK_GE(frame_count, 0); |
70 DCHECK(base_timestamp_ != kNoTimestamp()); | 70 DCHECK(base_timestamp_ != kNoTimestamp()); |
71 double frames_us = microseconds_per_frame_ * frame_count; | 71 double frames_us = microseconds_per_frame_ * frame_count; |
72 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); | 72 return base_timestamp_ + base::TimeDelta::FromMicroseconds(frames_us); |
73 } | 73 } |
74 | 74 |
75 } // namespace media | 75 } // namespace media |
OLD | NEW |