OSDN Git Service

va.h: Improve the comment on the encode framerate parameter
[android-x86/hardware-intel-common-libva.git] / va / va.h
diff --git a/va/va.h b/va/va.h
index b04f28a..a1ab4a8 100644 (file)
--- a/va/va.h
+++ b/va/va.h
@@ -205,6 +205,7 @@ typedef int VAStatus;       /** Return status type from functions */
 #define VA_CLEAR_DRAWABLE       0x00000008
 
 /** Color space conversion flags for vaPutSurface() */
+#define VA_SRC_COLOR_MASK       0x000000f0
 #define VA_SRC_BT601            0x00000010
 #define VA_SRC_BT709            0x00000020
 #define VA_SRC_SMPTE_240        0x00000040
@@ -221,6 +222,29 @@ typedef int VAStatus;      /** Return status type from functions */
  */
 const char *vaErrorStr(VAStatus error_status);
 
+typedef struct _VARectangle
+{
+    short x;
+    short y;
+    unsigned short width;
+    unsigned short height;
+} VARectangle;
+
+/** Type of a message callback, used for both error and info log. */
+typedef void (*vaMessageCallback)(const char *message);
+
+/**
+ * Set the callback for error messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetErrorCallback(vaMessageCallback);
+
+/**
+ * Set the callback for info messages, or NULL for no logging.
+ * Returns the previous one, or NULL if it was disabled.
+ */
+vaMessageCallback vaSetInfoCallback(vaMessageCallback);
+
 /**
  * Initialization:
  * A display must be obtained by calling vaGetDisplay() before calling
@@ -231,7 +255,14 @@ const char *vaErrorStr(VAStatus error_status);
 typedef void* VANativeDisplay; /* window system dependent */
 
 int vaDisplayIsValid(VADisplay dpy);
-    
+
+/**
+ *  Set the override driver name instead of queried driver driver.
+ */
+VAStatus vaSetDriverName(VADisplay dpy,
+                         char *driver_name
+);
+
 /**
  * Initialize the library 
  */
@@ -260,7 +291,7 @@ const char *vaQueryVendorString (
     VADisplay dpy
 );
 
-typedef int (*VAPrivFunc)();
+typedef int (*VAPrivFunc)(void);
 
 /**
  * Return a function pointer given a function name in the library.
@@ -294,7 +325,11 @@ typedef enum
     VAProfileH264MultiviewHigh          = 15,
     VAProfileH264StereoHigh             = 16,
     VAProfileHEVCMain                   = 17,
-    VAProfileHEVCMain10                 = 18
+    VAProfileHEVCMain10                 = 18,
+    VAProfileVP9Profile0                = 19,
+    VAProfileVP9Profile1                = 20,
+    VAProfileVP9Profile2                = 21,
+    VAProfileVP9Profile3                = 22
 } VAProfile;
 
 /**
@@ -309,6 +344,15 @@ typedef enum
     VAEntrypointDeblocking     = 5,
     VAEntrypointEncSlice       = 6,    /* slice level encode */
     VAEntrypointEncPicture     = 7,    /* pictuer encode, JPEG, etc */
+    /*
+     * For an implementation that supports a low power/high performance variant
+     * for slice level encode, it can choose to expose the
+     * VAEntrypointEncSliceLP entrypoint. Certain encoding tools may not be
+     * available with this entrypoint (e.g. interlace, MBAFF) and the
+     * application can query the encoding configuration attributes to find
+     * out more details if this entrypoint is supported.
+     */
+    VAEntrypointEncSliceLP     = 8,
     VAEntrypointVideoProc       = 10,   /**< Video pre/post-processing. */
 } VAEntrypoint;
 
@@ -322,6 +366,21 @@ typedef enum
     VAConfigAttribEncryption           = 4,
     VAConfigAttribRateControl          = 5,
 
+    /** @name Attributes for decoding */
+    /**@{*/
+    /**
+     * \brief Slice Decoding mode. Read/write.
+     *
+     * This attribute determines what mode the driver supports for slice
+     * decoding, through vaGetConfigAttributes(); and what mode the user
+     * will be providing to the driver, through vaCreateConfig(), if the
+     * driver supports those. If this attribute is not set by the user then
+     * it is assumed that VA_DEC_SLICE_MODE_NORMAL mode is used.
+     *
+     * See \c VA_DEC_SLICE_MODE_xxx for the list of slice decoding modes.
+     */
+    VAConfigAttribDecSliceMode         = 6,
+
     /** @name Attributes for encoding */
     /**@{*/
     /**
@@ -408,6 +467,34 @@ typedef enum
      * that can be configured. e.g. a value of 2 means there are two distinct quality levels. 
      */
     VAConfigAttribEncQualityRange     = 21,
