[FFmpeg-devel,11/18] cbs_h264, h264_metadata: Deleting SEI messages never fails

Submitted by Andreas Rheinhardt on June 17, 2019, 3:42 a.m.

Details

Message ID 20190617034223.21195-12-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt June 17, 2019, 3:42 a.m.
Deleting a unit from a fragment in CBS only fails if there is no unit
in the fragment corresponding to the position given as argument to
ff_cbs_delete_unit. Given that ff_cbs_h264_delete_sei_message asserts
this to be so, we know that the call to ff_cbs_delete_unit can never
fail and hence ff_cbs_h264_delete_sei_message doesn't need a return
value at all. The existing checks for these return values can be deleted.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/cbs_h264.h          |  8 ++++----
 libavcodec/cbs_h2645.c         | 12 +++++-------
 libavcodec/h264_metadata_bsf.c | 21 +++++----------------
 3 files changed, 14 insertions(+), 27 deletions(-)

Comments

James Almer June 17, 2019, 1 p.m.
On 6/17/2019 12:42 AM, Andreas Rheinhardt wrote:
> Deleting a unit from a fragment in CBS only fails if there is no unit
> in the fragment corresponding to the position given as argument to
> ff_cbs_delete_unit. Given that ff_cbs_h264_delete_sei_message asserts
> this to be so, we know that the call to ff_cbs_delete_unit can never
> fail and hence ff_cbs_h264_delete_sei_message doesn't need a return
> value at all. The existing checks for these return values can be deleted.

Same here. A single line saying it can't fail within the current loop
constrains or something like that should be enough.

> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavcodec/cbs_h264.h          |  8 ++++----
>  libavcodec/cbs_h2645.c         | 12 +++++-------
>  libavcodec/h264_metadata_bsf.c | 21 +++++----------------
>  3 files changed, 14 insertions(+), 27 deletions(-)
> 
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index a31be298ba..f63c19ffc0 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -479,9 +479,9 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
>   * Deletes from nal_unit, which must be an SEI NAL unit.  If this is the
>   * last message in nal_unit, also deletes it from access_unit.
>   */
> -int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
> -                                   CodedBitstreamFragment *access_unit,
> -                                   CodedBitstreamUnit *nal_unit,
> -                                   int position);
> +void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
> +                                    CodedBitstreamFragment *access_unit,
> +                                    CodedBitstreamUnit *nal_unit,
> +                                    int position);
>  
>  #endif /* AVCODEC_CBS_H264_H */
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 0456937710..a3bad83736 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1644,10 +1644,10 @@ int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
>      return 0;
>  }
>  
> -int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
> -                                   CodedBitstreamFragment *au,
> -                                   CodedBitstreamUnit *nal,
> -                                   int position)
> +void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
> +                                    CodedBitstreamFragment *au,
> +                                    CodedBitstreamUnit *nal,
> +                                    int position)
>  {
>      H264RawSEI *sei = nal->content;
>  
> @@ -1664,7 +1664,7 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
>          }
>          av_assert0(i < au->nb_units && "NAL unit not in access unit.");
>  
> -        return ff_cbs_delete_unit(ctx, au, i);
> +        ff_cbs_delete_unit(ctx, au, i);
>      } else {
>          cbs_h264_free_sei_payload(&sei->payload[position]);
>  
> @@ -1672,7 +1672,5 @@ int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
>          memmove(sei->payload + position,
>                  sei->payload + position + 1,
>                  (sei->payload_count - position) * sizeof(*sei->payload));
> -
> -        return 0;
>      }
>  }
> diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
> index d05b75be14..c7969f1152 100644
> --- a/libavcodec/h264_metadata_bsf.c
> +++ b/libavcodec/h264_metadata_bsf.c
> @@ -438,15 +438,9 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
>  
>                  for (j = sei->payload_count - 1; j >= 0; j--) {
>                      if (sei->payload[j].payload_type ==
> -                        H264_SEI_TYPE_FILLER_PAYLOAD) {
> -                        err = ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> -                                                             &au->units[i], j);
> -                        if (err < 0) {
> -                            av_log(bsf, AV_LOG_ERROR, "Failed to delete "
> -                                   "filler SEI message.\n");
> -                            goto fail;
> -                        }
> -                    }
> +                        H264_SEI_TYPE_FILLER_PAYLOAD)
> +                        ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> +                                                       &au->units[i], j);
>                  }
>              }
>          }
> @@ -470,13 +464,8 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
>  
>                  if (ctx->display_orientation == REMOVE ||
>                      ctx->display_orientation == INSERT) {
> -                    err = ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> -                                                         &au->units[i], j);
> -                    if (err < 0) {
> -                        av_log(bsf, AV_LOG_ERROR, "Failed to delete "
> -                               "display orientation SEI message.\n");
> -                        goto fail;
> -                    }
> +                    ff_cbs_h264_delete_sei_message(ctx->cbc, au,
> +                                                   &au->units[i], j);
>                      continue;
>                  }
>  
>

