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

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  chistatsalgo.h
/// @brief Defines CHI algorithm interface
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHISTATSALGO_H
#define CHISTATSALGO_H

#include "camxcdktypes.h"
#include "chi.h"
#include "chiafinterface.h"
#include "chihafalgorithminterface.h"
#include "chicommon.h"
#include "chiaecinterface.h"
#include "chiawbinterface.h"
#include "chiafdinterface.h"
#include "chiasdinterface.h"
#include "chihistalgointerface.h"
#include "chipdlibinterface.h"


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

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

typedef struct ChiAlgorithmInterface CHIALGORITHMINTERFACE;

/** @addtogroup chi_stats_algo
@{ */

/// @brief Handle to the camera session context.
typedef VOID* CHISTATSHANDLE;

/// @brief Information about the algorithm capabilities.
typedef struct /** @cond */ ChiAlgorithmCapsInfo /** @endcond */
{
    UINT32  size;                ///< Size of this structure.
    UINT32  algorithmCapsMask;   ///< Mask of algorithm capabilities.
} CHIALGORITHMCAPSINFO;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFNALGORITHMGETCAPABILITIES @endcond
///
/// @brief Gets all the capabilities supported by the algorithm.
///
/// @datatypes
/// #CHIALGORITHMCAPSINFO
///
/// @param[in] pCapsInfo  Pointer to the structure that defines the capabilities supported by the algorithm.
///
/// @detdesc
/// This information can be used to verify the algorithm properties that are set during algorithm creation.
///
/// @return #CDKResultSuccess or the appropriate error code (see Section @xref{hdr:resultMessages}).
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef CDKResult(*PFNALGORITHMGETCAPABILITIES)(CHIALGORITHMCAPSINFO* pCapsInfo);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond PFCHISETALGORITHMINTERFACE @endcond
///
/// @brief Sets the CHI interfaces required by a custom algorithm.
///        This function is the interface for a custom algorithm to call into the CHI interface.
///
/// @datatypes
/// #CHIALGORITHMINTERFACE
///
/// @param[in,out] pAlgoInterface  Pointer to the structure that defines the callbacks the algorithm sends to the CHI
///                                interface. The algorithm must fill in these function pointers.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
typedef VOID (*PFCHISETALGORITHMINTERFACE) (CHIALGORITHMINTERFACE* pAlgoInterface);


/// @brief Callback structure used when the CHI driver calls into a custom Histogram algorithm.
typedef struct /** @cond */ ChiHistogramAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEHISTOGRAMALGOPROCESS     pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIHISTALGORITHMCALLBACKS;


/// @brief Callback structure used when the CHI interface calls into a custom AEC algorithm.
typedef struct /** @cond */ ChiAECAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEAEC                      pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIAECALGORITHMCALLBACKS;

/// @brief Callback structure used when the CHI driver calls into a custom Autofocus algorithm.
typedef struct /** @cond */ ChiAFAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEAF                       pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    CREATEHAFALGORITHM             pfnCreateHAFAlgorithm;   ///< Mandatory function used to create an instance of the
                                                            ///  HAF algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm
                                                            ///  interface functions.
} CHIAFALGORITHMCALLBACKS;

/// @brief Callback structure used when the CHI driver calls into a custom AWB algorithm.
typedef struct /** @cond */ ChiAWBAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEAWB                      pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIAWBALGORITHMCALLBACKS;

/// @brief Callback structure used when the CHI driver calls into a custom AFD algorithm.
typedef struct /** @cond */ ChiAFDAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEAFD                      pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIAFDALGORITHMCALLBACKS;

/// @brief Callback structure used when the CHI driver calls into a custom ASD algorithm.
typedef struct /** @cond */ ChiASDAlgorithmCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEASD                      pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIASDALGORITHMCALLBACKS;

/// @brief Callback structure used when the CHI driver calls into a custom PD Library algorithm.
typedef struct /** @cond */ ChiPDLibraryCallbacks /** @endcond */
{
    UINT32                         size;                    ///< Size of this structure.
    UINT32                         majorVersion;            ///< Tracks the major version of the algorithm.
    UINT32                         minorVersion;            ///< Tracks the minor version of the algorithm.
    PFNALGORITHMGETCAPABILITIES    pfnGetCapabilities;      ///< Gets the capabilities supported by the algorithm.
    PFNCHIQUERYVENDORTAG           pfnQueryVendorTag;       ///< Optional function used to get the vendor tags supported by the
                                                            ///  node.
    CREATEPD                       pfnCreate;               ///< Mandatory function used to create an instance of the
                                                            ///  algorithm.
    PFCHISETALGORITHMINTERFACE     pfnSetAlgoInterface;     ///< Mandatory function used to set the algorithm interface
                                                            ///  functions.
} CHIPDLIBRARYCALLBACKS;