+    /**
+     * \brief Encoding skip frame attribute. Read-only.
+     *
+     * This attribute conveys whether the driver supports sending skip frame parameters 
+     * (VAEncMiscParameterTypeSkipFrame) to the encoder's rate control, when the user has 
+     * externally skipped frames. 
+     */
+    VAConfigAttribEncSkipFrame        = 24,
+    /**
+     * \brief Encoding region-of-interest (ROI) attribute. Read-only.
+     *
+     * This attribute conveys whether the driver supports region-of-interest (ROI) encoding,
+     * based on user provided ROI rectangles.  The attribute value is partitioned into fields
+     * as defined in the VAConfigAttribValEncROI union.
+     *
+     * If ROI encoding is supported, the ROI information is passed to the driver using
+     * VAEncMiscParameterTypeROI.
+     */
+    VAConfigAttribEncROI              = 25,
+    /**
+     * \brief Encoding extended rate control attribute. Read-only.
+     *
+     * This attribute conveys whether the driver supports any extended rate control features
+     * The attribute value is partitioned into fields as defined in the
+     * VAConfigAttribValEncRateControlExt union.
+     */
+    VAConfigAttribEncRateControlExt   = 26,
+
     /**@}*/
     VAConfigAttribTypeMax
 } VAConfigAttribType;
