• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <memory>
12 #include <string>
13 #include <tuple>
14 #include <vector>
15 
16 #include "api/test/create_videocodec_test_fixture.h"
17 #include "media/base/media_constants.h"
18 #include "modules/video_coding/codecs/test/android_codec_factory_helper.h"
19 #include "modules/video_coding/codecs/test/videocodec_test_fixture_impl.h"
20 #include "test/gtest.h"
21 #include "test/testsupport/file_utils.h"
22 
23 namespace webrtc {
24 namespace test {
25 
26 namespace {
27 const int kForemanNumFrames = 300;
28 const int kForemanFramerateFps = 30;
29 
CreateConfig()30 VideoCodecTestFixture::Config CreateConfig() {
31   VideoCodecTestFixture::Config config;
32   config.filename = "foreman_cif";
33   config.filepath = ResourcePath(config.filename, "yuv");
34   config.num_frames = kForemanNumFrames;
35   // In order to not overwhelm the OpenMAX buffers in the Android MediaCodec.
36   config.encode_in_real_time = true;
37   return config;
38 }
39 
CreateTestFixtureWithConfig(VideoCodecTestFixture::Config config)40 std::unique_ptr<VideoCodecTestFixture> CreateTestFixtureWithConfig(
41     VideoCodecTestFixture::Config config) {
42   InitializeAndroidObjects();  // Idempotent.
43   auto encoder_factory = CreateAndroidEncoderFactory();
44   auto decoder_factory = CreateAndroidDecoderFactory();
45   return CreateVideoCodecTestFixture(config, std::move(decoder_factory),
46                                      std::move(encoder_factory));
47 }
48 }  // namespace
49 
TEST(VideoCodecTestMediaCodec,ForemanCif500kbpsVp8)50 TEST(VideoCodecTestMediaCodec, ForemanCif500kbpsVp8) {
51   auto config = CreateConfig();
52   config.SetCodecSettings(cricket::kVp8CodecName, 1, 1, 1, false, false, false,
53                           352, 288);
54   auto fixture = CreateTestFixtureWithConfig(config);
55 
56   std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
57 
58   // The thresholds below may have to be tweaked to let even poor MediaCodec
59   // implementations pass. If this test fails on the bots, disable it and
60   // ping brandtr@.
61   std::vector<RateControlThresholds> rc_thresholds = {
62       {10, 1, 1, 0.1, 0.2, 0.1, 0, 1}};
63 
64   std::vector<QualityThresholds> quality_thresholds = {{36, 31, 0.92, 0.86}};
65 
66   fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
67 }
68 
TEST(VideoCodecTestMediaCodec,ForemanCif500kbpsH264CBP)69 TEST(VideoCodecTestMediaCodec, ForemanCif500kbpsH264CBP) {
70   auto config = CreateConfig();
71   const auto frame_checker =
72       std::make_unique<VideoCodecTestFixtureImpl::H264KeyframeChecker>();
73   config.encoded_frame_checker = frame_checker.get();
74   config.SetCodecSettings(cricket::kH264CodecName, 1, 1, 1, false, false, false,
75                           352, 288);
76   auto fixture = CreateTestFixtureWithConfig(config);
77 
78   std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
79 
80   // The thresholds below may have to be tweaked to let even poor MediaCodec
81   // implementations pass. If this test fails on the bots, disable it and
82   // ping brandtr@.
83   std::vector<RateControlThresholds> rc_thresholds = {
84       {10, 1, 1, 0.1, 0.2, 0.1, 0, 1}};
85 
86   std::vector<QualityThresholds> quality_thresholds = {{36, 31, 0.92, 0.86}};
87 
88   fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
89 }
90 
91 // TODO(brandtr): Enable this test when we have trybots/buildbots with
92 // HW encoders that support CHP.
TEST(VideoCodecTestMediaCodec,DISABLED_ForemanCif500kbpsH264CHP)93 TEST(VideoCodecTestMediaCodec, DISABLED_ForemanCif500kbpsH264CHP) {
94   auto config = CreateConfig();
95   const auto frame_checker =
96       std::make_unique<VideoCodecTestFixtureImpl::H264KeyframeChecker>();
97 
98   config.h264_codec_settings.profile = H264::kProfileConstrainedHigh;
99   config.encoded_frame_checker = frame_checker.get();
100   config.SetCodecSettings(cricket::kH264CodecName, 1, 1, 1, false, false, false,
101                           352, 288);
102   auto fixture = CreateTestFixtureWithConfig(config);
103 
104   std::vector<RateProfile> rate_profiles = {{500, kForemanFramerateFps, 0}};
105 
106   // The thresholds below may have to be tweaked to let even poor MediaCodec
107   // implementations pass. If this test fails on the bots, disable it and
108   // ping brandtr@.
109   std::vector<RateControlThresholds> rc_thresholds = {
110       {5, 1, 0, 0.1, 0.2, 0.1, 0, 1}};
111 
112   std::vector<QualityThresholds> quality_thresholds = {{37, 35, 0.93, 0.91}};
113 
114   fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
115 }
116 
TEST(VideoCodecTestMediaCodec,ForemanMixedRes100kbpsVp8H264)117 TEST(VideoCodecTestMediaCodec, ForemanMixedRes100kbpsVp8H264) {
118   auto config = CreateConfig();
119   const int kNumFrames = 30;
120   const std::vector<std::string> codecs = {cricket::kVp8CodecName,
121                                            cricket::kH264CodecName};
122   const std::vector<std::tuple<int, int>> resolutions = {
123       {128, 96}, {160, 120}, {176, 144}, {240, 136}, {320, 240}, {480, 272}};
124   const std::vector<RateProfile> rate_profiles = {
125       {100, kForemanFramerateFps, 0}};
126   const std::vector<QualityThresholds> quality_thresholds = {
127       {29, 26, 0.8, 0.75}};
128 
129   for (const auto& codec : codecs) {
130     for (const auto& resolution : resolutions) {
131       const int width = std::get<0>(resolution);
132       const int height = std::get<1>(resolution);
133       config.filename = std::string("foreman_") + std::to_string(width) + "x" +
134                         std::to_string(height);
135       config.filepath = ResourcePath(config.filename, "yuv");
136       config.num_frames = kNumFrames;
137       config.SetCodecSettings(codec, 1, 1, 1, false, false, false, width,
138                               height);
139 
140       auto fixture = CreateTestFixtureWithConfig(config);
141       fixture->RunTest(rate_profiles, nullptr /* rc_thresholds */,
142                        &quality_thresholds, nullptr /* bs_thresholds */);
143     }
144   }
145 }
146 
147 }  // namespace test
148 }  // namespace webrtc
149