From d05cbdbd72769d98d42a97fc8fb97fe39b22a582 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Fri, 26 Jul 2019 16:46:30 +0900 Subject: [PATCH] nvenc: Add property for AUD insertion Make AUD insertion configurable option --- sys/nvcodec/gstnvbaseenc.c | 2 +- sys/nvcodec/gstnvbaseenc.h | 2 ++ sys/nvcodec/gstnvh264enc.c | 41 +++++++++++++++++++++++++++++++++++--- sys/nvcodec/gstnvh264enc.h | 2 ++ sys/nvcodec/gstnvh265enc.c | 40 +++++++++++++++++++++++++++++++++++-- sys/nvcodec/gstnvh265enc.h | 3 +++ 6 files changed, 84 insertions(+), 6 deletions(-) diff --git a/sys/nvcodec/gstnvbaseenc.c b/sys/nvcodec/gstnvbaseenc.c index 5c2fca5380..f203e0d90d 100644 --- a/sys/nvcodec/gstnvbaseenc.c +++ b/sys/nvcodec/gstnvbaseenc.c @@ -2157,7 +2157,7 @@ gst_nv_base_enc_flush (GstVideoEncoder * enc) } #endif -static void +void gst_nv_base_enc_schedule_reconfig (GstNvBaseEnc * nvenc) { g_atomic_int_set (&nvenc->reconfig, TRUE); diff --git a/sys/nvcodec/gstnvbaseenc.h b/sys/nvcodec/gstnvbaseenc.h index b03d504c7b..1e9d36551c 100644 --- a/sys/nvcodec/gstnvbaseenc.h +++ b/sys/nvcodec/gstnvbaseenc.h @@ -131,5 +131,7 @@ GType gst_nv_base_enc_get_type (void); GType gst_nv_base_enc_register (const char * codec, guint device_id); +void gst_nv_base_enc_schedule_reconfig (GstNvBaseEnc * nvenc); + #endif /* __GST_NV_BASE_ENC_H_INCLUDED__ */ diff --git a/sys/nvcodec/gstnvh264enc.c b/sys/nvcodec/gstnvh264enc.c index 4a900c66d7..b63442b5bd 100644 --- a/sys/nvcodec/gstnvh264enc.c +++ b/sys/nvcodec/gstnvh264enc.c @@ -39,6 +39,14 @@ GST_DEBUG_CATEGORY_STATIC (gst_nv_h264_enc_debug); static GstElementClass *parent_class = NULL; +enum +{ + PROP_0, + PROP_AUD, +}; + +#define DEFAULT_AUD TRUE + static gboolean gst_nv_h264_enc_open (GstVideoEncoder * enc); static gboolean gst_nv_h264_enc_close (GstVideoEncoder * enc); static gboolean gst_nv_h264_enc_set_src_caps (GstNvBaseEnc * nvenc, @@ -77,6 +85,12 @@ gst_nv_h264_enc_class_init (GstNvH264EncClass * klass, gpointer data) nvenc_class->set_src_caps = gst_nv_h264_enc_set_src_caps; nvenc_class->set_pic_params = gst_nv_h264_enc_set_pic_params; + g_object_class_install_property (gobject_class, PROP_AUD, + g_param_spec_boolean ("aud", "AUD", + "Use AU (Access Unit) delimiter", DEFAULT_AUD, + G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | + G_PARAM_STATIC_STRINGS)); + if (cdata->is_default) long_name = g_strdup ("NVENC H.264 Video Encoder"); else @@ -109,6 +123,7 @@ gst_nv_h264_enc_class_init (GstNvH264EncClass * klass, gpointer data) static void gst_nv_h264_enc_init (GstNvH264Enc * nvenc) { + nvenc->aud = DEFAULT_AUD; } static void @@ -343,9 +358,7 @@ gst_nv_h264_enc_set_encoder_config (GstNvBaseEnc * nvenc, } h264_config->idrPeriod = config->gopLength; - - /* FIXME: make property */ - h264_config->outputAUD = 1; + h264_config->outputAUD = h264enc->aud; vui->videoSignalTypePresentFlag = 1; /* NOTE: vui::video_format represents the video format before @@ -386,18 +399,40 @@ static void gst_nv_h264_enc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { + GstNvH264Enc *self = (GstNvH264Enc *) object; + gboolean reconfig = FALSE; + switch (prop_id) { + case PROP_AUD: + { + gboolean aud; + + aud = g_value_get_boolean (value); + if (aud != self->aud) { + self->aud = aud; + reconfig = TRUE; + } + break; + } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } + + if (reconfig) + gst_nv_base_enc_schedule_reconfig (GST_NV_BASE_ENC (self)); } static void gst_nv_h264_enc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { + GstNvH264Enc *self = (GstNvH264Enc *) object; + switch (prop_id) { + case PROP_AUD: + g_value_set_boolean (value, self->aud); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/sys/nvcodec/gstnvh264enc.h b/sys/nvcodec/gstnvh264enc.h index c7722e0fbb..a6ab4e4a1c 100644 --- a/sys/nvcodec/gstnvh264enc.h +++ b/sys/nvcodec/gstnvh264enc.h @@ -24,6 +24,8 @@ typedef struct { GstNvBaseEnc base_nvenc; + /* properties */ + gboolean aud; } GstNvH264Enc; typedef struct { diff --git a/sys/nvcodec/gstnvh265enc.c b/sys/nvcodec/gstnvh265enc.c index 0779a182c6..fc4a506fb5 100644 --- a/sys/nvcodec/gstnvh265enc.c +++ b/sys/nvcodec/gstnvh265enc.c @@ -41,6 +41,14 @@ GST_DEBUG_CATEGORY_STATIC (gst_nv_h265_enc_debug); static GstElementClass *parent_class = NULL; +enum +{ + PROP_0, + PROP_AUD, +}; + +#define DEFAULT_AUD TRUE + static gboolean gst_nv_h265_enc_open (GstVideoEncoder * enc); static gboolean gst_nv_h265_enc_close (GstVideoEncoder * enc); static gboolean gst_nv_h265_enc_stop (GstVideoEncoder * enc); @@ -81,6 +89,12 @@ gst_nv_h265_enc_class_init (GstNvH265EncClass * klass, gpointer data) nvenc_class->set_src_caps = gst_nv_h265_enc_set_src_caps; nvenc_class->set_pic_params = gst_nv_h265_enc_set_pic_params; + g_object_class_install_property (gobject_class, PROP_AUD, + g_param_spec_boolean ("aud", "AUD", + "Use AU (Access Unit) delimiter", DEFAULT_AUD, + G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING | + G_PARAM_STATIC_STRINGS)); + if (cdata->is_default) long_name = g_strdup ("NVENC HEVC Video Encoder"); else @@ -113,6 +127,7 @@ gst_nv_h265_enc_class_init (GstNvH265EncClass * klass, gpointer data) static void gst_nv_h265_enc_init (GstNvH265Enc * nvenc) { + nvenc->aud = DEFAULT_AUD; } static void @@ -449,8 +464,7 @@ gst_nv_h265_enc_set_encoder_config (GstNvBaseEnc * nvenc, config->encodeCodecConfig.hevcConfig.pixelBitDepthMinus8 = 2; } - /* FIXME: make property */ - hevc_config->outputAUD = 1; + hevc_config->outputAUD = h265enc->aud; vui->videoSignalTypePresentFlag = 1; /* NOTE: vui::video_format represents the video format before @@ -540,18 +554,40 @@ static void gst_nv_h265_enc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { + GstNvH265Enc *self = (GstNvH265Enc *) object; + gboolean reconfig = FALSE; + switch (prop_id) { + case PROP_AUD: + { + gboolean aud; + + aud = g_value_get_boolean (value); + if (aud != self->aud) { + self->aud = aud; + reconfig = TRUE; + } + break; + } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } + + if (reconfig) + gst_nv_base_enc_schedule_reconfig (GST_NV_BASE_ENC (self)); } static void gst_nv_h265_enc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { + GstNvH265Enc *self = (GstNvH265Enc *) object; + switch (prop_id) { + case PROP_AUD: + g_value_set_boolean (value, self->aud); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/sys/nvcodec/gstnvh265enc.h b/sys/nvcodec/gstnvh265enc.h index bb8dbeb8f6..22daa3f87a 100644 --- a/sys/nvcodec/gstnvh265enc.h +++ b/sys/nvcodec/gstnvh265enc.h @@ -28,6 +28,9 @@ typedef struct { NV_ENC_SEI_PAYLOAD *sei_payload; guint num_sei_payload; + + /* properties */ + gboolean aud; } GstNvH265Enc; typedef struct {