summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-07-08 01:14:01 +0200
committerMark Thompson <sw@jkqxz.net>2019-07-08 22:59:41 +0100
commit730e5be3aa1118a63132122dd06aa4f3311af07d (patch)
tree21fee671a0a2538df4ecba1bbf2e48b5c036b23b
parent70a4f46e48da8bc8a547e490f67dde5165227dd8 (diff)
cbs: ff_cbs_delete_unit: Replace return value with assert
ff_cbs_delete_unit never fails if the index of the unit to delete is valid, as it is with all current callers of the function. So just assert in ff_cbs_delete_unit that the index is valid and change the return value to void in order to remove the callers' checks for whether ff_cbs_delete_unit failed. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--libavcodec/av1_metadata_bsf.c9
-rw-r--r--libavcodec/cbs.c12
-rw-r--r--libavcodec/cbs.h8
-rw-r--r--libavcodec/cbs_h2645.c6
-rw-r--r--libavcodec/h264_metadata_bsf.c8
-rw-r--r--libavcodec/h264_redundant_pps_bsf.c4
6 files changed, 17 insertions, 30 deletions
diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
index bb2ca2075b..226f7dffa4 100644
--- a/libavcodec/av1_metadata_bsf.c
+++ b/libavcodec/av1_metadata_bsf.c
@@ -167,13 +167,8 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
if (ctx->delete_padding) {
for (i = frag->nb_units - 1; i >= 0; i--) {
- if (frag->units[i].type == AV1_OBU_PADDING) {
- err = ff_cbs_delete_unit(ctx->cbc, frag, i);
- if (err < 0) {
- av_log(bsf, AV_LOG_ERROR, "Failed to delete Padding OBU.\n");
- goto fail;
- }
- }
+ if (frag->units[i].type == AV1_OBU_PADDING)
+ ff_cbs_delete_unit(ctx->cbc, frag, i);
}
}
diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 47679eca1b..2350416501 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -737,12 +737,12 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
return 0;
}
-int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
- CodedBitstreamFragment *frag,
- int position)
+void ff_cbs_delete_unit(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ int position)
{
- if (position < 0 || position >= frag->nb_units)
- return AVERROR(EINVAL);
+ av_assert0(0 <= position && position < frag->nb_units
+ && "Unit to be deleted not in fragment.");
cbs_unit_uninit(ctx, &frag->units[position]);
@@ -752,6 +752,4 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
memmove(frag->units + position,
frag->units + position + 1,
(frag->nb_units - position) * sizeof(*frag->units));
-
- return 0;
}
diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h
index 5260a39c63..fe57e7b2a5 100644
--- a/libavcodec/cbs.h
+++ b/libavcodec/cbs.h
@@ -380,10 +380,12 @@ int ff_cbs_insert_unit_data(CodedBitstreamContext *ctx,
/**
* Delete a unit from a fragment and free all memory it uses.
+ *
+ * Requires position to be >= 0 and < frag->nb_units.
*/
-int ff_cbs_delete_unit(CodedBitstreamContext *ctx,
- CodedBitstreamFragment *frag,
- int position);
+void ff_cbs_delete_unit(CodedBitstreamContext *ctx,
+ CodedBitstreamFragment *frag,
+ int position);
#endif /* AVCODEC_CBS_H */
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 0456937710..484b145852 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -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,7 @@ 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;
}
+
+ return 0;
}
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index f7ca1f0f09..e40baa3371 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -427,13 +427,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *pkt)
if (ctx->delete_filler) {
for (i = au->nb_units - 1; i >= 0; i--) {
if (au->units[i].type == H264_NAL_FILLER_DATA) {
- // Filler NAL units.
- err = ff_cbs_delete_unit(ctx->cbc, au, i);
- if (err < 0) {
- av_log(bsf, AV_LOG_ERROR, "Failed to delete "
- "filler NAL.\n");
- goto fail;
- }
+ ff_cbs_delete_unit(ctx->cbc, au, i);
continue;
}
diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c
index 907e95b9c8..8405738c4b 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -94,9 +94,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *pkt)
if (!au_has_sps) {
av_log(bsf, AV_LOG_VERBOSE, "Deleting redundant PPS "
"at %"PRId64".\n", pkt->pts);
- err = ff_cbs_delete_unit(ctx->input, au, i);
- if (err < 0)
- goto fail;
+ ff_cbs_delete_unit(ctx->input, au, i);
i--;
continue;
}