////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2022-2023 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  camxroimixerinterface.h
/// @brief ROI MIXER algorithm interfaces
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXROIMIXERINTERFACE_H
#define CAMXROIMIXERINTERFACE_H

#include "camxtrackerinterface.h"

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

/// Data structures that are exposed to OEM must be packed to have the expected layout.
#pragma pack(push, CDK_PACK_SIZE)

/// @brief Represents ROIMixer State type
typedef enum
{
    ROIMixerStageInvalid                = -1,         ///< Invalid type
    ROIMixerStageMixer,                               ///< Output regist ROI
    ROIMixerStageOutputROI,                           ///< Output final tracker ROI
    ROIMixerStageCount,                               ///< Indicate the total number of algorithm state
    ROIMixerStageMax                    = 0x7FFFFFFF  ///< Anchor to indicate the last item in the defines
} ROIMixerAlgoStage;

/// @brief Represents ROIMixer type
typedef enum
{
    ROITypeInvalid                      = 0,          ///< Invalid type
    ROITypeFace,                                      ///< Face Type
    ROITypeSaliency,                                  ///< Saliency Type
    ROITypeSeg,                                       ///< Segmentation Type
    ROITypeGeneral,                                   ///< General Type
    ROITypeCount,                                     ///< ROI count
    ROITypeMax                          = 0x7FFFFFFF  ///< Anchor to indicate the last item in the defines
} ROIMixerType;



/// @brief Represents ROIMixer output type
typedef enum
{
    ROIMixerAlgoOutputInvalid           = -1,         ///< Invalid type
    ROIMixerAlgoOutputInfo              = 0,          ///< ROI Mixer output
                                                      ///  Payload: ROIMixerLibOutput
    ROIMixerAlgoOutputDebugData,                      ///< Debug data used
                                                      ///  Payload: StatsDataPointer
    ROIMixerAlgoOutputVendorTag,                      ///< Vendor tag data. List of vendor tags the algorithm wants to publish.
                                                      ///  Payload StatsVendorTagList
    ROIMixerAlgoOutputCount,                          ///< Indicate the total number of algorithm output
    ROIMixerAlgoOutputMax               = 0x7FFFFFFF  ///< Anchor to indicate the last item in the defines
} ROIMixerAlgoOutputType;


/// @brief the one single type of ROIMixer output from the algorithm
typedef struct
{
    VOID*                    pOutput;                 ///< Pointer to the payload. See ROIMixerAlgoOutputType for details
                                                      ///  Algorithm implementer needs to do a deep copy
    SIZE_T                   sizeOfOutput;            ///< Size of input payload pointed to by pROIMixerOutput
    ROIMixerAlgoOutputType   outputType;              ///< Type of the payload
} ROIMixerAlgoOutput;

/// @brief Represents the array of ROIMixer output from the algorithm
typedef struct
{
    ROIMixerAlgoOutput* pROIMixerOutputList;          ///< Pointer to ROIMixerAlgoOutput array.
    SIZE_T              numberOfOutput;               ///< Number of elements in pOutputData
} ROIMixerAlgoOutputList;


/// @brief Identifies the type of input parameter to ROIMixer algorithm
typedef enum
{
    ROIMixerAlgoInputInvalid            = -1,         ///< Invalid type
    ROIMixerInputRequestID              =  0,         ///< Request ID type.
                                                      ///  Payload type: UINT64
    ROIMixerAlgoInputInfo,                            ///< ROI Mixer Algo Info
                                                      ///  Payload type: ROIMixerLibInput
    ROIMixerAlgoInputSegInfo,                         ///< The Segmentation data
                                                      ///  Payload type: FaceROIInformation
    ROIMixerAlgoInputTrackerState,                    ///< Tracker state
                                                      ///  Payload type: TrackerResults
    ROIMixerAlgoInputTrackerROI,                      ///< Tracker Result
                                                      ///  Payload type: TrackerROIInformation
    ROIMixerAlgoInputRegROI,                          ///< The Face data
                                                      ///  Payload type: TrackerROIInformation
    ROIMixerAlgoInputCount,                           ///< Indicate the total number of algorithm input
    ROIMixerAlgoInputMax                = 0x7FFFFFFF  ///< Anchor to indicate the last item in the defines
} ROIMixerAlgoInputType;

