///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
// All rights reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  chicommon.h
/// @brief Defines Chi Common Tag interface
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHICOMMON_H
#define CHICOMMON_H

#include "camxcdktypes.h"
#include "chicommontypes.h"

#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

// Pack data structures to ensure consistent layout.
#pragma pack(push, 8)

/** @addtogroup chi_common_tags
@{ */

/// @brief Duplicates the definitions of metadata for use in certain pools.
enum class MetadataPoolSection : UINT32
{
    // Result is implicit, and 0x0000
    Input          = 0x0800, // Input must be bitwise exclusive to the other so we can uniquely identify for both tags and
                             // props
    Usecase        = 0x2000,
    Static         = 0x7000,
    GlobalUsecase  = 0x400,
    // 0x3000 - Result Prop
    // 0x4000 - Internal Prop
    // 0x5000 - Usecase Prop
    // 0x6000 - DebugData Prop
};

/// Maximum number of format planes for a CHI node.
static const UINT32 ChiNodeFormatsMaxPlanes    = 4;

/// Maximum number of images in a batch for a CHI node.
static const UINT32 ChiNodeMaxImagesInBatch    = 8;

/// Mask to OR with tags to represent the input pool residency.
static const UINT32 InputMetadataSectionMask   = static_cast<UINT32>(MetadataPoolSection::Input)  << 16;

/// Mask to OR with tags to represent the use case pool residency.
static const UINT32 UsecaseMetadataSectionMask = static_cast<UINT32>(MetadataPoolSection::Usecase) << 16;

/// Mask to OR with tags to represent the static pool residency.
static const UINT32 StaticMetadataSectionMask  = static_cast<UINT32>(MetadataPoolSection::Static) << 16;

/// Mask to OR with tags to represent global pool residency.
static const UINT32 GlobalUsecaseMetadataSectionMask  = static_cast<UINT32>(MetadataPoolSection::GlobalUsecase) << 16;

static const UINT32 ChiMaxPortMetadata                = 10;          ///< Maximum number of per-port metadata tags.
static const UINT32 InvalidPortId                     = 0xFFFFFFFF;  ///< Invalid port identifier.


static const UINT32 ChiNodeMaxDependentFences         = 10;  ///< Maximum number of CHI fence dependencies that a node can have.

// Max number of metadata tags that can be subscribed in camx
static const UINT32 MaxMetadataTagsCap                = 5000;

typedef VOID*          CHIHANDLE;                      ///< Handle to a CHI context.
typedef VOID*          CHIFENCEHANDLE;                 ///< Handle to a CHI fence.
typedef VOID*          CHIREQUESTPAYLOAD;              ///< Handle to a request payload.
typedef VOID*          CHIHEALTHMONITORCLIENTHANDLE;   ///< Handle to a HealthMonitor.
typedef VOID*          CHIHMSJOBHANDLE;                ///< Handle to a HMSJob.

const UINT32 BufferHeapDefault    = 0xFFFFFFFF;  ///< Identifies the default buffer heap.
                                                 ///  @newpage


/// @brief Metadata pool types.
typedef enum /** @cond */ ChiMetadataType /** @endcond */
{
    ChiMetadataStatic   = 0x1,          ///< Static pool of metadata.
    ChiMetadataDynamic  = 0x2,          ///< Non-static metadata.
    ChiMetadataEnd      = 0xFFFFFFFF    ///< Marks the end.
} CHIMETADATATYPE;

/// @brief Tag visibility types.
typedef enum /** @cond */ ChiTagSectionVisibility /** @endcond */
{
    ChiTagSectionVisibleToOEM       = 0x1,           ///< VenderTag section is visible to an OEM.
    ChiTagSectionVisibleToFramework = 0x2,           ///< VenderTag section is visible to the Android framework.
    ChiTagSectionVisibleToAll       = 0xFFFFFFFF,    ///< VenderTag section is visible to all.
} CHITAGSECTIONVISIBILITY;

