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

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// @file  chxdefs.h
/// @brief CHX common definitions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef CHXDEFS_H
#define CHXDEFS_H

#include "camera3.h"
//#include <camera3.h>
#include "camxcdktypes.h"
#include "chivendortag.h"

// NOWHINE ENTIRE FILE - Temporarily bypassing for existing CHI files

#define CHX_STATIC_ASSERT(condition)   static_assert(condition, #condition)
#define CHX_ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0]))

/// Constants
static const UINT   MaxChiStreams          = 20;                         ///< Maximum number of CHI streams
static const UINT32 MaxOutstandingRequests = 256;                        ///< Number is bigger to prevent throttling of the
                                                                         ///  preview pipeline
static const UINT32 MaxPendingFrameNumber  = MaxOutstandingRequests;     ///< Max valid number mapping between Framework and CHI
                                                                         ///  keep same with MaxOutstandingRequests

static const INT64  InvalidFrameNumber             = 0x7FFFFFFFFFFFFFFF; ///< Invalid frame number

static const UINT32 InvalidIndex                   = 0xFFFFFFFF;         ///< Invalid index
static const UINT32 INVALIDSEQUENCEID              = 0xFFFFFFFF;         ///< Invalid sequence id
static const UINT32 INVALIDFRAMENUMBER             = 0xFFFFFFFF;         ///< Invalid frame number

static const UINT   tuningUsecasePreviewMask       = 1;                  ///< Mask to indicate to preview usecase.
static const UINT   tuningUsecaseVideoMask         = 2;                  ///< Mask to indicate to video usecase.
static const UINT   tuningUsecaseSnapshotMask      = 4;                  ///< Mask to indicate to snapshot usecase.
static const UINT   tuningUsecaseZSLMask           = 8;                  ///< Mask to indicate to ZSL usecase.

static const UINT   CHIImmediateBufferCountDefault = 2;                  ///< Number of buffers to allocate immediately when
                                                                         ///  chi buffer manager is being created.
static const UINT   CHIImmediateBufferCountZSL     = 3;                  ///< Number of buffers to allocate immediately when
                                                                         ///  chi buffer manager is being created for zsl usecase.

static const UINT32 UHDResolutionWidth             = 3840;               ///< UHD resolution width
static const UINT32 UHDResolutionHeight            = 2160;               ///< UHD resolution height
static const UINT32 FHDResolutionWidth             = 1920;               ///< FHD resolution width
static const UINT32 FHDResolutionHeight            = 1080;               ///< FHD resolution height
static const UINT8  MultiPreviewWindows            = 2;                  ///< Number of Preview Windows to enable Y2Y
static const UINT8  MaxNumSnapshotStreams          = 2;                  ///< Number of Snapshot streams that are supported

/// @brief Usecase identifying enums
enum class UsecaseId
{
    NoMatch             = 0,
    Default             = 1,
    Preview             = 2,
    PreviewZSL          = 3,
    MFNR                = 4,
    MFSR                = 5,
    MultiCamera         = 6,
    QuadCFA             = 7,
    RawJPEG             = 8,
    MultiCameraVR       = 9,
    Torch               = 10,
    YUVInBlobOut        = 11,
    VideoLiveShot       = 12,
    SuperSlowMotionFRC  = 13,
    Feature2            = 14,
    Depth               = 15,
    MaxUsecases         = 16,
};

