1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2016, Oblong Industries, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef __GST_MSDKENC_H__
33 #define __GST_MSDKENC_H__
36 #include <gst/video/gstvideoencoder.h>
38 #include "msdk-enums.h"
39 #include "gstmsdkcontext.h"
43 #define GST_TYPE_MSDKENC \
44 (gst_msdkenc_get_type())
45 #define GST_MSDKENC(obj) \
46 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MSDKENC,GstMsdkEnc))
47 #define GST_MSDKENC_CLASS(klass) \
48 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MSDKENC,GstMsdkEncClass))
49 #define GST_MSDKENC_GET_CLASS(obj) \
50 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_MSDKENC,GstMsdkEncClass))
51 #define GST_IS_MSDKENC(obj) \
52 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MSDKENC))
53 #define GST_IS_MSDKENC_CLASS(klass) \
54 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MSDKENC))
56 #define MAX_EXTRA_PARAMS 8
58 typedef struct _GstMsdkEnc GstMsdkEnc;
59 typedef struct _GstMsdkEncClass GstMsdkEncClass;
60 typedef struct _MsdkEncTask MsdkEncTask;
65 GST_MSDKENC_PROP_HARDWARE,
66 GST_MSDKENC_PROP_ASYNC_DEPTH,
67 GST_MSDKENC_PROP_TARGET_USAGE,
68 GST_MSDKENC_PROP_RATE_CONTROL,
69 GST_MSDKENC_PROP_BITRATE,
70 GST_MSDKENC_PROP_MAX_FRAME_SIZE,
71 GST_MSDKENC_PROP_MAX_VBV_BITRATE,
72 GST_MSDKENC_PROP_AVBR_ACCURACY,
73 GST_MSDKENC_PROP_AVBR_CONVERGENCE,
74 GST_MSDKENC_PROP_RC_LOOKAHEAD_DEPTH,
78 GST_MSDKENC_PROP_GOP_SIZE,
79 GST_MSDKENC_PROP_REF_FRAMES,
80 GST_MSDKENC_PROP_I_FRAMES,
81 GST_MSDKENC_PROP_B_FRAMES,
82 GST_MSDKENC_PROP_NUM_SLICES,
83 GST_MSDKENC_PROP_MBBRC,
84 GST_MSDKENC_PROP_ADAPTIVE_I,
85 GST_MSDKENC_PROP_ADAPTIVE_B,
86 GST_MSDKENC_PROP_EXT_CODING_PROPS,
87 GST_MSDKENC_PROP_LOWDELAY_BRC,
88 GST_MSDKENC_PROP_MAX_FRAME_SIZE_I,
89 GST_MSDKENC_PROP_MAX_FRAME_SIZE_P,
95 GstVideoEncoder element;
97 /* input description */
98 GstVideoCodecState *input_state;
100 /* List of frame/buffer mapping structs for
102 GList *pending_frames;
105 GstMsdkContext *context;
106 GstMsdkContext *old_context;
112 /* Extra frames for encoding, set by each element,
113 * the default value is 0 */
114 guint num_extra_frames;
117 mfxVideoParam vpp_param;
118 guint num_vpp_surfaces;
119 /* Input interfaces, output above */
120 mfxFrameAllocResponse vpp_alloc_resp;
121 mfxFrameAllocResponse alloc_resp;
123 mfxExtBuffer *extra_params[MAX_EXTRA_PARAMS];
124 guint num_extra_params;
126 /* Additional encoder coding options */
127 mfxExtCodingOption2 option2;
128 mfxExtCodingOption3 option3;
129 gboolean enable_extopt3;
131 /* parameters for per-frame based encoding control */
132 mfxEncodeCtrl enc_cntrl;
134 GstBufferPool *msdk_pool;
135 GstBufferPool *msdk_converted_pool;
136 GstVideoInfo aligned_info;
137 gboolean use_video_memory;
141 gboolean initialized;
143 /* element properties */
150 guint max_frame_size;
151 guint max_vbv_bitrate;
154 guint lookahead_depth;
166 guint max_frame_size_i;
167 guint max_frame_size_p;
170 GstStructure *ext_coding_props;
177 struct _GstMsdkEncClass
179 GstVideoEncoderClass parent_class;
181 gboolean (*set_format) (GstMsdkEnc * encoder);
182 gboolean (*configure) (GstMsdkEnc * encoder);
183 GstCaps *(*set_src_caps) (GstMsdkEnc * encoder);
184 /* Return TRUE if vpp is required before encoding
185 * @info (in), input video info
186 * @out_format (out), a pointer to the output format of vpp, which is set
189 gboolean (*need_conversion) (GstMsdkEnc * encoder, GstVideoInfo * info,
190 GstVideoFormat * out_format);
192 /* Return TRUE if sub class requires a recofnig */
193 gboolean (*need_reconfig) (GstMsdkEnc * encoder, GstVideoCodecFrame * frame);
195 /* Allow sub class set extra frame parameters */
196 void (*set_extra_params) (GstMsdkEnc * encoder, GstVideoCodecFrame * frame);
204 mfxSyncPoint sync_point;
205 mfxBitstream output_bitstream;
208 GType gst_msdkenc_get_type (void);
210 void gst_msdkenc_add_extra_param (GstMsdkEnc * thiz, mfxExtBuffer * param);
213 gst_msdkenc_install_common_properties (GstMsdkEncClass *encoder_class);
216 gst_msdkenc_set_common_property (GObject * object, guint prop_id,
217 const GValue * value, GParamSpec * pspec);
219 gst_msdkenc_get_common_property (GObject * object, guint prop_id,
220 GValue * value, GParamSpec * pspec);
222 gst_msdkenc_ensure_extended_coding_options (GstMsdkEnc * thiz);
225 gst_msdkenc_get_roi_params (GstMsdkEnc * thiz,
226 GstVideoCodecFrame * frame, mfxExtEncoderROI * encoder_roi);
229 #endif /* __GST_MSDKENC_H__ */