/* Copyright (c) 2006 NVIDIA Corporation. All rights reserved. * * NVIDIA Corporation and its licensors retain all intellectual property * and proprietary rights in and to this software, related documentation * and any modifications thereto. Any use, reproduction, disclosure or * distribution of this software and related documentation without an * express license agreement from NVIDIA Corporation is strictly prohibited. */ /** @file GFJxEnc.h GFSDK JPEG Encode API header file. */ #ifndef _GF_JPEG_ENC__ #define _GF_JPEG_ENC__ #include "GF.h" #include "GFRm.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ /** @addtogroup groupJxEnc JxEncAPI JPEG Encoder API */ /*@{*/ /** JxEncAPI property flag: JPEG quantization table is programmable. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_QTABLE 0x00000001 /** JxEncAPI property flag: Interrupt data capture mode and polling mode supported, if this flag is off then only polling mode is supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_INTERRUPT 0x00000004 /** JxEncAPI property flag: Digital zoom supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_DIGITAL_ZOOM 0x00000008 /** JxEncAPI property flag: Motion JPEG mode supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_MOTION_JPEG 0x00000010 /** JxEncAPI property flag: Rate control supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_RATE_CONTROL 0x00000020 /** JxEncAPI property flag: Planar YUV422 data supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_422_PLANAR 0x00000040 /** JxEncAPI property flag: Rotation supported. @see GFJxEncGetProperty(), GFPROPERTY::Capability */ #define GF_JX_ENC_CAP_ROTATION 0x00000080 /** Image source/target dimensions and data source for JPEG encoding. This structure is passed as parameter to GFJxEncStart() and describes data source, source cropping rectangle and destination image size. The surface the application wants to encode is pSrcSurf. If the application wants to encode an image from a camera or to re-encode a JPEG bitstream, this field should be set to NULL. If the application wants to encode an image from the display, this field should point to the primary surface. If an application wants to encode an existing image, it must create a system memory surface to hold the image and set this field to the system memory surface. @see GFJxEncStart() */ typedef struct _GFJXENCSTART { PGFRMSURFACE pSrcSurf;/**< Surface to encode, NULL for camera or re-encode JPEG */ PGFRECT pSrcRect; /**< Source image area need to encode */ NvU32 DestWidth; /**< Final encoded image width */ NvU32 DestHeight; /**< Final encode image height */ NvU32 uiOptions; /**< Bitmask of flags to control encoding
#GF_CAPT_BITSTREAM If set only bitstream is output, if unset JFIF header will be added
#GF_CAPT_PIECE_MEAL Piecemeal encoding @todo clarify meaning
*/ NvU32 Error; /**< Returns detailed error code on GFJxEncStart() failure
#GF_CAPT_ERROR_VIDEO_MEMORY_NOT_BIG_ENOUGH Not enough free video memory, try to release unnecessary video surfaces
#GF_CAPT_ERROR_WRONG_CONFIG Wrong input parameters, for example srcRect size greater than pSrcSurf dimensions
#GF_CAPT_ERROR_NO_CALLBACK No callback function available
*/ } GFJXENCSTART, *PGFJXENCSTART; /** JxEncAPI GFJXENCSTART::uiOptions flagbit: If set only bitstream is output, if unset JFIF header will be added. @see GFJXENCSTART, GFJxEncStart() */ #define GF_CAPT_BITSTREAM 1 /** JxEncAPI GFJXENCSTART::uiOptions flagbit: Piecemeal encoding @todo clarify meaning @see GFJXENCSTART, GFJxEncStart() */ #define GF_CAPT_PIECE_MEAL 2 /** JxEncAPI GFJXENCSTART::Error return code: Not enough free video memory. Try to release unnecessary video surfaces. @see GFJXENCSTART, GFJxEncStart() */ #define GF_CAPT_ERROR_VIDEO_MEMORY_NOT_BIG_ENOUGH 1 /** JxEncAPI GFJXENCSTART::Error return code: Wrong input parameters. E.g. srcRect size greater than pSrcSurf dimensions. @see GFJXENCSTART, GFJxEncStart() */ #define GF_CAPT_ERROR_WRONG_CONFIG 2 /** JxEncAPI GFJXENCSTART::Error return code: No callback function available. @todo clarify @see GFJXENCSTART, GFJxEncStart() */ #define GF_CAPT_ERROR_NO_CALLBACK 4 /** Descriptor for JPEG encode buffers. This structure describes a buffer and its fill status for encoded JPEG data or raw YUV transfered from the JPEG encoder to the application. It is used with GFJxEncCapture() and GFJxEncFetchImage() in either polling or callback data fetch mode. @see GFJxEncCapture(), GFJxEncFetchImage(), GFJxEncPRComplete() */ typedef struct _GFJXENC_BUF { NvU8 *pBuf; /**< Pointer to the buffer */ NvU32 bufSize; /**< Size of the buffer in bytes */ NvU32 nBytesCaptured; /**< Number of bytes captured, app initializes to 0 */ } GFJXENC_BUF, *PGFJXENC_BUF; /** Fetch buffer descriptor for use with GFJxEncFetchImage(). This data structure is used by GFJxEncInterruptHandler() to fetch encoded image data when IntType is GFJX_ENC_STREAM_BUF_INTR or GFJX_ENC_DONE_INTR. */ typedef struct _GFJXENC_FETCH_BUF{ PGFJXENC_BUF pBuf; NvU32 numOfBuf; NvU32 status; } GFJXENC_FETCH_BUF, *PGFJXENC_FETCH_BUF; /** JxEncAPI data fetch status code: All data of the current frame was fetched. @see GFJxEncFetchImage(), GFJxEncCapture() */ #define JXENC_DATA_COMPLETE 0x1 /** JxEncAPI data fetch status code: Data was fetched only partially. The application should make more calls to GFJxEncFetchImage() to fetch the rest. @see GFJxEncFetchImage(), GFJxEncCapture() */ #define JXENC_MORE_FETCH 0x2 /** JxEncAPI data fetch status code: New frame was encoded and is ready to fetch. @see GFJxEncFetchImage(), GFJxEncCapture() */ #define JXENC_NEW_FRAME 0x8 /** JxEncAPI data fetch status code: Time out error occured while encoded data is fetching. fetch. @see GFJxEncFetchImage(), GFJxEncCapture() */ #define JXENC_TIME_OUT 0x10 // definition of uiFeature for GFJxEncSetAttribute //the following definations are for set only /** JxEncAPI attribute: Choose preset QTable, coefficients in luma and chroma Qtable are all 1. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_100QUALITY 0 /** JxEncAPI attribute: Choose preset QTable, standard Qtable A and B, divided by 2. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_85QUALITY 1 /** JxEncAPI attribute: Choose preset QTable, standard Qtable A and B. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_75QUALITY 2 /** JxEncAPI attribute: Choose preset QTable, standard Qtable C and D. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_50QUALITY 3 /** JxEncAPI attribute: Choose preset QTable, standard Qtable C and D, multiplied by 2. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_25QUALITY 4 /** JxEncAPI attribute: Choose preset QTable, standard Qtable C and D, multiplied by 4. Interpretation of associated data block: None. Attribute is set-only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_SET_12QUALITY 5 //the following definations can be used for set and get /** JxEncAPI attribute: Set custom luma QTable. Interpretation of associated data block: A table of 64 16-bit (type NvU16) entries with quantization coefficients to be used for luma MCU's. Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_LQTABLE 6 /** JxEncAPI attribute: Set custom chroma QTable. Interpretation of associated data block: A table of 64 16-bit (type NvU16) entries with quantization coefficients to be used for chroma MCU's. Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_CQTABLE 7 /** JxEncAPI attribute: Decimation filter enable/disable. Interpretation of associated data block:
    NvU32 decimation enable
          0 = disable
          1 = enable
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_FILTER 8 /** JxEncAPI attribute: Huffman bit stuffing. Interpretation of associated data block:
    NvU32 Huffman stuffing enable
          0 = disable
          1 = enable
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_HUFF_BSTUFF 13 /** JxEncAPI attribute: Motion JPEG capturing mode enable/disable. Interpretation of associated data block:
    NvU32 Motion JPEG capturing mode enable
          0 = disable
          1 = enable
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_MOTION_JPEG 14 /** JxEncAPI attribute: Raw data capturing mode enable/disable. Interpretation of associated data block:
    NvU32 Raw data capturing mode enable
          0 = disable
          1 = enable
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_RAW_DATA 15 /** JxEncAPI attribute: Re-encode a JPEG bitstream. Registration of callback function for JPEG re-encode application:
    #PGFJXDECCALLBACK structure
    
Attribute is set only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_BITSTREAM 16 /** JxEncAPI attribute: JPEG encoding colour format. Only YUV420 and YUV422 encoding is supported. The JPEG encoder converts the incoming image to the configured colour format, and then encodes it in the JPEG bitstream. Only YUV420 and YUV422 are valid. Interpretation of associated data block:
    NvU32 Colour format identifier, one of:
          #GF_SURFACE_PLANAR_YUV422
          #GF_SURFACE_YUV420
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute(), GFRMSURFACE::ColorFormat */ #define JX_ENC_ENCODE_FORMAT 17 /** JxEncAPI attribute: Maximum JPEG byte size. The JPEG encoder will not generate a JPEG bitstream larger than this. Interpretation of associated data block:
    NvU32 Maximum size in bytes
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_MAX_SIZE 18 /** JxEncAPI attribute: Camera focal point. Image area which is close to the focal point will be encoded with higher quality. Takes effect only when #JX_ENC_MAX_SIZE is set. Interpretation of associated data block:
    NvU32 Focal point X position
    NvU32 Focal point Y position
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute(), #JX_ENC_DEGRADATION, #JX_ENC_MAX_SIZE */ #define JX_ENC_FOCAL_POINT 19 /** JxEncAPI attribute: Image quality degradation from focal point. Image areas further from the focal point get encoded with fewer bits. The number of bits is linearly degraded based on the percentage of degradation in the X and Y directions. This attribute takes effect only when JX_ENC_MAX_SIZE is set. Interpretation of associated data block:
    NvU32 X direction degradation percentage
    NvU32 Y direction degradation percentage
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute(), #JX_ENC_FOCAL_POINT, #JX_ENC_MAX_SIZE */ #define JX_ENC_DEGRADATION 20 /** JxEncAPI attribute: JPEG encode rotation and flip control. Interpretation of associated data block:
    NvU32 Rotation and flip control, one of the following constants
            #JX_ENC_ROTATE_0
            #JX_ENC_ROTATE_90
            #JX_ENC_ROTATE_180
            #JX_ENC_ROTATE_270
          optionally logically ORed with zero or more of the following flags
            #JX_ENC_H_FLIP
            #JX_ENC_V_FLIP
    
