Use avio_get_dyn_buf()+ffio_free_dyn_buf() instead of
avio_close_dyn_buf()+av_free(). This saves an allocation
(and memcpy) in case all the data fits in the AVIOContext's
write buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>
---
 libavformat/iamf_writer.c | 12 ++++++------
 libavformat/iamfenc.c     |  8 ++++----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libavformat/iamf_writer.c b/libavformat/iamf_writer.c
index f665f45b7a..5850c53c8e 100644
--- a/libavformat/iamf_writer.c
+++ b/libavformat/iamf_writer.c
@@ -453,11 +453,11 @@ static int iamf_write_codec_config(const IAMFContext 
*iamf,
     put_bits(&pbc, 3, 0);
     flush_put_bits(&pbc);
 
-    dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    dyn_size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     avio_write(pb, header, put_bytes_count(&pbc, 1));
     ffio_write_leb(pb, dyn_size);
     avio_write(pb, dyn_buf, dyn_size);
-    av_free(dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
 
     return 0;
 }
@@ -660,11 +660,11 @@ static int iamf_write_audio_element(const IAMFContext 
*iamf,
     put_bits(&pbc, 3, 0);
     flush_put_bits(&pbc);
 
-    dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    dyn_size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     avio_write(pb, header, put_bytes_count(&pbc, 1));
     ffio_write_leb(pb, dyn_size);
     avio_write(pb, dyn_buf, dyn_size);
-    av_free(dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
 
     return 0;
 }
@@ -796,11 +796,11 @@ static int iamf_write_mixing_presentation(const 
IAMFContext *iamf,
     put_bits(&pbc, 3, 0);
     flush_put_bits(&pbc);
 
-    dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    dyn_size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     avio_write(pb, header, put_bytes_count(&pbc, 1));
     ffio_write_leb(pb, dyn_size);
     avio_write(pb, dyn_buf, dyn_size);
-    av_free(dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
 
     return 0;
 }
diff --git a/libavformat/iamfenc.c b/libavformat/iamfenc.c
index a02f84035a..e1003d5495 100644
--- a/libavformat/iamfenc.c
+++ b/libavformat/iamfenc.c
@@ -257,10 +257,10 @@ static int write_parameter_block(AVFormatContext *s, 
const AVIAMFParamDefinition
         }
     }
 
-    dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    dyn_size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     ffio_write_leb(s->pb, dyn_size);
     avio_write(s->pb, dyn_buf, dyn_size);
-    av_free(dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
 
     return 0;
 }
@@ -340,10 +340,10 @@ static int iamf_write_packet(AVFormatContext *s, AVPacket 
*pkt)
     if (st->id > 17)
         ffio_write_leb(dyn_bc, st->id);
 
-    dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    dyn_size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     ffio_write_leb(s->pb, dyn_size + pkt->size);
     avio_write(s->pb, dyn_buf, dyn_size);
-    av_free(dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
     avio_write(s->pb, pkt->data, pkt->size);
 
     return 0;
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to