/// @brief Print formats for tag dumps.
typedef enum /** @cond */ ChiVendorTagPrint /** @endcond */
{
    NoPrintFormat = 0,
    // chivendortagdefines.h
    PrintSensorSyncModeMetadata,
    PrintInputMetadataOpticalZoom,
    PrintRealTimeMetadataOpticalZoom,
    PrintInputMetadataBokeh,
    PrintSATSwitchController,
    PrintOutputMetadataOpticalZoom,
    PrintOutputMetadataBokeh,
    PrintMultiCameraIds,
    PrintLowPowerModeInfo,
    PrintSyncModeInfo,
    PrintActiveCameraInfo,
    PrintCaptureRequestCropRegions,
    PrintCHIRECT,
    PrintMetadataOwnerInfo,
    PrintFeature2ControllerResult,
    PrintCameraConfigs,
    PrintChiMultiCameraConfig,
    PrintChiMultiCamDimensionDiffMap,
    PrintQLLData,
    PrintDumpFileName,
    PrintImageShiftData,
    PrintIPEICAPerspectiveTransform,
    PrintIPEICAGridTransform,
    PrintMarginRequest,
    PrintStabilizationMargin,
    PrintCHIImageDimensions,
    PrintCHIDimension,
    PrintDISMVStats,
    PrintMOFAlignment,
    PrintChiSensorModeInfo,
    PrintChiSensorCaps,
    PrintFOVCOutput,
    PrintBayerAlignmentShiftOut,
    PrintCHIRectangle,
    PrintAECFrameControl,
    PrintAWBFrameControl,
    PrintAFFrameControl,
    PrintSWISPBEStatsConfig,
    PrintChiAECData,
    PrintCHIIPEICACapability,
    PrintDebugData,
    PrintAFBracketingData,
    PrintChiEEPROMInformation,
    PrintChiSensorPDAFInfo,
    PrintChiDepthConversionLibInfo,
    PrintIPEICAInterpolationParams,
    PrintWindowRegionCropF,
    PrintOEM_AEC_IQTrigger,
    PrintOEM_AWB_IQTrigger,
    PrintOEM_AF_IQTrigger,
    PrintOEM_Reserve_IQTrigger,
    PrintChiTuningModeParameter,
    PrintIFECropInfo,
    PrintChiTimestampInfo,
    PrintSensorStrobeInfo,
    PrintCSIDBinningInfo,
    PrintGeoLibStreamOutput,
    PrintParsedBHistStatsOutput,
    PrintParsedHDRBHistStatsOutput,
    PrintParsedHDR10pStatsOutput,
    PrintParsedBFStatsOutput,
    PrintParsedBF27StatsOutput,
    PrintParsedRSStatsOutput,
    PrintParsedBFWStatsOutput,
    PrintParsedIHistStatsOutput,
    PrintIFELTMDCStatsOutput,
    PrintParsedCSStatsOutput,
    PrintBayerAlignmentSize,
    PrintBayerAlignmentOffset,
    PrintRefCropWindowSize,
    PrintGeoLib2StreamCfg,
    PrintGeoLibWindowSize,
    PrintStreamCropInfo,
    PrintISPADRCParams,
    PrintIdealRawInfo,
    PrintForceFullFOVInfo,
    PrintCHITESTGENCAPS,
    PrintIFETestGenConfig,
    PrintMultiFrameData,
    PrintCascade2DLUTControlData,
    PrintCameraStatusInfo,
    PrintLowResolutionUpscale,

    // camxvendortagdefines.h
    PrintFaceROIInformation,
    PrintFDMetaDataMaskResults,
    PrintFDMetaDataUpperBodyResults,
    PrintImageDimensions,
    PrintEISOISModeData,
    PrintAECStatsControl,
    PrintAWBStatsControl,
    PrintAFStatsControl,
    PrintAFDStatsControl,
    PrintIHistStatsControl,
    PrintPropertyISPRSStats,
    PrintTMCOutputData,
    PrintGammaInfo,
    PrintUVGammaInfo,
    PrintWBandGTMOutputForTMC,
    PrintGTMInfo,
    PrintNRMConfigs,
    PrintIntermediateDimensions,
    PrintOEMJPEGEXIFAppData,
    PrintOEMJPEGEXIFApp2Data,
    PrintChiMcxCallbackInfo,
    PrintIPEICACapability,
    PrintCHIRAWFORMATPORT,
    PrintSFECompandInfo,
    PrintISPGroupsInfo,
    PrintGroup,
    PrintGroupInfo,
    PrintISPSensorGroupConfig,
    PrintCVPEncoderMetaData,
    PrintNcLibEvaCalcMvData,
    PrintRequestCropInfo,
    PrintStreamMapMeta,
    PrintScratchBufferData,
    PrintTfiInformation,
    PrintQLLInputsIpe,
    PrintSWMFandAIDETuningParams,
    PrintChromatixMetadata,

    // chivendortafoemdefines.h
    PrintEISV3PerspectiveGridTransforms,
    PrintEISv3AlgoHandleData,
    PrintEISv3AlgoTimeIntervalSync,
    PrintITOFPreprocessCalInfo,

    // helpers
    PrintCameraMetadata,
    PrintWeightedRegion,
    PrintFDMetadataResults,
    PrintLowPowerModeData,
    PrintCHIRECTINT,
    PrintFeature2ActiveCameras,
    PrintCameraIdToSubSensorMode,
    PrintCameraConfiguration,
    PrintCHILENSCAPS,
    PrintPhysicalCameraInputConfiguration,
    PrintCHILINKNODEDESCRIPTOR,
    PrintPruneSettings,
    PrintPhysicalLogicalDiffMap,
    PrintICAGridArray,
    PrintCHIRATIONAL,
    PrintCHISENSORMODECAPS,
    PrintCHISENSORSTREAMCONFIG,
    PrintFOVCData,
    PrintAECExposureData,
    PrintAECYHistStretchData,
    PrintInSensorHDR3ExpTriggerInfo,
    PrintInSensorHDR3ExpTriggeResult,
    PrintCDFSet,
    PrintAECSkipStatsParser,
    PrintAECSAConfInfo,
    PrintAWBGainParams,
    PrintAWBCCMParams,
    PrintAWBAlgoDecisionInformation,
    PrintAWBDecisionPoint,
    PrintAWBSAConfInfo,
    PrintRectangleCoordinate,
    PrintFDROIRegion,
    PrintMoveLensOutput,
    PrintPDLibWindowConfig,
    PrintPDLibWindowInfo,
    PrintPDLibWindowInfoBrck,
    PrintChiRawOTPData,
    PrintChiEEPROMCustomInfo,
    PrintChiPDAFPixelCoordinates,
    PrintChiTuningMode,
    PrintHDRBHistStatsOutput,
    PrintHDR10PFrameBHist,
    PrintIHistStatsOutput,
    PrintLTMDCStatsOutput,
    PrintSubRequestData,
    PrintFaceROIData,
    PrintMaskROIData,
    PrintBGBEConfig,
    PrintBFStatsConfigParams,
    PrintBFInputConfigParams,
    PrintBFGammaLUTConfigType,
    PrintBFScaleConfigType,
    PrintBFFilterConfigParams,
    PrintBFFIRFilterConfigType,
    PrintBFIIRFilterConfigType,
    PrintBFFilterCoringConfigParams,
    PrintBFStatsROIConfigType,
    PrintBFStatsROIDimensionParams,
    PrintBFStatsFixedWindowParams,
    PrintBFStatsBlackLevelConfig,
    PrintAFDStatsRSConfig,
    PrintISPRSStatsConfig,
    PrintNRMConfigData,
    PrintNcLibImageSize,
    PrintNcLibFloat2,
    PrintStreamCropLinkInfo,
    PrintStreamMetaPublisherInfo,
    PrintStreamMapMetaEntry,
    PrintScratchOut,
    PrintTfiInformationHeader,
    PrintCamxTime,
    PrintQLLInputGmi,
    PrintQLLInputLmi,
    PrintEISv3TimeInterval,

    // properties
    PrintAECFrameInformation,
    PrintAWBFrameInfo,
    PrintAFFrameInformation,
    PrintAFPDAFData,
    PrintASDOutput,
    PrintAFDFrameInfo,
    PrintPDLibCreateParams,
    PrintPDHwConfig,
    PrintInSensorZoomInfo,
    PrintSensorMetaData,
    PrintSensorProperties,
    PrintSensorPDAFInfo,
    PrintSensorResolutionInfo,
    PrintPropertyISPBHistStats,
    PrintPropertyISPAECBHistStats,
    PrintPropertyISPTintlessBG,
    PrintIFEScalerOutput,
    PrintPropertyISPLTMDCStats,
    PrintEncoderOutInfo,
    PrintFDPropertyFrameSettings,
    PrintLRMEPropertyFrameSettings,
    PrintPropertyISPADRCParams,
    PrintPropertyISPIntermediateDimension,
    PrintPropertyOPELTMDCStats,
    PrintIFEInstanceSubmittedRequestInfo,
    PrintAECOutputInternal,
    PrintAFOutputInternal,
    PrintASDOutputInternal,
    PrintAWBOutputInternal,
    PrintAFDOutputInternal,
    PrintBGStatsOutput,
    PrintPropertyISPAWBBGStats,
    PrintPropertyISPBFStats,
    PrintPropertyISPBFWStats,
    PrintPropertyISPCSStats,
    PrintPropertyISPHDRBEStats,
    PrintPropertyISPAECBEStats,
    PrintPropertyISPHDRBHistStats,
    PrintPropertyISPIHistStats,
    PrintISPRegionsStatsParams,
    PrintISPStatsROIParams,
    PrintFDPerFrameSettings,
    PrintUsecaseSensorModes,
    PrintLensInfo,
    PrintCameraConfigurationInformation,
    PrintSensorTemperatureInfo,
    PrintStatsStreamInitConfig,
    PrintPropertyPipelineOutputDimensions,
    PrintFDMetaDataResults,
    PrintFDMetaDataVersionedFaceContourResultsInternal,
    PrintIFEInputResolution,
    PrintIFEOutputResolution,
    PrintPDLibDataBufferInfo,
    PrintPDHwAvailablity,
    PrintPDHWEnableConditions,
    PrintTrackerROIInformation,
    PrintAFBAFHardwareCapability,
    PrintSaliencyMapData,
    PrintIFEInstanceInfo,
    PrintStatsAuxInfo,
    // helpers
    PrintAFStatusParams,
    PrintMFDOFOutput,
    PrintMFDOFDualFace,

} CHIVENDORTAGPRINT;

