• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef C2CONFIG_H_
18 #define C2CONFIG_H_
19 
20 #include <C2.h>
21 #include <C2Component.h>
22 #include <C2Enum.h>
23 #include <C2ParamDef.h>
24 
25 /// \defgroup config Component configuration
26 /// @{
27 
28 /**
29  * Enumerated boolean.
30  */
31 C2ENUM(c2_bool_t, uint32_t,
32     C2_FALSE, ///< true
33     C2_TRUE,  ///< false
34 )
35 
36 typedef C2SimpleValueStruct<c2_bool_t> C2BoolValue;
37 
38 typedef C2SimpleValueStruct<C2EasyEnum<c2_bool_t>> C2EasyBoolValue;
39 
40 /**
41  * Enumerated set tri-state.
42  *
43  * Used for optional configurations to distinguish between values set by the client,
44  * default values set by the component, or unset values.
45  */
46 C2ENUM(c2_set_t, uint32_t,
47     C2_UNSET,   // parameter is unset and has no value
48     C2_SET,     // parameter is/has been set by the client
49     C2_DEFAULT, // parameter has not been set by the client, but is set by the component
50 )
51 
52 /** Enumerations used by configuration parameters */
53 struct C2Config {
54     enum aac_packaging_t : uint32_t;        ///< AAC packaging (RAW vs ADTS)
55     enum aac_sbr_mode_t : uint32_t;         ///< AAC SBR mode
56     enum api_feature_t : uint64_t;          ///< API features
57     enum api_level_t : uint32_t;            ///< API level
58     enum bitrate_mode_t : uint32_t;         ///< bitrate control mode
59     enum drc_compression_mode_t : int32_t;  ///< DRC compression mode
60     enum drc_effect_type_t : int32_t;       ///< DRC effect type
61     enum drc_album_mode_t : int32_t;        ///< DRC album mode
62     enum hdr_dynamic_metadata_type_t : uint32_t;  ///< HDR dynamic metadata type
63     enum hdr_format_t : uint32_t;           ///< HDR format
64     enum intra_refresh_mode_t : uint32_t;   ///< intra refresh modes
65     enum level_t : uint32_t;                ///< coding level
66     enum ordinal_key_t : uint32_t;          ///< work ordering keys
67     enum pcm_encoding_t : uint32_t;         ///< PCM encoding
68     enum picture_type_t : uint32_t;         ///< picture types
69     enum platform_feature_t : uint64_t;     ///< platform features
70     enum platform_level_t : uint32_t;       ///< platform level
71     enum prepend_header_mode_t : uint32_t;  ///< prepend header operational modes
72     enum profile_t : uint32_t;              ///< coding profile
73     enum scaling_method_t : uint32_t;       ///< scaling methods
74     enum scan_order_t : uint32_t;           ///< scan orders
75     enum secure_mode_t : uint32_t;          ///< secure/protected modes
76     enum supplemental_info_t : uint32_t;    ///< supplemental information types
77     enum tiling_mode_t : uint32_t;          ///< tiling modes
78 };
79 
80 struct C2PlatformConfig {
81     enum encoding_quality_level_t : uint32_t; ///< encoding quality level
82     enum tunnel_peek_mode_t: uint32_t;      ///< tunnel peek mode
83 };
84 
85 namespace {
86 
87 enum C2ParamIndexKind : C2Param::type_index_t {
88     C2_PARAM_INDEX_INVALID             = 0x0,    ///< do not use
89     C2_PARAM_INDEX_STRUCT_START        = 0x1,    ///< struct only indices
90     C2_PARAM_INDEX_PARAM_START         = 0x800,  ///< regular parameters
91     C2_PARAM_INDEX_CODER_PARAM_START   = 0x1000, ///< en/transcoder parameters
92     C2_PARAM_INDEX_PICTURE_PARAM_START = 0x1800, ///< image/video parameters
93     C2_PARAM_INDEX_VIDEO_PARAM_START   = 0x2000, ///< video parameters
94     C2_PARAM_INDEX_IMAGE_PARAM_START   = 0x2800, ///< image parameters
95     C2_PARAM_INDEX_AUDIO_PARAM_START   = 0x3000, ///< image parameters
96     C2_PARAM_INDEX_PLATFORM_START      = 0x4000, ///< platform-defined parameters
97 
98     /* =================================== structure indices =================================== */
99 
100     kParamIndexColorXy = C2_PARAM_INDEX_STRUCT_START,
101     kParamIndexMasteringDisplayColorVolume,
102     kParamIndexChromaOffset,
103     kParamIndexGopLayer,
104 
105     /* =================================== parameter indices =================================== */
106 
107     kParamIndexApiLevel = C2_PARAM_INDEX_PARAM_START,
108     kParamIndexApiFeatures,
109 
110     /* ------------------------------------ all components ------------------------------------ */
111 
112     /* generic component characteristics */
113     kParamIndexName,
114     kParamIndexAliases,
115     kParamIndexKind,
116     kParamIndexDomain,
117     kParamIndexAttributes,
118     kParamIndexTimeStretch,
119 
120     /* coding characteristics */
121     kParamIndexProfileLevel,
122     kParamIndexInitData,
123     kParamIndexSupplementalData,
124     kParamIndexSubscribedSupplementalData,
125 
126     /* pipeline characteristics */
127     kParamIndexMediaType,
128     __kParamIndexRESERVED_0,
129     kParamIndexDelay,
130     kParamIndexMaxReferenceAge,
131     kParamIndexMaxReferenceCount,
132     kParamIndexReorderBufferDepth,
133     kParamIndexReorderKey,
134     kParamIndexStreamCount,
135     kParamIndexSubscribedParamIndices,
136     kParamIndexSuggestedBufferCount,
137     kParamIndexBatchSize,
138     kParamIndexCurrentWork,
139     kParamIndexLastWorkQueued,
140 
141     /* memory allocation */
142     kParamIndexAllocators,
143     kParamIndexBlockPools,
144     kParamIndexBufferType,
145     kParamIndexUsage,
146     kParamIndexOutOfMemory,
147     kParamIndexMaxBufferSize,
148 
149     /* misc. state */
150     kParamIndexTripped,
151     kParamIndexConfigCounter,
152 
153     /* resources */
154     kParamIndexResourcesNeeded,
155     kParamIndexResourcesReserved,
156     kParamIndexOperatingRate,
157     kParamIndexRealTimePriority,
158 
159     /* protected content */
160     kParamIndexSecureMode,
161     kParamIndexEncryptedBuffer, // info-buffer, used with SM_READ_PROTECTED_WITH_ENCRYPTED
162 
163     /* multiple access unit support */
164     kParamIndexLargeFrame,
165     kParamIndexAccessUnitInfos, // struct
166 
167     /* Region of Interest Encoding parameters */
168     kParamIndexQpOffsetMapBuffer, // info-buffer, used to signal qp-offset map for a frame
169 
170     // deprecated
171     kParamIndexDelayRequest = kParamIndexDelay | C2Param::CoreIndex::IS_REQUEST_FLAG,
172 
173     /* ------------------------------------ (trans/en)coders ------------------------------------ */
174 
175     kParamIndexBitrate = C2_PARAM_INDEX_CODER_PARAM_START,
176     kParamIndexBitrateMode,
177     kParamIndexQuality,
178     kParamIndexComplexity,
179     kParamIndexPrependHeaderMode,
180 
181     /* --------------------------------- image/video components --------------------------------- */
182 
183     kParamIndexPictureSize = C2_PARAM_INDEX_PICTURE_PARAM_START,
184     kParamIndexCropRect,
185     kParamIndexPixelFormat,
186     kParamIndexRotation,
187     kParamIndexPixelAspectRatio,
188     kParamIndexScaledPictureSize,
189     kParamIndexScaledCropRect,
190     kParamIndexScalingMethod,
191     kParamIndexColorInfo,
192     kParamIndexColorAspects,
193     kParamIndexHdrStaticMetadata,
194     kParamIndexDefaultColorAspects,
195 
196     kParamIndexBlockSize,
197     kParamIndexBlockCount,
198     kParamIndexBlockRate,
199 
200     kParamIndexPictureTypeMask,
201     kParamIndexPictureType,
202     // deprecated
203     kParamIndexHdr10PlusMetadata,
204     kParamIndexPictureQuantization,
205     kParamIndexHdrDynamicMetadata,
206     kParamIndexHdrFormat,
207     kParamIndexQpOffsetRect,
208     kParamIndexQpOffsetRects,
209 
210     /* ------------------------------------ video components ------------------------------------ */
211 
212     kParamIndexFrameRate = C2_PARAM_INDEX_VIDEO_PARAM_START,
213     kParamIndexMaxBitrate,
214     kParamIndexMaxFrameRate,
215     kParamIndexMaxPictureSize,
216     kParamIndexGop,
217     kParamIndexSyncFrameInterval,
218     kParamIndexRequestSyncFrame,
219     kParamIndexTemporalLayering,
220     kParamIndexLayerIndex,
221     kParamIndexLayerCount,
222     kParamIndexIntraRefresh,
223 
224     /* ------------------------------------ image components ------------------------------------ */
225 
226     kParamIndexTileLayout = C2_PARAM_INDEX_IMAGE_PARAM_START,
227     kParamIndexTileHandling,
228 
229     /* ------------------------------------ audio components ------------------------------------ */
230 
231     kParamIndexSampleRate = C2_PARAM_INDEX_AUDIO_PARAM_START,
232     kParamIndexChannelCount,
233     kParamIndexPcmEncoding,
234     kParamIndexAacPackaging,
235     kParamIndexMaxChannelCount,
236     kParamIndexAacSbrMode, // aac encode, enum
237     kParamIndexDrcEncodedTargetLevel,  // drc, float (dBFS)
238     kParamIndexDrcTargetReferenceLevel, // drc, float (dBFS)
239     kParamIndexDrcCompression, // drc, enum
240     kParamIndexDrcBoostFactor, // drc, float (0-1)
241     kParamIndexDrcAttenuationFactor, // drc, float (0-1)
242     kParamIndexDrcEffectType, // drc, enum
243     kParamIndexDrcOutputLoudness, // drc, float (dBFS)
244     kParamIndexDrcAlbumMode, // drc, enum
245     kParamIndexAudioFrameSize, // int
246 
247     /* ============================== platform-defined parameters ============================== */
248 
249     kParamIndexPlatformLevel = C2_PARAM_INDEX_PLATFORM_START, // all, u32
250     kParamIndexPlatformFeatures, // all, u64 mask
251     kParamIndexStoreIonUsage, // store, struct
252     kParamIndexAspectsToDataSpace, // store, struct
253     kParamIndexFlexiblePixelFormatDescriptor, // store, struct
254     kParamIndexFlexiblePixelFormatDescriptors, // store, struct[]
255     kParamIndexDataSpaceToAspects, // store, struct
256     kParamIndexDataSpace, // u32
257     kParamIndexSurfaceScaling, // u32
258 
259     // input surface
260     kParamIndexInputSurfaceEos, // input-surface, eos
261     kParamIndexTimedControl, // struct
262     kParamIndexStartAt, // input-surface, struct
263     kParamIndexSuspendAt, // input-surface, struct
264     kParamIndexResumeAt, // input-surface, struct
265     kParamIndexStopAt, // input-surface, struct
266     kParamIndexTimeOffset, // input-surface, struct
267     kParamIndexMinFrameRate, // input-surface, float
268     kParamIndexTimestampGapAdjustment, // input-surface, struct
269 
270     kParamIndexSurfaceAllocator, // u32
271 
272     // low latency mode
273     kParamIndexLowLatencyMode, // bool
274 
275     // tunneled codec
276     kParamIndexTunneledMode, // struct
277     kParamIndexTunnelHandle, // int32[]
278     kParamIndexTunnelSystemTime, // int64
279     kParamIndexTunnelHoldRender, // bool
280     kParamIndexTunnelStartRender, // bool
281 
282     // dmabuf allocator
283     kParamIndexStoreDmaBufUsage,  // store, struct
284 
285     // encoding quality requirements
286     kParamIndexEncodingQualityLevel, // encoders, enum
287 
288     // encoding statistics, average block qp of a frame
289     kParamIndexAverageBlockQuantization, // int32
290 
291     // channel mask for decoded audio
292     kParamIndexAndroidChannelMask, // uint32
293 
294     // allow tunnel peek behavior to be unspecified for app compatibility
295     kParamIndexTunnelPeekMode, // tunnel mode, enum
296 };
297 
298 }
299 
300 /**
301  * Codec 2.0 parameter types follow the following naming convention:
302  *
303  * C2<group><domain><index><type>
304  *
305  * E.g. C2StreamPictureSizeInfo: group="" domain="Stream" index="PictureSize" type="Info".
306  * Group is somewhat arbitrary, but denotes kind of objects the parameter is defined.
307  * At this point we use Component and Store to distinguish basic component/store parameters.
308  *
309  * Parameter keys are named C2_PARAMKEY_[<group>_]<domain>_<index> as type is not expected
310  * to distinguish parameters. E.g. a component could change the type of the parameter and it
311  * is not expected users would need to change the key.
312  */
313 
314 /* ----------------------------------------- API level ----------------------------------------- */
315 
316 enum C2Config::api_level_t : uint32_t {
317     API_L0_1 = 0,   ///< support for API level 0.1
318 };
319 
320 // read-only
321 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Config::api_level_t>, kParamIndexApiLevel>
322         C2ApiLevelSetting;
323 constexpr char C2_PARAMKEY_API_LEVEL[] = "api.level";
324 
325 C2ENUM(C2Config::api_feature_t, uint64_t,
326     API_REFLECTION       = (1U << 0),  ///< ability to list supported parameters
327     API_VALUES           = (1U << 1),  ///< ability to list supported values for each parameter
328     API_CURRENT_VALUES   = (1U << 2),  ///< ability to list currently supported values for each parameter
329     API_DEPENDENCY       = (1U << 3),  ///< have a defined parameter dependency
330 
331     API_SAME_INPUT_BUFFER = (1U << 16),   ///< supporting multiple input buffers
332                                           ///< backed by the same allocation
333 
334     API_STREAMS          = (1ULL << 32),  ///< supporting variable number of streams
335 
336     API_TUNNELING        = (1ULL << 48)   ///< tunneling API
337 )
338 
339 // read-only
340 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Config::api_feature_t>, kParamIndexApiFeatures>
341         C2ApiFeaturesSetting;
342 constexpr char C2_PARAMKEY_API_FEATURES[] = "api.features";
343 
344 /* ----------------------------- generic component characteristics ----------------------------- */
345 
346 /**
347  * The name of the component.
348  *
349  * This must contain only alphanumeric characters or dot '.', hyphen '-', plus '+', or
350  * underline '_'. The name of each component must be unique.
351  *
352  * For Android: Component names must start with 'c2.' followed by the company name or abbreviation
353  * and another dot, e.g. 'c2.android.'. Use of lowercase is preferred but not required.
354  */
355 // read-only
356 typedef C2GlobalParam<C2Setting, C2StringValue, kParamIndexName> C2ComponentNameSetting;
357 constexpr char C2_PARAMKEY_COMPONENT_NAME[]  = "component.name";
358 
359 /**
360  * Alternate names (aliases) of the component.
361  *
362  * This is a comma ',' separated list of alternate component names. Unlike component names that
363  * must be unique, multiple components can have the same alias.
364  */
365 // read-only
366 typedef C2GlobalParam<C2Setting, C2StringValue, kParamIndexAliases> C2ComponentAliasesSetting;
367 constexpr char C2_PARAMKEY_COMPONENT_ALIASES[]  = "component.aliases";
368 
369 /**
370  * Component kind.
371  */
372 // read-only
373 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Component::kind_t>, kParamIndexKind>
374         C2ComponentKindSetting;
375 constexpr char C2_PARAMKEY_COMPONENT_KIND[]  = "component.kind";
376 
377 /**
378  * Component domain.
379  */
380 // read-only
381 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Component::domain_t>, kParamIndexDomain>
382         C2ComponentDomainSetting;
383 constexpr char C2_PARAMKEY_COMPONENT_DOMAIN[]  = "component.domain";
384 
385 /**
386  * Component attributes.
387  *
388  * These are a set of flags provided by the component characterizing its processing algorithm.
389  */
390 C2ENUM(C2Component::attrib_t, uint64_t,
391     ATTRIB_IS_TEMPORAL = 1u << 0, ///< component input ordering matters for processing
392 )
393 
394 // read-only
395 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Component::attrib_t>, kParamIndexAttributes>
396         C2ComponentAttributesSetting;
397 constexpr char C2_PARAMKEY_COMPONENT_ATTRIBUTES[] = "component.attributes";
398 
399 /**
400  * Time stretching.
401  *
402  * This is the ratio between the rate of the input timestamp, and the rate of the output timestamp.
403  * E.g. if this is 4.0, for every 1 seconds of input timestamp difference, the output shall differ
404  * by 4 seconds.
405  */
406 typedef C2GlobalParam<C2Tuning, C2FloatValue, kParamIndexTimeStretch> C2ComponentTimeStretchTuning;
407 constexpr char C2_PARAMKEY_TIME_STRETCH[]  = "algo.time-stretch";
408 
409 /* ----------------------------------- coding characteristics ----------------------------------- */
410 
411 /**
412  * Profile and level.
413  *
414  * Profile determines the tools used by the component.
415  * Level determines the level of resources used by the component.
416  */
417 
418 namespace {
419 
420 // Codec bases are ordered by their date of introduction to the code base.
421 enum : uint32_t {
422     _C2_PL_MP2V_BASE = 0x1000,
423     _C2_PL_AAC_BASE  = 0x2000,
424     _C2_PL_H263_BASE = 0x3000,
425     _C2_PL_MP4V_BASE = 0x4000,
426     _C2_PL_AVC_BASE  = 0x5000,
427     _C2_PL_HEVC_BASE = 0x6000,
428     _C2_PL_VP9_BASE  = 0x7000,
429     _C2_PL_DV_BASE   = 0x8000,
430     _C2_PL_AV1_BASE  = 0x9000,
431     _C2_PL_VP8_BASE  = 0xA000,
432     _C2_PL_MPEGH_BASE = 0xB000,     // MPEG-H 3D Audio
433 
434     C2_PROFILE_LEVEL_VENDOR_START = 0x70000000,
435 };
436 
437 }
438 
439 // Profiles and levels for each codec are ordered based on how they are ordered in the
440 // corresponding standard documents at introduction, and chronologically afterwards.
441 enum C2Config::profile_t : uint32_t {
442     PROFILE_UNUSED = 0,                         ///< profile is not used by this media type
443 
444     // AAC (MPEG-2 Part 7 and MPEG-4 Part 3) profiles
445     PROFILE_AAC_LC = _C2_PL_AAC_BASE,           ///< AAC Low-Complexity
446     PROFILE_AAC_MAIN,                           ///< AAC Main
447     PROFILE_AAC_SSR,                            ///< AAC Scalable Sampling Rate
448     PROFILE_AAC_LTP,                            ///< AAC Long Term Prediction
449     PROFILE_AAC_HE,                             ///< AAC High-Efficiency
450     PROFILE_AAC_SCALABLE,                       ///< AAC Scalable
451     PROFILE_AAC_ER_LC,                          ///< AAC Error Resilient Low-Complexity
452     PROFILE_AAC_ER_SCALABLE,                    ///< AAC Error Resilient Scalable
453     PROFILE_AAC_LD,                             ///< AAC Low Delay
454     PROFILE_AAC_HE_PS,                          ///< AAC High-Efficiency Parametric Stereo
455     PROFILE_AAC_ELD,                            ///< AAC Enhanced Low Delay
456     PROFILE_AAC_XHE,                            ///< AAC Extended High-Efficiency
457 
458     // MPEG-2 Video profiles
459     PROFILE_MP2V_SIMPLE = _C2_PL_MP2V_BASE,     ///< MPEG-2 Video (H.262) Simple
460     PROFILE_MP2V_MAIN,                          ///< MPEG-2 Video (H.262) Main
461     PROFILE_MP2V_SNR_SCALABLE,                  ///< MPEG-2 Video (H.262) SNR Scalable
462     PROFILE_MP2V_SPATIALLY_SCALABLE,            ///< MPEG-2 Video (H.262) Spatially Scalable
463     PROFILE_MP2V_HIGH,                          ///< MPEG-2 Video (H.262) High
464     PROFILE_MP2V_422,                           ///< MPEG-2 Video (H.262) 4:2:2
465     PROFILE_MP2V_MULTIVIEW,                     ///< MPEG-2 Video (H.262) Multi-view
466 
467     // H.263 profiles
468     PROFILE_H263_BASELINE = _C2_PL_H263_BASE,   ///< H.263 Baseline (Profile 0)
469     PROFILE_H263_H320,                          ///< H.263 H.320 Coding Efficiency Version 2 Backward-Compatibility (Profile 1)
470     PROFILE_H263_V1BC,                          ///< H.263 Version 1 Backward-Compatibility (Profile 2)
471     PROFILE_H263_ISWV2,                         ///< H.263 Version 2 Interactive and Streaming Wireless (Profile 3)
472     PROFILE_H263_ISWV3,                         ///< H.263 Version 3 Interactive and Streaming Wireless (Profile 4)
473     PROFILE_H263_HIGH_COMPRESSION,              ///< H.263 Conversational High Compression (Profile 5)
474     PROFILE_H263_INTERNET,                      ///< H.263 Conversational Internet (Profile 6)
475     PROFILE_H263_INTERLACE,                     ///< H.263 Conversational Interlace (Profile 7)
476     PROFILE_H263_HIGH_LATENCY,                  ///< H.263 High Latency (Profile 8)
477 
478     // MPEG-4 Part 2 (Video) Natural Visual Profiles
479     PROFILE_MP4V_SIMPLE,                        ///< MPEG-4 Video Simple
480     PROFILE_MP4V_SIMPLE_SCALABLE,               ///< MPEG-4 Video Simple Scalable
481     PROFILE_MP4V_CORE,                          ///< MPEG-4 Video Core
482     PROFILE_MP4V_MAIN,                          ///< MPEG-4 Video Main
483     PROFILE_MP4V_NBIT,                          ///< MPEG-4 Video N-Bit
484     PROFILE_MP4V_ARTS,                          ///< MPEG-4 Video Advanced Realtime Simple
485     PROFILE_MP4V_CORE_SCALABLE,                 ///< MPEG-4 Video Core Scalable
486     PROFILE_MP4V_ACE,                           ///< MPEG-4 Video Advanced Coding Efficiency
487     PROFILE_MP4V_ADVANCED_CORE,                 ///< MPEG-4 Video Advanced Core
488     PROFILE_MP4V_SIMPLE_STUDIO,                 ///< MPEG-4 Video Simple Studio
489     PROFILE_MP4V_CORE_STUDIO,                   ///< MPEG-4 Video Core Studio
490     PROFILE_MP4V_ADVANCED_SIMPLE,               ///< MPEG-4 Video Advanced Simple
491     PROFILE_MP4V_FGS,                           ///< MPEG-4 Video Fine Granularity Scalable
492 
493     // AVC / MPEG-4 Part 10 (H.264) profiles
494     PROFILE_AVC_BASELINE = _C2_PL_AVC_BASE,     ///< AVC (H.264) Baseline
495     PROFILE_AVC_CONSTRAINED_BASELINE,           ///< AVC (H.264) Constrained Baseline
496     PROFILE_AVC_MAIN,                           ///< AVC (H.264) Main
497     PROFILE_AVC_EXTENDED,                       ///< AVC (H.264) Extended
498     PROFILE_AVC_HIGH,                           ///< AVC (H.264) High
499     PROFILE_AVC_PROGRESSIVE_HIGH,               ///< AVC (H.264) Progressive High
500     PROFILE_AVC_CONSTRAINED_HIGH,               ///< AVC (H.264) Constrained High
501     PROFILE_AVC_HIGH_10,                        ///< AVC (H.264) High 10
502     PROFILE_AVC_PROGRESSIVE_HIGH_10,            ///< AVC (H.264) Progressive High 10
503     PROFILE_AVC_HIGH_422,                       ///< AVC (H.264) High 4:2:2
504     PROFILE_AVC_HIGH_444_PREDICTIVE,            ///< AVC (H.264) High 4:4:4 Predictive
505     PROFILE_AVC_HIGH_10_INTRA,                  ///< AVC (H.264) High 10 Intra
506     PROFILE_AVC_HIGH_422_INTRA,                 ///< AVC (H.264) High 4:2:2 Intra
507     PROFILE_AVC_HIGH_444_INTRA,                 ///< AVC (H.264) High 4:4:4 Intra
508     PROFILE_AVC_CAVLC_444_INTRA,                ///< AVC (H.264) CAVLC 4:4:4 Intra
509     PROFILE_AVC_SCALABLE_BASELINE = _C2_PL_AVC_BASE + 0x100,  ///< AVC (H.264) Scalable Baseline
510     PROFILE_AVC_SCALABLE_CONSTRAINED_BASELINE,  ///< AVC (H.264) Scalable Constrained Baseline
511     PROFILE_AVC_SCALABLE_HIGH,                  ///< AVC (H.264) Scalable High
512     PROFILE_AVC_SCALABLE_CONSTRAINED_HIGH,      ///< AVC (H.264) Scalable Constrained High
513     PROFILE_AVC_SCALABLE_HIGH_INTRA,            ///< AVC (H.264) Scalable High Intra
514     PROFILE_AVC_MULTIVIEW_HIGH = _C2_PL_AVC_BASE + 0x200,  ///< AVC (H.264) Multiview High
515     PROFILE_AVC_STEREO_HIGH,                    ///< AVC (H.264) Stereo High
516     PROFILE_AVC_MFC_HIGH,                       ///< AVC (H.264) MFC High
517     PROFILE_AVC_MULTIVIEW_DEPTH_HIGH = _C2_PL_AVC_BASE + 0x300,  ///< AVC (H.264) Multiview Depth High
518     PROFILE_AVC_MFC_DEPTH_HIGH,                 ///< AVC (H.264) MFC Depth High
519     PROFILE_AVC_ENHANCED_MULTIVIEW_DEPTH_HIGH = _C2_PL_AVC_BASE + 0x400,  ///< AVC (H.264) Enhanced Multiview Depth High
520 
521     // HEVC profiles
522     PROFILE_HEVC_MAIN = _C2_PL_HEVC_BASE,       ///< HEVC (H.265) Main
523     PROFILE_HEVC_MAIN_10,                       ///< HEVC (H.265) Main 10
524     PROFILE_HEVC_MAIN_STILL,                    ///< HEVC (H.265) Main Still Picture
525     PROFILE_HEVC_MONO = _C2_PL_HEVC_BASE + 0x100,  ///< HEVC (H.265) Monochrome
526     PROFILE_HEVC_MONO_12,                       ///< HEVC (H.265) Monochrome 12
527     PROFILE_HEVC_MONO_16,                       ///< HEVC (H.265) Monochrome 16
528     PROFILE_HEVC_MAIN_12,                       ///< HEVC (H.265) Main 12
529     PROFILE_HEVC_MAIN_422_10,                   ///< HEVC (H.265) Main 4:2:2 10
530     PROFILE_HEVC_MAIN_422_12,                   ///< HEVC (H.265) Main 4:2:2 12
531     PROFILE_HEVC_MAIN_444,                      ///< HEVC (H.265) Main 4:4:4
532     PROFILE_HEVC_MAIN_444_10,                   ///< HEVC (H.265) Main 4:4:4 10
533     PROFILE_HEVC_MAIN_444_12,                   ///< HEVC (H.265) Main 4:4:4 12
534     PROFILE_HEVC_MAIN_INTRA,                    ///< HEVC (H.265) Main Intra
535     PROFILE_HEVC_MAIN_10_INTRA,                 ///< HEVC (H.265) Main 10 Intra
536     PROFILE_HEVC_MAIN_12_INTRA,                 ///< HEVC (H.265) Main 12 Intra
537     PROFILE_HEVC_MAIN_422_10_INTRA,             ///< HEVC (H.265) Main 4:2:2 10 Intra
538     PROFILE_HEVC_MAIN_422_12_INTRA,             ///< HEVC (H.265) Main 4:2:2 12 Intra
539     PROFILE_HEVC_MAIN_444_INTRA,                ///< HEVC (H.265) Main 4:4:4 Intra
540     PROFILE_HEVC_MAIN_444_10_INTRA,             ///< HEVC (H.265) Main 4:4:4 10 Intra
541     PROFILE_HEVC_MAIN_444_12_INTRA,             ///< HEVC (H.265) Main 4:4:4 12 Intra
542     PROFILE_HEVC_MAIN_444_16_INTRA,             ///< HEVC (H.265) Main 4:4:4 16 Intra
543     PROFILE_HEVC_MAIN_444_STILL,                ///< HEVC (H.265) Main 4:4:4 Still Picture
544     PROFILE_HEVC_MAIN_444_16_STILL,             ///< HEVC (H.265) Main 4:4:4 16 Still Picture
545     PROFILE_HEVC_HIGH_444 = _C2_PL_HEVC_BASE + 0x200,  ///< HEVC (H.265) High Throughput 4:4:4
546     PROFILE_HEVC_HIGH_444_10,                   ///< HEVC (H.265) High Throughput 4:4:4 10
547     PROFILE_HEVC_HIGH_444_14,                   ///< HEVC (H.265) High Throughput 4:4:4 14
548     PROFILE_HEVC_HIGH_444_16_INTRA,             ///< HEVC (H.265) High Throughput 4:4:4 16 Intra
549     PROFILE_HEVC_SX_MAIN = _C2_PL_HEVC_BASE + 0x300,  ///< HEVC (H.265) Screen-Extended Main
550     PROFILE_HEVC_SX_MAIN_10,                    ///< HEVC (H.265) Screen-Extended Main 10
551     PROFILE_HEVC_SX_MAIN_444,                   ///< HEVC (H.265) Screen-Extended Main 4:4:4
552     PROFILE_HEVC_SX_MAIN_444_10,                ///< HEVC (H.265) Screen-Extended Main 4:4:4 10
553     PROFILE_HEVC_SX_HIGH_444,                   ///< HEVC (H.265) Screen-Extended High Throughput 4:4:4
554     PROFILE_HEVC_SX_HIGH_444_10,                ///< HEVC (H.265) Screen-Extended High Throughput 4:4:4 10
555     PROFILE_HEVC_SX_HIGH_444_14,                ///< HEVC (H.265) Screen-Extended High Throughput 4:4:4 14
556     PROFILE_HEVC_MULTIVIEW_MAIN = _C2_PL_HEVC_BASE + 0x400,  ///< HEVC (H.265) Multiview Main
557     PROFILE_HEVC_SCALABLE_MAIN = _C2_PL_HEVC_BASE + 0x500,  ///< HEVC (H.265) Scalable Main
558     PROFILE_HEVC_SCALABLE_MAIN_10,              ///< HEVC (H.265) Scalable Main 10
559     PROFILE_HEVC_SCALABLE_MONO = _C2_PL_HEVC_BASE + 0x600,  ///< HEVC (H.265) Scalable Monochrome
560     PROFILE_HEVC_SCALABLE_MONO_12,              ///< HEVC (H.265) Scalable Monochrome 12
561     PROFILE_HEVC_SCALABLE_MONO_16,              ///< HEVC (H.265) Scalable Monochrome 16
562     PROFILE_HEVC_SCALABLE_MAIN_444,             ///< HEVC (H.265) Scalable Main 4:4:4
563     PROFILE_HEVC_3D_MAIN = _C2_PL_HEVC_BASE + 0x700,  ///< HEVC (H.265) 3D Main
564 
565     // VP9 profiles
566     PROFILE_VP9_0 = _C2_PL_VP9_BASE,            ///< VP9 Profile 0 (4:2:0)
567     PROFILE_VP9_1,                              ///< VP9 Profile 1 (4:2:2 or 4:4:4)
568     PROFILE_VP9_2,                              ///< VP9 Profile 2 (4:2:0, 10 or 12 bit)
569     PROFILE_VP9_3,                              ///< VP9 Profile 3 (4:2:2 or 4:4:4, 10 or 12 bit)
570 
571     // Dolby Vision profiles
572     PROFILE_DV_AV_PER = _C2_PL_DV_BASE + 0,     ///< Dolby Vision dvav.per profile (deprecated)
573     PROFILE_DV_AV_PEN,                          ///< Dolby Vision dvav.pen profile (deprecated)
574     PROFILE_DV_HE_DER,                          ///< Dolby Vision dvhe.der profile (deprecated)
575     PROFILE_DV_HE_DEN,                          ///< Dolby Vision dvhe.den profile (deprecated)
576     PROFILE_DV_HE_04 = _C2_PL_DV_BASE + 4,      ///< Dolby Vision dvhe.04 profile
577     PROFILE_DV_HE_05 = _C2_PL_DV_BASE + 5,      ///< Dolby Vision dvhe.05 profile
578     PROFILE_DV_HE_DTH,                          ///< Dolby Vision dvhe.dth profile (deprecated)
579     PROFILE_DV_HE_07 = _C2_PL_DV_BASE + 7,      ///< Dolby Vision dvhe.07 profile
580     PROFILE_DV_HE_08 = _C2_PL_DV_BASE + 8,      ///< Dolby Vision dvhe.08 profile
581     PROFILE_DV_AV_09 = _C2_PL_DV_BASE + 9,      ///< Dolby Vision dvav.09 profile
582     PROFILE_DV_AV1_10 = _C2_PL_DV_BASE + 10,    ///< Dolby Vision dav1.10 profile
583 
584     // AV1 profiles
585     PROFILE_AV1_0 = _C2_PL_AV1_BASE,            ///< AV1 Profile 0 (4:2:0, 8 to 10 bit)
586     PROFILE_AV1_1,                              ///< AV1 Profile 1 (8 to 10 bit)
587     PROFILE_AV1_2,                              ///< AV1 Profile 2 (8 to 12 bit)
588 
589     // VP8 profiles
590     PROFILE_VP8_0 = _C2_PL_VP8_BASE,            ///< VP8 Profile 0
591     PROFILE_VP8_1,                              ///< VP8 Profile 1
592     PROFILE_VP8_2,                              ///< VP8 Profile 2
593     PROFILE_VP8_3,                              ///< VP8 Profile 3
594 
595     // MPEG-H 3D Audio profiles
596     PROFILE_MPEGH_MAIN = _C2_PL_MPEGH_BASE,     ///< MPEG-H Main
597     PROFILE_MPEGH_HIGH,                         ///< MPEG-H High
598     PROFILE_MPEGH_LC,                           ///< MPEG-H Low-complexity
599     PROFILE_MPEGH_BASELINE,                     ///< MPEG-H Baseline
600 };
601 
602 enum C2Config::level_t : uint32_t {
603     LEVEL_UNUSED = 0,                           ///< level is not used by this media type
604 
605     // MPEG-2 Video levels
606     LEVEL_MP2V_LOW = _C2_PL_MP2V_BASE,          ///< MPEG-2 Video (H.262) Low Level
607     LEVEL_MP2V_MAIN,                            ///< MPEG-2 Video (H.262) Main Level
608     LEVEL_MP2V_HIGH_1440,                       ///< MPEG-2 Video (H.262) High 1440 Level
609     LEVEL_MP2V_HIGH,                            ///< MPEG-2 Video (H.262) High Level
610     LEVEL_MP2V_HIGHP,                           ///< MPEG-2 Video (H.262) HighP Level
611 
612     // H.263 levels
613     LEVEL_H263_10 = _C2_PL_H263_BASE,           ///< H.263 Level 10
614     LEVEL_H263_20,                              ///< H.263 Level 20
615     LEVEL_H263_30,                              ///< H.263 Level 30
616     LEVEL_H263_40,                              ///< H.263 Level 40
617     LEVEL_H263_45,                              ///< H.263 Level 45
618     LEVEL_H263_50,                              ///< H.263 Level 50
619     LEVEL_H263_60,                              ///< H.263 Level 60
620     LEVEL_H263_70,                              ///< H.263 Level 70
621 
622     // MPEG-4 Part 2 (Video) levels
623     LEVEL_MP4V_0 = _C2_PL_MP4V_BASE,            ///< MPEG-4 Video Level 0
624     LEVEL_MP4V_0B,                              ///< MPEG-4 Video Level 0b
625     LEVEL_MP4V_1,                               ///< MPEG-4 Video Level 1
626     LEVEL_MP4V_2,                               ///< MPEG-4 Video Level 2
627     LEVEL_MP4V_3,                               ///< MPEG-4 Video Level 3
628     LEVEL_MP4V_3B,                              ///< MPEG-4 Video Level 3b
629     LEVEL_MP4V_4,                               ///< MPEG-4 Video Level 4
630     LEVEL_MP4V_4A,                              ///< MPEG-4 Video Level 4a
631     LEVEL_MP4V_5,                               ///< MPEG-4 Video Level 5
632     LEVEL_MP4V_6,                               ///< MPEG-4 Video Level 6
633 
634     // AVC / MPEG-4 Part 10 (H.264) levels
635     LEVEL_AVC_1 = _C2_PL_AVC_BASE,              ///< AVC (H.264) Level 1
636     LEVEL_AVC_1B,                               ///< AVC (H.264) Level 1b
637     LEVEL_AVC_1_1,                              ///< AVC (H.264) Level 1.1
638     LEVEL_AVC_1_2,                              ///< AVC (H.264) Level 1.2
639     LEVEL_AVC_1_3,                              ///< AVC (H.264) Level 1.3
640     LEVEL_AVC_2,                                ///< AVC (H.264) Level 2
641     LEVEL_AVC_2_1,                              ///< AVC (H.264) Level 2.1
642     LEVEL_AVC_2_2,                              ///< AVC (H.264) Level 2.2
643     LEVEL_AVC_3,                                ///< AVC (H.264) Level 3
644     LEVEL_AVC_3_1,                              ///< AVC (H.264) Level 3.1
645     LEVEL_AVC_3_2,                              ///< AVC (H.264) Level 3.2
646     LEVEL_AVC_4,                                ///< AVC (H.264) Level 4
647     LEVEL_AVC_4_1,                              ///< AVC (H.264) Level 4.1
648     LEVEL_AVC_4_2,                              ///< AVC (H.264) Level 4.2
649     LEVEL_AVC_5,                                ///< AVC (H.264) Level 5
650     LEVEL_AVC_5_1,                              ///< AVC (H.264) Level 5.1
651     LEVEL_AVC_5_2,                              ///< AVC (H.264) Level 5.2
652     LEVEL_AVC_6,                                ///< AVC (H.264) Level 6
653     LEVEL_AVC_6_1,                              ///< AVC (H.264) Level 6.1
654     LEVEL_AVC_6_2,                              ///< AVC (H.264) Level 6.2
655 
656     // HEVC (H.265) tiers and levels
657     LEVEL_HEVC_MAIN_1 = _C2_PL_HEVC_BASE,       ///< HEVC (H.265) Main Tier Level 1
658     LEVEL_HEVC_MAIN_2,                          ///< HEVC (H.265) Main Tier Level 2
659     LEVEL_HEVC_MAIN_2_1,                        ///< HEVC (H.265) Main Tier Level 2.1
660     LEVEL_HEVC_MAIN_3,                          ///< HEVC (H.265) Main Tier Level 3
661     LEVEL_HEVC_MAIN_3_1,                        ///< HEVC (H.265) Main Tier Level 3.1
662     LEVEL_HEVC_MAIN_4,                          ///< HEVC (H.265) Main Tier Level 4
663     LEVEL_HEVC_MAIN_4_1,                        ///< HEVC (H.265) Main Tier Level 4.1
664     LEVEL_HEVC_MAIN_5,                          ///< HEVC (H.265) Main Tier Level 5
665     LEVEL_HEVC_MAIN_5_1,                        ///< HEVC (H.265) Main Tier Level 5.1
666     LEVEL_HEVC_MAIN_5_2,                        ///< HEVC (H.265) Main Tier Level 5.2
667     LEVEL_HEVC_MAIN_6,                          ///< HEVC (H.265) Main Tier Level 6
668     LEVEL_HEVC_MAIN_6_1,                        ///< HEVC (H.265) Main Tier Level 6.1
669     LEVEL_HEVC_MAIN_6_2,                        ///< HEVC (H.265) Main Tier Level 6.2
670 
671     LEVEL_HEVC_HIGH_4 = _C2_PL_HEVC_BASE + 0x100,  ///< HEVC (H.265) High Tier Level 4
672     LEVEL_HEVC_HIGH_4_1,                        ///< HEVC (H.265) High Tier Level 4.1
673     LEVEL_HEVC_HIGH_5,                          ///< HEVC (H.265) High Tier Level 5
674     LEVEL_HEVC_HIGH_5_1,                        ///< HEVC (H.265) High Tier Level 5.1
675     LEVEL_HEVC_HIGH_5_2,                        ///< HEVC (H.265) High Tier Level 5.2
676     LEVEL_HEVC_HIGH_6,                          ///< HEVC (H.265) High Tier Level 6
677     LEVEL_HEVC_HIGH_6_1,                        ///< HEVC (H.265) High Tier Level 6.1
678     LEVEL_HEVC_HIGH_6_2,                        ///< HEVC (H.265) High Tier Level 6.2
679 
680     // VP9 levels
681     LEVEL_VP9_1 = _C2_PL_VP9_BASE,              ///< VP9 Level 1
682     LEVEL_VP9_1_1,                              ///< VP9 Level 1.1
683     LEVEL_VP9_2,                                ///< VP9 Level 2
684     LEVEL_VP9_2_1,                              ///< VP9 Level 2.1
685     LEVEL_VP9_3,                                ///< VP9 Level 3
686     LEVEL_VP9_3_1,                              ///< VP9 Level 3.1
687     LEVEL_VP9_4,                                ///< VP9 Level 4
688     LEVEL_VP9_4_1,                              ///< VP9 Level 4.1
689     LEVEL_VP9_5,                                ///< VP9 Level 5
690     LEVEL_VP9_5_1,                              ///< VP9 Level 5.1
691     LEVEL_VP9_5_2,                              ///< VP9 Level 5.2
692     LEVEL_VP9_6,                                ///< VP9 Level 6
693     LEVEL_VP9_6_1,                              ///< VP9 Level 6.1
694     LEVEL_VP9_6_2,                              ///< VP9 Level 6.2
695 
696     // Dolby Vision levels
697     LEVEL_DV_MAIN_HD_24 = _C2_PL_DV_BASE,       ///< Dolby Vision main tier hd24
698     LEVEL_DV_MAIN_HD_30,                        ///< Dolby Vision main tier hd30
699     LEVEL_DV_MAIN_FHD_24,                       ///< Dolby Vision main tier fhd24
700     LEVEL_DV_MAIN_FHD_30,                       ///< Dolby Vision main tier fhd30
701     LEVEL_DV_MAIN_FHD_60,                       ///< Dolby Vision main tier fhd60
702     LEVEL_DV_MAIN_UHD_24,                       ///< Dolby Vision main tier uhd24
703     LEVEL_DV_MAIN_UHD_30,                       ///< Dolby Vision main tier uhd30
704     LEVEL_DV_MAIN_UHD_48,                       ///< Dolby Vision main tier uhd48
705     LEVEL_DV_MAIN_UHD_60,                       ///< Dolby Vision main tier uhd60
706     LEVEL_DV_MAIN_UHD_120,                      ///< Dolby Vision main tier uhd120
707     LEVEL_DV_MAIN_8K_30,                        ///< Dolby Vision main tier 8k30
708     LEVEL_DV_MAIN_8K_60,                        ///< Dolby Vision main tier 8k60
709 
710     LEVEL_DV_HIGH_HD_24 = _C2_PL_DV_BASE + 0x100,  ///< Dolby Vision high tier hd24
711     LEVEL_DV_HIGH_HD_30,                        ///< Dolby Vision high tier hd30
712     LEVEL_DV_HIGH_FHD_24,                       ///< Dolby Vision high tier fhd24
713     LEVEL_DV_HIGH_FHD_30,                       ///< Dolby Vision high tier fhd30
714     LEVEL_DV_HIGH_FHD_60,                       ///< Dolby Vision high tier fhd60
715     LEVEL_DV_HIGH_UHD_24,                       ///< Dolby Vision high tier uhd24
716     LEVEL_DV_HIGH_UHD_30,                       ///< Dolby Vision high tier uhd30
717     LEVEL_DV_HIGH_UHD_48,                       ///< Dolby Vision high tier uhd48
718     LEVEL_DV_HIGH_UHD_60,                       ///< Dolby Vision high tier uhd60
719     LEVEL_DV_HIGH_UHD_120,                      ///< Dolby Vision high tier uhd120
720     LEVEL_DV_HIGH_8K_30,                        ///< Dolby Vision high tier 8k30
721     LEVEL_DV_HIGH_8K_60,                        ///< Dolby Vision high tier 8k60
722 
723     // AV1 levels
724     LEVEL_AV1_2    = _C2_PL_AV1_BASE ,          ///< AV1 Level 2
725     LEVEL_AV1_2_1,                              ///< AV1 Level 2.1
726     LEVEL_AV1_2_2,                              ///< AV1 Level 2.2
727     LEVEL_AV1_2_3,                              ///< AV1 Level 2.3
728     LEVEL_AV1_3,                                ///< AV1 Level 3
729     LEVEL_AV1_3_1,                              ///< AV1 Level 3.1
730     LEVEL_AV1_3_2,                              ///< AV1 Level 3.2
731     LEVEL_AV1_3_3,                              ///< AV1 Level 3.3
732     LEVEL_AV1_4,                                ///< AV1 Level 4
733     LEVEL_AV1_4_1,                              ///< AV1 Level 4.1
734     LEVEL_AV1_4_2,                              ///< AV1 Level 4.2
735     LEVEL_AV1_4_3,                              ///< AV1 Level 4.3
736     LEVEL_AV1_5,                                ///< AV1 Level 5
737     LEVEL_AV1_5_1,                              ///< AV1 Level 5.1
738     LEVEL_AV1_5_2,                              ///< AV1 Level 5.2
739     LEVEL_AV1_5_3,                              ///< AV1 Level 5.3
740     LEVEL_AV1_6,                                ///< AV1 Level 6
741     LEVEL_AV1_6_1,                              ///< AV1 Level 6.1
742     LEVEL_AV1_6_2,                              ///< AV1 Level 6.2
743     LEVEL_AV1_6_3,                              ///< AV1 Level 6.3
744     LEVEL_AV1_7,                                ///< AV1 Level 7
745     LEVEL_AV1_7_1,                              ///< AV1 Level 7.1
746     LEVEL_AV1_7_2,                              ///< AV1 Level 7.2
747     LEVEL_AV1_7_3,                              ///< AV1 Level 7.3
748 
749     // MPEG-H 3D Audio levels
750     LEVEL_MPEGH_1 = _C2_PL_MPEGH_BASE,          ///< MPEG-H L1
751     LEVEL_MPEGH_2,                              ///< MPEG-H L2
752     LEVEL_MPEGH_3,                              ///< MPEG-H L3
753     LEVEL_MPEGH_4,                              ///< MPEG-H L4
754     LEVEL_MPEGH_5,                              ///< MPEG-H L5
755 };
756 
757 struct C2ProfileLevelStruct {
758     C2Config::profile_t profile;  ///< coding profile
759     C2Config::level_t   level;    ///< coding level
760 
761     C2ProfileLevelStruct(
762             C2Config::profile_t profile_ = C2Config::PROFILE_UNUSED,
763             C2Config::level_t level_ = C2Config::LEVEL_UNUSED)
profileC2ProfileLevelStruct764         : profile(profile_), level(level_) { }
765 
766     DEFINE_AND_DESCRIBE_C2STRUCT(ProfileLevel)
767     C2FIELD(profile, "profile")
768     C2FIELD(level,   "level")
769 };
770 
771 // TODO: may need to make this explicit (have .set member)
772 typedef C2StreamParam<C2Info, C2ProfileLevelStruct, kParamIndexProfileLevel>
773         C2StreamProfileLevelInfo;
774 constexpr char C2_PARAMKEY_PROFILE_LEVEL[] = "coded.pl";
775 
776 /**
777  * Codec-specific initialization data.
778  *
779  * This is initialization data for the codec.
780  *
781  * For AVC/HEVC, these are the concatenated SPS/PPS/VPS NALs.
782  *
783  * TODO: define for other codecs.
784  */
785 typedef C2StreamParam<C2Info, C2BlobValue, kParamIndexInitData> C2StreamInitDataInfo;
786 constexpr char C2_PARAMKEY_INIT_DATA[] = "coded.init-data";
787 
788 /**
789  * Supplemental Data.
790  *
791  * This is coding-specific supplemental informational data, e.g. SEI for AVC/HEVC.
792  * This structure is not a configuration so it does not have a parameter key.
793  * This structure shall be returned in the configuration update, and can be repeated as needed
794  * in the same update.
795  */
796 C2ENUM(C2Config::supplemental_info_t, uint32_t,
797     INFO_NONE = 0,
798 
799     INFO_PREFIX_SEI_UNIT = 0x10000, ///< prefix SEI payload types add this flag
800     INFO_SUFFIX_SEI_UNIT = 0x20000, ///< suffix SEI payload types add this flag
801 
802     INFO_SEI_USER_DATA = INFO_PREFIX_SEI_UNIT | 4,    ///< closed-captioning data (ITU-T T35)
803     INFO_SEI_MDCV      = INFO_PREFIX_SEI_UNIT | 137,  ///< mastering display color volume
804     INFO_SET_USER_DATA_SFX = INFO_SUFFIX_SEI_UNIT | 4, ///< closed-captioning data (ITU-T T35)
805 
806     INFO_VENDOR_START = 0x70000000
807 )
808 
809 struct C2SupplementalDataStruct {
C2SupplementalDataStructC2SupplementalDataStruct810     C2SupplementalDataStruct()
811         : type_(INFO_NONE) { }
812 
C2SupplementalDataStructC2SupplementalDataStruct813     C2SupplementalDataStruct(
814             size_t flexCount, C2Config::supplemental_info_t type, std::vector<uint8_t> data_)
815         : type_(type) {
816             memcpy(data, &data_[0], c2_min(data_.size(), flexCount));
817     }
818 
819     C2Config::supplemental_info_t type_;
820     uint8_t data[];
821 
822     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(SupplementalData, data)
823     C2FIELD(type_, "type")
824     C2FIELD(data, "data")
825 };
826 typedef C2StreamParam<C2Info, C2SupplementalDataStruct, kParamIndexSupplementalData>
827         C2StreamSupplementalDataInfo;
828 
829 /**
830  * Supplemental Data Subscription
831  */
832 typedef C2StreamParam<C2Tuning, C2SimpleArrayStruct<C2Config::supplemental_info_t>,
833                 kParamIndexSubscribedSupplementalData>
834         C2StreamSubscribedSupplementalDataTuning;
835 constexpr char C2_PARAMKEY_SUBSCRIBED_SUPPLEMENTAL_DATA[] = "output.subscribed-supplemental";
836 
837 /* ---------------------------------- pipeline characteristics ---------------------------------- */
838 
839 /**
840  * Media-type.
841  *
842  * This is defined for both port and stream, but stream media type may be a subtype of the
843  * port media type.
844  */
845 typedef C2PortParam<C2Setting, C2StringValue, kParamIndexMediaType> C2PortMediaTypeSetting;
846 constexpr char C2_PARAMKEY_INPUT_MEDIA_TYPE[] = "input.media-type";
847 constexpr char C2_PARAMKEY_OUTPUT_MEDIA_TYPE[] = "output.media-type";
848 
849 typedef C2StreamParam<C2Setting, C2StringValue, kParamIndexMediaType> C2StreamMediaTypeSetting;
850 
851 /**
852  * Pipeline delays.
853  *
854  * Input delay is the number of additional input frames requested by the component to process
855  * an input frame.
856  *
857  * Output delay is the number of additional output frames that need to be generated before an
858  * output can be released by the component.
859  *
860  * Pipeline delay is the number of additional frames that are processed at one time by the
861  * component.
862  *
863  * As these may vary from frame to frame, the number is the maximum required value. E.g. if
864  * input delay is 0, the component is expected to consume each frame queued even if no further
865  * frames are queued. Similarly, if input delay is 1, as long as there are always exactly 2
866  * outstanding input frames queued to the component, it shall produce output.
867  */
868 
869 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexDelay | C2Param::CoreIndex::IS_REQUEST_FLAG>
870         C2PortRequestedDelayTuning;
871 constexpr char C2_PARAMKEY_INPUT_DELAY_REQUEST[] = "input.delay"; // deprecated
872 constexpr char C2_PARAMKEY_OUTPUT_DELAY_REQUEST[] = "output.delay"; // deprecated
873 
874 typedef C2GlobalParam<C2Tuning, C2Uint32Value,
875                 kParamIndexDelay | C2Param::CoreIndex::IS_REQUEST_FLAG>
876         C2RequestedPipelineDelayTuning;
877 constexpr char C2_PARAMKEY_PIPELINE_DELAY_REQUEST[] = "algo.delay"; // deprecated
878 
879 // read-only
880 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexDelay> C2PortDelayTuning;
881 typedef C2PortDelayTuning C2PortActualDelayTuning; // deprecated
882 constexpr char C2_PARAMKEY_INPUT_DELAY[] = "input.delay";
883 constexpr char C2_PARAMKEY_OUTPUT_DELAY[] = "output.delay";
884 
885 // read-only
886 typedef C2GlobalParam<C2Tuning, C2Uint32Value, kParamIndexDelay> C2PipelineDelayTuning;
887 typedef C2PipelineDelayTuning C2ActualPipelineDelayTuning; // deprecated
888 constexpr char C2_PARAMKEY_PIPELINE_DELAY[] = "algo.delay";
889 
890 /**
891  * Enable/disable low latency mode.
892  * If true, low latency is preferred over low power. Disable power optimizations that
893  * may result in increased latency. For decoders, this means that the decoder does not
894  * hold input and output data more than required by the codec standards.
895  */
896 typedef C2GlobalParam<C2Tuning, C2EasyBoolValue, kParamIndexLowLatencyMode>
897         C2GlobalLowLatencyModeTuning;
898 constexpr char C2_PARAMKEY_LOW_LATENCY_MODE[] = "algo.low-latency";
899 
900 /**
901  * Reference characteristics.
902  *
903  * The component may hold onto input and output buffers even after completing the corresponding
904  * work item.
905  *
906  * Max reference age is the longest number of additional frame processing that a component may
907  * hold onto a buffer for. Max reference count is the number of buffers that a component may
908  * hold onto at the same time at the worst case. These numbers assume single frame per buffers.
909  *
910  * Use max-uint32 if there is no limit for the max age or count.
911  */
912 typedef C2StreamParam<C2Tuning, C2Uint32Value, kParamIndexMaxReferenceAge>
913         C2StreamMaxReferenceAgeTuning;
914 constexpr char C2_PARAMKEY_INPUT_MAX_REFERENCE_AGE[] = "input.reference.max-age";
915 constexpr char C2_PARAMKEY_OUTPUT_MAX_REFERENCE_AGE[] = "output.reference.max-age";
916 
917 typedef C2StreamParam<C2Tuning, C2Uint32Value, kParamIndexMaxReferenceCount>
918         C2StreamMaxReferenceCountTuning;
919 constexpr char C2_PARAMKEY_INPUT_MAX_REFERENCE_COUNT[] = "input.reference.max-count";
920 constexpr char C2_PARAMKEY_OUTPUT_MAX_REFERENCE_COUNT[] = "output.reference.max-count";
921 
922 /**
923  * Output reordering.
924  *
925  * The size of the window to use for output buffer reordering. 0 is interpreted as 1.
926  */
927 // output only
928 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexReorderBufferDepth>
929         C2PortReorderBufferDepthTuning;
930 constexpr char C2_PARAMKEY_OUTPUT_REORDER_DEPTH[] = "output.reorder.depth";
931 
932 C2ENUM(C2Config::ordinal_key_t, uint32_t,
933         ORDINAL,
934         TIMESTAMP,
935         CUSTOM)
936 
937 // read-only, output only
938 typedef C2PortParam<C2Setting, C2SimpleValueStruct<C2Config::ordinal_key_t>, kParamIndexReorderKey>
939         C2PortReorderKeySetting;
940 constexpr char C2_PARAMKEY_OUTPUT_REORDER_KEY[] = "output.reorder.key";
941 
942 /**
943  * Stream count.
944  */
945 // private
946 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexStreamCount> C2PortStreamCountTuning;
947 constexpr char C2_PARAMKEY_INPUT_STREAM_COUNT[] = "input.stream-count";
948 constexpr char C2_PARAMKEY_OUTPUT_STREAM_COUNT[] = "output.stream-count";
949 
950 /**
951  * Config update subscription.
952  */
953 // private
954 typedef C2GlobalParam<C2Tuning, C2Uint32Array, kParamIndexSubscribedParamIndices>
955         C2SubscribedParamIndicesTuning;
956 constexpr char C2_PARAMKEY_SUBSCRIBED_PARAM_INDICES[] = "output.subscribed-indices";
957 
958 /**
959  * Suggested buffer (C2Frame) count. This is a suggestion by the component for the number of
960  * input and output frames allocated for the component's use in the buffer pools.
961  *
962  * Component shall set the acceptable range of buffers allocated for it. E.g. client shall
963  * allocate at least the minimum required value.
964  */
965 // read-only
966 typedef C2PortParam<C2Tuning, C2Uint64Array, kParamIndexSuggestedBufferCount>
967         C2PortSuggestedBufferCountTuning;
968 constexpr char C2_PARAMKEY_INPUT_SUGGESTED_BUFFER_COUNT[] = "input.buffers.pool-size";
969 constexpr char C2_PARAMKEY_OUTPUT_SUGGESTED_BUFFER_COUNT[] = "output.buffers.pool-size";
970 
971 /**
972  * Input/output batching.
973  *
974  * For input, component requests that client batches work in batches of specified size. For output,
975  * client requests that the component batches work completion in given batch size.
976  * Value 0 means don't care.
977  */
978 typedef C2PortParam<C2Tuning, C2Uint64Array, kParamIndexBatchSize> C2PortBatchSizeTuning;
979 constexpr char C2_PARAMKEY_INPUT_BATCH_SIZE[] = "input.buffers.batch-size";
980 constexpr char C2_PARAMKEY_OUTPUT_BATCH_SIZE[] = "output.buffers.batch-size";
981 
982 /**
983  * Current & last work ordinals.
984  *
985  * input port: last work queued to component.
986  * output port: last work completed by component.
987  * global: current work.
988  */
989 typedef C2PortParam<C2Tuning, C2WorkOrdinalStruct, kParamIndexLastWorkQueued> C2LastWorkQueuedTuning;
990 typedef C2GlobalParam<C2Tuning, C2WorkOrdinalStruct, kParamIndexCurrentWork> C2CurrentWorkTuning;
991 
992 
993 /* ------------------------------------- memory allocation ------------------------------------- */
994 
995 /**
996  * Allocators to use.
997  *
998  * These are requested by the component.
999  *
1000  * If none specified, client will use the default allocator ID based on the component domain and
1001  * kind.
1002  */
1003 typedef C2PortParam<C2Tuning, C2SimpleArrayStruct<C2Allocator::id_t>, kParamIndexAllocators>
1004         C2PortAllocatorsTuning;
1005 constexpr char C2_PARAMKEY_INPUT_ALLOCATORS[] = "input.buffers.allocator-ids";
1006 constexpr char C2_PARAMKEY_OUTPUT_ALLOCATORS[] = "output.buffers.allocator-ids";
1007 
1008 typedef C2GlobalParam<C2Tuning, C2SimpleArrayStruct<C2Allocator::id_t>, kParamIndexAllocators>
1009         C2PrivateAllocatorsTuning;
1010 constexpr char C2_PARAMKEY_PRIVATE_ALLOCATORS[] = "algo.buffers.allocator-ids";
1011 
1012 /**
1013  * Allocator to use for outputting to surface.
1014  *
1015  * Components can optionally request allocator type for outputting to surface.
1016  *
1017  * If none specified, client will use the default BufferQueue-backed allocator ID for outputting to
1018  * surface.
1019  */
1020 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexSurfaceAllocator>
1021         C2PortSurfaceAllocatorTuning;
1022 constexpr char C2_PARAMKEY_OUTPUT_SURFACE_ALLOCATOR[] = "output.buffers.surface-allocator-id";
1023 
1024 /**
1025  * Block pools to use.
1026  *
1027  * These are allocated by the client for the component using the allocator IDs specified by the
1028  * component. This is not used for the input port.
1029  */
1030 typedef C2PortParam<C2Tuning, C2SimpleArrayStruct<C2BlockPool::local_id_t>, kParamIndexBlockPools>
1031         C2PortBlockPoolsTuning;
1032 constexpr char C2_PARAMKEY_OUTPUT_BLOCK_POOLS[] = "output.buffers.pool-ids";
1033 
1034 typedef C2GlobalParam<C2Tuning, C2SimpleArrayStruct<C2BlockPool::local_id_t>, kParamIndexBlockPools>
1035         C2PrivateBlockPoolsTuning;
1036 constexpr char C2_PARAMKEY_PRIVATE_BLOCK_POOLS[] = "algo.buffers.pool-ids";
1037 
1038 /**
1039  * The max number of private allocations at any one time by the component.
1040  * (This is an array with a corresponding value for each private allocator)
1041  */
1042 typedef C2GlobalParam<C2Tuning, C2Uint32Array, kParamIndexMaxReferenceCount>
1043         C2MaxPrivateBufferCountTuning;
1044 constexpr char C2_PARAMKEY_MAX_PRIVATE_BUFFER_COUNT[] = "algo.buffers.max-count";
1045 
1046 /**
1047  * Buffer type
1048  *
1049  * This is provided by the component for the client to allocate the proper buffer type for the
1050  * input port, and can be provided by the client to control the buffer type for the output.
1051  */
1052 // private
1053 typedef C2StreamParam<C2Setting, C2SimpleValueStruct<C2EasyEnum<C2BufferData::type_t>>,
1054                 kParamIndexBufferType>
1055         C2StreamBufferTypeSetting;
1056 constexpr char C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE[] = "input.buffers.type";
1057 constexpr char C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE[] = "output.buffers.type";
1058 
1059 /**
1060  * Memory usage.
1061  *
1062  * Suggested by component for input and negotiated between client and component for output.
1063  */
1064 typedef C2StreamParam<C2Tuning, C2Uint64Value, kParamIndexUsage> C2StreamUsageTuning;
1065 constexpr char C2_PARAMKEY_INPUT_STREAM_USAGE[] = "input.buffers.usage";
1066 constexpr char C2_PARAMKEY_OUTPUT_STREAM_USAGE[] = "output.buffers.usage";
1067 
1068 /**
1069  * Picture (video or image frame) size.
1070  */
1071 struct C2PictureSizeStruct {
C2PictureSizeStructC2PictureSizeStruct1072     inline C2PictureSizeStruct()
1073         : width(0), height(0) { }
1074 
C2PictureSizeStructC2PictureSizeStruct1075     inline C2PictureSizeStruct(uint32_t width_, uint32_t height_)
1076         : width(width_), height(height_) { }
1077 
1078     uint32_t width;     ///< video width
1079     uint32_t height;    ///< video height
1080 
1081     DEFINE_AND_DESCRIBE_C2STRUCT(PictureSize)
1082     C2FIELD(width, "width")
1083     C2FIELD(height, "height")
1084 };
1085 
1086 /**
1087  * Out of memory signaling
1088  *
1089  * This is a configuration for the client to mark that it cannot allocate necessary private and/
1090  * or output buffers to continue operation, and to signal the failing configuration.
1091  */
1092 struct C2OutOfMemoryStruct {
1093     C2BlockPool::local_id_t pool;   ///< pool ID that failed the allocation
1094     uint64_t usage;                 ///< memory usage used
1095     C2PictureSizeStruct planar;     ///< buffer dimensions to be allocated if 2D
1096     uint32_t format;                ///< pixel format to be used if 2D
1097     uint32_t capacity;              ///< buffer capacity to be allocated if 1D
1098     c2_bool_t outOfMemory;           ///< true if component is out of memory
1099 
1100     DEFINE_AND_DESCRIBE_C2STRUCT(OutOfMemory)
1101     C2FIELD(pool, "pool")
1102     C2FIELD(usage, "usage")
1103     C2FIELD(planar, "planar")
1104     C2FIELD(format, "format")
1105     C2FIELD(capacity, "capacity")
1106     C2FIELD(outOfMemory, "out-of-memory")
1107 };
1108 
1109 typedef C2GlobalParam<C2Tuning, C2OutOfMemoryStruct, kParamIndexOutOfMemory> C2OutOfMemoryTuning;
1110 constexpr char C2_PARAMKEY_OUT_OF_MEMORY[] = "algo.oom";
1111 
1112 /**
1113  * Max buffer size
1114  *
1115  * This is a hint provided by the component for the maximum buffer size expected on a stream for the
1116  * current configuration on its input and output streams. This is communicated to clients so they
1117  * can preallocate input buffers, or configure downstream components that require a maximum size on
1118  * their buffers.
1119  *
1120  * Read-only. Required to be provided by components on all compressed streams.
1121  */
1122 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexMaxBufferSize> C2StreamMaxBufferSizeInfo;
1123 constexpr char C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE[] = "input.buffers.max-size";
1124 constexpr char C2_PARAMKEY_OUTPUT_MAX_BUFFER_SIZE[] = "output.buffers.max-size";
1125 
1126 /**
1127  * Large frame struct
1128  *
1129  * This structure describes the size limits for large frames (frames with multiple
1130  * access units.)
1131  */
1132 struct C2LargeFrameStruct {
1133     uint32_t maxSize;         ///< maximum size of the buffer in bytes
1134     uint32_t thresholdSize;   ///< size threshold for the buffer in bytes. The buffer is considered
1135                               ///< full as soon as its size reaches or surpasses this limit.
C2LargeFrameStructC2LargeFrameStruct1136     C2LargeFrameStruct()
1137         : maxSize(0),
1138           thresholdSize(0) {}
1139 
C2LargeFrameStructC2LargeFrameStruct1140     C2LargeFrameStruct(uint32_t maxSize_, uint32_t thresholdSize_)
1141         : maxSize(maxSize_), thresholdSize(thresholdSize_) {}
1142 
1143     DEFINE_AND_DESCRIBE_C2STRUCT(LargeFrame)
1144     C2FIELD(maxSize, "max-size")
1145     C2FIELD(thresholdSize, "threshold-size")
1146 };
1147 
1148 /**
1149  * This tuning controls the size limits for large output frames for the component.
1150  * The default value for this tuning is platform specific.
1151  */
1152 typedef C2StreamParam<C2Tuning, C2LargeFrameStruct, kParamIndexLargeFrame>
1153         C2LargeFrame;
1154 constexpr char C2_PARAMKEY_OUTPUT_LARGE_FRAME[] = "output.large-frame";
1155 
1156 /* ---------------------------------------- misc. state ---------------------------------------- */
1157 
1158 /**
1159  * Tripped state,
1160  *
1161  * This state exists to be able to provide reasoning for a tripped state during normal
1162  * interface operations, as well as to allow client to trip the component on demand.
1163  */
1164 typedef C2GlobalParam<C2Tuning, C2BoolValue, kParamIndexTripped>
1165         C2TrippedTuning;
1166 constexpr char C2_PARAMKEY_TRIPPED[] = "algo.tripped";
1167 
1168 /**
1169  * Configuration counters.
1170  *
1171  * Configurations are tracked using three counters. The input counter is incremented exactly
1172  * once with each work accepted by the component. The output counter is incremented exactly
1173  * once with each work completed by the component (in the order of work completion). The
1174  * global counter is incremented exactly once during to each config() call. These counters
1175  * shall be read-only.
1176  *
1177  * TODO: these should be counters.
1178  */
1179 typedef C2PortParam<C2Tuning, C2Uint64Value, kParamIndexConfigCounter> C2PortConfigCounterTuning;
1180 typedef C2GlobalParam<C2Tuning, C2Uint64Value, kParamIndexConfigCounter> C2ConfigCounterTuning;
1181 constexpr char C2_PARAMKEY_INPUT_COUNTER[] = "input.buffers.counter";
1182 constexpr char C2_PARAMKEY_OUTPUT_COUNTER[] = "output.buffers.counter";
1183 constexpr char C2_PARAMKEY_CONFIG_COUNTER[] = "algo.config.counter";
1184 
1185 /* ----------------------------------------- resources ----------------------------------------- */
1186 
1187 /**
1188  * Resources needed and resources reserved for current configuration.
1189  *
1190  * Resources are tracked as a vector of positive numbers. Available resources are defined by
1191  * the vendor.
1192  *
1193  * By default, no resources are reserved for a component. If resource reservation is successful,
1194  * the component shall be able to use those resources exclusively. If however, the component is
1195  * not using all of the reserved resources, those may be shared with other components.
1196  *
1197  * TODO: define some of the resources.
1198  */
1199 typedef C2GlobalParam<C2Tuning, C2Uint64Array, kParamIndexResourcesNeeded> C2ResourcesNeededTuning;
1200 typedef C2GlobalParam<C2Tuning, C2Uint64Array, kParamIndexResourcesReserved>
1201         C2ResourcesReservedTuning;
1202 constexpr char C2_PARAMKEY_RESOURCES_NEEDED[] = "resources.needed";
1203 constexpr char C2_PARAMKEY_RESOURCES_RESERVED[] = "resources.reserved";
1204 
1205 /**
1206  * Operating rate.
1207  *
1208  * Operating rate is the expected rate of work through the component. Negative values is
1209  * invalid.
1210  *
1211  * TODO: this could distinguish set value
1212  */
1213 typedef C2GlobalParam<C2Tuning, C2FloatValue, kParamIndexOperatingRate> C2OperatingRateTuning;
1214 constexpr char C2_PARAMKEY_OPERATING_RATE[] = "algo.rate";
1215 
1216 /**
1217  * Realtime / operating point.
1218  *
1219  * Priority value defines the operating point for the component. Operating points are defined by
1220  * the vendor. Priority value of 0 means that the client requires operation at the given operating
1221  * rate. Priority values -1 and below define operating points in decreasing performance. In this
1222  * case client expects best effort without exceeding the specific operating point. This allows
1223  * client to run components deeper in the background by using larger priority values. In these
1224  * cases operating rate is a hint for the maximum rate that the client anticipates.
1225  *
1226  * Operating rate and priority are used in tandem. E.g. if there are components that run at a
1227  * higher operating point (priority) it will make more resources available for components at
1228  * a lower operating point, so operating rate can be used to gate those components.
1229  *
1230  * Positive priority values are not defined at the moment and shall be treated equivalent to 0.
1231  */
1232 typedef C2GlobalParam<C2Tuning, C2Int32Value, kParamIndexRealTimePriority>
1233         C2RealTimePriorityTuning;
1234 constexpr char C2_PARAMKEY_PRIORITY[] = "algo.priority";
1235 
1236 /* ------------------------------------- protected content ------------------------------------- */
1237 
1238 /**
1239  * Secure mode.
1240  */
1241 C2ENUM(C2Config::secure_mode_t, uint32_t,
1242     SM_UNPROTECTED,    ///< no content protection
1243     SM_READ_PROTECTED, ///< input and output buffers shall be protected from reading
1244     /// both read protected and readable encrypted buffers are used
1245     SM_READ_PROTECTED_WITH_ENCRYPTED,
1246 )
1247 
1248 typedef C2GlobalParam<C2Tuning, C2SimpleValueStruct<C2Config::secure_mode_t>, kParamIndexSecureMode>
1249         C2SecureModeTuning;
1250 constexpr char C2_PARAMKEY_SECURE_MODE[] = "algo.secure-mode";
1251 
1252 /* ===================================== ENCODER COMPONENTS ===================================== */
1253 
1254 /**
1255  * Bitrate
1256  */
1257 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexBitrate> C2StreamBitrateInfo;
1258 constexpr char C2_PARAMKEY_BITRATE[] = "coded.bitrate";
1259 
1260 /**
1261  * Bitrate mode.
1262  *
1263  * TODO: refine this with bitrate ranges and suggested window
1264  */
1265 C2ENUM(C2Config::bitrate_mode_t, uint32_t,
1266     BITRATE_CONST_SKIP_ALLOWED = 0,      ///< constant bitrate, frame skipping allowed
1267     BITRATE_CONST = 1,                   ///< constant bitrate, keep all frames
1268     BITRATE_VARIABLE_SKIP_ALLOWED = 2,   ///< bitrate can vary, frame skipping allowed
1269     BITRATE_VARIABLE = 3,                ///< bitrate can vary, keep all frames
1270     BITRATE_IGNORE = 7,                  ///< bitrate can be exceeded at will to achieve
1271                                          ///< quality or other settings
1272 
1273     // bitrate modes are composed of the following flags
1274     BITRATE_FLAG_KEEP_ALL_FRAMES = 1,
1275     BITRATE_FLAG_CAN_VARY = 2,
1276     BITRATE_FLAG_CAN_EXCEED = 4,
1277 )
1278 
1279 typedef C2StreamParam<C2Tuning, C2SimpleValueStruct<C2Config::bitrate_mode_t>,
1280                 kParamIndexBitrateMode>
1281         C2StreamBitrateModeTuning;
1282 constexpr char C2_PARAMKEY_BITRATE_MODE[] = "algo.bitrate-mode";
1283 
1284 /**
1285  * Quality.
1286  *
1287  * This is defined by each component, the higher the better the output quality at the expense of
1288  * less compression efficiency. This setting is defined for the output streams in case the
1289  * component can support varying quality on each stream, or as an output port tuning in case the
1290  * quality is global to all streams.
1291  */
1292 typedef C2StreamParam<C2Tuning, C2Uint32Value, kParamIndexQuality> C2StreamQualityTuning;
1293 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexQuality> C2QualityTuning;
1294 constexpr char C2_PARAMKEY_QUALITY[] = "algo.quality";
1295 
1296 /**
1297  * Complexity.
1298  *
1299  * This is defined by each component, this higher the value, the more resources the component
1300  * will use to produce better quality at the same compression efficiency or better compression
1301  * efficiency at the same quality. This setting is defined for the output streams in case the
1302  * component can support varying complexity on each stream, or as an output port tuning in case the
1303  * quality is global to all streams
1304  */
1305 typedef C2StreamParam<C2Tuning, C2Uint32Value, kParamIndexComplexity> C2StreamComplexityTuning;
1306 typedef C2PortParam<C2Tuning, C2Uint32Value, kParamIndexComplexity> C2ComplexityTuning;
1307 constexpr char C2_PARAMKEY_COMPLEXITY[] = "algo.complexity";
1308 
1309 /**
1310  * Header (init-data) handling around sync frames.
1311  */
1312 C2ENUM(C2Config::prepend_header_mode_t, uint32_t,
1313     /**
1314      * don't prepend header. Signal header only through C2StreamInitDataInfo.
1315      */
1316     PREPEND_HEADER_TO_NONE,
1317 
1318     /**
1319      * prepend header before the first output frame and thereafter before the next sync frame
1320      * if it changes.
1321      */
1322     PREPEND_HEADER_ON_CHANGE,
1323 
1324     /**
1325      * prepend header before every sync frame.
1326      */
1327     PREPEND_HEADER_TO_ALL_SYNC,
1328 )
1329 
1330 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Config::prepend_header_mode_t>,
1331                 kParamIndexPrependHeaderMode>
1332         C2PrependHeaderModeSetting;
1333 constexpr char C2_PARAMKEY_PREPEND_HEADER_MODE[] = "output.buffers.prepend-header";
1334 
1335 /* =================================== IMAGE/VIDEO COMPONENTS =================================== */
1336 
1337 /*
1338  * Order of transformation is:
1339  *
1340  * crop => (scaling => scaled-crop) => sample-aspect-ratio => flip => rotation
1341  */
1342 
1343 /**
1344  * Picture (image- and video frame) size.
1345  *
1346  * This is used for the output of the video decoder, and the input of the video encoder.
1347  */
1348 typedef C2StreamParam<C2Info, C2PictureSizeStruct, kParamIndexPictureSize> C2StreamPictureSizeInfo;
1349 constexpr char C2_PARAMKEY_PICTURE_SIZE[] = "raw.size";
1350 
1351 /**
1352  * Crop rectangle.
1353  */
1354 struct C2RectStruct : C2Rect {
1355     C2RectStruct() = default;
C2RectStructC2RectStruct1356     C2RectStruct(const C2Rect &rect) : C2Rect(rect) { }
1357 
1358     bool operator==(const C2RectStruct &) = delete;
1359     bool operator!=(const C2RectStruct &) = delete;
1360 
1361     DEFINE_AND_DESCRIBE_BASE_C2STRUCT(Rect)
1362     C2FIELD(width, "width")
1363     C2FIELD(height, "height")
1364     C2FIELD(left, "left")
1365     C2FIELD(top, "top")
1366 };
1367 
1368 typedef C2StreamParam<C2Info, C2RectStruct, kParamIndexCropRect> C2StreamCropRectInfo;
1369 constexpr char C2_PARAMKEY_CROP_RECT[] = "raw.crop";
1370 constexpr char C2_PARAMKEY_CODED_CROP_RECT[] = "coded.crop";
1371 
1372 /**
1373  * Pixel format.
1374  */
1375 // TODO: define some
1376 
1377 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexPixelFormat> C2StreamPixelFormatInfo;
1378 constexpr char C2_PARAMKEY_PIXEL_FORMAT[] = "raw.pixel-format";
1379 
1380 /**
1381  * Extended rotation information also incorporating a flip.
1382  *
1383  * Rotation is counter clock-wise.
1384  */
1385 struct C2RotationStruct {
1386     C2RotationStruct(int32_t rotation = 0)
1387         : flip(0), value(rotation) { }
1388 
1389     int32_t flip;   ///< horizontal flip (left-right flip applied prior to rotation)
1390     int32_t value;  ///< rotation in degrees counter clockwise
1391 
1392     DEFINE_AND_DESCRIBE_BASE_C2STRUCT(Rotation)
1393     C2FIELD(flip, "flip")
1394     C2FIELD(value, "value")
1395 };
1396 
1397 typedef C2StreamParam<C2Info, C2RotationStruct, kParamIndexRotation> C2StreamRotationInfo;
1398 constexpr char C2_PARAMKEY_ROTATION[] = "raw.rotation";
1399 constexpr char C2_PARAMKEY_VUI_ROTATION[] = "coded.vui.rotation";
1400 
1401 /**
1402  * Region of Interest of an image/video frame communicated as an array of C2QpOffsetRectStruct
1403  *
1404  * Fields width, height, left and top of C2QpOffsetRectStruct form a bounding box contouring RoI.
1405  * Field qpOffset of C2QpOffsetRectStruct indicates the qp bias to be used for quantizing the
1406  * coding units of the bounding box.
1407  *
1408  * If Roi rect is not valid that is bounding box width is < 0 or bounding box height is < 0,
1409  * components may ignore the configuration silently. If Roi rect extends outside frame
1410  * boundaries, then rect shall be clamped to the frame boundaries.
1411  *
1412  * The scope of this key is throughout the encoding session until it is reconfigured with a
1413  * different value.
1414  *
1415  * The number of elements in C2StreamQpOffset array is not limited by C2 specification.
1416  * However components may mandate a limit. Implementations may drop the rectangles that are beyond
1417  * the supported limits. Hence it is preferable to place the rects in descending order of
1418  * importance. Transitively, if the bounding boxes overlap, then the most preferred
1419  * rectangle's qp offset (earlier rectangle qp offset) will be used to quantize the block.
1420  */
1421 struct C2QpOffsetRectStruct : C2Rect {
1422     C2QpOffsetRectStruct() = default;
C2QpOffsetRectStructC2QpOffsetRectStruct1423     C2QpOffsetRectStruct(const C2Rect &rect, int32_t offset) : C2Rect(rect), qpOffset(offset) {}
1424 
1425     bool operator==(const C2QpOffsetRectStruct &) = delete;
1426     bool operator!=(const C2QpOffsetRectStruct &) = delete;
1427 
1428     int32_t qpOffset;
1429 
1430     DEFINE_AND_DESCRIBE_C2STRUCT(QpOffsetRect)
1431     C2FIELD(width, "width")
1432     C2FIELD(height, "height")
1433     C2FIELD(left, "left")
1434     C2FIELD(top, "top")
1435     C2FIELD(qpOffset, "qp-offset")
1436 };
1437 
1438 typedef C2StreamParam<C2Info, C2SimpleArrayStruct<C2QpOffsetRectStruct>, kParamIndexQpOffsetRects>
1439         C2StreamQpOffsetRects;
1440 constexpr char C2_PARAMKEY_QP_OFFSET_RECTS[] = "coding.qp-offset-rects";
1441 
1442 /**
1443  * Pixel (sample) aspect ratio.
1444  */
1445 typedef C2StreamParam<C2Info, C2PictureSizeStruct, kParamIndexPixelAspectRatio>
1446         C2StreamPixelAspectRatioInfo;
1447 constexpr char C2_PARAMKEY_PIXEL_ASPECT_RATIO[] = "raw.sar";
1448 constexpr char C2_PARAMKEY_VUI_PIXEL_ASPECT_RATIO[] = "coded.vui.sar";
1449 
1450 /**
1451  * In-line scaling.
1452  *
1453  * Components can optionally support scaling of raw image/video frames.  Or scaling only a
1454  * portion of raw image/video frames (scaled-crop).
1455  */
1456 
1457 C2ENUM(C2Config::scaling_method_t, uint32_t,
1458     SCALING_ARBITRARY,   ///< arbitrary, unspecified
1459 )
1460 
1461 typedef C2StreamParam<C2Tuning, C2SimpleValueStruct<C2Config::scaling_method_t>,
1462                 kParamIndexScalingMethod>
1463         C2StreamScalingMethodTuning;
1464 constexpr char C2_PARAMKEY_SCALING_MODE[] = "raw.scaling-method";
1465 
1466 typedef C2StreamParam<C2Tuning, C2PictureSizeStruct, kParamIndexScaledPictureSize>
1467         C2StreamScaledPictureSizeTuning;
1468 constexpr char C2_PARAMKEY_SCALED_PICTURE_SIZE[] = "raw.scaled-size";
1469 
1470 typedef C2StreamParam<C2Tuning, C2RectStruct, kParamIndexScaledCropRect>
1471         C2StreamScaledCropRectTuning;
1472 constexpr char C2_PARAMKEY_SCALED_CROP_RECT[] = "raw.scaled-crop";
1473 
1474 /* ------------------------------------- color information ------------------------------------- */
1475 
1476 /**
1477  * Color Info
1478  *
1479  * Chroma location can vary for top and bottom fields, so use an array, that can have 0 to 2
1480  * values. Empty array is used for non YUV formats.
1481  */
1482 
1483 struct C2Color {
1484     enum matrix_t : uint32_t;  ///< matrix coefficient (YUV <=> RGB)
1485     enum plane_layout_t : uint32_t;  ///< plane layout for flexible formats
1486     enum primaries_t : uint32_t;  ///< color primaries and white point
1487     enum range_t : uint32_t;  ///< range of color component values
1488     enum subsampling_t : uint32_t;  ///< chroma subsampling
1489     enum transfer_t : uint32_t;  ///< transfer function
1490 };
1491 
1492 /// Chroma subsampling
1493 C2ENUM(C2Color::subsampling_t, uint32_t,
1494     MONOCHROME,     ///< there are no Cr nor Cb planes
1495     MONOCHROME_ALPHA, ///< there are no Cr nor Cb planes, but there is an alpha plane
1496     RGB,            ///< RGB
1497     RGBA,           ///< RGBA
1498     YUV_420,        ///< Cr and Cb planes are subsampled by 2 both horizontally and vertically
1499     YUV_422,        ///< Cr and Cb planes are subsampled horizontally
1500     YUV_444,        ///< Cr and Cb planes are not subsampled
1501     YUVA_444,       ///< Cr and Cb planes are not subsampled, there is an alpha plane
1502 )
1503 
1504 struct C2ChromaOffsetStruct {
1505     // chroma offsets defined by ITU
ITU_YUV_444C2ChromaOffsetStruct1506     constexpr static C2ChromaOffsetStruct ITU_YUV_444() { return { 0.0f, 0.0f }; }
ITU_YUV_422C2ChromaOffsetStruct1507     constexpr static C2ChromaOffsetStruct ITU_YUV_422() { return { 0.0f, 0.0f }; }
ITU_YUV_420_0C2ChromaOffsetStruct1508     constexpr static C2ChromaOffsetStruct ITU_YUV_420_0() { return { 0.0f, 0.5f }; }
ITU_YUV_420_1C2ChromaOffsetStruct1509     constexpr static C2ChromaOffsetStruct ITU_YUV_420_1() { return { 0.5f, 0.5f }; }
ITU_YUV_420_2C2ChromaOffsetStruct1510     constexpr static C2ChromaOffsetStruct ITU_YUV_420_2() { return { 0.0f, 0.0f }; }
ITU_YUV_420_3C2ChromaOffsetStruct1511     constexpr static C2ChromaOffsetStruct ITU_YUV_420_3() { return { 0.5f, 0.0f }; }
ITU_YUV_420_4C2ChromaOffsetStruct1512     constexpr static C2ChromaOffsetStruct ITU_YUV_420_4() { return { 0.0f, 1.0f }; }
ITU_YUV_420_5C2ChromaOffsetStruct1513     constexpr static C2ChromaOffsetStruct ITU_YUV_420_5() { return { 0.5f, 1.0f }; }
1514 
1515     float x;    ///< x offset in pixels (towards right)
1516     float y;    ///< y offset in pixels (towards down)
1517 
1518     DEFINE_AND_DESCRIBE_C2STRUCT(ChromaOffset)
1519     C2FIELD(x, "x")
1520     C2FIELD(y, "y")
1521 };
1522 
1523 struct C2ColorInfoStruct {
C2ColorInfoStructC2ColorInfoStruct1524     C2ColorInfoStruct()
1525         : bitDepth(8), subsampling(C2Color::YUV_420) { }
1526 
1527     uint32_t bitDepth;
1528     C2Color::subsampling_t subsampling;
1529     C2ChromaOffsetStruct locations[]; // max 2 elements
1530 
C2ColorInfoStructC2ColorInfoStruct1531     C2ColorInfoStruct(
1532             size_t /* flexCount */, uint32_t bitDepth_, C2Color::subsampling_t subsampling_)
1533         : bitDepth(bitDepth_), subsampling(subsampling_) { }
1534 
C2ColorInfoStructC2ColorInfoStruct1535     C2ColorInfoStruct(
1536             size_t flexCount, uint32_t bitDepth_, C2Color::subsampling_t subsampling_,
1537             std::initializer_list<C2ChromaOffsetStruct> locations_)
1538         : bitDepth(bitDepth_), subsampling(subsampling_) {
1539         size_t ix = 0;
1540         for (const C2ChromaOffsetStruct &location : locations_) {
1541             if (ix == flexCount) {
1542                 break;
1543             }
1544             locations[ix] = location;
1545             ++ix;
1546         }
1547     }
1548 
1549     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(ColorInfo, locations)
1550     C2FIELD(bitDepth, "bit-depth")
1551     C2FIELD(subsampling, "subsampling")
1552     C2FIELD(locations, "locations")
1553 };
1554 
1555 typedef C2StreamParam<C2Info, C2ColorInfoStruct, kParamIndexColorInfo> C2StreamColorInfo;
1556 constexpr char C2_PARAMKEY_COLOR_INFO[] = "raw.color-format";
1557 constexpr char C2_PARAMKEY_CODED_COLOR_INFO[] = "coded.color-format";
1558 
1559 /**
1560  * Color Aspects
1561  */
1562 
1563 /* The meaning of the following enumerators is as described in ITU-T H.273. */
1564 
1565 /// Range
1566 C2ENUM(C2Color::range_t, uint32_t,
1567     RANGE_UNSPECIFIED,          ///< range is unspecified
1568     RANGE_FULL,                 ///< full range
1569     RANGE_LIMITED,              ///< limited range
1570 
1571     RANGE_VENDOR_START = 0x80,  ///< vendor-specific range values start here
1572     RANGE_OTHER = 0XFF          ///< max value, reserved for undefined values
1573 )
1574 
1575 /// Color primaries
1576 C2ENUM(C2Color::primaries_t, uint32_t,
1577     PRIMARIES_UNSPECIFIED,          ///< primaries are unspecified
1578     PRIMARIES_BT709,                ///< Rec.ITU-R BT.709-6 or equivalent
1579     PRIMARIES_BT470_M,              ///< Rec.ITU-R BT.470-6 System M or equivalent
1580     PRIMARIES_BT601_625,            ///< Rec.ITU-R BT.601-6 625 or equivalent
1581     PRIMARIES_BT601_525,            ///< Rec.ITU-R BT.601-6 525 or equivalent
1582     PRIMARIES_GENERIC_FILM,         ///< Generic Film
1583     PRIMARIES_BT2020,               ///< Rec.ITU-R BT.2020 or equivalent
1584     PRIMARIES_RP431,                ///< SMPTE RP 431-2 or equivalent
1585     PRIMARIES_EG432,                ///< SMPTE EG 432-1 or equivalent
1586     PRIMARIES_EBU3213,              ///< EBU Tech.3213-E or equivalent
1587                                     ///
1588     PRIMARIES_VENDOR_START = 0x80,  ///< vendor-specific primaries values start here
1589     PRIMARIES_OTHER = 0xff          ///< max value, reserved for undefined values
1590 )
1591 
1592 /// Transfer function
1593 C2ENUM(C2Color::transfer_t, uint32_t,
1594     TRANSFER_UNSPECIFIED,           ///< transfer is unspecified
1595     TRANSFER_LINEAR,                ///< Linear transfer characteristics
1596     TRANSFER_SRGB,                  ///< sRGB or equivalent
1597     TRANSFER_170M,                  ///< SMPTE 170M or equivalent (e.g. BT.601/709/2020)
1598     TRANSFER_GAMMA22,               ///< Assumed display gamma 2.2
1599     TRANSFER_GAMMA28,               ///< Assumed display gamma 2.8
1600     TRANSFER_ST2084,                ///< SMPTE ST 2084 for 10/12/14/16 bit systems
1601     TRANSFER_HLG,                   ///< ARIB STD-B67 hybrid-log-gamma
1602 
1603     TRANSFER_240M = 0x40,           ///< SMPTE 240M or equivalent
1604     TRANSFER_XVYCC,                 ///< IEC 61966-2-4 or equivalent
1605     TRANSFER_BT1361,                ///< Rec.ITU-R BT.1361 extended gamut
1606     TRANSFER_ST428,                 ///< SMPTE ST 428-1 or equivalent
1607                                     ///
1608     TRANSFER_VENDOR_START = 0x80,   ///< vendor-specific transfer values start here
1609     TRANSFER_OTHER = 0xff           ///< max value, reserved for undefined values
1610 )
1611 
1612 /// Matrix coefficient
1613 C2ENUM(C2Color::matrix_t, uint32_t,
1614     MATRIX_UNSPECIFIED,             ///< matrix coefficients are unspecified
1615     MATRIX_BT709,                   ///< Rec.ITU-R BT.709-5 or equivalent
1616     MATRIX_FCC47_73_682,            ///< FCC Title 47 CFR 73.682 or equivalent (KR=0.30, KB=0.11)
1617     MATRIX_BT601,                   ///< Rec.ITU-R BT.470, BT.601-6 625 or equivalent
1618     MATRIX_240M,                    ///< SMPTE 240M or equivalent
1619     MATRIX_BT2020,                  ///< Rec.ITU-R BT.2020 non-constant luminance
1620     MATRIX_BT2020_CONSTANT,         ///< Rec.ITU-R BT.2020 constant luminance
1621     MATRIX_VENDOR_START = 0x80,     ///< vendor-specific matrix coefficient values start here
1622     MATRIX_OTHER = 0xff,            ///< max value, reserved for undefined values
1623 )
1624 
1625 struct C2ColorAspectsStruct {
1626     C2Color::range_t range;
1627     C2Color::primaries_t primaries;
1628     C2Color::transfer_t transfer;
1629     C2Color::matrix_t matrix;
1630 
C2ColorAspectsStructC2ColorAspectsStruct1631     C2ColorAspectsStruct()
1632         : range(C2Color::RANGE_UNSPECIFIED),
1633           primaries(C2Color::PRIMARIES_UNSPECIFIED),
1634           transfer(C2Color::TRANSFER_UNSPECIFIED),
1635           matrix(C2Color::MATRIX_UNSPECIFIED) { }
1636 
C2ColorAspectsStructC2ColorAspectsStruct1637     C2ColorAspectsStruct(C2Color::range_t range_, C2Color::primaries_t primaries_,
1638                          C2Color::transfer_t transfer_, C2Color::matrix_t matrix_)
1639         : range(range_), primaries(primaries_), transfer(transfer_), matrix(matrix_) {}
1640 
1641     DEFINE_AND_DESCRIBE_C2STRUCT(ColorAspects)
1642     C2FIELD(range, "range")
1643     C2FIELD(primaries, "primaries")
1644     C2FIELD(transfer, "transfer")
1645     C2FIELD(matrix, "matrix")
1646 };
1647 
1648 typedef C2StreamParam<C2Info, C2ColorAspectsStruct, kParamIndexColorAspects>
1649         C2StreamColorAspectsInfo;
1650 constexpr char C2_PARAMKEY_COLOR_ASPECTS[] = "raw.color";
1651 constexpr char C2_PARAMKEY_VUI_COLOR_ASPECTS[] = "coded.vui.color";
1652 
1653 /**
1654  * Default color aspects to use. These come from the container or client and shall be handled
1655  * according to the coding standard.
1656  */
1657 typedef C2StreamParam<C2Tuning, C2ColorAspectsStruct, kParamIndexDefaultColorAspects>
1658         C2StreamColorAspectsTuning;
1659 constexpr char C2_PARAMKEY_DEFAULT_COLOR_ASPECTS[] = "default.color";
1660 
1661 /**
1662  * HDR Static Metadata Info.
1663  */
1664 struct C2ColorXyStruct {
1665     float x; ///< x color coordinate in xyY space [0-1]
1666     float y; ///< y color coordinate in xyY space [0-1]
1667 
1668     DEFINE_AND_DESCRIBE_C2STRUCT(ColorXy)
1669     C2FIELD(x, "x")
1670     C2FIELD(y, "y")
1671 };
1672 
1673 struct C2MasteringDisplayColorVolumeStruct {
1674     C2ColorXyStruct red;    ///< coordinates of red display primary
1675     C2ColorXyStruct green;  ///< coordinates of green display primary
1676     C2ColorXyStruct blue;   ///< coordinates of blue display primary
1677     C2ColorXyStruct white;  ///< coordinates of white point
1678 
1679     float maxLuminance;  ///< max display mastering luminance in cd/m^2
1680     float minLuminance;  ///< min display mastering luminance in cd/m^2
1681 
1682     DEFINE_AND_DESCRIBE_C2STRUCT(MasteringDisplayColorVolume)
1683     C2FIELD(red, "red")
1684     C2FIELD(green, "green")
1685     C2FIELD(blue, "blue")
1686     C2FIELD(white, "white")
1687 
1688     C2FIELD(maxLuminance, "max-luminance")
1689     C2FIELD(minLuminance, "min-luminance")
1690 };
1691 
1692 struct C2HdrStaticMetadataStruct {
1693     C2MasteringDisplayColorVolumeStruct mastering;
1694 
1695     // content descriptors
1696     float maxCll;  ///< max content light level (pixel luminance) in cd/m^2
1697     float maxFall; ///< max frame average light level (frame luminance) in cd/m^2
1698 
1699     DEFINE_AND_DESCRIBE_BASE_C2STRUCT(HdrStaticMetadata)
1700     C2FIELD(mastering, "mastering")
1701     C2FIELD(maxCll, "max-cll")
1702     C2FIELD(maxFall, "max-fall")
1703 };
1704 typedef C2StreamParam<C2Info, C2HdrStaticMetadataStruct, kParamIndexHdrStaticMetadata>
1705         C2StreamHdrStaticMetadataInfo;
1706 typedef C2StreamParam<C2Info, C2HdrStaticMetadataStruct, kParamIndexHdrStaticMetadata>
1707         C2StreamHdrStaticInfo;  // deprecated
1708 constexpr char C2_PARAMKEY_HDR_STATIC_INFO[] = "raw.hdr-static-info";
1709 
1710 /**
1711  * HDR10+ Metadata Info.
1712  *
1713  * Deprecated. Use C2StreamHdrDynamicMetadataInfo with
1714  * HDR_DYNAMIC_METADATA_TYPE_SMPTE_2094_40
1715  */
1716 typedef C2StreamParam<C2Info, C2BlobValue, kParamIndexHdr10PlusMetadata>
1717         C2StreamHdr10PlusInfo;  // deprecated
1718 constexpr char C2_PARAMKEY_INPUT_HDR10_PLUS_INFO[] = "input.hdr10-plus-info";  // deprecated
1719 constexpr char C2_PARAMKEY_OUTPUT_HDR10_PLUS_INFO[] = "output.hdr10-plus-info";  // deprecated
1720 
1721 /**
1722  * HDR dynamic metadata types
1723  */
1724 C2ENUM(C2Config::hdr_dynamic_metadata_type_t, uint32_t,
1725     HDR_DYNAMIC_METADATA_TYPE_SMPTE_2094_10,  ///< SMPTE ST 2094-10
1726     HDR_DYNAMIC_METADATA_TYPE_SMPTE_2094_40,  ///< SMPTE ST 2094-40
1727 )
1728 
1729 struct C2HdrDynamicMetadataStruct {
C2HdrDynamicMetadataStructC2HdrDynamicMetadataStruct1730     inline C2HdrDynamicMetadataStruct() { memset(this, 0, sizeof(*this)); }
1731 
C2HdrDynamicMetadataStructC2HdrDynamicMetadataStruct1732     inline C2HdrDynamicMetadataStruct(
1733             size_t flexCount, C2Config::hdr_dynamic_metadata_type_t type)
1734         : type_(type) {
1735         memset(data, 0, flexCount);
1736     }
1737 
1738     C2Config::hdr_dynamic_metadata_type_t type_;
1739     uint8_t data[];
1740 
1741     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(HdrDynamicMetadata, data)
1742     C2FIELD(type_, "type")
1743     C2FIELD(data, "data")
1744 };
1745 
1746 /**
1747  * Dynamic HDR Metadata Info.
1748  */
1749 typedef C2StreamParam<C2Info, C2HdrDynamicMetadataStruct, kParamIndexHdrDynamicMetadata>
1750         C2StreamHdrDynamicMetadataInfo;
1751 constexpr char C2_PARAMKEY_INPUT_HDR_DYNAMIC_INFO[] = "input.hdr-dynamic-info";
1752 constexpr char C2_PARAMKEY_OUTPUT_HDR_DYNAMIC_INFO[] = "output.hdr-dynamic-info";
1753 
1754 /**
1755  * HDR Format
1756  */
1757 C2ENUM(C2Config::hdr_format_t, uint32_t,
1758     UNKNOWN,     ///< HDR format not known (default)
1759     SDR,         ///< not HDR (SDR)
1760     HLG,         ///< HLG
1761     HDR10,       ///< HDR10
1762     HDR10_PLUS,  ///< HDR10+
1763 );
1764 
1765 /**
1766  * HDR Format Info
1767  *
1768  * This information may be present during configuration to allow encoders to
1769  * prepare encoding certain HDR formats. When this information is not present
1770  * before start, encoders should determine the HDR format based on the available
1771  * HDR metadata on the first input frame.
1772  *
1773  * While this information is optional, it is not a hint. When present, encoders
1774  * that do not support dynamic reconfiguration do not need to switch to the HDR
1775  * format based on the metadata on the first input frame.
1776  */
1777 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2EasyEnum<C2Config::hdr_format_t>>,
1778                 kParamIndexHdrFormat>
1779         C2StreamHdrFormatInfo;
1780 constexpr char C2_PARAMKEY_HDR_FORMAT[] = "coded.hdr-format";
1781 
1782 /* ------------------------------------ block-based coding ----------------------------------- */
1783 
1784 /**
1785  * Block-size, block count and block rate. Used to determine or communicate profile-level
1786  * requirements.
1787  */
1788 typedef C2StreamParam<C2Info, C2PictureSizeStruct, kParamIndexBlockSize> C2StreamBlockSizeInfo;
1789 constexpr char C2_PARAMKEY_BLOCK_SIZE[] = "coded.block-size";
1790 
1791 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexBlockCount> C2StreamBlockCountInfo;
1792 constexpr char C2_PARAMKEY_BLOCK_COUNT[] = "coded.block-count";
1793 
1794 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexBlockRate> C2StreamBlockRateInfo;
1795 constexpr char C2_PARAMKEY_BLOCK_RATE[] = "coded.block-rate";
1796 
1797 /* ====================================== VIDEO COMPONENTS ====================================== */
1798 
1799 /**
1800  * Frame rate (coded and port for raw data)
1801  *
1802  * Coded frame rates are what is represented in the compressed bitstream and should correspond to
1803  * the timestamp.
1804  *
1805  * Frame rates on raw ports should still correspond to the timestamps.
1806  *
1807  * For slow motion or timelapse recording, the timestamp shall be adjusted prior to feeding an
1808  * encoder, and the time stretch parameter should be used to signal the relationship between
1809  * timestamp and real-world time.
1810  */
1811 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexFrameRate> C2StreamFrameRateInfo;
1812 constexpr char C2_PARAMKEY_FRAME_RATE[] = "coded.frame-rate";
1813 
1814 typedef C2PortParam<C2Info, C2FloatValue, kParamIndexFrameRate> C2PortFrameRateInfo;
1815 constexpr char C2_PARAMKEY_INPUT_FRAME_RATE[] = "input.frame-rate";
1816 constexpr char C2_PARAMKEY_OUTPUT_FRAME_RATE[] = "output.frame-rate";
1817 
1818 /**
1819  * Time stretch. Ratio between real-world time and timestamp. E.g. time stretch of 4.0 means that
1820  * timestamp grows 1/4 the speed of real-world time (e.g. 4x slo-mo input). This can be used to
1821  * optimize encoding.
1822  */
1823 typedef C2PortParam<C2Info, C2FloatValue, kParamIndexTimeStretch> C2PortTimeStretchInfo;
1824 constexpr char C2_PARAMKEY_INPUT_TIME_STRETCH[] = "input.time-stretch";
1825 constexpr char C2_PARAMKEY_OUTPUT_TIME_STRETCH[] = "output.time-stretch";
1826 
1827 /**
1828  * Max video frame size.
1829  */
1830 typedef C2StreamParam<C2Tuning, C2PictureSizeStruct, kParamIndexMaxPictureSize>
1831         C2StreamMaxPictureSizeTuning;
1832 typedef C2StreamMaxPictureSizeTuning C2MaxVideoSizeHintPortSetting;
1833 constexpr char C2_PARAMKEY_MAX_PICTURE_SIZE[] = "raw.max-size";
1834 
1835 /**
1836  * Picture type mask.
1837  */
1838 C2ENUM(C2Config::picture_type_t, uint32_t,
1839     SYNC_FRAME = (1 << 0),  ///< sync frame, e.g. IDR
1840     I_FRAME    = (1 << 1),  ///< intra frame that is completely encoded
1841     P_FRAME    = (1 << 2),  ///< inter predicted frame from previous frames
1842     B_FRAME    = (1 << 3),  ///< bidirectional predicted (out-of-order) frame
1843 )
1844 
1845 /**
1846  * Allowed picture types.
1847  */
1848 typedef C2StreamParam<C2Tuning, C2SimpleValueStruct<C2EasyEnum<C2Config::picture_type_t>>,
1849                 kParamIndexPictureTypeMask>
1850         C2StreamPictureTypeMaskTuning;
1851 constexpr char C2_PARAMKEY_PICTURE_TYPE_MASK[] = "coding.picture-type-mask";
1852 
1853 /**
1854  * Resulting picture type
1855  */
1856 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2EasyEnum<C2Config::picture_type_t>>,
1857                 kParamIndexPictureType>
1858         C2StreamPictureTypeInfo;
1859 typedef C2StreamPictureTypeInfo C2StreamPictureTypeMaskInfo;
1860 constexpr char C2_PARAMKEY_PICTURE_TYPE[] = "coded.picture-type";
1861 
1862 /**
1863  * GOP specification.
1864  *
1865  * GOP is specified in layers between sync frames, by specifying the number of specific type of
1866  * frames between the previous type (starting with sync frames for the first layer):
1867  *
1868  * E.g.
1869  *      - 4 I frames between each sync frame
1870  *      - 2 P frames between each I frame
1871  *      - 1 B frame between each P frame
1872  *
1873  *      [ { I, 4 }, { P, 2 }, { B, 1 } ] ==> (Sync)BPBPB IBPBPB IBPBPB IBPBPB IBPBPB (Sync)BPBPB
1874  *
1875  * For infinite GOP, I layer can be omitted (as the first frame is always a sync frame.):
1876  *
1877  *      [ { P, MAX_UINT } ]   ==> (Sync)PPPPPPPPPPPPPPPPPP...
1878  *
1879  * Sync frames can also be requested on demand, and as a time-based interval. For time-based
1880  * interval, if there hasn't been a sync frame in at least the given time, the next I frame shall
1881  * be encoded as a sync frame.  For sync request, the next I frame shall be encoded as a sync frame.
1882  *
1883  * Temporal layering will determine GOP structure other than the I frame count between sync
1884  * frames.
1885  */
1886 struct C2GopLayerStruct {
C2GopLayerStructC2GopLayerStruct1887     C2GopLayerStruct() : type_((C2Config::picture_type_t)0), count(0) {}
C2GopLayerStructC2GopLayerStruct1888     C2GopLayerStruct(C2Config::picture_type_t type, uint32_t count_)
1889         : type_(type), count(count_) { }
1890 
1891     C2Config::picture_type_t type_;
1892     uint32_t count;
1893 
1894     DEFINE_AND_DESCRIBE_C2STRUCT(GopLayer)
1895     C2FIELD(type_, "type")
1896     C2FIELD(count, "count")
1897 };
1898 
1899 typedef C2StreamParam<C2Tuning, C2SimpleArrayStruct<C2GopLayerStruct>, kParamIndexGop>
1900         C2StreamGopTuning;
1901 constexpr char C2_PARAMKEY_GOP[] = "coding.gop";
1902 
1903 /**
1904  * Quantization
1905  * min/max for each picture type
1906  *
1907  */
1908 struct C2PictureQuantizationStruct {
C2PictureQuantizationStructC2PictureQuantizationStruct1909     C2PictureQuantizationStruct() : type_((C2Config::picture_type_t)0),
1910                                          min(INT32_MIN), max(INT32_MAX) {}
C2PictureQuantizationStructC2PictureQuantizationStruct1911     C2PictureQuantizationStruct(C2Config::picture_type_t type, int32_t min_, int32_t max_)
1912         : type_(type), min(min_), max(max_) { }
1913 
1914     C2Config::picture_type_t type_;
1915     int32_t min;      // INT32_MIN == 'no lower bound specified'
1916     int32_t max;      // INT32_MAX == 'no upper bound specified'
1917 
1918     DEFINE_AND_DESCRIBE_C2STRUCT(PictureQuantization)
1919     C2FIELD(type_, "type")
1920     C2FIELD(min, "min")
1921     C2FIELD(max, "max")
1922 };
1923 
1924 typedef C2StreamParam<C2Tuning, C2SimpleArrayStruct<C2PictureQuantizationStruct>,
1925         kParamIndexPictureQuantization> C2StreamPictureQuantizationTuning;
1926 constexpr char C2_PARAMKEY_PICTURE_QUANTIZATION[] = "coding.qp";
1927 
1928 /**
1929  * Sync frame can be requested on demand by the client.
1930  *
1931  * If true, the next I frame shall be encoded as a sync frame. This config can be passed
1932  * synchronously with the work, or directly to the component - leading to different result.
1933  * If it is passed with work, it shall take effect when that work item is being processed (so
1934  * the first I frame at or after that work item shall be a sync frame).
1935  */
1936 typedef C2StreamParam<C2Tuning, C2EasyBoolValue, kParamIndexRequestSyncFrame>
1937         C2StreamRequestSyncFrameTuning;
1938 constexpr char C2_PARAMKEY_REQUEST_SYNC_FRAME[] = "coding.request-sync-frame";
1939 
1940 /**
1941  * Sync frame interval in time domain (timestamp).
1942  *
1943  * If there hasn't been a sync frame in at least this value, the next intra frame shall be encoded
1944  * as a sync frame. The value of MAX_I64 or a negative value means no sync frames after the first
1945  * frame. A value of 0 means all sync frames.
1946  */
1947 typedef C2StreamParam<C2Tuning, C2Int64Value, kParamIndexSyncFrameInterval>
1948         C2StreamSyncFrameIntervalTuning;
1949 constexpr char C2_PARAMKEY_SYNC_FRAME_INTERVAL[] = "coding.sync-frame-interval";
1950 
1951 /**
1952  * Temporal layering
1953  *
1954  * Layer index is a value between 0 and layer count - 1. Layers with higher index have higher
1955  * frequency:
1956  *     0
1957  *   1   1
1958  *  2 2 2 2
1959  */
1960 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexLayerIndex> C2StreamLayerIndexInfo;
1961 constexpr char C2_PARAMKEY_LAYER_INDEX[] = "coded.layer-index";
1962 
1963 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexLayerCount> C2StreamLayerCountInfo;
1964 constexpr char C2_PARAMKEY_LAYER_COUNT[] = "coded.layer-count";
1965 
1966 struct C2TemporalLayeringStruct {
C2TemporalLayeringStructC2TemporalLayeringStruct1967     C2TemporalLayeringStruct()
1968         : layerCount(0), bLayerCount(0) { }
1969 
C2TemporalLayeringStructC2TemporalLayeringStruct1970     C2TemporalLayeringStruct(size_t /* flexCount */, uint32_t layerCount_, uint32_t bLayerCount_)
1971         : layerCount(layerCount_), bLayerCount(c2_min(layerCount_, bLayerCount_)) { }
1972 
C2TemporalLayeringStructC2TemporalLayeringStruct1973     C2TemporalLayeringStruct(size_t flexCount, uint32_t layerCount_, uint32_t bLayerCount_,
1974                              std::initializer_list<float> ratios)
1975         : layerCount(layerCount_), bLayerCount(c2_min(layerCount_, bLayerCount_)) {
1976         size_t ix = 0;
1977         for (float ratio : ratios) {
1978             if (ix == flexCount) {
1979                 break;
1980             }
1981             bitrateRatios[ix++] = ratio;
1982         }
1983     }
1984 
1985     uint32_t layerCount;     ///< total number of layers (0 means no temporal layering)
1986     uint32_t bLayerCount;    ///< total number of bidirectional layers (<= num layers)
1987     /**
1988      * Bitrate budgets for each layer and the layers below, given as a ratio of the total
1989      * stream bitrate. This can be omitted or partially specififed by the client while configuring,
1990      * in which case the component shall fill in appropriate values for the missing layers.
1991      * This must be provided by the component when queried for at least layer count - 1 (as the
1992      * last layer's budget is always 1.0).
1993      */
1994     float bitrateRatios[];   ///< 1.0-based
1995 
1996     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(TemporalLayering, bitrateRatios)
1997     C2FIELD(layerCount, "layer-count")
1998     C2FIELD(bLayerCount, "b-layer-count")
1999     C2FIELD(bitrateRatios, "bitrate-ratios")
2000 };
2001 
2002 typedef C2StreamParam<C2Tuning, C2TemporalLayeringStruct, kParamIndexTemporalLayering>
2003         C2StreamTemporalLayeringTuning;
2004 constexpr char C2_PARAMKEY_TEMPORAL_LAYERING[] = "coding.temporal-layering";
2005 
2006 /**
2007  * Intra-refresh.
2008  */
2009 
2010 C2ENUM(C2Config::intra_refresh_mode_t, uint32_t,
2011     INTRA_REFRESH_DISABLED,     ///< no intra refresh
2012     INTRA_REFRESH_ARBITRARY,    ///< arbitrary, unspecified
2013 )
2014 
2015 struct C2IntraRefreshStruct {
C2IntraRefreshStructC2IntraRefreshStruct2016     C2IntraRefreshStruct()
2017         : mode(C2Config::INTRA_REFRESH_DISABLED), period(0.) { }
2018 
C2IntraRefreshStructC2IntraRefreshStruct2019     C2IntraRefreshStruct(C2Config::intra_refresh_mode_t mode_, float period_)
2020         : mode(mode_), period(period_) { }
2021 
2022     C2Config::intra_refresh_mode_t mode; ///< refresh mode
2023     float period;         ///< intra refresh period in frames (must be >= 1), 0 means disabled
2024 
2025     DEFINE_AND_DESCRIBE_C2STRUCT(IntraRefresh)
2026     C2FIELD(mode, "mode")
2027     C2FIELD(period, "period")
2028 };
2029 
2030 typedef C2StreamParam<C2Tuning, C2IntraRefreshStruct, kParamIndexIntraRefresh>
2031         C2StreamIntraRefreshTuning;
2032 constexpr char C2_PARAMKEY_INTRA_REFRESH[] = "coding.intra-refresh";
2033 
2034 /* ====================================== IMAGE COMPONENTS ====================================== */
2035 
2036 /**
2037  * Tile layout.
2038  *
2039  * This described how the image is decomposed into tiles.
2040  */
2041 C2ENUM(C2Config::scan_order_t, uint32_t,
2042     SCAN_LEFT_TO_RIGHT_THEN_DOWN
2043 )
2044 
2045 struct C2TileLayoutStruct {
2046     C2PictureSizeStruct tile;       ///< tile size
2047     uint32_t columnCount;           ///< number of tiles horizontally
2048     uint32_t rowCount;              ///< number of tiles vertically
2049     C2Config::scan_order_t order;   ///< tile order
2050 
2051     DEFINE_AND_DESCRIBE_C2STRUCT(TileLayout)
2052     C2FIELD(tile, "tile")
2053     C2FIELD(columnCount, "columns")
2054     C2FIELD(rowCount, "rows")
2055     C2FIELD(order, "order")
2056 };
2057 
2058 typedef C2StreamParam<C2Info, C2TileLayoutStruct, kParamIndexTileLayout> C2StreamTileLayoutInfo;
2059 constexpr char C2_PARAMKEY_TILE_LAYOUT[] = "coded.tile-layout";
2060 
2061 /**
2062  * Tile handling.
2063  *
2064  * Whether to concatenate tiles or output them each.
2065  */
2066 C2ENUM(C2Config::tiling_mode_t, uint32_t,
2067     TILING_SEPARATE,    ///< output each tile in a separate onWorkDone
2068     TILING_CONCATENATE  ///< output one work completion per frame (concatenate tiles)
2069 )
2070 
2071 typedef C2StreamParam<C2Tuning, C2TileLayoutStruct, kParamIndexTileHandling>
2072         C2StreamTileHandlingTuning;
2073 constexpr char C2_PARAMKEY_TILE_HANDLING[] = "coding.tile-handling";
2074 
2075 /* ====================================== AUDIO COMPONENTS ====================================== */
2076 
2077 /**
2078  * Sample rate
2079  */
2080 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexSampleRate> C2StreamSampleRateInfo;
2081 constexpr char C2_PARAMKEY_SAMPLE_RATE[] = "raw.sample-rate";
2082 constexpr char C2_PARAMKEY_CODED_SAMPLE_RATE[] = "coded.sample-rate";
2083 
2084 /**
2085  * Channel count.
2086  */
2087 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexChannelCount> C2StreamChannelCountInfo;
2088 constexpr char C2_PARAMKEY_CHANNEL_COUNT[] = "raw.channel-count";
2089 constexpr char C2_PARAMKEY_CODED_CHANNEL_COUNT[] = "coded.channel-count";
2090 
2091 /**
2092  * Max channel count. Used to limit the number of coded or decoded channels.
2093  */
2094 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexMaxChannelCount> C2StreamMaxChannelCountInfo;
2095 constexpr char C2_PARAMKEY_MAX_CHANNEL_COUNT[] = "raw.max-channel-count";
2096 constexpr char C2_PARAMKEY_MAX_CODED_CHANNEL_COUNT[] = "coded.max-channel-count";
2097 
2098 /**
2099  * Audio channel mask. Used by decoder to express audio channel mask of decoded content,
2100  * or by encoder for the channel mask of the encoded content once decoded.
2101  * Channel representation is specified according to the Java android.media.AudioFormat
2102  * CHANNEL_OUT_* constants.
2103  */
2104  typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexAndroidChannelMask> C2StreamChannelMaskInfo;
2105  const char C2_PARAMKEY_CHANNEL_MASK[] = "raw.channel-mask";
2106 
2107 /**
2108  * Audio sample format (PCM encoding)
2109  */
2110 C2ENUM(C2Config::pcm_encoding_t, uint32_t,
2111     PCM_16,
2112     PCM_8,
2113     PCM_FLOAT,
2114     PCM_24,
2115     PCM_32
2116 )
2117 
2118 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::pcm_encoding_t>, kParamIndexPcmEncoding>
2119         C2StreamPcmEncodingInfo;
2120 constexpr char C2_PARAMKEY_PCM_ENCODING[] = "raw.pcm-encoding";
2121 constexpr char C2_PARAMKEY_CODED_PCM_ENCODING[] = "coded.pcm-encoding";
2122 
2123 /**
2124  * AAC SBR Mode. Used during encoding.
2125  */
2126 C2ENUM(C2Config::aac_sbr_mode_t, uint32_t,
2127     AAC_SBR_OFF,
2128     AAC_SBR_SINGLE_RATE,
2129     AAC_SBR_DUAL_RATE,
2130     AAC_SBR_AUTO ///< let the codec decide
2131 )
2132 
2133 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::aac_sbr_mode_t>, kParamIndexAacSbrMode>
2134         C2StreamAacSbrModeTuning;
2135 constexpr char C2_PARAMKEY_AAC_SBR_MODE[] = "coding.aac-sbr-mode";
2136 
2137 /**
2138  * DRC Compression. Used during decoding.
2139  */
2140 C2ENUM(C2Config::drc_compression_mode_t, int32_t,
2141     DRC_COMPRESSION_ODM_DEFAULT, ///< odm's default
2142     DRC_COMPRESSION_NONE,
2143     DRC_COMPRESSION_LIGHT,
2144     DRC_COMPRESSION_HEAVY ///<
2145 )
2146 
2147 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::drc_compression_mode_t>,
2148                 kParamIndexDrcCompression>
2149         C2StreamDrcCompressionModeTuning;
2150 constexpr char C2_PARAMKEY_DRC_COMPRESSION_MODE[] = "coding.drc.compression-mode";
2151 
2152 /**
2153  * DRC target reference level in dBFS. Used during decoding.
2154  */
2155 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcTargetReferenceLevel>
2156         C2StreamDrcTargetReferenceLevelTuning;
2157 constexpr char C2_PARAMKEY_DRC_TARGET_REFERENCE_LEVEL[] = "coding.drc.reference-level";
2158 
2159 /**
2160  * DRC target reference level in dBFS. Used during decoding.
2161  */
2162 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcEncodedTargetLevel>
2163         C2StreamDrcEncodedTargetLevelTuning;
2164 constexpr char C2_PARAMKEY_DRC_ENCODED_TARGET_LEVEL[] = "coding.drc.encoded-level";
2165 
2166 /**
2167  * DRC target reference level in dBFS. Used during decoding.
2168  */
2169 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcBoostFactor>
2170         C2StreamDrcBoostFactorTuning;
2171 constexpr char C2_PARAMKEY_DRC_BOOST_FACTOR[] = "coding.drc.boost-factor";
2172 
2173 /**
2174  * DRC target reference level in dBFS. Used during decoding.
2175  */
2176 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcAttenuationFactor>
2177         C2StreamDrcAttenuationFactorTuning;
2178 constexpr char C2_PARAMKEY_DRC_ATTENUATION_FACTOR[] = "coding.drc.attenuation-factor";
2179 
2180 /**
2181  * DRC Effect Type (see ISO 23003-4) Uniform Dynamic Range Control. Used during decoding.
2182  */
2183 C2ENUM(C2Config::drc_effect_type_t, int32_t,
2184     DRC_EFFECT_ODM_DEFAULT = -2, ///< odm's default
2185     DRC_EFFECT_OFF = -1,    ///< no DRC
2186     DRC_EFFECT_NONE = 0,    ///< no DRC except to prevent clipping
2187     DRC_EFFECT_LATE_NIGHT,
2188     DRC_EFFECT_NOISY_ENVIRONMENT,
2189     DRC_EFFECT_LIMITED_PLAYBACK_RANGE,
2190     DRC_EFFECT_LOW_PLAYBACK_LEVEL,
2191     DRC_EFFECT_DIALOG_ENHANCEMENT,
2192     DRC_EFFECT_GENERAL_COMPRESSION
2193 )
2194 
2195 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::drc_effect_type_t>,
2196                 kParamIndexDrcEffectType>
2197         C2StreamDrcEffectTypeTuning;
2198 constexpr char C2_PARAMKEY_DRC_EFFECT_TYPE[] = "coding.drc.effect-type";
2199 
2200 /**
2201  * DRC album mode. Used during decoding.
2202  */
2203 C2ENUM(C2Config::drc_album_mode_t, int32_t,
2204     DRC_ALBUM_MODE_OFF = 0,
2205     DRC_ALBUM_MODE_ON = 1
2206 )
2207 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2Config::drc_album_mode_t>, kParamIndexDrcAlbumMode>
2208         C2StreamDrcAlbumModeTuning;
2209 constexpr char C2_PARAMKEY_DRC_ALBUM_MODE[] = "coding.drc.album-mode";
2210 
2211 /**
2212  * DRC output loudness in dBFS. Retrieved during decoding
2213  */
2214 typedef C2StreamParam<C2Info, C2FloatValue, kParamIndexDrcOutputLoudness>
2215         C2StreamDrcOutputLoudnessTuning;
2216 constexpr char C2_PARAMKEY_DRC_OUTPUT_LOUDNESS[] = "output.drc.output-loudness";
2217 
2218 /**
2219  * Audio frame size in samples.
2220  *
2221  * Audio encoders can expose this parameter to signal the desired audio frame
2222  * size that corresponds to a single coded access unit.
2223  * Default value is 0, meaning that the encoder accepts input buffers of any size.
2224  */
2225 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexAudioFrameSize>
2226         C2StreamAudioFrameSizeInfo;
2227 constexpr char C2_PARAMKEY_AUDIO_FRAME_SIZE[] = "raw.audio-frame-size";
2228 
2229 /**
2230  * Information for an access unit in a large frame (containing multiple access units)
2231  */
2232 struct C2AccessUnitInfosStruct {
2233 
C2AccessUnitInfosStructC2AccessUnitInfosStruct2234     inline C2AccessUnitInfosStruct() {
2235         memset(this, 0, sizeof(*this));
2236     }
2237 
C2AccessUnitInfosStructC2AccessUnitInfosStruct2238     inline C2AccessUnitInfosStruct(
2239             uint32_t flags_,
2240             uint32_t size_,
2241             int64_t timestamp_)
2242         : flags(flags_),
2243           size(size_),
2244           timestamp(timestamp_) { }
2245 
2246     uint32_t flags; ///<flags for the access-unit
2247     uint32_t size; ///<size of access-unit
2248     int64_t timestamp; ///<timestamp in us for the access-unit
2249 
2250     DEFINE_AND_DESCRIBE_C2STRUCT(AccessUnitInfos)
2251     C2FIELD(flags, "flags")
2252     C2FIELD(size, "size")
2253     C2FIELD(timestamp, "timestamp")
2254 };
2255 
2256 /**
2257  * Multiple access unit support (e.g large audio frames)
2258  *
2259  * If supported by a component, multiple access units may be contained
2260  * in a single work item. For now this is only defined for linear buffers.
2261  * The metadata indicates the access-unit boundaries in a single buffer.
2262  * The boundary of each access-units are marked by its size, immediately
2263  * followed by the next access-unit.
2264  */
2265 typedef C2StreamParam<C2Info, C2SimpleArrayStruct<C2AccessUnitInfosStruct>,
2266                 kParamIndexAccessUnitInfos>
2267         C2AccessUnitInfos;
2268 
2269 constexpr char C2_PARAMKEY_INPUT_ACCESS_UNIT_INFOS[] = "input.access-unit-infos";
2270 constexpr char C2_PARAMKEY_OUTPUT_ACCESS_UNIT_INFOS[] = "output.access-unit-infos";
2271 
2272 /* --------------------------------------- AAC components --------------------------------------- */
2273 
2274 /**
2275  * AAC stream format
2276  */
2277 C2ENUM(C2Config::aac_packaging_t, uint32_t,
2278     AAC_PACKAGING_RAW,
2279     AAC_PACKAGING_ADTS
2280 )
2281 
2282 typedef C2StreamParam<C2Info, C2SimpleValueStruct<C2EasyEnum<C2Config::aac_packaging_t>>,
2283         kParamIndexAacPackaging> C2StreamAacPackagingInfo;
2284 typedef C2StreamAacPackagingInfo C2StreamAacFormatInfo;
2285 constexpr char C2_PARAMKEY_AAC_PACKAGING[] = "coded.aac-packaging";
2286 
2287 /* ================================ PLATFORM-DEFINED PARAMETERS ================================ */
2288 
2289 /**
2290  * Platform level and features.
2291  */
2292 enum C2Config::platform_level_t : uint32_t {
2293     PLATFORM_P,   ///< support for Android 9.0 feature set
2294 };
2295 
2296 // read-only
2297 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Config::platform_level_t>,
2298                 kParamIndexPlatformLevel>
2299         C2PlatformLevelSetting;
2300 constexpr char C2_PARAMKEY_PLATFORM_LEVEL[] = "api.platform-level";
2301 
2302 enum C2Config::platform_feature_t : uint64_t {
2303     // no platform-specific features have been defined
2304 };
2305 
2306 // read-only
2307 typedef C2GlobalParam<C2Setting, C2SimpleValueStruct<C2Config::platform_feature_t>,
2308                 kParamIndexPlatformFeatures>
2309         C2PlatformFeaturesSetting;
2310 constexpr char C2_PARAMKEY_PLATFORM_FEATURES[] = "api.platform-features";
2311 
2312 /**
2313  * This structure describes the preferred ion allocation parameters for a given memory usage.
2314  */
2315 struct C2StoreIonUsageStruct {
C2StoreIonUsageStructC2StoreIonUsageStruct2316     inline C2StoreIonUsageStruct() {
2317         memset(this, 0, sizeof(*this));
2318     }
2319 
C2StoreIonUsageStructC2StoreIonUsageStruct2320     inline C2StoreIonUsageStruct(uint64_t usage_, uint32_t capacity_)
2321         : usage(usage_), capacity(capacity_), heapMask(0), allocFlags(0), minAlignment(0) { }
2322 
2323     uint64_t usage;        ///< C2MemoryUsage
2324     uint32_t capacity;     ///< capacity
2325     int32_t heapMask;      ///< ion heapMask
2326     int32_t allocFlags;    ///< ion allocation flags
2327     uint32_t minAlignment; ///< minimum alignment
2328 
2329     DEFINE_AND_DESCRIBE_C2STRUCT(StoreIonUsage)
2330     C2FIELD(usage, "usage")
2331     C2FIELD(capacity, "capacity")
2332     C2FIELD(heapMask, "heap-mask")
2333     C2FIELD(allocFlags, "alloc-flags")
2334     C2FIELD(minAlignment, "min-alignment")
2335 };
2336 
2337 // store, private
2338 typedef C2GlobalParam<C2Info, C2StoreIonUsageStruct, kParamIndexStoreIonUsage>
2339         C2StoreIonUsageInfo;
2340 
2341 /**
2342  * This structure describes the preferred DMA-Buf allocation parameters for a given memory usage.
2343  */
2344 struct C2StoreDmaBufUsageStruct {
C2StoreDmaBufUsageStructC2StoreDmaBufUsageStruct2345     inline C2StoreDmaBufUsageStruct() { memset(this, 0, sizeof(*this)); }
2346 
C2StoreDmaBufUsageStructC2StoreDmaBufUsageStruct2347     inline C2StoreDmaBufUsageStruct(size_t flexCount, uint64_t usage_, uint32_t capacity_)
2348         : usage(usage_), capacity(capacity_), allocFlags(0) {
2349         memset(heapName, 0, flexCount);
2350     }
2351 
2352     uint64_t usage;                         ///< C2MemoryUsage
2353     uint32_t capacity;                      ///< capacity
2354     int32_t allocFlags;                     ///< ion allocation flags
2355     char heapName[];                        ///< dmabuf heap name
2356 
2357     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(StoreDmaBufUsage, heapName)
2358     C2FIELD(usage, "usage")
2359     C2FIELD(capacity, "capacity")
2360     C2FIELD(allocFlags, "alloc-flags")
2361     C2FIELD(heapName, "heap-name")
2362 };
2363 
2364 // store, private
2365 typedef C2GlobalParam<C2Info, C2StoreDmaBufUsageStruct, kParamIndexStoreDmaBufUsage>
2366         C2StoreDmaBufUsageInfo;
2367 
2368 /**
2369  * Flexible pixel format descriptors
2370  */
2371 struct C2FlexiblePixelFormatDescriptorStruct {
2372     uint32_t pixelFormat;
2373     uint32_t bitDepth;
2374     C2Color::subsampling_t subsampling;
2375     C2Color::plane_layout_t layout;
2376 
2377     DEFINE_AND_DESCRIBE_C2STRUCT(FlexiblePixelFormatDescriptor)
2378     C2FIELD(pixelFormat, "pixel-format")
2379     C2FIELD(bitDepth, "bit-depth")
2380     C2FIELD(subsampling, "subsampling")
2381     C2FIELD(layout, "layout")
2382 };
2383 
2384 /**
2385  * Plane layout of flexible pixel formats.
2386  *
2387  * bpp: bytes per color component, e.g. 1 for 8-bit formats, and 2 for 10-16-bit formats.
2388  */
2389 C2ENUM(C2Color::plane_layout_t, uint32_t,
2390        /** Unknown layout */
2391        UNKNOWN_LAYOUT,
2392 
2393        /** Planar layout with rows of each plane packed (colInc = bpp) */
2394        PLANAR_PACKED,
2395 
2396        /** Semiplanar layout with rows of each plane packed (colInc_Y/A = bpp (planar),
2397         *  colInc_Cb/Cr = 2*bpp (interleaved). Used only for YUV(A) formats. */
2398        SEMIPLANAR_PACKED,
2399 
2400        /** Interleaved packed. colInc = N*bpp (N are the number of color components) */
2401        INTERLEAVED_PACKED,
2402 
2403        /** Interleaved aligned. colInc = smallest power of 2 >= N*bpp (N are the number of color
2404         *  components) */
2405        INTERLEAVED_ALIGNED
2406 )
2407 
2408 typedef C2GlobalParam<C2Info, C2SimpleArrayStruct<C2FlexiblePixelFormatDescriptorStruct>,
2409                 kParamIndexFlexiblePixelFormatDescriptors>
2410         C2StoreFlexiblePixelFormatDescriptorsInfo;
2411 
2412 /**
2413  * This structure describes the android dataspace for a raw video/image frame.
2414  */
2415 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexDataSpace> C2StreamDataSpaceInfo;
2416 constexpr char C2_PARAMKEY_DATA_SPACE[] = "raw.data-space";
2417 
2418 /**
2419  * This structure describes the android surface scaling mode for a raw video/image frame.
2420  */
2421 typedef C2StreamParam<C2Info, C2Uint32Value, kParamIndexSurfaceScaling> C2StreamSurfaceScalingInfo;
2422 constexpr char C2_PARAMKEY_SURFACE_SCALING_MODE[] = "raw.surface-scaling";
2423 
2424 /* ======================================= INPUT SURFACE ======================================= */
2425 
2426 /**
2427  * Input surface EOS
2428  */
2429 typedef C2GlobalParam<C2Tuning, C2EasyBoolValue, kParamIndexInputSurfaceEos>
2430         C2InputSurfaceEosTuning;
2431 constexpr char C2_PARAMKEY_INPUT_SURFACE_EOS[] = "input-surface.eos";
2432 
2433 /**
2434  * Start/suspend/resume/stop controls and timestamps for input surface.
2435  *
2436  * TODO: make these counters
2437  */
2438 
2439 struct C2TimedControlStruct {
2440     c2_bool_t enabled; ///< control is enabled
2441     int64_t timestamp; ///< if enabled, time the control should take effect
2442 
C2TimedControlStructC2TimedControlStruct2443     C2TimedControlStruct()
2444         : enabled(C2_FALSE), timestamp(0) { }
2445 
C2TimedControlStructC2TimedControlStruct2446     /* implicit */ C2TimedControlStruct(uint64_t timestamp_)
2447         : enabled(C2_TRUE), timestamp(timestamp_) { }
2448 
2449     DEFINE_AND_DESCRIBE_C2STRUCT(TimedControl)
2450     C2FIELD(enabled,   "enabled")
2451     C2FIELD(timestamp, "timestamp")
2452 };
2453 
2454 typedef C2PortParam<C2Tuning, C2TimedControlStruct, kParamIndexStartAt>
2455         C2PortStartTimestampTuning;
2456 constexpr char C2_PARAMKEY_INPUT_SURFACE_START_AT[] = "input-surface.start";
2457 typedef C2PortParam<C2Tuning, C2TimedControlStruct, kParamIndexSuspendAt>
2458         C2PortSuspendTimestampTuning;
2459 constexpr char C2_PARAMKEY_INPUT_SURFACE_SUSPEND_AT[] = "input-surface.suspend";
2460 typedef C2PortParam<C2Tuning, C2TimedControlStruct, kParamIndexResumeAt>
2461         C2PortResumeTimestampTuning;
2462 constexpr char C2_PARAMKEY_INPUT_SURFACE_RESUME_AT[] = "input-surface.resume";
2463 typedef C2PortParam<C2Tuning, C2TimedControlStruct, kParamIndexStopAt>
2464         C2PortStopTimestampTuning;
2465 constexpr char C2_PARAMKEY_INPUT_SURFACE_STOP_AT[] = "input-surface.stop";
2466 
2467 /**
2468  * Time offset for input surface. Input timestamp to codec is surface buffer timestamp plus this
2469  * time offset.
2470  */
2471 typedef C2GlobalParam<C2Tuning, C2Int64Value, kParamIndexTimeOffset> C2ComponentTimeOffsetTuning;
2472 constexpr char C2_PARAMKEY_INPUT_SURFACE_TIME_OFFSET[] = "input-surface.time-offset";
2473 
2474 /**
2475  * Minimum fps for input surface.
2476  *
2477  * Repeat frame to meet this.
2478  */
2479 typedef C2PortParam<C2Tuning, C2FloatValue, kParamIndexMinFrameRate> C2PortMinFrameRateTuning;
2480 constexpr char C2_PARAMKEY_INPUT_SURFACE_MIN_FRAME_RATE[] = "input-surface.min-frame-rate";
2481 
2482 /**
2483  * Timestamp adjustment (override) for input surface buffers. These control the input timestamp
2484  * fed to the codec, but do not impact the output timestamp.
2485  */
2486 struct C2TimestampGapAdjustmentStruct {
2487     /// control modes
2488     enum mode_t : uint32_t;
2489 
2490     inline C2TimestampGapAdjustmentStruct();
2491 
C2TimestampGapAdjustmentStructC2TimestampGapAdjustmentStruct2492     inline C2TimestampGapAdjustmentStruct(mode_t mode_, uint64_t value_)
2493         : mode(mode_), value(value_) { }
2494 
2495     mode_t mode;    ///< control mode
2496     uint64_t value; ///< control value for gap between two timestamp
2497 
2498     DEFINE_AND_DESCRIBE_C2STRUCT(TimestampGapAdjustment)
2499     C2FIELD(mode, "mode")
2500     C2FIELD(value, "value")
2501 };
2502 
2503 C2ENUM(C2TimestampGapAdjustmentStruct::mode_t, uint32_t,
2504     NONE,
2505     MIN_GAP,
2506     FIXED_GAP,
2507 );
2508 
C2TimestampGapAdjustmentStruct()2509 inline C2TimestampGapAdjustmentStruct::C2TimestampGapAdjustmentStruct()
2510     : mode(C2TimestampGapAdjustmentStruct::NONE), value(0) { }
2511 
2512 typedef C2PortParam<C2Tuning, C2TimestampGapAdjustmentStruct> C2PortTimestampGapTuning;
2513 constexpr char C2_PARAMKEY_INPUT_SURFACE_TIMESTAMP_ADJUSTMENT[] = "input-surface.timestamp-adjustment";
2514 
2515 /* ===================================== TUNNELED CODEC ==================================== */
2516 
2517 /**
2518  * Tunneled codec control.
2519  */
2520 struct C2TunneledModeStruct {
2521     /// mode
2522     enum mode_t : uint32_t;
2523     /// sync type
2524     enum sync_type_t : uint32_t;
2525 
2526     inline C2TunneledModeStruct() = default;
2527 
C2TunneledModeStructC2TunneledModeStruct2528     inline C2TunneledModeStruct(
2529             size_t flexCount, mode_t mode_, sync_type_t type, std::vector<int32_t> id)
2530         : mode(mode_), syncType(type) {
2531         memcpy(&syncId, &id[0], c2_min(id.size(), flexCount) * FLEX_SIZE);
2532     }
2533 
C2TunneledModeStructC2TunneledModeStruct2534     inline C2TunneledModeStruct(size_t flexCount, mode_t mode_, sync_type_t type, int32_t id)
2535         : mode(mode_), syncType(type) {
2536         if (flexCount >= 1) {
2537             syncId[0] = id;
2538         }
2539     }
2540 
2541     mode_t mode;          ///< tunneled mode
2542     sync_type_t syncType; ///< type of sync used for tunneled mode
2543     int32_t syncId[];     ///< sync id
2544 
2545     DEFINE_AND_DESCRIBE_FLEX_C2STRUCT(TunneledMode, syncId)
2546     C2FIELD(mode, "mode")
2547     C2FIELD(syncType, "sync-type")
2548     C2FIELD(syncId, "sync-id")
2549 
2550 };
2551 
2552 C2ENUM(C2TunneledModeStruct::mode_t, uint32_t,
2553     NONE,
2554     SIDEBAND,
2555 );
2556 
2557 
2558 C2ENUM(C2TunneledModeStruct::sync_type_t, uint32_t,
2559     REALTIME,
2560     AUDIO_HW_SYNC,
2561     HW_AV_SYNC,
2562 );
2563 
2564 /**
2565  * Configure tunneled mode
2566  */
2567 typedef C2PortParam<C2Tuning, C2TunneledModeStruct, kParamIndexTunneledMode>
2568         C2PortTunneledModeTuning;
2569 constexpr char C2_PARAMKEY_TUNNELED_RENDER[] = "output.tunneled-render";
2570 
2571 /**
2572  * Tunneled mode handle. The meaning of this is depends on the
2573  * tunneled mode. If the tunneled mode is SIDEBAND, this is the
2574  * sideband handle.
2575  */
2576 typedef C2PortParam<C2Tuning, C2Int32Array, kParamIndexTunnelHandle> C2PortTunnelHandleTuning;
2577 constexpr char C2_PARAMKEY_OUTPUT_TUNNEL_HANDLE[] = "output.tunnel-handle";
2578 
2579 /**
2580  * The system time using CLOCK_MONOTONIC in nanoseconds at the tunnel endpoint.
2581  * For decoders this is the render time for the output frame and
2582  * this corresponds to the media timestamp of the output frame.
2583  */
2584 typedef C2PortParam<C2Info, C2SimpleValueStruct<int64_t>, kParamIndexTunnelSystemTime>
2585         C2PortTunnelSystemTime;
2586 constexpr char C2_PARAMKEY_OUTPUT_RENDER_TIME[] = "output.render-time";
2587 
2588 
2589 /**
2590  * Tunneled mode video peek signaling flag.
2591  *
2592  * When a video frame is pushed to the decoder with this parameter set to true,
2593  * the decoder must decode the frame, signal partial completion, and hold on the
2594  * frame until C2StreamTunnelStartRender is set to true (which resets this
2595  * flag). Flush will also result in the frames being returned back to the
2596  * client (but not rendered).
2597  */
2598 typedef C2StreamParam<C2Info, C2EasyBoolValue, kParamIndexTunnelHoldRender>
2599         C2StreamTunnelHoldRender;
2600 constexpr char C2_PARAMKEY_TUNNEL_HOLD_RENDER[] = "output.tunnel-hold-render";
2601 
2602 /**
2603  * Tunneled mode video peek signaling flag.
2604  *
2605  * Upon receiving this flag, the decoder shall set C2StreamTunnelHoldRender to
2606  * false, which shall cause any frames held for rendering to be immediately
2607  * displayed, regardless of their timestamps.
2608 */
2609 typedef C2StreamParam<C2Info, C2EasyBoolValue, kParamIndexTunnelStartRender>
2610         C2StreamTunnelStartRender;
2611 constexpr char C2_PARAMKEY_TUNNEL_START_RENDER[] = "output.tunnel-start-render";
2612 
2613 /** Tunnel Peek Mode. */
2614 C2ENUM(C2PlatformConfig::tunnel_peek_mode_t, uint32_t,
2615     UNSPECIFIED_PEEK = 0,
2616     SPECIFIED_PEEK = 1
2617 );
2618 
2619 /**
2620  * Tunnel Peek Mode Tuning parameter.
2621  *
2622  * If set to UNSPECIFIED_PEEK_MODE, the decoder is free to ignore the
2623  * C2StreamTunnelHoldRender and C2StreamTunnelStartRender flags and associated
2624  * features. Additionally, it becomes up to the decoder to display any frame
2625  * before receiving synchronization information.
2626  *
2627  * Note: This parameter allows a decoder to ignore the video peek machinery and
2628  * to revert to its preferred behavior.
2629  */
2630 typedef C2StreamParam<C2Tuning,
2631         C2SimpleValueStruct<C2EasyEnum<C2PlatformConfig::tunnel_peek_mode_t>>,
2632         kParamIndexTunnelPeekMode> C2StreamTunnelPeekModeTuning;
2633 constexpr char C2_PARAMKEY_TUNNEL_PEEK_MODE[] =
2634         "output.tunnel-peek-mode";
2635 
2636 /**
2637  * Encoding quality level signaling.
2638  *
2639  * Signal the 'minimum encoding quality' introduced in Android 12/S. It indicates
2640  * whether the underlying codec is expected to take extra steps to ensure quality meets the
2641  * appropriate minimum. A value of NONE indicates that the codec is not to apply
2642  * any minimum quality bar requirements. Other values indicate that the codec is to apply
2643  * a minimum quality bar, with the exact quality bar being decided by the parameter value.
2644  */
2645 typedef C2GlobalParam<C2Setting,
2646         C2SimpleValueStruct<C2EasyEnum<C2PlatformConfig::encoding_quality_level_t>>,
2647         kParamIndexEncodingQualityLevel> C2EncodingQualityLevel;
2648 constexpr char C2_PARAMKEY_ENCODING_QUALITY_LEVEL[] = "algo.encoding-quality-level";
2649 
2650 C2ENUM(C2PlatformConfig::encoding_quality_level_t, uint32_t,
2651     NONE = 0,
2652     S_HANDHELD = 1              // corresponds to VMAF=70
2653 );
2654 
2655 /**
2656  * Video Encoding Statistics Export
2657  */
2658 
2659 /**
2660  * Average block QP exported from video encoder.
2661  */
2662 typedef C2StreamParam<C2Info, C2SimpleValueStruct<int32_t>, kParamIndexAverageBlockQuantization>
2663         C2AndroidStreamAverageBlockQuantizationInfo;
2664 constexpr char C2_PARAMKEY_AVERAGE_QP[] = "coded.average-qp";
2665 
2666 /// @}
2667 
2668 #endif  // C2CONFIG_H_
2669