@@ -429,6 +516,9 @@ typedef struct _VAConfigAttrib {
 #define VA_RT_FORMAT_YUV444    0x00000004
 #define VA_RT_FORMAT_YUV411    0x00000008
 #define VA_RT_FORMAT_YUV400    0x00000010
+/** YUV formats with more than 8 bpp */
+#define VA_RT_FORMAT_YUV420_10BPP      0x00000100
+/** RGB formats */
 #define VA_RT_FORMAT_RGB16     0x00010000
 #define VA_RT_FORMAT_RGB32     0x00020000
 /* RGBP covers RGBP and BGRP fourcc */ 
@@ -449,6 +539,18 @@ typedef struct _VAConfigAttrib {
 #define VA_RC_CQP                       0x00000010
 /** \brief Variable bitrate with peak rate higher than average bitrate. */
 #define VA_RC_VBR_CONSTRAINED           0x00000020
+/** \brief Macroblock based rate control.  Per MB control is decided
+ *  internally in the encoder. It may be combined with other RC modes, except CQP. */
+#define VA_RC_MB                        0x00000080
+
+/**@}*/
+
+/** @name Attribute values for VAConfigAttribDecSliceMode */
+/**@{*/
+/** \brief Driver supports normal mode for slice decoding */
+#define VA_DEC_SLICE_MODE_NORMAL       0x00000001
+/** \brief Driver supports base mode for slice decoding */
+#define VA_DEC_SLICE_MODE_BASE         0x00000002
 /**@}*/
 
 /** @name Attribute values for VAConfigAttribEncPackedHeaders */
@@ -510,6 +612,81 @@ typedef union _VAConfigAttribValEncJPEG {
     unsigned int value;
 } VAConfigAttribValEncJPEG;
 
+/** \brief Attribute value for VAConfigAttribEncROI */
+typedef union _VAConfigAttribValEncROI {
+    struct {
+        /** \brief The number of ROI regions supported, 0 if ROI is not supported. */
+        unsigned int num_roi_regions           : 8;
+        /**
+         * \brief A flag indicates whether ROI priority is supported
+         *
+         * \ref roi_rc_priority_support equal to 1 specifies the underlying driver supports
+         * ROI priority when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value
+         * in #VAEncROI to set ROI priority. \ref roi_rc_priority_support equal to 0 specifies
+         * the underlying driver doesn't support ROI priority.
+         *
+         * User should ignore \ref roi_rc_priority_support when VAConfigAttribRateControl == VA_RC_CQP
+         * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP.
+         */
+        unsigned int roi_rc_priority_support   : 1;
+        /**
+         * \brief A flag indicates whether ROI delta QP is supported
+         *
+         * \ref roi_rc_qp_delat_support equal to 1 specifies the underlying driver supports
+         * ROI delta QP when VAConfigAttribRateControl != VA_RC_CQP, user can use \c roi_value
+         * in #VAEncROI to set ROI delta QP. \ref roi_rc_qp_delat_support equal to 0 specifies
+         * the underlying driver doesn't support ROI delta QP.
+         *
+         * User should ignore \ref roi_rc_qp_delat_support when VAConfigAttribRateControl == VA_RC_CQP
+         * because ROI delta QP is always required when VAConfigAttribRateControl == VA_RC_CQP.
+         */
+        unsigned int roi_rc_qp_delat_support    : 1;
+        unsigned int reserved                   : 22;
+     } bits;
+     unsigned int value;
+} VAConfigAttribValEncROI;
+
+/** \brief Attribute value for VAConfigAttribEncRateControlExt */
+typedef union _VAConfigAttribValEncRateControlExt {
+    struct {
+        /**
+         * \brief The maximum number of temporal layers minus 1
+         *
+         * \ref max_num_temporal_layers_minus1 plus 1 specifies the maximum number of temporal
+         * layers that supported by the underlying driver. \ref max_num_temporal_layers_minus1
+         * equal to 0 implies the underlying driver doesn't support encoding with temporal layer.
+         */
+        unsigned int max_num_temporal_layers_minus1      : 8;
+
+        /**
+         * /brief support temporal layer bit-rate control flag
+         *
+         * \ref temporal_layer_bitrate_control_flag equal to 1 specifies the underlying driver
+         * can support bit-rate control per temporal layer when (#VAConfigAttribRateControl == #VA_RC_CBR ||
+         * #VAConfigAttribRateControl == #VA_RC_VBR).
+         *
+         * The underlying driver must set \ref temporal_layer_bitrate_control_flag to 0 when
+         * \c max_num_temporal_layers_minus1 is equal to 0
+         *
+         * To use bit-rate control per temporal layer, an application must send the right layer
+         * structure via #VAEncMiscParameterTemporalLayerStructure at the beginning of a coded sequence
+         * and then followed by #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate structures
+         * for each layer, using the \c temporal_id field as the layer identifier. Otherwise
+         * the driver doesn't use bitrate control per temporal layer if an application doesn't send the
+         * layer structure via #VAEncMiscParameterTemporalLayerStructure to the driver. The driver returns
+         * VA_STATUS_ERROR_INVALID_PARAMETER if an application sends a wrong layer structure or doesn't send
+         * #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate for each layer.
+         *
+         * The driver will ignore #VAEncMiscParameterTemporalLayerStructure and the \c temporal_id field
+         * in #VAEncMiscParameterRateControl and #VAEncMiscParameterFrameRate if
+         * \ref temporal_layer_bitrate_control_flag is equal to 0 or #VAConfigAttribRateControl == #VA_RC_CQP
+         */
+        unsigned int temporal_layer_bitrate_control_flag : 1;
+        unsigned int reserved                            : 23;
+    } bits;
+    unsigned int value;
+} VAConfigAttribValEncRateControlExt;
+
 /**
  * if an attribute is not applicable for a given
  * profile/entrypoint pair, then set the value to the following 
@@ -981,6 +1158,13 @@ typedef enum
     /** \brief Buffer type used for HRD parameters. */
     VAEncMiscParameterTypeHRD           = 5,
     VAEncMiscParameterTypeQualityLevel  = 6,
+    /** \brief Buffer type used for sending skip frame parameters to the encoder's
+      * rate control, when the user has externally skipped frames. */
+    VAEncMiscParameterTypeSkipFrame     = 9,
+    /** \brief Buffer type used for region-of-interest (ROI) parameters. */
+    VAEncMiscParameterTypeROI           = 10,
+    /** \brief Buffer type used for temporal layer structure */
+    VAEncMiscParameterTypeTemporalLayerStructure   = 12,
 } VAEncMiscParameterType;
 
 /** \brief Packed header type. */
@@ -1037,6 +1221,22 @@ typedef struct _VAEncMiscParameterBuffer
     unsigned int data[0];
 } VAEncMiscParameterBuffer;
 
+/** \brief Temporal layer Structure*/
+typedef struct _VAEncMiscParameterTemporalLayerStructure
+{
+    /** \brief The number of temporal layers */
+    unsigned int number_of_layers;
+    /** \brief The length of the array defining frame layer membership. Should be 1-32 */
+    unsigned int periodicity;
+    /**
+     * \brief The array indicating the layer id for each frame
+     *
+     * The layer id for the first frame in a coded sequence is always 0, so layer_id[] specifies the layer
+     * ids for frames starting from the 2nd frame.
+     */
+    unsigned int layer_id[32];
+} VAEncMiscParameterTemporalLayerStructure;
+
 
 /** \brief Rate control parameters */
 typedef struct _VAEncMiscParameterRateControl