Patch hide | download patch | download mbox

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index a31be298ba..f63c19ffc0 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -479,9 +479,9 @@  int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
  * Deletes from nal_unit, which must be an SEI NAL unit.  If this is the
  * last message in nal_unit, also deletes it from access_unit.
  */
-int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
-                                   CodedBitstreamFragment *access_unit,
-                                   CodedBitstreamUnit *nal_unit,
-                                   int position);
+void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
+                                    CodedBitstreamFragment *access_unit,
+                                    CodedBitstreamUnit *nal_unit,
+                                    int position);
 
 #endif /* AVCODEC_CBS_H264_H */
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 0456937710..a3bad83736 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1644,10 +1644,10 @@  int ff_cbs_h264_add_sei_message(CodedBitstreamContext *ctx,
     return 0;
 }
 
-int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
-                                   CodedBitstreamFragment *au,
-                                   CodedBitstreamUnit *nal,
-                                   int position)
+void ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
+                                    CodedBitstreamFragment *au,
+                                    CodedBitstreamUnit *nal,
+                                    int position)
 {
     H264RawSEI *sei = nal->content;
 
@@ -1664,7 +1664,7 @@  int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
         }
         av_assert0(i < au->nb_units && "NAL unit not in access unit.");
 
-        return ff_cbs_delete_unit(ctx, au, i);
+        ff_cbs_delete_unit(ctx, au, i);
     } else {
         cbs_h264_free_sei_payload(&sei->payload[position]);
 
@@ -1672,7 +1672,5 @@  int ff_cbs_h264_delete_sei_message(CodedBitstreamContext *ctx,
         memmove(sei->payload + position,
                 sei->payload + position + 1,
                 (sei->payload_count - position) * sizeof(*sei->payload));
-
-        return 0;
     }
 }
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index d05b75be14..c7969f1152 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -438,15 +438,9 @@  static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
 
                 for (j = sei->payload_count - 1; j >= 0; j--) {
                     if (sei->payload[j].payload_type ==
-                        H264_SEI_TYPE_FILLER_PAYLOAD) {
-                        err = ff_cbs_h264_delete_sei_message(ctx->cbc, au,
-                                                             &au->units[i], j);
-                        if (err < 0) {
-                            av_log(bsf, AV_LOG_ERROR, "Failed to delete "
-                                   "filler SEI message.\n");
-                            goto fail;
-                        }
-                    }
+                        H264_SEI_TYPE_FILLER_PAYLOAD)
+                        ff_cbs_h264_delete_sei_message(ctx->cbc, au,
+                                                       &au->units[i], j);
                 }
             }
         }
@@ -470,13 +464,8 @@  static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
 
                 if (ctx->display_orientation == REMOVE ||
                     ctx->display_orientation == INSERT) {
-                    err = ff_cbs_h264_delete_sei_message(ctx->cbc, au,
-                                                         &au->units[i], j);
-                    if (err < 0) {
-                        av_log(bsf, AV_LOG_ERROR, "Failed to delete "
-                               "display orientation SEI message.\n");
-                        goto fail;
-                    }
+                    ff_cbs_h264_delete_sei_message(ctx->cbc, au,
+                                                   &au->units[i], j);
                     continue;
                 }