Currently, a fragment's unit array is constantly reallocated during splitting of a packet. This commit changes this: One can keep the units array by distinguishing between the number of allocated and the number of valid units in the units array. 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.
Showing the changes to libavcodec/vaapi_encode_mpeg2.c (1 of 15 files). Show all
Unified · Split
| @@ -135,7 +135,7 @@ static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, · 134 unmodified lines | |||
| 135 | 135 | ||
| 136 | err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); | 136 | err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); |
| 137 | fail: | 137 | fail: |
| 138 | ff_cbs_fragment_uninit(priv->cbc, frag); | 138 | ff_cbs_fragment_reset(priv->cbc, frag); |
| 139 | return 0; | 139 | return 0; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| @@ -159,7 +159,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, · 17 unmodified lines | |||
| 159 | 159 | ||
| 160 | err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); | 160 | err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag); |
| 161 | fail: | 161 | fail: |
| 162 | ff_cbs_fragment_uninit(priv->cbc, frag); | 162 | ff_cbs_fragment_reset(priv->cbc, frag); |
| 163 | return 0; | 163 | return 0; |
| 164 | } | 164 | } |
| 165 | 165 | ||
| @@ -628,6 +628,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx) · 462 unmodified lines | |||
| 628 | { | 628 | { |
| 629 | VAAPIEncodeMPEG2Context *priv = avctx->priv_data; | 629 | VAAPIEncodeMPEG2Context *priv = avctx->priv_data; |
| 630 | 630 | ||
| 631 | ff_cbs_fragment_free(priv->cbc, &priv->current_fragment); | ||
| 631 | ff_cbs_close(&priv->cbc); | 632 | ff_cbs_close(&priv->cbc); |
| 632 | 633 | ||
| 633 | return ff_vaapi_encode_close(avctx); | 634 | return ff_vaapi_encode_close(avctx); |