OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <sstream> | 5 #include <sstream> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 return out.str(); | 83 return out.str(); |
84 } | 84 } |
85 }; | 85 }; |
86 | 86 |
87 } // namespace | 87 } // namespace |
88 | 88 |
89 class AudioEncoderTest : public ::testing::TestWithParam<TestScenario> { | 89 class AudioEncoderTest : public ::testing::TestWithParam<TestScenario> { |
90 public: | 90 public: |
91 AudioEncoderTest() { | 91 AudioEncoderTest() { |
92 InitializeMediaLibraryForTesting(); | 92 InitializeMediaLibraryForTesting(); |
93 testing_clock_.Advance( | 93 testing_clock_ = new base::SimpleTestTickClock(); |
| 94 testing_clock_->Advance( |
94 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 95 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
95 } | 96 } |
96 | 97 |
97 virtual void SetUp() { | 98 virtual void SetUp() { |
98 task_runner_ = new test::FakeTaskRunner(&testing_clock_); | 99 task_runner_ = new test::FakeTaskRunner(testing_clock_); |
99 cast_environment_ = new CastEnvironment(&testing_clock_, task_runner_, | 100 cast_environment_ = new CastEnvironment( |
| 101 scoped_ptr<base::TickClock>(testing_clock_).Pass(), task_runner_, |
100 task_runner_, task_runner_, task_runner_, task_runner_, task_runner_, | 102 task_runner_, task_runner_, task_runner_, task_runner_, task_runner_, |
101 GetDefaultCastSenderLoggingConfig()); | 103 GetDefaultCastSenderLoggingConfig()); |
102 } | 104 } |
103 | 105 |
104 virtual ~AudioEncoderTest() {} | 106 virtual ~AudioEncoderTest() {} |
105 | 107 |
106 void RunTestForCodec(transport::AudioCodec codec) { | 108 void RunTestForCodec(transport::AudioCodec codec) { |
107 const TestScenario& scenario = GetParam(); | 109 const TestScenario& scenario = GetParam(); |
108 SCOPED_TRACE(::testing::Message() | 110 SCOPED_TRACE(::testing::Message() |
109 << "Durations: " << scenario.ToString()); | 111 << "Durations: " << scenario.ToString()); |
110 | 112 |
111 CreateObjectsForCodec(codec); | 113 CreateObjectsForCodec(codec); |
112 | 114 |
113 receiver_->SetRecordedTimeLowerBound(testing_clock_.NowTicks()); | 115 receiver_->SetRecordedTimeLowerBound(testing_clock_->NowTicks()); |
114 for (size_t i = 0; i < scenario.num_durations; ++i) { | 116 for (size_t i = 0; i < scenario.num_durations; ++i) { |
115 const base::TimeDelta duration = | 117 const base::TimeDelta duration = |
116 base::TimeDelta::FromMilliseconds(scenario.durations_in_ms[i]); | 118 base::TimeDelta::FromMilliseconds(scenario.durations_in_ms[i]); |
117 receiver_->SetRecordedTimeUpperBound( | 119 receiver_->SetRecordedTimeUpperBound( |
118 testing_clock_.NowTicks() + duration); | 120 testing_clock_->NowTicks() + duration); |
119 | 121 |
120 const scoped_ptr<AudioBus> bus( | 122 const scoped_ptr<AudioBus> bus( |
121 audio_bus_factory_->NextAudioBus(duration)); | 123 audio_bus_factory_->NextAudioBus(duration)); |
122 | 124 |
123 const int last_count = release_callback_count_; | 125 const int last_count = release_callback_count_; |
124 audio_encoder_->InsertAudio( | 126 audio_encoder_->InsertAudio( |
125 bus.get(), testing_clock_.NowTicks(), | 127 bus.get(), testing_clock_->NowTicks(), |
126 base::Bind(&AudioEncoderTest::IncrementReleaseCallbackCounter, | 128 base::Bind(&AudioEncoderTest::IncrementReleaseCallbackCounter, |
127 base::Unretained(this))); | 129 base::Unretained(this))); |
128 task_runner_->RunTasks(); | 130 task_runner_->RunTasks(); |
129 EXPECT_EQ(1, release_callback_count_ - last_count) | 131 EXPECT_EQ(1, release_callback_count_ - last_count) |
130 << "Release callback was not invoked once."; | 132 << "Release callback was not invoked once."; |
131 | 133 |
132 testing_clock_.Advance(duration); | 134 testing_clock_->Advance(duration); |
133 } | 135 } |
134 | 136 |
135 DVLOG(1) << "Received " << receiver_->frames_received() | 137 DVLOG(1) << "Received " << receiver_->frames_received() |
136 << " frames for this test run: " << scenario.ToString(); | 138 << " frames for this test run: " << scenario.ToString(); |
137 } | 139 } |
138 | 140 |
139 private: | 141 private: |
140 void CreateObjectsForCodec(transport::AudioCodec codec) { | 142 void CreateObjectsForCodec(transport::AudioCodec codec) { |
141 AudioSenderConfig audio_config; | 143 AudioSenderConfig audio_config; |
142 audio_config.codec = codec; | 144 audio_config.codec = codec; |
(...skipping 13 matching lines...) Expand all Loading... |
156 cast_environment_, audio_config, | 158 cast_environment_, audio_config, |
157 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded, | 159 base::Bind(&TestEncodedAudioFrameReceiver::FrameEncoded, |
158 base::Unretained(receiver_.get()))); | 160 base::Unretained(receiver_.get()))); |
159 release_callback_count_ = 0; | 161 release_callback_count_ = 0; |
160 } | 162 } |
161 | 163 |
162 void IncrementReleaseCallbackCounter() { | 164 void IncrementReleaseCallbackCounter() { |
163 ++release_callback_count_; | 165 ++release_callback_count_; |
164 } | 166 } |
165 | 167 |
166 base::SimpleTestTickClock testing_clock_; | 168 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. |
167 scoped_refptr<test::FakeTaskRunner> task_runner_; | 169 scoped_refptr<test::FakeTaskRunner> task_runner_; |
168 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; | 170 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; |
169 scoped_ptr<TestEncodedAudioFrameReceiver> receiver_; | 171 scoped_ptr<TestEncodedAudioFrameReceiver> receiver_; |
170 scoped_refptr<AudioEncoder> audio_encoder_; | 172 scoped_refptr<AudioEncoder> audio_encoder_; |
171 scoped_refptr<CastEnvironment> cast_environment_; | 173 scoped_refptr<CastEnvironment> cast_environment_; |
172 int release_callback_count_; | 174 int release_callback_count_; |
173 | 175 |
174 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest); | 176 DISALLOW_COPY_AND_ASSIGN(AudioEncoderTest); |
175 }; | 177 }; |
176 | 178 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 TestScenario(kManyCalls_3Millis, arraysize(kManyCalls_3Millis)), | 227 TestScenario(kManyCalls_3Millis, arraysize(kManyCalls_3Millis)), |
226 TestScenario(kManyCalls_10Millis, arraysize(kManyCalls_10Millis)), | 228 TestScenario(kManyCalls_10Millis, arraysize(kManyCalls_10Millis)), |
227 TestScenario(kManyCalls_Mixed1, arraysize(kManyCalls_Mixed1)), | 229 TestScenario(kManyCalls_Mixed1, arraysize(kManyCalls_Mixed1)), |
228 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)), | 230 TestScenario(kManyCalls_Mixed2, arraysize(kManyCalls_Mixed2)), |
229 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)), | 231 TestScenario(kManyCalls_Mixed3, arraysize(kManyCalls_Mixed3)), |
230 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)), | 232 TestScenario(kManyCalls_Mixed4, arraysize(kManyCalls_Mixed4)), |
231 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)))); | 233 TestScenario(kManyCalls_Mixed5, arraysize(kManyCalls_Mixed5)))); |
232 | 234 |
233 } // namespace cast | 235 } // namespace cast |
234 } // namespace media | 236 } // namespace media |
OLD | NEW |