[Pkg-gstreamer-commits] [gstreamer-vaapi] 122/176: encoder: clean-up objects.

Vincent Cheng vcheng at moszumanska.debian.org
Tue Jun 3 08:09:33 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 d45c6a486f7e12235c9d514b7303f5f8257e1bff
Author: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
Date:   Tue Jan 14 12:01:11 2014 +0100

    encoder: clean-up objects.
    
    Various clean-ups to improve consistency and readability: rename some
    variables, drop unused macro definitions, drop initialization of vars
    that are zero-initialized from the base class, drop un-necessary casts,
    allocate GPtrArrays with a destroy function.
---
 gst-libs/gst/vaapi/gstvaapiencoder.c         |   2 +-
 gst-libs/gst/vaapi/gstvaapiencoder_h264.c    |  19 +--
 gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c   |   8 +-
 gst-libs/gst/vaapi/gstvaapiencoder_objects.c | 211 +++++++++++----------------
 gst-libs/gst/vaapi/gstvaapiencoder_objects.h | 179 ++++++++---------------
 5 files changed, 162 insertions(+), 257 deletions(-)

diff --git a/gst-libs/gst/vaapi/gstvaapiencoder.c b/gst-libs/gst/vaapi/gstvaapiencoder.c
index 89b77e5..b9767f1 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder.c
@@ -318,7 +318,7 @@ gst_vaapi_encoder_put_frame (GstVaapiEncoder * encoder,
       goto error_encode;
 
     gst_vaapi_coded_buffer_proxy_set_user_data (codedbuf_proxy,
-        picture, (GDestroyNotify) gst_vaapi_enc_picture_unref);
+        picture, (GDestroyNotify) gst_vaapi_mini_object_unref);
     g_async_queue_push (encoder->codedbuf_queue, codedbuf_proxy);
     encoder->num_codedbuf_queued++;
 
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
index ff16098..6338522 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c
@@ -393,8 +393,9 @@ _set_i_frame (GstVaapiEncPicture * pic, GstVaapiEncoderH264 * encoder)
   g_return_if_fail (pic->type == GST_VAAPI_PICTURE_TYPE_NONE);
   pic->type = GST_VAAPI_PICTURE_TYPE_I;
   pic->frame_num = (encoder->cur_frame_num % encoder->max_frame_num);
-  g_assert (GST_VAAPI_ENC_PICTURE_GET_FRAME (pic));
-  GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (GST_VAAPI_ENC_PICTURE_GET_FRAME (pic));
+
+  g_assert (pic->frame);
+  GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (pic->frame);
 }
 
 static inline void
@@ -406,8 +407,8 @@ _set_idr_frame (GstVaapiEncPicture * pic, GstVaapiEncoderH264 * encoder)
   pic->poc = 0;
   GST_VAAPI_ENC_PICTURE_FLAG_SET (pic, GST_VAAPI_ENC_PICTURE_FLAG_IDR);
 
-  g_assert (GST_VAAPI_ENC_PICTURE_GET_FRAME (pic));
-  GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (GST_VAAPI_ENC_PICTURE_GET_FRAME (pic));
+  g_assert (pic->frame);
+  GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (pic->frame);
 }
 
 static inline void
