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.
Unified · Split
| @@ -889,7 +889,7 @@ void ff_er_add_slice(ERContext *s, int startx, int starty, · 888 unmodified lines | ||
| 889 | 889 | } |
| 890 | 890 | } |
| 891 | 891 | |
| 892 | −void ff_er_frame_end(ERContext *s) | |
| 892 | +void ff_er_frame_end(ERContext *s, int *decode_error_flags) | |
| 893 | 893 | { |
| 894 | 894 | int *linesize = NULL; |
| 895 | 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 | 1114 | av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n", |
| 1115 | 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 | 1122 | is_intra_likely = is_intra_more_likely(s); |
| 1120 | 1123 | |
| @@ -90,7 +90,17 @@ typedef struct ERContext { · 89 unmodified lines | ||
| 90 | 90 | } ERContext; |
| 91 | 91 | |
| 92 | 92 | void ff_er_frame_start(ERContext *s); |
| 93 | −void 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 | + */ | |
| 103 | +void ff_er_frame_end(ERContext *s, int *decode_error_flags); | |
| 94 | 104 | void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, |
| 95 | 105 | int status); |
| 96 | 106 | |
| @@ -622,7 +622,7 @@ retry: · 621 unmodified lines | ||
| 622 | 622 | av_assert1(s->bitstream_buffer_size == 0); |
| 623 | 623 | frame_end: |
| 624 | 624 | if (!s->studio_profile) |
| 625 | − ff_er_frame_end(&s->er); | |
| 625 | + ff_er_frame_end(&s->er, NULL); | |
| 626 | 626 | |
| 627 | 627 | if (avctx->hwaccel) { |
| 628 | 628 | ret = FF_HW_SIMPLE_CALL(avctx, end_frame); |
| @@ -779,7 +779,7 @@ end: · 778 unmodified lines | ||
| 779 | 779 | if (sl->ref_count[1]) |
| 780 | 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 | 783 | if (use_last_pic) |
| 784 | 784 | memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0])); |
| 785 | 785 | } |
| @@ -2033,7 +2033,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) · 2032 unmodified lines | ||
| 2033 | 2033 | if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) { |
| 2034 | 2034 | /* end of image */ |
| 2035 | 2035 | |
| 2036 | − ff_er_frame_end(&s->er); | |
| 2036 | + ff_er_frame_end(&s->er, NULL); | |
| 2037 | 2037 | |
| 2038 | 2038 | ff_mpv_frame_end(s); |
| 2039 | 2039 | |
| @@ -422,7 +422,7 @@ static int decode_wmv9(AVCodecContext *avctx, const uint8_t *buf, int buf_size, · 421 unmodified lines | ||
| 422 | 422 | ff_vc1_decode_blocks(v); |
| 423 | 423 | |
| 424 | 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 | 426 | } else { |
| 427 | 427 | av_log(v->s.avctx, AV_LOG_WARNING, |
| 428 | 428 | "disabling error correction due to block count mismatch %dx%d != %dx%d\n", |
| @@ -477,7 +477,7 @@ static int rv10_decode_packet(AVCodecContext *avctx, const uint8_t *buf, · 476 unmodified lines | ||
| 477 | 477 | if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) { |
| 478 | 478 | // FIXME write parser so we always have complete frames? |
| 479 | 479 | if (s->current_picture_ptr) { |
| 480 | − ff_er_frame_end(&s->er); | |
| 480 | + ff_er_frame_end(&s->er, NULL); | |
| 481 | 481 | ff_mpv_frame_end(s); |
| 482 | 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 | 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 | 653 | ff_mpv_frame_end(s); |
| 654 | 654 | |
| 655 | 655 | if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { |
| @@ -1560,7 +1560,7 @@ static int finish_frame(AVCodecContext *avctx, AVFrame *pict) · 1559 unmodified lines | ||
| 1560 | 1560 | MpegEncContext *s = &r->s; |
| 1561 | 1561 | int got_picture = 0, ret; |
| 1562 | 1562 | |
| 1563 | − ff_er_frame_end(&s->er); | |
| 1563 | + ff_er_frame_end(&s->er, NULL); | |
| 1564 | 1564 | ff_mpv_frame_end(s); |
| 1565 | 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 | 1655 | av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n", |
| 1656 | 1656 | s->mb_num_left); |
| 1657 | 1657 | if (!s->context_reinit) |
| 1658 | − ff_er_frame_end(&s->er); | |
| 1658 | + ff_er_frame_end(&s->er, NULL); | |
| 1659 | 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 | 1790 | av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n"); |
| 1791 | 1791 | /* always mark the current frame as finished, frame-mt supports |
| 1792 | 1792 | * only complete frames */ |
| 1793 | − ff_er_frame_end(&s->er); | |
| 1793 | + ff_er_frame_end(&s->er, NULL); | |
| 1794 | 1794 | ff_mpv_frame_end(s); |
| 1795 | 1795 | s->mb_num_left = 0; |
| 1796 | 1796 | ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); |
| @@ -1348,7 +1348,7 @@ static int vc1_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 1347 unmodified lines | ||
| 1348 | 1348 | if ( !v->field_mode |
| 1349 | 1349 | && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE |
| 1350 | 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 | 1354 | ff_mpv_frame_end(s); |