History

avcodec/error_resilience: Make applying decode_error_flags optional

Add a pointer parameter that if supplied will be used to return the updated decode_error_flags. This will allow to fix several races when using frame-threading; these resulted from AVFrame that the earlier code updated concurrently being used as source in an av_frame_ref() call in the decoder's update_thread_context.

Andreas Rheinhardt committed 3 years ago

Commit d2bc0391 parent 4f4dc0a9 files · +26 −13Browse files

Unified · Split

9 files
  1. libavcodec/error_resilience.c +5 −2
  2. libavcodec/error_resilience.h +11 −1
  3. libavcodec/h263dec.c +1 −1
  4. libavcodec/h264dec.c +1 −1
  5. libavcodec/mpeg12dec.c +1 −1
  6. libavcodec/mss2.c +1 −1
  7. libavcodec/rv10.c +2 −2
  8. libavcodec/rv34.c +3 −3
  9. libavcodec/vc1dec.c +1 −1
libavcodec/error_resilience.c+5−2
@@ -889,7 +889,7 @@ void ff_er_add_slice(ERContext *s, int startx, int starty, · 888 unmodified lines
889 }889 }
890}890}
891 891
892void ff_er_frame_end(ERContext *s)892void ff_er_frame_end(ERContext *s, int *decode_error_flags)
893{893{
894 int *linesize = NULL;894 int *linesize = NULL;
895 int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;895 int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
@@ -1114,7 +1114,10 @@ void ff_er_frame_end(ERContext *s) · 218 unmodified lines
1114 av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n",1114 av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n",
1115 dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type));1115 dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type));
1116 1116
1117 s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;1117 if (decode_error_flags)
1118 *decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
1119 else
1120 s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE;
1118 1121
1119 is_intra_likely = is_intra_more_likely(s);1122 is_intra_likely = is_intra_more_likely(s);
1120 1123
libavcodec/error_resilience.h+11−1
@@ -90,7 +90,17 @@ typedef struct ERContext { · 89 unmodified lines
90} ERContext;90} ERContext;
91 91
92void ff_er_frame_start(ERContext *s);92void ff_er_frame_start(ERContext *s);
93void ff_er_frame_end(ERContext *s);93
94/**
95 * Indicate that a frame has finished decoding and perform error concealment
96 * in case it has been enabled and is necessary and supported.
97 *
98 * @param s ERContext in use
99 * @param decode_error_flags pointer where updated decode_error_flags are written
100 * if supplied; if not, the new flags are directly
101 * applied to the AVFrame whose errors are concealed
102 */
103void ff_er_frame_end(ERContext *s, int *decode_error_flags);
94void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy,104void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy,
95 int status);105 int status);
96 106
libavcodec/h263dec.c+1−1
@@ -622,7 +622,7 @@ retry: · 621 unmodified lines
622 av_assert1(s->bitstream_buffer_size == 0);622 av_assert1(s->bitstream_buffer_size == 0);
623frame_end:623frame_end:
624 if (!s->studio_profile)624 if (!s->studio_profile)
625 ff_er_frame_end(&s->er);625 ff_er_frame_end(&s->er, NULL);
626 626
627 if (avctx->hwaccel) {627 if (avctx->hwaccel) {
628 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);628 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
libavcodec/h264dec.c+1−1
@@ -779,7 +779,7 @@ end: · 778 unmodified lines
779 if (sl->ref_count[1])779 if (sl->ref_count[1])
780 ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);780 ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);
781 781
782 ff_er_frame_end(&h->er);782 ff_er_frame_end(&h->er, NULL);
783 if (use_last_pic)783 if (use_last_pic)
784 memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));784 memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
785 }785 }
libavcodec/mpeg12dec.c+1−1
@@ -2033,7 +2033,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) · 2032 unmodified lines
2033 if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {2033 if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {
2034 /* end of image */2034 /* end of image */
2035 2035
2036 ff_er_frame_end(&s->er);2036 ff_er_frame_end(&s->er, NULL);
2037 2037
2038 ff_mpv_frame_end(s);2038 ff_mpv_frame_end(s);
2039 2039
libavcodec/mss2.c+1−1
@@ -422,7 +422,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, · 421 unmodified lines
422 ff_vc1_decode_blocks(v);422 ff_vc1_decode_blocks(v);
423 423
424 if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {424 if (v->end_mb_x == s->mb_width && s->end_mb_y == s->mb_height) {
425 ff_er_frame_end(&s->er);425 ff_er_frame_end(&s->er, NULL);
426 } else {426 } else {
427 av_log(v->s.avctx, AV_LOG_WARNING,427 av_log(v->s.avctx, AV_LOG_WARNING,
428 "disabling error correction due to block count mismatch %dx%d != %dx%d\n",428 "disabling error correction due to block count mismatch %dx%d != %dx%d\n",
libavcodec/rv10.c+2−2
@@ -477,7 +477,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 476 unmodified lines
477 if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {477 if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {
478 // FIXME write parser so we always have complete frames?478 // FIXME write parser so we always have complete frames?
479 if (s->current_picture_ptr) {479 if (s->current_picture_ptr) {
480 ff_er_frame_end(&s->er);480 ff_er_frame_end(&s->er, NULL);
481 ff_mpv_frame_end(s);481 ff_mpv_frame_end(s);
482 s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;482 s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
483 }483 }
@@ -649,7 +649,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 165 unmodified lines
649 }649 }
650 650
651 if (s->current_picture_ptr && s->mb_y >= s->mb_height) {651 if (s->current_picture_ptr && s->mb_y >= s->mb_height) {
652 ff_er_frame_end(&s->er);652 ff_er_frame_end(&s->er, NULL);
653 ff_mpv_frame_end(s);653 ff_mpv_frame_end(s);
654 654
655 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {655 if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
libavcodec/rv34.c+3−3
@@ -1560,7 +1560,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) · 1559 unmodified lines
1560 MpegEncContext *s = &r->s;1560 MpegEncContext *s = &r->s;
1561 int got_picture = 0, ret;1561 int got_picture = 0, ret;
1562 1562
1563 ff_er_frame_end(&s->er);1563 ff_er_frame_end(&s->er, NULL);
1564 ff_mpv_frame_end(s);1564 ff_mpv_frame_end(s);
1565 s->mb_num_left = 0;1565 s->mb_num_left = 0;
1566 1566
@@ -1655,7 +1655,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 88 unmodified lines
1655 av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",1655 av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
1656 s->mb_num_left);1656 s->mb_num_left);
1657 if (!s->context_reinit)1657 if (!s->context_reinit)
1658 ff_er_frame_end(&s->er);1658 ff_er_frame_end(&s->er, NULL);
1659 ff_mpv_frame_end(s);1659 ff_mpv_frame_end(s);
1660 }1660 }
1661 1661
@@ -1790,7 +1790,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 128 unmodified lines
1790 av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");1790 av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");
1791 /* always mark the current frame as finished, frame-mt supports1791 /* always mark the current frame as finished, frame-mt supports
1792 * only complete frames */1792 * only complete frames */
1793 ff_er_frame_end(&s->er);1793 ff_er_frame_end(&s->er, NULL);
1794 ff_mpv_frame_end(s);1794 ff_mpv_frame_end(s);
1795 s->mb_num_left = 0;1795 s->mb_num_left = 0;
1796 ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);1796 ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
libavcodec/vc1dec.c+1−1
@@ -1348,7 +1348,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1347 unmodified lines
1348 if ( !v->field_mode1348 if ( !v->field_mode
1349 && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE1349 && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE
1350 && avctx->codec_id != AV_CODEC_ID_VC1IMAGE)1350 && avctx->codec_id != AV_CODEC_ID_VC1IMAGE)
1351 ff_er_frame_end(&s->er);1351 ff_er_frame_end(&s->er, NULL);
1352 }1352 }
1353 1353
1354 ff_mpv_frame_end(s);1354 ff_mpv_frame_end(s);

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