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