From patchwork Sat Nov 11 22:16:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 5958 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp523938jah; Sat, 11 Nov 2017 14:17:22 -0800 (PST) X-Google-Smtp-Source: AGs4zMZcc3IetraEUpZJxUU9KaMhYxCw5M3hfmyCambAnQW4Bbt9xLRLXT7geRFhgu3UMBA3ut6l X-Received: by 10.223.135.143 with SMTP id b15mr3278587wrb.278.1510438642440; Sat, 11 Nov 2017 14:17:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510438642; cv=none; d=google.com; s=arc-20160816; b=HuQL4SlLorZ7ICfew1JbChL2lIiyBmccL2zkMk8G7VUXhiytBGCg1g6LM5/MnEiWvS df7EeRkUi+2v7kGlzFEeaB8CyK0Gx09U938z3S3aALLLTeTD02+oWqeEBztFxgX1d/OJ NqSqxNjBZBQTPjxpCikIQy1RQfF7ZQQdaptS4mKaWi9JJkq5niELqVlHMhPlGJA6I79U AOCXmvO7JzkpNR3DLBy6t/Pbz+Fwb+/VoL3UsoqQKvK72QOEXSOH4OJYIJb/xpoEl9/T +QycGCi8leszoGpqjTZsRG4kzyOV/OqUPXM2wQcQQ+6Emrn5W733mVJksTJzmfbK+0Dk r4hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=RHum4hm47pSQMTapj4g+dlKdG/sjXauu10PX1UaJfEg=; b=YUAEtTukVq9j2jQjMko/VBMvP1k2y09nhfaxWvKzL8bKRzojBc9gV9dh1mLnCHHUrt fcq6qHN5iW53qFk8uuOyd1/bPJHRAaVycTdbA2gtL26KURty1kEk+OUIM81WJDaCdm1h RHef0U8fPMeV3kr5H2FPfI1yOsU+5luRrqQ1wATSIXHoQlK067qqmCXB430E9T2aJuyV RW+NsgrxnmNlR8PBwLGEBdTnM5j8f/z8/JXzi4F3apa/ikxE/0/aq4Ex+e7rGqHggXKQ nuZf2z2tQ73Q6QtwMGPyUE7aibKnLtHf9g/aerx+1tgcB8nRhxQ7FHJwnkxxUmBIuMic wEcQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id a16si10861611wrf.316.2017.11.11.14.17.22; Sat, 11 Nov 2017 14:17:22 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0FA2268A218; Sun, 12 Nov 2017 00:17:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-qmta-pe02-3.mx.upcmail.net (vie01a-qmta-pe02-3.mx.upcmail.net [62.179.121.183]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 56BF068A20F for ; Sun, 12 Nov 2017 00:16:59 +0200 (EET) Received: from [172.31.218.36] (helo=vie01a-dmta-pe02-3.mx.upcmail.net) by vie01a-pqmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eDe5R-0001LZ-AP for ffmpeg-devel@ffmpeg.org; Sat, 11 Nov 2017 23:17:13 +0100 Received: from [172.31.216.43] (helo=vie01a-pemc-psmtp-pe01) by vie01a-dmta-pe02.mx.upcmail.net with esmtp (Exim 4.88) (envelope-from ) id 1eDe5M-0006a4-2K for ffmpeg-devel@ffmpeg.org; Sat, 11 Nov 2017 23:17:08 +0100 Received: from localhost ([213.47.41.20]) by vie01a-pemc-psmtp-pe01 with SMTP @ mailcloud.upcmail.net id YmGy1w01Z0S5wYM01mGz5h; Sat, 11 Nov 2017 23:17:00 +0100 X-SourceIP: 213.47.41.20 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 11 Nov 2017 23:16:56 +0100 Message-Id: <20171111221656.12096-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171111221656.12096-1-michael@niedermayer.cc> References: <20171111221656.12096-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/2] avcodec/h264: Move error resilience from slice to main context X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This should fix some issues with slice threads and ER, it may or may not fix all --- libavcodec/h264_slice.c | 26 ++++++++++---------------- libavcodec/h264dec.c | 31 +++++++++++++------------------ libavcodec/h264dec.h | 2 +- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index da76b9293f..919e66a906 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -25,6 +25,7 @@ * @author Michael Niedermayer */ +#include "libavutil/atomic.h" #include "libavutil/avassert.h" #include "libavutil/display.h" #include "libavutil/imgutils.h" @@ -503,7 +504,7 @@ static int h264_frame_start(H264Context *h) h->cur_pic_ptr = pic; ff_h264_unref_picture(h, &h->cur_pic); if (CONFIG_ERROR_RESILIENCE) { - ff_h264_set_erpic(&h->slice_ctx[0].er.cur_pic, NULL); + ff_h264_set_erpic(&h->er.cur_pic, NULL); } if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0) @@ -515,9 +516,9 @@ static int h264_frame_start(H264Context *h) } if (CONFIG_ERROR_RESILIENCE && h->enable_er) { - ff_er_frame_start(&h->slice_ctx[0].er); - ff_h264_set_erpic(&h->slice_ctx[0].er.last_pic, NULL); - ff_h264_set_erpic(&h->slice_ctx[0].er.next_pic, NULL); + ff_er_frame_start(&h->er); + ff_h264_set_erpic(&h->er.last_pic, NULL); + ff_h264_set_erpic(&h->er.next_pic, NULL); } for (i = 0; i < 16; i++) { @@ -2480,7 +2481,7 @@ static void decode_finish_row(const H264Context *h, H264SliceContext *sl) ff_h264_draw_horiz_band(h, sl, top, height); - if (h->droppable || sl->h264->slice_ctx[0].er.error_occurred) + if (h->droppable || sl->h264->er.error_occurred) return; ff_thread_report_progress(&h->cur_pic_ptr->tf, top + height - 1, @@ -2495,7 +2496,7 @@ static void er_add_slice(H264SliceContext *sl, return; if (CONFIG_ERROR_RESILIENCE) { - ERContext *er = &sl->h264->slice_ctx[0].er; + ERContext *er = &sl->h264->er; ff_er_add_slice(er, startx, starty, endx, endy, status); } @@ -2526,13 +2527,13 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg) sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME || (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); - if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && h->slice_ctx[0].er.error_status_table) { + if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && h->er.error_status_table) { const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1); if (start_i) { - int prev_status = h->slice_ctx[0].er.error_status_table[h->slice_ctx[0].er.mb_index2xy[start_i - 1]]; + int prev_status = h->er.error_status_table[h->er.mb_index2xy[start_i - 1]]; prev_status &= ~ VP_START; if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END)) - h->slice_ctx[0].er.error_occurred = 1; + avpriv_atomic_int_set(&h->er.error_occurred, 1); } } @@ -2746,9 +2747,6 @@ int ff_h264_execute_decode_slices(H264Context *h) int slice_idx; sl = &h->slice_ctx[i]; - if (CONFIG_ERROR_RESILIENCE) { - sl->er.error_count = 0; - } /* make sure none of those slices overlap */ slice_idx = sl->mb_y * h->mb_width + sl->mb_x; @@ -2769,10 +2767,6 @@ int ff_h264_execute_decode_slices(H264Context *h) /* pull back stuff from slices to master context */ sl = &h->slice_ctx[context_count - 1]; h->mb_y = sl->mb_y; - if (CONFIG_ERROR_RESILIENCE) { - for (i = 1; i < context_count; i++) - h->slice_ctx[0].er.error_count += h->slice_ctx[i].er.error_count; - } if (h->postpone_filter) { h->postpone_filter = 0; diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index aed23c4fba..abf05158f9 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -157,13 +157,14 @@ void ff_h264_free_tables(H264Context *h) av_buffer_pool_uninit(&h->motion_val_pool); av_buffer_pool_uninit(&h->ref_index_pool); + av_freep(&h->er.mb_index2xy); + av_freep(&h->er.error_status_table); + av_freep(&h->er.er_temp_buffer); + for (i = 0; i < h->nb_slice_ctx; i++) { H264SliceContext *sl = &h->slice_ctx[i]; av_freep(&sl->dc_val_base); - av_freep(&sl->er.mb_index2xy); - av_freep(&sl->er.error_status_table); - av_freep(&sl->er.er_temp_buffer); av_freep(&sl->bipred_scratchpad); av_freep(&sl->edge_emu_buffer); @@ -237,7 +238,6 @@ fail: */ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) { - ERContext *er = &sl->er; int mb_array_size = h->mb_height * h->mb_stride; int y_size = (2 * h->mb_width + 1) * (2 * h->mb_height + 1); int c_size = h->mb_stride * (h->mb_height + 1); @@ -251,10 +251,8 @@ int ff_h264_slice_context_init(H264Context *h, H264SliceContext *sl) sl->ref_cache[1][scan8[7] + 1] = sl->ref_cache[1][scan8[13] + 1] = PART_NOT_AVAILABLE; - if (sl != h->slice_ctx) { - memset(er, 0, sizeof(*er)); - } else - if (CONFIG_ERROR_RESILIENCE) { + if (CONFIG_ERROR_RESILIENCE && sl == h->slice_ctx) { + ERContext *er = &h->er; /* init ER */ er->avctx = h->avctx; @@ -432,9 +430,6 @@ static av_cold int h264_decode_init(AVCodecContext *avctx) ff_h264_flush_change(h); - if (h->enable_er < 0 && (avctx->active_thread_type & FF_THREAD_SLICE)) - h->enable_er = 0; - if (h->enable_er && (avctx->active_thread_type & FF_THREAD_SLICE)) { av_log(avctx, AV_LOG_WARNING, "Error resilience with slice threads is enabled. It is unsafe and unsupported and may crash. " @@ -773,25 +768,25 @@ end: H264SliceContext *sl = h->slice_ctx; int use_last_pic = h->last_pic_for_ec.f->buf[0] && !sl->ref_count[0]; - ff_h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr); + ff_h264_set_erpic(&h->er.cur_pic, h->cur_pic_ptr); if (use_last_pic) { - ff_h264_set_erpic(&sl->er.last_pic, &h->last_pic_for_ec); + ff_h264_set_erpic(&h->er.last_pic, &h->last_pic_for_ec); sl->ref_list[0][0].parent = &h->last_pic_for_ec; memcpy(sl->ref_list[0][0].data, h->last_pic_for_ec.f->data, sizeof(sl->ref_list[0][0].data)); memcpy(sl->ref_list[0][0].linesize, h->last_pic_for_ec.f->linesize, sizeof(sl->ref_list[0][0].linesize)); sl->ref_list[0][0].reference = h->last_pic_for_ec.reference; } else if (sl->ref_count[0]) { - ff_h264_set_erpic(&sl->er.last_pic, sl->ref_list[0][0].parent); + ff_h264_set_erpic(&h->er.last_pic, sl->ref_list[0][0].parent); } else - ff_h264_set_erpic(&sl->er.last_pic, NULL); + ff_h264_set_erpic(&h->er.last_pic, NULL); if (sl->ref_count[1]) - ff_h264_set_erpic(&sl->er.next_pic, sl->ref_list[1][0].parent); + ff_h264_set_erpic(&h->er.next_pic, sl->ref_list[1][0].parent); - sl->er.ref_count = sl->ref_count[0]; + h->er.ref_count = sl->ref_count[0]; - ff_er_frame_end(&sl->er); + ff_er_frame_end(&h->er); if (use_last_pic) memset(&sl->ref_list[0][0], 0, sizeof(sl->ref_list[0][0])); } diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index b87b947f95..81c4f2ebc0 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -177,7 +177,6 @@ typedef struct H264Ref { typedef struct H264SliceContext { struct H264Context *h264; GetBitContext gb; - ERContext er; int slice_num; int slice_type; @@ -341,6 +340,7 @@ typedef struct H264Context { H264DSPContext h264dsp; H264ChromaContext h264chroma; H264QpelContext h264qpel; + ERContext er; H264Picture DPB[H264_MAX_PICTURE_COUNT]; H264Picture *cur_pic_ptr;