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

Side by Side Diff: media/base/audio_timestamp_helper_unittest.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 | « media/base/audio_timestamp_helper.cc ('k') | no next file » | 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "media/base/audio_timestamp_helper.h" 9 #include "media/base/audio_timestamp_helper.h"
10 #include "media/base/timestamp_constants.h" 10 #include "media/base/timestamp_constants.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 AudioTimestampHelper::FramesToTime(48000000000, k48kHz)); 73 AudioTimestampHelper::FramesToTime(48000000000, k48kHz));
74 } 74 }
75 75
76 TEST_F(AudioTimestampHelperTest, TimeToFrames) { 76 TEST_F(AudioTimestampHelperTest, TimeToFrames) {
77 // Negative value. 77 // Negative value.
78 EXPECT_EQ(-48000, AudioTimestampHelper::TimeToFrames( 78 EXPECT_EQ(-48000, AudioTimestampHelper::TimeToFrames(
79 base::TimeDelta::FromSeconds(-1), k48kHz)); 79 base::TimeDelta::FromSeconds(-1), k48kHz));
80 // Zero. 80 // Zero.
81 EXPECT_EQ(0, AudioTimestampHelper::TimeToFrames( 81 EXPECT_EQ(0, AudioTimestampHelper::TimeToFrames(
82 base::TimeDelta::FromMicroseconds(0), k48kHz)); 82 base::TimeDelta::FromMicroseconds(0), k48kHz));
83 // Any duration less than 21 microseconds will return zero frames at 48 kHz 83 // Duration of each frame is 20.833 microseconds. The result is rounded to
84 // because each frame is 20.833 microseconds. 84 // integral.
85 EXPECT_EQ(0, AudioTimestampHelper::TimeToFrames( 85 EXPECT_EQ(0, AudioTimestampHelper::TimeToFrames(
86 base::TimeDelta::FromMicroseconds(10), k48kHz));
87 EXPECT_EQ(1, AudioTimestampHelper::TimeToFrames(
86 base::TimeDelta::FromMicroseconds(20), k48kHz)); 88 base::TimeDelta::FromMicroseconds(20), k48kHz));
87 EXPECT_EQ(1, AudioTimestampHelper::TimeToFrames( 89 EXPECT_EQ(1, AudioTimestampHelper::TimeToFrames(
88 base::TimeDelta::FromMicroseconds(21), k48kHz)); 90 base::TimeDelta::FromMicroseconds(21), k48kHz));
89 // Exact value with maximum precision of TimeDelta. 91 // Exact value with maximum precision of TimeDelta.
90 EXPECT_EQ(750, AudioTimestampHelper::TimeToFrames( 92 EXPECT_EQ(750, AudioTimestampHelper::TimeToFrames(
91 base::TimeDelta::FromMicroseconds(15625), k48kHz)); 93 base::TimeDelta::FromMicroseconds(15625), k48kHz));
92 // One second. 94 // One second.
93 EXPECT_EQ(48000, AudioTimestampHelper::TimeToFrames( 95 EXPECT_EQ(48000, AudioTimestampHelper::TimeToFrames(
94 base::TimeDelta::FromSeconds(1), k48kHz)); 96 base::TimeDelta::FromSeconds(1), k48kHz));
95 // Argument and return value exceeding 32 bits. 97 // Argument and return value exceeding 32 bits.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 // tested above to verify that the code is rounding properly. 171 // tested above to verify that the code is rounding properly.
170 TestGetFramesToTargetRange(0, 103, 124); 172 TestGetFramesToTargetRange(0, 103, 124);
171 TestGetFramesToTargetRange(-1, 80, 102); 173 TestGetFramesToTargetRange(-1, 80, 102);
172 TestGetFramesToTargetRange(-2, 57, 79); 174 TestGetFramesToTargetRange(-2, 57, 79);
173 TestGetFramesToTargetRange(-3, 35, 56); 175 TestGetFramesToTargetRange(-3, 35, 56);
174 TestGetFramesToTargetRange(-4, 12, 34); 176 TestGetFramesToTargetRange(-4, 12, 34);
175 TestGetFramesToTargetRange(-5, 0, 11); 177 TestGetFramesToTargetRange(-5, 0, 11);
176 } 178 }
177 179
178 } // namespace media 180 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_timestamp_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698