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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file camxipeproperty.h
/// @brief Define ipe properties per usecase and per frame
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CAMXIPEPROPERTY_H
#define CAMXIPEPROPERTY_H

#include "camxdefs.h"
#include "camxtypes.h"


CAMX_NAMESPACE_BEGIN

/// This is the requestId that the HAL will associate the very first incoming frame.
/// All proceeding frames will have a sequentially incrementing requestId. This value
/// *MUST* be greater than 0.
static const UINT64 FIRST_VALID_REQUEST_ID = 1;

/// Maximum buffer composite ID, independently of the ports a node supports
static const UINT32 MAX_BUFFER_COMPOSITE = 50;

static const UINT32 IPE_MAX_PASSES                  = 4; // Number of multi pass
/// @ brief scratch buffer data
struct ScratchBufferData
{
    UINT32 scratchBufferSize;                ///< scratch Buffer size
    UINT32 pdiOffset[IPE_MAX_PASSES];        ///< pdi offset
    UINT32 pdiSize [IPE_MAX_PASSES];         ///< pdi size
    UINT32 tfiOffset[IPE_MAX_PASSES];        ///< tfi offset
    UINT32 tfiSize[IPE_MAX_PASSES];          ///< tfi size
    UINT32 tfrOffset[IPE_MAX_PASSES];        ///< tfr offset
    UINT32 tfrSize[IPE_MAX_PASSES];          ///< tfr size
    UINT32 lmciOffset[IPE_MAX_PASSES];       ///< lmci offset
    UINT32 lmciSize[IPE_MAX_PASSES];         ///< lmci size
    UINT32 ltmmaskOffset[IPE_MAX_PASSES];    ///< ltmmask offset
    UINT32 ltmmaskSize[IPE_MAX_PASSES];      ///< ltmmask size
    UINT32 ltmminmaxOffset[IPE_MAX_PASSES];  ///< ltmminmax offset
    UINT32 ltmminmaxSize[IPE_MAX_PASSES];    ///< ltmminmax size
    UINT32 maclm1Size[IPE_MAX_PASSES];       ///< maclm1 size
    UINT32 maclm1Offset[IPE_MAX_PASSES];     ///< maclm1 offset
    UINT32 maclm2Size[IPE_MAX_PASSES];       ///< maclm2 size
    UINT32 maclm2Offset[IPE_MAX_PASSES];     ///< maclm2 offset
    UINT32 ltmdcOffset[IPE_MAX_PASSES];      ///< ltmdc offset
    UINT32 ltmdcSize[IPE_MAX_PASSES];        ///< ltmdc size
};

static const UINT32 IPE_TFI_DATA_SIZE_MAX = 1700000;    // Max TFI data size based on DC4 path for 24M image

static const UINT32 IPE_PASS_NAME_FULL = 0;     // IPE FULL pass
static const UINT32 IPE_PASS_NAME_DC4  = 1;     // IPE DC4 pass
static const UINT32 IPE_PASS_NAME_DC16 = 2;     // IPE DC16 pass
static const UINT32 IPE_PASS_NAME_DC64 = 3;     // IPE DC64 pass


/// @ brief TFI information header structure
struct TfiInformationHeader
{
    UINT64      requestId;                       ///< request id of the TFI data
    CamxTime    timeStamp;                       ///< timestamp of the TFI data
    UINT32      tfiPassName;                     ///< pass index for the tfi data
    UINT32      tfiWidth;                        ///< tfi width
    UINT32      tfiHeight;                       ///< tfi height
    UINT32      tfiStride;                       ///< tfi buffer stride
    UINT32      tfiDataSize;                     ///< tfi buffer size
    UINT8       tfiDataError;                    ///< set to 1 if any error in tfi data
};

/// @ brief TFI information structure
struct TfiInformation
{
    TfiInformationHeader    header;                         ///< header information
    BYTE                    tfiData[IPE_TFI_DATA_SIZE_MAX]; ///< TFI data memory block
};


/// @ brief QLL input for global motion indication
struct QLLInputGmi
{
    FLOAT       normAvg;                        ///< Norm average [0, 1]
    FLOAT       gmi;                            ///< Global Motion indication [0, 1]
    UINT8       tripodEnabled;                  ///< Whether EVA tripod is enabled. 1 == TRUE, 0 == FALSE
    FLOAT       tripodVal;                      ///< EVA tripod value */
};

/// @ brief QLL input for local motion indication
struct QLLInputLmi
{
    UINT8       calcType;                       ///< Calcuation type: 0 == DMM, 1 == TFI
    FLOAT       lmi;                            ///< Global Motion indication [0, 1]
};

/// @ brief QLL library inputs from IPE node
struct QLLInputsIpe
{
    UINT64          requestId;                  ///< request id for this qll input information
    CamxTime        timeStamp;                  ///< timestamp for this qll input information
    QLLInputGmi     gmiInfo;                    ///< global motion indication Information
    QLLInputLmi     lmiInfo;                    ///< local motion indication Information
};

// UBWC_CR_STATS_INFO
#define MAX_UBWC_STATS_LENGTH 32
#define UBWC_STATS_ARRAY_SIZE 2

enum UBWC_Version {
  UBWC_UNUSED = 0,
  UBWC_1_0 = 0x1,
  UBWC_2_0 = 0x2,
  UBWC_3_0 = 0x3,
  UBWC_4_0 = 0x4,
  UBWC_MAX_VERSION = 0xFF,
};

struct UBWC_2_0_Stats {
  uint32_t nCRStatsTile32;  /**< UBWC Stats info for  32 Byte Tile */
  uint32_t nCRStatsTile64;  /**< UBWC Stats info for  64 Byte Tile */
  uint32_t nCRStatsTile96;  /**< UBWC Stats info for  96 Byte Tile */
  uint32_t nCRStatsTile128; /**< UBWC Stats info for 128 Byte Tile */
  uint32_t nCRStatsTile160; /**< UBWC Stats info for 160 Byte Tile */
  uint32_t nCRStatsTile192; /**< UBWC Stats info for 192 Byte Tile */
  uint32_t nCRStatsTile256; /**< UBWC Stats info for 256 Byte Tile */
};

struct UBWCStats {
  enum UBWC_Version version; /* Union depends on this version. */
  uint8_t bDataValid;        /* If [non-zero], CR Stats data is valid.
                              * Consumers may use stats data.
                              * If [zero], CR Stats data is invalid.
                              * Consumers *Shall* not use stats data */
  union {
    struct UBWC_2_0_Stats ubwc_stats;
    uint32_t reserved[MAX_UBWC_STATS_LENGTH]; /* This is for future */
  };
};

CAMX_NAMESPACE_END

#endif // CAMXIPEPROPERTY_H
