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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  chistatsnninterface.h
/// @brief statsNN algorithms interfaces
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// NOWHINE FILE GR016: Typedefs must not be used for structs, classes, and enumerations

#ifndef CHISTATSNNINTERFACE_H
#define CHISTATSNNINTERFACE_H

#include "chi.h"
#include "chistatsinterfacedefs.h"
#include "chistatsdebug.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)

#define SALINETMAXW 80
#define SALINETMAXH 60
#define SALINETROINUMMAX 5

/// @brief StatsNNBufFormatDimension     Structure to create algorithm instance
typedef struct
{
    ChiBufferFormat         imgBufFmt;          ///< Img Buffer format
    StatsDimension          imgBufDim;          ///< Img buffer dimension
    UINT32                  planeStride;        ///< Img buffer planeStride
    UINT32                  sliceHeight;        ///< Img buffer plane slice height
    UINT32                  scaleDownRatio;     ///< Img buffer scale down ratio for cv lib
} StatsNNBufFormatDimension;

typedef struct
{
    FLOAT x;
    FLOAT y;
    FLOAT dx;
    FLOAT dy;
} StatsNNSaliencyROI;

typedef struct
{
    UINT8                   isValid;                                  ///< Flag to check the data validity
    UINT8                   outWidth;                                 ///< saliency model output width
    UINT8                   outHeight;                                ///< saliency model output height
    UINT8                   saliNetOut[SALINETMAXW * SALINETMAXH];    ///< saliency model output buffer
    UINT8                   numSalROI;                                ///< number of salient ROIs
    StatsNNSaliencyROI      salientROI[SALINETROINUMMAX];             ///< Salient ROIs to be populated by saliency net
} StatsNNSaliNetOut;


/// @brief StatsNNResults   Algorithm output structure
typedef struct
{
    StatsNNSaliNetOut       saliencyOut;        ///< saliency Model output data
} StatsNNResults;

/// @brief statsnn crop information
typedef struct
{
    CHIRectangle appliedCropFD;                     ///< crop applied on FD buffer
    CHIRectangle residualCropFD;                    ///< residual crop to be applied on the FD buffer
                                                    ///  during preprocessing stage in backend statsnn driver
} StatsNNCropInfo;

/// @brief Identifies the type of input to StatsNN algorithm
typedef enum
{
    StatsNNInputTypeInvalid         = -1,           ///< Invalid type. Payload: NULL & set size to zero.
    StatsNNInputTypeCameraID,                       ///< CameraID,                  UINT32
    StatsNNInputTypeRequestNumber,                  ///< Request number             UINT64
    StatsNNInputTypeImgBuf,                         ///< Input Image buffer,        BYTE*
    StatsNNInputTypeCount,                          ///< Count of input types
} StatsNNAlgoInputType;

/// @brief Represents StatsNN inputs base structure to the StatsNN algorithm, used as part of StatsNNAlgoInputList
typedef struct
{
    VOID*                   pStatsNNInput;          ///< Pointer to the payload. See StatsNNAlgoInputType for details.
    UINT32                  sizeOfStatsNNInput;     ///< Size of input payload
    StatsNNAlgoInputType    inputType;              ///< Type of the payload
} StatsNNAlgoInput;

/// @brief Represents StatsNN module inputs to the StatsNN algorithm
typedef struct
{
    StatsNNAlgoInput*       pStatsNNInputs;             ///< Pointer to StatsNNAlgoInput array
    UINT32                  inputCount;                 ///< Number of inputs
} StatsNNAlgoInputList;

/// @brief Represents StatsNN output type
typedef enum
{
    StatsNNOutputTypeInvalid            = -1,           ///< Invalid type
    StatsNNOutputSaliencyResult,                        ///< StatsNNResults type
    StatsNNOutputTypeCount,                             ///< Count of the enum
} StatsNNAlgoOutputType;

/// @brief Represents StatsNN output from the algorithm
typedef struct
{
    VOID*                   pStatsNNOutput;             ///< Pointer to the payload. See StatsNNAlgoOutputType for details
                                                        ///  Algorithm implementer needs to do a deep copy to the given memory
    UINT32                  sizeOfStatsNNOutput;        ///< Size of input payload pointed to by pStatsNNOutput
    UINT32                  sizeOfWrittenStatsNNOutput; ///< Size of payload written back. If no output set to zero.
    StatsNNAlgoOutputType   outputType;                 ///< Type of the payload
} StatsNNAlgoOutput;

/// @brief Represents StatsNN output list from the algorithm
typedef struct
{
    StatsNNAlgoOutput*      pStatsNNOutputs;    ///< Pointer to StatsNNAlgoOutput elements array.
    UINT32                  outputCount;        ///< Number of elements in pStatsNNOutputs
} StatsNNAlgoOutputList;

/// @brief Represents StatsNN  type
typedef enum
{
    StatsNNGetParamInputTypeInvalid = -1,              ///< Invalid type. Payload: NULL & set size to zero
    StatsNNGetParamInputTypeCount,                     ///< Count of the enum
} StatsNNAlgoGetParamInputType;

