[FFmpeg-devel] [PATCH 34/36] avcodec/dump_extradata_bsf: Remove intermediate packet
Andreas Rheinhardt
andreas.rheinhardt at gmail.com
Sat May 30 19:05:39 EEST 2020
This commit ends using separate packets for in- and output. Instead,
the input is read directly into the packet destined for output via
ff_bsf_get_packet_ref() and only the buffer-related fields are modified;
the others are not touched.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
libavcodec/dump_extradata_bsf.c | 33 ++++++++++++++-------------------
1 file changed, 14 insertions(+), 19 deletions(-)
diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index be5e23ba5b..5df7e064cf 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -33,49 +33,44 @@ enum DumpFreq {
typedef struct DumpExtradataContext {
const AVClass *class;
- AVPacket pkt;
int freq;
} DumpExtradataContext;
-static int dump_extradata(AVBSFContext *ctx, AVPacket *out)
+static int dump_extradata(AVBSFContext *ctx, AVPacket *pkt)
{
DumpExtradataContext *s = ctx->priv_data;
const AVCodecParameters *par;
- AVPacket *in = &s->pkt;
int ret = 0;
- ret = ff_bsf_get_packet_ref(ctx, in);
+ ret = ff_bsf_get_packet_ref(ctx, pkt);
if (ret < 0)
return ret;
if ((par = ctx->par_in)->extradata_size &&
(s->freq == DUMP_FREQ_ALL ||
- (s->freq == DUMP_FREQ_KEYFRAME && in->flags & AV_PKT_FLAG_KEY)) &&
- (in->size < par->extradata_size ||
- memcmp(in->data, par->extradata, par->extradata_size))) {
- if (in->size >= INT_MAX - par->extradata_size) {
+ (s->freq == DUMP_FREQ_KEYFRAME && pkt->flags & AV_PKT_FLAG_KEY)) &&
+ (pkt->size < par->extradata_size ||
+ memcmp(pkt->data, par->extradata, par->extradata_size))) {
+ AVBufferRef *out = NULL;
+
+ if (pkt->size >= INT_MAX - par->extradata_size) {
ret = AVERROR(ERANGE);
goto fail;
}
- ret = av_new_packet(out, in->size + par->extradata_size);
+ ret = ff_buffer_padded_realloc(&out, pkt->size + par->extradata_size);
if (ret < 0)
goto fail;
- ret = av_packet_copy_props(out, in);
- if (ret < 0) {
- av_packet_unref(out);
- goto fail;
- }
-
memcpy(out->data, par->extradata, par->extradata_size);
- memcpy(out->data + par->extradata_size, in->data, in->size);
- } else {
- av_packet_move_ref(out, in);
+ memcpy(out->data + par->extradata_size, pkt->data, pkt->size);
+
+ ff_packet_replace_buffer(pkt, out);
}
fail:
- av_packet_unref(in);
+ if (ret < 0)
+ av_packet_unref(pkt);
return ret;
}
--
2.20.1
More information about the ffmpeg-devel
mailing list