| 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 // This test generate synthetic data. For audio it's a sinusoid waveform with | 5 // This test generate synthetic data. For audio it's a sinusoid waveform with |
| 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern | 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern |
| 7 // that is shifting by one pixel per frame, each pixels neighbors right and down | 7 // that is shifting by one pixel per frame, each pixels neighbors right and down |
| 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap | 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap |
| 9 // frequently within the image. Visually this will create diagonally color bands | 9 // frequently within the image. Visually this will create diagonally color bands |
| 10 // that moves across the screen | 10 // that moves across the screen |
| 11 | 11 |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 #include <stddef.h> | 13 #include <stddef.h> |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 | 15 |
| 16 #include <algorithm> | 16 #include <algorithm> |
| 17 #include <functional> | 17 #include <functional> |
| 18 #include <list> | 18 #include <list> |
| 19 #include <map> | 19 #include <map> |
| 20 #include <utility> | 20 #include <utility> |
| 21 | 21 |
| 22 #include "base/bind.h" | 22 #include "base/bind.h" |
| 23 #include "base/bind_helpers.h" | 23 #include "base/bind_helpers.h" |
| 24 #include "base/memory/ptr_util.h" |
| 24 #include "base/strings/string_number_conversions.h" | 25 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/sys_byteorder.h" | 26 #include "base/sys_byteorder.h" |
| 26 #include "base/test/simple_test_tick_clock.h" | 27 #include "base/test/simple_test_tick_clock.h" |
| 27 #include "base/time/tick_clock.h" | 28 #include "base/time/tick_clock.h" |
| 28 #include "media/base/audio_bus.h" | 29 #include "media/base/audio_bus.h" |
| 29 #include "media/base/fake_single_thread_task_runner.h" | 30 #include "media/base/fake_single_thread_task_runner.h" |
| 30 #include "media/base/video_frame.h" | 31 #include "media/base/video_frame.h" |
| 31 #include "media/cast/cast_config.h" | 32 #include "media/cast/cast_config.h" |
| 32 #include "media/cast/cast_environment.h" | 33 #include "media/cast/cast_environment.h" |
| 33 #include "media/cast/cast_receiver.h" | 34 #include "media/cast/cast_receiver.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // Shim that turns forwards packets from a test::PacketPipe to a | 145 // Shim that turns forwards packets from a test::PacketPipe to a |
| 145 // PacketReceiverCallback. | 146 // PacketReceiverCallback. |
| 146 class LoopBackPacketPipe : public test::PacketPipe { | 147 class LoopBackPacketPipe : public test::PacketPipe { |
| 147 public: | 148 public: |
| 148 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) | 149 explicit LoopBackPacketPipe(const PacketReceiverCallback& packet_receiver) |
| 149 : packet_receiver_(packet_receiver) {} | 150 : packet_receiver_(packet_receiver) {} |
| 150 | 151 |
| 151 ~LoopBackPacketPipe() final {} | 152 ~LoopBackPacketPipe() final {} |
| 152 | 153 |
| 153 // PacketPipe implementations. | 154 // PacketPipe implementations. |
| 154 void Send(scoped_ptr<Packet> packet) final { | 155 void Send(std::unique_ptr<Packet> packet) final { |
| 155 packet_receiver_.Run(std::move(packet)); | 156 packet_receiver_.Run(std::move(packet)); |
| 156 } | 157 } |
| 157 | 158 |
| 158 private: | 159 private: |
| 159 PacketReceiverCallback packet_receiver_; | 160 PacketReceiverCallback packet_receiver_; |
| 160 }; | 161 }; |
| 161 | 162 |
| 162 // Class that sends the packet direct from sender into the receiver with the | 163 // Class that sends the packet direct from sender into the receiver with the |
| 163 // ability to drop packets between the two. | 164 // ability to drop packets between the two. |
| 164 // | 165 // |
| 165 // TODO(miu): This should be reconciled/merged into | 166 // TODO(miu): This should be reconciled/merged into |
| 166 // media/cast/test/loopback_transport.*. It's roughly the same class and has | 167 // media/cast/test/loopback_transport.*. It's roughly the same class and has |
| 167 // exactly the same name (and when it was outside of the anonymous namespace bad | 168 // exactly the same name (and when it was outside of the anonymous namespace bad |
| 168 // things happened when linking on Android!). | 169 // things happened when linking on Android!). |
| 169 class LoopBackTransport : public PacketTransport { | 170 class LoopBackTransport : public PacketTransport { |
| 170 public: | 171 public: |
| 171 explicit LoopBackTransport(scoped_refptr<CastEnvironment> cast_environment) | 172 explicit LoopBackTransport(scoped_refptr<CastEnvironment> cast_environment) |
| 172 : send_packets_(true), | 173 : send_packets_(true), |
| 173 drop_packets_belonging_to_odd_frames_(false), | 174 drop_packets_belonging_to_odd_frames_(false), |
| 174 cast_environment_(cast_environment), | 175 cast_environment_(cast_environment), |
| 175 bytes_sent_(0) {} | 176 bytes_sent_(0) {} |
| 176 | 177 |
| 177 void SetPacketReceiver( | 178 void SetPacketReceiver( |
| 178 const PacketReceiverCallback& packet_receiver, | 179 const PacketReceiverCallback& packet_receiver, |
| 179 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 180 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 180 base::TickClock* clock) { | 181 base::TickClock* clock) { |
| 181 scoped_ptr<test::PacketPipe> loopback_pipe( | 182 std::unique_ptr<test::PacketPipe> loopback_pipe( |
| 182 new LoopBackPacketPipe(packet_receiver)); | 183 new LoopBackPacketPipe(packet_receiver)); |
| 183 if (packet_pipe_) { | 184 if (packet_pipe_) { |
| 184 packet_pipe_->AppendToPipe(std::move(loopback_pipe)); | 185 packet_pipe_->AppendToPipe(std::move(loopback_pipe)); |
| 185 } else { | 186 } else { |
| 186 packet_pipe_ = std::move(loopback_pipe); | 187 packet_pipe_ = std::move(loopback_pipe); |
| 187 } | 188 } |
| 188 packet_pipe_->InitOnIOThread(task_runner, clock); | 189 packet_pipe_->InitOnIOThread(task_runner, clock); |
| 189 } | 190 } |
| 190 | 191 |
| 191 bool SendPacket(PacketRef packet, const base::Closure& cb) final { | 192 bool SendPacket(PacketRef packet, const base::Closure& cb) final { |
| 192 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); | 193 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); |
| 193 if (!send_packets_) | 194 if (!send_packets_) |
| 194 return true; | 195 return true; |
| 195 | 196 |
| 196 bytes_sent_ += packet->data.size(); | 197 bytes_sent_ += packet->data.size(); |
| 197 if (drop_packets_belonging_to_odd_frames_) { | 198 if (drop_packets_belonging_to_odd_frames_) { |
| 198 uint32_t frame_id = packet->data[13]; | 199 uint32_t frame_id = packet->data[13]; |
| 199 if (frame_id % 2 == 1) | 200 if (frame_id % 2 == 1) |
| 200 return true; | 201 return true; |
| 201 } | 202 } |
| 202 | 203 |
| 203 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); | 204 std::unique_ptr<Packet> packet_copy(new Packet(packet->data)); |
| 204 packet_pipe_->Send(std::move(packet_copy)); | 205 packet_pipe_->Send(std::move(packet_copy)); |
| 205 return true; | 206 return true; |
| 206 } | 207 } |
| 207 | 208 |
| 208 int64_t GetBytesSent() final { return bytes_sent_; } | 209 int64_t GetBytesSent() final { return bytes_sent_; } |
| 209 | 210 |
| 210 void StartReceiving( | 211 void StartReceiving( |
| 211 const PacketReceiverCallbackWithStatus& packet_receiver) final {} | 212 const PacketReceiverCallbackWithStatus& packet_receiver) final {} |
| 212 | 213 |
| 213 void StopReceiving() final {} | 214 void StopReceiving() final {} |
| 214 | 215 |
| 215 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; } | 216 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; } |
| 216 | 217 |
| 217 void DropAllPacketsBelongingToOddFrames() { | 218 void DropAllPacketsBelongingToOddFrames() { |
| 218 drop_packets_belonging_to_odd_frames_ = true; | 219 drop_packets_belonging_to_odd_frames_ = true; |
| 219 } | 220 } |
| 220 | 221 |
| 221 void SetPacketPipe(scoped_ptr<test::PacketPipe> pipe) { | 222 void SetPacketPipe(std::unique_ptr<test::PacketPipe> pipe) { |
| 222 // Append the loopback pipe to the end. | 223 // Append the loopback pipe to the end. |
| 223 pipe->AppendToPipe(std::move(packet_pipe_)); | 224 pipe->AppendToPipe(std::move(packet_pipe_)); |
| 224 packet_pipe_ = std::move(pipe); | 225 packet_pipe_ = std::move(pipe); |
| 225 } | 226 } |
| 226 | 227 |
| 227 private: | 228 private: |
| 228 bool send_packets_; | 229 bool send_packets_; |
| 229 bool drop_packets_belonging_to_odd_frames_; | 230 bool drop_packets_belonging_to_odd_frames_; |
| 230 scoped_refptr<CastEnvironment> cast_environment_; | 231 scoped_refptr<CastEnvironment> cast_environment_; |
| 231 scoped_ptr<test::PacketPipe> packet_pipe_; | 232 std::unique_ptr<test::PacketPipe> packet_pipe_; |
| 232 int64_t bytes_sent_; | 233 int64_t bytes_sent_; |
| 233 }; | 234 }; |
| 234 | 235 |
| 235 // Class that verifies the audio frames coming out of the receiver. | 236 // Class that verifies the audio frames coming out of the receiver. |
| 236 class TestReceiverAudioCallback | 237 class TestReceiverAudioCallback |
| 237 : public base::RefCountedThreadSafe<TestReceiverAudioCallback> { | 238 : public base::RefCountedThreadSafe<TestReceiverAudioCallback> { |
| 238 public: | 239 public: |
| 239 struct ExpectedAudioFrame { | 240 struct ExpectedAudioFrame { |
| 240 scoped_ptr<AudioBus> audio_bus; | 241 std::unique_ptr<AudioBus> audio_bus; |
| 241 base::TimeTicks playout_time; | 242 base::TimeTicks playout_time; |
| 242 }; | 243 }; |
| 243 | 244 |
| 244 TestReceiverAudioCallback() : num_called_(0) {} | 245 TestReceiverAudioCallback() : num_called_(0) {} |
| 245 | 246 |
| 246 void SetExpectedSamplingFrequency(int expected_sampling_frequency) { | 247 void SetExpectedSamplingFrequency(int expected_sampling_frequency) { |
| 247 expected_sampling_frequency_ = expected_sampling_frequency; | 248 expected_sampling_frequency_ = expected_sampling_frequency; |
| 248 } | 249 } |
| 249 | 250 |
| 250 void AddExpectedResult(const AudioBus& audio_bus, | 251 void AddExpectedResult(const AudioBus& audio_bus, |
| 251 const base::TimeTicks& playout_time) { | 252 const base::TimeTicks& playout_time) { |
| 252 scoped_ptr<ExpectedAudioFrame> expected_audio_frame( | 253 std::unique_ptr<ExpectedAudioFrame> expected_audio_frame( |
| 253 new ExpectedAudioFrame()); | 254 new ExpectedAudioFrame()); |
| 254 expected_audio_frame->audio_bus = | 255 expected_audio_frame->audio_bus = |
| 255 AudioBus::Create(audio_bus.channels(), audio_bus.frames()); | 256 AudioBus::Create(audio_bus.channels(), audio_bus.frames()); |
| 256 audio_bus.CopyTo(expected_audio_frame->audio_bus.get()); | 257 audio_bus.CopyTo(expected_audio_frame->audio_bus.get()); |
| 257 expected_audio_frame->playout_time = playout_time; | 258 expected_audio_frame->playout_time = playout_time; |
| 258 expected_frames_.push_back(expected_audio_frame.release()); | 259 expected_frames_.push_back(expected_audio_frame.release()); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void IgnoreAudioFrame(scoped_ptr<AudioBus> audio_bus, | 262 void IgnoreAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
| 262 const base::TimeTicks& playout_time, | 263 const base::TimeTicks& playout_time, |
| 263 bool is_continuous) { | 264 bool is_continuous) { |
| 264 ++num_called_; | 265 ++num_called_; |
| 265 } | 266 } |
| 266 | 267 |
| 267 void CheckAudioFrame(scoped_ptr<AudioBus> audio_bus, | 268 void CheckAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
| 268 const base::TimeTicks& playout_time, | 269 const base::TimeTicks& playout_time, |
| 269 bool is_continuous) { | 270 bool is_continuous) { |
| 270 ++num_called_; | 271 ++num_called_; |
| 271 | 272 |
| 272 ASSERT_TRUE(audio_bus); | 273 ASSERT_TRUE(audio_bus); |
| 273 ASSERT_FALSE(expected_frames_.empty()); | 274 ASSERT_FALSE(expected_frames_.empty()); |
| 274 const scoped_ptr<ExpectedAudioFrame> expected_audio_frame( | 275 const std::unique_ptr<ExpectedAudioFrame> expected_audio_frame( |
| 275 expected_frames_.front()); | 276 expected_frames_.front()); |
| 276 expected_frames_.pop_front(); | 277 expected_frames_.pop_front(); |
| 277 | 278 |
| 278 EXPECT_EQ(audio_bus->channels(), kAudioChannels); | 279 EXPECT_EQ(audio_bus->channels(), kAudioChannels); |
| 279 EXPECT_EQ(audio_bus->frames(), expected_audio_frame->audio_bus->frames()); | 280 EXPECT_EQ(audio_bus->frames(), expected_audio_frame->audio_bus->frames()); |
| 280 for (int ch = 0; ch < audio_bus->channels(); ++ch) { | 281 for (int ch = 0; ch < audio_bus->channels(); ++ch) { |
| 281 EXPECT_NEAR(CountZeroCrossings( | 282 EXPECT_NEAR(CountZeroCrossings( |
| 282 expected_audio_frame->audio_bus->channel(ch), | 283 expected_audio_frame->audio_bus->channel(ch), |
| 283 expected_audio_frame->audio_bus->frames()), | 284 expected_audio_frame->audio_bus->frames()), |
| 284 CountZeroCrossings(audio_bus->channel(ch), | 285 CountZeroCrossings(audio_bus->channel(ch), |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 std::list<ExpectedVideoFrame> expected_frame_; | 391 std::list<ExpectedVideoFrame> expected_frame_; |
| 391 base::TimeTicks last_playout_time_; | 392 base::TimeTicks last_playout_time_; |
| 392 }; | 393 }; |
| 393 | 394 |
| 394 } // namespace | 395 } // namespace |
| 395 | 396 |
| 396 // The actual test class, generate synthetic data for both audio and video and | 397 // The actual test class, generate synthetic data for both audio and video and |
| 397 // send those through the sender and receiver and analyzes the result. | 398 // send those through the sender and receiver and analyzes the result. |
| 398 class End2EndTest : public ::testing::Test { | 399 class End2EndTest : public ::testing::Test { |
| 399 public: | 400 public: |
| 400 void ReceivePacket(scoped_ptr<media::cast::Packet> packet) { | 401 void ReceivePacket(std::unique_ptr<media::cast::Packet> packet) { |
| 401 cast_receiver_->ReceivePacket(std::move(packet)); | 402 cast_receiver_->ReceivePacket(std::move(packet)); |
| 402 }; | 403 }; |
| 403 | 404 |
| 404 protected: | 405 protected: |
| 405 End2EndTest() | 406 End2EndTest() |
| 406 : start_time_(), | 407 : start_time_(), |
| 407 task_runner_(new FakeSingleThreadTaskRunner(&testing_clock_)), | 408 task_runner_(new FakeSingleThreadTaskRunner(&testing_clock_)), |
| 408 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), | 409 testing_clock_sender_(new test::SkewedTickClock(&testing_clock_)), |
| 409 task_runner_sender_( | 410 task_runner_sender_( |
| 410 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 411 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
| 411 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), | 412 testing_clock_receiver_(new test::SkewedTickClock(&testing_clock_)), |
| 412 task_runner_receiver_( | 413 task_runner_receiver_( |
| 413 new test::SkewedSingleThreadTaskRunner(task_runner_)), | 414 new test::SkewedSingleThreadTaskRunner(task_runner_)), |
| 414 cast_environment_sender_(new CastEnvironment( | 415 cast_environment_sender_(new CastEnvironment( |
| 415 scoped_ptr<base::TickClock>(testing_clock_sender_), | 416 std::unique_ptr<base::TickClock>(testing_clock_sender_), |
| 416 task_runner_sender_, | 417 task_runner_sender_, |
| 417 task_runner_sender_, | 418 task_runner_sender_, |
| 418 task_runner_sender_)), | 419 task_runner_sender_)), |
| 419 cast_environment_receiver_(new CastEnvironment( | 420 cast_environment_receiver_(new CastEnvironment( |
| 420 scoped_ptr<base::TickClock>(testing_clock_receiver_), | 421 std::unique_ptr<base::TickClock>(testing_clock_receiver_), |
| 421 task_runner_receiver_, | 422 task_runner_receiver_, |
| 422 task_runner_receiver_, | 423 task_runner_receiver_, |
| 423 task_runner_receiver_)), | 424 task_runner_receiver_)), |
| 424 receiver_to_sender_(new LoopBackTransport(cast_environment_receiver_)), | 425 receiver_to_sender_(new LoopBackTransport(cast_environment_receiver_)), |
| 425 sender_to_receiver_(new LoopBackTransport(cast_environment_sender_)), | 426 sender_to_receiver_(new LoopBackTransport(cast_environment_sender_)), |
| 426 test_receiver_audio_callback_(new TestReceiverAudioCallback()), | 427 test_receiver_audio_callback_(new TestReceiverAudioCallback()), |
| 427 test_receiver_video_callback_(new TestReceiverVideoCallback()) { | 428 test_receiver_video_callback_(new TestReceiverVideoCallback()) { |
| 428 testing_clock_.Advance( | 429 testing_clock_.Advance( |
| 429 base::TimeDelta::FromMilliseconds(kStartMillisecond)); | 430 base::TimeDelta::FromMilliseconds(kStartMillisecond)); |
| 430 cast_environment_sender_->logger()->Subscribe(&event_subscriber_sender_); | 431 cast_environment_sender_->logger()->Subscribe(&event_subscriber_sender_); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 void SetExpectedVideoPlayoutSmoothness(base::TimeDelta min_delta, | 507 void SetExpectedVideoPlayoutSmoothness(base::TimeDelta min_delta, |
| 507 base::TimeDelta max_delta, | 508 base::TimeDelta max_delta, |
| 508 base::TimeDelta max_curvature) { | 509 base::TimeDelta max_curvature) { |
| 509 min_video_playout_delta_ = min_delta; | 510 min_video_playout_delta_ = min_delta; |
| 510 max_video_playout_delta_ = max_delta; | 511 max_video_playout_delta_ = max_delta; |
| 511 max_video_playout_curvature_ = max_curvature; | 512 max_video_playout_curvature_ = max_curvature; |
| 512 } | 513 } |
| 513 | 514 |
| 514 void FeedAudioFrames(int count, bool will_be_checked) { | 515 void FeedAudioFrames(int count, bool will_be_checked) { |
| 515 for (int i = 0; i < count; ++i) { | 516 for (int i = 0; i < count; ++i) { |
| 516 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 517 std::unique_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| 517 base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs))); | 518 base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs))); |
| 518 const base::TimeTicks reference_time = | 519 const base::TimeTicks reference_time = |
| 519 testing_clock_sender_->NowTicks() + | 520 testing_clock_sender_->NowTicks() + |
| 520 i * base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs); | 521 i * base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs); |
| 521 if (will_be_checked) { | 522 if (will_be_checked) { |
| 522 test_receiver_audio_callback_->AddExpectedResult( | 523 test_receiver_audio_callback_->AddExpectedResult( |
| 523 *audio_bus, | 524 *audio_bus, |
| 524 reference_time + | 525 reference_time + |
| 525 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs)); | 526 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs)); |
| 526 } | 527 } |
| 527 audio_frame_input_->InsertAudio(std::move(audio_bus), reference_time); | 528 audio_frame_input_->InsertAudio(std::move(audio_bus), reference_time); |
| 528 } | 529 } |
| 529 } | 530 } |
| 530 | 531 |
| 531 void FeedAudioFramesWithExpectedDelay(int count, | 532 void FeedAudioFramesWithExpectedDelay(int count, |
| 532 const base::TimeDelta& delay) { | 533 const base::TimeDelta& delay) { |
| 533 for (int i = 0; i < count; ++i) { | 534 for (int i = 0; i < count; ++i) { |
| 534 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 535 std::unique_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| 535 base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs))); | 536 base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs))); |
| 536 const base::TimeTicks reference_time = | 537 const base::TimeTicks reference_time = |
| 537 testing_clock_sender_->NowTicks() + | 538 testing_clock_sender_->NowTicks() + |
| 538 i * base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs); | 539 i * base::TimeDelta::FromMilliseconds(kAudioFrameDurationMs); |
| 539 test_receiver_audio_callback_->AddExpectedResult( | 540 test_receiver_audio_callback_->AddExpectedResult( |
| 540 *audio_bus, | 541 *audio_bus, |
| 541 reference_time + delay + | 542 reference_time + delay + |
| 542 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs)); | 543 base::TimeDelta::FromMilliseconds(kTargetPlayoutDelayMs)); |
| 543 audio_frame_input_->InsertAudio(std::move(audio_bus), reference_time); | 544 audio_frame_input_->InsertAudio(std::move(audio_bus), reference_time); |
| 544 } | 545 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 last_video_playout_time_ = playout_time; | 799 last_video_playout_time_ = playout_time; |
| 799 | 800 |
| 800 video_ticks_.push_back(std::make_pair( | 801 video_ticks_.push_back(std::make_pair( |
| 801 testing_clock_receiver_->NowTicks(), | 802 testing_clock_receiver_->NowTicks(), |
| 802 playout_time)); | 803 playout_time)); |
| 803 cast_receiver_->RequestDecodedVideoFrame( | 804 cast_receiver_->RequestDecodedVideoFrame( |
| 804 base::Bind(&End2EndTest::BasicPlayerGotVideoFrame, | 805 base::Bind(&End2EndTest::BasicPlayerGotVideoFrame, |
| 805 base::Unretained(this))); | 806 base::Unretained(this))); |
| 806 } | 807 } |
| 807 | 808 |
| 808 void BasicPlayerGotAudioFrame(scoped_ptr<AudioBus> audio_bus, | 809 void BasicPlayerGotAudioFrame(std::unique_ptr<AudioBus> audio_bus, |
| 809 const base::TimeTicks& playout_time, | 810 const base::TimeTicks& playout_time, |
| 810 bool is_continuous) { | 811 bool is_continuous) { |
| 811 VLOG_IF(1, !last_audio_playout_time_.is_null()) | 812 VLOG_IF(1, !last_audio_playout_time_.is_null()) |
| 812 << "Audio frame playout time delta (compared to last frame) is " | 813 << "Audio frame playout time delta (compared to last frame) is " |
| 813 << (playout_time - last_audio_playout_time_).InMicroseconds() | 814 << (playout_time - last_audio_playout_time_).InMicroseconds() |
| 814 << " usec."; | 815 << " usec."; |
| 815 last_audio_playout_time_ = playout_time; | 816 last_audio_playout_time_ = playout_time; |
| 816 | 817 |
| 817 audio_ticks_.push_back(std::make_pair( | 818 audio_ticks_.push_back(std::make_pair( |
| 818 testing_clock_receiver_->NowTicks(), | 819 testing_clock_receiver_->NowTicks(), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 base::TimeTicks last_video_playout_time_; | 856 base::TimeTicks last_video_playout_time_; |
| 856 base::TimeDelta last_video_playout_delta_; | 857 base::TimeDelta last_video_playout_delta_; |
| 857 base::TimeTicks last_audio_playout_time_; | 858 base::TimeTicks last_audio_playout_time_; |
| 858 | 859 |
| 859 scoped_refptr<CastEnvironment> cast_environment_sender_; | 860 scoped_refptr<CastEnvironment> cast_environment_sender_; |
| 860 scoped_refptr<CastEnvironment> cast_environment_receiver_; | 861 scoped_refptr<CastEnvironment> cast_environment_receiver_; |
| 861 | 862 |
| 862 LoopBackTransport* receiver_to_sender_; // Owned by CastTransport. | 863 LoopBackTransport* receiver_to_sender_; // Owned by CastTransport. |
| 863 LoopBackTransport* sender_to_receiver_; // Owned by CastTransport. | 864 LoopBackTransport* sender_to_receiver_; // Owned by CastTransport. |
| 864 | 865 |
| 865 scoped_ptr<CastTransportImpl> transport_sender_; | 866 std::unique_ptr<CastTransportImpl> transport_sender_; |
| 866 scoped_ptr<CastTransportImpl> transport_receiver_; | 867 std::unique_ptr<CastTransportImpl> transport_receiver_; |
| 867 | 868 |
| 868 scoped_ptr<CastReceiver> cast_receiver_; | 869 std::unique_ptr<CastReceiver> cast_receiver_; |
| 869 scoped_ptr<CastSender> cast_sender_; | 870 std::unique_ptr<CastSender> cast_sender_; |
| 870 scoped_refptr<AudioFrameInput> audio_frame_input_; | 871 scoped_refptr<AudioFrameInput> audio_frame_input_; |
| 871 scoped_refptr<VideoFrameInput> video_frame_input_; | 872 scoped_refptr<VideoFrameInput> video_frame_input_; |
| 872 | 873 |
| 873 scoped_refptr<TestReceiverAudioCallback> test_receiver_audio_callback_; | 874 scoped_refptr<TestReceiverAudioCallback> test_receiver_audio_callback_; |
| 874 scoped_refptr<TestReceiverVideoCallback> test_receiver_video_callback_; | 875 scoped_refptr<TestReceiverVideoCallback> test_receiver_video_callback_; |
| 875 | 876 |
| 876 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; | 877 std::unique_ptr<TestAudioBusFactory> audio_bus_factory_; |
| 877 | 878 |
| 878 SimpleEventSubscriber event_subscriber_sender_; | 879 SimpleEventSubscriber event_subscriber_sender_; |
| 879 | 880 |
| 880 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > audio_ticks_; | 881 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > audio_ticks_; |
| 881 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > video_ticks_; | 882 std::vector<std::pair<base::TimeTicks, base::TimeTicks> > video_ticks_; |
| 882 | 883 |
| 883 // |transport_sender_| has a RepeatingTimer which needs a MessageLoop. | 884 // |transport_sender_| has a RepeatingTimer which needs a MessageLoop. |
| 884 base::MessageLoop message_loop_; | 885 base::MessageLoop message_loop_; |
| 885 }; | 886 }; |
| 886 | 887 |
| 887 namespace { | 888 namespace { |
| 888 | 889 |
| 889 class TransportClient : public CastTransport::Client { | 890 class TransportClient : public CastTransport::Client { |
| 890 public: | 891 public: |
| 891 TransportClient(LogEventDispatcher* log_event_dispatcher, | 892 TransportClient(LogEventDispatcher* log_event_dispatcher, |
| 892 End2EndTest* e2e_test) | 893 End2EndTest* e2e_test) |
| 893 : log_event_dispatcher_(log_event_dispatcher), e2e_test_(e2e_test) {} | 894 : log_event_dispatcher_(log_event_dispatcher), e2e_test_(e2e_test) {} |
| 894 | 895 |
| 895 void OnStatusChanged(media::cast::CastTransportStatus status) final { | 896 void OnStatusChanged(media::cast::CastTransportStatus status) final { |
| 896 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || | 897 bool result = (status == TRANSPORT_AUDIO_INITIALIZED || |
| 897 status == TRANSPORT_VIDEO_INITIALIZED); | 898 status == TRANSPORT_VIDEO_INITIALIZED); |
| 898 EXPECT_TRUE(result); | 899 EXPECT_TRUE(result); |
| 899 }; | 900 }; |
| 900 void OnLoggingEventsReceived( | 901 void OnLoggingEventsReceived( |
| 901 scoped_ptr<std::vector<FrameEvent>> frame_events, | 902 std::unique_ptr<std::vector<FrameEvent>> frame_events, |
| 902 scoped_ptr<std::vector<PacketEvent>> packet_events) final { | 903 std::unique_ptr<std::vector<PacketEvent>> packet_events) final { |
| 903 log_event_dispatcher_->DispatchBatchOfEvents(std::move(frame_events), | 904 log_event_dispatcher_->DispatchBatchOfEvents(std::move(frame_events), |
| 904 std::move(packet_events)); | 905 std::move(packet_events)); |
| 905 }; | 906 }; |
| 906 void ProcessRtpPacket(scoped_ptr<Packet> packet) final { | 907 void ProcessRtpPacket(std::unique_ptr<Packet> packet) final { |
| 907 if (e2e_test_) | 908 if (e2e_test_) |
| 908 e2e_test_->ReceivePacket(std::move(packet)); | 909 e2e_test_->ReceivePacket(std::move(packet)); |
| 909 }; | 910 }; |
| 910 | 911 |
| 911 private: | 912 private: |
| 912 LogEventDispatcher* const log_event_dispatcher_; // Not owned by this class. | 913 LogEventDispatcher* const log_event_dispatcher_; // Not owned by this class. |
| 913 End2EndTest* const e2e_test_; // Not owned by this class. | 914 End2EndTest* const e2e_test_; // Not owned by this class. |
| 914 | 915 |
| 915 DISALLOW_COPY_AND_ASSIGN(TransportClient); | 916 DISALLOW_COPY_AND_ASSIGN(TransportClient); |
| 916 }; | 917 }; |
| 917 | 918 |
| 918 } // namespace | 919 } // namespace |
| 919 | 920 |
| 920 void End2EndTest::Create() { | 921 void End2EndTest::Create() { |
| 921 transport_sender_.reset(new CastTransportImpl( | 922 transport_sender_.reset(new CastTransportImpl( |
| 922 testing_clock_sender_, base::TimeDelta::FromMilliseconds(1), | 923 testing_clock_sender_, base::TimeDelta::FromMilliseconds(1), |
| 923 make_scoped_ptr( | 924 base::WrapUnique( |
| 924 new TransportClient(cast_environment_sender_->logger(), nullptr)), | 925 new TransportClient(cast_environment_sender_->logger(), nullptr)), |
| 925 make_scoped_ptr(sender_to_receiver_), task_runner_sender_)); | 926 base::WrapUnique(sender_to_receiver_), task_runner_sender_)); |
| 926 | 927 |
| 927 transport_receiver_.reset(new CastTransportImpl( | 928 transport_receiver_.reset(new CastTransportImpl( |
| 928 testing_clock_sender_, base::TimeDelta::FromMilliseconds(1), | 929 testing_clock_sender_, base::TimeDelta::FromMilliseconds(1), |
| 929 make_scoped_ptr( | 930 base::WrapUnique( |
| 930 new TransportClient(cast_environment_receiver_->logger(), this)), | 931 new TransportClient(cast_environment_receiver_->logger(), this)), |
| 931 make_scoped_ptr(receiver_to_sender_), task_runner_sender_)); | 932 base::WrapUnique(receiver_to_sender_), task_runner_sender_)); |
| 932 | 933 |
| 933 cast_receiver_ = | 934 cast_receiver_ = |
| 934 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, | 935 CastReceiver::Create(cast_environment_receiver_, audio_receiver_config_, |
| 935 video_receiver_config_, transport_receiver_.get()); | 936 video_receiver_config_, transport_receiver_.get()); |
| 936 | 937 |
| 937 cast_sender_ = | 938 cast_sender_ = |
| 938 CastSender::Create(cast_environment_sender_, transport_sender_.get()); | 939 CastSender::Create(cast_environment_sender_, transport_sender_.get()); |
| 939 | 940 |
| 940 // Initializing audio and video senders. | 941 // Initializing audio and video senders. |
| 941 cast_sender_->InitializeAudio(audio_sender_config_, | 942 cast_sender_->InitializeAudio(audio_sender_config_, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 EXPECT_LT(static_cast<size_t>(kLongTestIterations / 100), | 1201 EXPECT_LT(static_cast<size_t>(kLongTestIterations / 100), |
| 1201 video_ticks_.size()); | 1202 video_ticks_.size()); |
| 1202 EXPECT_GE(static_cast<size_t>(kLongTestIterations / 3), video_ticks_.size()); | 1203 EXPECT_GE(static_cast<size_t>(kLongTestIterations / 3), video_ticks_.size()); |
| 1203 VLOG(1) << "Fully transmitted " << video_ticks_.size() << " frames."; | 1204 VLOG(1) << "Fully transmitted " << video_ticks_.size() << " frames."; |
| 1204 EXPECT_LT((video_ticks_.back().second - test_end).InMilliseconds(), 1000); | 1205 EXPECT_LT((video_ticks_.back().second - test_end).InMilliseconds(), 1000); |
| 1205 } | 1206 } |
| 1206 | 1207 |
| 1207 TEST_F(End2EndTest, OldPacketNetwork) { | 1208 TEST_F(End2EndTest, OldPacketNetwork) { |
| 1208 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); | 1209 Configure(CODEC_VIDEO_FAKE, CODEC_AUDIO_PCM16); |
| 1209 sender_to_receiver_->SetPacketPipe(test::NewRandomDrop(0.01)); | 1210 sender_to_receiver_->SetPacketPipe(test::NewRandomDrop(0.01)); |
| 1210 scoped_ptr<test::PacketPipe> echo_chamber( | 1211 std::unique_ptr<test::PacketPipe> echo_chamber( |
| 1211 test::NewDuplicateAndDelay(1, 10 * kFrameTimerMs)); | 1212 test::NewDuplicateAndDelay(1, 10 * kFrameTimerMs)); |
| 1212 echo_chamber->AppendToPipe( | 1213 echo_chamber->AppendToPipe( |
| 1213 test::NewDuplicateAndDelay(1, 20 * kFrameTimerMs)); | 1214 test::NewDuplicateAndDelay(1, 20 * kFrameTimerMs)); |
| 1214 echo_chamber->AppendToPipe( | 1215 echo_chamber->AppendToPipe( |
| 1215 test::NewDuplicateAndDelay(1, 40 * kFrameTimerMs)); | 1216 test::NewDuplicateAndDelay(1, 40 * kFrameTimerMs)); |
| 1216 echo_chamber->AppendToPipe( | 1217 echo_chamber->AppendToPipe( |
| 1217 test::NewDuplicateAndDelay(1, 80 * kFrameTimerMs)); | 1218 test::NewDuplicateAndDelay(1, 80 * kFrameTimerMs)); |
| 1218 echo_chamber->AppendToPipe( | 1219 echo_chamber->AppendToPipe( |
| 1219 test::NewDuplicateAndDelay(1, 160 * kFrameTimerMs)); | 1220 test::NewDuplicateAndDelay(1, 160 * kFrameTimerMs)); |
| 1220 | 1221 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 EXPECT_EQ(0u, jump); | 1271 EXPECT_EQ(0u, jump); |
| 1271 jump = i; | 1272 jump = i; |
| 1272 } | 1273 } |
| 1273 } | 1274 } |
| 1274 EXPECT_GT(jump, 49u); | 1275 EXPECT_GT(jump, 49u); |
| 1275 EXPECT_LT(jump, 120u); | 1276 EXPECT_LT(jump, 120u); |
| 1276 } | 1277 } |
| 1277 | 1278 |
| 1278 } // namespace cast | 1279 } // namespace cast |
| 1279 } // namespace media | 1280 } // namespace media |
| OLD | NEW |