@@ -1303,8 +1304,8 @@ ensure_misc (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
   g_assert (misc);
   if (!misc)
     return FALSE;
-  gst_vaapi_enc_picture_add_misc_buffer (picture, misc);
-  hrd = misc->impl;
+  gst_vaapi_enc_picture_add_misc_param (picture, misc);
+  hrd = misc->data;
   if (base_encoder->bitrate > 0) {
     hrd->initial_buffer_fullness = base_encoder->bitrate * 1000 * 4;
     hrd->buffer_size = base_encoder->bitrate * 1000 * 8;
@@ -1321,8 +1322,8 @@ ensure_misc (GstVaapiEncoderH264 * encoder, GstVaapiEncPicture * picture)
     g_assert (misc);
     if (!misc)
       return FALSE;
-    gst_vaapi_enc_picture_add_misc_buffer (picture, misc);
-    rate_control = misc->impl;
+    gst_vaapi_enc_picture_add_misc_param (picture, misc);
+    rate_control = misc->data;
     memset (rate_control, 0, sizeof (VAEncMiscParameterRateControl));
     if (base_encoder->bitrate)
       rate_control->bits_per_second = base_encoder->bitrate * 1000;
@@ -1672,7 +1673,7 @@ gst_vaapi_encoder_h264_reordering (GstVaapiEncoder * base_encoder,
 
 end:
   g_assert (picture);
-  frame = GST_VAAPI_ENC_PICTURE_GET_FRAME (picture);
+  frame = picture->frame;
   if (GST_CLOCK_TIME_IS_VALID (frame->pts))
     frame->pts += encoder->cts_offset;
   *output = picture;
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
index 958dd6e..943325c 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_mpeg2.c
@@ -454,8 +454,8 @@ set_misc_parameters (GstVaapiEncoderMpeg2 * encoder,
   g_assert (misc);
   if (!misc)
     return FALSE;
-  gst_vaapi_enc_picture_add_misc_buffer (picture, misc);
-  hrd = misc->impl;
+  gst_vaapi_enc_picture_add_misc_param (picture, misc);
+  hrd = misc->data;
   if (base_encoder->bitrate > 0) {
     hrd->initial_buffer_fullness = base_encoder->bitrate * 1000 * 4;
     hrd->buffer_size = base_encoder->bitrate * 1000 * 8;
@@ -471,8 +471,8 @@ set_misc_parameters (GstVaapiEncoderMpeg2 * encoder,
     g_assert (misc);
     if (!misc)
       return FALSE;
-    gst_vaapi_enc_picture_add_misc_buffer (picture, misc);
-    rate_control = misc->impl;
+    gst_vaapi_enc_picture_add_misc_param (picture, misc);
+    rate_control = misc->data;
     memset (rate_control, 0, sizeof (VAEncMiscParameterRateControl));
     if (base_encoder->bitrate)
       rate_control->bits_per_second = base_encoder->bitrate * 1000;
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_objects.c b/gst-libs/gst/vaapi/gstvaapiencoder_objects.c
index b4bdbd9..3702318 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_objects.c
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_objects.c
@@ -20,12 +20,10 @@
  */
 
 #include "sysdeps.h"
-#include "glibcompat.h"
-
 #include "gstvaapiencoder_objects.h"
-#include "gstvaapiencoder.h"
 #include "gstvaapiencoder_priv.h"
 #include "gstvaapisurfaceproxy_priv.h"
+#include "gstvaapicompat.h"
 #include "gstvaapiutils.h"
 
 #define DEBUG 1
@@ -43,45 +41,39 @@ GST_VAAPI_CODEC_DEFINE_TYPE (GstVaapiEncPackedHeader,
     gst_vaapi_enc_packed_header);
 
 void
-gst_vaapi_enc_packed_header_destroy (GstVaapiEncPackedHeader * packed_header)
+gst_vaapi_enc_packed_header_destroy (GstVaapiEncPackedHeader * header)
 {
-  vaapi_destroy_buffer (GET_VA_DISPLAY (packed_header),
-      &packed_header->param_id);
-  vaapi_destroy_buffer (GET_VA_DISPLAY (packed_header),
-      &packed_header->data_id);
-  packed_header->param = NULL;
-  packed_header->data = NULL;
+  vaapi_destroy_buffer (GET_VA_DISPLAY (header), &header->param_id);
+  vaapi_destroy_buffer (GET_VA_DISPLAY (header), &header->data_id);
+  header->param = NULL;
+  header->data = NULL;
 }
 
 gboolean
-gst_vaapi_enc_packed_header_create (GstVaapiEncPackedHeader * packed_header,
+gst_vaapi_enc_packed_header_create (GstVaapiEncPackedHeader * header,
     const GstVaapiCodecObjectConstructorArgs * args)
 {
   gboolean success;
 
-  packed_header->param_id = VA_INVALID_ID;
-  packed_header->param = NULL;
-  packed_header->data_id = VA_INVALID_ID;
-  packed_header->data = NULL;
-  success = vaapi_create_buffer (GET_VA_DISPLAY (packed_header),
-      GET_VA_CONTEXT (packed_header),
+  header->param_id = VA_INVALID_ID;
+  header->data_id = VA_INVALID_ID;
+
+  success = vaapi_create_buffer (GET_VA_DISPLAY (header),
+      GET_VA_CONTEXT (header),
       VAEncPackedHeaderParameterBufferType,
-      args->param_size,
-      args->param, &packed_header->param_id, &packed_header->param);
+      args->param_size, args->param, &header->param_id, &header->param);
   if (!success)
     return FALSE;
 
   if (!args->data_size)
     return TRUE;
 
-  success = vaapi_create_buffer (GET_VA_DISPLAY (packed_header),
-      GET_VA_CONTEXT (packed_header),
+  success = vaapi_create_buffer (GET_VA_DISPLAY (header),
+      GET_VA_CONTEXT (header),
       VAEncPackedHeaderDataBufferType,
-      args->data_size,
-      args->data, &packed_header->data_id, &packed_header->data);
+      args->data_size, args->data, &header->data_id, &header->data);
   if (!success)
     return FALSE;
-
   return TRUE;
 }
 
@@ -97,21 +89,18 @@ gst_vaapi_enc_packed_header_new (GstVaapiEncoder * encoder,
 }
 
 gboolean
-gst_vaapi_enc_packed_header_set_data (GstVaapiEncPackedHeader * packed_header,
+gst_vaapi_enc_packed_header_set_data (GstVaapiEncPackedHeader * header,
     gconstpointer data, guint data_size)
 {
   gboolean success;
 
-  g_assert (packed_header->data_id == VA_INVALID_ID);
-  if (packed_header->data_id != VA_INVALID_ID) {
-    vaapi_destroy_buffer (GET_VA_DISPLAY (packed_header),
-        &packed_header->data_id);
-    packed_header->data = NULL;
-  }
-  success = vaapi_create_buffer (GET_VA_DISPLAY (packed_header),
-      GET_VA_CONTEXT (packed_header),
+  vaapi_destroy_buffer (GET_VA_DISPLAY (header), &header->data_id);
+  header->data = NULL;
+
+  success = vaapi_create_buffer (GET_VA_DISPLAY (header),
+      GET_VA_CONTEXT (header),
       VAEncPackedHeaderDataBufferType,
-      data_size, data, &packed_header->data_id, &packed_header->data);
+      data_size, data, &header->data_id, &header->data);
   if (!success)
     return FALSE;
   return TRUE;
@@ -143,7 +132,6 @@ gst_vaapi_enc_sequence_create (GstVaapiEncSequence * sequence,
       args->param_size, args->param, &sequence->param_id, &sequence->param);
   if (!success)
     return FALSE;
-
   return TRUE;
 }
 
@@ -155,7 +143,7 @@ gst_vaapi_enc_sequence_new (GstVaapiEncoder * encoder,
 
   object = gst_vaapi_codec_object_new (&GstVaapiEncSequenceClass,
       GST_VAAPI_CODEC_BASE (encoder), param, param_size, NULL, 0, 0);
-  return GST_VAAPI_ENC_SEQUENCE_CAST (object);
+  return GST_VAAPI_ENC_SEQUENCE (object);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -184,7 +172,6 @@ gst_vaapi_enc_slice_create (GstVaapiEncSlice * slice,
       args->param_size, args->param, &slice->param_id, &slice->param);
   if (!success)
     return FALSE;
-
   return TRUE;
 }
 
@@ -196,7 +183,7 @@ gst_vaapi_enc_slice_new (GstVaapiEncoder * encoder,
 
   object = gst_vaapi_codec_object_new (&GstVaapiEncSliceClass,
       GST_VAAPI_CODEC_BASE (encoder), param, param_size, NULL, 0, 0);
-  return GST_VAAPI_ENC_SLICE_CAST (object);
+  return GST_VAAPI_ENC_SLICE (object);
 }
 
 /* ------------------------------------------------------------------------- */
@@ -210,7 +197,7 @@ gst_vaapi_enc_misc_param_destroy (GstVaapiEncMiscParam * misc)
 {
   vaapi_destroy_buffer (GET_VA_DISPLAY (misc), &misc->param_id);
   misc->param = NULL;
-  misc->impl = NULL;
+  misc->data = NULL;
 }
 
 gboolean
@@ -226,29 +213,28 @@ gst_vaapi_enc_misc_param_create (GstVaapiEncMiscParam * misc,
       args->param_size, args->param, &misc->param_id, &misc->param);
   if (!success)
     return FALSE;
-
   return TRUE;
 }
 
 GstVaapiEncMiscParam *
 gst_vaapi_enc_misc_param_new (GstVaapiEncoder * encoder,
-    VAEncMiscParameterType type, guint total_size)
+    VAEncMiscParameterType type, guint data_size)
 {
   GstVaapiCodecObject *object;
-  GstVaapiEncMiscParam *misc_obj;
-  VAEncMiscParameterBuffer *misc;
+  GstVaapiEncMiscParam *misc;
+  VAEncMiscParameterBuffer *va_misc;
 
   object = gst_vaapi_codec_object_new (&GstVaapiEncMiscParamClass,
-      GST_VAAPI_CODEC_BASE (encoder), NULL, total_size, NULL, 0, 0);
+      GST_VAAPI_CODEC_BASE (encoder),
+      NULL, sizeof (VAEncMiscParameterBuffer) + data_size, NULL, 0, 0);
   if (!object)
     return NULL;
 
-  misc_obj = GST_VAAPI_ENC_MISC_PARAM_CAST (object);
-  misc = misc_obj->param;
-  misc->type = type;
-  misc_obj->impl = misc->data;
-  g_assert (misc_obj->impl);
-  return misc_obj;
+  misc = GST_VAAPI_ENC_MISC_PARAM (object);
+  va_misc = misc->param;
+  va_misc->type = type;
+  misc->data = va_misc->data;
+  return misc;
 }
 
 /* ------------------------------------------------------------------------- */
@@ -257,34 +243,22 @@ gst_vaapi_enc_misc_param_new (GstVaapiEncoder * encoder,
 
 GST_VAAPI_CODEC_DEFINE_TYPE (GstVaapiEncPicture, gst_vaapi_enc_picture);
 
-static void
-destroy_vaapi_obj_cb (gpointer data, gpointer user_data)
-{
-  GstVaapiMiniObject *const object = data;
-
-  gst_vaapi_mini_object_unref (object);
-}
-
 void
 gst_vaapi_enc_picture_destroy (GstVaapiEncPicture * picture)
 {
   if (picture->packed_headers) {
-    g_ptr_array_foreach (picture->packed_headers, destroy_vaapi_obj_cb, NULL);
-    g_ptr_array_free (picture->packed_headers, TRUE);
+    g_ptr_array_unref (picture->packed_headers);
     picture->packed_headers = NULL;
   }
-  if (picture->misc_buffers) {
-    g_ptr_array_foreach (picture->misc_buffers, destroy_vaapi_obj_cb, NULL);
-    g_ptr_array_free (picture->misc_buffers, TRUE);
-    picture->misc_buffers = NULL;
+  if (picture->misc_params) {
+    g_ptr_array_unref (picture->misc_params);
+    picture->misc_params = NULL;
   }
   if (picture->slices) {
-    g_ptr_array_foreach (picture->slices, destroy_vaapi_obj_cb, NULL);
-    g_ptr_array_free (picture->slices, TRUE);
+    g_ptr_array_unref (picture->slices);
     picture->slices = NULL;
   }
-  gst_vaapi_mini_object_replace (
-      (GstVaapiMiniObject **) (&picture->sequence), NULL);
+  gst_vaapi_codec_object_replace (&picture->sequence, NULL);
 
   gst_vaapi_surface_proxy_replace (&picture->proxy, NULL);
   picture->surface_id = VA_INVALID_ID;
@@ -292,7 +266,6 @@ gst_vaapi_enc_picture_destroy (GstVaapiEncPicture * picture)
 
   vaapi_destroy_buffer (GET_VA_DISPLAY (picture), &picture->param_id);
   picture->param = NULL;
-  picture->param = NULL;
 
   if (picture->frame) {
     gst_video_codec_frame_unref (picture->frame);
@@ -307,8 +280,6 @@ gst_vaapi_enc_picture_create (GstVaapiEncPicture * picture,
   GstVideoCodecFrame *const frame = (GstVideoCodecFrame *) args->data;
   gboolean success;
 
-  g_return_val_if_fail (frame != NULL, FALSE);
-
   picture->proxy = gst_video_codec_frame_get_user_data (frame);
   if (!gst_vaapi_surface_proxy_ref (picture->proxy))
     return FALSE;
@@ -321,7 +292,6 @@ gst_vaapi_enc_picture_create (GstVaapiEncPicture * picture,
   if (picture->surface_id == VA_INVALID_ID)
     return FALSE;
 
-  picture->sequence = NULL;
   picture->type = GST_VAAPI_PICTURE_TYPE_NONE;
   picture->pts = GST_CLOCK_TIME_NONE;
   picture->frame_num = 0;
@@ -329,7 +299,6 @@ gst_vaapi_enc_picture_create (GstVaapiEncPicture * picture,
 
   picture->param_id = VA_INVALID_ID;
   picture->param_size = args->param_size;
-  picture->param = NULL;
   success = vaapi_create_buffer (GET_VA_DISPLAY (picture),
       GET_VA_CONTEXT (picture),
       VAEncPictureParameterBufferType,
@@ -338,17 +307,22 @@ gst_vaapi_enc_picture_create (GstVaapiEncPicture * picture,
     return FALSE;
   picture->param_size = args->param_size;
 
-  picture->packed_headers = g_ptr_array_new ();
-  picture->misc_buffers = g_ptr_array_new ();
-  picture->slices = g_ptr_array_new ();
+  picture->packed_headers = g_ptr_array_new_with_free_func ((GDestroyNotify)
+      gst_vaapi_mini_object_unref);
+  if (!picture->packed_headers)
+    return FALSE;
 
-  g_assert (picture->packed_headers && picture->misc_buffers
-      && picture->slices);
-  if (!picture->packed_headers || !picture->misc_buffers || !picture->slices)
+  picture->misc_params = g_ptr_array_new_with_free_func ((GDestroyNotify)
+      gst_vaapi_mini_object_unref);
+  if (!picture->misc_params)
     return FALSE;
 
-  picture->frame = gst_video_codec_frame_ref (frame);
+  picture->slices = g_ptr_array_new_with_free_func ((GDestroyNotify)
+      gst_vaapi_mini_object_unref);
+  if (!picture->slices)
+    return FALSE;
 
+  picture->frame = gst_video_codec_frame_ref (frame);
   return TRUE;
 }
 
@@ -358,59 +332,52 @@ gst_vaapi_enc_picture_new (GstVaapiEncoder * encoder,
 {
   GstVaapiCodecObject *object;
 
+  g_return_val_if_fail (frame != NULL, NULL);
+
   object = gst_vaapi_codec_object_new (&GstVaapiEncPictureClass,
       GST_VAAPI_CODEC_BASE (encoder), param, param_size, frame, 0, 0);
-  if (!object)
-    return NULL;
-  return GST_VAAPI_ENC_PICTURE_CAST (object);
+  return GST_VAAPI_ENC_PICTURE (object);
 }
 
 void
 gst_vaapi_enc_picture_set_sequence (GstVaapiEncPicture * picture,
     GstVaapiEncSequence * sequence)
 {
-  g_return_if_fail (GST_VAAPI_IS_ENC_PICTURE (picture));
-  g_return_if_fail (GST_VAAPI_IS_ENC_SEQUENCE (sequence));
+  g_return_if_fail (picture != NULL);
+  g_return_if_fail (sequence != NULL);
 
-  g_assert (sequence);
-  gst_vaapi_mini_object_replace (
-      (GstVaapiMiniObject **) (&picture->sequence),
-      GST_VAAPI_MINI_OBJECT (sequence));
+  gst_vaapi_codec_object_replace (&picture->sequence, sequence);
 }
 
 void
 gst_vaapi_enc_picture_add_packed_header (GstVaapiEncPicture * picture,
     GstVaapiEncPackedHeader * header)
 {
-  g_return_if_fail (GST_VAAPI_IS_ENC_PICTURE (picture));
-  g_return_if_fail (GST_VAAPI_IS_ENC_PACKED_HEADER (header));
+  g_return_if_fail (picture != NULL);
+  g_return_if_fail (header != NULL);
 
-  g_assert (picture->packed_headers);
   g_ptr_array_add (picture->packed_headers,
-      gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (header)));
+      gst_vaapi_codec_object_ref (header));
 }
 
 void
-gst_vaapi_enc_picture_add_misc_buffer (GstVaapiEncPicture * picture,
+gst_vaapi_enc_picture_add_misc_param (GstVaapiEncPicture * picture,
     GstVaapiEncMiscParam * misc)
 {
-  g_return_if_fail (GST_VAAPI_IS_ENC_PICTURE (picture));
-  g_return_if_fail (GST_VAAPI_IS_ENC_MISC_PARAM (misc));
+  g_return_if_fail (picture != NULL);
+  g_return_if_fail (misc != NULL);
 
-  g_assert (picture->misc_buffers);
-  g_ptr_array_add (picture->misc_buffers,
-      gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (misc)));
+  g_ptr_array_add (picture->misc_params, gst_vaapi_codec_object_ref (misc));
 }
 
 void
 gst_vaapi_enc_picture_add_slice (GstVaapiEncPicture * picture,
     GstVaapiEncSlice * slice)
 {
-  g_return_if_fail (GST_VAAPI_IS_ENC_PICTURE (picture));
-  g_return_if_fail (GST_VAAPI_IS_ENC_SLICE (slice));
+  g_return_if_fail (picture != NULL);
+  g_return_if_fail (slice != NULL);
 
-  g_ptr_array_add (picture->slices,
-      gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (slice)));
+  g_ptr_array_add (picture->slices, gst_vaapi_codec_object_ref (slice));
 }
 
 static gboolean
@@ -433,15 +400,12 @@ gboolean
 gst_vaapi_enc_picture_encode (GstVaapiEncPicture * picture)
 {
   GstVaapiEncSequence *sequence;
-  GstVaapiEncPackedHeader *packed_header;
-  GstVaapiEncMiscParam *misc;
-  GstVaapiEncSlice *slice;
   VADisplay va_display;
   VAContextID va_context;
   VAStatus status;
   guint i;
 
-  g_return_val_if_fail (GST_VAAPI_IS_ENC_PICTURE (picture), FALSE);
+  g_return_val_if_fail (picture != NULL, FALSE);
   g_return_val_if_fail (picture->surface_id != VA_INVALID_SURFACE, FALSE);
 
   va_display = GET_VA_DISPLAY (picture);
@@ -453,38 +417,37 @@ gst_vaapi_enc_picture_encode (GstVaapiEncPicture * picture)
   if (!vaapi_check_status (status, "vaBeginPicture()"))
     return FALSE;
 
-  /* encode sequence parameter */
+  /* Submit Sequence parameter */
   sequence = picture->sequence;
-  if (sequence) {
-    if (!do_encode (va_display, va_context,
-            &sequence->param_id, &sequence->param))
-      return FALSE;
-  }
+  if (sequence && !do_encode (va_display, va_context,
+          &sequence->param_id, &sequence->param))
+    return FALSE;
 
-  /* encode picture parameter */
+  /* Submit Picture parameter */
   if (!do_encode (va_display, va_context, &picture->param_id, &picture->param))
     return FALSE;
 
-  /* encode packed headers  */
+  /* Submit Packed Headers */
   for (i = 0; i < picture->packed_headers->len; i++) {
-    packed_header = g_ptr_array_index (picture->packed_headers, i);
+    GstVaapiEncPackedHeader *const header =
+        g_ptr_array_index (picture->packed_headers, i);
     if (!do_encode (va_display, va_context,
-            &packed_header->param_id, &packed_header->param) ||
-        !do_encode (va_display, va_context,
-            &packed_header->data_id, &packed_header->data))
+            &header->param_id, &header->param) ||
+        !do_encode (va_display, va_context, &header->data_id, &header->data))
       return FALSE;
   }
 
-  /* encode misc buffers  */
-  for (i = 0; i < picture->misc_buffers->len; i++) {
-    misc = g_ptr_array_index (picture->misc_buffers, i);
+  /* Submit Misc Params */
+  for (i = 0; i < picture->misc_params->len; i++) {
+    GstVaapiEncMiscParam *const misc =
+        g_ptr_array_index (picture->misc_params, i);
     if (!do_encode (va_display, va_context, &misc->param_id, &misc->param))
       return FALSE;
   }
 
-  /* encode slice parameters */
+  /* Submit Slice parameters */
   for (i = 0; i < picture->slices->len; i++) {
-    slice = g_ptr_array_index (picture->slices, i);
+    GstVaapiEncSlice *const slice = g_ptr_array_index (picture->slices, i);
     if (!do_encode (va_display, va_context, &slice->param_id, &slice->param))
       return FALSE;
   }
diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_objects.h b/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
index d57ad50..f97d4af 100644
--- a/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
+++ b/gst-libs/gst/vaapi/gstvaapiencoder_objects.h
@@ -39,27 +39,21 @@ typedef struct _GstVaapiEncPackedHeader GstVaapiEncPackedHeader;
 /* --- Encoder Packed Header                                             --- */
 /* ------------------------------------------------------------------------- */
 
-#define GST_VAAPI_ENC_PACKED_HEADER_CAST(obj) \
-    ((GstVaapiEncPackedHeader *)(obj))
-
-#define GST_VAAPI_ENC_PACKED_HEADER(obj)      \
-    GST_VAAPI_ENC_PACKED_HEADER_CAST(obj)
-
-#define GST_VAAPI_IS_ENC_PACKED_HEADER(obj)   \
-    (GST_VAAPI_ENC_PACKED_HEADER(obj) != NULL)
+#define GST_VAAPI_ENC_PACKED_HEADER(obj) \
+  ((GstVaapiEncPackedHeader *) (obj))
 
 /**
  * GstVaapiEncPackedHeader:
  *
- * A #GstVaapiCodecObject holding a encoder packed header
- * parameter/data parameter.
+ * A #GstVaapiCodecObject holding a packed header (param/data) for the
+ * encoder.
  */
 struct _GstVaapiEncPackedHeader
 {
-  /*< private > */
+  /*< private >*/
   GstVaapiCodecObject parent_instance;
 
-  /*< public > */
+  /*< public >*/
   VABufferID param_id;
   gpointer param;
   VABufferID data_id;
@@ -73,33 +67,27 @@ gst_vaapi_enc_packed_header_new (GstVaapiEncoder * encoder,
 
 G_GNUC_INTERNAL
 gboolean
-gst_vaapi_enc_packed_header_set_data (GstVaapiEncPackedHeader * packed_header,
+gst_vaapi_enc_packed_header_set_data (GstVaapiEncPackedHeader * header,
     gconstpointer data, guint data_size);
 
 /* ------------------------------------------------------------------------- */
 /* --- Encoder Sequence                                                  --- */
 /* ------------------------------------------------------------------------- */
 
-#define GST_VAAPI_ENC_SEQUENCE_CAST(obj) \
-    ((GstVaapiEncSequence *)(obj))
-
-#define GST_VAAPI_ENC_SEQUENCE(obj)      \
-    GST_VAAPI_ENC_SEQUENCE_CAST(obj)
-
-#define GST_VAAPI_IS_ENC_SEQUENCE(obj)   \
-    (GST_VAAPI_ENC_SEQUENCE(obj) != NULL)
+#define GST_VAAPI_ENC_SEQUENCE(obj) \
+  ((GstVaapiEncSequence *) (obj))
 
 /**
  * GstVaapiEncSequence:
  *
- * A #GstVaapiCodecObject holding a encoder sequence parameter.
+ * A #GstVaapiCodecObject holding a sequence parameter for encoding.
  */
 struct _GstVaapiEncSequence
 {
-  /*< private > */
+  /*< private >*/
   GstVaapiCodecObject parent_instance;
 
-  /*< public > */
+  /*< public >*/
   VABufferID param_id;
   gpointer param;
 };
@@ -113,40 +101,25 @@ gst_vaapi_enc_sequence_new (GstVaapiEncoder * encoder,
 /* --- Encoder Slice                                                     --- */
 /* ------------------------------------------------------------------------- */
 
-#define GST_VAAPI_ENC_SLICE_CAST(obj) \
-    ((GstVaapiEncSlice *)(obj))
-
-#define GST_VAAPI_ENC_SLICE(obj)      \
-    GST_VAAPI_ENC_SLICE_CAST(obj)
-
-#define GST_VAAPI_IS_ENC_SLICE(obj)   \
-    (GST_VAAPI_ENC_SLICE(obj) != NULL)
+#define GST_VAAPI_ENC_SLICE(obj) \
+  ((GstVaapiEncSlice *) (obj))
 
 /**
  * GstVaapiEncSlice:
  *
- * A #GstVaapiCodecObject holding a encoder slice parameter.
+ * A #GstVaapiCodecObject holding a slice parameter used for encoding.
  */
 struct _GstVaapiEncSlice
 {
-  /*< private > */
+  /*< private >*/
   GstVaapiCodecObject parent_instance;
 
-  /*< public > */
+  /*< public >*/
   VABufferID param_id;
   gpointer param;
 };
 
 G_GNUC_INTERNAL
-void
-gst_vaapi_enc_slice_destroy (GstVaapiEncSlice * slice);
-
-G_GNUC_INTERNAL
-gboolean
-gst_vaapi_enc_slice_create (GstVaapiEncSlice * slice,
-    const GstVaapiCodecObjectConstructorArgs * args);
-
-G_GNUC_INTERNAL
 GstVaapiEncSlice *
 gst_vaapi_enc_slice_new (GstVaapiEncoder * encoder,
     gconstpointer param, guint param_size);
@@ -155,48 +128,37 @@ gst_vaapi_enc_slice_new (GstVaapiEncoder * encoder,
 /* --- Encoder Misc Parameter Buffer                                     --- */
 /* ------------------------------------------------------------------------- */
 
-#define GST_VAAPI_ENC_MISC_PARAM_CAST(obj) \
-    ((GstVaapiEncMiscParam *)(obj))
-
-#define GST_VAAPI_ENC_MISC_PARAM(obj)      \
-    GST_VAAPI_ENC_MISC_PARAM_CAST(obj)
-
-#define GST_VAAPI_IS_ENC_MISC_PARAM(obj)   \
-    (GST_VAAPI_ENC_MISC_PARAM(obj) != NULL)
+#define GST_VAAPI_ENC_MISC_PARAM(obj) \
+  ((GstVaapiEncMiscParam *) (obj))
 
 /**
  * GstVaapiEncMiscParam:
  *
- * A #GstVaapiCodecObject holding a encoder misc parameter.
+ * A #GstVaapiCodecObject holding a misc parameter and associated data
+ * used for controlling the encoder dynamically.
  */
 struct _GstVaapiEncMiscParam
 {
-  /*< private > */
+  /*< private >*/
   GstVaapiCodecObject parent_instance;
   gpointer param;
 
-  /*< public > */
+  /*< public >*/
   VABufferID param_id;
-  gpointer impl;
+  gpointer data;
 };
 
 G_GNUC_INTERNAL
 GstVaapiEncMiscParam *
 gst_vaapi_enc_misc_param_new (GstVaapiEncoder * encoder,
-    VAEncMiscParameterType type, guint total_size);
+    VAEncMiscParameterType type, guint data_size);
 
 /* ------------------------------------------------------------------------- */
 /* --- Encoder Picture                                                   --- */
 /* ------------------------------------------------------------------------- */
 
-#define GST_VAAPI_ENC_PICTURE_CAST(obj) \
-    ((GstVaapiEncPicture *)(obj))
-
 #define GST_VAAPI_ENC_PICTURE(obj) \
-    GST_VAAPI_ENC_PICTURE_CAST(obj)
-
-#define GST_VAAPI_IS_ENC_PICTURE(obj) \
-    (GST_VAAPI_ENC_PICTURE(obj) != NULL)
+  ((GstVaapiEncPicture *) (obj))
 
 typedef enum
 {
@@ -212,48 +174,37 @@ typedef enum
 #define GST_VAAPI_ENC_PICTURE_IS_IDR(picture) \
     GST_VAAPI_ENC_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_ENC_PICTURE_FLAG_IDR)
 
-#define GST_VAAPI_ENC_PICTURE_GET_FRAME(picture) \
-    (picture)->frame
-
 /**
  * GstVaapiEncPicture:
  *
- * A #GstVaapiCodecObject holding a picture parameter.
+ * A #GstVaapiCodecObject holding a picture parameter for encoding.
  */
 struct _GstVaapiEncPicture
 {
-  /*< private > */
+  /*< private >*/
   GstVaapiCodecObject parent_instance;
   GstVideoCodecFrame *frame;
   GstVaapiSurfaceProxy *proxy;
   GstVaapiSurface *surface;
-  GstVaapiEncSequence *sequence;
-  /*< private >, picture packed header */
-  GPtrArray *packed_headers;
-  GPtrArray *misc_buffers;
-  GPtrArray *slices;
   VABufferID param_id;
   guint param_size;
 
-  /*< public > */
+  /* Additional data to pass down */
+  GstVaapiEncSequence *sequence;
+  GPtrArray *packed_headers;
+  GPtrArray *misc_params;
+
+  /*< public >*/
   GstVaapiPictureType type;
   VASurfaceID surface_id;
   gpointer param;
+  GPtrArray *slices;
   GstClockTime pts;
   guint frame_num;
   guint poc;
 };
 
 G_GNUC_INTERNAL
-void
-gst_vaapi_enc_picture_destroy (GstVaapiEncPicture * picture);
-
-G_GNUC_INTERNAL
-gboolean
-gst_vaapi_enc_picture_create (GstVaapiEncPicture * picture,
-    const GstVaapiCodecObjectConstructorArgs * args);
-
-G_GNUC_INTERNAL
 GstVaapiEncPicture *
 gst_vaapi_enc_picture_new (GstVaapiEncoder * encoder,
     gconstpointer param, guint param_size, GstVideoCodecFrame * frame);
@@ -270,7 +221,7 @@ gst_vaapi_enc_picture_add_packed_header (GstVaapiEncPicture * picture,
 
 G_GNUC_INTERNAL
 void
-gst_vaapi_enc_picture_add_misc_buffer (GstVaapiEncPicture * picture,
+gst_vaapi_enc_picture_add_misc_param (GstVaapiEncPicture * picture,
     GstVaapiEncMiscParam * misc);
 
 G_GNUC_INTERNAL
@@ -282,47 +233,37 @@ G_GNUC_INTERNAL
 gboolean
 gst_vaapi_enc_picture_encode (GstVaapiEncPicture * picture);
 
-static inline gpointer
-gst_vaapi_enc_picture_ref (gpointer ptr)
-{
-  return gst_vaapi_mini_object_ref (GST_VAAPI_MINI_OBJECT (ptr));
-}
-
-static inline void
-gst_vaapi_enc_picture_unref (gpointer ptr)
-{
-  gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (ptr));
-}
+#define gst_vaapi_enc_picture_ref(picture) \
+  gst_vaapi_codec_object_ref (picture)
+#define gst_vaapi_enc_picture_unref(picture) \
+  gst_vaapi_codec_object_unref (picture)
+#define gst_vaapi_enc_picture_replace(old_picture_ptr, new_picture) \
+  gst_vaapi_codec_object_replace (old_picture_ptr, new_picture)
 
-#define gst_vaapi_enc_picture_replace(old_picture_p, new_picture)       \
-    gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_picture_p), \
-        (GstVaapiMiniObject *)(new_picture))
-
-/* GST_VAAPI_CODED_BUFFER_NEW  */
-#define GST_VAAPI_CODED_BUFFER_NEW(encoder, size)                       \
-        gst_vaapi_coded_buffer_new(GST_VAAPI_ENCODER_CAST(encoder),     \
-                                NULL, size)
+/* ------------------------------------------------------------------------- */
+/* --- Helpers to create codec-dependent objects                         --- */
+/* ------------------------------------------------------------------------- */
 
-/* GST_VAAPI_ENC_SEQUENCE_NEW */
+/* GstVaapiEncSequence */
 #define GST_VAAPI_ENC_SEQUENCE_NEW(codec, encoder)                      \
-        gst_vaapi_enc_sequence_new(GST_VAAPI_ENCODER_CAST(encoder),     \
-                  NULL, sizeof(VAEncSequenceParameterBuffer##codec))
-
-/* GST_VAAPI_ENC_SLICE_NEW */
-#define GST_VAAPI_ENC_SLICE_NEW(codec, encoder)                         \
-        gst_vaapi_enc_slice_new(GST_VAAPI_ENCODER_CAST(encoder),        \
-                   NULL, sizeof(VAEncSliceParameterBuffer##codec))
+  gst_vaapi_enc_sequence_new (GST_VAAPI_ENCODER_CAST (encoder),         \
+      NULL, sizeof (G_PASTE (VAEncSequenceParameterBuffer, codec)))
 
-/* GST_VAAPI_ENC_MISC_PARAM_NEW */
+/* GstVaapiEncMiscParam */
 #define GST_VAAPI_ENC_MISC_PARAM_NEW(type, encoder)                     \
-        gst_vaapi_enc_misc_param_new(GST_VAAPI_ENCODER_CAST(encoder),   \
-           VAEncMiscParameterType##type,                                \
-         (sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameter##type)))
+  gst_vaapi_enc_misc_param_new (GST_VAAPI_ENCODER_CAST (encoder),       \
+      G_PASTE (VAEncMiscParameterType, type),                           \
+      sizeof (G_PASTE (VAEncMiscParameter, type)))
 
-/* GST_VAAPI_ENC_PICTURE_NEW  */
+/* GstVaapiEncPicture  */
 #define GST_VAAPI_ENC_PICTURE_NEW(codec, encoder, frame)                \
-        gst_vaapi_enc_picture_new(GST_VAAPI_ENCODER_CAST(encoder),      \
-            NULL, sizeof(VAEncPictureParameterBuffer##codec), frame)
+  gst_vaapi_enc_picture_new (GST_VAAPI_ENCODER_CAST (encoder),          \
+      NULL, sizeof (G_PASTE (VAEncPictureParameterBuffer, codec)), frame)
+
+/* GstVaapiEncSlice */
+#define GST_VAAPI_ENC_SLICE_NEW(codec, encoder)                         \
+  gst_vaapi_enc_slice_new (GST_VAAPI_ENCODER_CAST (encoder),            \
+      NULL, sizeof(G_PASTE (VAEncSliceParameterBuffer, codec)))
 
 G_END_DECLS
 

-- 
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