/// @brief Represents the input data to query which contains any associated data necessary to support that query
typedef struct
{
    VOID*                           pGetParamInput;         ///< Pointer to input data given in the query info to generate
                                                            ///  the output. See StatsNNAlgoGetParamInputType for details.
    UINT32                          sizeOfGetParamInput;    ///< Size of input payload
    StatsNNAlgoGetParamInputType    getParamInputType;      ///< Type of the payload
} StatsNNAlgoGetParamInput;

/// @brief Represents StatsNN module inputs to the StatsNN algorithm
typedef struct
{
    StatsNNAlgoGetParamInput*       pGetParamInputs;    ///< Pointer to StatsNNAlgoGetParamInput array
    UINT32                          getParamInputCount; ///< Number of inputs
} StatsNNAlgoGetParamInputList;

/// @brief Represents StatsNN output type
typedef enum
{
    StatsNNGetParamOutputTypeInvalid = -1,              ///< Invalid type. Payload: NULL & set size to zero
    StatsNNGetParamOutputTypeCount,                     ///< Count of the enum
} StatsNNAlgoGetParamOutputType;

/// @brief Represents StatsNN get output information from the algorithm
typedef struct
{
    VOID*                           pGetParamOutput;                ///< Pointer to the payload.
    UINT32                          sizeOfGetParamOutput;           ///< Size of input payload pointed to by pGetParamOutput
    UINT32                          sizeOfWrittenGetParamOutput;    ///< Size of payload written back. If no output set to zero.
    StatsNNAlgoGetParamOutputType   getParamOutputType;             ///< Type of the payload
} StatsNNAlgoGetParamOutput;

/// @brief Represents StatsNN get output list from the algorithm
typedef struct
{
    StatsNNAlgoGetParamOutput*      pGetParamOutputs;       ///< Pointer to StatsNNAlgorithmOutput array.
    UINT32                          getParamOutputCount;    ///< Number of elements in pStatsNNOutputs
} StatsNNAlgoGetParamOutputList;

/// @brief Defines the StatsNN get parameter information
typedef struct
{
    StatsNNAlgoGetParamInputList    inputInfoList;  ///< Data that's needed for processing the output
    StatsNNAlgoGetParamOutputList   outputInfoList; ///< Output requested in the query
} StatsNNAlgoGetParam;

/// @brief Identifies the type of input parameter to StatsNN algorithm
typedef enum
{
    StatsNNSetParamTypeInvalid          = -1,           ///< Invalid type
    StatsNNSetParamTypeTuningData,                      ///< Tuning data type
                                                        ///  Payload type: StatsTuningData
    StatsNNSetParamTypeFDCropInformation,               ///< FD crop information
                                                        ///  Payload type: StatsNNCropInfo
    StatsNNSetParamTypeCount,                           ///< Count of the enum
} StatsNNAlgoSetParamType;

/// @brief Represents an StatsNN input parameter
typedef struct
{
    const VOID*             pStatsNNSetParam;       ///< Pointer to StatsNN input param data
                                                     ///  See StatsNNAlgoSetParamType for details
    UINT32                   sizeOfSetParam;         ///< Size of data pointed to by pStatsNNInputParam
    StatsNNAlgoSetParamType  setParamType;           ///< Type of the input parameter
} StatsNNAlgoSetParam;

/// @brief Represents an StatsNN input parameter passed to CHIStatsNNAlgorithm::StatsNNSetParam()
typedef struct
{
    StatsNNAlgoSetParam*        pStatsNNSetParams;      ///< Pointer to StatsNN input param data
    UINT32                      setParamsCount;       ///< Number of input param parameters
} StatsNNAlgoSetParamList;

/// @brief Identifies the type of create parameter to StatsNN algorithm
typedef enum
{
    StatsNNCreateParamsTypeInvalid      = -1,       ///< Invalid type
    StatsNNCreateParamsTypeLogger,                  ///< Logger function
    StatsNNCreateParamsTypeCameraInfo,              ///< CameraInfo of type StatsCameraInfo
    StatsNNCreateParamsTypeBufFmtDim,               ///< Image buf format and dimension, StatsNNBufFmtDim type
    StatsNNCreateParamsTypeTuningParams,            ///< Tuning Parameters
    StatsNNCreateParamTypeSettingsPtr,              ///< Settings Data Pointer
    StatsNNCreateParamsTypeCount,                   ///< Count of StatsNNAlgoCreateParamType
} StatsNNAlgoCreateParamType;

/// @brief Represents StatsNN create parameter base structure, used as part of StatsNNAlgoCreateParamList
typedef struct
{
    VOID*                       pCreateParam;           ///< Payload: See StatsNNAlgoCreateParamType for details
    UINT32                      sizeOfCreateParam;      ///< Size of payload pointed by data.
    StatsNNAlgoCreateParamType  createParamType;        ///< Create parameter type.
} StatsNNAlgoCreateParam;

