]> git.sesse.net Git - ffmpeg/commit
avcodec/frame_thread_encoder: Avoid allocations of AVPackets, fix deadlock
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 7 Feb 2021 12:36:52 +0000 (13:36 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 16 Feb 2021 21:11:53 +0000 (22:11 +0100)
commitfbf242a51d4005a11d1a52dc5d2bff939311c24d
tree70408ab3fb396a9df3a81e8863dcb58078951525
parent2ccbc40eefd22a6aac1e543ea849951e159f4d8a
avcodec/frame_thread_encoder: Avoid allocations of AVPackets, fix deadlock

Up until now, when doing frame thread encoding, each worker thread
tried to allocate an AVPacket for every AVFrame to be encoded; said
packets would then be handed back to the main thread, where the content
of said packet is copied into the packet actually destined for output;
the temporary AVPacket is then freed.

Besides being wasteful this also has another problem: There is a risk of
deadlock, namely if no AVPacket can be allocated at all. The user
doesn't get an error at all in this case and the worker threads will
simply try to allocate a packet again and again. If the user has
supplied enough frames, the user's thread will block until a task has
been completed, which just doesn't happen if no packet can ever be
allocated.

This patch instead modifies the code to allocate the packets during
init; they are then reused again and again.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/frame_thread_encoder.c