1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61

ash / components / arc / mojom / video_accelerator_mojom_traits_unittest.cc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/components/arc/mojom/video_accelerator_mojom_traits.h"

#include <vector>

#include "ash/components/arc/mojom/video_common.mojom.h"
#include "media/base/video_frame_layout.h"
#include "media/base/video_types.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mojo {

namespace {
constexpr int kWidth = 640;
constexpr int kHeight = 480;
constexpr media::VideoPixelFormat kFormat = media::PIXEL_FORMAT_I420;
constexpr gfx::Size kCodedSize(kWidth, kHeight);
}  // namespace

TEST(VideoAcceleratorStructTraitsTest, ConvertVideoFrameLayout) {
  std::vector<media::ColorPlaneLayout> planes;
  planes.emplace_back(kWidth, 0, kWidth * kHeight);
  planes.emplace_back(kWidth / 2, kWidth * kHeight, kWidth * kHeight / 4);
  planes.emplace_back(kWidth / 2, kWidth * kHeight + kWidth * kHeight / 4,
                      kWidth * kHeight / 4);
  // Choose a non-default value.
  constexpr size_t buffer_addr_align = 128;
  constexpr uint64_t modifier = 0x1234;

  std::optional<media::VideoFrameLayout> layout =
      media::VideoFrameLayout::CreateWithPlanes(kFormat, kCodedSize, planes,
                                                buffer_addr_align, modifier);
  EXPECT_TRUE(layout);

  std::unique_ptr<media::VideoFrameLayout> input =
      std::make_unique<media::VideoFrameLayout>(*layout);
  std::unique_ptr<media::VideoFrameLayout> output;
  mojo::test::SerializeAndDeserialize<arc::mojom::VideoFrameLayout>(input,
                                                                    output);

  EXPECT_EQ(output->format(), kFormat);
  EXPECT_EQ(output->coded_size(), kCodedSize);
  EXPECT_EQ(output->planes(), planes);
  EXPECT_EQ(output->buffer_addr_align(), buffer_addr_align);
  EXPECT_EQ(output->modifier(), modifier);
}

TEST(VideoAcceleratorStructTraitsTest, ConvertNullVideoFrameLayout) {
  std::unique_ptr<media::VideoFrameLayout> input;
  std::unique_ptr<media::VideoFrameLayout> output;
  mojo::test::SerializeAndDeserialize<arc::mojom::VideoFrameLayout>(input,
                                                                    output);

  EXPECT_FALSE(output);
}

}  // namespace mojo