History

libavcodec/cbs: Stop needlessly reallocating the units array

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.

Andreas Rheinhardt committed 7 years ago

Commit b8c45bb1 parent c5b452e15 files · +113 −59Browse files

Showing the changes to libavcodec/vaapi_encode_mpeg2.c (1 of 15 files). Show all

Unified · Split

libavcodec/vaapi_encode_mpeg2.c+3−2
@@ -135,7 +135,7 @@ static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, · 134 unmodified lines
135135
136136 err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
137137 fail:
138− ff_cbs_fragment_uninit(priv->cbc, frag);
138+ ff_cbs_fragment_reset(priv->cbc, frag);
139139 return 0;
140140 }
141141
@@ -159,7 +159,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, · 17 unmodified lines
159159
160160 err = vaapi_encode_mpeg2_write_fragment(avctx, data, data_len, frag);
161161 fail:
162− ff_cbs_fragment_uninit(priv->cbc, frag);
162+ ff_cbs_fragment_reset(priv->cbc, frag);
163163 return 0;
164164 }
165165
@@ -628,6 +628,7 @@ static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx) · 462 unmodified lines
628628 {
629629 VAAPIEncodeMPEG2Context *priv = avctx->priv_data;
630630
631+ ff_cbs_fragment_free(priv->cbc, &priv->current_fragment);
631632 ff_cbs_close(&priv->cbc);
632633
633634 return ff_vaapi_encode_close(avctx);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t