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 "mcs/video/videoformat.h"
19
#include "mcs/logger.h"
24
std::string ResolutionTypeToString(wds::ResolutionType type) {
38
std::string CEARatesAndResolutionsToString(wds::CEARatesAndResolutions type) {
40
case wds::CEA640x480p60:
42
case wds::CEA720x480p60:
44
case wds::CEA720x480i60:
46
case wds::CEA720x576p50:
48
case wds::CEA720x576i50:
50
case wds::CEA1280x720p30:
52
case wds::CEA1280x720p60:
54
case wds::CEA1920x1080p30:
55
return "1920x1080p30";
56
case wds::CEA1920x1080p60:
57
return "1920x1080p60";
58
case wds::CEA1920x1080i60:
59
return "1920x1080i60";
60
case wds::CEA1280x720p25:
62
case wds::CEA1280x720p50:
64
case wds::CEA1920x1080p25:
65
return "1920x1080p25";
66
case wds::CEA1920x1080p50:
67
return "1920x1080p50";
68
case wds::CEA1920x1080i50:
69
return "1920x1080i50";
70
case wds::CEA1280x720p24:
72
case wds::CEA1920x1080p24:
73
return "1920x1080p24";
80
std::string VESARatesAndResolutionsToString(wds::VESARatesAndResolutions type) {
82
case wds::VESA800x600p30:
84
case wds::VESA800x600p60:
86
case wds::VESA1024x768p30:
88
case wds::VESA1024x768p60:
90
case wds::VESA1152x864p30:
92
case wds::VESA1152x864p60:
94
case wds::VESA1280x768p30:
96
case wds::VESA1280x768p60:
98
case wds::VESA1280x800p30:
100
case wds::VESA1280x800p60:
101
return "1280x800p60";
102
case wds::VESA1360x768p30:
103
return "1360x768p30";
104
case wds::VESA1360x768p60:
105
return "1360x768p60";
106
case wds::VESA1366x768p30:
107
return "1366x768p30";
108
case wds::VESA1366x768p60:
109
return "1366x768p60";
110
case wds::VESA1280x1024p30:
111
return "1280x1024p30";
112
case wds::VESA1280x1024p60:
113
return "1280x1024p60";
114
case wds::VESA1400x1050p30:
115
return "1400x1050p30";
116
case wds::VESA1400x1050p60:
117
return "1400x1050p60";
118
case wds::VESA1440x900p30:
119
return "1440x900p30";
120
case wds::VESA1440x900p60:
121
return "1440x900p60";
122
case wds::VESA1600x900p30:
123
return "1600x900p30";
124
case wds::VESA1600x900p60:
125
return "1600x900p60";
126
case wds::VESA1600x1200p30:
127
return "1600x1200p30";
128
case wds::VESA1600x1200p60:
129
return "1600x1200p60";
130
case wds::VESA1680x1024p30:
131
return "1680x1024p30";
132
case wds::VESA1680x1024p60:
133
return "1680x1024p60";
134
case wds::VESA1680x1050p30:
135
return "1680x1050p30";
136
case wds::VESA1680x1050p60:
137
return "1680x1050p60";
138
case wds::VESA1920x1200p30:
139
return "1920x1200p30";
146
std::string HHRatesAndResolutionsToString(wds::HHRatesAndResolutions type) {
148
case wds::HH800x480p30:
150
case wds::HH800x480p60:
152
case wds::HH854x480p30:
154
case wds::HH854x480p60:
156
case wds::HH864x480p30:
158
case wds::HH864x480p60:
160
case wds::HH640x360p30:
162
case wds::HH640x360p60:
164
case wds::HH960x540p30:
166
case wds::HH960x540p60:
168
case wds::HH848x480p30:
170
case wds::HH848x480p60:
178
std::string LevelToString(wds::H264Level level) {
196
std::string ProfileToString(wds::H264Profile profile) {
208
void DumpVideoCodec(const wds::H264VideoCodec &codec) {
211
DEBUG(" profile: %s", ProfileToString(codec.profile));
212
DEBUG(" level: %s", LevelToString(codec.level));
214
DEBUG(" CEA resolutions: ");
215
for (i = wds::CEA640x480p60; i <= wds::CEA1920x1080p24; ++i)
216
if (codec.cea_rr.test(i))
217
DEBUG(" %s", CEARatesAndResolutionsToString((wds::CEARatesAndResolutions) i).c_str());
219
DEBUG(" VESA resolutions: ");
220
for (i = wds::VESA800x600p30; i <= wds::VESA1920x1200p30; ++i)
221
if (codec.vesa_rr.test(i))
222
DEBUG(" %s", VESARatesAndResolutionsToString((wds::VESARatesAndResolutions) i).c_str());
224
DEBUG(" HH resolutions: ");
225
for (i = wds::HH800x480p30; i <= wds::HH848x480p60; ++i)
226
if (codec.hh_rr.test(i))
227
DEBUG(" %s", HHRatesAndResolutionsToString((wds::HHRatesAndResolutions) i).c_str());
230
void DumpVideoFormat(const wds::H264VideoFormat &format) {
231
DEBUG(" profile: %s", ProfileToString(format.profile));
232
DEBUG(" level: %s", LevelToString(format.level));
233
DEBUG(" resolution type: %s", ResolutionTypeToString(format.type));
235
if (format.type == wds::CEA)
236
DEBUG("resolution: %s", CEARatesAndResolutionsToString((wds::CEARatesAndResolutions) format.rate_resolution));
237
if (format.type == wds::VESA)
238
DEBUG("resolution: %s", VESARatesAndResolutionsToString((wds::VESARatesAndResolutions) format.rate_resolution));
239
if (format.type == wds::HH)
240
DEBUG("resolution: %s", HHRatesAndResolutionsToString((wds::HHRatesAndResolutions) format.rate_resolution));
243
void DumpNativeFormat(const wds::NativeVideoFormat &format) {
244
DEBUG(" resolution type: %s", ResolutionTypeToString(format.type));
246
if (format.type == wds::CEA)
247
DEBUG("resolution: %s", CEARatesAndResolutionsToString((wds::CEARatesAndResolutions) format.rate_resolution));
248
if (format.type == wds::VESA)
249
DEBUG("resolution: %s", VESARatesAndResolutionsToString((wds::VESARatesAndResolutions) format.rate_resolution));
250
if (format.type == wds::HH)
251
DEBUG("resolution: %s", HHRatesAndResolutionsToString((wds::HHRatesAndResolutions) format.rate_resolution));
254
std::string ExtractH264Profile(const wds::H264VideoFormat &format) {
256
switch (format.profile) {
258
profile = "constrained-baseline";
269
std::string ExtractH264Level(const wds::H264VideoFormat &format) {
271
switch (format.level) {
293
RateAndResolution ExtractRateAndResolution(const wds::H264VideoFormat &format) {
294
RateAndResolution rr;
295
switch (format.type) {
297
switch (format.rate_resolution) {
298
case wds::CEA640x480p60:
303
case wds::CEA720x480p60:
304
case wds::CEA720x480i60:
309
case wds::CEA720x576p50:
310
case wds::CEA720x576i50:
315
case wds::CEA1280x720p30:
320
case wds::CEA1280x720p60:
325
case wds::CEA1920x1080p30:
330
case wds::CEA1920x1080p60:
331
case wds::CEA1920x1080i60:
336
case wds::CEA1280x720p25:
341
case wds::CEA1280x720p50:
346
case wds::CEA1280x720p24:
351
case wds::CEA1920x1080p25:
356
case wds::CEA1920x1080p50:
361
case wds::CEA1920x1080i50:
366
case wds::CEA1920x1080p24:
375
// FIXME Add support for VESA and HH
385
void ExtractProfileLevel(const wds::H264VideoFormat &format, int *profile,
386
int *level, int *constraint) {
388
if (format.profile == wds::CBP) {
392
else if (format.profile == wds::CHP) {
397
switch (format.level) {