| OLD | NEW |
| 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/cast/sender/audio_sender.h" | 5 #include "media/cast/sender/audio_sender.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/test/simple_test_tick_clock.h" | 14 #include "base/test/simple_test_tick_clock.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "media/base/fake_single_thread_task_runner.h" |
| 16 #include "media/base/media.h" | 17 #include "media/base/media.h" |
| 17 #include "media/cast/cast_config.h" | 18 #include "media/cast/cast_config.h" |
| 18 #include "media/cast/cast_environment.h" | 19 #include "media/cast/cast_environment.h" |
| 19 #include "media/cast/constants.h" | 20 #include "media/cast/constants.h" |
| 20 #include "media/cast/net/cast_transport_config.h" | 21 #include "media/cast/net/cast_transport_config.h" |
| 21 #include "media/cast/net/cast_transport_sender_impl.h" | 22 #include "media/cast/net/cast_transport_sender_impl.h" |
| 22 #include "media/cast/test/fake_single_thread_task_runner.h" | |
| 23 #include "media/cast/test/utility/audio_utility.h" | 23 #include "media/cast/test/utility/audio_utility.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 25 |
| 26 namespace media { | 26 namespace media { |
| 27 namespace cast { | 27 namespace cast { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 void SaveOperationalStatus(OperationalStatus* out_status, | 31 void SaveOperationalStatus(OperationalStatus* out_status, |
| 32 OperationalStatus in_status) { | 32 OperationalStatus in_status) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(TestPacketSender); | 89 DISALLOW_COPY_AND_ASSIGN(TestPacketSender); |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 class AudioSenderTest : public ::testing::Test { | 92 class AudioSenderTest : public ::testing::Test { |
| 93 protected: | 93 protected: |
| 94 AudioSenderTest() { | 94 AudioSenderTest() { |
| 95 InitializeMediaLibrary(); | 95 InitializeMediaLibrary(); |
| 96 testing_clock_ = new base::SimpleTestTickClock(); | 96 testing_clock_ = new base::SimpleTestTickClock(); |
| 97 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); | 97 testing_clock_->Advance(base::TimeTicks::Now() - base::TimeTicks()); |
| 98 task_runner_ = new test::FakeSingleThreadTaskRunner(testing_clock_); | 98 task_runner_ = new FakeSingleThreadTaskRunner(testing_clock_); |
| 99 cast_environment_ = | 99 cast_environment_ = |
| 100 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_), | 100 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_), |
| 101 task_runner_, task_runner_, task_runner_); | 101 task_runner_, task_runner_, task_runner_); |
| 102 audio_config_.codec = CODEC_AUDIO_OPUS; | 102 audio_config_.codec = CODEC_AUDIO_OPUS; |
| 103 audio_config_.use_external_encoder = false; | 103 audio_config_.use_external_encoder = false; |
| 104 audio_config_.frequency = kDefaultAudioSamplingRate; | 104 audio_config_.frequency = kDefaultAudioSamplingRate; |
| 105 audio_config_.channels = 2; | 105 audio_config_.channels = 2; |
| 106 audio_config_.bitrate = kDefaultAudioEncoderBitrate; | 106 audio_config_.bitrate = kDefaultAudioEncoderBitrate; |
| 107 audio_config_.rtp_payload_type = 127; | 107 audio_config_.rtp_payload_type = 127; |
| 108 | 108 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 119 transport_sender_.get())); | 119 transport_sender_.get())); |
| 120 task_runner_->RunTasks(); | 120 task_runner_->RunTasks(); |
| 121 CHECK_EQ(STATUS_INITIALIZED, operational_status); | 121 CHECK_EQ(STATUS_INITIALIZED, operational_status); |
| 122 } | 122 } |
| 123 | 123 |
| 124 ~AudioSenderTest() override {} | 124 ~AudioSenderTest() override {} |
| 125 | 125 |
| 126 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. | 126 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. |
| 127 TestPacketSender* transport_; // Owned by CastTransportSender. | 127 TestPacketSender* transport_; // Owned by CastTransportSender. |
| 128 scoped_ptr<CastTransportSenderImpl> transport_sender_; | 128 scoped_ptr<CastTransportSenderImpl> transport_sender_; |
| 129 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 129 scoped_refptr<FakeSingleThreadTaskRunner> task_runner_; |
| 130 scoped_ptr<AudioSender> audio_sender_; | 130 scoped_ptr<AudioSender> audio_sender_; |
| 131 scoped_refptr<CastEnvironment> cast_environment_; | 131 scoped_refptr<CastEnvironment> cast_environment_; |
| 132 AudioSenderConfig audio_config_; | 132 AudioSenderConfig audio_config_; |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 TEST_F(AudioSenderTest, Encode20ms) { | 135 TEST_F(AudioSenderTest, Encode20ms) { |
| 136 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(20); | 136 const base::TimeDelta kDuration = base::TimeDelta::FromMilliseconds(20); |
| 137 scoped_ptr<AudioBus> bus( | 137 scoped_ptr<AudioBus> bus( |
| 138 TestAudioBusFactory(audio_config_.channels, | 138 TestAudioBusFactory(audio_config_.channels, |
| 139 audio_config_.frequency, | 139 audio_config_.frequency, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 161 base::TimeDelta max_rtcp_timeout = | 161 base::TimeDelta max_rtcp_timeout = |
| 162 base::TimeDelta::FromMilliseconds(1 + kRtcpReportIntervalMs * 3 / 2); | 162 base::TimeDelta::FromMilliseconds(1 + kRtcpReportIntervalMs * 3 / 2); |
| 163 testing_clock_->Advance(max_rtcp_timeout); | 163 testing_clock_->Advance(max_rtcp_timeout); |
| 164 task_runner_->RunTasks(); | 164 task_runner_->RunTasks(); |
| 165 EXPECT_LE(1, transport_->number_of_rtp_packets()); | 165 EXPECT_LE(1, transport_->number_of_rtp_packets()); |
| 166 EXPECT_LE(1, transport_->number_of_rtcp_packets()); | 166 EXPECT_LE(1, transport_->number_of_rtcp_packets()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace cast | 169 } // namespace cast |
| 170 } // namespace media | 170 } // namespace media |
| OLD | NEW |