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