[FFmpeg-devel] [PATCH 16/36] avcodec/mjpega_dump_header_bsf: Only allocate when necessary
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sat May 30 19:05:21 EEST 2020
This avoids having to free a buffer that hasn't been used at all.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/mjpega_dump_header_bsf.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c
index 1cd2b48719..4608fe550b 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -42,6 +42,13 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out)
if (ret < 0)
return ret;
+ for (i = 0; i < in->size - 3; i++) {
+ if (in->data[i] == 0xff) {
+ switch (in->data[i + 1]) {
+ case DQT: dqt = i + 46U; break;
+ case DHT: dht = i + 46U; break;
+ case SOF0: sof0 = i + 46U; break;
+ case SOS:
ret = av_new_packet(out, in->size + 44U);
if (ret < 0)
goto fail;
@@ -61,14 +68,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out)
bytestream_put_be32(&out_buf, in->size + 44U); /* field size */
bytestream_put_be32(&out_buf, in->size + 44U); /* pad field size */
bytestream_put_be32(&out_buf, 0); /* next ptr */
-
- for (i = 0; i < in->size - 3; i++) {
- if (in->data[i] == 0xff) {
- switch (in->data[i + 1]) {
- case DQT: dqt = i + 46U; break;
- case DHT: dht = i + 46U; break;
- case SOF0: sof0 = i + 46U; break;
- case SOS:
bytestream_put_be32(&out_buf, dqt); /* quant off */
bytestream_put_be32(&out_buf, dht); /* huff off */
bytestream_put_be32(&out_buf, sof0); /* image off */
@@ -82,7 +81,6 @@ static int mjpega_dump_header(AVBSFContext *ctx, AVPacket *out)
case APP1:
if (i + 12U <= in->size && AV_RL32(in->data + i + 8) == AV_RL32("mjpg")) {
av_log(ctx, AV_LOG_ERROR, "bitstream already formatted\n");
- av_packet_unref(out);
av_packet_move_ref(out, in);
av_packet_free(&in);
return 0;
--
2.20.1
More information about the ffmpeg-devel
mailing list