From patchwork Tue Mar 28 23:52:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Ronald S. Bultje" X-Patchwork-Id: 3159 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp854811vss; Tue, 28 Mar 2017 16:52:26 -0700 (PDT) X-Received: by 10.28.12.147 with SMTP id 141mr17185295wmm.8.1490745146503; Tue, 28 Mar 2017 16:52:26 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e16si5037874wmd.4.2017.03.28.16.52.26; Tue, 28 Mar 2017 16:52:26 -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=@gmail.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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A51C86899C1; Wed, 29 Mar 2017 02:52:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt0-f195.google.com (mail-qt0-f195.google.com [209.85.216.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDB426882E9 for ; Wed, 29 Mar 2017 02:51:55 +0300 (EEST) Received: by mail-qt0-f195.google.com with SMTP id r45so34772qte.0 for ; Tue, 28 Mar 2017 16:52:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=bPq34pROw5gCgj2v5R/C9LsnryOsCOM/hJlzx4ssY1k=; b=C7SJT04YGLQ2iPAkzjooc7aHZZQ34G3zyOWk0sCCA2+MQ2Oyh8IhjJGr6QEkVRc6e8 egjLOyfIj7BxbVkIluxAOg68xpAhInb1wwMdycMBv9DRzb5AmwVWG58EYmuy2LpxHnf7 VMRKJTMj4zXxgAol1HVr3IdsCJ/St84KvmfkZmhKLqUso7TOOR8iCZXuIFhK0jYGK5ds OpQx3bAgouNCMOeH2WTbmqe/Y0GQ5fwj5jELW+YUxnMG+3RwnJr57gCRnj2+u9O0vfa/ WDNvYdNV0PqF4hB+GR/fge340qbVmHVhasNSqClwtdOk+nmMALS6H1lbe18Ln3pn5nOL D/Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=bPq34pROw5gCgj2v5R/C9LsnryOsCOM/hJlzx4ssY1k=; b=iU21mC433iFI3ji2xezXBuJjU9wy6+OryOCaDTHW9AfbjfgYdz8KiZVBWgYeEIwiH0 oN/nBWuj6vPGg+faC7DCGSG7cfFKCsBZZs4C1twUk4ygVEEB9nUKjHW+qU76LSwKCdNf +LuNRo1jztKbQdr4XLzwtfmCd6yQLhQXGg8sexGLCYL+PiwSmwI9S07f/p0sto8WDW/S VCDdTnvunaAApVwZgJxW0w3tsC2Qv70qFL0ot2dGqb8Y+5OlPFkOI8+VE5UNjeq03t2+ gd5C657KNVR1tHtjkDjfWu57NPRRV74qcfA5q+3PoX5iiufe3RfI7d8khKobC6x2T85A VU3g== X-Gm-Message-State: AFeK/H3Sf7ScBTlWu1+USJfEgyoqtfhAM1pZMdJO8aNzxCBQ40aWNy92PuKEmCOUh7HuFw== X-Received: by 10.200.46.196 with SMTP id i4mr30821377qta.17.1490745136937; Tue, 28 Mar 2017 16:52:16 -0700 (PDT) Received: from Macintosh-7.home (pool-96-246-175-85.nycmny.fios.verizon.net. [96.246.175.85]) by smtp.gmail.com with ESMTPSA id 137sm3771472qkd.19.2017.03.28.16.52.16 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 28 Mar 2017 16:52:16 -0700 (PDT) From: "Ronald S. Bultje" To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Mar 2017 19:52:14 -0400 Message-Id: <1490745134-60882-1-git-send-email-rsbultje@gmail.com> X-Mailer: git-send-email 2.8.1 Subject: [FFmpeg-devel] [PATCH] fic: set pict_type/key_frame after (instead of during) slice decoding. 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: "Ronald S. Bultje" MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This fixes a race condition that was already documented in the source code, and is also reported by tsan in fate-fic-avi. --- libavcodec/fic.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/libavcodec/fic.c b/libavcodec/fic.c index d3952a4..2bec3d7 100644 --- a/libavcodec/fic.c +++ b/libavcodec/fic.c @@ -34,6 +34,7 @@ typedef struct FICThreadContext { int slice_h; int src_size; int y_off; + int p_frame; } FICThreadContext; typedef struct FICContext { @@ -133,16 +134,13 @@ static void fic_idct_put(uint8_t *dst, int stride, int16_t *block) } } static int fic_decode_block(FICContext *ctx, GetBitContext *gb, - uint8_t *dst, int stride, int16_t *block) + uint8_t *dst, int stride, int16_t *block, int *is_p) { int i, num_coeff; /* Is it a skip block? */ if (get_bits1(gb)) { - /* This is a P-frame. */ - ctx->frame->key_frame = 0; - ctx->frame->pict_type = AV_PICTURE_TYPE_P; - + *is_p = 1; return 0; } @@ -182,7 +180,8 @@ static int fic_decode_slice(AVCodecContext *avctx, void *tdata) for (x = 0; x < (ctx->aligned_width >> !!p); x += 8) { int ret; - if ((ret = fic_decode_block(ctx, &gb, dst + x, stride, tctx->block)) != 0) + if ((ret = fic_decode_block(ctx, &gb, dst + x, stride, + tctx->block, &tctx->p_frame)) != 0) return ret; } @@ -348,15 +347,6 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, return AVERROR_INVALIDDATA; } - /* - * Set the frametype to I initially. It will be set to P if the frame - * has any dependencies (skip blocks). There will be a race condition - * inside the slice decode function to set these, but we do not care. - * since they will only ever be set to 0/P. - */ - ctx->frame->key_frame = 1; - ctx->frame->pict_type = AV_PICTURE_TYPE_I; - /* Allocate slice data. */ av_fast_malloc(&ctx->slice_data, &ctx->slice_data_size, nslices * sizeof(ctx->slice_data[0])); @@ -398,6 +388,15 @@ static int fic_decode_frame(AVCodecContext *avctx, void *data, NULL, nslices, sizeof(ctx->slice_data[0]))) < 0) return ret; + ctx->frame->key_frame = 1; + ctx->frame->pict_type = AV_PICTURE_TYPE_I; + for (slice = 0; slice < nslices; slice++) { + if (ctx->slice_data[slice].p_frame) { + ctx->frame->key_frame = 0; + ctx->frame->pict_type = AV_PICTURE_TYPE_P; + break; + } + } av_frame_free(&ctx->final_frame); ctx->final_frame = av_frame_clone(ctx->frame); if (!ctx->final_frame) {