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

Unified Diff: media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc

Issue 2924573002: [NotForReview] Convert accelerated JPEG Decoder IPC to 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc
diff --git a/media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc b/media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc
index 67fd1fdae43fec3a69cd85095b981fef3707469b..28d4c2d57e366cb7dbbdb938e9de758a69e85999 100644
--- a/media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc
+++ b/media/gpu/ipc/service/gpu_jpeg_decode_accelerator_unittest.cc
@@ -3,43 +3,22 @@
// found in the LICENSE file.
#include "media/gpu/ipc/service/gpu_jpeg_decode_accelerator.h"
+
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/run_loop.h"
-#include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h"
#include "base/threading/thread.h"
-#include "gpu/ipc/service/gpu_channel.h"
-#include "media/gpu/ipc/common/media_messages.h"
-#include "testing/gmock/include/gmock/gmock.h"
+#include "media/base/media_switches.h"
+#include "mojo/public/cpp/system/platform_handle.h"
+#include "services/service_manager/public/cpp/bind_source_info.h"
#include "testing/gtest/include/gtest/gtest.h"
-using testing::_;
-using testing::SaveArg;
-using testing::InvokeWithoutArgs;
-using testing::Return;
-
namespace media {
-static const size_t kOutputFrameSizeInBytes = 1024;
-static const gfx::Size kDummyFrameCodedSize(10, 10);
-
-class MockFilteredSender : public gpu::FilteredSender {
- public:
- MOCK_METHOD1(AddFilter, void(IPC::MessageFilter*));
- MOCK_METHOD1(RemoveFilter, void(IPC::MessageFilter*));
- MOCK_METHOD1(Send, bool(IPC::Message*));
-};
+static const int32_t kArbitraryBitstreamBufferId = 123;
-class MockJpegDecodeAccelerator : public media::JpegDecodeAccelerator {
- public:
- MOCK_METHOD1(Initialize, bool(Client*));
- MOCK_METHOD2(Decode,
- void(const BitstreamBuffer&,
- const scoped_refptr<media::VideoFrame>&));
- MOCK_METHOD0(IsSupported, bool());
-};
-
-// Test fixture for the unit that is created via the constructor of
+// Test fixture for the unit that is created via the mojom interface for
// class GpuJpegDecodeAccelerator. Uses a FakeJpegDecodeAccelerator to
// simulate the actual decoding without the need for special hardware.
class GpuJpegDecodeAcceleratorTest : public ::testing::Test {
@@ -48,36 +27,20 @@ class GpuJpegDecodeAcceleratorTest : public ::testing::Test {
~GpuJpegDecodeAcceleratorTest() override{};
void SetUp() override {
- output_frame_memory_.CreateAndMapAnonymous(kOutputFrameSizeInBytes);
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kUseFakeJpegDecodeAccelerator);
io_thread_.Start();
- std::vector<GpuJpegDecodeAcceleratorFactoryProvider::CreateAcceleratorCB>
- accelerator_factory_functions;
- accelerator_factory_functions.push_back(
- base::Bind(&GpuJpegDecodeAcceleratorTest::GetMockJpegDecodeAccelerator,
- base::Unretained(this)));
- system_under_test_ = base::MakeUnique<GpuJpegDecodeAccelerator>(
- &gpu_channel_, io_thread_.task_runner(), accelerator_factory_functions);
}
- MOCK_METHOD1(GetMockJpegDecodeAccelerator,
- std::unique_ptr<JpegDecodeAccelerator>(
- scoped_refptr<base::SingleThreadTaskRunner>));
-
- void SendStubFrame(IPC::MessageFilter* message_filter, int32_t route_id) {
- AcceleratedJpegDecoderMsg_Decode_Params decode_params;
- decode_params.output_video_frame_handle = output_frame_memory_.handle();
- decode_params.output_buffer_size =
- static_cast<uint32_t>(kOutputFrameSizeInBytes);
- decode_params.coded_size = kDummyFrameCodedSize;
- AcceleratedJpegDecoderMsg_Decode message(route_id, decode_params);
- message_filter->OnMessageReceived(message);
+ void OnDecodeAck(const base::Closure& continuation,
+ int32_t bitstream_buffer_id,
+ mojom::Error error) {
+ EXPECT_EQ(kArbitraryBitstreamBufferId, bitstream_buffer_id);
+ continuation.Run();
}
protected:
base::Thread io_thread_;
- MockFilteredSender gpu_channel_;
- std::unique_ptr<GpuJpegDecodeAccelerator> system_under_test_;
- base::SharedMemory output_frame_memory_;
private:
// This is required to allow base::ThreadTaskRunnerHandle::Get() from the
@@ -85,48 +48,45 @@ class GpuJpegDecodeAcceleratorTest : public ::testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_;
};
-// Tests that the communication for decoding a frame between the caller of
-// IPC:MessageFilter and the media::JpegDecodeAccelerator works as expected.
-TEST_F(GpuJpegDecodeAcceleratorTest, DecodeFrameCallArrivesAtDecoder) {
- static const int32_t kArbitraryRouteId = 123;
- auto io_task_runner = io_thread_.task_runner();
- auto main_task_runner = base::ThreadTaskRunnerHandle::Get();
- auto decoder = base::MakeUnique<MockJpegDecodeAccelerator>();
- auto* decoder_ptr = decoder.get();
- ON_CALL(*decoder, Initialize(_)).WillByDefault(Return(true));
-
- IPC::MessageFilter* message_filter = nullptr;
- EXPECT_CALL(*this, GetMockJpegDecodeAccelerator(_))
- .WillOnce(InvokeWithoutArgs([&decoder]() { return std::move(decoder); }));
- EXPECT_CALL(gpu_channel_, AddFilter(_)).WillOnce(SaveArg<0>(&message_filter));
+TEST_F(GpuJpegDecodeAcceleratorTest, InitializeAndDecode) {
+ mojom::GpuJpegDecodeAcceleratorPtr jpeg_decoder_;
+ GpuJpegDecodeAccelerator::Create(io_thread_.task_runner(),
+ service_manager::BindSourceInfo(),
+ mojo::MakeRequest(&jpeg_decoder_));
+
+ bool succeeded = false;
+ jpeg_decoder_->Initialize(&succeeded);
+ EXPECT_TRUE(succeeded);
+
+ const size_t kInputBufferSizeInBytes = 512;
+ const size_t kOutputFrameSizeInBytes = 1024;
+ const gfx::Size kDummyFrameCodedSize(10, 10);
+ const char kKeyId[] = "key id";
+ const char kIv[] = "0123456789abcdef";
+ std::vector<SubsampleEntry> subsamples;
+ subsamples.push_back(SubsampleEntry(10, 5));
+ subsamples.push_back(SubsampleEntry(15, 7));
+
base::RunLoop run_loop;
- auto response_cb = base::Bind(
- [](base::RunLoop* run_loop,
- scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
- bool succeeded) {
- EXPECT_TRUE(succeeded);
- if (main_task_runner->BelongsToCurrentThread() == false) {
- DLOG(INFO) << "Response arrived on thread other than main thread.";
- main_task_runner->PostTask(FROM_HERE, run_loop->QuitClosure());
- return;
- }
- run_loop->Quit();
- },
- &run_loop, main_task_runner);
- system_under_test_->AddClient(kArbitraryRouteId, response_cb);
+ mojo::ScopedSharedBufferHandle input_buffer_handle =
+ mojo::SharedBufferHandle::Create(kInputBufferSizeInBytes);
+ mojom::BitstreamBufferPtr buffer = mojom::BitstreamBuffer::New();
+ buffer->id = kArbitraryBitstreamBufferId;
+ buffer->memory_handle = std::move(input_buffer_handle);
+ buffer->size = kInputBufferSizeInBytes;
+ buffer->key_id = kKeyId;
+ buffer->iv = kIv;
+ buffer->subsamples = subsamples;
+
+ mojo::ScopedSharedBufferHandle output_frame_handle =
+ mojo::SharedBufferHandle::Create(kOutputFrameSizeInBytes);
+
+ jpeg_decoder_->Decode(
+ std::move(buffer), kDummyFrameCodedSize, std::move(output_frame_handle),
+ base::checked_cast<uint32_t>(kOutputFrameSizeInBytes),
+ base::Bind(&GpuJpegDecodeAcceleratorTest::OnDecodeAck,
+ base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
- ASSERT_TRUE(message_filter);
-
- // Send a AcceleratedJpegDecoderMsg_Decode to the |message_filter| on the
- // io_thread.
- base::RunLoop run_loop2;
- EXPECT_CALL(*decoder_ptr, Decode(_, _));
- io_task_runner->PostTaskAndReply(
- FROM_HERE,
- base::Bind(&GpuJpegDecodeAcceleratorTest::SendStubFrame,
- base::Unretained(this), message_filter, kArbitraryRouteId),
- run_loop2.QuitClosure());
- run_loop2.Run();
}
} // namespace media
« 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