~phablet-team/aethercast/fix-for-microsoft-dongle

« back to all changes in this revision

Viewing changes to tests/mcs/video/videoformat_tests.cpp

Add hardware encoding and video streaming support.

The hardware encoding is currently only for Android 5.x based devices. On all others encoding will simply not work. The streaming part of aethercast (MPEGTS packetizing, RTP sending) as based on some code from Android.

Approved by PS Jenkins bot, Thomas Voß, Jim Hodapp.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2016 Canonical, Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 */
 
17
 
 
18
#include <gtest/gtest.h>
 
19
 
 
20
#include "mcs/video/videoformat.h"
 
21
 
 
22
namespace {
 
23
template<typename T>
 
24
void ExtractAndVerifyRateResolution(T rr, int width, int height, int framerate) {
 
25
    auto format = wds::H264VideoFormat{wds::CBP, wds::k3_1, rr};
 
26
    auto result = mcs::video::ExtractRateAndResolution(format);
 
27
    EXPECT_EQ(width, result.width);
 
28
    EXPECT_EQ(height, result.height);
 
29
    EXPECT_EQ(framerate, result.framerate);
 
30
}
 
31
}
 
32
 
 
33
TEST(VideoFormat, ExtractRateAndResolution) {
 
34
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA640x480p60, 640, 480, 60);
 
35
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA720x480p60, 720, 480, 60);
 
36
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA720x480i60, 720, 480, 60);
 
37
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA720x576p50, 720, 576, 50);
 
38
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA720x576i50, 720, 576, 50);
 
39
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1280x720p30, 1280, 720, 30);
 
40
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1280x720p60, 1280, 720, 60);
 
41
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080p30, 1920, 1080, 30);
 
42
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080p60, 1920, 1080, 60);
 
43
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080i60, 1920, 1080, 60);
 
44
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1280x720p25, 1280, 720, 25);
 
45
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1280x720p50, 1280, 720, 50);
 
46
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080p25, 1920, 1080, 25);
 
47
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080p50, 1920, 1080, 50);
 
48
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080i50, 1920, 1080, 50);
 
49
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1280x720p24, 1280, 720, 24);
 
50
    ExtractAndVerifyRateResolution<wds::CEARatesAndResolutions>(wds::CEA1920x1080p24, 1920, 1080, 24);
 
51
 
 
52
#if 0
 
53
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA800x600p30, 800, 600, 30);
 
54
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA800x600p60, 800, 600, 60);
 
55
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1024x768p30, 1024, 768, 30);
 
56
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1024x768p60, 1024, 768, 60);
 
57
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1152x864p30, 1152, 864, 30);
 
58
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1152x864p60, 1152, 864, 60);
 
59
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x768p30, 1280, 768, 30);
 
60
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x768p60, 1280, 768, 60);
 
61
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x800p30, 1280, 800, 30);
 
62
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x800p60, 1280, 800, 60);
 
63
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1360x768p30, 1360, 768, 30);
 
64
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1360x768p60, 1360, 768, 60);
 
65
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1366x768p30, 1366, 768, 30);
 
66
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1366x768p60, 1366, 768, 60);
 
67
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x1024p30, 1280, 1024, 30);
 
68
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1280x1024p60, 1280, 1024, 30);
 
69
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1400x1050p30, 1400, 1050, 30);
 
70
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1400x1050p60, 1400, 1050, 30);
 
71
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1440x900p30, 1440, 900, 30);
 
72
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1440x900p60, 1440, 900, 60);
 
73
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1600x900p30, 1600, 900, 30);
 
74
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1600x900p60, 1600, 900, 30);
 
75
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1600x1200p30, 1600, 1200, 30);
 
76
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1600x1200p60, 1600, 1200, 60);
 
77
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1680x1024p30, 1680, 1024, 30);
 
78
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1680x1024p60, 1680, 1024, 60);
 
79
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1680x1050p30, 1680, 1050, 30);
 
80
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1680x1050p60, 1680, 1050, 60);
 
81
    ExtractAndVerifyRateResolution<wds::VESARatesAndResolutions>(wds::VESA1920x1200p30, 1920, 1200, 30);
 
82
 
 
83
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH800x480p30, 800, 480, 30);
 
84
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH800x480p60, 800, 480, 60);
 
85
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH854x480p30, 854, 480, 30);
 
86
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH854x480p60, 854, 480, 60);
 
87
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH864x480p30, 864, 480, 30);
 
88
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH864x480p60, 864, 480, 60);
 
89
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH640x360p30, 640, 360, 30);
 
90
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH640x360p60, 640, 360, 60);
 
91
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH960x540p30, 960, 540, 30);
 
92
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH960x540p60, 960, 540, 60);
 
93
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH848x480p30, 848, 480, 30);
 
94
    ExtractAndVerifyRateResolution<wds::HHRatesAndResolutions>(wds::HH848x480p60, 848, 480, 60);
 
