OLD | NEW |
(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/mojo/service/gpu_jpeg_decode_accelerator.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" |
| 9 #include "base/run_loop.h" |
| 10 #include "base/test/scoped_task_environment.h" |
| 11 #include "base/threading/thread.h" |
| 12 #include "media/base/media_switches.h" |
| 13 #include "mojo/public/cpp/system/platform_handle.h" |
| 14 #include "services/service_manager/public/cpp/bind_source_info.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 |
| 17 namespace media { |
| 18 |
| 19 static const int32_t kArbitraryBitstreamBufferId = 123; |
| 20 |
| 21 // Test fixture for the unit that is created via the mojom interface for |
| 22 // class GpuJpegDecodeAccelerator. Uses a FakeJpegDecodeAccelerator to |
| 23 // simulate the actual decoding without the need for special hardware. |
| 24 class GpuJpegDecodeAcceleratorTest : public ::testing::Test { |
| 25 public: |
| 26 GpuJpegDecodeAcceleratorTest() : io_thread_("io") {} |
| 27 ~GpuJpegDecodeAcceleratorTest() override{}; |
| 28 |
| 29 void SetUp() override { |
| 30 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 31 switches::kUseFakeJpegDecodeAccelerator); |
| 32 io_thread_.Start(); |
| 33 } |
| 34 |
| 35 void OnDecodeAck(const base::Closure& continuation, |
| 36 int32_t bitstream_buffer_id, |
| 37 mojom::Error error) { |
| 38 EXPECT_EQ(kArbitraryBitstreamBufferId, bitstream_buffer_id); |
| 39 continuation.Run(); |
| 40 } |
| 41 |
| 42 protected: |
| 43 base::Thread io_thread_; |
| 44 |
| 45 private: |
| 46 // This is required to allow base::ThreadTaskRunnerHandle::Get() from the |
| 47 // test execution thread. |
| 48 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 49 }; |
| 50 |
| 51 TEST_F(GpuJpegDecodeAcceleratorTest, InitializeAndDecode) { |
| 52 mojom::GpuJpegDecodeAcceleratorPtr jpeg_decoder_; |
| 53 GpuJpegDecodeAccelerator::Create(io_thread_.task_runner(), |
| 54 service_manager::BindSourceInfo(), |
| 55 mojo::MakeRequest(&jpeg_decoder_)); |
| 56 |
| 57 bool succeeded = false; |
| 58 jpeg_decoder_->Initialize(&succeeded); |
| 59 EXPECT_TRUE(succeeded); |
| 60 |
| 61 const size_t kInputBufferSizeInBytes = 512; |
| 62 const size_t kOutputFrameSizeInBytes = 1024; |
| 63 const gfx::Size kDummyFrameCodedSize(10, 10); |
| 64 const char kKeyId[] = "key id"; |
| 65 const char kIv[] = "0123456789abcdef"; |
| 66 std::vector<SubsampleEntry> subsamples; |
| 67 subsamples.push_back(SubsampleEntry(10, 5)); |
| 68 subsamples.push_back(SubsampleEntry(15, 7)); |
| 69 |
| 70 base::RunLoop run_loop; |
| 71 mojo::ScopedSharedBufferHandle input_buffer_handle = |
| 72 mojo::SharedBufferHandle::Create(kInputBufferSizeInBytes); |
| 73 mojom::BitstreamBufferPtr buffer = mojom::BitstreamBuffer::New(); |
| 74 buffer->id = kArbitraryBitstreamBufferId; |
| 75 buffer->memory_handle = std::move(input_buffer_handle); |
| 76 buffer->size = kInputBufferSizeInBytes; |
| 77 buffer->key_id = kKeyId; |
| 78 buffer->iv = kIv; |
| 79 buffer->subsamples = subsamples; |
| 80 |
| 81 mojo::ScopedSharedBufferHandle output_frame_handle = |
| 82 mojo::SharedBufferHandle::Create(kOutputFrameSizeInBytes); |
| 83 |
| 84 jpeg_decoder_->Decode( |
| 85 std::move(buffer), kDummyFrameCodedSize, std::move(output_frame_handle), |
| 86 base::checked_cast<uint32_t>(kOutputFrameSizeInBytes), |
| 87 base::Bind(&GpuJpegDecodeAcceleratorTest::OnDecodeAck, |
| 88 base::Unretained(this), run_loop.QuitClosure())); |
| 89 run_loop.Run(); |
| 90 } |
| 91 |
| 92 } // namespace media |
OLD | NEW |