/// @brief Contains essential data that describes a vendor tag.
typedef struct /** @cond */ ChiVendorTagData /** @endcond */
{
    const CHAR*         pVendorTagName;     ///< Pointer to the string representation of the vendor tag name.
    UINT8               vendorTagType;      ///< Type of vendor tag.
    SIZE_T              numUnits;           ///< Number of units of vendorTagType required to program this tag.
    CHIVENDORTAGPRINT   printFormat;        ///< Detailed tag dump.
} CHIVENDORTAGDATA;

/// @brief Contains essential data that describes a vendor tag section.
typedef struct /** @cond */ ChiVendorTagSectionData /** @endcond */
{
    const CHAR*             pVendorTagSectionName;   ///< Pointer to the string representation of the vendor tag section name.
    UINT32                  firstVendorTag;          ///< First vendor tag in the vendor tag section.
    UINT32                  numTags;                 ///< Number of vendor tags in the section.
    CHIVENDORTAGDATA*       pVendorTagaData;         ///< Pointer to the vendor tag data arrays.
    CHITAGSECTIONVISIBILITY visbility;               ///< Visibility of this tag section.
} CHIVENDORTAGSECTIONDATA;

/// @brief Contains camera vendor tags capabilities. These capabilities are used to populate supported vendor tags by node.
typedef struct /** @cond */ ChiVendorTagInfo /** @endcond */
{
    CHIVENDORTAGSECTIONDATA*    pVendorTagDataArray;  ///< Pointer to the array of vendor tag sections.
    UINT32                      numSections;          ///< Number of vendor tag section in pVendorTagDataArray.
} CHIVENDORTAGINFO;

/// @brief Vendor tag information for a query.
typedef struct /** @cond */ ChiQueryVendorTag /** @endcond */
{
    UINT32               size;            ///< Size of this structure.
                                          ///
                                          ///  Mismatches in size are a warning to the node that the interface header used by
                                          ///  the node does not match the interface header used by CHI.

    CHIVENDORTAGINFO*    pVendorTagInfo;  ///< Pointer to the vendor tags that are published by the node.
                                          ///
                                          ///  Only vendor tags are reported. Android metadata tags to be published by the
                                          ///  by the node do not must be included.
} CHIQUERYVENDORTAG;

/// @brief Contains the CHI tag data.
typedef struct /** @cond */ ChiTagData /** @endcond */
{
    UINT32  size;       ///< Size of this structure.
    UINT64  requestId;                      ///< ID of the request associated with this tag.
    VOID*   pData;                          ///< Pointer to the actual data list.
    SIZE_T  dataSize;                       ///< Size of the tag data.
    UINT64  offset;                         ///< Offset from the request ID from which to request data.

    BOOL    negate;                         ///< Determines whether the offset value is be treated as negative.
                                            ///
                                            ///  @valuesbul
                                            ///   - 0 -- FALSE
                                            ///   - 1 -- TRUE (value is negative) @tablebulletend
} CHITAGDATA;

/// @brief Defines the information about the vendor tag base used by PFNCHIGETVENDORTAGBASE().
typedef struct /** @cond */ ChiVendorTagBaseInfo /** @endcond */
{
    UINT32      size;           ///< Size of this structure.
    UINT32      vendorTagBase;              ///< CHI-assigned runtime vendor tag base for a node.
    const CHAR* pComponentName;             ///< Pointer to the name of the node associated with the vendor tag base.

    const CHAR* pTagName;                   ///< Pointer to the tag name to query.
                                            ///
                                            ///  If this value is NULL, the function queries only for the base of the specified
                                            ///  pComponentName.
} CHIVENDORTAGBASEINFO;

/// @brief Contains identification information for vendor tags.
struct VendorTagInfo
{
    const CHAR*  pSectionName;  ///< Pointer to the section name for the vendor tag.
    const CHAR*  pTagName;      ///< Pointer to the name of the vendor tag.
    UINT32       tagId;         ///< Unique identifier for the vendor tag.
};

/// @brief Defines the metadata information used by PFNCHIGETMETADATA().
typedef struct /** @cond */ ChiMetadataInfo /** @endcond */
{
    UINT32              size;          ///< Size of this structure.
                                       ///
                                       ///  Mismatches in size are a warning to the node that the interface header used by
                                       ///  the node does not match the interface header used by CHI.

    CHIHANDLE           chiSession;    ///< CHI driver handle that the node can use to call back into CHI.
    UINT32              tagNum;        ///< Number of tags in the tag list.

    UINT32*             pTagList;      ///< Pointer to the list of tags for which the node requires tag data.
                                       ///
                                       ///  The list is an array of size tagNum. If a tag is published for this request,
                                       ///  CHI provides this data. Otherwise, the tag is notified as not available so the
                                       ///  node can report a dependency for its availability.

    CHITAGDATA*         pTagData;      ///< Pointer to the CHI-populated tag data for the tags requested by the node (if
                                       ///  the tags are available).
                                       ///
                                       ///  The tag data is an array of size tagNum.  If a tag is not available, CHI
                                       ///  returns the status as not available so the node can report it as a dependency
                                       ///  and return.

    CHIMETADATATYPE     metadataType;  ///< Type of metadata that the node is querying for.
                                       ///
                                       ///  All tags in tagList have same metadata type.

    const UINT32*       pTypeIdList;   ///< Pointer to the array of identifiers that represents types for given metadata.
} CHIMETADATAINFO;

/// @brief Defines a CHI fence callback after a request is done.
typedef struct /** @cond */ ChiFenceCallbackInfo /** @endcond */
{
    UINT32    size;               ///< Size of this structure.
    CHIHANDLE hChiSession;        ///< CHI driver handle that a node can use for the callback function.
    UINT64    frameNum;           ///< Frame number associated with the current request.
    INT32     processSequenceId;  ///< ID of the sequence.
    VOID*     pUserData;          ///< Pointer to the user data payload for the callback function.
} CHIFENCECALLBACKINFO;

