Line data Source code
1 : /*
2 : * If not stated otherwise in this file or this component's LICENSE file the
3 : * following copyright and licenses apply:
4 : *
5 : * Copyright 2026 Sky UK
6 : *
7 : * Licensed under the Apache License, Version 2.0 (the "License");
8 : * you may not use this file except in compliance with the License.
9 : * You may obtain a copy of the License at
10 : *
11 : * http://www.apache.org/licenses/LICENSE-2.0
12 : *
13 : * Unless required by applicable law or agreed to in writing, software
14 : * distributed under the License is distributed on an "AS IS" BASIS,
15 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 : * See the License for the specific language governing permissions and
17 : * limitations under the License.
18 : */
19 :
20 : #include "CapabilityConverters.h"
21 :
22 : namespace
23 : {
24 : using AudioCap = firebolt::rialto::AudioCapabilities;
25 : using VideoCap = firebolt::rialto::VideoCapabilities;
26 :
27 : // ---------- struct -> proto (serialise) ----------
28 :
29 17 : void fillProfileCap(const firebolt::rialto::common::AudioProfileCapability &src, AudioCap::AudioProfileCapability *dst)
30 : {
31 17 : dst->set_max_bitrate_in_bps(src.maxBitrateInBps);
32 17 : dst->set_max_channels(src.maxChannels);
33 17 : dst->set_max_sample_rate_in_hz(src.maxSampleRateInHz);
34 17 : dst->set_max_bit_depth(src.maxBitDepth);
35 : }
36 :
37 1 : AudioCap::AacProfile toProto(firebolt::rialto::common::AacProfile p)
38 : {
39 1 : switch (p)
40 : {
41 0 : case firebolt::rialto::common::AacProfile::HE_V1:
42 0 : return AudioCap::AAC_PROFILE_HE_V1;
43 0 : case firebolt::rialto::common::AacProfile::HE_V2:
44 0 : return AudioCap::AAC_PROFILE_HE_V2;
45 0 : case firebolt::rialto::common::AacProfile::ELD:
46 0 : return AudioCap::AAC_PROFILE_ELD;
47 0 : case firebolt::rialto::common::AacProfile::X_HE:
48 0 : return AudioCap::AAC_PROFILE_X_HE;
49 1 : default:
50 1 : return AudioCap::AAC_PROFILE_LC;
51 : }
52 : }
53 1 : AudioCap::DolbyEac3Profile toProto(firebolt::rialto::common::DolbyEac3Profile p)
54 : {
55 1 : return (p == firebolt::rialto::common::DolbyEac3Profile::PLUS_JOC) ? AudioCap::DOLBY_EAC3_PROFILE_PLUS_JOC
56 1 : : AudioCap::DOLBY_EAC3_PROFILE_PLUS;
57 : }
58 1 : AudioCap::MpegAudioProfile toProto(firebolt::rialto::common::MpegAudioProfile p)
59 : {
60 1 : return (p == firebolt::rialto::common::MpegAudioProfile::LAYER_2) ? AudioCap::MPEG_AUDIO_PROFILE_LAYER_2
61 1 : : AudioCap::MPEG_AUDIO_PROFILE_LAYER_1;
62 : }
63 1 : AudioCap::RealAudioProfile toProto(firebolt::rialto::common::RealAudioProfile p)
64 : {
65 1 : return (p == firebolt::rialto::common::RealAudioProfile::RA10) ? AudioCap::REALAUDIO_PROFILE_RA10
66 1 : : AudioCap::REALAUDIO_PROFILE_RA8;
67 : }
68 1 : AudioCap::UsacProfile toProto(firebolt::rialto::common::UsacProfile p)
69 : {
70 1 : return (p == firebolt::rialto::common::UsacProfile::EXTENDED_HE_AAC) ? AudioCap::USAC_PROFILE_EXTENDED_HE_AAC
71 1 : : AudioCap::USAC_PROFILE_BASELINE;
72 : }
73 1 : AudioCap::DtsProfile toProto(firebolt::rialto::common::DtsProfile p)
74 : {
75 1 : switch (p)
76 : {
77 0 : case firebolt::rialto::common::DtsProfile::HD_HRA:
78 0 : return AudioCap::DTS_PROFILE_HD_HRA;
79 0 : case firebolt::rialto::common::DtsProfile::HD_MA:
80 0 : return AudioCap::DTS_PROFILE_HD_MA;
81 1 : default:
82 1 : return AudioCap::DTS_PROFILE_CORE;
83 : }
84 : }
85 1 : AudioCap::AvsProfile toProto(firebolt::rialto::common::AvsProfile p)
86 : {
87 1 : switch (p)
88 : {
89 1 : case firebolt::rialto::common::AvsProfile::AVS2:
90 1 : return AudioCap::AVS_PROFILE_AVS2;
91 0 : case firebolt::rialto::common::AvsProfile::AVS3:
92 0 : return AudioCap::AVS_PROFILE_AVS3;
93 0 : default:
94 0 : return AudioCap::AVS_PROFILE_AVS1_PART2;
95 : }
96 : }
97 :
98 : template <typename Map, typename ProtoEntry, typename Conv>
99 7 : void fillNamedProfiles(const Map &m, ProtoEntry *proto, Conv conv)
100 : {
101 14 : for (const auto &[profile, cap] : m)
102 : {
103 7 : auto *e = proto->add_profiles();
104 7 : e->set_profile(conv(profile));
105 7 : fillProfileCap(cap, e->mutable_capability());
106 : }
107 : }
108 :
109 1 : void fillAudioDecoderCapability(const firebolt::rialto::common::AudioDecoderCapability &src,
110 : AudioCap::AudioDecoderCapability *dst)
111 : {
112 9 : auto fillBase = [&](const firebolt::rialto::common::AudioProfileCapability &cap, auto *proto)
113 9 : { fillProfileCap(cap, proto->mutable_base()); };
114 :
115 1 : if (src.pcm)
116 1 : fillBase(src.pcm->base, dst->mutable_pcm());
117 1 : if (src.mp3)
118 1 : fillBase(src.mp3->base, dst->mutable_mp3());
119 1 : if (src.alac)
120 1 : fillBase(src.alac->base, dst->mutable_alac());
121 1 : if (src.sbc)
122 1 : fillBase(src.sbc->base, dst->mutable_sbc());
123 1 : if (src.dolbyAc4)
124 1 : fillBase(src.dolbyAc4->base, dst->mutable_dolby_ac4());
125 1 : if (src.dolbyTruehd)
126 1 : fillBase(src.dolbyTruehd->base, dst->mutable_dolby_truehd());
127 1 : if (src.flac)
128 1 : fillBase(src.flac->base, dst->mutable_flac());
129 1 : if (src.vorbis)
130 1 : fillBase(src.vorbis->base, dst->mutable_vorbis());
131 1 : if (src.opus)
132 1 : fillBase(src.opus->base, dst->mutable_opus());
133 1 : if (src.dolbyAc3)
134 : {
135 2 : for (const auto &[p, c] : src.dolbyAc3->profiles)
136 : {
137 1 : auto *e = dst->mutable_dolby_ac3()->add_profiles();
138 1 : e->set_profile(AudioCap::DOLBY_AC3_PROFILE_STANDARD);
139 1 : fillProfileCap(c, e->mutable_capability());
140 : }
141 : }
142 1 : if (src.aac)
143 2 : fillNamedProfiles(src.aac->profiles, dst->mutable_aac(), [](auto p) { return toProto(p); });
144 1 : if (src.mpegAudio)
145 2 : fillNamedProfiles(src.mpegAudio->profiles, dst->mutable_mpeg_audio(), [](auto p) { return toProto(p); });
146 1 : if (src.dolbyEac3)
147 2 : fillNamedProfiles(src.dolbyEac3->profiles, dst->mutable_dolby_eac3(), [](auto p) { return toProto(p); });
148 1 : if (src.realAudio)
149 2 : fillNamedProfiles(src.realAudio->profiles, dst->mutable_real_audio(), [](auto p) { return toProto(p); });
150 1 : if (src.usac)
151 2 : fillNamedProfiles(src.usac->profiles, dst->mutable_usac(), [](auto p) { return toProto(p); });
152 1 : if (src.dts)
153 2 : fillNamedProfiles(src.dts->profiles, dst->mutable_dts(), [](auto p) { return toProto(p); });
154 1 : if (src.avs)
155 2 : fillNamedProfiles(src.avs->profiles, dst->mutable_avs(), [](auto p) { return toProto(p); });
156 1 : }
157 :
158 9 : VideoCap::DynamicRange toDR(firebolt::rialto::common::DynamicRange dr)
159 : {
160 9 : switch (dr)
161 : {
162 1 : case firebolt::rialto::common::DynamicRange::HLG:
163 1 : return VideoCap::DYNAMIC_RANGE_HLG;
164 2 : case firebolt::rialto::common::DynamicRange::HDR10:
165 2 : return VideoCap::DYNAMIC_RANGE_HDR10;
166 1 : case firebolt::rialto::common::DynamicRange::HDR10PLUS:
167 1 : return VideoCap::DYNAMIC_RANGE_HDR10PLUS;
168 1 : case firebolt::rialto::common::DynamicRange::DOLBY_VISION:
169 1 : return VideoCap::DYNAMIC_RANGE_DOLBY_VISION;
170 4 : default:
171 4 : return VideoCap::DYNAMIC_RANGE_SDR;
172 : }
173 : }
174 :
175 : // ---------- proto -> struct (deserialise) ----------
176 :
177 35 : firebolt::rialto::common::AudioProfileCapability toAudioProfileCapability(const AudioCap::AudioProfileCapability &src)
178 : {
179 35 : firebolt::rialto::common::AudioProfileCapability dst{};
180 35 : dst.maxBitrateInBps = src.max_bitrate_in_bps();
181 35 : dst.maxChannels = src.max_channels();
182 35 : dst.maxSampleRateInHz = src.max_sample_rate_in_hz();
183 35 : dst.maxBitDepth = src.max_bit_depth();
184 35 : return dst;
185 : }
186 :
187 7 : firebolt::rialto::common::AacProfile fromProto(AudioCap::AacProfile p)
188 : {
189 7 : switch (p)
190 : {
191 1 : case AudioCap::AAC_PROFILE_HE_V1:
192 1 : return firebolt::rialto::common::AacProfile::HE_V1;
193 1 : case AudioCap::AAC_PROFILE_HE_V2:
194 1 : return firebolt::rialto::common::AacProfile::HE_V2;
195 1 : case AudioCap::AAC_PROFILE_ELD:
196 1 : return firebolt::rialto::common::AacProfile::ELD;
197 1 : case AudioCap::AAC_PROFILE_X_HE:
198 1 : return firebolt::rialto::common::AacProfile::X_HE;
199 3 : default:
200 3 : return firebolt::rialto::common::AacProfile::LC;
201 : }
202 : }
203 2 : firebolt::rialto::common::DolbyEac3Profile fromProto(AudioCap::DolbyEac3Profile p)
204 : {
205 2 : return (p == AudioCap::DOLBY_EAC3_PROFILE_PLUS_JOC) ? firebolt::rialto::common::DolbyEac3Profile::PLUS_JOC
206 2 : : firebolt::rialto::common::DolbyEac3Profile::PLUS;
207 : }
208 2 : firebolt::rialto::common::MpegAudioProfile fromProto(AudioCap::MpegAudioProfile p)
209 : {
210 2 : return (p == AudioCap::MPEG_AUDIO_PROFILE_LAYER_2) ? firebolt::rialto::common::MpegAudioProfile::LAYER_2
211 2 : : firebolt::rialto::common::MpegAudioProfile::LAYER_1;
212 : }
213 2 : firebolt::rialto::common::RealAudioProfile fromProto(AudioCap::RealAudioProfile p)
214 : {
215 2 : return (p == AudioCap::REALAUDIO_PROFILE_RA10) ? firebolt::rialto::common::RealAudioProfile::RA10
216 2 : : firebolt::rialto::common::RealAudioProfile::RA8;
217 : }
218 2 : firebolt::rialto::common::UsacProfile fromProto(AudioCap::UsacProfile p)
219 : {
220 2 : return (p == AudioCap::USAC_PROFILE_EXTENDED_HE_AAC) ? firebolt::rialto::common::UsacProfile::EXTENDED_HE_AAC
221 2 : : firebolt::rialto::common::UsacProfile::BASELINE;
222 : }
223 3 : firebolt::rialto::common::DtsProfile fromProto(AudioCap::DtsProfile p)
224 : {
225 3 : switch (p)
226 : {
227 1 : case AudioCap::DTS_PROFILE_HD_HRA:
228 1 : return firebolt::rialto::common::DtsProfile::HD_HRA;
229 1 : case AudioCap::DTS_PROFILE_HD_MA:
230 1 : return firebolt::rialto::common::DtsProfile::HD_MA;
231 1 : default:
232 1 : return firebolt::rialto::common::DtsProfile::CORE;
233 : }
234 : }
235 3 : firebolt::rialto::common::AvsProfile fromProto(AudioCap::AvsProfile p)
236 : {
237 3 : switch (p)
238 : {
239 1 : case AudioCap::AVS_PROFILE_AVS2:
240 1 : return firebolt::rialto::common::AvsProfile::AVS2;
241 1 : case AudioCap::AVS_PROFILE_AVS3:
242 1 : return firebolt::rialto::common::AvsProfile::AVS3;
243 1 : default:
244 1 : return firebolt::rialto::common::AvsProfile::AVS1_PART2;
245 : }
246 : }
247 :
248 : template <typename ProtoRepeated, typename Map, typename Conv>
249 23 : void fillProfileMap(const ProtoRepeated &src, Map &dst, Conv conv)
250 : {
251 69 : for (const auto &entry : src)
252 : {
253 23 : if (entry.has_profile() && entry.has_capability())
254 21 : dst[conv(entry.profile())] = toAudioProfileCapability(entry.capability());
255 : }
256 : }
257 :
258 28 : firebolt::rialto::common::AudioDecoderCapability toAudioDecoderCapability(const AudioCap::AudioDecoderCapability &src)
259 : {
260 28 : firebolt::rialto::common::AudioDecoderCapability dst;
261 28 : if (src.has_pcm())
262 3 : dst.pcm = firebolt::rialto::common::PcmCapability{toAudioProfileCapability(src.pcm().base())};
263 28 : if (src.has_mp3())
264 3 : dst.mp3 = firebolt::rialto::common::Mp3Capability{toAudioProfileCapability(src.mp3().base())};
265 28 : if (src.has_alac())
266 1 : dst.alac = firebolt::rialto::common::AlacCapability{toAudioProfileCapability(src.alac().base())};
267 28 : if (src.has_sbc())
268 1 : dst.sbc = firebolt::rialto::common::SbcCapability{toAudioProfileCapability(src.sbc().base())};
269 28 : if (src.has_dolby_ac4())
270 1 : dst.dolbyAc4 = firebolt::rialto::common::DolbyAc4Capability{toAudioProfileCapability(src.dolby_ac4().base())};
271 28 : if (src.has_dolby_truehd())
272 : dst.dolbyTruehd =
273 1 : firebolt::rialto::common::DolbyTruehdCapability{toAudioProfileCapability(src.dolby_truehd().base())};
274 28 : if (src.has_flac())
275 1 : dst.flac = firebolt::rialto::common::FlacCapability{toAudioProfileCapability(src.flac().base())};
276 28 : if (src.has_vorbis())
277 1 : dst.vorbis = firebolt::rialto::common::VorbisCapability{toAudioProfileCapability(src.vorbis().base())};
278 28 : if (src.has_opus())
279 1 : dst.opus = firebolt::rialto::common::OpusCapability{toAudioProfileCapability(src.opus().base())};
280 28 : if (src.has_dolby_ac3())
281 : {
282 2 : firebolt::rialto::common::DolbyAc3Capability cap;
283 4 : for (const auto &entry : src.dolby_ac3().profiles())
284 2 : if (entry.has_capability())
285 1 : cap.profiles[firebolt::rialto::common::DolbyAc3Profile::STANDARD] =
286 1 : toAudioProfileCapability(entry.capability());
287 2 : dst.dolbyAc3 = cap;
288 : }
289 28 : if (src.has_aac())
290 : {
291 9 : firebolt::rialto::common::AacCapability cap;
292 16 : fillProfileMap(src.aac().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
293 9 : dst.aac = cap;
294 : }
295 28 : if (src.has_mpeg_audio())
296 : {
297 2 : firebolt::rialto::common::MpegAudioCapability cap;
298 4 : fillProfileMap(src.mpeg_audio().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
299 2 : dst.mpegAudio = cap;
300 : }
301 28 : if (src.has_dolby_eac3())
302 : {
303 2 : firebolt::rialto::common::DolbyEac3Capability cap;
304 4 : fillProfileMap(src.dolby_eac3().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
305 2 : dst.dolbyEac3 = cap;
306 : }
307 28 : if (src.has_real_audio())
308 : {
309 2 : firebolt::rialto::common::RealAudioCapability cap;
310 4 : fillProfileMap(src.real_audio().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
311 2 : dst.realAudio = cap;
312 : }
313 28 : if (src.has_usac())
314 : {
315 2 : firebolt::rialto::common::UsacCapability cap;
316 4 : fillProfileMap(src.usac().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
317 2 : dst.usac = cap;
318 : }
319 28 : if (src.has_dts())
320 : {
321 3 : firebolt::rialto::common::DtsCapability cap;
322 6 : fillProfileMap(src.dts().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
323 3 : dst.dts = cap;
324 : }
325 28 : if (src.has_avs())
326 : {
327 3 : firebolt::rialto::common::AvsCapability cap;
328 6 : fillProfileMap(src.avs().profiles(), cap.profiles, [](auto p) { return fromProto(p); });
329 3 : dst.avs = cap;
330 : }
331 28 : return dst;
332 : }
333 :
334 11 : firebolt::rialto::common::DynamicRange fromDR(VideoCap::DynamicRange dr)
335 : {
336 11 : switch (dr)
337 : {
338 1 : case VideoCap::DYNAMIC_RANGE_HLG:
339 1 : return firebolt::rialto::common::DynamicRange::HLG;
340 5 : case VideoCap::DYNAMIC_RANGE_HDR10:
341 5 : return firebolt::rialto::common::DynamicRange::HDR10;
342 1 : case VideoCap::DYNAMIC_RANGE_HDR10PLUS:
343 1 : return firebolt::rialto::common::DynamicRange::HDR10PLUS;
344 1 : case VideoCap::DYNAMIC_RANGE_DOLBY_VISION:
345 1 : return firebolt::rialto::common::DynamicRange::DOLBY_VISION;
346 3 : default:
347 3 : return firebolt::rialto::common::DynamicRange::SDR;
348 : }
349 : }
350 :
351 4 : firebolt::rialto::common::Mpeg2ProfileType fromProto(VideoCap::Mpeg2ProfileType t)
352 : {
353 4 : return (t == VideoCap::MPEG2_PROFILE_SIMPLE) ? firebolt::rialto::common::Mpeg2ProfileType::MPEG2_SIMPLE
354 4 : : firebolt::rialto::common::Mpeg2ProfileType::MPEG2_MAIN;
355 : }
356 4 : firebolt::rialto::common::Mpeg2Level fromProto(VideoCap::Mpeg2Level l)
357 : {
358 4 : switch (l)
359 : {
360 1 : case VideoCap::MPEG2_LEVEL_MAIN:
361 1 : return firebolt::rialto::common::Mpeg2Level::MPEG2_LEVEL_MAIN;
362 2 : case VideoCap::MPEG2_LEVEL_HIGH:
363 2 : return firebolt::rialto::common::Mpeg2Level::MPEG2_LEVEL_HIGH;
364 1 : default:
365 1 : return firebolt::rialto::common::Mpeg2Level::MPEG2_LEVEL_LOW;
366 : }
367 : }
368 4 : firebolt::rialto::common::H264ProfileType fromProto(VideoCap::H264ProfileType t)
369 : {
370 4 : switch (t)
371 : {
372 0 : case VideoCap::H264_PROFILE_MAIN:
373 0 : return firebolt::rialto::common::H264ProfileType::H264_MAIN;
374 3 : case VideoCap::H264_PROFILE_HIGH:
375 3 : return firebolt::rialto::common::H264ProfileType::H264_HIGH;
376 1 : default:
377 1 : return firebolt::rialto::common::H264ProfileType::H264_BASELINE;
378 : }
379 : }
380 4 : firebolt::rialto::common::H264Level fromProto(VideoCap::H264Level l)
381 : {
382 4 : switch (l)
383 : {
384 0 : case VideoCap::H264_LEVEL_3_1:
385 0 : return firebolt::rialto::common::H264Level::H264_LEVEL_3_1;
386 0 : case VideoCap::H264_LEVEL_4:
387 0 : return firebolt::rialto::common::H264Level::H264_LEVEL_4;
388 0 : case VideoCap::H264_LEVEL_4_1:
389 0 : return firebolt::rialto::common::H264Level::H264_LEVEL_4_1;
390 0 : case VideoCap::H264_LEVEL_5:
391 0 : return firebolt::rialto::common::H264Level::H264_LEVEL_5;
392 3 : case VideoCap::H264_LEVEL_5_1:
393 3 : return firebolt::rialto::common::H264Level::H264_LEVEL_5_1;
394 0 : case VideoCap::H264_LEVEL_5_2:
395 0 : return firebolt::rialto::common::H264Level::H264_LEVEL_5_2;
396 1 : default:
397 1 : return firebolt::rialto::common::H264Level::H264_LEVEL_3;
398 : }
399 : }
400 4 : firebolt::rialto::common::H265ProfileType fromProto(VideoCap::H265ProfileType t)
401 : {
402 4 : switch (t)
403 : {
404 0 : case VideoCap::H265_PROFILE_MAIN_10:
405 0 : return firebolt::rialto::common::H265ProfileType::H265_MAIN_10;
406 1 : case VideoCap::H265_PROFILE_MAIN_10_HDR10:
407 1 : return firebolt::rialto::common::H265ProfileType::H265_MAIN_10_HDR10;
408 3 : default:
409 3 : return firebolt::rialto::common::H265ProfileType::H265_MAIN;
410 : }
411 : }
412 4 : firebolt::rialto::common::H265Level fromProto(VideoCap::H265Level l)
413 : {
414 4 : switch (l)
415 : {
416 0 : case VideoCap::H265_LEVEL_4_1:
417 0 : return firebolt::rialto::common::H265Level::H265_LEVEL_4_1;
418 2 : case VideoCap::H265_LEVEL_5:
419 2 : return firebolt::rialto::common::H265Level::H265_LEVEL_5;
420 0 : case VideoCap::H265_LEVEL_5_1:
421 0 : return firebolt::rialto::common::H265Level::H265_LEVEL_5_1;
422 0 : case VideoCap::H265_LEVEL_5_2:
423 0 : return firebolt::rialto::common::H265Level::H265_LEVEL_5_2;
424 1 : case VideoCap::H265_LEVEL_6:
425 1 : return firebolt::rialto::common::H265Level::H265_LEVEL_6;
426 0 : case VideoCap::H265_LEVEL_6_1:
427 0 : return firebolt::rialto::common::H265Level::H265_LEVEL_6_1;
428 0 : case VideoCap::H265_LEVEL_6_2:
429 0 : return firebolt::rialto::common::H265Level::H265_LEVEL_6_2;
430 1 : default:
431 1 : return firebolt::rialto::common::H265Level::H265_LEVEL_4;
432 : }
433 : }
434 2 : firebolt::rialto::common::Vp9ProfileType fromProto(VideoCap::Vp9ProfileType t)
435 : {
436 2 : switch (t)
437 : {
438 0 : case VideoCap::VP9_PROFILE_1:
439 0 : return firebolt::rialto::common::Vp9ProfileType::VP9_PROFILE_1;
440 1 : case VideoCap::VP9_PROFILE_2:
441 1 : return firebolt::rialto::common::Vp9ProfileType::VP9_PROFILE_2;
442 0 : case VideoCap::VP9_PROFILE_3:
443 0 : return firebolt::rialto::common::Vp9ProfileType::VP9_PROFILE_3;
444 1 : default:
445 1 : return firebolt::rialto::common::Vp9ProfileType::VP9_PROFILE_0;
446 : }
447 : }
448 2 : firebolt::rialto::common::Vp9Level fromProto(VideoCap::Vp9Level l)
449 : {
450 2 : switch (l)
451 : {
452 0 : case VideoCap::VP9_LEVEL_1_1:
453 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_1_1;
454 0 : case VideoCap::VP9_LEVEL_2:
455 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_2;
456 0 : case VideoCap::VP9_LEVEL_2_1:
457 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_2_1;
458 0 : case VideoCap::VP9_LEVEL_3:
459 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_3;
460 0 : case VideoCap::VP9_LEVEL_3_1:
461 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_3_1;
462 1 : case VideoCap::VP9_LEVEL_4:
463 1 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_4;
464 0 : case VideoCap::VP9_LEVEL_4_1:
465 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_4_1;
466 0 : case VideoCap::VP9_LEVEL_5:
467 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_5;
468 0 : case VideoCap::VP9_LEVEL_5_1:
469 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_5_1;
470 0 : case VideoCap::VP9_LEVEL_5_2:
471 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_5_2;
472 0 : case VideoCap::VP9_LEVEL_6:
473 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_6;
474 0 : case VideoCap::VP9_LEVEL_6_1:
475 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_6_1;
476 0 : case VideoCap::VP9_LEVEL_6_2:
477 0 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_6_2;
478 1 : default:
479 1 : return firebolt::rialto::common::Vp9Level::VP9_LEVEL_1;
480 : }
481 : }
482 3 : firebolt::rialto::common::Av1ProfileType fromProto(VideoCap::Av1ProfileType t)
483 : {
484 3 : return (t == VideoCap::AV1_PROFILE_HIGH) ? firebolt::rialto::common::Av1ProfileType::AV1_HIGH
485 3 : : firebolt::rialto::common::Av1ProfileType::AV1_MAIN;
486 : }
487 3 : firebolt::rialto::common::Av1Level fromProto(VideoCap::Av1Level l)
488 : {
489 3 : switch (l)
490 : {
491 0 : case VideoCap::AV1_LEVEL_4_1:
492 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_4_1;
493 1 : case VideoCap::AV1_LEVEL_5_0:
494 1 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_5_0;
495 0 : case VideoCap::AV1_LEVEL_5_1:
496 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_5_1;
497 0 : case VideoCap::AV1_LEVEL_5_2:
498 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_5_2;
499 0 : case VideoCap::AV1_LEVEL_6_0:
500 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_6_0;
501 0 : case VideoCap::AV1_LEVEL_6_1:
502 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_6_1;
503 0 : case VideoCap::AV1_LEVEL_6_2:
504 0 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_6_2;
505 2 : default:
506 2 : return firebolt::rialto::common::Av1Level::AV1_LEVEL_4_0;
507 : }
508 : }
509 :
510 : template <typename CommonProfile, typename ProtoProfile, typename TypeConv, typename LevelConv>
511 17 : CommonProfile toVideoProfile(const ProtoProfile &src, TypeConv typeConv, LevelConv levelConv)
512 : {
513 17 : CommonProfile dst{};
514 17 : dst.type = typeConv(src.type());
515 17 : dst.maxLevel = levelConv(src.max_level());
516 17 : dst.maxBitrateInBps = src.max_bitrate_in_bps();
517 17 : return dst;
518 : }
519 :
520 : template <typename CommonCodecCapability, typename ProtoCodecCapability, typename TypeConv, typename LevelConv>
521 17 : CommonCodecCapability toVideoCodecCapability(const ProtoCodecCapability &src, TypeConv typeConv, LevelConv levelConv)
522 : {
523 : using CommonProfile = typename decltype(CommonCodecCapability{}.profiles)::value_type;
524 17 : CommonCodecCapability cap;
525 34 : for (const auto &p : src.profiles())
526 17 : cap.profiles.push_back(toVideoProfile<CommonProfile>(p, typeConv, levelConv));
527 28 : for (const auto &dr : src.dynamic_ranges())
528 11 : cap.dynamicRanges.push_back(fromDR(static_cast<VideoCap::DynamicRange>(dr)));
529 17 : return cap;
530 : }
531 :
532 17 : firebolt::rialto::common::VideoDecoderCapability toVideoDecoderCapability(const VideoCap::VideoDecoderCapability &src)
533 : {
534 17 : firebolt::rialto::common::VideoDecoderCapability dst;
535 17 : if (!src.has_codec_capabilities())
536 1 : return dst;
537 16 : const auto &cc = src.codec_capabilities();
538 16 : if (cc.has_mpeg2())
539 : {
540 8 : dst.codecCapabilities.mpeg2 = toVideoCodecCapability<firebolt::rialto::common::Mpeg2CodecCapability>(
541 12 : cc.mpeg2(), [](auto t) { return fromProto(t); }, [](auto l) { return fromProto(l); });
542 : }
543 16 : if (cc.has_h264())
544 : {
545 8 : dst.codecCapabilities.h264 = toVideoCodecCapability<firebolt::rialto::common::H264CodecCapability>(
546 12 : cc.h264(), [](auto t) { return fromProto(t); }, [](auto l) { return fromProto(l); });
547 : }
548 16 : if (cc.has_h265())
549 : {
550 8 : dst.codecCapabilities.h265 = toVideoCodecCapability<firebolt::rialto::common::H265CodecCapability>(
551 12 : cc.h265(), [](auto t) { return fromProto(t); }, [](auto l) { return fromProto(l); });
552 : }
553 16 : if (cc.has_vp9())
554 : {
555 4 : dst.codecCapabilities.vp9 = toVideoCodecCapability<firebolt::rialto::common::Vp9CodecCapability>(
556 6 : cc.vp9(), [](auto t) { return fromProto(t); }, [](auto l) { return fromProto(l); });
557 : }
558 16 : if (cc.has_av1())
559 : {
560 6 : dst.codecCapabilities.av1 = toVideoCodecCapability<firebolt::rialto::common::Av1CodecCapability>(
561 9 : cc.av1(), [](auto t) { return fromProto(t); }, [](auto l) { return fromProto(l); });
562 : }
563 16 : return dst;
564 : }
565 : } // namespace
566 :
567 : namespace firebolt::rialto::ipc::common
568 : {
569 3 : void serialiseAudioCapabilities(const firebolt::rialto::common::AudioDecoderCapabilities &src,
570 : ::firebolt::rialto::AudioCapabilities *dst)
571 : {
572 3 : dst->set_interface_version(src.interfaceVersion);
573 3 : dst->set_schema_version(src.schemaVersion);
574 4 : for (const auto &cap : src.capabilities)
575 1 : fillAudioDecoderCapability(cap, dst->add_capabilities());
576 3 : }
577 :
578 3 : void serialiseVideoCapabilities(const firebolt::rialto::common::VideoDecoderCapabilities &src,
579 : ::firebolt::rialto::VideoCapabilities *dst)
580 : {
581 3 : dst->set_interface_version(src.interfaceVersion);
582 3 : dst->set_schema_version(src.schemaVersion);
583 4 : for (const auto &cap : src.capabilities)
584 : {
585 1 : auto *dstCap = dst->add_capabilities();
586 1 : auto *cc = dstCap->mutable_codec_capabilities();
587 1 : const auto &sc = cap.codecCapabilities;
588 1 : if (sc.mpeg2)
589 : {
590 1 : auto *c = cc->mutable_mpeg2();
591 4 : for (const auto &p : sc.mpeg2->profiles)
592 : {
593 3 : auto *e = c->add_profiles();
594 3 : e->set_type(static_cast<VideoCap::Mpeg2ProfileType>(p.type));
595 3 : e->set_max_level(static_cast<VideoCap::Mpeg2Level>(p.maxLevel));
596 3 : e->set_max_bitrate_in_bps(p.maxBitrateInBps);
597 : }
598 2 : for (const auto &dr : sc.mpeg2->dynamicRanges)
599 1 : c->add_dynamic_ranges(toDR(dr));
600 : }
601 1 : if (sc.h264)
602 : {
603 1 : auto *c = cc->mutable_h264();
604 4 : for (const auto &p : sc.h264->profiles)
605 : {
606 3 : auto *e = c->add_profiles();
607 3 : e->set_type(static_cast<VideoCap::H264ProfileType>(p.type));
608 3 : e->set_max_level(static_cast<VideoCap::H264Level>(p.maxLevel));
609 3 : e->set_max_bitrate_in_bps(p.maxBitrateInBps);
610 : }
611 6 : for (const auto &dr : sc.h264->dynamicRanges)
612 5 : c->add_dynamic_ranges(toDR(dr));
613 : }
614 1 : if (sc.h265)
615 : {
616 1 : auto *c = cc->mutable_h265();
617 4 : for (const auto &p : sc.h265->profiles)
618 : {
619 3 : auto *e = c->add_profiles();
620 3 : e->set_type(static_cast<VideoCap::H265ProfileType>(p.type));
621 3 : e->set_max_level(static_cast<VideoCap::H265Level>(p.maxLevel));
622 3 : e->set_max_bitrate_in_bps(p.maxBitrateInBps);
623 : }
624 2 : for (const auto &dr : sc.h265->dynamicRanges)
625 1 : c->add_dynamic_ranges(toDR(dr));
626 : }
627 1 : if (sc.vp9)
628 : {
629 1 : auto *c = cc->mutable_vp9();
630 5 : for (const auto &p : sc.vp9->profiles)
631 : {
632 4 : auto *e = c->add_profiles();
633 4 : e->set_type(static_cast<VideoCap::Vp9ProfileType>(p.type));
634 4 : e->set_max_level(static_cast<VideoCap::Vp9Level>(p.maxLevel));
635 4 : e->set_max_bitrate_in_bps(p.maxBitrateInBps);
636 : }
637 2 : for (const auto &dr : sc.vp9->dynamicRanges)
638 1 : c->add_dynamic_ranges(toDR(dr));
639 : }
640 1 : if (sc.av1)
641 : {
642 1 : auto *c = cc->mutable_av1();
643 3 : for (const auto &p : sc.av1->profiles)
644 : {
645 2 : auto *e = c->add_profiles();
646 2 : e->set_type(static_cast<VideoCap::Av1ProfileType>(p.type));
647 2 : e->set_max_level(static_cast<VideoCap::Av1Level>(p.maxLevel));
648 2 : e->set_max_bitrate_in_bps(p.maxBitrateInBps);
649 : }
650 2 : for (const auto &dr : sc.av1->dynamicRanges)
651 1 : c->add_dynamic_ranges(toDR(dr));
652 : }
653 : }
654 3 : }
655 :
656 : firebolt::rialto::common::AudioDecoderCapabilities
657 31 : deserialiseAudioCapabilities(const ::firebolt::rialto::AudioCapabilities &src)
658 : {
659 31 : firebolt::rialto::common::AudioDecoderCapabilities result;
660 31 : result.interfaceVersion = src.interface_version();
661 31 : result.schemaVersion = src.schema_version();
662 59 : for (const auto &cap : src.capabilities())
663 28 : result.capabilities.push_back(toAudioDecoderCapability(cap));
664 31 : return result;
665 : }
666 :
667 : firebolt::rialto::common::VideoDecoderCapabilities
668 19 : deserialiseVideoCapabilities(const ::firebolt::rialto::VideoCapabilities &src)
669 : {
670 19 : firebolt::rialto::common::VideoDecoderCapabilities result;
671 19 : result.interfaceVersion = src.interface_version();
672 19 : result.schemaVersion = src.schema_version();
673 36 : for (const auto &cap : src.capabilities())
674 17 : result.capabilities.push_back(toVideoDecoderCapability(cap));
675 19 : return result;
676 : }
677 : } // namespace firebolt::rialto::ipc::common
|