// List of Vendor Tags
enum class VendorTag
{
    SensorBpsModeIndex  = 0,        ///< SensorBpsModeIndex
    SensorBpsGain,                  ///< SensorBpsGain
    DebugDataTag,                   ///< DebugData
    SensorModeIndex,                ///< SensorModeIndex
    CropRegions,                    ///< Crop Regions
    TuningMode,                     ///< TagTuningMode
    RefCropSize,                    ///< Ref crop size
    MultiCamera,                    ///< multicamera
    IsFlashRequiredTag,             ///< Is Flash Required for Snapshot
    Feature1Mode,                   ///< Feature1Mode
    Feature2Mode,                   ///< Feature1Mode
    VideoHDR10Mode,                 ///< Video HDR10 Mode
    StatsSkipMode,                  ///< Force skip stats processing
    BurstFps,                       ///< Burst Fps indicates vendor tag coming from APP
    BurstShot,                      ///< Burst Shot indicates vendor tag to determine 2 consecutive JPEG/YUV/HEIF streams
    CustomNoiseReduction,           ///< MFNR  Hint
    FastShutterMode,                ///< FS mode
    IHDRControl,                    ///< IHDR Control
    HistNodeLTCRatioIndex,          ///< LTC ratio from histogram node
    IFEMaxWidth,                    ///< Max single IFE supported
    ZSLTimestampRange,              ///< Range of time within which to pull ZSL Buffers
    IPEOverrideScale,               ///< IPE Override Scale Flag
    LivePreview,                    ///< Live Preview Enablement flag
    SnapshotFrameExposureType,      ///< Exposure Type of the Live Snapshot Frame being processed
    DebugDumpConfig,                ///< Record timestamp and app frame number
    GPUOverrideRotation,            ///< GPU Node Rotation
    SWMCTFEnable,                   ///< SWMCTF Node enablement
    ScreenGrab,                     ///< Is ScreenGrab Snapshot
    MFNRCapability,                 ///< MFNR Capability
    T2TConfigRegROI,                ///< Tracker registration ROI from application
    T2TResultROI,                   ///< Tracker result ROI from driver
    SeemlessInSensorZoomModeSwitch, ///< InSensorZoom Mode Switch
    SeemlessInSensorZoomState,      ///< InSensorZoom State
    EnableMFNR,                     ///< Flag indicating MF Feature enablement
    EnableSHDR,                     ///< SHDR mode is enabled
    EnableMFHDR,                    ///< MFHDR mode is enabled
    MetadataOwnerCamId,             ///< Owner of given metadata used in multicam case
    NumPCRsBeforeStreamOn,          ///< Number of PCRs before stream on (earlyPCR)
    EnableMCXMasterCb,              ///< Flag indicating MasterRawCb enablement
    RawCbSourceType,                ///< Flag indicating Raw callback source type
    HDRVideoModeSession,            ///< HDRVideoMode enablement
    ExtendedMaxZoom,                ///< Extended MaxZoom
    SaliencyNumOfROI,               ///< Number of salient ROIs
    SaliencyROIData,                ///< Saliency ROI Data from driver
    SensorModeInfo,                 ///< SensorModeInfo
    McxYuvCbInfo,                   ///< Multicamera YUV callback information
    McxRawCbInfo,                   ///< Multicamera RAW callback information
    DynamicFPSConfig,               ///< Configuration of video dynamic FPS
    QLLControl,                     ///< QLL frame control
    AnchorSync,                     ///< fix anchor frame picked
    MultiFrameBurstCount,           ///< number of multiframe burst
    MultiFrameBurst,                ///< Enable multiframe burst
    QCFASnapshot,                   ///< Is QCFA Snapshot
    HWMFHDRSupported,               ///< MFHDR fuse value
    SWMCTFEnableWithRef,            ///< SWMCTF enable with reference frame handling in node
    EnableQLL,                      ///< QLL mode is enabled from UI
    IsQLLSupported,                 ///< QLL mode is supported
    EnableSWMF,                     ///< SWMF is enabled from application
    EnableAIDE,                     ///< AIDE is enabled from application
    EnableShadingCorrection,        ///< Enable SWBEstats in offline snapshot path
    EnableSWPDPC,                   ///< Enable SWPDPC in offline snapshot path
    FacialContourVersion,           ///< Facial countour version
    InSensorSHDRMode,               ///< Insensor SHDR mode capability
    EnableHVXSHDRMode,              ///< HVX SHDR mode
    enableSecureMode,               ///< Secure Mode session tag
    EnableHVXMFHDRMode,             ///< HVX MFHDR mode
    EnableMFNRAIDEMode,             ///< AIDE2 mode is enabled
    EnableHWMFNR,                   ///< HWMFNR is enabled from application
    EnableAIDE2,                    ///< AIDE2 is enabled from application
    MultiRoIEnable,                 ///< MultiRoI is enabled from application
    SWSHDRType,                     ///< SW SHDR Type
    SHDRSwitchEnable,               ///< SHDRSwitch is enabled from application
    VideoHDRmode,                   ///< HDR for SHDR switching
    MLInfEnable,                    ///< MLInf is enabled from application
    NumVendorTags                   ///< Max Tags
};

