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

Side by Side Diff: media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc

Issue 2923933004: [NotForReview] Move GJDAH and GJDA to media/gpu/mojo
Patch Set: . Created 3 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 2017 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 "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
6 #include "base/bind.h"
7 #include "base/run_loop.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/test/scoped_task_environment.h"
10 #include "base/threading/thread.h"
11 #include "gpu/ipc/service/gpu_channel.h"
12 #include "media/gpu/ipc/common/media_messages.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using testing::_;
17 using testing::SaveArg;
18 using testing::InvokeWithoutArgs;
19 using testing::Return;
20
21 namespace media {
22
23 static const size_t kOutputFrameSizeInBytes = 1024;
24 static const gfx::Size kDummyFrameCodedSize(10, 10);
25
26 class MockFilteredSender : public gpu::FilteredSender {
27 public:
28 MOCK_METHOD1(AddFilter, void(IPC::MessageFilter*));
29 MOCK_METHOD1(RemoveFilter, void(IPC::MessageFilter*));
30 MOCK_METHOD1(Send, bool(IPC::Message*));
31 };
32
33 class MockJpegDecodeAccelerator : public media::JpegDecodeAccelerator {
34 public:
35 MOCK_METHOD1(Initialize, bool(Client*));
36 MOCK_METHOD2(Decode,
37 void(const BitstreamBuffer&,
38 const scoped_refptr<media::VideoFrame>&));
39 MOCK_METHOD0(IsSupported, bool());
40 };
41
42 // Test fixture for the unit that is created via the constructor of
43 // class GpuJpegDecodeAccelerator. Uses a FakeJpegDecodeAccelerator to
44 // simulate the actual decoding without the need for special hardware.
45 class GpuJpegDecodeAcceleratorTest : public ::testing::Test {
46 public:
47 GpuJpegDecodeAcceleratorTest() : io_thread_("io") {}
48 ~GpuJpegDecodeAcceleratorTest() override{};
49
50 void SetUp() override {
51 output_frame_memory_.CreateAndMapAnonymous(kOutputFrameSizeInBytes);
52 io_thread_.Start();
53 std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB>
54 accelerator_factory_functions;
55 accelerator_factory_functions.push_back(
56 base::Bind(&GpuJpegDecodeAcceleratorTest::GetMockJpegDecodeAccelerator,
57 base::Unretained(this)));
58 system_under_test_ = base::MakeUnique<GpuJpegDecodeAccelerator>(
59 &gpu_channel_, io_thread_.task_runner(), accelerator_factory_functions);
60 }
61
62 MOCK_METHOD1(GetMockJpegDecodeAccelerator,
63 std::unique_ptr<JpegDecodeAccelerator>(
64 scoped_refptr<base::SingleThreadTaskRunner>));
65
66 void SendStubFrame(IPC::MessageFilter* message_filter, int32_t route_id) {
67 AcceleratedJpegDecoderMsg_Decode_Params decode_params;
68 decode_params.output_video_frame_handle = output_frame_memory_.handle();
69 decode_params.output_buffer_size =
70 static_cast<uint32_t>(kOutputFrameSizeInBytes);
71 decode_params.coded_size = kDummyFrameCodedSize;
72 AcceleratedJpegDecoderMsg_Decode message(route_id, decode_params);
73 message_filter->OnMessageReceived(message);
74 }
75
76 protected:
77 base::Thread io_thread_;
78 MockFilteredSender gpu_channel_;
79 std::unique_ptr<GpuJpegDecodeAccelerator> system_under_test_;
80 base::SharedMemory output_frame_memory_;
81
82 private:
83 // This is required to allow base::ThreadTaskRunnerHandle::Get() from the
84 // test execution thread.
85 base::test::ScopedTaskEnvironment scoped_task_environment_;
86 };
87
88 // Tests that the communication for decoding a frame between the caller of
89 // IPC:MessageFilter and the media::JpegDecodeAccelerator works as expected.
90 TEST_F(GpuJpegDecodeAcceleratorTest, DecodeFrameCallArrivesAtDecoder) {
91 static const int32_t kArbitraryRouteId = 123;
92 auto io_task_runner = io_thread_.task_runner();
93 auto main_task_runner = base::ThreadTaskRunnerHandle::Get();
94 auto decoder = base::MakeUnique<MockJpegDecodeAccelerator>();
95 auto* decoder_ptr = decoder.get();
96 ON_CALL(*decoder, Initialize(_)).WillByDefault(Return(true));
97
98 IPC::MessageFilter* message_filter = nullptr;
99 EXPECT_CALL(*this, GetMockJpegDecodeAccelerator(_))
100 .WillOnce(InvokeWithoutArgs([&decoder]() { return std::move(decoder); }));
101 EXPECT_CALL(gpu_channel_, AddFilter(_)).WillOnce(SaveArg<0>(&message_filter));
102 base::RunLoop run_loop;
103 auto response_cb = base::Bind(
104 [](base::RunLoop* run_loop,
105 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
106 bool succeeded) {
107 EXPECT_TRUE(succeeded);
108 if (main_task_runner->BelongsToCurrentThread() == false) {
109 DLOG(INFO) << "Response arrived on thread other than main thread.";
110 main_task_runner->PostTask(FROM_HERE, run_loop->QuitClosure());
111 return;
112 }
113 run_loop->Quit();
114 },
115 &run_loop, main_task_runner);
116 system_under_test_->AddClient(kArbitraryRouteId, response_cb);
117 run_loop.Run();
118 ASSERT_TRUE(message_filter);
119
120 // Send a AcceleratedJpegDecoderMsg_Decode to the |message_filter| on the
121 // io_thread.
122 base::RunLoop run_loop2;
123 EXPECT_CALL(*decoder_ptr, Decode(_, _));
124 io_task_runner->PostTaskAndReply(
125 FROM_HERE,
126 base::Bind(&GpuJpegDecodeAcceleratorTest::SendStubFrame,
127 base::Unretained(this), message_filter, kArbitraryRouteId),
128 run_loop2.QuitClosure());
129 run_loop2.Run();
130 }
131
132 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/ipc/service/gpu_jpeg_decode_accelerator.cc ('k') | media/gpu/ipc/service/media_gpu_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698