/// @brief Represents one single ROIMixer input to the ROIMixer algorithm
struct ROIMixerAlgoInput
{
    VOID*                   pInput;                   ///< Pointer to the payload. See ROIMixerAlgoInputType for details.
    UINT32                  sizeOfInput;              ///< Size of payload
    ROIMixerAlgoInputType   inputType;                ///< Type of the payload
    ROIMixerAlgoInput()
    : pInput(NULL)
    , sizeOfInput(0)
    , inputType(ROIMixerAlgoInputInvalid)
    {};
};

/// @brief Represents ROIMixer module inputs to the ROIMixer algorithm
typedef struct
{
    ROIMixerAlgoInput*  pROIMixerInputList;           ///< Pointer to the payload. See ROIMixerAlgoInput for details.
    SIZE_T              numberOfInput;                ///< Number of discrete input
} ROIMixerAlgoInputList;

/// @brief Identifies the type of input parameter to AWB algorithm
typedef enum
{
    ROIMixerAlgoSetParamInvalid         = -1,         ///< Invalid type
    ROIMixerAlgoSetParamChromatixData,                ///< The chromatix tuning header for ROIMixer
                                                      ///  Payload type: StatsTuningData
    ROIMixerAlgoSetParamOverrideSettings,             ///< Override Settings
                                                      ///  Payload:
    ROIMixerSetParamCount,                            ///< Indicate the total number of algorithm Set Param
    ROIMixerAlgoSetParamMax             = 0x7FFFFFFF  ///< Anchor to indicate the last item in the defines
} ROIMixerAlgoSetParamType;

/// @brief Represents a roi Mixer input parameter
struct ROIMixerAlgoSetParam
{
    VOID*                      pSetParam;             ///< Pointer to ROIMixer set param data
    UINT32                     sizeOfSetParam;        ///< Size of data pointed to by pSetParam
    ROIMixerAlgoSetParamType   setParamType;          ///< Type of the input parameter
    ROIMixerAlgoSetParam()
    : pSetParam(NULL)
    , sizeOfSetParam(0)
    , setParamType(ROIMixerAlgoSetParamInvalid)
    {};
};


/// @brief Represents an AWB input parameter passed to AWBAlgorithm::SetInput()
typedef struct
{
    ROIMixerAlgoSetParam*   pROIMixerSetParamList;    ///< Pointer to ROIMixer input param data
    SIZE_T                  numberOfSetParam;         ///< Number of input param parameters
} ROIMixerAlgoSetParamList;

/// @brief Describe ROIMixer Algorithm Get Parameter definition
typedef enum
{
    ROIMixerAlgoGetParameterTypeInvalid = -1,         ///< Invalid type
                                                      ///  Payload: NULL & set size to zero.
    ROIMixerAlgoGetParamPublishingVendorTagsInfo,     ///< The vendor tags published by the algorithm
                                                      ///  Payload in: NULL
                                                      ///  Payload out: ROIMixerAlgoGetParamOutputs include following type
    ROIMixerAlgoGetParamDependentVendorTags,          ///< The vendor tags the algorithm depends on Input
                                                      ///  Payload in: NULL
                                                      ///  Payload out: ROIMixerAlgoGetParamOutputs include following type
    ROIMixerAlgoGetParamCount,                        ///< Indicate the total number of get param to algorithm
    ROIMixerAlgoGetParameterTypeMax     = 0x7FFFFFFF
} ROIMixerAlgoGetParamType;

/// @brief Represents the metadata to query for, and contains any associated data necessary to support that query
typedef struct
{
    VOID*   pInputData;         ///< Pointer to input data given in the query metadata to generate the output.
    UINT32  sizeOfInputData;    ///< Size of input data pointed to by pInputData
} ROIMixerAlgoGetParamInputs;

/// @brief Represents the output for the metadata to query for
typedef struct
{
    VOID*   pOutputData;        ///< Pointer to output data for which queried the metadata.
    UINT32  sizeOfOutputData;   ///< Size of output data pointed to by pOutputData.
} ROIMixerAlgoGetParamOutputs;


/// @brief Represents the structure to query information from ROIMixer algorithm
typedef struct
{
    ROIMixerAlgoGetParamType        type;       ///< Type of the metadta query
    ROIMixerAlgoGetParamInputs      inputs;     ///< The input used to indicate the detail information to get
    ROIMixerAlgoGetParamOutputs     outputs;    ///< The outputs of queried information
} ROIMixerAlgoGetParam;