/// @brief Data request types.
typedef enum /** @cond */ ChiDataRequestType /** @endcond */
{
    ChiFetchData,
    ChiIterateData,
} CHIDATAREQUESTTYPE;

/// @brief Data source types.
typedef enum /** @cond */ ChiDataSource /** @endcond */
{
    ChiDataGyro,
    ChiDataAccel,
    ChiTuningManager,
    ChiTuningDataManager,
    ChiDepth,
    ChiDataMagnetometer,
    ChiDataOIS,
    ChiDataGravity,
    ChiDataAISegCatMap,
    ChiDataFDROI,
    ChiEVS,
    ChiDataMax,
} CHIDATASOURCETYPE;

/// @brief Capabilities of the data sources.
typedef struct /** @cond */ ChiDataSourceCapability /** @endcond */
{
    CHIDATASOURCETYPE sourceType;      ///< Type of data source.
    UINT              numOfCaps;       ///< Number of capabilities.
    VOID*             hCaps;           ///< Pointer to an array of data source capabilities.
} CHIDATASOURCECAPABILITY;

/// @brief Defines data source configuration.
typedef struct /** @cond */ ChiDataSourceConfig /** @endcond */
{
    CHIDATASOURCETYPE sourceType;      ///< Data source type.
    VOID*             pConfig;         ///< Pointer to the data source configuration data.
} CHIDATASOURCECONFIG;

/// @brief Configuration parameters for the data sources handle.
typedef struct /** @cond */ ChiDataSourceHandle /** @endcond */
{
    CHIDATASOURCETYPE dataSourceType;  ///< Type of data source.
    VOID*             pHandle;         ///< Pointer to the internal data handle.
} CHIDATASOURCE;

/// @brief Defines the CHI data request payload.
typedef struct /** @cond */ ChiDataRequest /** @endcond */
{
    ChiDataRequestType requestType;    ///< Type of data request (fetch or iterate).
    CHIREQUESTPAYLOAD  hRequestPd;     ///< Handle to the request payload.
    INT                index;          ///< Index of the data to fetch while iterating through an appropriate data source.
} CHIDATAREQUEST;

/// @brief Contains the data for creating a buffer manager.
struct CHINodeBufferManagerCreateData
{
    UINT32              width;                  ///< Width of the buffer.
    UINT32              height;                 ///< Height of the buffer.
    UINT32              format;                 ///< Format of the buffer.
    UINT64              producerFlags;          ///< Gralloc flags for the buffer producer.
    UINT64              consumerFlags;          ///< Gralloc flags for the buffer consumer.
    UINT32              bufferStride;           ///< Indicates the buffer stride (in bytes).
    UINT                maxBufferCount;         ///< Maximum number of buffers to be allocated.
    UINT                immediateBufferCount;   ///< Number of buffers to be allocated immediately.

    BOOL                bEnableLateBinding;     ///< Indicates whether late binding for the image buffer is enabled for this
                                                ///  buffer manager.
                                                ///
                                                ///  @valuesbul
                                                ///   - 0 -- FALSE
                                                ///   - 1 -- TRUE
                                                ///
                                                ///  This value is used only if a unified buffer manager is utilized for CHI
                                                ///  buffers.

    UINT32              bufferHeap;             ///< Buffer heap that decides whether buffers are to be allocated through
                                                ///  gralloc or CSL.
};

/// Metadata ID information about a vendor tag or camera tag.
typedef struct /** @cond */ ChiMetadataId /** @endcond */
{
    BOOL isVendorTag;                   ///< Indicates whether the metadata ID is a vendor tag or camera tag.
                                        ///
                                        ///  @valuesbul
                                        ///  - 0 -- FALSE (cameraTag structure is filled)
                                        ///  - 1 -- TRUE (vendorTag structure is filled) @tablebulletend

    /// @brief Vendor and camera tag identifiers.
    union TagIdInfo
    {
        VendorTagInfo vendorTag;        ///< Information about the vendor tag.
        UINT32 cameraTag;               ///< Unique identifier of the camera tag.
    } u;    ///< Vendor and camera tag identifiers.
} CHIMETADATAID;

/// @brief Contains information for a fence handle.
typedef struct /** @cond */ CHIMultiFenceHandle /** @endcond */
{
    UINT            numChiFences;                           ///< Number of CHI fences.
    CHIFENCEHANDLE  hChiFence[ChiNodeMaxDependentFences];   ///< Array of CHI fence handles.
} CHIMULTIFENCEHANDLE;

/// @brief Information about a vendor or camera tag.
typedef struct /** @cond */ ChiMetadataIdArray /** @endcond */
{
    UINT32         size;                            ///< Size of this structure.
    CHIHANDLE      chiSession;                      ///< CHI driver handle that a node can use for the callback function.
    UINT32         tagCount;                        ///< Count of valid data in tagIdArray.
    CHIMETADATAID  tagIdArray[ChiMaxPortMetadata];  ///< Array of vendor or camera tag IDs.
} CHIMETADATAIDARRAY;

/// @brief Contains port-specific information about a metadata list.
typedef struct /** @cond */ ChiPSMetadata /** @endcond */
{
    UINT32              size;               ///< Size of this structure.
    CHIHANDLE           chiSession;         ///< CHI driver handle that a node can use for the callback function.
    UINT32              portId;             ///< Unique identifier of the port.
    UINT32              tagCount;           ///< Number of tags in pTagList.
    UINT32*             pTagList;           ///< Pointer to the list of tags.
    CHITAGDATA*         pTagData;           ///< Pointer to the vendor or camera tag data.
} CHIPSMETADATA;

/// @brief Contains port-specific bypass information about a metadata list.
typedef struct /** @cond */ ChiPSMetadataBypassInfo /** @endcond */
{
    UINT32              size;               ///< Size of this structure.
    CHIHANDLE           chiSession;         ///< CHI driver handle that the node can use to call back into CHI.
    UINT32              portCount;          ///< Number of ports to be bypassed.
    UINT32*             pInputPortIds;      ///< Pointer to the list of input port IDs.
    UINT32*             pOutputPortIds;     ///< Pointer to the list of output port IDs.
} CHIPSMETADATABYPASSINFO;

/// @brief Contains port-specific tag information.
typedef struct /** @cond */ ChiPSTagInfo /** @endcond */
{
    UINT                tag;                ///< Unique identifier of the tag.
    UINT32              inputPortId;        ///< Unique identifier of the input port.
    CHIHANDLE           chiSession;         ///< CHI driver handle that a node can use for a callback function.
} CHIPSTAGINFO;

/// @brief Contains resource information.
typedef struct /** @cond */ ChiResourceInfo /** @endcond */
{
    UINT32        resourceId;               ///< Unique identifier of the resource. Values [0-100] are reserved for internal
                                            ///  use.
    UINT32        deviceID;                 ///< Unique identifier of the device.
    const CHAR*   pResourceName;            ///< Pointer to the name of the resource.
    UINT32        totalAvailableResource;   ///< Total number of available resources.
} CHIRESOURCEINFO;

