2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License along
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <gtest/gtest.h>
20
#include <mcs/video/h264analyzer.h>
22
TEST(H264Analyzer, DetectSPSCorrect) {
23
mcs::video::H264Analyzer analyzer;
25
uint8_t sps[] {0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x0a, 0xf8, 0x41, 0xa2};
27
auto result = analyzer.Process(sps, 11);
29
EXPECT_EQ(1, result.units);
30
EXPECT_EQ(0, result.slices);
31
EXPECT_EQ(0, result.idr_frames);
32
EXPECT_EQ(1, result.sps);
33
EXPECT_EQ(0, result.pps);
37
TEST(H264Analyzer, DetectPPSCorrect) {
38
mcs::video::H264Analyzer analyzer;
40
uint8_t pps[] { 0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80 };
42
auto result = analyzer.Process(pps, 8);
44
EXPECT_EQ(1, result.units);
45
EXPECT_EQ(0, result.slices);
46
EXPECT_EQ(0, result.idr_frames);
47
EXPECT_EQ(0, result.sps);
48
EXPECT_EQ(1, result.pps);
51
TEST(H264Analyzer, DetectMultipleUnits) {
52
mcs::video::H264Analyzer analyzer;
54
uint8_t multiple_units[] {
55
0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x0a, 0xf8, 0x41, 0xa2,
56
0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80
59
auto result = analyzer.Process(multiple_units, 19);
61
EXPECT_EQ(2, result.units);
62
EXPECT_EQ(0, result.slices);
63
EXPECT_EQ(0, result.idr_frames);
64
EXPECT_EQ(1, result.sps);
65
EXPECT_EQ(1, result.pps);
68
TEST(H264Analyzer, CollectStatistics) {
69
mcs::video::H264Analyzer analyzer(true);
71
uint8_t multiple_units[] {
72
0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x0a, 0xf8, 0x41, 0xa2,
73
0x00, 0x00, 0x00, 0x01, 0x68, 0xce, 0x38, 0x80
76
analyzer.Process(multiple_units, 19);
77
analyzer.Process(multiple_units, 19);
78
analyzer.Process(multiple_units, 19);
80
auto statistics = analyzer.Statistics();
82
EXPECT_EQ(6, statistics.units);
83
EXPECT_EQ(0, statistics.slices);
84
EXPECT_EQ(0, statistics.idr_frames);
85
EXPECT_EQ(3, statistics.sps);
86
EXPECT_EQ(3, statistics.pps);