]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vaapi_encode.h
libopenh264dec: Export the decoded profile and level in AVCodecContext
[ffmpeg] / libavcodec / vaapi_encode.h
index 85f3a0c89450ddacb7a43ff8b957a5f3d7cad352..31c3790531072d157b28fabbf653e45b58081a8b 100644 (file)
@@ -35,11 +35,8 @@ enum {
     MAX_CONFIG_ATTRIBUTES  = 4,
     MAX_GLOBAL_PARAMS      = 4,
     MAX_PICTURE_REFERENCES = 2,
-    MAX_PICTURE_SLICES     = 1,
-    MAX_PARAM_BUFFERS      = 16,
     MAX_REORDER_DELAY      = 16,
     MAX_PARAM_BUFFER_SIZE  = 1024,
-    MAX_OUTPUT_BUFFER_SIZE = 1024 * 1024,
 };
 
 enum {
@@ -49,16 +46,8 @@ enum {
     PICTURE_TYPE_B   = 3,
 };
 
-enum {
-    // All encode operations are done independently.
-    ISSUE_MODE_SERIALISE_EVERYTHING = 0,
-    // Overlap as many operations as possible.
-    ISSUE_MODE_MAXIMISE_THROUGHPUT,
-    // Overlap operations only when satisfying parallel dependencies.
-    ISSUE_MODE_MINIMISE_LATENCY,
-};
-
 typedef struct VAAPIEncodeSlice {
+    int             index;
     void           *priv_data;
     void           *codec_slice_params;
 } VAAPIEncodeSlice;
@@ -82,8 +71,9 @@ typedef struct VAAPIEncodePicture {
     VASurfaceID     recon_surface;
 
     int          nb_param_buffers;
-    VABufferID      param_buffers[MAX_PARAM_BUFFERS];
+    VABufferID     *param_buffers;
 
+    AVBufferRef    *output_buffer_ref;
     VABufferID      output_buffer;
 
     void           *priv_data;
@@ -93,7 +83,7 @@ typedef struct VAAPIEncodePicture {
     struct VAAPIEncodePicture *refs[MAX_PICTURE_REFERENCES];
 
     int          nb_slices;
-    VAAPIEncodeSlice *slices[MAX_PICTURE_SLICES];
+    VAAPIEncodeSlice *slices;
 } VAAPIEncodePicture;
 
 typedef struct VAAPIEncodeContext {
@@ -102,41 +92,78 @@ typedef struct VAAPIEncodeContext {
     // Codec-specific hooks.
     const struct VAAPIEncodeType *codec;
 
+    // Encoding profile (VAProfileXXX).
+    VAProfile       va_profile;
+    // Encoding entrypoint (usually VAEntryointEncSlice).
+    VAEntrypoint    va_entrypoint;
+    // Surface colour/sampling format (usually VA_RT_FORMAT_YUV420).
+    unsigned int    va_rt_format;
+    // Rate control mode.
+    unsigned int    va_rc_mode;
+    // Supported packed headers (initially the desired set, modified
+    // later to what is actually supported).
+    unsigned int    va_packed_headers;
+
+    // The required size of surfaces.  This is probably the input
+    // size (AVCodecContext.width|height) aligned up to whatever
+    // block size is required by the codec.
+    int             surface_width;
+    int             surface_height;
+
+    // Everything above this point must be set before calling
+    // ff_vaapi_encode_init().
+
     // Codec-specific state.
     void *priv_data;
 
-    VAProfile       va_profile;
-    VAEntrypoint    va_entrypoint;
+    // Configuration attributes to use when creating va_config.
+    VAConfigAttrib  config_attributes[MAX_CONFIG_ATTRIBUTES];
+    int          nb_config_attributes;
+
     VAConfigID      va_config;
     VAContextID     va_context;
 
-    int             va_rc_mode;
-
     AVBufferRef    *device_ref;
     AVHWDeviceContext *device;
     AVVAAPIDeviceContext *hwctx;
 
+    // The hardware frame context containing the input frames.
     AVBufferRef    *input_frames_ref;
     AVHWFramesContext *input_frames;
 
-    // Input size, set from input frames.
-    int             input_width;
-    int             input_height;
-    // Aligned size, set by codec init, becomes hwframe size.
-    int             aligned_width;
-    int             aligned_height;
-
-    int          nb_recon_frames;
+    // The hardware frame context containing the reconstructed frames.
     AVBufferRef    *recon_frames_ref;
     AVHWFramesContext *recon_frames;
 
-    VAConfigAttrib  config_attributes[MAX_CONFIG_ATTRIBUTES];
-    int          nb_config_attributes;
+    // Pool of (reusable) bitstream output buffers.
+    AVBufferPool   *output_buffer_pool;
 
+    // Global parameters which will be applied at the start of the
+    // sequence (includes rate control parameters below).
     VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
     size_t          global_params_size[MAX_GLOBAL_PARAMS];
     int          nb_global_params;
 
+    // Rate control parameters.
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterRateControl rc;
+    } rc_params;
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterHRD hrd;
+    } hrd_params;
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterFrameRate fr;
+    } fr_params;
+#if VA_CHECK_VERSION(0, 36, 0)
+    struct {
+        VAEncMiscParameterBuffer misc;
+        VAEncMiscParameterBufferQualityLevel quality;
+    } quality_params;
+#endif
+
     // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
     void           *codec_sequence_params;
 
@@ -156,7 +183,15 @@ typedef struct VAAPIEncodeContext {
     // Next output order index (encode order).
     int64_t         output_order;
 
-    int             issue_mode;
+    enum {
+        // All encode operations are done independently (synchronise
+        // immediately after every operation).
+        ISSUE_MODE_SERIALISE_EVERYTHING = 0,
+        // Overlap as many operations as possible.
+        ISSUE_MODE_MAXIMISE_THROUGHPUT,
+        // Overlap operations only when satisfying parallel dependencies.
+        ISSUE_MODE_MINIMISE_LATENCY,
+    } issue_mode;
 
     // Timestamp handling.
     int64_t         first_pts;
@@ -164,11 +199,10 @@ typedef struct VAAPIEncodeContext {
     int64_t         ts_ring[MAX_REORDER_DELAY * 3];
 
     // Frame type decision.
-    int i_per_idr;
     int p_per_i;
     int b_per_p;
-    int idr_counter;
-    int i_counter;
+    int force_idr;
+    int gop_counter;
     int p_counter;
     int end_of_stream;
 
@@ -181,15 +215,20 @@ typedef struct VAAPIEncodeContext {
 
 
 typedef struct VAAPIEncodeType {
-    size_t    priv_data_size;
+    size_t priv_data_size;
 
-    int  (*init)(AVCodecContext *avctx);
-    int (*close)(AVCodecContext *avctx);
+    // Perform any extra codec-specific configuration after the
+    // codec context is initialised (set up the private data and
+    // add any necessary global parameters).
+    int (*configure)(AVCodecContext *avctx);
 
+    // The size of the parameter structures:
+    // sizeof(VAEnc{type}ParameterBuffer{codec}).
     size_t sequence_params_size;
     size_t picture_params_size;
     size_t slice_params_size;
 
+    // Fill the parameter structures.
     int  (*init_sequence_params)(AVCodecContext *avctx);
     int   (*init_picture_params)(AVCodecContext *avctx,
                                  VAAPIEncodePicture *pic);
@@ -197,10 +236,15 @@ typedef struct VAAPIEncodeType {
                                  VAAPIEncodePicture *pic,
                                  VAAPIEncodeSlice *slice);
 
+    // The type used by the packed header: this should look like
+    // VAEncPackedHeader{something}.
     int sequence_header_type;
     int picture_header_type;
     int slice_header_type;
 
+    // Write the packed header data to the provided buffer.
+    // The sequence header is also used to fill the codec extradata
+    // when the encoder is starting.
     int (*write_sequence_header)(AVCodecContext *avctx,
                                  char *data, size_t *data_len);
     int  (*write_picture_header)(AVCodecContext *avctx,
@@ -211,10 +255,18 @@ typedef struct VAAPIEncodeType {
                                  VAAPIEncodeSlice *slice,
                                  char *data, size_t *data_len);
 
+    // Fill an extra parameter structure, which will then be
+    // passed to vaRenderPicture().  Will be called repeatedly
+    // with increasing index argument until AVERROR_EOF is
+    // returned.
     int    (*write_extra_buffer)(AVCodecContext *avctx,
                                  VAAPIEncodePicture *pic,
                                  int index, int *type,
                                  char *data, size_t *data_len);
+
+    // Write an extra packed header.  Will be called repeatedly
+    // with increasing index argument until AVERROR_EOF is
+    // returned.
     int    (*write_extra_header)(AVCodecContext *avctx,
                                  VAAPIEncodePicture *pic,
                                  int index, int *type,
@@ -225,8 +277,7 @@ typedef struct VAAPIEncodeType {
 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
                      const AVFrame *input_image, int *got_packet);
 
-int ff_vaapi_encode_init(AVCodecContext *avctx,
-                         const VAAPIEncodeType *type);
+int ff_vaapi_encode_init(AVCodecContext *avctx);
 int ff_vaapi_encode_close(AVCodecContext *avctx);
 
 #endif /* AVCODEC_VAAPI_ENCODE_H */