/// @brief Parameters used when a custom algorithm calls into the CHI algorithm interface.
typedef struct /** @cond */ ChiAlgorithmInterface /** @endcond */
{
    UINT32                          size;                       ///< Size of this structure.
    UINT32                          majorVersion;               ///< Tracks the major version of the algorithm.
    UINT32                          minorVersion;               ///< Tracks the minor version of the algorithm.
    PFNCHIGETMETADATA               pGetMetadata;               ///< Get the data from metadata if the metadata is already
                                                                ///  published.
    PFNCHISETMETADATA               pSetMetaData;               ///< Set the metadata and publish it.
    PFNCHIGETVENDORTAGBASE          pGetVendorTagBase;          ///< Get the vendor tag base for a tag.
    PFNCHIQUERYVENDORTAGLOCATION    pQueryVendorTagLocation;    ///< Get the location of the vendor tag.
                                                                ///  @newpagetable
} CHIALGORITHMINTERFACE;


#ifndef DOXYGEN_SHOULD_SKIP_THIS

/// Histogram Algorithm Callback Function
typedef VOID(*PFHDRCHIALGORITHMENTRY) (CHIHISTALGORITHMCALLBACKS* pHISTOGRAMALGORITHMCallbacks);

typedef VOID (*PFAECCHIALGORITHMENTRY) (CHIAECALGORITHMCALLBACKS* pAECALGORITHMCallbacks);

typedef VOID (*PFAFCHIALGORITHMENTRY)  (CHIAFALGORITHMCALLBACKS*  pAFALGORITHMCallbacks);

typedef VOID (*PFAWBCHIALGORITHMENTRY) (CHIAWBALGORITHMCALLBACKS* pAWBALGORITHMCallbacks);

typedef VOID (*PFAFDCHIALGORITHMENTRY) (CHIAFDALGORITHMCALLBACKS* pAFDALGORITHMCallbacks);

typedef VOID (*PFASDCHIALGORITHMENTRY) (CHIASDALGORITHMCALLBACKS* pASDALGORITHMCallbacks);

typedef VOID(*PFPDCHILIBRARYENTRY) (CHIPDLIBRARYCALLBACKS* pPDLIBRARYCallbacks);

#endif /* DOXYGEN_SHOULD_SKIP_THIS */


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiHistogramAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom histogram algorithm.
///
/// @datatypes
/// #CHIHISTALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm. The algorithm must
///                                     fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiHistogramAlgorithmEntry(
    CHIHISTALGORITHMCALLBACKS* pAlgorithmCallbacks);


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiAECAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom AEC algorithm.
///
/// @datatypes
/// #CHIAECALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm.
///                                     The algorithm must fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiAECAlgorithmEntry(
    CHIAECALGORITHMCALLBACKS* pAlgorithmCallbacks);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiAFAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom Autofocus algorithm.
///
/// @datatypes
/// #CHIAFALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm.
///                                     The algorithm must fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiAFAlgorithmEntry(
    CHIAFALGORITHMCALLBACKS* pAlgorithmCallbacks);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiAWBAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom AWB algorithm.
///
/// @datatypes
/// #CHIAWBALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm.
///                                     The algorithm must fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiAWBAlgorithmEntry(
    CHIAWBALGORITHMCALLBACKS* pAlgorithmCallbacks);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiAFDAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom AFD algorithm.
///
/// @datatypes
/// #CHIAFDALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm. The algorithm must
///                                     fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiAFDAlgorithmEntry(
    CHIAFDALGORITHMCALLBACKS* pAlgorithmCallbacks);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiASDAlgorithmEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom ASD algorithm.
///
/// @datatypes
/// #CHIASDALGORITHMCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm. The algorithm must
///                                     fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None. @newpage
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiASDAlgorithmEntry(
    CHIASDALGORITHMCALLBACKS* pAlgorithmCallbacks);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @cond ChiPDLibraryEntry @endcond
///
/// @brief Entry point called by the CHI driver to initialize a custom PD Library.
///
/// @datatypes
/// #CHIPDLIBRARYCALLBACKS
///
/// @param[in,out] pAlgorithmCallbacks  Pointer to the callbacks that the CHI driver sends to the algorithm. The algorithm must
///                fill in these function pointers.
///
/// @detdesc
/// This function must be exported by every \<library>.so file for the driver to initialize the algorithm. It is called during
/// camera server initialization, which occurs during HAL process start.
/// @par
/// In addition to communicating the necessary function pointers between the CHI driver and external algorithms, this function
/// allows an algorithm to do any initialization work that it would typically do during process initialization.
/// @par
/// Anything done here should not be specific to a session, and any variables stored in the algorithm must be protected against
/// multiple sessions accessing it at the same time.
///
/// @return None.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CAMX_VISIBILITY_PUBLIC VOID ChiPDLibraryEntry(
    CHIPDLIBRARYCALLBACKS* pAlgorithmCallbacks);

/** @} */ /* end_addtogroup chi_stats_algo */

#pragma pack(pop)

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // CHISTATSALGO_H
