[Pkg-gstreamer-commits] [gstreamer-vaapi] 25/176: vaapiencode: additional clean-ups.

Vincent Cheng vcheng at moszumanska.debian.org
Tue Jun 3 08:09:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

vcheng pushed a commit to branch upstream
in repository gstreamer-vaapi.

commit 8116d8a50ea8681d0e384198506e33879493f7e6
Author: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
Date:   Thu Nov 28 13:57:54 2013 +0100

    vaapiencode: additional clean-ups.
    
    Constify pointers wherever possible. Drop unused variables, and use
    consistent variable names. Fix gst_vaapiencode_h264_allocate_buffer()
    to correctly report errors, especially when in-place conversion from
    bytestream to avcC format failed.
---
 gst/vaapi/gstvaapiencode.c       | 42 ++++++++++++++++++----------------------
 gst/vaapi/gstvaapiencode.h       |  1 -
 gst/vaapi/gstvaapiencode_h264.c  | 33 +++++++++++++++++--------------
 gst/vaapi/gstvaapiencode_h264.h  |  2 --
 gst/vaapi/gstvaapiencode_mpeg2.c | 16 +++++++--------
 5 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c
index 73dc7a6..0fc5154 100644
--- a/gst/vaapi/gstvaapiencode.c
+++ b/gst/vaapi/gstvaapiencode.c
@@ -162,7 +162,7 @@ gst_vaapiencode_query (GST_PAD_QUERY_FUNCTION_ARGS)
       GST_VAAPIENCODE_CAST (gst_pad_get_parent_element (pad));
   gboolean success;
 
-  GST_INFO_OBJECT(encode, "query type %s", GST_QUERY_TYPE_NAME(query));
+  GST_INFO_OBJECT (encode, "query type %s", GST_QUERY_TYPE_NAME (query));
 
   if (gst_vaapi_reply_to_query (query, encode->display))
     success = TRUE;