95
#endif
 
96
}
 
97
 
 
98
TEST(VideoFormat, ExtractH264Profile) {
 
99
    EXPECT_EQ("constrained-baseline", mcs::video::ExtractH264Profile(wds::H264VideoFormat{wds::CBP, wds::k3_1, wds::CEA640x480p60}));
 
100
    EXPECT_EQ("high", mcs::video::ExtractH264Profile(wds::H264VideoFormat{wds::CHP, wds::k3_1, wds::CEA640x480p60}));
 
101
}
 
102
 
 
103
TEST(VideoFormat, ExtractH264Level) {
 
104
    EXPECT_EQ("3.1", mcs::video::ExtractH264Level(wds::H264VideoFormat{wds::CBP, wds::k3_1, wds::CEA640x480p60}));
 
105
    EXPECT_EQ("3.2", mcs::video::ExtractH264Level(wds::H264VideoFormat{wds::CBP, wds::k3_2, wds::CEA640x480p60}));
 
106
    EXPECT_EQ("4", mcs::video::ExtractH264Level(wds::H264VideoFormat{wds::CBP, wds::k4, wds::CEA640x480p60}));
 
107
    EXPECT_EQ("4.1", mcs::video::ExtractH264Level(wds::H264VideoFormat{wds::CBP, wds::k4_1, wds::CEA640x480p60}));
 
108
    EXPECT_EQ("4.2", mcs::video::ExtractH264Level(wds::H264VideoFormat{wds::CBP, wds::k4_2, wds::CEA640x480p60}));
 
109
}
 
110
 
 
111
TEST(VideoFormat, ExtractProfileLevel) {
 
112
    int profile = 0, level = 0, constraint = 0;
 
113
 
 
114
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CBP, wds::k3_1, wds::CEA640x480p60},
 
115
                                    &profile, &level, &constraint);
 
116
    EXPECT_EQ(66, profile);
 
117
    EXPECT_EQ(0xc0, constraint);
 
118
    EXPECT_EQ(31, level);
 
119
 
 
120
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CBP, wds::k3_2, wds::CEA640x480p60},
 
121
                                    &profile, &level, &constraint);
 
122
    EXPECT_EQ(66, profile);
 
123
    EXPECT_EQ(0xc0, constraint);
 
124
    EXPECT_EQ(32, level);
 
125
 
 
126
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CBP, wds::k4, wds::CEA640x480p60},
 
127
                                    &profile, &level, &constraint);
 
128
    EXPECT_EQ(66, profile);
 
129
    EXPECT_EQ(0xc0, constraint);
 
130
    EXPECT_EQ(40, level);
 
131
 
 
132
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CBP, wds::k4_1, wds::CEA640x480p60},
 
133
                                    &profile, &level, &constraint);
 
134
    EXPECT_EQ(66, profile);
 
135
    EXPECT_EQ(0xc0, constraint);
 
136
    EXPECT_EQ(41, level);
 
137
 
 
138
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CBP, wds::k4_2, wds::CEA640x480p60},
 
139
                                    &profile, &level, &constraint);
 
140
    EXPECT_EQ(66, profile);
 
141
    EXPECT_EQ(0xc0, constraint);
 
142
    EXPECT_EQ(42, level);
 
143
 
 
144
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CHP, wds::k3_1, wds::CEA640x480p60},
 
145
                                    &profile, &level, &constraint);
 
146
    EXPECT_EQ(100, profile);
 
147
    EXPECT_EQ(0x0c, constraint);
 
148
    EXPECT_EQ(31, level);
 
149
 
 
150
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CHP, wds::k3_2, wds::CEA640x480p60},
 
151
                                    &profile, &level, &constraint);
 
152
    EXPECT_EQ(100, profile);
 
153
    EXPECT_EQ(0x0c, constraint);
 
154
    EXPECT_EQ(32, level);
 
155
 
 
156
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CHP, wds::k4, wds::CEA640x480p60},
 
157
                                    &profile, &level, &constraint);
 
158
    EXPECT_EQ(100, profile);
 
159
    EXPECT_EQ(0x0c, constraint);
 
160
    EXPECT_EQ(40, level);
 
161
 
 
162
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CHP, wds::k4_1, wds::CEA640x480p60},
 
163
                                    &profile, &level, &constraint);
 
164
    EXPECT_EQ(100, profile);
 
165
    EXPECT_EQ(0x0c, constraint);
 
166
    EXPECT_EQ(41, level);
 
167
 
 
168
    mcs::video::ExtractProfileLevel(wds::H264VideoFormat{wds::CHP, wds::k4_2, wds::CEA640x480p60},
 
169
                                    &profile, &level, &constraint);
 
170
    EXPECT_EQ(100, profile);
 
171
    EXPECT_EQ(0x0c, constraint);
 
172
    EXPECT_EQ(42, level);
 
173
}