blob: 1131288f26bab70ea5de0c94fbc893d72c021d97 [file] [log] [blame]
Sergey Silkin0e42cf72021-03-15 09:12:571/*
2 * Copyright (c) 2021 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 "modules/video_coding/utility/qp_parser.h"
12
13#include <stddef.h>
14
15#include "test/gtest.h"
16
17namespace webrtc {
18
19namespace {
20// ffmpeg -s 16x16 -f rawvideo -pix_fmt rgb24 -r 30 -i /dev/zero -c:v libvpx
21// -qmin 20 -qmax 20 -crf 20 -frames:v 1 -y out.ivf
22const uint8_t kCodedFrameVp8Qp25[] = {
23 0x10, 0x02, 0x00, 0x9d, 0x01, 0x2a, 0x10, 0x00, 0x10, 0x00,
24 0x02, 0x47, 0x08, 0x85, 0x85, 0x88, 0x85, 0x84, 0x88, 0x0c,
25 0x82, 0x00, 0x0c, 0x0d, 0x60, 0x00, 0xfe, 0xfc, 0x5c, 0xd0};
26
27// ffmpeg -s 16x16 -f rawvideo -pix_fmt rgb24 -r 30 -i /dev/zero -c:v libvpx-vp9
28// -qmin 24 -qmax 24 -crf 24 -frames:v 1 -y out.ivf
29const uint8_t kCodedFrameVp9Qp96[] = {
30 0xa2, 0x49, 0x83, 0x42, 0xe0, 0x00, 0xf0, 0x00, 0xf6, 0x00,
31 0x38, 0x24, 0x1c, 0x18, 0xc0, 0x00, 0x00, 0x30, 0x70, 0x00,
32 0x00, 0x4a, 0xa7, 0xff, 0xfc, 0xb9, 0x01, 0xbf, 0xff, 0xff,
33 0x97, 0x20, 0xdb, 0xff, 0xff, 0xcb, 0x90, 0x5d, 0x40};
34
35// ffmpeg -s 16x16 -f rawvideo -pix_fmt yuv420p -r 30 -i /dev/zero -c:v libx264
36// -qmin 38 -qmax 38 -crf 38 -profile:v baseline -frames:v 2 -y out.264
37const uint8_t kCodedFrameH264SpsPpsIdrQp38[] = {
38 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x0a, 0xd9, 0x1e, 0x84,
39 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c,
40 0x48, 0x99, 0x20, 0x00, 0x00, 0x00, 0x01, 0x68, 0xcb, 0x80, 0xc4,
41 0xb2, 0x00, 0x00, 0x01, 0x65, 0x88, 0x84, 0xf1, 0x18, 0xa0, 0x00,
42 0x20, 0x5b, 0x1c, 0x00, 0x04, 0x07, 0xe3, 0x80, 0x00, 0x80, 0xfe};
43
44const uint8_t kCodedFrameH264SpsPpsIdrQp49[] = {
45 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0xc0, 0x0a, 0xd9, 0x1e, 0x84,
46 0x00, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x03, 0x00, 0xf0, 0x3c,
47 0x48, 0x99, 0x20, 0x00, 0x00, 0x00, 0x01, 0x68, 0xcb, 0x80, 0x5d,
48 0x2c, 0x80, 0x00, 0x00, 0x01, 0x65, 0x88, 0x84, 0xf1, 0x18, 0xa0,
49 0x00, 0x5e, 0x38, 0x00, 0x08, 0x03, 0xc7, 0x00, 0x01, 0x00, 0x7c};
50
51const uint8_t kCodedFrameH264InterSliceQpDelta0[] = {0x00, 0x00, 0x00, 0x01,
52 0x41, 0x9a, 0x39, 0xea};
53
54} // namespace
55
56TEST(QpParserTest, ParseQpVp8) {
57 QpParser parser;
58 absl::optional<uint32_t> qp = parser.Parse(
59 kVideoCodecVP8, 0, kCodedFrameVp8Qp25, sizeof(kCodedFrameVp8Qp25));
60 EXPECT_EQ(qp, 25u);
61}
62
63TEST(QpParserTest, ParseQpVp9) {
64 QpParser parser;
65 absl::optional<uint32_t> qp = parser.Parse(
66 kVideoCodecVP9, 0, kCodedFrameVp9Qp96, sizeof(kCodedFrameVp9Qp96));
67 EXPECT_EQ(qp, 96u);
68}
69
70TEST(QpParserTest, ParseQpH264) {
71 QpParser parser;
72 absl::optional<uint32_t> qp = parser.Parse(
73 VideoCodecType::kVideoCodecH264, 0, kCodedFrameH264SpsPpsIdrQp38,
74 sizeof(kCodedFrameH264SpsPpsIdrQp38));
75 EXPECT_EQ(qp, 38u);
76
77 qp = parser.Parse(kVideoCodecH264, 1, kCodedFrameH264SpsPpsIdrQp49,
78 sizeof(kCodedFrameH264SpsPpsIdrQp49));
79 EXPECT_EQ(qp, 49u);
80
81 qp = parser.Parse(kVideoCodecH264, 0, kCodedFrameH264InterSliceQpDelta0,
82 sizeof(kCodedFrameH264InterSliceQpDelta0));
83 EXPECT_EQ(qp, 38u);
84
85 qp = parser.Parse(kVideoCodecH264, 1, kCodedFrameH264InterSliceQpDelta0,
86 sizeof(kCodedFrameH264InterSliceQpDelta0));
87 EXPECT_EQ(qp, 49u);
88}
89
90TEST(QpParserTest, ParseQpUnsupportedCodecType) {
91 QpParser parser;
92 absl::optional<uint32_t> qp = parser.Parse(
93 kVideoCodecGeneric, 0, kCodedFrameVp8Qp25, sizeof(kCodedFrameVp8Qp25));
94 EXPECT_FALSE(qp.has_value());
95}
96
97TEST(QpParserTest, ParseQpNullData) {
98 QpParser parser;
99 absl::optional<uint32_t> qp = parser.Parse(kVideoCodecVP8, 0, nullptr, 100);
100 EXPECT_FALSE(qp.has_value());
101}
102
103TEST(QpParserTest, ParseQpEmptyData) {
104 QpParser parser;
105 absl::optional<uint32_t> qp =
106 parser.Parse(kVideoCodecVP8, 0, kCodedFrameVp8Qp25, 0);
107 EXPECT_FALSE(qp.has_value());
108}
109
110TEST(QpParserTest, ParseQpSpatialIdxExceedsMax) {
111 QpParser parser;
112 absl::optional<uint32_t> qp =
113 parser.Parse(kVideoCodecVP8, kMaxSimulcastStreams, kCodedFrameVp8Qp25,
114 sizeof(kCodedFrameVp8Qp25));
115 EXPECT_FALSE(qp.has_value());
116}
117
118} // namespace webrtc