/// @brief ROIMixer create parameters information necessary to create ROIMixer algorithm. See CreateROIMixer.
typedef enum
{
    ROIMixerCreateParamsInvalid                  = -1,        ///< Invalid type
    ROIMixerCreateParamsTypeLogger,                           ///< Logging function pointer
                                                              ///  Payload type: StatsLoggerFunction
    ROIMixerCreateParamsTypeTuningData,                       ///< Stats Tuning data.
                                                              ///  Payload type: Tuning
    ROIMixerCreateParamsTypeStatsCameraInfo,                  ///< stats camera info
                                                              ///  Payload type: StatsCameraInfo
    ROIMixerCreateParamsTypeCount,                            ///< Create Param Type Count
    ROIMixerAlgoCreateParamsMax                  = 0x7FFFFFFF ///< Anchor to indicate the last item in the defines
} ROIMixerAlgoCreateParamsType;

/// @brief Represents one single ROIMixer create parameters used to create the ROIMixer algorithm instance
typedef struct
{
    VOID*                         pParam;                         ///< Payload. See ROIMixerAlgoCreateParamType for details
    UINT32                        sizeOfParam;                    ///< Size of payload pointed by data.
    ROIMixerAlgoCreateParamsType  createParamType;                ///< Create parameter type.
} ROIMixerAlgoCreateParam;

/// @brief Represents ROIMixer create parameter list used to create the ROIMixer algorithm instance
typedef struct
{
    ROIMixerAlgoCreateParam*     pParamList;                      ///< Payload. See ROIMixerAlgoCreateParamType for details
    SIZE_T                       paramCount;                      ///< Number of create parameters.
} ROIMixerAlgoCreateParamList;

/// @brief Defines any manual override settings be set to the algorithm
typedef struct
{
    // All the override flags will be added here
    // These setting will be used to override tuning settings
    UINT32 profile3A;                                             ///< 3A Profiling value
} ROIMixerAlgoOverrideSettingParam;


/// @brief Identifies the type of destroy parameter for ROIMixer
enum ROIMixerAlgoDestroyParamType
{
    ROIMixerDestroyParamTypeInvalid               = -1,           ///< Type Invalid
    ROIMixerDestroyParamTypeCameraCloseIndicator,                 ///< Camera Close Indicator
                                                                  ///< UINT 0 - Camera Close 1 Camera Open
    ROIMixerDestroyParamsTypeStatsCameraInfo,                     ///< stats camera info
                                                                  ///  Payload: StatsCameraInfo
    ROIMixerDestroyParamTypeCount,                                ///< Destroy Param Type Count
    ROIMixerDestroyParamTypeMax                   = 0x7FFFFFFF    ///< Max Destroy Param Type
};

/// @brief Represents a ROIMixer destroy parameter
struct ROIMixerAlgoDestroyParam
{
    ROIMixerAlgoDestroyParamType  destroyParamType;               ///< Type of parameter passed
    VOID*                         pParam;                         ///< Payload of the particular parameter type
    UINT32                        sizeOfParam;                    ///< Size of the payload.
};

/// @brief Represents ROIMixer algorithm destroy parameters
struct ROIMixerAlgoDestroyParamList
{
    ROIMixerAlgoDestroyParam* pParamList;                         ///< Pointer to ROIMixer create-parameter
    UINT32                    paramCount;                         ///< Number of input destroy-parameters
};


/// @brief The information input by ROIMixer algorithm
struct ROIMixerLibInput
{
    UINT64                requestId;                              ///< Indicate the current ReqId
    CHIDimension          sensordim;                              ///< Indicate the current sensor dim
    CHIDimension          activeSensordim;                        ///< Indicate the current sensor active array
    CHIDimension          trackerdim;                             ///< Indicate the tracker buffer dimension
    CHIRectangle          appliedCropFDdim;                       ///< Indicate the crop dim applied
    CHIRectangle          CAMIFMap;                               ///< Indicate the CAMIF dim
    FLOAT                 gravityX;                               ///< Indicate the gravity in X axis
    FLOAT                 gravityY;                               ///< Indicate the gravity in Y axis
    FLOAT                 gravityZ;                               ///< Indicate the gravity in Z axis
    ROIMixerAlgoStage     inputStage;                             ///< Indicate the Input Stage of the ALgo
    TrackerCMDType        currentCMD;                             ///< Indicate current cmd of tracker engine
    TrackerResults        trackerAlgoResult;                      ///< Indicate the Tracker algo result
    UINT                  trackerROIMixerDebugSetting;            ///< Indicate if we enable debug
    FaceROIInformation*   pFaceROI;                               ///< Indicate the Pointer to Face info
    SaliencyMapData*      pSaliencyMap;                           ///< Indicate the Pointer to Saliency Map
};