Default is #JX_ENC_ROTATE_0. Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATION 21 /** JxEncAPI attribute: Rotation and flip control for rartial rotation API. Enables and configures the partial rotation engine for partially rotated JPEG encoding. Partially rotated JPEG encoding allows for rotated encoding of large image sizes with a small image capture buffer. Interpretation of associated data block:
    NvU32 Rotation and flip control, one of the following constants
            #JX_PRENC_ROTATE_UNSET - reset and disable partial rotation engine
            #JX_ENC_ROTATE_0
            #JX_ENC_ROTATE_90
            #JX_ENC_ROTATE_180
            #JX_ENC_ROTATE_270
          if not #JX_PRENC_ROTATE_UNSET optionally logically ORed with zero or
          more of the following flags
            #JX_ENC_H_FLIP
            #JX_ENC_V_FLIP
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_PARTIAL_ROTATE 22 /** JxEncAPI attribute: Bypass FIFO. Interpretation of associated data block:
    NvU32 Raw data capturing mode enable
          0 = Fetching encoded data through DMA FIFO
          1 = Fetching encoded data directly through output buffer not through
              DMA FIFO
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_BYPASS_FIFO 23 /** JxEncAPI attribute: Piece-Meal encoding. Interpretation of associated data block:
    NvU32 Piece-Meal encoding enable
          0 = enable
          1 = disable
    
Attribute is get only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_PIECE_MEAL 24 /** JxEncAPI attribute: Fetch Low bitstream. Registration of callback function for fetching raw data stream from JPEG encoder:
    #PGFJXDECCALLBACK structure
    
Attribute is set only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_RAW_DATA_STREAM 25 /** JxEncAPI attribute: Fetch Low JPEG bitstream. Registration of callback function for fetching JPEG raw data stream from JPEG encoder:
    #PGFJXDECCALLBACK structure
    
Attribute is set only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_RAW_JPEG_CAPTURE 26 /** JxEncAPI attribute: Set Timeout value Interpretation of associated data block:
    NvU32 timeout   timeout value
        0       = no timeout
        > 0     = timeout value
    
Attribute is set only. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_TIMEOUT_CONF 27 /** JxEncAPI attribute: Stop preview enable/disable. Interpretation of associated data block:
    NvU32 Stop preview mode enable
          0 = disable
          1 = enable
    
Attribute can be set and get. @see GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_STOP_PREVIEW 28 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: Non-rotated JPEG encode. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATE_0 0x0 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: JPEG encode rotated 90 degrees. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATE_90 0x1 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: JPEG encode rotated 180 degrees. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATE_180 0x2 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: JPEG encode rotated 270 degrees. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATE_270 0x3 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: JPEG encode horizontally flipped. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_H_FLIP 0x10 /** Option for attributes #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE: JPEG encode vertically flipped. @see #JX_ENC_ROTATION, #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_V_FLIP 0x20 /** Option for attribute #JX_ENC_PARTIAL_ROTATE: Reset and disable partial rotation. Pass this to GFJxEncSetAttribute() for attribute #JX_ENC_PARTIAL_ROTATE to unset the Partial Rotation Flag and reset the PR Engine. @see #JX_ENC_PARTIAL_ROTATE, GFJxEncSetAttribute(), GFJxEncGetAttribute() */ #define JX_ENC_ROTATE_UNSET 0xff typedef void (*GFJX_ENC_CALLBACK)(void *userData); /** JxEncAPI interrupt operation types. Constants to specify operation for a call to GFJxEncInterruptControl(). @see GFJX_ENC_INTERRUPT_TYPE, GFJxEncInterruptControl() */ typedef enum { /** Enable interrupt/status assertion for an interrupt type. */ GFJX_ENC_INTERRUPT_ENABLE, /** Disable interrupt/status assertion for an interrupt type. */ GFJX_ENC_INTERRUPT_DISABLE, /** Clear interrupt/status assertion for an interrupt type. */ GFJX_ENC_INTERRUPT_CLEAR, /** Query for interrupt/status assertion for an interrupt type. */ GFJX_ENC_INTERRUPT_QUERY_STATUS, /** Set DMA FIFO threshold. */ GFJX_ENC_INTERRUPT_SET_DMA_FIFO_THRESHOLD, /** Get DMA FIFO threshold. */ GFJX_ENC_INTERRUPT_GET_DMA_FIFO_THRESHOLD, /** Set strean buffer threshold. */ GFJX_ENC_INTERRUPT_SET_BUF_THRESHOLD, /** Get strean buffer threshold. */ GFJX_ENC_INTERRUPT_GET_BUF_THRESHOLD } GFJX_ENC_INTERRUPT_OPERATION_TYPE; /** JxEncAPI interrupt types. @see GFJX_ENC_INTERRUPT_OPERATION_TYPE, GFJxEncInterruptControl() */ typedef enum { /** JPEG read DMA FIFO low threshold. Interrupt/status is asserted if the JPEG read DMA FIFO status is less than the JPEG read DMA FIFO threshold value. */ GFJX_ENC_DMA_FIFO_LOW_INTR = 0, /** JPEG read DMA FIFO high threshold. Interrupt/status is asserted if the JPEG read DMA FIFO status is greater than or equal to the JPEG read DMA FIFO threshold value. */ GFJX_ENC_DMA_FIFO_HIGH_INTR = 0x1, /** Stream buffer threshold interrupt. */ GFJX_ENC_STREAM_BUF_INTR = 0x2, /** Main buffer end hit interrupt. */ GFJX_ENC_MAIN_BUF_HIT_INTR = 0x4, /** Encoding done interrupt. */ GFJX_ENC_DONE_INTR = 0x8, /** Encoded stream transfer done interrupt. */ GFJX_ENC_TRANSFER_DONE_INTR = 0x10, /** Maximum bit count hit interrupt. */ GFJX_ENC_MAX_BIT_HIT_INTR = 0x20, /** Circular buffer overflow interrupt. */ GFJX_ENC_CIR_BUF_OVERFLOW_INTR = 0x40 } GFJX_ENC_INTERRUPT_TYPE; /** JxEncAPI virtual function pointer table. */ typedef struct _GFJXENCTABLE { GF_RETTYPE (* JxEncGetProperty)(GFJxEncHandle hJxEnc, PGFPROPERTY pJXProp); GF_RETTYPE (* JxEncSetAttribute)(GFJxEncHandle hJxEnc, NvU32 uiFeature, NvU32* pInfo); GF_RETTYPE (* JxEncGetAttribute)(GFJxEncHandle hJxEnc, NvU32 uiFeature, NvU32* pInfo); GF_RETTYPE (* JxEncStart)(GFJxEncHandle hJxEnc, PGFJXENCSTART pStart); GF_RETTYPE (* JxEncFetchImage)(GFJxEncHandle hJxEnc, PGFJXENC_BUF aBuf, NvU32 nBuf, NvU32 *pStatus); GF_RETTYPE (* JxEncEnd)(GFJxEncHandle hJxEnc); GF_RETTYPE (* JxEncSetupInterrupt)(GFJxEncHandle hJxEnc, void (*Inter)(void *), void *IPara); GF_RETTYPE (* JxEncCapture)(GFJxEncHandle hJxEnc, PGFJXENC_BUF aBuf, NvU32 nBuf, NvU32 *pStatus); GF_RETTYPE (* JxEncInterruptControl)(GFJxEncHandle hJxEnc, GFJX_ENC_INTERRUPT_TYPE IntType, GFJX_ENC_INTERRUPT_OPERATION_TYPE op, void * pData); GF_RETTYPE (* JxEncInterruptHandler)(GFJxEncHandle hJxEnc, GFJX_ENC_INTERRUPT_TYPE IntType, void * pData); // Reserved. GF_RETTYPE (*JxEncPRComplete)(GFJxEncHandle hJxEnc, PGFJXENC_BUF inBuf,NvU32 inBufNum,PGFJXENC_BUF outBuf, NvU32 outBufNum,PGFJXENC_BUF dcacBuf,NvU32 dcacBufNum); GF_RETTYPE (*JxEncBracket)(GFJxEncHandle hJxEnc, GFJX_ENC_CALLBACK before, GFJX_ENC_CALLBACK after, void *userData); } GFJXENCTABLE, *PGFJXENCTABLE; #ifdef PROJECT_SEC_G1 // Attribute constant and data structure for EXIF #define JX_ENC_SET_EXIF_INFO 30 typedef struct _GFJXENCEXIFINFO { NvS8 CameraMaker[32]; NvS8 CameraModel[40]; NvS8 FirmwareVersion[5]; NvU32 FNumberNum; NvU32 FNumberDenom; NvS32 ExpBiasNum; NvS32 ExpBiasDenom; NvU16 WhiteBalance; NvU32 DigitalZoomNum; NvU32 DigitalZoomDenom; } GFJXENCEXIFINFO; #endif // Typesafe functions for opening and closing this component GF_RETTYPE GFJxEncOpen(GFRmHandle hRm, GFJxEncHandle *phJxEnc, GF_STATE_TYPE state, GFRmChHandle hCh); void GFJxEncClose(GFJxEncHandle *phJxEnc); /* #### JxEnc Helper macros. Maybe useful for backward compatible API. #### */ /** @name Functions @{*/ /** This function returns version and capabilities of API and hardware. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param pJXProp (PGFPROPERTY) Pointer to property structure to be filled in @retval #GF_SUCCESS \a pJXProp filled in successfully @retval #GF_ERROR Some error occured The #GFPROPERTY structure passed with parameter \a pJXProp will be filled in on successfull return. The GFPROPERTY::Capability field will hold a combination of flagbits indicating capabilities specific to the JxEncAPI:
#GF_JX_ENC_CAP_QTABLE JPEG quantization table is programmable.
#GF_JX_ENC_CAP_INTERRUPT Interrupt data capture mode and polling mode supported, if this flag is off then only polling mode is supported.
#GF_JX_ENC_CAP_DIGITAL_ZOOM Digital zoom supported.
#GF_JX_ENC_CAP_MOTION_JPEG Motion JPEG mode supported.
#GF_JX_ENC_CAP_RATE_CONTROL Rate control supported.
#GF_JX_ENC_CAP_422_PLANAR Planar YUV422 data supported.
#GF_JX_ENC_CAP_ROTATION Rotation supported.
It is a good practice to call this function to query for the API version and its capabilities before using the rest of the JxEncAPI functions. @see GFPROPERTY */ #define GFJxEncGetProperty(hJxEnc, pJXProp) \ ((PGFJXENCTABLE)hJxEnc)->JxEncGetProperty(hJxEnc, pJXProp) /** Set configuration of a feature of the JPEG encoder hardware. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param uiFeature (NvU32) Feature type identifier, see table. @param pInfo (NvU32*) Pointer to feature specific input parameter block. Pointer type will be reinterpreted according to feature type. @retval #GF_SUCCESS Configuration changed successfully @retval #GF_ERROR Some error occured The feature to be set is identified with parameter \a uiFeature, specific input parameters are passed via a block in parameter \a pInfo. The contents of this data block is interpreted depending on the feature to be set. The following features are defined, for the data to be provided in \a pInfo see the individual attribute's documentation.
\b Attribute \b Direction \b Synopsis
#JX_ENC_SET_100QUALITYset Choose preset QTable, coefficients in luma and chroma Qtable are all 1.
#JX_ENC_SET_85QUALITY set Choose preset QTable, standard Qtable A and B, divided by 2.
#JX_ENC_SET_75QUALITY set Choose preset QTable, standard Qtable A and B.
#JX_ENC_SET_50QUALITY set Choose preset QTable, standard Qtable C and D.
#JX_ENC_SET_25QUALITY set Choose preset QTable, standard Qtable C and D, multiplied by 2.
#JX_ENC_SET_12QUALITY set Choose preset QTable, standard Qtable C and D, multiplied by 4.
#JX_ENC_LQTABLE set, get Set custom luma QTable.
#JX_ENC_CQTABLE set, get Set custom chroma QTable.
#JX_ENC_FILTER set, get Decimation filter enable/disable.
#JX_ENC_HUFF_BSTUFF set, get Huffman bit stuffing.
#JX_ENC_MOTION_JPEG set, get Motion JPEG capturing mode enable/disable.
#JX_ENC_RAW_DATA set, get Raw data capturing mode enable/disable.
#JX_ENC_BITSTREAM set Re-encode a JPEG bitstream.
#JX_ENC_ENCODE_FORMAT set, get JPEG encoding colour format.
#JX_ENC_MAX_SIZE set, get Maximum JPEG byte size.
#JX_ENC_FOCAL_POINT set, get Camera focal point.
#JX_ENC_DEGRADATION set, get Image quality degradation from focal point.
#JX_ENC_ROTATION set, get JPEG encode rotation and flip control.
#JX_ENC_PARTIAL_ROTATEset, get Rotation and flip control for Partial Rotation API.
#JX_ENC_BYPASS_FIFO set, get Bypass FIFO.
#JX_ENC_PIECE_MEAL get Piece-Meal encoding.
#JX_ENC_STOP_PREVIEW set, get Stop preview mode enable/disable.
#JX_ENC_RAW_JPEG_CAPTURE set Fetch Low JPEG bitstream.
#JX_ENC_RAW_DATA_STREAM set Fetch Low bitstream.
#JX_ENC_TIMEOUT_CONF set, get Set Timeout value.
Most of the time an application should only set a quantization table for luminance or chrominance. These quantization tables are in the same format as standard quantization tables (1 to 255). Other features are hardware dependent. @see GFJxEncGetAttribute() */ #define GFJxEncSetAttribute(hJxEnc, uiFeature, pInfo) \ ((PGFJXENCTABLE)hJxEnc)->JxEncSetAttribute(hJxEnc, uiFeature, pInfo) /** Get current configuration of a feature of the JPEG encoder hardware. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param uiFeature (NvU32) Feature type identifier, see table in GFJxEncSetAttribute(). @param pInfo (NvU32*) Pointer to feature specific input parameter block. Pointer type will be reinterpreted according to feature type. @retval #GF_SUCCESS \a pInfo filled in successfully @retval #GF_ERROR Some error occured @see GFJxEncSetAttribute() */ #define GFJxEncGetAttribute(hJxEnc, uiFeature, pInfo) \ ((PGFJXENCTABLE)hJxEnc)->JxEncGetAttribute(hJxEnc, uiFeature, pInfo) /** Setup JxEncAPI for JPEG encoding. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param pStart (#PGFJXENCSTART) Pointer to #GFJXENCSTART structure for definition of encode source and destination @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured, check GFJXENCSTART::Error for detailed error reason code. Before starting capture, the application should call this function to setup the encoder. Once this function has been called, the application can use GFJxEncCapture() to capture as many frames as desired. JxEncCapture() starts and optionally fetches data for a frame. JxEncFetchImageData() fetches the image data to host CPU side. An application should keep calling it until all encoded data is processed. Finally GFJxEncEnd() has to be called to release the encoder. Parameter \a pStart passes a #GFJXENCSTART structure describing image data source, source cropping area, and destination size. Encoding is from one of the following sources: - VI (Camera, cropping and scale up/down is done via VxVIPSet(), Rotation/flip is done via JxEncSelectEPPRotation() ) - Screen encoding (GC, source is primary surface) - Bitstream encoding. This is used to re-encode a JPEG bit stream, and invokes JxDecAPI internally to decode the existing bitstream. The following options are available for bitstream re-encoding: - Crop image size - Scale up - Change QTables - Apply rate control - Rotation (0, 90, 180, 270, H-Flip, V-Flip) On failure an error reason code is returned in field GFJXENCSTART::Error of parameter \a pStart. @see GFJXENCSTART, GFJxEncSetAttribute(), GFJxEncCapture(), GFJxEncFetchImage(), GFJxEncEnd() */ #define GFJxEncStart(hJxEnc, pStart) \ ((PGFJXENCTABLE)hJxEnc)->JxEncStart(hJxEnc, pStart) /** Polls JxEncAPI for data fetch from JPEG encoder. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param aBuf (#PGFJXENC_BUF) Pointer to array of #GFJXENC_BUF structures @param nBuf (NvU32) Number of pointers passed with \a aBuf. @param pStatus (NvU32) Returns data fetch status, see table @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured Captures the JPEG encoded bit stream in the given application owned buffers. Capturing the encoded image can be done in polling or interrupt mode. This function should be called after GFJxEncCapture(). It is usually called from either the application's fetching poll loop, or the interrupt callback routine set up with GFJxEncSetupInterrupt(). The application must fill all the fields in the referenced buffer structures and must make sure each PGFJXENC_BUF::nBytesCaptured is set to 0. The PGFJXENC_BUF::nBytesCaptured field is updated by the JXEncAPI to show the actual number of bytes captured. JXEncAPI keeps filling the buffers in the array until it exhausts all the buffers. If all the buffers are exhausted and there is more data to be copied, the function returns and sets \a pStatus to #JXENC_MORE_FETCH. The application should then keep calling GFJxEncFetchImage() to fetch the remaining data. Each buffer in the array should be a multiple of 64 bytes for best performance. The status of the data fetch is returned in \a pStatus as one of the following reason codes:
#JXENC_DATA_COMPLETEAll data of the current frame was fetched.
#JXENC_MORE_FETCH Data was fetched only partially. The application should make more calls to GFJxEncFetchImage() to fetch the rest.
#JXENC_NEW_FRAME A new frame was encoded and is ready to fetch.
#JXENC_TIME_OUT Timeout on GFJxEncFetchImage
@see GFJxEncCapture(), GFJxEncSetupInterrupt(), #GFJXENC_BUF */ #define GFJxEncFetchImage(hJxEnc, aBuf, nBuf, pStatus) \ ((PGFJXENCTABLE)hJxEnc)->JxEncFetchImage(hJxEnc, aBuf, nBuf, pStatus) /** Polls JxEncAPI for data fetch from JPEG encoder. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured This function disables the encoder and releases internal resources related to the current capture. @see GFJxEncStart() */ #define GFJxEncEnd(hJxEnc) \ ((PGFJXENCTABLE)hJxEnc)->JxEncEnd(hJxEnc) /** Register a callback function for fetching encoded JPEG data. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param Inter (void(*)(void *)) Application callback function pointer @param IPara (void*) Parameter to pass on to application callback function @retval #GF_SUCCESS Callback installed successfully @retval #GF_ERROR Some error occured This function can be used to register a callback function for fetching encoded JPEG data. This function must be called before GFJxEncCapture(). The callback function must meet the following prototype:
    void InterruptCallback(void* lPara);
    