/// @brief Represents StatsNN create parameters information necessary to create StatsNN algorithm. See CreateStatsNN.
typedef struct
{
    StatsNNAlgoCreateParam*     pCreateParams;          ///< A pointer to CreateStatsNN array
    UINT32                      createParamsCount;      ///< Number of create parameters.
} StatsNNAlgoCreateParamList;

/// @brief Identifies the type of destroy parameter
typedef enum
{
    StatsNNDestroyParamTypeInvalid               = -1,  ///< Type Invalid
    StatsNNDestroyParamTypeCameraID,                    ///< Type camera ID
    StatsNNDestroyParamTypeCount,                       ///< Count of destroy params
} StatsNNAlgoDestroyParamType;

/// @brief Represents an StatsNN destroy parameter
typedef struct
{
    StatsNNAlgoDestroyParamType destroyParamType;       ///< Type of parameter passed
    VOID*                       pParam;                 ///< Payload of the particular parameter type
    UINT32                      sizeOfParam;            ///< Size of the payload.
} StatsNNAlgoDestroyParam;

/// @brief Represents StatsNN algorithm destroy parameters
typedef struct
{
    StatsNNAlgoDestroyParam*    pParamList;         ///< Pointer to StatsNN destroy-parameter
    UINT32                      paramCount;         ///< Number of input destroy-parameters
} StatsNNAlgoDestroyParamList;

/// @brief Represents StatsNN algo settings controlled from camxsettings
typedef struct
{
    BOOL                        profile;
    UINT8                       dump;
} StatsNNAlgoSettings;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Interface for StatsNN algorithm.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct CHIStatsNNAlgorithm
{
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// StatsNNProcess
    ///
    /// @brief  Runs the StatsNN algorithm on the given inputs.
    ///
    /// @param  pCHIStatsNNAlgorithm   Pointer to CHIStatsNNAlgorithm instance
    /// @param  pInputs                Pointer to stats inputs interface
    /// @param  pOutputs               Pointer to stats data output by the algorithm
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult (*StatsNNProcess)(
        CHIStatsNNAlgorithm*           pCHIStatsNNAlgorithm,
        const StatsNNAlgoInputList*    pInputs,
        StatsNNAlgoOutputList*         pOutputs);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// StatsNNGetParam
    ///
    /// @brief  This method retrieves the most up-to-date StatsNN algorithm information. The output
    ///         is generally updated after calling CHIStatsNNAlgorithm::Process()
    ///
    /// @param  pCHIStatsNNAlgorithm   Pointer to CHIStatsNNAlgorithm instance
    /// @param  pGetParam              Describes the metadata to query for, and contains any associated data necessary to
    ///                                support that query
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult(*StatsNNGetParam)(
        CHIStatsNNAlgorithm*    pCHIStatsNNAlgorithm,
        StatsNNAlgoGetParam*    pGetParam);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// StatsNNSetParam
    ///
    /// @brief  Sets parameters to StatsNN.
    ///
    /// @param  pCHIStatsNNAlgorithm   Pointer to CHIStatsNNAlgorithm instance
    /// @param  pSetParams             StatsNN input parameters to set.
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult(*StatsNNSetParam)(
        CHIStatsNNAlgorithm*             pCHIStatsNNAlgorithm,
        const StatsNNAlgoSetParamList*   pSetParams);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// StatsNNGetFeatureCapability
    ///
    /// @brief  Sets parameters to StatsNN.
    ///
    /// @param  pCHIStatsNNAlgorithm    Pointer to CHIStatsNNAlgorithm instance
    /// @param  pFeatures               Features supported by the algorithm
    ///
    /// @return CDKResultSuccess upon success.
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CDKResult(*StatsNNGetFeatureCapability)(
        CHIStatsNNAlgorithm*    pCHIStatsNNAlgorithm,
        UINT64*                 pFeatures);

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    /// StatsNNDestroy
    ///
    /// @brief  This method destroys the derived instance of the interface
    ///
    /// @param  pCHIStatsNNAlgorithm    Pointer to CHIStatsNNAlgorithm instance
    /// @param  pDestroyParams          Pointer to destroy Param List
    ///
    /// @return None
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    VOID (*StatsNNDestroy)(
        CHIStatsNNAlgorithm*                 pCHIStatsNNAlgorithm,
        const StatsNNAlgoDestroyParamList*   pDestroyParams);
} CHIStatsNNAlgorithm;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// CreateStatsNN
///
/// @brief  This method creates an instance to the CHIStatsNNAlgorithm.
///
/// @param  pCreateParams           Pointer to create params
/// @param  ppCHIStatsNNAlgorithm   Pointer to the created CHIStatsNNAlgorithm instance
///
/// @return CDKResultSuccess upon success.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult (*CREATESTATSNN)(
    const StatsNNAlgoCreateParamList*   pCreateParams,
    CHIStatsNNAlgorithm**               ppCHIStatsNNAlgorithm);

#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHISTATSNNINTERFACE_H
