1 /* GStreamer Intel MSDK plugin 2 * Copyright (c) 2016, Oblong Industries, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 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. 14 * 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. 18 * 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. 30 */ 31 32 #ifndef __GST_MSDKENC_H__ 33 #define __GST_MSDKENC_H__ 34 35 #include <gst/gst.h> 36 #include <gst/video/gstvideoencoder.h> 37 #include "msdk.h" 38 #include "msdk-enums.h" 39 #include "gstmsdkcontext.h" 40 41 G_BEGIN_DECLS 42 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)) 55 56 #define MAX_EXTRA_PARAMS 8 57 58 typedef struct _GstMsdkEnc GstMsdkEnc; 59 typedef struct _GstMsdkEncClass GstMsdkEncClass; 60 typedef struct _MsdkEncTask MsdkEncTask; 61 62 enum 63 { 64 GST_MSDKENC_PROP_0, 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, 75 GST_MSDKENC_PROP_QPI, 76 GST_MSDKENC_PROP_QPP, 77 GST_MSDKENC_PROP_QPB, 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_MAX, 87 }; 88 89 struct _GstMsdkEnc 90 { 91 GstVideoEncoder element; 92 93 /* input description */ 94 GstVideoCodecState *input_state; 95 96 /* List of frame/buffer mapping structs for 97 * pending frames */ 98 GList *pending_frames; 99 100 /* MFX context */ 101 GstMsdkContext *context; 102 mfxVideoParam param; 103 guint num_surfaces; 104 guint num_tasks; 105 MsdkEncTask *tasks; 106 guint next_task; 107 108 gboolean has_vpp; 109 mfxVideoParam vpp_param; 110 guint num_vpp_surfaces; 111 /* Input interfaces, output above */ 112 mfxFrameAllocResponse vpp_alloc_resp; 113 mfxFrameAllocResponse alloc_resp; 114 115 mfxExtBuffer *extra_params[MAX_EXTRA_PARAMS]; 116 guint num_extra_params; 117 118 /* Additional encoder coding options */ 119 mfxExtCodingOption2 option2; 120 mfxExtCodingOption3 option3; 121 gboolean enable_extopt3; 122 123 /* parameters for per-frame based encoding control */ 124 mfxEncodeCtrl enc_cntrl; 125 126 GstBufferPool *msdk_pool; 127 GstBufferPool *msdk_converted_pool; 128 GstVideoInfo aligned_info; 129 gboolean use_video_memory; 130 gboolean use_dmabuf; 131 gboolean initialized; 132 133 /* element properties */ 134 gboolean hardware; 135 136 guint async_depth; 137 guint target_usage; 138 guint rate_control; 139 guint bitrate; 140 guint max_frame_size; 141 guint max_vbv_bitrate; 142 guint accuracy; 143 guint convergence; 144 guint lookahead_depth; 145 guint qpi; 146 guint qpp; 147 guint qpb; 148 guint gop_size; 149 guint ref_frames; 150 guint i_frames; 151 guint b_frames; 152 guint num_slices; 153 gint16 mbbrc; 154 gint16 adaptive_i; 155 gint16 adaptive_b; 156 157 gboolean reconfig; 158 }; 159 160 struct _GstMsdkEncClass 161 { 162 GstVideoEncoderClass parent_class; 163 164 gboolean (*set_format) (GstMsdkEnc * encoder); 165 gboolean (*configure) (GstMsdkEnc * encoder); 166 GstCaps *(*set_src_caps) (GstMsdkEnc * encoder); 167 }; 168 169 struct _MsdkEncTask 170 { 171 mfxSyncPoint sync_point; 172 mfxBitstream output_bitstream; 173 }; 174 175 GType gst_msdkenc_get_type (void); 176 177 void gst_msdkenc_add_extra_param (GstMsdkEnc * thiz, mfxExtBuffer * param); 178 179 void 180 gst_msdkenc_install_common_properties (GstMsdkEncClass *encoder_class); 181 182 gboolean 183 gst_msdkenc_set_common_property (GObject * object, guint prop_id, 184 const GValue * value, GParamSpec * pspec); 185 gboolean 186 gst_msdkenc_get_common_property (GObject * object, guint prop_id, 187 GValue * value, GParamSpec * pspec); 188 void 189 gst_msdkenc_ensure_extended_coding_options (GstMsdkEnc * thiz); 190 191 G_END_DECLS 192 193 #endif /* __GST_MSDKENC_H__ */ 194