mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-30 12:10:37 +00:00
vaapiencode: move common properties to base class.
Move "rate-control" mode and "bitrate" properties to the GstVaapiEncode base class. The actual range of supported rate control modes is currently implemented as a plug-in element hook. This ought to be determined from the GstVaapiEncoder object instead, i.e. from libgstvaapi.
This commit is contained in:
parent
1a4b3c3b22
commit
d759fe34e6
6 changed files with 104 additions and 80 deletions
|
@ -20,6 +20,7 @@
|
|||
*/
|
||||
|
||||
#include "gst/vaapi/sysdeps.h"
|
||||
#include <gst/vaapi/gstvaapivalue.h>
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include <gst/vaapi/gstvaapiencoder_priv.h>
|
||||
#include <gst/vaapi/gstvaapiencoder_objects.h>
|
||||
|
@ -109,6 +110,13 @@ G_DEFINE_TYPE_WITH_CODE (GstVaapiEncode,
|
|||
#endif
|
||||
)
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_RATE_CONTROL,
|
||||
PROP_BITRATE,
|
||||
};
|
||||
|
||||
static inline gboolean
|
||||
ensure_display (GstVaapiEncode * encode)
|
||||
{
|
||||
|
@ -858,6 +866,60 @@ error_no_caps:
|
|||
}
|
||||
#endif
|
||||
|
||||
static inline gboolean
|
||||
check_ratecontrol (GstVaapiEncode * encode, GstVaapiRateControl rate_control)
|
||||
{
|
||||
GstVaapiEncodeClass *const klass = GST_VAAPIENCODE_GET_CLASS (encode);
|
||||
|
||||
return !klass->check_ratecontrol || klass->check_ratecontrol (encode,
|
||||
rate_control);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapiencode_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
{
|
||||
GstVaapiRateControl rate_control = g_value_get_enum (value);
|
||||
if (check_ratecontrol (encode, rate_control)) {
|
||||
encode->rate_control = rate_control;
|
||||
} else {
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROP_BITRATE:
|
||||
encode->bitrate = g_value_get_uint (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapiencode_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
g_value_set_enum (value, encode->rate_control);
|
||||
break;
|
||||
case PROP_BITRATE:
|
||||
g_value_set_uint (value, encode->bitrate);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapiencode_finalize (GObject * object)
|
||||
{
|
||||
|
@ -901,6 +963,8 @@ gst_vaapiencode_class_init (GstVaapiEncodeClass * klass)
|
|||
GST_PLUGIN_NAME, 0, GST_PLUGIN_DESC);
|
||||
|
||||
object_class->finalize = gst_vaapiencode_finalize;
|
||||
object_class->set_property = gst_vaapiencode_set_property;
|
||||
object_class->get_property = gst_vaapiencode_get_property;
|
||||
|
||||
#if GST_CHECK_VERSION(1,1,0)
|
||||
element_class->set_context = GST_DEBUG_FUNCPTR (gst_vaapiencode_set_context);
|
||||
|
@ -923,4 +987,20 @@ gst_vaapiencode_class_init (GstVaapiEncodeClass * klass)
|
|||
|
||||
/* Registering debug symbols for function pointers */
|
||||
GST_DEBUG_REGISTER_FUNCPTR (gst_vaapiencode_query);
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_RATE_CONTROL,
|
||||
g_param_spec_enum ("rate-control",
|
||||
"Rate Control",
|
||||
"Rate control mode",
|
||||
GST_VAAPI_TYPE_RATE_CONTROL,
|
||||
GST_VAAPI_RATECONTROL_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_BITRATE,
|
||||
g_param_spec_uint ("bitrate",
|
||||
"Bitrate (kbps)",
|
||||
"The desired bitrate expressed in kbps (0: auto-calculate)",
|
||||
0, 100 * 1024, 0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
|
|
@ -71,6 +71,9 @@ struct _GstVaapiEncode
|
|||
#endif
|
||||
guint video_buffer_size;
|
||||
|
||||
GstVaapiRateControl rate_control;
|
||||
guint32 bitrate; /* kbps */
|
||||
|
||||
guint32 is_running:1;
|
||||
guint32 out_caps_done:1;
|
||||
};
|
||||
|
@ -80,6 +83,8 @@ struct _GstVaapiEncodeClass
|
|||
/*< private >*/
|
||||
GstVideoEncoderClass parent_class;
|
||||
|
||||
gboolean (*check_ratecontrol) (GstVaapiEncode * encode,
|
||||
GstVaapiRateControl rate_control);
|
||||
GstVaapiEncoder * (*create_encoder) (GstVaapiEncode * encode,
|
||||
GstVaapiDisplay * display);
|
||||
GstFlowReturn (*allocate_buffer) (GstVaapiEncode * encode,
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
#include "gst/vaapi/sysdeps.h"
|
||||
#include <gst/vaapi/gstvaapivalue.h>
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include <gst/vaapi/gstvaapiencoder_h264.h>
|
||||
#include "gst/vaapi/gstvaapiencoder_h264_priv.h"
|
||||
|
@ -76,8 +75,6 @@ G_DEFINE_TYPE (GstVaapiEncodeH264, gst_vaapiencode_h264, GST_TYPE_VAAPIENCODE)
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_RATE_CONTROL,
|
||||
PROP_BITRATE,
|
||||
PROP_KEY_PERIOD,
|
||||
PROP_MAX_BFRAMES,
|
||||
PROP_INIT_QP,
|
||||
|
@ -103,12 +100,6 @@ gst_vaapiencode_h264_set_property (GObject * object,
|
|||
GstVaapiEncodeH264 *const encode = GST_VAAPIENCODE_H264_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
encode->rate_control = g_value_get_enum (value);
|
||||
break;
|
||||
case PROP_BITRATE:
|
||||
encode->bitrate = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_KEY_PERIOD:
|
||||
encode->intra_period = g_value_get_uint (value);
|
||||
break;
|
||||
|
@ -137,12 +128,6 @@ gst_vaapiencode_h264_get_property (GObject * object,
|
|||
GstVaapiEncodeH264 *const encode = GST_VAAPIENCODE_H264_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
g_value_set_enum (value, encode->rate_control);
|
||||
break;
|
||||
case PROP_BITRATE:
|
||||
g_value_set_uint (value, encode->bitrate);
|
||||
break;
|
||||
case PROP_KEY_PERIOD:
|
||||
g_value_set_uint (value, encode->intra_period);
|
||||
break;
|
||||
|
@ -169,6 +154,7 @@ gst_vaapiencode_h264_create_encoder (GstVaapiEncode * base,
|
|||
GstVaapiDisplay * display)
|
||||
{
|
||||
GstVaapiEncodeH264 *const encode = GST_VAAPIENCODE_H264_CAST (base);
|
||||
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (base);
|
||||
GstVaapiEncoder *base_encoder;
|
||||
GstVaapiEncoderH264 *encoder;
|
||||
|
||||
|
@ -179,8 +165,8 @@ gst_vaapiencode_h264_create_encoder (GstVaapiEncode * base,
|
|||
|
||||
encoder->profile = GST_VAAPI_PROFILE_UNKNOWN;
|
||||
encoder->level = GST_VAAPI_ENCODER_H264_DEFAULT_LEVEL;
|
||||
GST_VAAPI_ENCODER_RATE_CONTROL (encoder) = encode->rate_control;
|
||||
encoder->bitrate = encode->bitrate;
|
||||
GST_VAAPI_ENCODER_RATE_CONTROL (encoder) = base_encode->rate_control;
|
||||
encoder->bitrate = base_encode->bitrate;
|
||||
encoder->intra_period = encode->intra_period;
|
||||
encoder->init_qp = encode->init_qp;
|
||||
encoder->min_qp = encode->min_qp;
|
||||
|
@ -340,22 +326,6 @@ gst_vaapiencode_h264_class_init (GstVaapiEncodeH264Class * klass)
|
|||
gst_static_pad_template_get (&gst_vaapiencode_h264_src_factory)
|
||||
);
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_RATE_CONTROL,
|
||||
g_param_spec_enum ("rate-control",
|
||||
"Rate Control",
|
||||
"Rate control mode",
|
||||
GST_VAAPI_TYPE_RATE_CONTROL,
|
||||
GST_VAAPI_RATECONTROL_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_BITRATE,
|
||||
g_param_spec_uint ("bitrate",
|
||||
"Bitrate (kbps)",
|
||||
"The desired bitrate expressed in kbps (0: auto-calculate)",
|
||||
0, 100 * 1024, 0, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_KEY_PERIOD,
|
||||
g_param_spec_uint ("key-period",
|
||||
|
|
|
@ -55,8 +55,6 @@ struct _GstVaapiEncodeH264
|
|||
|
||||
GstVaapiProfile profile;
|
||||
guint32 level;
|
||||
GstVaapiRateControl rate_control;
|
||||
guint32 bitrate; /* kbps */
|
||||
guint32 intra_period;
|
||||
guint32 init_qp;
|
||||
guint32 min_qp;
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
|
||||
#include "gst/vaapi/sysdeps.h"
|
||||
#include <gst/vaapi/gstvaapivalue.h>
|
||||
#include <gst/vaapi/gstvaapidisplay.h>
|
||||
#include <gst/vaapi/gstvaapiencoder_mpeg2.h>
|
||||
#include "gst/vaapi/gstvaapiencoder_mpeg2_priv.h"
|
||||
|
@ -77,8 +76,6 @@ G_DEFINE_TYPE (GstVaapiEncodeMpeg2, gst_vaapiencode_mpeg2, GST_TYPE_VAAPIENCODE)
|
|||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_RATE_CONTROL,
|
||||
PROP_BITRATE,
|
||||
PROP_QUANTIZER,
|
||||
PROP_KEY_PERIOD,
|
||||
PROP_MAX_BFRAMES
|
||||
|
@ -87,8 +84,9 @@ enum
|
|||
static void
|
||||
gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * mpeg2_encode)
|
||||
{
|
||||
mpeg2_encode->rate_control = GST_VAAPI_ENCODER_MPEG2_DEFAULT_RATE_CONTROL;
|
||||
mpeg2_encode->bitrate = 0;
|
||||
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (mpeg2_encode);
|
||||
|
||||
base_encode->rate_control = GST_VAAPI_ENCODER_MPEG2_DEFAULT_RATE_CONTROL;
|
||||
mpeg2_encode->quantizer = GST_VAAPI_ENCODER_MPEG2_DEFAULT_CQP;
|
||||
mpeg2_encode->intra_period = GST_VAAPI_ENCODER_MPEG2_DEFAULT_GOP_SIZE;
|
||||
mpeg2_encode->ip_period = GST_VAAPI_ENCODER_MPEG2_DEFAULT_MAX_BFRAMES;
|
||||
|
@ -107,20 +105,6 @@ gst_vaapiencode_mpeg2_set_property (GObject * object,
|
|||
GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
{
|
||||
GstVaapiRateControl rate_control = g_value_get_enum (value);
|
||||
if (rate_control == GST_VAAPI_RATECONTROL_CBR ||
|
||||
rate_control == GST_VAAPI_RATECONTROL_CQP) {
|
||||
encode->rate_control = g_value_get_enum (value);
|
||||
} else {
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PROP_BITRATE:
|
||||
encode->bitrate = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_QUANTIZER:
|
||||
encode->quantizer = g_value_get_uint (value);
|
||||
break;
|
||||
|
@ -143,12 +127,6 @@ gst_vaapiencode_mpeg2_get_property (GObject * object,
|
|||
GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_RATE_CONTROL:
|
||||
g_value_set_enum (value, encode->rate_control);
|
||||
break;
|
||||
case PROP_BITRATE:
|
||||
g_value_set_uint (value, encode->bitrate);
|
||||
break;
|
||||
case PROP_QUANTIZER:
|
||||
g_value_set_uint (value, encode->quantizer);
|
||||
break;
|
||||
|
@ -169,6 +147,7 @@ gst_vaapiencode_mpeg2_create_encoder (GstVaapiEncode * base,
|
|||
GstVaapiDisplay * display)
|
||||
{
|
||||
GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (base);
|
||||
GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (base);
|
||||
GstVaapiEncoder *base_encoder;
|
||||
GstVaapiEncoderMpeg2 *encoder;
|
||||
|
||||
|
@ -179,14 +158,23 @@ gst_vaapiencode_mpeg2_create_encoder (GstVaapiEncode * base,
|
|||
|
||||
encoder->profile = GST_VAAPI_ENCODER_MPEG2_DEFAULT_PROFILE;
|
||||
encoder->level = GST_VAAPI_ENCODER_MPEG2_DEFAULT_LEVEL;
|
||||
GST_VAAPI_ENCODER_RATE_CONTROL (encoder) = encode->rate_control;
|
||||
encoder->bitrate = encode->bitrate;
|
||||
GST_VAAPI_ENCODER_RATE_CONTROL (encoder) = base_encode->rate_control;
|
||||
encoder->bitrate = base_encode->bitrate;
|
||||
encoder->cqp = encode->quantizer;
|
||||
encoder->intra_period = encode->intra_period;
|
||||
encoder->ip_period = encode->ip_period;
|
||||
return base_encoder;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_vaapiencode_mpeg2_check_ratecontrol (GstVaapiEncode * encode,
|
||||
GstVaapiRateControl rate_control)
|
||||
{
|
||||
/* XXX: get information from GstVaapiEncoder object */
|
||||
return rate_control == GST_VAAPI_RATECONTROL_CQP ||
|
||||
rate_control == GST_VAAPI_RATECONTROL_CBR;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
|
||||
{
|
||||
|
@ -202,6 +190,7 @@ gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
|
|||
object_class->get_property = gst_vaapiencode_mpeg2_get_property;
|
||||
|
||||
encode_class->create_encoder = gst_vaapiencode_mpeg2_create_encoder;
|
||||
encode_class->check_ratecontrol = gst_vaapiencode_mpeg2_check_ratecontrol;
|
||||
|
||||
gst_element_class_set_static_metadata (element_class,
|
||||
"VA-API MPEG-2 encoder",
|
||||
|
@ -218,22 +207,6 @@ gst_vaapiencode_mpeg2_class_init (GstVaapiEncodeMpeg2Class * klass)
|
|||
gst_static_pad_template_get (&gst_vaapiencode_mpeg2_src_factory)
|
||||
);
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_RATE_CONTROL,
|
||||
g_param_spec_enum ("rate-control",
|
||||
"Rate Control",
|
||||
"Rate control mode (CQP or CBR only)",
|
||||
GST_VAAPI_TYPE_RATE_CONTROL,
|
||||
GST_VAAPI_RATECONTROL_NONE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_BITRATE,
|
||||
g_param_spec_uint ("bitrate",
|
||||
"Bitrate (kbps)",
|
||||
"The desired bitrate expressed in kbps (0: auto-calculate)",
|
||||
0, GST_VAAPI_ENCODER_MPEG2_MAX_BITRATE, 0, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_QUANTIZER,
|
||||
g_param_spec_uint ("quantizer",
|
||||
|
|
|
@ -53,8 +53,6 @@ struct _GstVaapiEncodeMpeg2
|
|||
/*< private >*/
|
||||
GstVaapiEncode parent_instance;
|
||||
|
||||
GstVaapiRateControl rate_control;
|
||||
guint32 bitrate; /* kbps */
|
||||
guint32 quantizer;
|
||||
guint32 intra_period;
|
||||
guint32 ip_period;
|
||||
|
|
Loading…
Reference in a new issue