Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: media/base/audio_timestamp_helper.cc

Issue 2562243005: Make AudioTimestampHelper::TimeToFrames() more accurate (Closed)
Patch Set: Modified unittests. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/base/audio_timestamp_helper_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_timestamp_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698