@@ -1063,6 +1263,12 @@ typedef struct _VAEncMiscParameterRateControl
             unsigned int reset : 1;
             unsigned int disable_frame_skip : 1; /* Disable frame skip in rate control mode */
             unsigned int disable_bit_stuffing : 1; /* Disable bit stuffing in rate control mode */
+            unsigned int mb_rate_control : 4; /* Control VA_RC_MB 0: default, 1: enable, 2: disable, other: reserved*/
+            /*
+             * The temporal layer that the rate control parameters are specified for.
+             */
+            unsigned int temporal_id : 8;
+            unsigned int reserved : 17;
         } bits;
         unsigned int value;
     } rc_flags;
@@ -1070,7 +1276,37 @@ typedef struct _VAEncMiscParameterRateControl
 
 typedef struct _VAEncMiscParameterFrameRate
 {
+    /*
+     * The framerate is specified as a number of frames per second, as a
+     * fraction.  The denominator of the fraction is given in the top half
+     * (the high two bytes) of the framerate field, and the numerator is
+     * given in the bottom half (the low two bytes).
+     *
+     * That is:
+     * denominator = framerate >> 16 & 0xffff;
+     * numerator   = framerate & 0xffff;
+     * fps         = numerator / denominator;
+     *
+     * For example, if framerate is set to (100 << 16 | 750), this is
+     * 750 / 100, hence 7.5fps.
+     *
+     * If the denominator is zero (the high two bytes are both zero) then
+     * it takes the value one instead, so the framerate is just the integer
+     * in the low 2 bytes.
+     */
     unsigned int framerate;
+    union
+    {
+        struct
+        {
+            /*
+             * The temporal id the framerate parameters are specified for.
+             */
+            unsigned int temporal_id : 8;
+            unsigned int reserved : 24;
+         } bits;
+         unsigned int value;
+     } framerate_flags;
 } VAEncMiscParameterFrameRate;
 
 /**
@@ -1130,7 +1366,101 @@ typedef struct _VAEncMiscParameterBufferQualityLevel {
     unsigned int                quality_level;
 } VAEncMiscParameterBufferQualityLevel;
 
-/* 
+/**
+ * \brief Encoding skip frame.
+ *
+ * The application may choose to skip frames externally to the encoder (e.g. drop completely or 
+ * code as all skip's). For rate control purposes the encoder will need to know the size and number 
+ * of skipped frames.  Skip frame(s) indicated through this structure is applicable only to the 
+ * current frame.  It is allowed for the application to still send in packed headers for the driver to 
+ * pack, although no frame will be encoded (e.g. for HW to encrypt the frame).  
+ */
+typedef struct _VAEncMiscParameterSkipFrame {
+    /** \brief Indicates skip frames as below.
+      * 0: Encode as normal, no skip.
+      * 1: One or more frames were skipped prior to the current frame, encode the current frame as normal.  
+      * 2: The current frame is to be skipped, do not encode it but pack/encrypt the packed header contents
+      *    (all except VAEncPackedHeaderSlice) which could contain actual frame contents (e.g. pack the frame 
+      *    in VAEncPackedHeaderPicture).  */
+    unsigned char               skip_frame_flag;
+    /** \brief The number of frames skipped prior to the current frame.  Valid when skip_frame_flag = 1. */
+    unsigned char               num_skip_frames;
+    /** \brief When skip_frame_flag = 1, the size of the skipped frames in bits.   When skip_frame_flag = 2, 
+      * the size of the current skipped frame that is to be packed/encrypted in bits. */
+    unsigned int                size_skip_frames;
+} VAEncMiscParameterSkipFrame;
+
+/**
+ * \brief Encoding region-of-interest (ROI).
+ *
+ * The encoding ROI can be set through VAEncMiscParameterBufferROI, if the implementation
+ * supports ROI input. The ROI set through this structure is applicable only to the
+ * current frame or field, so must be sent every frame or field to be applied.  The number of
+ * supported ROIs can be queried through the VAConfigAttribEncROI.  The encoder will use the
+ * ROI information to adjust the QP values of the MB's that fall within the ROIs.
+ */
+typedef struct _VAEncROI
+{
+        /** \brief Defines the ROI boundary in pixels, the driver will map it to appropriate
+         *  codec coding units.  It is relative to frame coordinates for the frame case and
+         *  to field coordinates for the field case. */
+        VARectangle     roi_rectangle;
+        /**
+         * \brief ROI value
+         *
+         * \ref roi_value specifies ROI delta QP or ROI priority.
+         * --  ROI delta QP is the value that will be added on top of the frame level QP.
+         * --  ROI priority specifies the priority of a region, it can be positive (more important)
+         * or negative (less important) values and is compared with non-ROI region (taken as value 0),
+         * E.g. ROI region with \ref roi_value -3 is less important than the non-ROI region (\ref roi_value
+         * implied to be 0) which is less important than ROI region with roi_value +2. For overlapping
+         * regions, the roi_value that is first in the ROI array will have priority.
+         *
+         * \ref roi_value always specifes ROI delta QP when VAConfigAttribRateControl == VA_RC_CQP, no matter
+         * the value of \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI.
+         *
+         * \ref roi_value depends on \c roi_value_is_qp_delta in #VAEncMiscParameterBufferROI when
+         * VAConfigAttribRateControl != VA_RC_CQP. \ref roi_value specifies ROI_delta QP if \c roi_value_is_qp_delta
+         * in VAEncMiscParameterBufferROI is 1, otherwise \ref roi_value specifies ROI priority.
+         */
+        char            roi_value;
+} VAEncROI;
+
+typedef struct _VAEncMiscParameterBufferROI {
+    /** \brief Number of ROIs being sent.*/
+    unsigned int        num_roi;
+
+    /** \brief Valid when VAConfigAttribRateControl != VA_RC_CQP, then the encoder's
+     *  rate control will determine actual delta QPs.  Specifies the max/min allowed delta
+     *  QPs. */
+    char                max_delta_qp;
+    char                min_delta_qp;
+
+   /** \brief Pointer to a VAEncROI array with num_roi elements.  It is relative to frame
+     *  coordinates for the frame case and to field coordinates for the field case.*/
+    VAEncROI            *roi;
+    union {
+        struct {
+            /**
+             * \brief An indication for roi value.
+             *
+             * \ref roi_value_is_qp_delta equal to 1 indicates \c roi_value in #VAEncROI should
+             * be used as ROI delta QP. \ref roi_value_is_qp_delta equal to 0 indicates \c roi_value
+             * in #VAEncROI should be used as ROI priority.
+             *
+             * \ref roi_value_is_qp_delta is only available when VAConfigAttribRateControl != VA_RC_CQP,
+             * the setting must comply with \c roi_rc_priority_support and \c roi_rc_qp_delat_support in
+             * #VAConfigAttribValEncROI. The underlying driver should ignore this field
+             * when VAConfigAttribRateControl == VA_RC_CQP.
+             */
+            uint32_t  roi_value_is_qp_delta    : 1;
+            uint32_t  reserved                 : 31;
+        } bits;
+        uint32_t value;
+    } roi_flags;
+} VAEncMiscParameterBufferROI;
+
+/**
  * There will be cases where the bitstream buffer will not have enough room to hold
  * the data for the entire slice, and the following flags will be used in the slice
  * parameter to signal to the server for the possible cases.
@@ -2214,6 +2544,21 @@ VAStatus vaQuerySurfaceError(
 #define VA_FOURCC_RGBP          0x50424752
 #define VA_FOURCC_BGRP          0x50524742
 #define VA_FOURCC_411R          0x52313134 /* rotated 411P */
