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

Showing the changes to libavcodec (9 of 9 files). Show all

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
889889 }
890890 }
891891
892−void ff_er_frame_end(ERContext *s)
892+void ff_er_frame_end(ERContext *s, int *decode_error_flags)
893893 {
894894 int *linesize = NULL;
895895 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
11141114 av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n",
11151115 dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type));
11161116
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;
11181121
11191122 is_intra_likely = is_intra_more_likely(s);
11201123
libavcodec/error_resilience.h+11−1
@@ -90,7 +90,17 @@ typedef struct ERContext { · 89 unmodified lines
9090 } ERContext;
9191
9292 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);
94104 void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy,
95105 int status);
96106
libavcodec/h263dec.c+1−1
@@ -622,7 +622,7 @@ retry: · 621 unmodified lines
622622 av_assert1(s->bitstream_buffer_size == 0);
623623 frame_end:
624624 if (!s->studio_profile)
625− ff_er_frame_end(&s->er);
625+ ff_er_frame_end(&s->er, NULL);
626626
627627 if (avctx->hwaccel) {
628628 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
libavcodec/h264dec.c+1−1
@@ -779,7 +779,7 @@ end: · 778 unmodified lines
779779 if (sl->ref_count[1])
780780 ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent);
781781
782− ff_er_frame_end(&h->er);
782+ ff_er_frame_end(&h->er, NULL);
783783 if (use_last_pic)
784784 memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0]));
785785 }
libavcodec/mpeg12dec.c+1−1
@@ -2033,7 +2033,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) · 2032 unmodified lines
20332033 if (/* s->mb_y << field_pic == s->mb_height && */ !s->first_field && !s1->first_slice) {
20342034 /* end of image */
20352035
2036− ff_er_frame_end(&s->er);
2036+ ff_er_frame_end(&s->er, NULL);
20372037
20382038 ff_mpv_frame_end(s);
20392039
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
422422 ff_vc1_decode_blocks(v);
423423
424424 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);
426426 } else {
427427 av_log(v->s.avctx, AV_LOG_WARNING,
428428 "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
477477 if ((s->mb_x == 0 && s->mb_y == 0) || !s->current_picture_ptr) {
478478 // FIXME write parser so we always have complete frames?
479479 if (s->current_picture_ptr) {
480− ff_er_frame_end(&s->er);
480+ ff_er_frame_end(&s->er, NULL);
481481 ff_mpv_frame_end(s);
482482 s->mb_x = s->mb_y = s->resync_mb_x = s->resync_mb_y = 0;
483483 }
@@ -649,7 +649,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 165 unmodified lines
649649 }
650650
651651 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);
653653 ff_mpv_frame_end(s);
654654
655655 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
15601560 MpegEncContext *s = &r->s;
15611561 int got_picture = 0, ret;
15621562
1563− ff_er_frame_end(&s->er);
1563+ ff_er_frame_end(&s->er, NULL);
15641564 ff_mpv_frame_end(s);
15651565 s->mb_num_left = 0;
15661566
@@ -1655,7 +1655,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 88 unmodified lines
16551655 av_log(avctx, AV_LOG_ERROR, "New frame but still %d MB left.\n",
16561656 s->mb_num_left);
16571657 if (!s->context_reinit)
1658− ff_er_frame_end(&s->er);
1658+ ff_er_frame_end(&s->er, NULL);
16591659 ff_mpv_frame_end(s);
16601660 }
16611661
@@ -1790,7 +1790,7 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, AVFrame *pict, · 128 unmodified lines
17901790 av_log(avctx, AV_LOG_INFO, "marking unfished frame as finished\n");
17911791 /* always mark the current frame as finished, frame-mt supports
17921792 * only complete frames */
1793− ff_er_frame_end(&s->er);
1793+ ff_er_frame_end(&s->er, NULL);
17941794 ff_mpv_frame_end(s);
17951795 s->mb_num_left = 0;
17961796 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
13481348 if ( !v->field_mode
13491349 && avctx->codec_id != AV_CODEC_ID_WMV3IMAGE
13501350 && avctx->codec_id != AV_CODEC_ID_VC1IMAGE)
1351− ff_er_frame_end(&s->er);
1351+ ff_er_frame_end(&s->er, NULL);
13521352 }
13531353
13541354 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