[FFmpeg-devel] [PATCH, RFC, v2] lavc/phtread_frame: update context in child thread in multi-thread mode

Michael Niedermayer michael at niedermayer.cc
Wed Jun 26 19:28:48 EEST 2019


On Wed, Jun 26, 2019 at 04:24:52PM -0400, Linjie Fu wrote:
> Currently in ff_thread_decode_frame, context is updated from child thread
> to main thread, and main thread releases the context in avcodec_close()
> when decode finishes.
> 
> However, when resolution/format change in vp9, ff_get_format was called,
> and hwaccel_uninit() and hwaccel_init will be used to destroy and re-create
> the context. Due to the async between main-thread and child-thread,
> main-thread updated its context from child earlier than the context was
> refreshed in child-thread. And it will lead to:
>     1. memory leak in child-thread.
>     2. double free in main-thread while calling avcodec_close().
> 
> Can be reproduced with a resolution change case in vp9, and use -vframes
> to terminate the decode between the dynamic resolution change frames:
> 
> ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 -v
> verbose -i ./test2360_1672_4980.ivf -pix_fmt p010le -f rawvideo -vsync
> passthrough -vframes 6 -y out.yuv
> 
> Move update_context_from_thread from ff_thread_decode_frame(main thread)
> to frame_worker_thread(child thread), update the context in child thread
> right after the context was updated to avoid the async issue.
> 
> Signed-off-by: Linjie Fu <linjie.fu at intel.com>
> ---
> Request for Comments, not quite familiar with the constraints.
> Thanks in advance.

i dont think i fully understand the problem you are trying to fix but
this patch looks like it writes into the users context without any
lock while the user can access it.
Thats looks like a race condition unless iam missing something

What is very noticable though is that you seem to talk about vp9
why is this vp9 specific and does not affect other codecs ?

thanks

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The real ebay dictionary, page 2
"100% positive feedback" - "All either got their money back or didnt complain"
"Best seller ever, very honest" - "Seller refunded buyer after failed scam"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190626/6f9f4bac/attachment.sig>


More information about the ffmpeg-devel mailing list