hevc_unittest.cc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "media/formats/mp4/hevc.h"
  5. #include "media/formats/mp4/nalu_test_helper.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace media {
  8. namespace mp4 {
  9. TEST(HEVCAnalyzeAnnexBTest, ValidAnnexBConstructs) {
  10. struct {
  11. const char* case_string;
  12. const bool is_keyframe;
  13. } test_cases[] = {
  14. {"I", true}, {"I I I I", true}, {"AUD I", true},
  15. {"AUD SPS I", true}, {"I EOS", true}, {"I EOS EOB", true},
  16. {"I EOB", true}, {"P", false}, {"P P P P", false},
  17. {"AUD SPS P", false}, {"AUD,I", true}, {"AUD,SPS,I", true},
  18. };
  19. for (size_t i = 0; i < std::size(test_cases); ++i) {
  20. std::vector<uint8_t> buf;
  21. std::vector<SubsampleEntry> subsamples;
  22. HevcStringToAnnexB(test_cases[i].case_string, &buf, nullptr);
  23. BitstreamConverter::AnalysisResult expected;
  24. expected.is_conformant = true;
  25. expected.is_keyframe = test_cases[i].is_keyframe;
  26. EXPECT_PRED2(AnalysesMatch,
  27. HEVC::AnalyzeAnnexB(buf.data(), buf.size(), subsamples),
  28. expected)
  29. << "'" << test_cases[i].case_string << "' failed";
  30. }
  31. }
  32. TEST(HEVCAnalyzeAnnexBTest, InvalidAnnexBConstructs) {
  33. struct {
  34. const char* case_string;
  35. const absl::optional<bool> is_keyframe;
  36. } test_cases[] = {
  37. // For these cases, lack of conformance is determined before detecting any
  38. // IDR or non-IDR slices, so the non-conformant frames' keyframe analysis
  39. // reports absl::nullopt (which means undetermined analysis result).
  40. {"AUD", absl::nullopt}, // No VCL present.
  41. {"AUD,SPS", absl::nullopt}, // No VCL present.
  42. {"SPS AUD I", absl::nullopt}, // Parameter sets must come after AUD.
  43. {"EOS", absl::nullopt}, // EOS must come after a VCL.
  44. {"EOB", absl::nullopt}, // EOB must come after a VCL.
  45. // For these cases, IDR slice is first VCL and is detected before
  46. // conformance failure, so the non-conformant frame is reported as a
  47. // keyframe.
  48. {"I EOB EOS", true}, // EOS must come before EOB.
  49. {"I SPS", true}, // SPS must come before first VCL.
  50. // For this case, P slice is first VCL and is detected before conformance
  51. // failure, so the non-conformant frame is reported as a non-keyframe.
  52. {"P SPS P",
  53. false}, // SPS after first VCL would indicate a new access unit.
  54. };
  55. BitstreamConverter::AnalysisResult expected;
  56. expected.is_conformant = false;
  57. for (size_t i = 0; i < std::size(test_cases); ++i) {
  58. std::vector<uint8_t> buf;
  59. std::vector<SubsampleEntry> subsamples;
  60. HevcStringToAnnexB(test_cases[i].case_string, &buf, nullptr);
  61. expected.is_keyframe = test_cases[i].is_keyframe;
  62. EXPECT_PRED2(AnalysesMatch,
  63. HEVC::AnalyzeAnnexB(buf.data(), buf.size(), subsamples),
  64. expected)
  65. << "'" << test_cases[i].case_string << "' failed";
  66. }
  67. }
  68. } // namespace mp4
  69. } // namespace media