mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-12-12 01:40:04 +01:00
pthread_frame: allow per-field ThreadFrame owners.
This tries to handle cases where separate invocations of decode_frame()
(each running in separate threads) write to respective fields in the
same AVFrame->data[]. Having per-field owners makes interaction between
readers (the referencing thread) and writers (the decoding thread)
slightly more optimal if both accesses are field-based, since they will
use the respective producer's thread objects (mutex/cond) instead of
sharing the thread objects of the first field's producer.
In practice, this fixes the following tsan-warning in fate-h264:
WARNING: ThreadSanitizer: data race (pid=21615)
Read of size 4 at 0x7d640000d9fc by thread T2 (mutexes: write M1006):
#0 ff_thread_report_progress pthread_frame.c:569 (ffmpeg:x86_64+0x100f7cf54)
[..]
Previous write of size 4 at 0x7d640000d9fc by main thread (mutexes: write M1004):
#0 update_context_from_user pthread_frame.c:335 (ffmpeg:x86_64+0x100f81abb)
This commit is contained in:
@@ -3971,7 +3971,8 @@ int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
|
||||
{
|
||||
int ret;
|
||||
|
||||
dst->owner = src->owner;
|
||||
dst->owner[0] = src->owner[0];
|
||||
dst->owner[1] = src->owner[1];
|
||||
|
||||
ret = av_frame_ref(dst->f, src->f);
|
||||
if (ret < 0)
|
||||
@@ -3981,7 +3982,7 @@ int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
|
||||
|
||||
if (src->progress &&
|
||||
!(dst->progress = av_buffer_ref(src->progress))) {
|
||||
ff_thread_release_buffer(dst->owner, dst);
|
||||
ff_thread_release_buffer(dst->owner[0], dst);
|
||||
return AVERROR(ENOMEM);
|
||||
}
|
||||
|
||||
@@ -3997,7 +3998,7 @@ enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixe
|
||||
|
||||
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
|
||||
{
|
||||
f->owner = avctx;
|
||||
f->owner[0] = f->owner[1] = avctx;
|
||||
return ff_get_buffer(avctx, f->f, flags);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user