libs: decoder: h264, h266: fix g_return_val_if_fail() missuse
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sat, 21 Sep 2019 11:39:42 +0000 (13:39 +0200)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 27 Sep 2019 08:53:14 +0000 (10:53 +0200)
g_return_val_fail() documentations says:

  If expr evaluates to FALSE, the current function should be
  considered to have undefined behaviour (a programmer error).
  The only correct solution to such an error is to change the
  module that is calling the current function, so that it avoids
  this incorrect call.

So it was missused in a couple parts of the H264 and H265 internal
decoders. This patch changes that to plain conditionals.

Also, it was included a couple code-style fixes.

gst-libs/gst/vaapi/gstvaapidecoder_h264.c
gst-libs/gst/vaapi/gstvaapidecoder_h265.c

index b724184..b20e727 100644 (file)
@@ -369,10 +369,15 @@ gst_vaapi_frame_store_add (GstVaapiFrameStore * fs,
 
   field = picture->structure == GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD ?
       TOP_FIELD : BOTTOM_FIELD;
-  g_return_val_if_fail (fs->buffers[0]->field_poc[field] == G_MAXINT32, FALSE);
+
+  if (fs->buffers[0]->field_poc[field] != G_MAXINT32)
+    return FALSE;
   fs->buffers[0]->field_poc[field] = picture->field_poc[field];
-  g_return_val_if_fail (picture->field_poc[!field] == G_MAXINT32, FALSE);
+
+  if (picture->field_poc[!field] != G_MAXINT32)
+    return FALSE;
   picture->field_poc[!field] = fs->buffers[0]->field_poc[!field];
+
   return TRUE;
 }
 
@@ -744,7 +749,8 @@ dpb_output (GstVaapiDecoderH264 * decoder, GstVaapiFrameStore * fs)
 
   for (i = 0; i < fs->num_buffers; i++) {
     GstVaapiPictureH264 *const pic = fs->buffers[i];
-    g_return_val_if_fail (pic != NULL, FALSE);
+    if (pic == NULL)
+      return FALSE;
     pic->output_needed = FALSE;
     if (!GST_VAAPI_PICTURE_FLAG_IS_SET (pic, GST_VAAPI_PICTURE_FLAG_GHOST))
       picture = pic;
@@ -3994,8 +4000,8 @@ decode_picture (GstVaapiDecoderH264 * decoder, GstVaapiDecoderUnit * unit)
   GstVaapiPictureH264 *picture, *first_field;
   GstVaapiDecoderStatus status;
 
-  g_return_val_if_fail (pps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
-  g_return_val_if_fail (sps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
+  if (!(pps && sps))
+    return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
 
   status = ensure_context (decoder, sps);
   if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
index 7a5a2e6..a04c74b 100644 (file)
@@ -676,7 +676,8 @@ dpb_output (GstVaapiDecoderH265 * decoder, GstVaapiFrameStore * fs)
   g_return_val_if_fail (fs != NULL, FALSE);
 
   picture = fs->buffer;
-  g_return_val_if_fail (picture != NULL, FALSE);
+  if (!picture)
+    return FALSE;
 
   picture->output_needed = FALSE;
   return gst_vaapi_picture_output (GST_VAAPI_PICTURE_CAST (picture));
@@ -1630,8 +1631,8 @@ init_picture_refs (GstVaapiDecoderH265 * decoder,
 {
   GstVaapiDecoderH265Private *const priv = &decoder->priv;
   guint32 NumRpsCurrTempList0 = 0, NumRpsCurrTempList1 = 0;
-  GstVaapiPictureH265 *RefPicListTemp0[16] = { NULL, }, *RefPicListTemp1[16] = {
-  NULL,};
+  GstVaapiPictureH265 *RefPicListTemp0[16] = { NULL, };
+  GstVaapiPictureH265 *RefPicListTemp1[16] = { NULL, };
   guint i, rIdx = 0;
   guint num_ref_idx_l0_active_minus1 = 0;
   guint num_ref_idx_l1_active_minus1 = 0;
@@ -2208,9 +2209,9 @@ decode_ref_pic_set (GstVaapiDecoderH265 * decoder,
     priv->NumPocLtCurr = priv->NumPocLtFoll = 0;
   } else {
     GstH265ShortTermRefPicSet *stRefPic = NULL;
-    gint32 num_lt_pics, pocLt, PocLsbLt[16] = { 0, }
-    , UsedByCurrPicLt[16] = {
-    0,};
+    gint32 num_lt_pics, pocLt;
+    gint32 PocLsbLt[16] = { 0, };
+    gint32 UsedByCurrPicLt[16] = { 0, };
     gint32 DeltaPocMsbCycleLt[16] = { 0, };
     gint numtotalcurr = 0;
 
@@ -2306,8 +2307,8 @@ decode_picture (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
   GstVaapiPictureH265 *picture;
   GstVaapiDecoderStatus status;
 
-  g_return_val_if_fail (pps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
-  g_return_val_if_fail (sps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
+  if (!(pps && sps))
+    return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
 
   status = ensure_context (decoder, sps);
   if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)