h264encoder: add rate-control attribute
authorWind Yuan <feng.yuan@intel.com>
Wed, 14 Nov 2012 08:35:48 +0000 (16:35 +0800)
committerZhong Cong <congx.zhong@intel.com>
Tue, 5 Feb 2013 07:37:12 +0000 (15:37 +0800)
encoder create context with special rate-control config

gst-libs/gst/vaapi/gstvaapibaseencoder.c
gst-libs/gst/vaapi/gstvaapiencoder.c
gst-libs/gst/vaapi/gstvaapiencoder.h
gst/vaapi/gstvaapiencode_h264.c

index e491d86..38854e8 100644 (file)
@@ -232,6 +232,26 @@ gst_vaapi_base_encoder_close_default(GstVaapiEncoder* encoder)
   return ret;
 }
 
+static GstVaapiContext *
+_create_context(
+    GstVaapiDisplay    *display,
+    GstVaapiProfile     profile,
+    guint               width,
+    guint               height,
+    GstVaapiRateControl rate_control
+)
+{
+  GstVaapiContextInfo info;
+
+  info.profile    = profile;
+  info.entrypoint = GST_VAAPI_ENTRYPOINT_SLICE_ENCODE;
+  info.rate_control = rate_control;
+  info.width      = width;
+  info.height     = height;
+  info.ref_frames = 4;
+  return gst_vaapi_context_new_full(display, &info);
+}
+
 static EncoderStatus
 gst_vaapi_base_encoder_open_default(
     GstVaapiEncoder* encoder,
@@ -263,11 +283,11 @@ gst_vaapi_base_encoder_open_default(
 
   ENCODER_ASSERT(ENCODER_DISPLAY(encoder));
 
-  out_context = gst_vaapi_context_new(display,
+  out_context = _create_context(display,
                         gst_vaapi_profile(priv->profile),
-                        gst_vaapi_entrypoint(VAEntrypointEncSlice),
                         ENCODER_WIDTH(encoder),
-                        ENCODER_HEIGHT(encoder));
+                        ENCODER_HEIGHT(encoder),
+                        ENCODER_RATE_CONTROL(encoder));
   ENCODER_CHECK_STATUS(out_context,
                        ENCODER_CONTEXT_ERR,
                        "gst_vaapi_context_new failed.");
index b27b397..a003ac5 100644 (file)
@@ -324,6 +324,7 @@ gst_vaapi_encoder_init(GstVaapiEncoder *encoder)
   encoder->width = 0;
   encoder->height = 0;
   encoder->frame_rate = 0;
+  encoder->rate_control = GST_VAAPI_RATECONTROL_NONE;
 }
 
 static void
index 8030ed1..301d25b 100644 (file)
@@ -164,6 +164,8 @@ typedef struct _GstVaapiEncoderClass         GstVaapiEncoderClass;
 #define ENCODER_WIDTH(encoder)   (((GstVaapiEncoder*)(encoder))->width)
 #define ENCODER_HEIGHT(encoder)  (((GstVaapiEncoder*)(encoder))->height)
 #define ENCODER_FPS(encoder)     (((GstVaapiEncoder*)(encoder))->frame_rate)
+#define ENCODER_RATE_CONTROL(encoder)   \
+    (((GstVaapiEncoder*)(encoder))->rate_control)
 
 struct _GstVaapiEncoder {
   GObject parent;
@@ -172,6 +174,7 @@ struct _GstVaapiEncoder {
   guint32 width;
   guint32 height;
   guint32 frame_rate;
+  GstVaapiRateControl rate_control;
 };
 
 struct _GstVaapiEncoderClass {
index 41bc6b5..9df2143 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "gstvaapiencode_h264.h"
 #include "gst/vaapi/gstvaapiencoder_h264.h"
+#include "gst/vaapi/gstvaapivalue.h"
 
 #include <string.h>
 
@@ -68,6 +69,7 @@ enum {
     H264_PROP_0,
     H264_PROP_PROFILE,
     H264_PROP_LEVEL,
+    H264_PROP_RATE_CONTROL,
     H264_PROP_BITRATE,
     H264_PROP_INTRA_PERIOD,
     H264_PROP_INIT_QP,
@@ -177,6 +179,11 @@ gst_vaapi_encode_h264_set_property(
     }
       break;
 
+    case H264_PROP_RATE_CONTROL: {
+      ENCODER_RATE_CONTROL(h264encoder) = g_value_get_enum(value);
+    }
+      break;
+
     case H264_PROP_BITRATE: {
       h264encoder->bitrate = g_value_get_uint(value);
     }
@@ -234,6 +241,10 @@ gst_vaapi_encode_h264_get_property (
       g_value_set_uint (value, h264encoder->level);
       break;
 
+    case H264_PROP_RATE_CONTROL:
+      g_value_set_enum(value, ENCODER_RATE_CONTROL(h264encoder));
+      break;
+
     case H264_PROP_BITRATE:
       g_value_set_uint (value, h264encoder->bitrate);
       break;
@@ -365,6 +376,16 @@ gst_vaapi_encode_h264_class_init(GstVaapiEncodeH264Class *klass)
 
   g_object_class_install_property (
       object_class,
+      H264_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,
       H264_PROP_BITRATE,
       g_param_spec_uint (
           "bitrate",