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 <vector>
13
14 #include "api/test/create_videocodec_test_fixture.h"
15 #include "media/base/media_constants.h"
16 #include "modules/video_coding/codecs/test/videocodec_test_fixture_impl.h"
17 #include "test/gtest.h"
18 #include "test/testsupport/file_utils.h"
19
20 namespace webrtc {
21 namespace test {
22
23 namespace {
24 // Codec settings.
25 const int kCifWidth = 352;
26 const int kCifHeight = 288;
27 const int kNumFrames = 100;
28
CreateConfig()29 VideoCodecTestFixture::Config CreateConfig() {
30 VideoCodecTestFixture::Config config;
31 config.filename = "foreman_cif";
32 config.filepath = ResourcePath(config.filename, "yuv");
33 config.num_frames = kNumFrames;
34 // Only allow encoder/decoder to use single core, for predictability.
35 config.use_single_core = true;
36 return config;
37 }
38 } // namespace
39
TEST(VideoCodecTestOpenH264,ConstantHighBitrate)40 TEST(VideoCodecTestOpenH264, ConstantHighBitrate) {
41 auto frame_checker =
42 std::make_unique<VideoCodecTestFixtureImpl::H264KeyframeChecker>();
43 auto config = CreateConfig();
44 config.SetCodecSettings(cricket::kH264CodecName, 1, 1, 1, false, true, false,
45 kCifWidth, kCifHeight);
46 config.encoded_frame_checker = frame_checker.get();
47 auto fixture = CreateVideoCodecTestFixture(config);
48
49 std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
50
51 std::vector<RateControlThresholds> rc_thresholds = {
52 {5, 1, 0, 0.1, 0.2, 0.1, 0, 1}};
53
54 std::vector<QualityThresholds> quality_thresholds = {{37, 35, 0.93, 0.91}};
55
56 fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds, nullptr);
57 }
58
59 // H264: Enable SingleNalUnit packetization mode. Encoder should split
60 // large frames into multiple slices and limit length of NAL units.
TEST(VideoCodecTestOpenH264,SingleNalUnit)61 TEST(VideoCodecTestOpenH264, SingleNalUnit) {
62 auto frame_checker =
63 std::make_unique<VideoCodecTestFixtureImpl::H264KeyframeChecker>();
64 auto config = CreateConfig();
65 config.h264_codec_settings.packetization_mode =
66 H264PacketizationMode::SingleNalUnit;
67 config.max_payload_size_bytes = 500;
68 config.SetCodecSettings(cricket::kH264CodecName, 1, 1, 1, false, true, false,
69 kCifWidth, kCifHeight);
70 config.encoded_frame_checker = frame_checker.get();
71 auto fixture = CreateVideoCodecTestFixture(config);
72
73 std::vector<RateProfile> rate_profiles = {{500, 30, 0}};
74
75 std::vector<RateControlThresholds> rc_thresholds = {
76 {5, 1, 0, 0.1, 0.2, 0.1, 0, 1}};
77
78 std::vector<QualityThresholds> quality_thresholds = {{37, 35, 0.93, 0.91}};
79
80 BitstreamThresholds bs_thresholds = {config.max_payload_size_bytes};
81
82 fixture->RunTest(rate_profiles, &rc_thresholds, &quality_thresholds,
83 &bs_thresholds);
84 }
85
86 } // namespace test
87 } // namespace webrtc
88