[FFmpeg-devel] [PATCH 11/12] avformat/hevc: Clarify documentation of filter_ps

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sat Jan 25 00:48:32 EET 2020


and use it to avoid unnecessary initializations and frees in
ff_hevc_annexb2mp4() and ff_hevc_annexb2mp4_buf(): Even if the caller
does not want to strip HEVC parameter sets away when converting from
Annex B to mp4, a pointer has been initialized to NULL and later freed
while still being NULL despite having not been used at all.

The reason for this is that there is still a jump to the end of the
function in order to set a variable (returned via a pointer argument)
containing the number of parameter set NAL units stripped away to zero.
But if the caller does not want to strip these parameter sets away, it
is pointless to set this variable. Document this behaviour and remove
the jump.

Also document that said number won't be set on error (in case of
ff_hevc_annexb2mp4_buf(), this was actually the behaviour anyway) and
remove the jump to the end on error, too; this also allows to avoid
initializing the pointer mentioned above.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/hevc.c |  8 +++-----
 libavformat/hevc.h | 14 ++++++++------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libavformat/hevc.c b/libavformat/hevc.c
index 616e9ed49a..b07897d9a5 100644
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -1000,16 +1000,15 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
                        int size, int filter_ps, int *ps_count)
 {
     int num_ps = 0, ret = 0;
-    uint8_t *buf, *end, *start = NULL;
+    uint8_t *buf, *end, *start;
 
     if (!filter_ps) {
-        ret = ff_avc_parse_nal_units(pb, buf_in, size);
-        goto end;
+        return ff_avc_parse_nal_units(pb, buf_in, size);
     }
 
     ret = ff_avc_parse_nal_units_buf(buf_in, &start, &size);
     if (ret < 0)
-        goto end;
+        return ret;
 
     ret = 0;
     buf = start;
@@ -1037,7 +1036,6 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
         buf += len;
     }
 
-end:
     av_free(start);
     if (ps_count)
         *ps_count = num_ps;
diff --git a/libavformat/hevc.h b/libavformat/hevc.h
index 0f56325c1c..3ff4614022 100644
--- a/libavformat/hevc.h
+++ b/libavformat/hevc.h
@@ -42,9 +42,10 @@
  * @param buf_in address of the buffer holding the input data
  * @param size size (in bytes) of the input buffer
  * @param filter_ps whether to write parameter set NAL units to the output (0)
- *        or to discard them (non-zero)
- * @param ps_count address of the variable where the number of discarded
- *        parameter set NAL units shall be written, may be NULL
+ *        or to count but discard them (non-zero)
+ * @param ps_count if filter_ps is nonzero, address of the variable where the
+ *        number of discarded parameter set NAL units shall be written
+ *        on success; otherwise ignored; may be NULL
  * @return the amount (in bytes) of data written in case of success, a negative
  *         value corresponding to an AVERROR code in case of failure
  */
@@ -68,9 +69,10 @@ int ff_hevc_annexb2mp4(AVIOContext *pb, const uint8_t *buf_in,
  * @param buf_out on success, address of the variable holding the address of
  *        the output buffer
  * @param filter_ps whether to write parameter set NAL units to the output (0)
- *        or to discard them (non-zero)
- * @param ps_count address of the variable where the number of discarded
- *        parameter set NAL units shall be written, may be NULL
+ *        or to count but discard them (non-zero)
+ * @param ps_count if filter_ps is nonzero, address of the variable where the
+ *        number of discarded parameter set NAL units shall be written
+ *        on success; otherwise ignored; may be NULL
  * @return 0 in case of success, a negative value corresponding to an AVERROR
  *         code in case of failure
  * @note *buf_out will be treated as uninitialized on input and won't be freed.
-- 
2.20.1



More information about the ffmpeg-devel mailing list