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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file camxfdproperty.h
/// @brief Define Qualcomm Technologies, Inc. FD proprietary data for holding internal properties/events
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXFDPROPERTY_H
#define CAMXFDPROPERTY_H

#include "chifdproperty.h"
#include "camxcsl.h"
#include "camxifeproperty.h"
#include "camxhal3metadatatags.h"

CAMX_NAMESPACE_BEGIN

class ImageBuffer;

#define MAX(a, b) (((a)>(b))?(a):(b))

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @brief Describes Common FD data structures
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static const UINT32 FDFrameWidth    = 640; ///< FD Frame width
static const UINT32 FDFrameHeight   = 480; ///< FD Frame height

static const UINT32 GBDLimitNumberOfFaces   = 2;  ///< Limit of number of faces for gaze and blink detection
static const UINT32 CTDLimitNumberOfFacesSW = 2;  ///< Limit of number of faces for facial contour detection
static const UINT32 CTDLimitNumberOfFacesDL = 5;  ///< Limit of number of faces for facial contour detection


///< Max number of contour points as the count of FDPoint's
///  All Facial contour versions: to publish contours for the faces with valid contours, up to the max limit,
//                                each contour up to the max point per face of all supported versions.
static const UINT32 FDContourPointMax = CTDLimitNumberOfFacesDL * FDContourPointPerFaceMax ;

/// @brief Structure FD HW frame settings
struct FDFrameHwSettings
{
    BOOL skipProcess;  ///< Whether to skip processing this frame
};

/// @brief Structure FD SW frame settings
struct FDFrameSwSettings
{
    BOOL skipProcess;  ///< Whether to skip processing this frame
};

/// @brief Structure FD frame settings
struct FDPropertyFrameSettings
{
    BOOL                enableFD;   ///< Whether to enable FD
    FDFrameHwSettings   hwSettings; ///< Frame settings for HW detection
    FDFrameSwSettings   swSettings; ///< Frame settings for SW detection
};

/// @brief FDManagerSequence processing sequence
enum FDManagerSequence
{
    FDSWIntermittent = 0,        ///< Use SW Intermittent execution
    FDFPFiltering,               ///< Use FP filtering
};

/// @brief Structure FD frame settings
struct FDPerFrameSettings
{
    UINT64                          requestId;                     ///< Frame request ID
    BOOL                            skipProcess;                   ///< Whether to skip complete frame
    FDPropertyFrameSettings         frameSettings;                 ///< FD node frame settings
    StatisticsFaceDetectModeValues  fdModeReceived;                ///< FD mode received
    ControlModeValues               controlMode;                   ///< Control mode received
    ControlSceneModeValues          sceneMode;                     ///< Scene mode received
    BOOL                            gzEnable;                      ///< the received enable setting of gaze detection
    BOOL                            bkEnable;                      ///< the received enable setting of blink detection
    BOOL                            ctEnable;                      ///< the received enable setting of facial contour detection
    BOOL                            postCTtoMeta;                  ///< flag to indicate whether to post CT to meta or not
    BOOL                            genderEnable;                  ///< the received enable setting of gender detection
    BOOL                            faceExpressionEnable;          ///< the received enable setting of expression detection
    BOOL                            faceMaskEnable;                ///< the received enable setting of face mask detection
    BOOL                            upperBodyEnable;               ///< the received enable setting of upper body detection
    CHIRectangle                    inputFrameMap;                 ///< Input frame mapping w.r.t CAMIF
    CHIRectangle                    finalFOVCrop;                  ///< Final FOV crop w.r.t FD input frame
    CHIRectangle                    finalScalerCropRegion;         ///< Final FOV scale crop w.r.t Active array size
    CropWindow                      originalHALCrop;               ///< OriginalHAL crop window
    CropWindow                      HALCrop;                       ///< HAL crop window
    BOOL                            postResultsToMetaData;         ///< Flag to indicate if results need to be published to
                                                                   ///< metadata
    BOOL                            postResultsToProperty;         ///< Flag to indicate if results need to be published to
                                                                   ///< property
    BOOL                            postResultsToPropertyPriorReq; ///< Flag to indicate if results need to be published to
                                                                   ///< property for the prior request
    ImageBuffer*                    pImageBuffer;                  ///< ImageBuffer handle for input frame buffer
    BYTE*                           pUVImageAddress;               ///< UV plane image address
    BYTE*                           pImageAddress;                 ///< Y plane image address
    INT32                           fd;                            ///< FD of the buffer
    FDConfig                        FDConfig;                      ///< Face detection tuning configuration
    BOOL                            FDConfigUpdated;               ///< Whether configuration changed compared to previous
                                                                   ///< request
    INT32                           deviceOrientation;             ///< Device orientation angle
    BOOL                            inputBufferInvalidateRequired; ///< Whether input buffer need to be cache invalidated
    FDManagerSequence               FDManagerExecutionSequence;    ///< Control the FD Manager executon sequence
};

/// @brief Struct FD upper body ROI information with respect to CAMIF dimension
struct  FDMetadataUpperBodyInfo
{
    UINT64               requestId;                     ///< Identifier for the processed frame request.
    UINT64               frameNumber;                   ///< Number of the frame that is associated with requestId.
    INT32                numHeads;                      ///< Number of the detected head(s)
    INT32                linkedFaceId[FDMaxFaceCount];  ///< ID of the face associated with the head/body.
    RectangleCoordinate  headROI[FDMaxFaceCount];       ///< Head ROI
    BOOL                 torsoValid[FDMaxFaceCount];    ///< Indicators of whether a torso is detected.
    RectangleCoordinate  torsoROI[FDMaxFaceCount];      ///< Torso ROI
};

CAMX_BEGIN_PACKED
/// @brief Structure Facial Contour results with version number for backward compatibility
///        Counterpart of FDMetaDataVersionedFaceContourResults for CamX and FD internal use
struct FDMetaDataVersionedFaceContourResultsInternal
{
    CamxFDCTDResultStatus          status;                        ///< Status of facial contour result
    INT32                          version;                       ///< Version number of the facial contour point definition
    INT32                          numPointsPerFace;              ///< Number of contour points per face
    UINT32                         numFaces;                      ///< Number of faces with contour info
    INT32                          reserved[4];                   ///< Reserved fields
    INT32                          faceID[FDMaxFaceCount];        ///< Array of face IDs of face contours
    FDPoint                        points[FDContourPointMax];     ///< Array of contour points
} CAMX_PACKED;

CAMX_END_PACKED

CAMX_NAMESPACE_END

#endif // CAMXFDPROPERTY_H
