2015-07-30 06:42:38 +00:00
|
|
|
/* GStreamer NVENC plugin
|
|
|
|
* Copyright (C) 2015 Centricular Ltd
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GST_NV_BASE_ENC_H_INCLUDED__
|
|
|
|
#define __GST_NV_BASE_ENC_H_INCLUDED__
|
|
|
|
|
|
|
|
#include "gstnvenc.h"
|
|
|
|
|
|
|
|
#include <gst/video/gstvideoencoder.h>
|
2019-07-25 10:33:54 +00:00
|
|
|
#include "gstcudacontext.h"
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_NV_BASE_ENC \
|
|
|
|
(gst_nv_base_enc_get_type())
|
|
|
|
#define GST_NV_BASE_ENC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_NV_BASE_ENC,GstNvBaseEnc))
|
|
|
|
#define GST_NV_BASE_ENC_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_NV_BASE_ENC,GstNvBaseEncClass))
|
|
|
|
#define GST_NV_BASE_ENC_GET_CLASS(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_NV_BASE_ENC,GstNvBaseEncClass))
|
|
|
|
#define GST_IS_NV_BASE_ENC(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_NV_BASE_ENC))
|
|
|
|
#define GST_IS_NV_BASE_ENC_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_NV_BASE_ENC))
|
|
|
|
|
2016-04-07 12:46:08 +00:00
|
|
|
typedef enum {
|
|
|
|
GST_NV_PRESET_DEFAULT,
|
|
|
|
GST_NV_PRESET_HP,
|
|
|
|
GST_NV_PRESET_HQ,
|
|
|
|
/* FIXME: problematic GST_NV_PRESET_BD, */
|
|
|
|
GST_NV_PRESET_LOW_LATENCY_DEFAULT,
|
|
|
|
GST_NV_PRESET_LOW_LATENCY_HQ,
|
|
|
|
GST_NV_PRESET_LOW_LATENCY_HP,
|
|
|
|
GST_NV_PRESET_LOSSLESS_DEFAULT,
|
|
|
|
GST_NV_PRESET_LOSSLESS_HP,
|
|
|
|
} GstNvPreset;
|
|
|
|
|
2016-04-08 04:51:44 +00:00
|
|
|
typedef enum {
|
|
|
|
GST_NV_RC_MODE_DEFAULT,
|
|
|
|
GST_NV_RC_MODE_CONSTQP,
|
|
|
|
GST_NV_RC_MODE_CBR,
|
|
|
|
GST_NV_RC_MODE_VBR,
|
|
|
|
GST_NV_RC_MODE_VBR_MINQP,
|
2019-09-03 12:33:15 +00:00
|
|
|
GST_NV_RC_MODE_CBR_LOWDELAY_HQ,
|
|
|
|
GST_NV_RC_MODE_CBR_HQ,
|
|
|
|
GST_NV_RC_MODE_VBR_HQ,
|
2016-04-08 04:51:44 +00:00
|
|
|
} GstNvRCMode;
|
|
|
|
|
2019-09-03 12:28:44 +00:00
|
|
|
typedef struct {
|
|
|
|
gboolean weighted_prediction;
|
2019-09-03 12:33:15 +00:00
|
|
|
gint rc_modes;
|
|
|
|
gboolean custom_vbv_bufsize;
|
|
|
|
gboolean lookahead;
|
|
|
|
gboolean temporal_aq;
|
2019-09-03 12:22:08 +00:00
|
|
|
gint bframes;
|
2019-09-03 12:28:44 +00:00
|
|
|
} GstNvEncDeviceCaps;
|
|
|
|
|
2019-09-03 10:46:09 +00:00
|
|
|
typedef struct {
|
|
|
|
gint qp_i;
|
|
|
|
gint qp_p;
|
|
|
|
gint qp_b;
|
|
|
|
} GstNvEncQP;
|
|
|
|
|
2015-07-30 06:42:38 +00:00
|
|
|
typedef struct {
|
|
|
|
GstVideoEncoder video_encoder;
|
|
|
|
|
|
|
|
/* properties */
|
2016-04-07 12:46:08 +00:00
|
|
|
GstNvPreset preset_enum;
|
|
|
|
GUID selected_preset;
|
2016-04-08 04:51:44 +00:00
|
|
|
GstNvRCMode rate_control_mode;
|
|
|
|
gint qp_min;
|
2019-09-03 10:46:09 +00:00
|
|
|
GstNvEncQP qp_min_detail;
|
2016-04-08 04:51:44 +00:00
|
|
|
gint qp_max;
|
2019-09-03 10:46:09 +00:00
|
|
|
GstNvEncQP qp_max_detail;
|
2016-04-08 04:51:44 +00:00
|
|
|
gint qp_const;
|
2019-09-03 10:46:09 +00:00
|
|
|
GstNvEncQP qp_const_detail;
|
2016-04-08 04:51:44 +00:00
|
|
|
guint bitrate;
|
2017-04-16 14:08:27 +00:00
|
|
|
gint gop_size;
|
2019-09-03 12:33:15 +00:00
|
|
|
guint max_bitrate;
|
|
|
|
gboolean spatial_aq;
|
|
|
|
guint aq_strength;
|
|
|
|
gboolean non_refp;
|
|
|
|
/* zero reorder delay (consistent naming with x264) */
|
|
|
|
gboolean zerolatency;
|
|
|
|
gboolean strict_gop;
|
|
|
|
gdouble const_quality;
|
|
|
|
gboolean i_adapt;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
2019-07-25 10:33:54 +00:00
|
|
|
GstCudaContext * cuda_ctx;
|
2019-08-18 13:51:18 +00:00
|
|
|
CUstream cuda_stream;
|
2015-07-30 06:42:38 +00:00
|
|
|
void * encoder;
|
2019-08-31 08:34:13 +00:00
|
|
|
NV_ENC_INITIALIZE_PARAMS init_params;
|
|
|
|
NV_ENC_CONFIG config;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
/* the supported input formats */
|
|
|
|
GValue * input_formats; /* OBJECT LOCK */
|
|
|
|
|
|
|
|
GstVideoCodecState *input_state;
|
2017-04-17 11:58:53 +00:00
|
|
|
volatile gint reconfig; /* ATOMIC */
|
2015-07-30 06:42:38 +00:00
|
|
|
gboolean gl_input;
|
|
|
|
|
2019-09-02 05:13:26 +00:00
|
|
|
/* array of allocated input/output buffers (GstNvEncFrameState),
|
|
|
|
* and hold the ownership of the GstNvEncFrameState. */
|
|
|
|
GArray *items;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
2019-09-02 05:13:26 +00:00
|
|
|
/* (GstNvEncFrameState) available empty items which could be submitted
|
|
|
|
* to encoder */
|
|
|
|
GAsyncQueue *available_queue;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
2019-09-02 05:13:26 +00:00
|
|
|
/* (GstNvEncFrameState) submitted to encoder but not ready to finish
|
|
|
|
* (due to bframe or lookhead operation) */
|
|
|
|
GAsyncQueue *pending_queue;
|
|
|
|
|
|
|
|
/* (GstNvEncFrameState) submitted to encoder and ready to finish.
|
|
|
|
* finished items will go back to available item queue */
|
|
|
|
GAsyncQueue *bitstream_queue;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
/* we spawn a thread that does the (blocking) waits for output buffers
|
|
|
|
* to become available, so we can continue to feed data to the encoder
|
|
|
|
* while we wait */
|
|
|
|
GThread *bitstream_thread;
|
|
|
|
|
2019-09-02 05:13:26 +00:00
|
|
|
GstObject *display; /* GstGLDisplay */
|
|
|
|
GstObject *other_context; /* GstGLContext */
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
GstVideoInfo input_info; /* buffer configuration for buffers sent to NVENC */
|
|
|
|
|
|
|
|
GstFlowReturn last_flow; /* ATOMIC */
|
2019-09-03 12:28:44 +00:00
|
|
|
|
2019-08-18 08:31:53 +00:00
|
|
|
/* the first frame when bframe was enabled */
|
|
|
|
GstVideoCodecFrame *first_frame;
|
|
|
|
GstClockTime dts_offset;
|
|
|
|
|
2019-09-03 12:28:44 +00:00
|
|
|
/*< protected >*/
|
|
|
|
/* device capability dependent properties, set by subclass */
|
|
|
|
gboolean weighted_pred;
|
2019-09-03 12:33:15 +00:00
|
|
|
guint vbv_buffersize;
|
|
|
|
guint rc_lookahead;
|
|
|
|
gboolean temporal_aq;
|
2019-09-03 12:22:08 +00:00
|
|
|
guint bframes;
|
|
|
|
gboolean b_adapt;
|
2015-07-30 06:42:38 +00:00
|
|
|
} GstNvBaseEnc;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GstVideoEncoderClass video_encoder_class;
|
|
|
|
|
|
|
|
GUID codec_id;
|
2019-07-09 04:31:27 +00:00
|
|
|
guint cuda_device_id;
|
2019-09-03 12:28:44 +00:00
|
|
|
GstNvEncDeviceCaps device_caps;
|
2015-07-30 06:42:38 +00:00
|
|
|
|
|
|
|
gboolean (*set_src_caps) (GstNvBaseEnc * nvenc,
|
|
|
|
GstVideoCodecState * state);
|
|
|
|
gboolean (*set_pic_params) (GstNvBaseEnc * nvenc,
|
|
|
|
GstVideoCodecFrame * frame,
|
|
|
|
NV_ENC_PIC_PARAMS * pic_params);
|
2016-04-07 13:24:47 +00:00
|
|
|
gboolean (*set_encoder_config) (GstNvBaseEnc * nvenc,
|
|
|
|
GstVideoCodecState * state,
|
|
|
|
NV_ENC_CONFIG * config);
|
2015-07-30 06:42:38 +00:00
|
|
|
} GstNvBaseEncClass;
|
|
|
|
|
|
|
|
G_GNUC_INTERNAL
|
|
|
|
GType gst_nv_base_enc_get_type (void);
|
|
|
|
|
2019-09-03 09:46:30 +00:00
|
|
|
GType gst_nv_base_enc_register (const char * codec,
|
2019-09-03 12:28:44 +00:00
|
|
|
guint device_id,
|
|
|
|
GstNvEncDeviceCaps * device_caps);
|
2019-07-09 04:31:27 +00:00
|
|
|
|
2019-07-26 07:46:30 +00:00
|
|
|
void gst_nv_base_enc_schedule_reconfig (GstNvBaseEnc * nvenc);
|
|
|
|
|
2019-07-09 04:31:27 +00:00
|
|
|
|
2015-07-30 06:42:38 +00:00
|
|
|
#endif /* __GST_NV_BASE_ENC_H_INCLUDED__ */
|