From patchwork Mon Mar 12 07:33:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aman Karmani X-Patchwork-Id: 7949 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp1298857jad; Mon, 12 Mar 2018 00:34:13 -0700 (PDT) X-Google-Smtp-Source: AG47ELv19qkb3TkW91INvHA8qquzgrpGJv3VAGFaG1rWAGFsbYUzjIqAPktbUjBUUmz8kPdk4/NY X-Received: by 10.28.95.139 with SMTP id t133mr4418134wmb.16.1520840053375; Mon, 12 Mar 2018 00:34:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520840053; cv=none; d=google.com; s=arc-20160816; b=rM3VY5itn3zEr6gNuKNYbLyYQaulM8+NSC9EHklEWKI5tq7V8s+FTrSqZR8jsI9z7a 19+9ninRqxDJk/qd4+B4pmcIVxSeet4A/jdh6x0nabIvoMutlp84UmNAvMxF+J/nd4KQ gT/cyvxkXmmHqN/rL/S3TkeaQRoAUkYCSdi88iBCvmvbZ023ih+7OS8Z4wo+MD6pKU4+ yBwAGPaFgI2sgSKvlovTZlPHotE3PhyFEU1R7FVPVELxfExFBdLjzqKr/LutsGg2JoHA 0SO6wNX/PAgiEIoePFpUoUgiYf4aGiPhpln23Cyr6DKMwtAQo64kK35tSQ/6gIEwdgvG c87w== 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:cc: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:dkim-signature:delivered-to:arc-authentication-results; bh=7sgQybmPwgpkmyV598Vs79E2XyNC45Ae86C6NzhVu5w=; b=ziGIx3QT6XirJNgXfOWdpC1KBiI+YAMkI3DXgoRWWfpmDHQeAHx3HT3h8twXaA9Y4x 2G+T1/sfgVoixfQU1UHYYVlAf4n2vmPC7RSS6ZlA6gRPi4YYlM7UbjpSHgp9bVFqaGhh Iq8XB7dRbCtchg3g7zroIFhMgZkZOVW0NQx0/26AVbDbYlE2V/2NXXMrG4M36KieeT9R BD3IwUtRSWOEYOQmRUaEVezBd+CE0TgvELloM8vxNeTnhC9T6rfvK8fGZuiJB3jwaUBa VWuW6GaoLGHI2tC8Uq4MGRA9sRfk1mIiu+f+SSRhqQ6lfL3rkYEBsedlQ5FUWIy1dHKZ YrPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=BD3OawkJ; 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 o15si4803634wro.212.2018.03.12.00.34.12; Mon, 12 Mar 2018 00:34:13 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@tmm1-net.20150623.gappssmtp.com header.s=20150623 header.b=BD3OawkJ; 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 28B1768A47D; Mon, 12 Mar 2018 09:34:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl0-f46.google.com (mail-pl0-f46.google.com [209.85.160.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06E40689AA7 for ; Mon, 12 Mar 2018 09:33:54 +0200 (EET) Received: by mail-pl0-f46.google.com with SMTP id m22-v6so8881017pls.5 for ; Mon, 12 Mar 2018 00:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tmm1-net.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=zQCKpJfdehj5IEJfFPiNYrKueGQj6crPXc1iyidQUgM=; b=BD3OawkJOdZC/XL44coLb5JW2OfrV2hgFJdx4oU58ye2SGPSKR8RR3nW2s+4QQEFSn PsSogcbpltoXaB4+HyXnMJiIdpM8PcpgDFfIHMkNIRrtxBb/NcogsvrrcFwbrhi6oNJE yfGdMItsRQFvq8iDc3tZPf4mBtuRsfUShcQBiAGTwrEnTwAwsEGW7auhebChrAKS3Emk oApRXQx+QJ/zGj8uHKPcpWnIYl/BeUAkkltqkGVEpjJvmR0GuMdzrWbmw7HHCATfXG5c 7pWCSuWL29+6UCZY4XMryJcWJMl23ECL4wnVWtp+BpWXTqGubMz9PMfGJ6pPUbNY4GQR bI7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=zQCKpJfdehj5IEJfFPiNYrKueGQj6crPXc1iyidQUgM=; b=MFQznff7/s307Ar+9E+aKdiXDLvF55pDRfM0oD0n4kErLBqpbDdW+L//3A5Vg7VUVn WHkdeYF4fjzeReWY0amRH1kiUciibRNWHocbz3oFJOyJMUT/egPrxtaXcfS6beeW38W3 3R7hOdKQtryzNQOCiA/UUPP7ee8hYCAVAo5P+NiaM9YRyL3E+eWOwyepQu2r40nxokH3 Ukc49sbls0+hT6VmBJz3RT5eaQvVY9BSg/UTnJRTYm9zmBZljaMRuvfwtgpVnhYs9gpW gtfSeCWtChCEmUDipdfSYjR6kOE9ZRZ6ilI6abS2Chfuhis0E+RZyYcbfqblexvYH4AR JRlg== X-Gm-Message-State: AElRT7Fivz1/rtIq4jMNSognKX9gUvDHVzn/Ohl5i7RKFILmiH9tZ6dv xlQKSeM7akElAJEU89ki5Txe+FSp X-Received: by 2002:a17:902:bd46:: with SMTP id b6-v6mr7109129plx.247.1520840042800; Mon, 12 Mar 2018 00:34:02 -0700 (PDT) Received: from localhost.localdomain (c-69-181-54-242.hsd1.ca.comcast.net. [69.181.54.242]) by smtp.gmail.com with ESMTPSA id b5sm15879984pfc.12.2018.03.12.00.34.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Mar 2018 00:34:02 -0700 (PDT) From: Aman Gupta To: ffmpeg-devel@ffmpeg.org Date: Mon, 12 Mar 2018 00:33:54 -0700 Message-Id: <20180312073354.27572-1-ffmpeg@tmm1.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180311230102.13713-1-atomnuker@gmail.com> References: <20180311230102.13713-1-atomnuker@gmail.com> Subject: [FFmpeg-devel] [PATCH v2] avcodec: fix atomics usage for h264/mpeg error_count 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 Cc: Aman Gupta , atomnuker@gmail.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Aman Gupta --- libavcodec/h264_slice.c | 5 +++-- libavcodec/mpeg12dec.c | 14 +++++++++----- libavcodec/mpegvideo_enc.c | 3 ++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 90e05ed8f1..b381397b4d 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -2762,7 +2762,7 @@ int ff_h264_execute_decode_slices(H264Context *h) sl = &h->slice_ctx[i]; if (CONFIG_ERROR_RESILIENCE) { - sl->er.error_count = 0; + sl->er.error_count = ATOMIC_VAR_INIT(0); } /* make sure none of those slices overlap */ @@ -2786,7 +2786,8 @@ int ff_h264_execute_decode_slices(H264Context *h) 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; + atomic_fetch_add(&h->slice_ctx[0].er.error_count, + atomic_load(&h->slice_ctx[i].er.error_count)); } if (h->postpone_filter) { diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c index 9e076e89da..ad2586dc07 100644 --- a/libavcodec/mpeg12dec.c +++ b/libavcodec/mpeg12dec.c @@ -1992,7 +1992,8 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) int mb_y = s->start_mb_y; const int field_pic = s->picture_structure != PICT_FRAME; - s->er.error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic; + s->er.error_count = ATOMIC_VAR_INIT( + (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic); for (;;) { uint32_t start_code; @@ -2002,7 +2003,7 @@ static int slice_decode_thread(AVCodecContext *c, void *arg) emms_c(); ff_dlog(c, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n", ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, - s->start_mb_y, s->end_mb_y, s->er.error_count); + s->start_mb_y, s->end_mb_y, atomic_load(&s->er.error_count)); if (ret < 0) { if (c->err_recognition & AV_EF_EXPLODE) return ret; @@ -2485,7 +2486,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, &s2->thread_context[0], NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) - s2->er.error_count += s2->thread_context[i]->er.error_count; + atomic_fetch_add(&s2->er.error_count, + atomic_load(&s2->thread_context[i]->er.error_count)); } ret = slice_end(avctx, picture); @@ -2499,7 +2501,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, } s2->pict_type = 0; - if (avctx->err_recognition & AV_EF_EXPLODE && s2->er.error_count) + if (avctx->err_recognition & AV_EF_EXPLODE && + atomic_load(&s2->er.error_count)) return AVERROR_INVALIDDATA; return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); @@ -2553,7 +2556,8 @@ static int decode_chunks(AVCodecContext *avctx, AVFrame *picture, s2->thread_context, NULL, s->slice_count, sizeof(void *)); for (i = 0; i < s->slice_count; i++) - s2->er.error_count += s2->thread_context[i]->er.error_count; + atomic_fetch_add(&s2->er.error_count, + atomic_load(&s2->thread_context[i]->er.error_count)); s->slice_count = 0; } if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 979e138b88..b69e0e1727 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -3595,7 +3595,8 @@ static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src) MERGE(b_count); MERGE(skip_count); MERGE(misc_bits); - MERGE(er.error_count); + atomic_fetch_add(&dst->er.error_count, atomic_load(&src->er.error_count)); + src->er.error_count = ATOMIC_VAR_INIT(0); MERGE(padding_bug_score); MERGE(current_picture.encoding_error[0]); MERGE(current_picture.encoding_error[1]);