/// @brief Contains per frame information for depth frame synchronization.
typedef struct /** @cond */ ChiDepthSyncPerFrameInfo /** @endcond */
{
    UINT64  sofTimestamp;   ///< Start-of-frame timestamp for the Bayer sensor.
    UINT64  soeTimestamp;   ///< End-of-frame timestamp for the Bayer sensor.
    UINT64  frameDuration;  ///< Frame duration for the Bayer sensor.
                            ///  @newpagetable
} CHIDEPTHSYNCPERFRAMEINFO;

/// @brief Contains present information for metadata in publishList
typedef struct ChiMetaDataPresent
{
    BOOL    isPresent;      ///< Indicates whether the metadata is present
    UINT32  tagId;          ///< tagId Identifier of the tag to be checked
    UINT32  typeId;         ///< typeId Type id which represents type for a given meta data
} CHIMETADATAPRESENT;

/// @brief Valid resource priorities, where the highest priority implies exclusive access to resources.
typedef enum /** @cond */ ChiResourcePriority /** @endcond */
{
    LOW_PRIORITY,
    NORMAL_PRIORITY,
    HIGH_PRIORITY,
} CHIRESOURCEPRIORITY;

/// @brief Valid resource types.
typedef enum /** @cond */ ChiResourceType /** @endcond */
{
    SENSOR          = 1,    ///< Hardware resource type.
    IFE             = 2,    ///< Image Front End.
    IPE             = 3,    ///< Image Processing Engine.
    BPS             = 4,    ///< Bayer Processing Section.
    CSIPHY          = 5,    ///< Physical hardware for the Camera Serial Interface.
    AONI2C          = 6,    ///< AON I2C
    ResourceTypeMax = 7,    ///< Maximum number of resource types.
    RESERVED        = 100,  ///< Must be initialized to NULL.
} CHIRESOURCETYPE;

typedef CHIDATASOURCE* CHIDATASOURCEHANDLE;  ///< Pointer to the handle to a CHI data source.

typedef VOID* IMAGEBUFFERHANDLE; ///< Pointer to the handle for the image buffer.

/// @brief Valid pixel formats.
typedef enum /** @cond */ ChiFormat /** @endcond */
{
    JPEG               = 0,           ///< JPEG format.
    Y8                 = 1,           ///< Luma only, with 8 bits per pixel.
    Y16                = 2,           ///< Luma only, with 16 bits per pixel.
    YUV420NV12         = 3,           ///< YUV 420 format as described by the NV12 FOURCC.
    YUV420NV21         = 4,           ///< YUV 420 format as described by the NV21 FOURCC.
    YUV422NV16         = 5,           ///< YUV 422 format as described by the NV16 FOURCC.
    Blob               = 6,           ///< Any non-image data.

    RawYUV8BIT         = 7,           ///< Packed YUV/YVU Raw format where 16 bpp = 8 bits Y and 8 bits UV.
                                      ///  U and V are interleaved as YUYV or YVYV.

    RawPrivate         = 8,           ///< Private Raw formats where data is packed into 64-bit words. P0 is stored at the LSB
                                      ///  for all BPPs. \n @vertspace{4}
                                      ///  - 8 BPP: 64-bit word contains 8 pixels p0 to p7, where p0 is stored at the LSB.
                                      ///    @vertspace{-3}
                                      ///  - 10 BPP: 64-bit word contains 6 pixels p0 to p5, where the most significant 4 bits
                                      ///    are set to 0. @vertspace{-3}
                                      ///  - 12 BPP: 64-bit word contains 5 pixels p0 to p4, where the most significant 4 bits
                                      ///    are set to 0. @vertspace{-3}
                                      ///  - 14 BPP: 64-bit word contains 4 pixels p0 to p3, where the most significant 8 bits
                                      ///    are set to 0. @vertspace{3}

    RawMIPI            = 9,           ///< MIPI Raw formats based on the MIPI CSI-2 specification. \n @vertspace{4}
                                      ///  - 8 BPP: Each pixel occupies one byte, starting at the LSB. The output width of the
                                      ///    image has no restrictions. @vertspace{-3}
                                      ///  - 10 BPP: 4 pixels are held in every 5 bytes. The output width of the image must be
                                      ///    a multiple of 4 pixels. @vertspace{3}

    RawMIPI10          = RawMIPI,     ///< MIPI Raw format; the default is a 10-bit format.

    RawPlain16         = 10,          ///< Plain16 Raw format, where a single pixel is packed into two bytes, in little endian
                                      ///  format. Not all bits can be used because Raw data is typically 8, 10, or 12 bits per
                                      ///  pixel. Lower order bits are filled first.

    RawPlain16LSB10bit = RawPlain16,  ///< Plain16 Raw format; the default is a 10-bit format.

    RawMeta8BIT        = 11,          ///< Generic 8-bit Raw metadata for internal camera usage.
    UBWCTP10           = 12,          ///< UBWC TP10 format (per the UBWC2.0 design specification).
    UBWCNV12           = 13,          ///< UBWC NV12 format (per the UBWC2.0 design specification).
    UBWCNV124R         = 14,          ///< UBWC NV12-4R format (per the UBWC2.0 design specification).
    YUV420NV12TP10     = 15,          ///< YUV 420 format; 10 bits per compressed tight packed format.
    YUV420NV21TP10     = 16,          ///< YUV 420 format; 10 bits per compressed tight packed format.
    YUV422NV16TP10     = 17,          ///< YUV 422 format; 10 bits per compressed tight packed format.
    PD10               = 18,          ///< PD10 format.
    RawMIPI8           = 19,          ///< 8 BPP, where each pixel occupies 1 byte starting at the LSB. The output width of the
                                      ///  image has no restrictions.
    P010               = 22,          ///< P010 format.
    RawPlain64         = 23,          ///< Plain 64 Raw format.
    UBWCP010           = 24,          ///< UBWC P010 format (per the UBWC2.0 design specification).
    RawMIPI12          = 26,          ///< 12 BPP, where 2 pixels are held in every 3 bytes. The output width of the image must
                                      ///  be a multiple of 2 pixels.
    RawPlain16LSB12bit = 27,          ///< Plain 16 Raw format; 12 bits per pixel.
    RawMIPI14          = 28,          ///< 14 BPP, where 4 pixels are held in every 7 bytes. The output width of the image must
                                      ///  be a multiple of 4 pixels.
    RawPlain16LSB14bit = 29,          ///< Plain 16 Raw format; 14 bits per pixel.
    LMC                = 32,          ///< DMM map used for LMC. The size is 64 bits per 8x8 block, including two MVs
                                      ///  (X and Y).
    BlurMap            = 33,          ///< Plain8 format for a Blur map. Its stride requires two more pixels than its width.
    P010LSB            = 34,          ///< P010 format; LSB-aligned.
    ARGB               = 35,          ///< ARGB format where each pixel occupies 4 or 8 bytes.
                                      ///  ARGB8888 and ARGB2101010 are 4 bytes; ARGB16161616 is 8 bytes.
    UBWCP016LMC        = 36,          ///< UBWC P016 format for lmc mv
    UBWCP016           = 37,          ///< UBWC P016 format (as per UBWC4.0 design specification)
    RGB_888            = 39,          ///< RGB 888 format, interlaved, RGB: 24bit
} ChiFormat;