Whenever encoding is triggered, JXEncAPI calls the registered interrupt callback function, passing on the application defined parameter \a IPara. Inside the callback function, the application can call GFJxEncFetchImage() to portionally fetch the encoded datastream. If no callback function shall be used, the application could alternatively use a polling scheme. @see GFJxEncCapture() */ #define GFJxEncSetupInterrupt(hJxEnc, Inter, IPara) \ ((PGFJXENCTABLE)hJxEnc)->JxEncSetupInterrupt(hJxEnc, Inter, IPara) /** Trigger JPEG encoder for one frame and optionally display capture preview. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param aBuf (#PGFJXENC_BUF) Pointer to array #GFJXENC_BUF structures @param nBuf (NvU32) Number of pointers passed with \a aBuf, if passing 0 then the function is non-blocking @param pStatus (NvU32) Returns data fetch status, for reason codes see table at GFJxEncFetchImage() @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured Triggers the JPEG encoder for a frame and optionally displays the same frame in a preview window in decimated form. Encoded data can be fetched via a polling scheme or via an interrupt handler set up with GFJxEncSetupInterrupt(). In any case GFJxEncFetchImage() is used to transfer encoded data to application buffers. If application set up an interrupt handler to fetch encoded data, then \a nBuf should be passed as 0. This function can optionally fetch data right after triggering encoding to buffers provided via \a aBuf. This will block the CPU until all data is returned or buffer space is exhausted. If \a nBuf is 0, the function returns right away and \a pStatus is updated to #JXENC_NEW_FRAME to indicate data is pending. The application should then call GFJxEncFetchImage() either from an interrupt handler or from same thread to fetch the encoded/raw data. If \a nBuf is not 0, it specifies the number of buffers in the array \a aBuf. The function will block until it runs out of buffers. It will return #JXENC_MORE_FETCH in parameter \a pStatus if more data is available. The application must call GFJxEncFetchImage() to fetch the remaining data. See GFJxEncFetchImage() for information on return status codes and how the passed buffers are handled. JPEG Encoding from camera or raw data capture from camera happens in realtime, so if the internal circular buffer in GPU memory is not big enough then GFJxEncFetchImage() should be called more fequently to empty the outputBuf and avoid buffer overflows. @see GFJxEncSetupInterrupt(), GFJxEncFetchImage(), #GFJXENC_BUF */ #define GFJxEncCapture(hJxEnc, aBuf, nBuf, pStatus) \ ((PGFJXENCTABLE)hJxEnc)->JxEncCapture(hJxEnc, aBuf, nBuf, pStatus) /** JxEncAPI Component-level interrupt control. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param IntType (#GFJX_ENC_INTERRUPT_TYPE) JxEncAPI interrupt type @param op (#GFJX_ENC_INTERRUPT_OPERATION_TYPE) GFJxEncAPI interrupt operation @param pData (void*) Pointer to input or output data block, see table @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured @retval #GF_ERROR_BAD_PARAMETER Invalid parameters The following operations (parameter op) are defined for this call. Operation #GFJX_ENC_INTERRUPT_ENABLE Enable status/interrupt generation for interrupts of type specified by \a IntType. Depending on the interrupt type additional action and the parameter \a pData is interpreted as following:
#GFJX_ENC_DMA_FIFO_LOW_INTR JPEG read DMA FIFO status/interrupt generation is put into low threshold mode, i.e. interrupt/status is asserted if the JPEG read DMA FIFO status is less than the threshold value. \a pData points to block containing:
NvU32 DMA FIFO low threshold value in range 0..15 \a pData can be NULL to leave the threshold value unchanged.
#GFJX_ENC_DMA_FIFO_HIGH_INTR JPEG read DMA FIFO status/interrupt generation is put into high threshold mode, i.e. interrupt/status is asserted if the JPEG read DMA FIFO status is greater than or equal toless than the threshold value. \a pData points to block containing:
NvU32 DMA FIFO high threshold value in range 0..15 \a pData can be NULL to leave the threshold value unchanged.
#GFJX_ENC_STREAM_BUF_INTR \a pData points to block containing:
NvU32 JPEG stream buffer threshold value in bytes, must be multiple of 8 \a pData can be NULL to leave the threshold value unchanged.
otherwise \a pData is ignored
Operation #GFJX_ENC_INTERRUPT_DISABLE Disable status/interrupt generation for interrupts of type specified by \a IntType. Operation #GFJX_ENC_INTERRUPT_CLEAR Clear status/interrupt assertion for interrupt of type specified by \a IntType. Operation #GFJX_ENC_INTERRUPT_QUERY_STATUS Return current status/interrupt assertion for interrupt of type specified by \a IntType. The state is returned in the block referenced by \a pData. Interpretation of associated data block \a pData
        NvU32 Interrupt/status assertion state, one of:
              GF_INTERRUPT_ON_STATUS_TRUE = asserted
              GF_INTERRUPT_ON_STATUS_FALSE = not asserted
        
