test_utils.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2019 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. #ifndef MEDIA_GPU_VAAPI_TEST_UTILS_H_
  5. #define MEDIA_GPU_VAAPI_TEST_UTILS_H_
  6. #include <stddef.h>
  7. #include <stdint.h>
  8. #include <va/va.h>
  9. #include <string>
  10. #include "testing/gtest/include/gtest/gtest.h"
  11. #include "ui/gfx/geometry/size.h"
  12. namespace media {
  13. class ScopedVAImage;
  14. namespace vaapi_test_utils {
  15. struct TestParam {
  16. const char* test_name;
  17. const char* filename;
  18. };
  19. std::string TestParamToString(
  20. const testing::TestParamInfo<TestParam>& param_info);
  21. constexpr size_t kMaxNumberPlanes = std::size(VAImage().pitches);
  22. static_assert(kMaxNumberPlanes <= 3u, "The number of planes should be <= 3");
  23. static_assert(
  24. std::size(VAImage().pitches) == std::size(VAImage().offsets),
  25. "The number of VAImage pitches is not equal to the number of offsets");
  26. // A structure to hold generic image decodes in planar format.
  27. struct DecodedImage {
  28. uint32_t fourcc;
  29. uint32_t number_of_planes; // Can not be greater than kMaxNumberPlanes.
  30. gfx::Size size;
  31. struct {
  32. uint8_t* data;
  33. int stride;
  34. } planes[kMaxNumberPlanes];
  35. };
  36. // Takes a ScopedVAImage and returns a DecodedImage object that represents
  37. // the same decoded result.
  38. DecodedImage ScopedVAImageToDecodedImage(const ScopedVAImage* scoped_va_image);
  39. // Compares the result of sw decoding |reference_image| with |hw_decoded_image|
  40. // using SSIM. Returns true if all conversions work and SSIM is at least
  41. // |min_ssim|, or false otherwise. Note that |reference_image| must be given in
  42. // I420 format.
  43. bool CompareImages(const DecodedImage& reference_image,
  44. const DecodedImage& hw_decoded_image,
  45. double min_ssim = 0.995);
  46. } // namespace vaapi_test_utils
  47. } // namespace media
  48. #endif // MEDIA_GPU_VAAPI_TEST_UTILS_H_