| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "remoting/client/audio_decode_scheduler.h" | 5 #include "remoting/protocol/audio_decode_scheduler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "remoting/base/auto_thread.h" | 11 #include "remoting/base/auto_thread.h" |
| 12 #include "remoting/base/auto_thread_task_runner.h" | 12 #include "remoting/base/auto_thread_task_runner.h" |
| 13 #include "remoting/client/fake_audio_consumer.h" | |
| 14 #include "remoting/proto/audio.pb.h" | 13 #include "remoting/proto/audio.pb.h" |
| 15 #include "remoting/protocol/session_config.h" | 14 #include "remoting/protocol/session_config.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 16 |
| 17 namespace remoting { |
| 18 namespace protocol { |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 | 21 |
| 20 const int kAudioSampleBytes = 4; | 22 const int kAudioSampleBytes = 4; |
| 21 const uint8_t kDummyAudioData = 0x8B; | 23 const uint8_t kDummyAudioData = 0x8B; |
| 22 | 24 |
| 25 class FakeAudioConsumer : public AudioStub { |
| 26 public: |
| 27 FakeAudioConsumer(): weak_factory_(this) {} |
| 28 ~FakeAudioConsumer() override {} |
| 29 |
| 30 base::WeakPtr<FakeAudioConsumer> GetWeakPtr(){ |
| 31 return weak_factory_.GetWeakPtr(); |
| 32 } |
| 33 |
| 34 // AudioStub implementation. |
| 35 void ProcessAudioPacket(std::unique_ptr<AudioPacket> packet, |
| 36 const base::Closure& done) override { |
| 37 if (!done.is_null()) |
| 38 done.Run(); |
| 39 } |
| 40 |
| 41 private: |
| 42 base::WeakPtrFactory<FakeAudioConsumer> weak_factory_; |
| 43 |
| 44 DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumer); |
| 45 }; |
| 46 |
| 23 } // namespace | 47 } // namespace |
| 24 | 48 |
| 25 namespace remoting { | |
| 26 | |
| 27 class AudioDecodeSchedulerTest : public ::testing::Test { | 49 class AudioDecodeSchedulerTest : public ::testing::Test { |
| 28 public: | 50 public: |
| 29 AudioDecodeSchedulerTest() {} | 51 AudioDecodeSchedulerTest() {} |
| 30 | 52 |
| 31 void SetUp() override; | 53 void SetUp() override; |
| 32 void TearDown() override; | 54 void TearDown() override; |
| 33 | 55 |
| 34 protected: | 56 protected: |
| 35 base::MessageLoop message_loop_; | 57 base::MessageLoop message_loop_; |
| 36 base::RunLoop run_loop_; | 58 base::RunLoop run_loop_; |
| 37 scoped_refptr<AutoThreadTaskRunner> audio_decode_task_runner_; | 59 scoped_refptr<AutoThreadTaskRunner> audio_decode_task_runner_; |
| 38 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; | 60 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; |
| 39 std::unique_ptr<protocol::SessionConfig> session_config_; | 61 std::unique_ptr<SessionConfig> session_config_; |
| 40 }; | 62 }; |
| 41 | 63 |
| 42 void AudioDecodeSchedulerTest::SetUp() { | 64 void AudioDecodeSchedulerTest::SetUp() { |
| 43 main_task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), | 65 main_task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), |
| 44 run_loop_.QuitClosure()); | 66 run_loop_.QuitClosure()); |
| 45 audio_decode_task_runner_ = AutoThread::Create("decode", main_task_runner_); | 67 audio_decode_task_runner_ = AutoThread::Create("decode", main_task_runner_); |
| 46 session_config_ = protocol::SessionConfig::ForTestWithAudio(); | 68 session_config_ = SessionConfig::ForTestWithAudio(); |
| 47 } | 69 } |
| 48 | 70 |
| 49 void AudioDecodeSchedulerTest::TearDown() { | 71 void AudioDecodeSchedulerTest::TearDown() { |
| 50 // Release the task runners, so that the test can quit. | 72 // Release the task runners, so that the test can quit. |
| 51 audio_decode_task_runner_ = nullptr; | 73 audio_decode_task_runner_ = nullptr; |
| 52 main_task_runner_ = nullptr; | 74 main_task_runner_ = nullptr; |
| 53 | 75 |
| 54 // Run the MessageLoop until everything has torn down. | 76 // Run the MessageLoop until everything has torn down. |
| 55 run_loop_.Run(); | 77 run_loop_.Run(); |
| 56 } | 78 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 80 } | 102 } |
| 81 | 103 |
| 82 std::unique_ptr<AudioPacket> CreatePacket48000Hz_(int samples) { | 104 std::unique_ptr<AudioPacket> CreatePacket48000Hz_(int samples) { |
| 83 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_48000, | 105 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_48000, |
| 84 samples); | 106 samples); |
| 85 } | 107 } |
| 86 | 108 |
| 87 TEST_F(AudioDecodeSchedulerTest, Shutdown) { | 109 TEST_F(AudioDecodeSchedulerTest, Shutdown) { |
| 88 std::unique_ptr<FakeAudioConsumer> audio_consumer(new FakeAudioConsumer()); | 110 std::unique_ptr<FakeAudioConsumer> audio_consumer(new FakeAudioConsumer()); |
| 89 std::unique_ptr<AudioDecodeScheduler> audio_scheduler( | 111 std::unique_ptr<AudioDecodeScheduler> audio_scheduler( |
| 90 new AudioDecodeScheduler(main_task_runner_, audio_decode_task_runner_, | 112 new AudioDecodeScheduler(audio_decode_task_runner_, |
| 91 audio_consumer->GetWeakPtr())); | 113 audio_consumer->GetWeakPtr())); |
| 92 | 114 |
| 93 audio_scheduler->Initialize(*session_config_); | 115 audio_scheduler->Initialize(*session_config_); |
| 94 | 116 |
| 95 audio_scheduler->ProcessAudioPacket(CreatePacket44100Hz_(1000), | 117 audio_scheduler->ProcessAudioPacket(CreatePacket44100Hz_(1000), |
| 96 base::Bind(&base::DoNothing)); | 118 base::Bind(&base::DoNothing)); |
| 97 | 119 |
| 98 audio_scheduler.reset(); | 120 audio_scheduler.reset(); |
| 99 audio_consumer.reset(); | 121 audio_consumer.reset(); |
| 100 // TODO(nicholss): This test does not really test anything. Add a way to get | 122 // TODO(nicholss): This test does not really test anything. Add a way to get |
| 101 // a count of the calls to AddAudioPacket. | 123 // a count of the calls to AddAudioPacket. |
| 102 } | 124 } |
| 103 | 125 |
| 126 } // namespace protocol |
| 104 } // namespace remoting | 127 } // namespace remoting |
| OLD | NEW |