/// @brief Degrees of rotation in a clockwise direction.
///
/// The specific variable or structure member must declare the semantics of the rotation (for example, the image has been
/// rotated or must be rotated).
typedef enum  /** @cond */ ChiRotation /** @endcond */
{
    CW0Degrees,     ///< Zero degree rotation.
    CW90Degrees,    ///< 90 degree clockwise rotation.
    CW180Degrees,   ///< 180 degree clockwise rotation.
    CW270Degrees    ///< 270 degree clockwise rotation.
} ChiRotation;

/// @brief Valid color space specifications.
typedef enum /** @cond */ ChiColorSpace /** @endcond */
{
    Unknown,    ///< Assumes the default data space when the space is not explicitly specified.
    BT601Full,  ///< ITU-R Recommendation 601 (BT.601) -- Full range.
    BT601625,   ///< ITU-R Recommendation 601 (BT.601) -- 625-line  SDTV, 625 lines (PAL).
    BT601525,   ///< ITU-R Recommendation 601 (BT.601) -- 525-line SDTV, 525 lines (NTSC).
    BT709,      ///< ITU-R Recommendation 709 (BT.709) -- HDTV.
    Depth       ///< Buffer contains depth ranging measurements from a depth camera per the HAL definition.
} ChiColorSpace;

/// @brief Color filter patterns for Raw outputs.
typedef enum class /** @cond */ ChiColorFilterPattern /** @endcond */
{
    Y,      ///< Monochrome pixel pattern.
    YUYV,   ///< YUYV pixel pattern.
    YVYU,   ///< YVYU pixel pattern.
    UYVY,   ///< UYVY pixel pattern.
    VYUY,   ///< VYUY pixel pattern.
    RGGB,   ///< RGGB pixel pattern.
    GRBG,   ///< GRBG pixel pattern.
    GBRG,   ///< GBRG pixel pattern.
    BGGR,   ///< BGGR pixel pattern.
    RGB     ///< RGB pixel pattern.
} ChiColorFilterPattern;

/// @brief Defines the Raw format.
typedef struct /** @cond */ ChiRawFormat /** @endcond */
{
    INT32                  bitsPerPixel;        ///< Bits per pixel of the Raw format.
    UINT32                 stride;              ///< Stride in bytes.

    UINT32                 sliceHeight;         ///< Number of lines in the plane.
                                                ///
                                                ///  This value can be equal to or larger than the actual frame height.

    ChiColorFilterPattern  colorFilterPattern;  ///< Color filter pattern of the Raw format.
} CHIRAWFORMAT;

/// @brief Defines the YUV formats.
typedef struct /** @cond */ ChiYUVFormat /** @endcond */
{
    UINT32 width;           ///< Width of the YUV plane (in pixels).
                            ///
                            ///  The tile width is aligned in bytes for UBWC.

    UINT32 height;          ///< Height of the YUV plane (in pixels).

    UINT32 planeStride;     ///< Number of bytes between the first byte of two sequential lines on plane 1.
                            ///
                            ///  If the line includes padding, this value might be greater than nWidth * nDepth / 8.
                            ///
                            ///  The macro tile width is aligned for UBWC.

    UINT32 sliceHeight;     ///< Number of lines in the plane that can be equal to or greater than the actual frame height.
                            ///
                            ///  The tile height is aligned for UBWC.

    UINT32 metadataStride;  ///< Aligned metadata plane stride (in bytes) that is used for UBWC formats.
    UINT32 metadataHeight;  ///< Aligned metadata plane height (in bytes) that is used for UBWC formats.
    UINT32 metadataSize;    ///< Aligned metadata plane size (in bytes) that is used for UBWC formats.
    SIZE_T pixelPlaneSize;  ///< Aligned pixel plane size (in bytes) that is calculated once for UBWC formats and stored
                            ///  thereafter (because the calculations are expensive).
                            ///  @newpagetable
} CHIYUVFORMAT;

/// @brief Defines the JPEG format.
struct CHIJPEGFormat
{
    UINT32              maxJPEGSizeInBytes;       ///< Size of the JPEG image for the maximum resolution (in bytes).
};

/// @brief Union of parameters that are only specified in certain output formats: YUV, Raw, or JPEG.
union ChiFormatParams
{
    CHIYUVFORMAT  yuvFormat[ChiNodeFormatsMaxPlanes];    ///< Array of YUV format-specific properties.
    CHIRAWFORMAT  rawFormat;                             ///< Raw format-specific properties.
    CHIJPEGFormat jpegFormat;                            ///< JPEG format-specific properties.
};

/// @brief Stride and scanline alignment for each plane.
typedef struct /** @cond */ ChiAlignmentInfo /** @endcond */
{
    UINT32 strideAlignment;      ///< Aligns by stride.
    UINT32 scanlineAlignment;    ///< Aligns by scanline.
} CHIALIGNMENTINFO;

/// @brief Defines the image format.
typedef struct /** @cond */ ChiImageFormat /** @endcond */
{
    UINT32           width;                                   ///< Width of the image (in pixels).
    UINT32           height;                                  ///< Height of the image (in pixels).
    ChiFormat        format;                                  ///< Format of the image.
    ChiColorSpace    colorSpace;                              ///< Color space of the image.
    ChiRotation      rotation;                                ///< Rotation applied to the image.
    ChiFormatParams  formatParams;                            ///< Format-specific definitions.
    SIZE_T           alignment;                               ///< Required alignment (in bytes) of the starting address of
                                                              ///  the allocated buffer with this image format.
    CHIALIGNMENTINFO planeAlignment[ChiNodeFormatsMaxPlanes]; ///< Array of strides and scanline alignments for each plane.
} CHIIMAGEFORMAT;

/// @brief Defines the image buffer.
typedef struct /** @cond */ ChiImage /** @endcond */
{
    UINT32           size;                                   ///< Size of the structure.
    INT              fd[ChiNodeFormatsMaxPlanes];            ///< Maps the buffer to the file descriptor.
    UCHAR*           pAddr[ChiNodeFormatsMaxPlanes];         ///< Pointer to the starting virtual address of the allocated
                                                             ///  buffer.
    CHIHANDLE        pNativeHandle;                          ///< Pointer to the native handle.
} CHIIMAGE;


