From: "J. Dekker" <jdek@itanimul.li> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 3/7] lavc/error_resilience: fill ecinfo Date: Fri, 21 Jul 2023 15:37:42 +0200 Message-ID: <20230721133746.33335-3-jdek@itanimul.li> (raw) In-Reply-To: <20230721133746.33335-1-jdek@itanimul.li> Fill ECInfo inside error resilience using references set by the decoder. Co-Authored-By: Thomas Guillem <thomas@gllm.fr> Signed-off-by: J. Dekker <jdek@itanimul.li> --- libavcodec/error_resilience.c | 91 +++++++++++++++++++++++++++++------ libavcodec/error_resilience.h | 4 +- 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index 2aa6f1d864..c1417ecf07 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -28,6 +28,7 @@ #include <limits.h> #include "libavutil/internal.h" +#include "libavutil/ec.h" #include "avcodec.h" #include "error_resilience.h" #include "me_cmp.h" @@ -411,7 +412,7 @@ static void guess_mv(ERContext *s) num_avail = 0; if (s->last_pic.motion_val[0]) - ff_thread_await_progress(s->last_pic.tf, mb_height-1, 0); + ff_thread_await_progress(s->last_pic.tf, INT_MAX, 0); for (i = 0; i < mb_width * mb_height; i++) { const int mb_xy = s->mb_index2xy[i]; int f = 0; @@ -889,25 +890,61 @@ void ff_er_add_slice(ERContext *s, int startx, int starty, } } -void ff_er_frame_end(ERContext *s) +static void +er_fill_info_ref(ERContext *s) +{ + uint64_t acc_ok = 0, acc_err = 0; + av_assert0(s->cur_pic.info); + + if (s->cur_pic.f->pict_type != AV_PICTURE_TYPE_I) { + ERPicture *reffs[2] = {&s->last_pic, &s->next_pic}; + int i, nb_ref_pics = s->cur_pic.f->pict_type == AV_PICTURE_TYPE_B ? 2 : 1; + + for (i = 0; i < nb_ref_pics; i++) { + ERPicture *reff = reffs[i]; + + if (reff->info == NULL) + continue; + + ff_thread_await_progress(reff->tf, INT_MAX, 0); + + /* should check more accurately how refs are used */ + if (reff->info->error == 0 && reff->info->ref_error == 0) + continue; + + if (acc_err < (reff->info->error + reff->info->ref_error)){ + acc_err = reff->info->error + reff->info->ref_error; + acc_ok = reff->info->ok + reff->info->ref_ok; + } + } + } + + s->cur_pic.info->ref_error = acc_err; + s->cur_pic.info->ref_ok = acc_ok; +} + +int ff_er_frame_end(ERContext *s) { int *linesize = NULL; - int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error; + int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error, terror; int distance; int threshold_part[4] = { 100, 100, 100 }; int threshold = 50; int is_intra_likely; int size = s->b8_stride * 2 * s->mb_height; + /* We do not support ER of field pictures yet, * though it should not crash if enabled. */ - if (!s->avctx->error_concealment || !atomic_load(&s->error_count) || - s->avctx->lowres || - !er_supported(s) || - atomic_load(&s->error_count) == 3 * s->mb_width * - (s->avctx->skip_top + s->avctx->skip_bottom)) { - return; + if (!s->avctx->error_concealment || s->avctx->lowres || !er_supported(s)) + return 0; + + if (!atomic_load(&s->error_count) || + atomic_load(&s->error_count) == 3 * s->mb_width * (s->avctx->skip_top + s->avctx->skip_bottom)) + { + goto end_find_ref_errs; } + linesize = s->cur_pic.f->linesize; if ( s->avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO @@ -921,7 +958,7 @@ void ff_er_frame_end(ERContext *s) if (mb_x == s->mb_width) { av_log(s->avctx, AV_LOG_DEBUG, "ignoring last missing slice\n"); - return; + goto end_find_ref_errs; } } @@ -960,7 +997,7 @@ void ff_er_frame_end(ERContext *s) s->cur_pic.ref_index[i] = NULL; s->cur_pic.motion_val[i] = NULL; } - return; + goto end_find_ref_errs; } } @@ -1100,10 +1137,12 @@ void ff_er_frame_end(ERContext *s) } #endif - dc_error = ac_error = mv_error = 0; + terror = dc_error = ac_error = mv_error = 0; for (i = 0; i < s->mb_num; i++) { const int mb_xy = s->mb_index2xy[i]; int error = s->error_status_table[mb_xy]; + if (error) + terror++; if (error & ER_DC_ERROR) dc_error++; if (error & ER_AC_ERROR) @@ -1111,10 +1150,9 @@ void ff_er_frame_end(ERContext *s) if (error & ER_MV_ERROR) mv_error++; } - av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors in %c frame\n", - dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type)); - s->cur_pic.f->decode_error_flags |= FF_DECODE_ERROR_CONCEALMENT_ACTIVE; + fprintf(stderr, "concealing %d DC, %d AC, %d MV errors in %c frame: %d\n", + dc_error, ac_error, mv_error, av_get_picture_type_char(s->cur_pic.f->pict_type), terror * 256); is_intra_likely = is_intra_more_likely(s); @@ -1349,7 +1387,30 @@ void ff_er_frame_end(ERContext *s) s->cur_pic.motion_val[i] = NULL; } + av_assert0(terror); + if (s->cur_pic.info) { + /* assumes 16x16 mbs */ + s->cur_pic.info->error = terror * 256; + s->cur_pic.info->ok = (s->mb_num - terror) * 256; + er_fill_info_ref(s); + } + + memset(&s->cur_pic, 0, sizeof(ERPicture)); + memset(&s->last_pic, 0, sizeof(ERPicture)); + memset(&s->next_pic, 0, sizeof(ERPicture)); + + return 1; + +end_find_ref_errs: + if (s->cur_pic.info) + { + er_fill_info_ref(s); + s->cur_pic.info->error = s->cur_pic.info->ok = 0; + } + memset(&s->cur_pic, 0, sizeof(ERPicture)); memset(&s->last_pic, 0, sizeof(ERPicture)); memset(&s->next_pic, 0, sizeof(ERPicture)); + + return 0; } diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h index 47cc8a4fc6..97479d2c0c 100644 --- a/libavcodec/error_resilience.h +++ b/libavcodec/error_resilience.h @@ -25,6 +25,7 @@ #include "avcodec.h" #include "me_cmp.h" #include "threadframe.h" +#include "libavutil/ec.h" ///< current MB is the first after a resync marker #define VP_START 1 @@ -48,6 +49,7 @@ typedef struct ERPicture { uint32_t *mb_type; int field_picture; + AVECInfo *info; } ERPicture; typedef struct ERContext { @@ -90,7 +92,7 @@ typedef struct ERContext { } ERContext; void ff_er_frame_start(ERContext *s); -void ff_er_frame_end(ERContext *s); +int ff_er_frame_end(ERContext *s); void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status); -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2023-07-21 13:38 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-21 13:37 [FFmpeg-devel] [PATCH 1/7] lavu: add ecinfo sidedata J. Dekker 2023-07-21 13:37 ` [FFmpeg-devel] [PATCH 2/7] lavc: add AV_CODEC_EXPORT_DATA_ERROR J. Dekker 2023-07-21 13:37 ` J. Dekker [this message] 2023-07-21 13:37 ` [FFmpeg-devel] [PATCH 4/7] lavc: set decode_error_flags when ec active J. Dekker 2023-07-21 13:37 ` [FFmpeg-devel] [PATCH 5/7] lavc/h264: export ecinfo J. Dekker 2023-07-21 13:37 ` [FFmpeg-devel] [PATCH 6/7] tools/ffprobe: add ecinfo frame side data J. Dekker 2023-07-21 13:47 ` [FFmpeg-devel] [PATCH 6/7 v1.1] " J. Dekker 2023-07-21 13:37 ` [FFmpeg-devel] [PATCH 7/7] fate: add ecinfo sidedata test J. Dekker 2023-07-21 14:44 ` [FFmpeg-devel] [PATCH 1/7] lavu: add ecinfo sidedata Devin Heitmueller 2023-07-25 12:05 ` J. Dekker 2023-07-25 22:00 ` Michael Niedermayer 2023-07-21 23:49 ` Michael Niedermayer [not found] ` <20230721133746.33335-1-jdek@itanimul.li-N_sf260--B-9> 2023-07-22 0:12 ` Lynne
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230721133746.33335-3-jdek@itanimul.li \ --to=jdek@itanimul.li \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git