Operation #GFJX_ENC_INTERRUPT_SET_DMA_FIFO_THRESHOLD Set DMA FIFO threshold value that controls interrupt/status assertion for interrupt types #GFJX_ENC_DMA_FIFO_LOW_INTR and #GFJX_ENC_DMA_FIFO_HIGH_INTR. Interpretation of associated data block \a pData
        NvU32 DMA FIFO threshold value in range 0..15
        
Operation #GFJX_ENC_INTERRUPT_GET_DMA_FIFO_THRESHOLD Return DMA FIFO threshold value that controls interrupt/status assertion for interrupt types #GFJX_ENC_DMA_FIFO_LOW_INTR and #GFJX_ENC_DMA_FIFO_HIGH_INTR. Interpretation of associated data block \a pData
        NvU32 DMA FIFO threshold value in range 0..15
        
Operation #GFJX_ENC_INTERRUPT_SET_BUF_THRESHOLD Set JPEG stream buffer threshold value that controls interrupt/status assertion for interrupt type #GFJX_ENC_STREAM_BUF_INTR. Interpretation of associated data block \a pData
        NvU32 DMA read buffer threshold value in bytes, must be multiple of 8
        
Operation #GFJX_ENC_INTERRUPT_GET_BUF_THRESHOLD Return JPEG stream buffer threshold value that controls interrupt/status assertion for interrupt type #GFJX_ENC_STREAM_BUF_INTR. Interpretation of associated data block \a pData
        NvU32 DMA read buffer threshold value in bytes, must be multiple of 8
        