@@ -236,23 +236,23 @@ static GstFlowReturn
 gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 ms_timeout)
 {
   GstVideoEncoder *const venc = GST_VIDEO_ENCODER_CAST (encode);
-  GstVaapiEncodeClass *klass = GST_VAAPIENCODE_GET_CLASS (encode);
+  GstVaapiEncodeClass *const klass = GST_VAAPIENCODE_GET_CLASS (encode);
   GstVideoCodecFrame *out_frame = NULL;
   GstVaapiCodedBufferProxy *coded_buf_proxy = NULL;
   GstVaapiCodedBuffer *coded_buf;
-  GstVaapiEncoderStatus encode_status;
-  GstBuffer *output_buf;
+  GstVaapiEncoderStatus status;
+  GstBuffer *out_buffer;
   GstFlowReturn ret;
 
   g_return_val_if_fail (klass->allocate_buffer, GST_FLOW_ERROR);
 
-  encode_status = gst_vaapi_encoder_get_buffer (encode->encoder,
+  status = gst_vaapi_encoder_get_buffer (encode->encoder,
       &out_frame, &coded_buf_proxy, ms_timeout);
-  if (encode_status == GST_VAAPI_ENCODER_STATUS_TIMEOUT)
+  if (status == GST_VAAPI_ENCODER_STATUS_TIMEOUT)
     return GST_VAAPI_ENCODE_FLOW_TIMEOUT;
 
-  if (encode_status != GST_VAAPI_ENCODER_STATUS_SUCCESS) {
-    GST_ERROR ("get encoded buffer failed, status:%d", encode_status);
+  if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) {
+    GST_ERROR ("get encoded buffer failed, status:%d", status);
     ret = GST_FLOW_ERROR;
     goto error;
   }
@@ -264,24 +264,22 @@ gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 ms_timeout)
   g_assert (coded_buf);
 
   /* alloc buffer */
-  ret = klass->allocate_buffer (encode, coded_buf, &output_buf);
+  ret = klass->allocate_buffer (encode, coded_buf, &out_buffer);
   if (ret != GST_FLOW_OK)
     goto error;
 
-  out_frame->output_buffer = output_buf;
+  out_frame->output_buffer = out_buffer;
 
   gst_vaapi_coded_buffer_proxy_replace (&coded_buf_proxy, NULL);
 
   /* check out_caps, need lock first */
   GST_VIDEO_ENCODER_STREAM_LOCK (encode);
   if (!encode->out_caps_done) {
-    GstVaapiEncoderStatus encoder_status;
     GstVideoCodecState *old_state, *new_state;
     GstBuffer *codec_data;
 
-    encoder_status =
-        gst_vaapi_encoder_get_codec_data (encode->encoder, &codec_data);
-    if (encoder_status != GST_VAAPI_ENCODER_STATUS_SUCCESS) {
+    status = gst_vaapi_encoder_get_codec_data (encode->encoder, &codec_data);
+    if (status != GST_VAAPI_ENCODER_STATUS_SUCCESS) {
       ret = GST_VAAPI_ENCODE_FLOW_CODEC_DATA_ERROR;
       goto error_unlock;
     }
@@ -313,7 +311,7 @@ gst_vaapiencode_push_frame (GstVaapiEncode * encode, gint64 ms_timeout)
   GST_VIDEO_ENCODER_STREAM_UNLOCK (encode);
 
   GST_DEBUG ("output:%" GST_TIME_FORMAT ", size:%d",
-      GST_TIME_ARGS (out_frame->pts), gst_buffer_get_size (output_buf));
+      GST_TIME_ARGS (out_frame->pts), gst_buffer_get_size (out_buffer));
 
   ret = gst_video_encoder_finish_frame (venc, out_frame);
   out_frame = NULL;
@@ -472,7 +470,7 @@ gst_vaapiencode_update_src_caps (GstVaapiEncode * encode,
   GstVideoCodecState *out_state;
   GstStructure *structure;
   GstCaps *outcaps, *allowed_caps, *template_caps, *intersect;
-  GstVaapiEncoderStatus encoder_status;
+  GstVaapiEncoderStatus status;
   GstBuffer *codec_data = NULL;
 
   g_return_val_if_fail (encode->encoder, FALSE);
@@ -498,9 +496,8 @@ gst_vaapiencode_update_src_caps (GstVaapiEncode * encode,
   }
   structure = gst_caps_get_structure (outcaps, 0);
   if (!gst_structure_has_field (structure, "codec_data")) {
-    encoder_status =
-        gst_vaapi_encoder_get_codec_data (encode->encoder, &codec_data);
-    if (encoder_status == GST_VAAPI_ENCODER_STATUS_SUCCESS) {
+    status = gst_vaapi_encoder_get_codec_data (encode->encoder, &codec_data);
+    if (status == GST_VAAPI_ENCODER_STATUS_SUCCESS) {
       if (codec_data) {
         outcaps = gst_caps_make_writable (outcaps);
         gst_caps_set_simple (outcaps,
@@ -626,7 +623,6 @@ gst_vaapiencode_reset (GstVideoEncoder * venc, gboolean hard)
   GST_DEBUG ("vaapiencode starting reset");
 
   /* FIXME: compare sink_caps with encoder */
-  encode->is_running = FALSE;
   encode->out_caps_done = FALSE;
   return TRUE;
 }
@@ -782,7 +778,7 @@ gst_vaapiencode_handle_frame (GstVideoEncoder * venc,
 {
   GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (venc);
   GstFlowReturn ret = GST_FLOW_OK;
-  GstVaapiEncoderStatus encoder_ret = GST_VAAPI_ENCODER_STATUS_SUCCESS;
+  GstVaapiEncoderStatus status = GST_VAAPI_ENCODER_STATUS_SUCCESS;
   GstBuffer *buf;
   gpointer user_data;
 
@@ -801,11 +797,11 @@ gst_vaapiencode_handle_frame (GstVideoEncoder * venc,
 
   GST_VIDEO_ENCODER_STREAM_UNLOCK (encode);
   /*encoding frames */
-  encoder_ret = gst_vaapi_encoder_put_frame (encode->encoder, frame);
+  status = gst_vaapi_encoder_put_frame (encode->encoder, frame);
   GST_VIDEO_ENCODER_STREAM_LOCK (encode);
 
   GST_VAAPI_ENCODER_CHECK_STATUS (GST_VAAPI_ENCODER_STATUS_SUCCESS <=
-      encoder_ret, GST_FLOW_ERROR, "gst_vaapiencoder_encode failed.");
+      status, GST_FLOW_ERROR, "gst_vaapiencoder_encode failed.");
 
 end:
   gst_video_codec_frame_unref (frame);
diff --git a/gst/vaapi/gstvaapiencode.h b/gst/vaapi/gstvaapiencode.h
index 8249523..6d59980 100644
--- a/gst/vaapi/gstvaapiencode.h
+++ b/gst/vaapi/gstvaapiencode.h
@@ -74,7 +74,6 @@ struct _GstVaapiEncode
   GstVaapiRateControl rate_control;
   guint32 bitrate;              /* kbps */
 
-  guint32 is_running:1;
   guint32 out_caps_done:1;
 };
 
diff --git a/gst/vaapi/gstvaapiencode_h264.c b/gst/vaapi/gstvaapiencode_h264.c
index 4ccb4a2..386f8b2 100644
--- a/gst/vaapi/gstvaapiencode_h264.c
+++ b/gst/vaapi/gstvaapiencode_h264.c
@@ -180,7 +180,7 @@ static guint8 *
 _h264_byte_stream_next_nal (guint8 * buffer, guint32 len, guint32 * nal_size)
 {
   const guint8 *cur = buffer;
-  const guint8 *end = buffer + len;
+  const guint8 *const end = buffer + len;
   guint8 *nal_start = NULL;
   guint32 flag = 0xFFFFFFFF;
   guint32 nal_start_len = 0;
@@ -268,30 +268,35 @@ error:
 }
 
 static GstFlowReturn
-gst_vaapiencode_h264_alloc_buffer (GstVaapiEncode * encode,
-    GstVaapiCodedBuffer * coded_buf, GstBuffer ** out_buf)
+gst_vaapiencode_h264_allocate_buffer (GstVaapiEncode * encode,
+    GstVaapiCodedBuffer * coded_buf, GstBuffer ** out_buffer_ptr)
 {
+  GstVaapiEncoderH264 *const encoder = GST_VAAPI_ENCODER_H264 (encode->encoder);
   GstFlowReturn ret;
-  GstVaapiEncoderH264 *h264encoder;
 
-  g_return_val_if_fail (encode->encoder, GST_FLOW_ERROR);
+  g_return_val_if_fail (encoder != NULL, GST_FLOW_ERROR);
 
   ret =
       GST_VAAPIENCODE_CLASS (gst_vaapiencode_h264_parent_class)->allocate_buffer
-      (encode, coded_buf, out_buf);
+      (encode, coded_buf, out_buffer_ptr);
   if (ret != GST_FLOW_OK)
     return ret;
 
-  h264encoder = GST_VAAPI_ENCODER_H264 (encode->encoder);
-  if (!gst_vaapi_encoder_h264_is_avc (h264encoder))
-    return ret;
+  if (!gst_vaapi_encoder_h264_is_avc (encoder))
+    return GST_FLOW_OK;
 
   /* Convert to avcC format */
-  if (!_h264_convert_byte_stream_to_avc (*out_buf)) {
-    GST_ERROR ("convert H.264 bytestream to avc buf failed.");
-    gst_buffer_replace (out_buf, NULL);
-  }
+  if (!_h264_convert_byte_stream_to_avc (*out_buffer_ptr))
+    goto error_convert_buffer;
   return GST_FLOW_OK;
+
+  /* ERRORS */
+error_convert_buffer:
+  {
+    GST_ERROR ("failed to convert from bytestream format to avcC format");
+    gst_buffer_replace (out_buffer_ptr, NULL);
+    return GST_FLOW_ERROR;
+  }
 }
 
 static void
@@ -309,7 +314,7 @@ gst_vaapiencode_h264_class_init (GstVaapiEncodeH264Class * klass)
   object_class->get_property = gst_vaapiencode_h264_get_property;
 
   encode_class->create_encoder = gst_vaapiencode_h264_create_encoder;
-  encode_class->allocate_buffer = gst_vaapiencode_h264_alloc_buffer;
+  encode_class->allocate_buffer = gst_vaapiencode_h264_allocate_buffer;
 
   gst_element_class_set_static_metadata (element_class,
       "VA-API H.264 encoder",
diff --git a/gst/vaapi/gstvaapiencode_h264.h b/gst/vaapi/gstvaapiencode_h264.h
index 8d90610..d6dad76 100644
--- a/gst/vaapi/gstvaapiencode_h264.h
+++ b/gst/vaapi/gstvaapiencode_h264.h
@@ -53,8 +53,6 @@ struct _GstVaapiEncodeH264
   /*< private >*/
   GstVaapiEncode parent_instance;
 
-  GstVaapiProfile profile;
-  guint32 level;
   guint32 intra_period;
   guint32 init_qp;
   guint32 min_qp;
diff --git a/gst/vaapi/gstvaapiencode_mpeg2.c b/gst/vaapi/gstvaapiencode_mpeg2.c
index 7295a06..6aebab3 100644
--- a/gst/vaapi/gstvaapiencode_mpeg2.c
+++ b/gst/vaapi/gstvaapiencode_mpeg2.c
@@ -82,14 +82,14 @@ enum
 };
 
 static void
-gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * mpeg2_encode)
+gst_vaapiencode_mpeg2_init (GstVaapiEncodeMpeg2 * encode)
 {
-  GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (mpeg2_encode);
+  GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (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;
+  encode->quantizer = GST_VAAPI_ENCODER_MPEG2_DEFAULT_CQP;
+  encode->intra_period = GST_VAAPI_ENCODER_MPEG2_DEFAULT_GOP_SIZE;
+  encode->ip_period = GST_VAAPI_ENCODER_MPEG2_DEFAULT_MAX_BFRAMES;
 }
 
 static void
@@ -102,7 +102,7 @@ static void
 gst_vaapiencode_mpeg2_set_property (GObject * object,
     guint prop_id, const GValue * value, GParamSpec * pspec)
 {
-  GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (object);
+  GstVaapiEncodeMpeg2 *const encode = GST_VAAPIENCODE_MPEG2_CAST (object);
 
   switch (prop_id) {
     case PROP_QUANTIZER:
@@ -124,7 +124,7 @@ static void
 gst_vaapiencode_mpeg2_get_property (GObject * object,
     guint prop_id, GValue * value, GParamSpec * pspec)
 {
-  GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (object);
+  GstVaapiEncodeMpeg2 *const encode = GST_VAAPIENCODE_MPEG2_CAST (object);
 
   switch (prop_id) {
     case PROP_QUANTIZER:
@@ -146,7 +146,7 @@ static GstVaapiEncoder *
 gst_vaapiencode_mpeg2_create_encoder (GstVaapiEncode * base,
     GstVaapiDisplay * display)
 {
-  GstVaapiEncodeMpeg2 *encode = GST_VAAPIENCODE_MPEG2_CAST (base);
+  GstVaapiEncodeMpeg2 *const encode = GST_VAAPIENCODE_MPEG2_CAST (base);
   GstVaapiEncode *const base_encode = GST_VAAPIENCODE_CAST (base);
   GstVaapiEncoder *base_encoder;
   GstVaapiEncoderMpeg2 *encoder;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gstreamer/gstreamer-vaapi.git



More information about the Pkg-gstreamer-commits mailing list