/// @brief The information output by ROIMixer algorithm
struct ROIMixerLibOutput
{
    BOOL                 enable;                                  ///< Indicate the output is enable
    TrackerCMDType       outputCMD;                               ///< Indicate the Command to tracker node
    TrackerROIData       regROI;                                  ///< Indicate the regROI of trackerNode
    BOOL                 isPublishROI;                            ///< Indicate if ROIMixer publish ROI to Tracker
    TrackerROIData       outputROI;                               ///< Indicate the outputROI ROIMixer published
    BOOL                 dumpEnable;                              ///< Indicate if we  dump debug data
    CHAR                 dumpStamp[256];                          ///< Indicate the dump stamp
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Interface for ROIMixer algorithm.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ROIMixerAlgorithm
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ROIMixerProcess
    ///
    /// @brief  Runs the statistic algorithm on the given inputs. This method must only be called after the algorithm is
    ///         initialized.
    ///
    /// @param  pROIMixerAlgorithm   Pointer to ROIMixerAlgorithm instance
    /// @param  pInput             Pointer to stats inputs interface
    /// @param  pOutput            Pointer to the stats data output by the algorithm
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult (*ROIMixerProcess)(
        ROIMixerAlgorithm*            pROIMixerAlgorithm,
        const ROIMixerAlgoInputList*     pInputs,
        ROIMixerAlgoOutputList*          pOutputs);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ROIMixerGetParam
    ///
    /// @brief  This method retrieves the most up-to-date ROIMixer algorithm metadata. The output
    ///         is generally updated after calling ROIMixerAlgorithm::ROIMixerProcess()
    ///
    /// @param  pROIMixerAlgorithm   Pointer to ROIMixerAlgorithm instance
    /// @param  pGetParam          Describes the metadata to query for, and contains any associated data necessary to support
    ///                            that query
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult (*ROIMixerGetParam)(
        ROIMixerAlgorithm*   pROIMixerAlgorithm,
        ROIMixerAlgoGetParam*   pGetParam);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ROIMixerSetParam
    ///
    /// @brief  Sets configuration parameters to ROIMixer.
    ///
    /// @param  pROIMixerAlgorithm  Pointer to ROIMixerAlgorithm instance
    /// @param  pSetParams        Stats configuration parameters to set.Each element of the list is of type AECAlgorithmInputParams
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult (*ROIMixerSetParam)(
        ROIMixerAlgorithm*              pROIMixerAlgorithm,
        const ROIMixerAlgoSetParamList*    pSetParams);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// ROIMixerDestroy
    ///
    /// @brief  This method destroys the derived instance of the interface
    ///
    /// @param  pROIMixerAlgorithm   Pointer to ROIMixer Algorithm instance
    /// @param  pDestroyParams     Pointer to Destroy ROIMixer parameters
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID(*ROIMixerDestroy)(
        ROIMixerAlgorithm*               pROIMixerAlgorithm,
        const ROIMixerAlgoDestroyParamList* pDestroyParams);

} ROIMixerAlgorithm; // ROIMixerAlgorithm interface

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CreateROIMixer
///
/// @brief  This function pointer to method creates an instance to the ROIMixerAlgorithm.
///
/// @param  pCreateParams       Pointer to create params
/// @param  ppROIMixerAlgorithm   Pointer to the created ROIMixerAlgorithm instance
///
/// @return CDKResultSuccess upon success.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*CREATEROIMIXER)(
    const ROIMixerAlgoCreateParamList*    pCreateParams,
    ROIMixerAlgorithm**                ppROIMixerAlgorithm);


#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CAMXROIMIXERINTERFACE_H