@see GFJX_ENC_INTERRUPT_TYPE, GFJX_ENC_INTERRUPT_OPERATION_TYPE */ #define GFJxEncInterruptControl(hJxEnc, IntType, op, pData)\ ((PGFJXENCTABLE)hJxEnc)->JxEncInterruptControl(hJxEnc, IntType, op, pData) /** Standard interrupt handler for fetching encoded JPEG data. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param IntType (#GFJX_ENC_INTERRUPT_TYPE) JxEncAPI interrupt type @param pData (void*) Pointer to input or output data block, depending on \a IntType. See table. @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured
\a IntType Interpretation of \a pData
#GFJX_ENC_STREAM_BUF_INTR, GFJX_ENC_DONE_INTR #PGFJXENC_FETCH_BUF
Usually this callback is not used, because the interrupt service thread at the application level can call GFJxEncFetchImage() directly to complete the task of fetching encoded data. @todo clarify @see GFJxEncFetchImage() */ #define GFJxEncInterruptHandler(hJxEnc, IntType, pData)\ ((PGFJXENCTABLE)hJxEnc)->JxEncInterruptHandler(hJxEnc, IntType, pData) /** Generate final JPEG bitstream from a partially rotated bitstream. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param inBuf (#PGFJXENC_BUF) Pointer to array of #GFJXENC_BUF structs holding fragmented input bitstream @param inBufNum (NvU32) Size of array \a inBuf @param outBuf (#PGFJXENC_BUF) Pointer to array of #GFJXENC_BUF structs to output fragmented JPEG bitstream @param outBufNum (NvU32) Size of array \a outBuf @param dcacBuf (#PGFJXENC_BUF) ? @param dcacBufNum (NvU32) Size of array \a dcacBuf @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured @todo clarify */ #define GFJxEncPRComplete(hJxEnc,inBuf,inBufNum,outBuf,outBufNum,dcacBuf,dcacBufNum)\ ((PGFJXENCTABLE)hJxEnc)->JxEncPRComplete(hJxEnc,inBuf,inBufNum,outBuf,outBufNum,dcacBuf,dcacBufNum) /** Provide callbacks for immediately before and after any encode events. These will be called by JxEncode() when it is invoked. Calling this routine a second time will overwrite previously set values. @param hJxEnc (#GFJxEncHandle) Handle to JxEncAPI @param before (#GFJX_ENC_CALLBACK) proc to call before capture @param after (#GFJX_ENC_CALLBACK) proc to call after capture @param userData (void *) data to be supplied to before() and after() when they are invoked. @retval #GF_SUCCESS Success @retval #GF_ERROR Some error occured */ #define GFJxEncBracket(hJxEnc, before, after, userData) \ ((PGFJXENCTABLE)hJxEnc)->JxEncBracket(hJxEnc, before, after, userData) /*@}*/ /*@}*/ /** @page pageJxEncAppNotes JxEncAPI Application Notes @section pageJxEncAppNotes1 Programming Sequence The following procedure requires that GFRmOpen() is called first to start GFSDK usage. The description is for a typical case where encoding of a still image being captured from a camera is done and preview shown on the display. 1. In case of camera encoding, setup the camera & initialize VIP.
2. Obtain the handle specific to JPEG encoder by calling GFJxEncOpen().
3. Call GFRmSurfaceAlloc() to allocate one referance surface for encoding purposes.
4. Call GFJxEncSetAttribute() if specific features need to be set, such as encoding width, encoding height, rotation, quality factor, etc.
5. Start the encoding by calling GFJxEncStart().
6. If the current source image is from the CPU, the application should call GFJxEncFeedImage() to feed the image to the GFJxEncAPI via GFJxEncCapture().
7. The application should fetch the encoded stream by calling GFJxEncFetchImage(). Application should keep it calling till whole encoded data is out.
8. For exiting, free all relevent resources and call GFJxEncEnd() to free the JPEG encoder component.
*/ #ifdef __cplusplus } // only need to export C interface if // used by C++ source code #endif #endif //_GF_JPEG_ENC__