@@ -170,7 +170,7 @@ static int av1_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
if (err < 0)
av_packet_unref(out);
@@ -215,13 +215,15 @@ static int av1_metadata_init(AVBSFContext *bsf)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
return err;
}
static void av1_metadata_close(AVBSFContext *bsf)
{
AV1MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->access_unit, 1);
ff_cbs_close(&ctx->cbc);
}
@@ -72,7 +72,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
goto end;
}
- ff_cbs_fragment_uninit(s->cbc, td, 1);
+ ff_cbs_fragment_uninit(s->cbc, td, 0);
}
ret = ff_cbs_read(s->cbc, td, data, size, 1);
@@ -159,7 +159,7 @@ static int av1_parser_parse(AVCodecParserContext *ctx,
}
end:
- ff_cbs_fragment_uninit(s->cbc, td, 1);
+ ff_cbs_fragment_uninit(s->cbc, td, 0);
s->cbc->log_ctx = NULL;
@@ -193,6 +193,7 @@ static void av1_parser_close(AVCodecParserContext *ctx)
{
AV1ParseContext *s = ctx->priv_data;
+ ff_cbs_fragment_uninit(s->cbc, &s->temporal_unit, 1);
ff_cbs_close(&s->cbc);
}
@@ -139,7 +139,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out)
// Don't return packets with nothing in them.
av_packet_free(&in);
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
}
err = ff_cbs_write_packet(ctx->cbc, out, frag);
@@ -153,7 +153,7 @@ static int filter_units_filter(AVBSFContext *bsf, AVPacket *out)
goto fail;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
av_packet_free(&in);
return err;
@@ -199,18 +199,18 @@ static int filter_units_init(AVBSFContext *bsf)
ctx->cbc->nb_decompose_unit_types = 0;
if (bsf->par_in->extradata) {
- CodedBitstreamFragment ps;
+ CodedBitstreamFragment *frag = &ctx->fragment;
- err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in, 0);
+ err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in, 1);
if (err < 0) {
av_log(bsf, AV_LOG_ERROR, "Failed to read extradata.\n");
} else {
- err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, &ps);
+ err = ff_cbs_write_extradata(ctx->cbc, bsf->par_out, frag);
if (err < 0)
av_log(bsf, AV_LOG_ERROR, "Failed to write extradata.\n");
}
- ff_cbs_fragment_uninit(ctx->cbc, &ps, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
}
return err;
@@ -222,6 +222,7 @@ static void filter_units_close(AVBSFContext *bsf)
av_freep(&ctx->type_list);
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->fragment, 1);
ff_cbs_close(&ctx->cbc);
}
@@ -604,7 +604,7 @@ static int h264_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, au, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, au, 0);
av_freep(&displaymatrix_side_data);
if (err < 0)
@@ -648,13 +648,15 @@ static int h264_metadata_init(AVBSFContext *bsf)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, au, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, au, 0);
return err;
}
static void h264_metadata_close(AVBSFContext *bsf)
{
H264MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->access_unit, 1);
ff_cbs_close(&ctx->cbc);
}
@@ -118,7 +118,7 @@ static int h264_redundant_pps_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->output, au, 1);
+ ff_cbs_fragment_uninit(ctx->output, au, 0);
av_packet_free(&in);
if (err < 0)
av_packet_unref(out);
@@ -167,7 +167,7 @@ static int h264_redundant_pps_init(AVBSFContext *bsf)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->output, au, 1);
+ ff_cbs_fragment_uninit(ctx->output, au, 0);
return err;
}
@@ -180,6 +180,8 @@ static void h264_redundant_pps_flush(AVBSFContext *bsf)
static void h264_redundant_pps_close(AVBSFContext *bsf)
{
H264RedundantPPSContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->output, &ctx->access_unit, 1);
ff_cbs_close(&ctx->input);
ff_cbs_close(&ctx->output);
}
@@ -322,7 +322,7 @@ static int h265_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, au, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, au, 0);
if (err < 0)
av_packet_unref(out);
@@ -370,13 +370,15 @@ static int h265_metadata_init(AVBSFContext *bsf)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, au, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, au, 0);
return err;
}
static void h265_metadata_close(AVBSFContext *bsf)
{
H265MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->access_unit, 1);
ff_cbs_close(&ctx->cbc);
}
@@ -214,7 +214,7 @@ static int mpeg2_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
if (err < 0)
av_packet_unref(out);
@@ -255,13 +255,15 @@ static int mpeg2_metadata_init(AVBSFContext *bsf)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
return err;
}
static void mpeg2_metadata_close(AVBSFContext *bsf)
{
MPEG2MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->fragment, 1);
ff_cbs_close(&ctx->cbc);
}
@@ -28,6 +28,7 @@
typedef struct TraceHeadersContext {
CodedBitstreamContext *cbc;
+ CodedBitstreamFragment fragment;
} TraceHeadersContext;
@@ -44,13 +45,13 @@ static int trace_headers_init(AVBSFContext *bsf)
ctx->cbc->trace_level = AV_LOG_INFO;
if (bsf->par_in->extradata) {
- CodedBitstreamFragment ps;
+ CodedBitstreamFragment *frag = &ctx->fragment;
av_log(bsf, AV_LOG_INFO, "Extradata\n");
- err = ff_cbs_read_extradata(ctx->cbc, &ps, bsf->par_in, 0);
+ err = ff_cbs_read_extradata(ctx->cbc, frag, bsf->par_in, 1);
- ff_cbs_fragment_uninit(ctx->cbc, &ps, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
}
return err;
@@ -60,13 +61,14 @@ static void trace_headers_close(AVBSFContext *bsf)
{
TraceHeadersContext *ctx = bsf->priv_data;
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->fragment, 1);
ff_cbs_close(&ctx->cbc);
}
static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
{
TraceHeadersContext *ctx = bsf->priv_data;
- CodedBitstreamFragment au;
+ CodedBitstreamFragment *frag = &ctx->fragment;
char tmp[256] = { 0 };
int err;
@@ -92,9 +94,9 @@ static int trace_headers(AVBSFContext *bsf, AVPacket *pkt)
av_log(bsf, AV_LOG_INFO, "Packet: %d bytes%s.\n", pkt->size, tmp);
- err = ff_cbs_read_packet(ctx->cbc, &au, pkt, 0);
+ err = ff_cbs_read_packet(ctx->cbc, frag, pkt, 1);
- ff_cbs_fragment_uninit(ctx->cbc, &au, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
if (err < 0)
av_packet_unref(pkt);
@@ -86,7 +86,7 @@ static int vp9_metadata_filter(AVBSFContext *bsf, AVPacket *out)
err = 0;
fail:
- ff_cbs_fragment_uninit(ctx->cbc, frag, 1);
+ ff_cbs_fragment_uninit(ctx->cbc, frag, 0);
if (err < 0)
av_packet_unref(out);
@@ -105,6 +105,8 @@ static int vp9_metadata_init(AVBSFContext *bsf)
static void vp9_metadata_close(AVBSFContext *bsf)
{
VP9MetadataContext *ctx = bsf->priv_data;
+
+ ff_cbs_fragment_uninit(ctx->cbc, &ctx->fragment, 1);
ff_cbs_close(&ctx->cbc);
}
This commit changes various places that make use of cbs to keep the fragments' unit arrays instead of constantly reallocating them. The more units a packet is split into, the bigger the benefit. So MPEG-2 benefits the most; for a video coming from an NTSC-DVD (usually 32 units per frame) the average cost of cbs_insert_unit (for a single unit) went down from 6717 decicycles to 450 decicycles (based upon 10 runs with 4194304 runs each); if each packet consists of only one unit, it went down from 2425 to 448; for a H.264 video where most packets contain nine units, it went from 4431 to 450. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com> --- libavcodec/av1_metadata_bsf.c | 6 ++++-- libavcodec/av1_parser.c | 5 +++-- libavcodec/filter_units_bsf.c | 13 +++++++------ libavcodec/h264_metadata_bsf.c | 6 ++++-- libavcodec/h264_redundant_pps_bsf.c | 6 ++++-- libavcodec/h265_metadata_bsf.c | 6 ++++-- libavcodec/mpeg2_metadata_bsf.c | 6 ++++-- libavcodec/trace_headers_bsf.c | 14 ++++++++------ libavcodec/vp9_metadata_bsf.c | 4 +++- 9 files changed, 41 insertions(+), 25 deletions(-)