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

Side by Side Diff: media/filters/audio_clock_unittest.cc

Issue 1233963002: Fix accumulation error with front_timestamp, move test only code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused vars. Created 5 years, 5 months 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/filters/audio_clock.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "media/base/buffers.h" 6 #include "media/base/buffers.h"
7 #include "media/filters/audio_clock.h" 7 #include "media/filters/audio_clock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
(...skipping 22 matching lines...) Expand all
33 int BackTimestampInMilliseconds() { 33 int BackTimestampInMilliseconds() {
34 return clock_.back_timestamp().InMilliseconds(); 34 return clock_.back_timestamp().InMilliseconds();
35 } 35 }
36 36
37 int TimeUntilPlaybackInMilliseconds(int timestamp_ms) { 37 int TimeUntilPlaybackInMilliseconds(int timestamp_ms) {
38 return clock_.TimeUntilPlayback(base::TimeDelta::FromMilliseconds( 38 return clock_.TimeUntilPlayback(base::TimeDelta::FromMilliseconds(
39 timestamp_ms)).InMilliseconds(); 39 timestamp_ms)).InMilliseconds();
40 } 40 }
41 41
42 int ContiguousAudioDataBufferedInDays() { 42 int ContiguousAudioDataBufferedInDays() {
43 return clock_.contiguous_audio_data_buffered().InDays(); 43 base::TimeDelta total, same_rate_total;
44 clock_.ContiguousAudioDataBufferedForTesting(&total, &same_rate_total);
45 return total.InDays();
44 } 46 }
45 47
46 int ContiguousAudioDataBufferedInMilliseconds() { 48 int ContiguousAudioDataBufferedInMilliseconds() {
47 return clock_.contiguous_audio_data_buffered().InMilliseconds(); 49 base::TimeDelta total, same_rate_total;
50 clock_.ContiguousAudioDataBufferedForTesting(&total, &same_rate_total);
51 return total.InMilliseconds();
48 } 52 }
49 53
50 int ContiguousAudioDataBufferedAtSameRateInMilliseconds() { 54 int ContiguousAudioDataBufferedAtSameRateInMilliseconds() {
51 return clock_.contiguous_audio_data_buffered_at_same_rate() 55 base::TimeDelta total, same_rate_total;
52 .InMilliseconds(); 56 clock_.ContiguousAudioDataBufferedForTesting(&total, &same_rate_total);
57 return same_rate_total.InMilliseconds();
53 } 58 }
54 59
55 const int sample_rate_; 60 const int sample_rate_;
56 AudioClock clock_; 61 AudioClock clock_;
57 62
58 private: 63 private:
59 DISALLOW_COPY_AND_ASSIGN(AudioClockTest); 64 DISALLOW_COPY_AND_ASSIGN(AudioClockTest);
60 }; 65 };
61 66
62 TEST_F(AudioClockTest, FrontTimestampStartsAtStartTimestamp) { 67 TEST_F(AudioClockTest, FrontTimestampStartsAtStartTimestamp) {
63 base::TimeDelta expected = base::TimeDelta::FromSeconds(123); 68 base::TimeDelta expected = base::TimeDelta::FromSeconds(123);
64 AudioClock clock(expected, sample_rate_); 69 AudioClock clock(expected, sample_rate_);
65 70
66 EXPECT_EQ(expected, clock.front_timestamp()); 71 EXPECT_EQ(expected, clock.front_timestamp());
67 } 72 }
68 73
69 TEST_F(AudioClockTest, BackTimestampStartsAtStartTimestamp) { 74 TEST_F(AudioClockTest, BackTimestampStartsAtStartTimestamp) {
70 base::TimeDelta expected = base::TimeDelta::FromSeconds(123); 75 base::TimeDelta expected = base::TimeDelta::FromSeconds(123);
71 AudioClock clock(expected, sample_rate_); 76 AudioClock clock(expected, sample_rate_);
72 77
73 EXPECT_EQ(expected, clock.back_timestamp()); 78 EXPECT_EQ(expected, clock.back_timestamp());
74 } 79 }
75 80
76 TEST_F(AudioClockTest, ContiguousAudioDataBufferedStartsAtZero) {
77 EXPECT_EQ(base::TimeDelta(), clock_.contiguous_audio_data_buffered());
78 }
79
80 TEST_F(AudioClockTest, ContiguousAudioDataBufferedAtSameRateStartsAtZero) {
81 EXPECT_EQ(base::TimeDelta(),
82 clock_.contiguous_audio_data_buffered_at_same_rate());
83 }
84
85 TEST_F(AudioClockTest, Playback) { 81 TEST_F(AudioClockTest, Playback) {
86 // The first time we write data we should still expect our start timestamp 82 // The first time we write data we should still expect our start timestamp
87 // due to delay. 83 // due to delay.
88 WroteAudio(10, 10, 20, 1.0); 84 WroteAudio(10, 10, 20, 1.0);
89 EXPECT_EQ(0, FrontTimestampInMilliseconds()); 85 EXPECT_EQ(0, FrontTimestampInMilliseconds());
90 EXPECT_EQ(1000, BackTimestampInMilliseconds()); 86 EXPECT_EQ(1000, BackTimestampInMilliseconds());
91 EXPECT_EQ(0, ContiguousAudioDataBufferedInMilliseconds()); 87 EXPECT_EQ(0, ContiguousAudioDataBufferedInMilliseconds());
92 EXPECT_EQ(0, ContiguousAudioDataBufferedAtSameRateInMilliseconds()); 88 EXPECT_EQ(0, ContiguousAudioDataBufferedAtSameRateInMilliseconds());
93 89
94 // The media time should remain at start timestamp as we write data. 90 // The media time should remain at start timestamp as we write data.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 346 }
351 347
352 // Exhausting all frames should advance timestamps and prime the buffer with 348 // Exhausting all frames should advance timestamps and prime the buffer with
353 // our delay frames value. 349 // our delay frames value.
354 clock_.CompensateForSuspendedWrites(base::TimeDelta::FromMilliseconds(7000), 350 clock_.CompensateForSuspendedWrites(base::TimeDelta::FromMilliseconds(7000),
355 kDelayFrames); 351 kDelayFrames);
356 EXPECT_EQ(kDelayFrames * 100, TimeUntilPlaybackInMilliseconds(1000)); 352 EXPECT_EQ(kDelayFrames * 100, TimeUntilPlaybackInMilliseconds(1000));
357 } 353 }
358 354
359 } // namespace media 355 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/audio_clock.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698