| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/client/audio_decode_scheduler.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/threading/thread.h" | |
| 11 #include "remoting/base/auto_thread.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" | |
| 15 #include "remoting/protocol/session_config.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const int kAudioSampleBytes = 4; | |
| 21 const uint8_t kDummyAudioData = 0x8B; | |
| 22 | |
| 23 } // namespace | |
| 24 | |
| 25 namespace remoting { | |
| 26 | |
| 27 class AudioDecodeSchedulerTest : public ::testing::Test { | |
| 28 public: | |
| 29 AudioDecodeSchedulerTest() {} | |
| 30 | |
| 31 void SetUp() override; | |
| 32 void TearDown() override; | |
| 33 | |
| 34 protected: | |
| 35 base::MessageLoop message_loop_; | |
| 36 base::RunLoop run_loop_; | |
| 37 scoped_refptr<AutoThreadTaskRunner> audio_decode_task_runner_; | |
| 38 scoped_refptr<AutoThreadTaskRunner> main_task_runner_; | |
| 39 std::unique_ptr<protocol::SessionConfig> session_config_; | |
| 40 }; | |
| 41 | |
| 42 void AudioDecodeSchedulerTest::SetUp() { | |
| 43 main_task_runner_ = new AutoThreadTaskRunner(message_loop_.task_runner(), | |
| 44 run_loop_.QuitClosure()); | |
| 45 audio_decode_task_runner_ = AutoThread::Create("decode", main_task_runner_); | |
| 46 session_config_ = protocol::SessionConfig::ForTestWithAudio(); | |
| 47 } | |
| 48 | |
| 49 void AudioDecodeSchedulerTest::TearDown() { | |
| 50 // Release the task runners, so that the test can quit. | |
| 51 audio_decode_task_runner_ = nullptr; | |
| 52 main_task_runner_ = nullptr; | |
| 53 | |
| 54 // Run the MessageLoop until everything has torn down. | |
| 55 run_loop_.Run(); | |
| 56 } | |
| 57 | |
| 58 // TODO(nicholss): Could share the following in a common class for use | |
| 59 // in other places. | |
| 60 std::unique_ptr<AudioPacket> CreatePacketWithSamplingRate_( | |
| 61 AudioPacket::SamplingRate rate, | |
| 62 int samples) { | |
| 63 std::unique_ptr<AudioPacket> packet(new AudioPacket()); | |
| 64 packet->set_encoding(AudioPacket::ENCODING_RAW); | |
| 65 packet->set_sampling_rate(rate); | |
| 66 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | |
| 67 packet->set_channels(AudioPacket::CHANNELS_STEREO); | |
| 68 | |
| 69 // The data must be a multiple of 4 bytes (channels x bytes_per_sample). | |
| 70 std::string data; | |
| 71 data.resize(samples * kAudioSampleBytes, kDummyAudioData); | |
| 72 packet->add_data(data); | |
| 73 | |
| 74 return packet; | |
| 75 } | |
| 76 | |
| 77 std::unique_ptr<AudioPacket> CreatePacket44100Hz_(int samples) { | |
| 78 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_44100, | |
| 79 samples); | |
| 80 } | |
| 81 | |
| 82 std::unique_ptr<AudioPacket> CreatePacket48000Hz_(int samples) { | |
| 83 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_48000, | |
| 84 samples); | |
| 85 } | |
| 86 | |
| 87 TEST_F(AudioDecodeSchedulerTest, Shutdown) { | |
| 88 std::unique_ptr<FakeAudioConsumer> audio_consumer(new FakeAudioConsumer()); | |
| 89 std::unique_ptr<AudioDecodeScheduler> audio_scheduler( | |
| 90 new AudioDecodeScheduler(main_task_runner_, audio_decode_task_runner_, | |
| 91 audio_consumer->GetWeakPtr())); | |
| 92 | |
| 93 audio_scheduler->Initialize(*session_config_); | |
| 94 | |
| 95 audio_scheduler->ProcessAudioPacket(CreatePacket44100Hz_(1000), | |
| 96 base::Bind(&base::DoNothing)); | |
| 97 | |
| 98 audio_scheduler.reset(); | |
| 99 audio_consumer.reset(); | |
| 100 // TODO(nicholss): This test does not really test anything. Add a way to get | |
| 101 // a count of the calls to AddAudioPacket. | |
| 102 } | |
| 103 | |
| 104 } // namespace remoting | |
| OLD | NEW |