/// @brief Master structure for a single image buffer.
///
/// In batch mode, the single image buffer might contain multiple image buffers (#CHIIMAGE).
typedef struct /** @cond */ ChiImageList /** @endcond */
{
    UINT32            size;                                   ///< Size of this structure.
    CHIIMAGEFORMAT    format;                                 ///< Buffer format: width, height, format, and so on.
    UINT              numberOfPlanes;                         ///< Number of planes in this image type.
    SIZE_T            planeSize[ChiNodeFormatsMaxPlanes];     ///< Array of plane sizes.
    SIZE_T            metadataSize[ChiNodeFormatsMaxPlanes];  ///< Array of metadata sizes.
    UINT32            imageCount;                             ///< Number of images in the pImageList.
    CHIIMAGE          pImageList[ChiNodeMaxImagesInBatch];    ///< Array of images.
    UINT32            portId;                                 ///< Port for the image.
    INT32             handles[ChiNodeFormatsMaxPlanes];       ///< CSL memory handle of buffers.

    VOID*             pfenceHandle;                           ///< Handle to the image buffer fence.
                                                              ///
                                                              ///  If this parameter is set to NULL, do not set the dependency.
                                                              ///  The parameter is NULL for the output buffers.
    VOID*             pSynxFenceHandle;                       ///< Synx fence corresponding to pfenceHandle
    VOID*             pIsFenceSignaled;                       ///< Pointer to the fence variable whose signaled status is
                                                              ///  checked.
                                                              ///
                                                              ///  This parameter is valid only when fenceHandle in not NULL.

    IMAGEBUFFERHANDLE imageHandle;                            ///< Handle of the image buffer.
} CHIIMAGELIST;

/** @} */ /* end_addtogroup chi_node_datatypes */


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIGETLOGICALCAMERAID @endcond
///
/// @brief Gets the logical camera ID associated with a CHI session.
///
/// @datatypes
/// #CHIHANDLE
///
/// @param[in] hChiSession  Handle of the session.
///
/// @return Logical camera ID. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef UINT32 (*PFNCHIGETLOGICALCAMERAID)(CHIHANDLE hChiSession);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIFENCECALLBACK @endcond
///
/// @brief Asynchronous wait callback signature for a CHI fence.
///
/// @datatypes
/// #CHIFENCEHANDLE
///
/// @param[in] hChiFence  Handle to the CHI fence.
/// @param[in] pUserData  User data provided when waiting on the fence.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID (*PFNCHIFENCECALLBACK)(CHIMULTIFENCEHANDLE hMultiFenceHandle, VOID* pUserData);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIGETMETADATA @endcond
///
/// @brief Gets a list of metadata information based on metadata tags.
///
/// @datatypes
/// #CHIMETADATAINFO
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information requested by the node.
///
/// @detdesc
/// The tag can be an Android tag or a vendor tag.
/// @par
/// If the metadata information associated with a tag is not published, CHI returns that tag as unpublished when this function
/// returns. The node can add them in the dependency reporting.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIGETMETADATA)(CHIMETADATAINFO* pMetadataInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIGETMULTICAMDYNAMICMETABYCAMID @endcond
///
/// @brief Gets a list of metadata information for multi-camera metadata tags that are based on the camera ID.
///
/// @datatypes
/// #CHIMETADATAINFO
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information requested by the node.
/// @param[in] cameraId       Unique ID of the camera. This ID must be set while posting metadata. An invalid camera ID can be
///                           set if the camera ID is not required.
///
/// @detdesc
/// The tag can be an Android tag or a vendor tag.
/// @par
/// If the metadata information associated with the tag is not published, the CHI driver returns those tags as unpublished when
/// this function returns. The node can add them in the dependency reporting.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIGETMULTICAMDYNAMICMETABYCAMID)(CHIMETADATAINFO* pMetadataInfo, UINT32 cameraId);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIGETSTATICMETADATA @endcond
///
/// @brief Gets a list of static metadata information based on metadata tags.
///
/// @datatypes
/// #CHIMETADATAINFO
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information requested by the node.
/// @param[in] cameraId       Unique ID of the camera.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult(*PFNCHIGETSTATICMETADATA)(CHIMETADATAINFO* pMetadataInfo, UINT32 cameraId);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNFORCEDRQTOREMOVELDEPENDENCIES @endcond
///
/// @brief Forces the DRQ to remove all the dependencies of a node.
///
/// @param[in] hChiSession  Handle to the CHI session.
/// @param[in] reqId        requestId
///
/// @return None.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID(*PFNFORCEDRQTOREMOVEDEPENDENCIES)(CHIHANDLE hChiSession, UINT64 reqId);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHISETMETADATA @endcond
///
/// @brief Sets a list of metadata information based on metadata tags.
///
/// @datatypes
/// #CHIMETADATAINFO
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information published by the node.
///
/// @detdesc
/// The tag can be an Android tag or a vendor tag.
/// @par
/// When published, the CHI driver notifies all other nodes that reported these tags as dependencies.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHISETMETADATA)(CHIMETADATAINFO* pMetadataInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIGETVENDORTAGBASE @endcond
///
/// @brief Queries the base of all vendor tags of other nodes.
///
/// @datatypes
/// #CHIVENDORTAGBASEINFO
///
/// @param[in] pVendorTagBaseInfo  Pointer to the structure that defines the run-time CHI-assigned vendor tag base.
///
/// @detdesc
/// This function serves two purposes:
/// - Gets the vendor tag base for tags exported from the CHI component.
///    - A tag can be from a CHI default node or another third-party custom node on which this node is dependent for request
///      processing.
///    - The node uses this base and the actual tag offset to derive the tag ID (= base + offset) to report the dependencies.
/// - Gets the tag value for a specific tag(string). The tag can be any one of the tags populated by other nodes.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIGETVENDORTAGBASE)(CHIVENDORTAGBASEINFO* pVendorTagBaseInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIQUERYVENDORTAG @endcond
///
/// @brief Gets the vendor tags that the node can publish.
///
/// @datatypes
/// #CHIQUERYVENDORTAG
///
/// @param[in] pQueryVendorTag  Pointer to the exported vendor tags.
///
/// @detdesc
/// This function exports the vendor tags supported by the component.
/// @par
/// The CHI driver appends these vendor tags to the overall vendor tag superset. This superset comprises all enumerated vendor
/// tags from other extension components, including CHI default component-supported vendor tags.
/// @par
/// If the node does not publish any vendor tags, set this function pointer to NULL.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIQUERYVENDORTAG)(CHIQUERYVENDORTAG* pQueryVendorTag);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIPSGETSUPPORTEDMETADATALIST @endcond
///
/// @brief Gets a list of port-specific metadata supported by the CHI driver.
///
/// @datatypes
/// #CHIMETADATAIDARRAY
///
/// @param[in] pMetadataIdArray  Pointer to the array of metadata IDs.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIPSGETSUPPORTEDMETADATALIST) (
    CHIMETADATAIDARRAY* pMetadataIdArray);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIPSGETMETADATA @endcond
