Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: remoting/client/audio_decode_scheduler_unittest.cc

Issue 2052723002: Adding an interface to allow extention of the audio player for CRD and iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a unit test for Decoder. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
Lambros 2016/06/17 18:32:29 No (c).
nicholss 2016/06/17 22:35:00 Done.
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"
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 18:32:29 I'm a bit puzzled by these tests, since you don't
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(
42 message_loop_.task_runner(), 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:: could share the following in a common class for use other places.
Lambros 2016/06/17 18:32:29 Remove TODO or use correct formatting: TODO(userna
nicholss 2016/06/17 22:35:00 Done.
57 std::unique_ptr<AudioPacket> CreatePacketWithSamplingRate_(
58 AudioPacket::SamplingRate rate,
59 int samples) {
60 std::unique_ptr<AudioPacket> packet(new AudioPacket());
61 packet->set_encoding(AudioPacket::ENCODING_RAW);
62 packet->set_sampling_rate(rate);
63 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2);
64 packet->set_channels(AudioPacket::CHANNELS_STEREO);
65
66 // The data must be a multiple of 4 bytes (channels x bytes_per_sample).
67 std::string data;
68 data.resize(samples * kAudioSampleBytes, kDummyAudioData);
69 packet->add_data(data);
70
71 return packet;
72 }
73
74 std::unique_ptr<AudioPacket> CreatePacket44100Hz_(int samples) {
75 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_44100,
76 samples);
77 }
78
79 std::unique_ptr<AudioPacket> CreatePacket48000Hz_(int samples) {
80 return CreatePacketWithSamplingRate_(AudioPacket::SAMPLING_RATE_48000,
81 samples);
82 }
83
84 void Done() {}
Lambros 2016/06/17 18:32:29 Remove (see below).
nicholss 2016/06/17 22:35:00 Done.
85
86 TEST_F(AudioDecodeSchedulerTest, Shutdown) {
87
88 std::unique_ptr<FakeAudioConsumer> audio_consumer(new FakeAudioConsumer());
89 std::unique_ptr<AudioDecodeScheduler> audio_scheduler(
90 new AudioDecodeScheduler(main_task_runner_,
91 audio_decode_task_runner_, audio_consumer.get()));
Lambros 2016/06/17 18:32:29 Looks like wrong indentation. Please run git cl fo
nicholss 2016/06/17 22:34:59 Done.
92
93 audio_scheduler->Initialize(*session_config_);
94
95 audio_scheduler->ProcessAudioPacket(CreatePacket44100Hz_(1000),
96 base::Bind(&Done));
Lambros 2016/06/17 18:32:29 base::Bind(&base::DoNothing)
nicholss 2016/06/17 22:34:59 Done.
97
98 audio_scheduler.reset();
99 audio_consumer.reset();
100 }
101
102 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698