From patchwork Mon Oct 18 12:47:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 31144 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp3262028ioa; Mon, 18 Oct 2021 05:47:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEb5TRyVGQl/2mM57BoViDwjZXFBqZ5fIhab5gpFABz1W1OqdRk7FwvIY1cKd07uKwioAf X-Received: by 2002:a17:907:c25:: with SMTP id ga37mr29201920ejc.2.1634561271011; Mon, 18 Oct 2021 05:47:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634561271; cv=none; d=google.com; s=arc-20160816; b=Tln1dj06a1CA36HaBgjRwmrjEJEk3tg9jqT4cPSBmZStvP7NAxicpKUSFi6cRPVt2s rheMDLQK4z/fmek1Afe6h/gCnAT8OhCQiSkil3kZqkLjLeekoc8KKTlII/BCPHCR2841 J08PG/49PKS96c6PvY6N9jPxKWw5W087N6bI+HEXqt9aOp+b8LsUq9VeVrZxR6vHU43+ we6sKaMENLR+p777tbKLB0Ju1w1ITFOlenbwbrCkYQXR//D9dKRGRuaKMKR7aFECfMZV Ya6OVd8g8/LkQ8VTAq2VqrVkLRnQb99uviFEMqvQhdFaYrEC12YuW2i8OelS5HCbLvJY SBHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=wRSEctCSmBoKcaCnnExPgzkkFSykaOoErg5UDBq8UPE=; b=ihc2Zb4Cp2csn47ULIUuOcMHeKBI8XOy11wljmaZWvvh9bkwhQQTC5uLkk3SmHNYrp /nXDsdRVGfuMTgGuIj1cVzHRd8z8tWd9rLCjYmRMt7Y/4/wa873VPOmj0UUCNAWgJjho 8c1QHlBcpO4PEHIhs1isg+HCJfwSyXpZgX1xPm0oWWovMWsk7suULrV8ugKPUZbBNLJy uX4P7gAbDFkR34u9HaLh5hQiWKSPmvIO94KI5vAwES21kE8DLix6AC7gBY++dhKOYASn s/h0JqC3UylWl9hpdxlKZynmw4DRsEkJCdRsl//WVg+Bkg4W86Z9xRvRIPMjtayClb3j PRuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=ArvVWNmw; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w18si18852312edu.157.2021.10.18.05.47.50; Mon, 18 Oct 2021 05:47:51 -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 header.s=20210112 header.b=ArvVWNmw; 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=QUARANTINE 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 05D0B68A755; Mon, 18 Oct 2021 15:47:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CB7A468A1A7 for ; Mon, 18 Oct 2021 15:47:30 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id n7so8827189ljp.5 for ; Mon, 18 Oct 2021 05:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=C6ksTXyf1Yy/rjdG6mxROGVe8oQZKqi3I4aBfCc2oj8=; b=ArvVWNmwgW7KSmltxmoHp4a720RCxYj+3UmKQwPkjcpq6AHnadJcSYX/Vsp/SN05zn grjtYTHvgEpxho4ZNsztfJzKVxbSZbZw2UjLNIYjZky4nj2exRL1nGSDufx9+ZziJrSZ BjRZj9843++R6PfXb8xEmH5Som4Od2zDcCer7ab8BjHiOeMsAYGoyc8/x3JwNtLhpf5/ TCsB4pkt1j+dxNxWLJj9I/7YhgOXLVC2LyAYQyoJK2qVMbFkv0+jM5mrcbwv1KCLevuj OXjlRfwyFXIXaWL7vCuNZriGrhIfs2Tmh/Y5bcRxlh3zCP9p/2u0FVNzHu4VOostIOQ/ z2SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C6ksTXyf1Yy/rjdG6mxROGVe8oQZKqi3I4aBfCc2oj8=; b=lJ76i0PpykQaWM2rfWsQmA1Mkr/yHFAxq+uLC6uwkn7K5vwtichet6PYmdZrIivKXS WAyNuMnyA4bVH/SVIQLFZwwjkPqL7ks3KQHx2Q/6kk7jsYKexZSw7nakyYSmJmyqCEAL kPeB/fCxbqEUeMDpol0epdUXBiQnbMZe9Q+ayasGYLw+qhyRnB++CQwraacVDE/KmZm0 8xLf0Y17GsFobTVL+rbnj+9mISQMyS/zR02ZoMdynRCsYzSS9uoIILU2vZ/v3imek5TQ 2OklbVxdtylCmLIgJuT6C9BUlFTBGCforfZK5ee0ZxU+vFXgHo5izgs6SgoXx/0UoAFv 0Uqg== X-Gm-Message-State: AOAM531TzZpWVzLiSKE0w8e0oRX9+J/QQKJ7KxvRJekQV3ZFBEUls55J xYwyDqNhZsjoev7eHAusDNqgrxSFKQKoWqJI X-Received: by 2002:a2e:9c4b:: with SMTP id t11mr33291430ljj.376.1634561250175; Mon, 18 Oct 2021 05:47:30 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id m16sm1392779lfl.212.2021.10.18.05.47.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Oct 2021 05:47:29 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Oct 2021 15:47:21 +0300 Message-Id: <20211018124723.11497-2-jeebjp@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211018124723.11497-1-jeebjp@gmail.com> References: <20211018124723.11497-1-jeebjp@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 1/3] avformat/avio: privatize point of truth for AVIOContext::written X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: uKqcBJGRVMgR Looking at 3f75e5116b900f1428aa13041fc7d6301bf1988a, the field was supposed to be private, but during merging the field and the group that had the comment about it got separated. Thus, move the actual privately utilized state of this variable into the private FFIOContext. Additionally, name the private field somewhat better, so that it does not get confused with the amount of bytes written out. --- libavformat/avio_internal.h | 6 ++++++ libavformat/aviobuf.c | 11 +++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index eded38759b..467e80701f 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -66,6 +66,12 @@ typedef struct FFIOContext { * used after probing to ensure seekback and to reset the buffer size */ int orig_buffer_size; + + /** + * Written output size + * is updated each time a successful writeout ends up further position-wise + */ + int64_t written_output_size; } FFIOContext; static av_always_inline FFIOContext *ffiocontext(AVIOContext *ctx) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 3d87d66091..b18a56ef19 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -164,8 +164,10 @@ static void writeout(AVIOContext *s, const uint8_t *data, int len) if (ret < 0) { s->error = ret; } else { - if (s->pos + len > s->written) - s->written = s->pos + len; + if (s->pos + len > ctx->written_output_size) { + ctx->written_output_size = s->pos + len; + s->written = ctx->written_output_size; + } } } if (ctx->current_type == AVIO_DATA_MARKER_SYNC_POINT || @@ -337,13 +339,14 @@ int64_t avio_skip(AVIOContext *s, int64_t offset) int64_t avio_size(AVIOContext *s) { + FFIOContext *const ctx = ffiocontext(s); int64_t size; if (!s) return AVERROR(EINVAL); - if (s->written) - return s->written; + if (ctx->written_output_size) + return ctx->written_output_size; if (!s->seek) return AVERROR(ENOSYS);