///
/// @brief Gets a list of port-specific metadata information based on metadata tags.
///
/// @datatypes
/// #CHIPSMETADATA
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information requested by the node.
///
/// @detdesc
/// The tag must be per-port metadata defined by the CHI driver and queried through PFNCHIPSGETSUPPORTEDMETADATALIST().
/// @par
/// If the metadata information associated with the tag is not published, the CHI driver returns those tags as unpublished when
/// this function returns. The node can add them in the dependency reporting.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIPSGETMETADATA) (
    CHIPSMETADATA* pMetadataInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIPSSETMETADATA @endcond
///
/// @brief Sets a list of port-specific metadata information based on metadata tags.
///
/// @datatypes
/// #CHIPSMETADATA
///
/// @param[in] pMetadataInfo  Pointer to the list of metadata information published by the node.
///
/// @detdesc
/// The tag must be per-port metadata defined by the driver and queried through PFNCHIPSGETSUPPORTEDMETADATALIST().
/// @par
/// When published, the CHI driver notifies all other node that reported the tag as a dependency.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIPSSETMETADATA) (
    CHIPSMETADATA* pMetadataInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIPSPUBLISHMETADATA @endcond
///
/// @brief Publishes a list of port-specific metadata information based on metadata tags.
///
/// @datatypes
/// #CHIPSMETADATABYPASSINFO
///
/// @param[in] metadataId   Unique ID of the metadata.
/// @param[in] pBypassInfo  If non-NULL, points to a map of the input and output ports that contain the metadata.
///
/// @detdesc
/// The tag must be per-port metadata defined by the CHI driver and queried through PFNCHIPSGETSUPPORTEDMETADATALIST().
/// @par
/// When published, the CHI driver notifies all other nodes that reported the tag as a dependency.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIPSPUBLISHMETADATA) (
    UINT32                   metadataId,
    CHIPSMETADATABYPASSINFO* pBypassInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIISPSMMETADATAPUBLISHED @endcond
///
/// @brief Checks whether port metadata was published.
///
/// @datatypes
/// #CHIPSTAGINFO
///
/// @param[in] tag  Pointer to the process request information for the CHI node.
///
/// @return TRUE if published. Otherwise, FALSE. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef BOOL (*PFNCHIISPSMETADATAPUBLISHED) (
    CHIPSTAGINFO* pTagInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIREGISTERRESOURCE @endcond
///
/// @brief Registers a resource.
///
/// @datatypes
/// #CHIRESOURCEINFO
///
/// @param[in] pResourceInfo  Pointer to the CHI node resource information.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIREGISTERRESOURCE) (
    CHIRESOURCEINFO* pResourceInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIUNREGISTERRESOURCE @endcond
///
/// @brief Deregisters a resource.
///
/// @param[in] resourceId  Unique identifier of the resource.
/// @param[in] deviceID    Unique identifier of the device.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIUNREGISTERRESOURCE) (
    UINT32 resourceId,
    UINT32 deviceID);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNRELEASERESOURCE @endcond
///
/// @brief Asynchronous notification callback function used to release resources.
///
/// @param[in] reservationId     Unique identifier of the reservation that CamX is to preempt.
/// @param[in] pCallbackContext  Pointer to the context of the callback.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID(*PFNRELEASERESOURCE) (
    UINT32 reservationId,
    VOID*  pcallbackContext);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIRESERVERESOURCE @endcond
///
/// @brief Reserves a resource given a reservation ID and priority.
///
/// @datatypes
/// #CHIHANDLE \n
/// #CHIRESOURCETYPE \n
/// #CHIRESOURCEPRIORITY \n
/// #PFNRELEASERESOURCE
///
/// @param[in] hChiSession       Handle to the CHI session.
/// @param[in] resourceType      Type of resource to be reserved.
/// @param[in] deviceId          Unique identifier of the device.
/// @param[in] priority          Priority of the reservation.
/// @param[in] resourceCost      Cost of the resource (maximum cost is 100).
/// @param[in] pfnRelease        Callback function to indicate release of the resource.
/// @param[in] pCallbackContext  Pointer to the context of the callback.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIRESERVERESOURCE) (
    CHIHANDLE           hChiSession,
    CHIRESOURCETYPE     resourceType,
    UINT32              deviceId,
    CHIRESOURCEPRIORITY priority,
    UINT32              resourceCost,
    PFNRELEASERESOURCE  pfnRelease,
    VOID*               pCallbackContext);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNCHIUNREGISTERRESOURCE @endcond
///
/// @brief Unreserve a resource.
///
/// @datatypes
/// #CHIHANDLE
///
/// @param[in] hChiSession CHI session handle.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNCHIUNRESERVERESOURCE) (
    CHIHANDLE   hChiSession);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNDUMPCORENODECONFIG @endcond
///
/// @brief Dumps initial configuration and session information per node.
///
/// @datatypes
/// #CHIHANDLE
///
/// @param[in] fd         File descriptor.
/// @param[in] indent     Number of indent spaces.
/// @param[in] requestId  Unique identifier of the request.
/// @param[in] hHandle    Handle of the node session.
///
/// @return #CDKResultSuccess or an error code (see Section @xref{hdr:resultMessages}). @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*PFNDUMPCORENODECONFIG) (
    INT         fd,
    UINT32      indent,
    CHIHANDLE   hHandle);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNHMSEVENTCB @endcond
///
/// @brief Funtion pointer callback for HMS event.
///
/// @param[in] pFailedJobs             Failed jobs list.
/// @param[in] numFailedJobs           Number of failed jobs.
/// @param[in] isDumpOnly              If only dump is requested.
/// @param[in] forceSigAbort           Trigger sigabort.
/// @param[in] isThreadDumpRequested   If thread dump is requested.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID (*PFNHMSEVENTCB) (
    VOID*   pFailedJobs,
    UINT32  numFailedJobs,
    BOOL    isDumpOnly,
    BOOL    forceSigAbort,
    BOOL    isThreadDumpRequested);

/** @} */ /* end_addtogroup chi_common_tags */

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNISMETADATAPRESENTINPUBLISHLIST @endcond
///
/// @brief Checks if the tag defined by tagId is present in the Per-Frame publishlist.
///
/// @param[in] hChiSession     Handle to the CHI session.
/// @param[in] pMetadataList   Metadata List to check if the tag defined by tagId is present in the Per-Frame publishlist.
/// @param[in] numOfMetadata   Indicates the number of Metadata
///
/// @return None.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID (*PFNISMETADATAPRESENTINPUBLISHLIST) (
    CHIHANDLE            hChiSession,
    CHIMETADATAPRESENT*  pMetadataList,
    UINT32               numOfMetadata);

#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHICOMMON_H

