summaryrefslogtreecommitdiffstats
path: root/libavcodec/h264_slice.c
diff options
context:
space:
mode:
authorRonald S. Bultje <[email protected]>2017-04-03 10:24:05 -0400
committerMichael Niedermayer <[email protected]>2017-04-13 02:29:26 +0200
commitf4f3bf3c94a9aa485c09d0c03d68ca79a4785866 (patch)
tree91c033db9b6fd121b40c46cd0ef4a5b96cb01eda /libavcodec/h264_slice.c
parent6557ea8e2bd768f5d82bce0fab28262437a292bf (diff)
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) (cherry picked from commit 083300bea935d125b83f60d7030f78a7ffb0f3df) Signed-off-by: Michael Niedermayer <[email protected]>
Diffstat (limited to 'libavcodec/h264_slice.c')
-rw-r--r--libavcodec/h264_slice.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 70ad05f640..acf6a73f60 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1423,14 +1423,14 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl,
* We have to do that before the "dummy" in-between frame allocation,
* since that can modify h->cur_pic_ptr. */
if (h->first_field) {
+ int last_field = last_pic_structure == PICT_BOTTOM_FIELD;
av_assert0(h->cur_pic_ptr);
av_assert0(h->cur_pic_ptr->f->buf[0]);
assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
/* Mark old field/frame as completed */
- if (h->cur_pic_ptr->tf.owner == h->avctx) {
- ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
- last_pic_structure == PICT_BOTTOM_FIELD);
+ if (h->cur_pic_ptr->tf.owner[last_field] == h->avctx) {
+ ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_field);
}
/* figure out if we have a complementary field pair */
@@ -1568,7 +1568,9 @@ static int h264_field_start(H264Context *h, const H264SliceContext *sl,
return AVERROR_INVALIDDATA;
}
} else {
+ int field = h->picture_structure == PICT_BOTTOM_FIELD;
release_unused_pictures(h, 0);
+ h->cur_pic_ptr->tf.owner[field] = h->avctx;
}
/* Some macroblocks can be accessed before they're available in case
* of lost slices, MBAFF or threading. */