1 /* GStreamer NVENC plugin
2 * Copyright (C) 2015 Centricular Ltd
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef __GST_NV_BASE_ENC_H_INCLUDED__
21 #define __GST_NV_BASE_ENC_H_INCLUDED__
25 #include <gst/video/gstvideoencoder.h>
26 #include "gstcudacontext.h"
28 #define GST_TYPE_NV_BASE_ENC \
29 (gst_nv_base_enc_get_type())
30 #define GST_NV_BASE_ENC(obj) \
31 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NV_BASE_ENC,GstNvBaseEnc))
32 #define GST_NV_BASE_ENC_CLASS(klass) \
33 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NV_BASE_ENC,GstNvBaseEncClass))
34 #define GST_NV_BASE_ENC_GET_CLASS(obj) \
35 (G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_NV_BASE_ENC,GstNvBaseEncClass))
36 #define GST_IS_NV_BASE_ENC(obj) \
37 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NV_BASE_ENC))
38 #define GST_IS_NV_BASE_ENC_CLASS(obj) \
39 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NV_BASE_ENC))
42 GST_NV_PRESET_DEFAULT,
45 /* FIXME: problematic GST_NV_PRESET_BD, */
46 GST_NV_PRESET_LOW_LATENCY_DEFAULT,
47 GST_NV_PRESET_LOW_LATENCY_HQ,
48 GST_NV_PRESET_LOW_LATENCY_HP,
49 GST_NV_PRESET_LOSSLESS_DEFAULT,
50 GST_NV_PRESET_LOSSLESS_HP,
54 GST_NV_RC_MODE_DEFAULT,
55 GST_NV_RC_MODE_CONSTQP,
58 GST_NV_RC_MODE_VBR_MINQP,
59 GST_NV_RC_MODE_CBR_LOWDELAY_HQ,
60 GST_NV_RC_MODE_CBR_HQ,
61 GST_NV_RC_MODE_VBR_HQ,
66 GST_NVENC_MEM_TYPE_SYSTEM = 0,
67 GST_NVENC_MEM_TYPE_GL,
68 GST_NVENC_MEM_TYPE_CUDA,
69 /* FIXME: add support D3D11 memory */
73 gboolean weighted_prediction;
75 gboolean custom_vbv_bufsize;
88 GstVideoEncoder video_encoder;
91 GstNvPreset preset_enum;
93 GstNvRCMode rate_control_mode;
95 GstNvEncQP qp_min_detail;
97 GstNvEncQP qp_max_detail;
99 GstNvEncQP qp_const_detail;
106 /* zero reorder delay (consistent naming with x264) */
107 gboolean zerolatency;
109 gdouble const_quality;
112 GstCudaContext * cuda_ctx;
113 CUstream cuda_stream;
115 NV_ENC_INITIALIZE_PARAMS init_params;
116 NV_ENC_CONFIG config;
118 /* the supported input formats */
119 GValue * input_formats; /* OBJECT LOCK */
121 GstVideoCodecState *input_state;
122 volatile gint reconfig; /* ATOMIC */
123 GstNvEncMemType mem_type;
125 /* array of allocated input/output buffers (GstNvEncFrameState),
126 * and hold the ownership of the GstNvEncFrameState. */
129 /* (GstNvEncFrameState) available empty items which could be submitted
131 GAsyncQueue *available_queue;
133 /* (GstNvEncFrameState) submitted to encoder but not ready to finish
134 * (due to bframe or lookhead operation) */
135 GAsyncQueue *pending_queue;
137 /* (GstNvEncFrameState) submitted to encoder and ready to finish.
138 * finished items will go back to available item queue */
139 GAsyncQueue *bitstream_queue;
141 /* we spawn a thread that does the (blocking) waits for output buffers
142 * to become available, so we can continue to feed data to the encoder
144 GThread *bitstream_thread;
146 GstObject *display; /* GstGLDisplay */
147 GstObject *other_context; /* GstGLContext */
148 GstObject *gl_context; /* GstGLContext */
150 GstVideoInfo input_info; /* buffer configuration for buffers sent to NVENC */
152 GstFlowReturn last_flow; /* ATOMIC */
154 /* the first frame when bframe was enabled */
155 GstVideoCodecFrame *first_frame;
156 GstClockTime dts_offset;
159 /* device capability dependent properties, set by subclass */
160 gboolean weighted_pred;
161 guint vbv_buffersize;
163 gboolean temporal_aq;
169 GstVideoEncoderClass video_encoder_class;
172 guint cuda_device_id;
173 GstNvEncDeviceCaps device_caps;
175 gboolean (*set_src_caps) (GstNvBaseEnc * nvenc,
176 GstVideoCodecState * state);
177 gboolean (*set_pic_params) (GstNvBaseEnc * nvenc,
178 GstVideoCodecFrame * frame,
179 NV_ENC_PIC_PARAMS * pic_params);
180 gboolean (*set_encoder_config) (GstNvBaseEnc * nvenc,
181 GstVideoCodecState * state,
182 NV_ENC_CONFIG * config);
186 GType gst_nv_base_enc_get_type (void);
188 GType gst_nv_base_enc_register (const char * codec,
190 GstNvEncDeviceCaps * device_caps);
192 void gst_nv_base_enc_schedule_reconfig (GstNvBaseEnc * nvenc);
195 #endif /* __GST_NV_BASE_ENC_H_INCLUDED__ */