aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2019-11-27 13:22:08 +0100
committerJames Almer <jamrial@gmail.com>2019-11-28 15:20:37 -0300
commitc36a3df67692113af15f7accb006f02956882817 (patch)
tree60577fddd354d23ba870680024be550cf97bf952 /libavformat
parenta31f68fb449eaf6f030ce5633435663f154bb34d (diff)
downloadffmpeg-c36a3df67692113af15f7accb006f02956882817.tar.gz
avformat/avc: Avoid allocation for small SPS/PPS arrays
By using avio_get_dyn_buf() + ffio_free_dyn_buf() instead of avio_close_dyn_buf() + av_free() one can avoid an allocation + copy for small extradata. Furthermore, it simplifies freeing. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/avc.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/libavformat/avc.c b/libavformat/avc.c
index a041e84357..7f9d81825b 100644
--- a/libavformat/avc.c
+++ b/libavformat/avc.c
@@ -25,6 +25,7 @@
#include "avformat.h"
#include "avio.h"
#include "avc.h"
+#include "avio_internal.h"
static const uint8_t *ff_avc_find_startcode_internal(const uint8_t *p, const uint8_t *end)
{
@@ -109,7 +110,7 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
{
AVIOContext *sps_pb = NULL, *pps_pb = NULL;
uint8_t *buf = NULL, *end, *start = NULL;
- uint8_t *sps = NULL, *pps = NULL;
+ uint8_t *sps, *pps;
uint32_t sps_size = 0, pps_size = 0;
int ret, nb_sps = 0, nb_pps = 0;
@@ -164,8 +165,8 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
buf += size;
}
- sps_size = avio_close_dyn_buf(sps_pb, &sps);
- pps_size = avio_close_dyn_buf(pps_pb, &pps);
+ sps_size = avio_get_dyn_buf(sps_pb, &sps);
+ pps_size = avio_get_dyn_buf(pps_pb, &pps);
if (sps_size < 6 || !pps_size) {
ret = AVERROR_INVALIDDATA;
@@ -184,12 +185,8 @@ int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len)
avio_write(pb, pps, pps_size);
fail:
- if (!sps)
- avio_close_dyn_buf(sps_pb, &sps);
- if (!pps)
- avio_close_dyn_buf(pps_pb, &pps);
- av_free(sps);
- av_free(pps);
+ ffio_free_dyn_buf(&sps_pb);
+ ffio_free_dyn_buf(&pps_pb);
av_free(start);
return ret;