// Enum Class for Partial Result Count
enum class PartialResultCount
{
    NoPartialResult     = 0,
    FirstPartialResult  = 1,
    SecondPartialResult = 2,
    ThirdPartialResult  = 3,
};

// Enum Class for Total Partial Metadata that will be sent
enum class MetaDataResultCount
{
    NoMetaDataCount     = 0,
    OneMetaDataCount    = 1,
    TwoMetaDataCount    = 2,
    ThreeMetaDataCount  = 3,
};

// Enum Class for Partial Metadata sender
enum class PartialResultSender
{
    DriverPartialData = 0,
    CHIPartialData    = 1,
    DriverMetaData    = 2,
};

// Enum Class for Partial Metadata support from CHI
enum class PartialMetaSupport
{
    NoSupport           = 0,
    SeperatePartialMeta = 1,
    CombinedPartialMeta = 2,
};

/// @brief Various HDR modes supported
enum HDRFeatureMode
{
    HDRFeatureModeNone,                                         ///< HDRFeature mode None
    HDRFeatureModeSHDR,                                         ///< HDRFeature mode SHDR
    HDRFeatureModeMFHDR,                                        ///< HDRFeature mode MFHDR
    HDRFeatureModeQHDR,                                         ///< HDRFeature mode QHDR
    BayerFusionStaticSHDR,                                      ///< HDRFeature mode IOT SHDRv2
    YUVFusionSHDR,                                              ///< HDRFeature mode IOT SHDRv3
    HDRFeatureModeMax,                                          ///< Max MFHDR modes
};

/// @brief Various SW HDR modes supported
enum SWHDRFeatureMode
{
    SWSHDRNone,
    SWSHDRLI2Frame,
    SWYUVSHDRVC2Frame,
    SWSHDRVC2Frame,
    SWSHDRVC3Frame,
    SWSHDRV2VC2Frame,
    SWSHDRMax,
};
typedef HDRFeatureMode ChiHDRFeatureMode;
/// @brief Various HVX HDR modes supported
enum HVXFeatureMode
{
    HVXFeatureModeNone,                                         ///< HDRFeature mode None
    HVXFeatureModeSHDR,                                         ///< HDRFeature mode SHDR
    HVXFeatureModeMFHDR,                                        ///< HDRFeature mode MFHDR
    HVXFeatureModeMax,                                          ///< Max MFHDR modes
};

/// @brief Supported LDC feature modes.
typedef enum
{
    LDCFeatureModeNone,
    LDCFeatureModeON,
    LDCFeatureModeMax
} ChiLDCFeatureMode;

/// @brief Supported EIS feature modes.
typedef enum
{
    EISFeatureModeNone,
    EISFeatureModeON,
    EISFeatureModeMax
} ChiEISFeatureMode;

/// @brief Information about the last frame returned to the framework for a given stream
struct PerStreamBufferReturnInfo
{
    camera3_stream_t*   pCameraStream;                                    ///< Camera stream
    UINT64              activeFrames[MaxOutstandingRequests];             ///< Last framework number buffer returned on this stream
    UINT32              frameNumberToIndexToUse[MaxOutstandingRequests];  ///< frame number to index use per stream buffer
    UINT32              lastIndexEnqueued;                                ///< Last index for slot used in the activeFrames array
    UINT32              lastIndexDequeued;                                ///< Last index we removed a frame from
};

/// @brief Association info for CHI frames
struct ChiFrameNumAssociationInfo
{
    UINT32                      appFrameNumber;             ///< HALFrameNumber
    UINT32                      chiOverrideFrameNum;        ///< CHiFrameNumber
    UINT32                      chiAssociatedframeNum;      ///< Associated CHiFrameNumber given by the derived usecase/feature
    VOID*                       pAssociatedSesssionHandle;  ///< Associated Sesssion Handle
    VOID*                       pAssociatedPipelineHandle;  ///< Associated Pipeline Handle
};

#endif // CHXDEFS_H