+/**
+ * Planar YUV 4:2:2.
+ * 8-bit Y plane, followed by 8-bit 2x1 subsampled V and U planes
+ */
+#define VA_FOURCC_YV16          0x36315659
+/**
+ * 10-bit and 16-bit Planar YUV 4:2:0. 
+ */
+#define VA_FOURCC_P010          0x30313050
+#define VA_FOURCC_P016          0x36313050
+
+/**
+ * 10-bit Planar YUV 420 and occupy the lower 10-bit.
+ */
+#define VA_FOURCC_I010          0x30313049
 
 /* byte order */
 #define VA_LSB_FIRST           1
@@ -2526,14 +2871,6 @@ VAStatus vaDeassociateSubpicture (
     int num_surfaces
 );
 
-typedef struct _VARectangle
-{
-    short x;
-    short y;
-    unsigned short width;
-    unsigned short height;
-} VARectangle;
-
 /**
  * Display attributes
  * Display attributes are used to control things such as contrast, hue, saturation,
@@ -2772,10 +3109,13 @@ typedef struct _VAPictureHEVC
 #include <va/va_dec_hevc.h>
 #include <va/va_dec_jpeg.h>
 #include <va/va_dec_vp8.h>
+#include <va/va_dec_vp9.h>
+#include <va/va_enc_hevc.h>
 #include <va/va_enc_h264.h>
 #include <va/va_enc_jpeg.h>
 #include <va/va_enc_mpeg2.h>
 #include <va/va_enc_vp8.h>
+#include <va/va_enc_vp9.h>
 #include <va/va_vpp.h>
 
 /**@}*/