From patchwork Tue Mar 31 12:37:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18530 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8199944B0FC for ; Tue, 31 Mar 2020 15:38:10 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5F6AB68B0B6; Tue, 31 Mar 2020 15:38:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6BFE868AAAE for ; Tue, 31 Mar 2020 15:38:04 +0300 (EEST) Received: by mail-wm1-f51.google.com with SMTP id g62so2430392wme.1 for ; Tue, 31 Mar 2020 05:38:04 -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:mime-version :content-transfer-encoding; bh=2g9L1zMLzzTmZMr4EJ/mj8Wdj6Mljv6c4DaZnyHxgs8=; b=kO0jPFx5jkGfx4rGPIyAR65bEHfRG4wrbcKBlYamoDRWmR6SKwd6BVerWSEHmp5dJK yeVKIYI6R40gwYl7a+UocSUH7ooc4wfYWrXdtlcPeXGPtm0RTzOakQETbBDnf1VUhZTm L03vbln96Y9h2go3Cd45KKhPQx/LWzDL0NKHksZd6mVYSfOf+o1wlJ5bBQMJ45ZhLKLn i62mGpOnS0AbXuIMDC2iZomcZkYRwCIWad0Q0BurzlN6Zw00V1KWHR0athhms9JM3FPl PkRt+n2RK2HTRGXU8WP6pVyklNSImKP3HhCx/mVb2c3HEWvTMIhzWqbIh2hZl6FGgiAU 3/CA== 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:mime-version :content-transfer-encoding; bh=2g9L1zMLzzTmZMr4EJ/mj8Wdj6Mljv6c4DaZnyHxgs8=; b=MTWJiCM+gQPucsHcgb2mlkY9ehni5gcqQ1oLAWQ1IuLxspUN6V/WGLhVm8dGoSdqdz b8Mbe2xerITvJ4VHq4ENA77EUslRNUhhhkscSEKCeT5kvVQRLqeDIFlLGbuOJSdLN492 9UvxUsHi8A1lOBVXC7fYRX8sQKVpstt7Y86LX9aBNNP/6vHwt0idA8JdjQKcdXxuYfFt pLQDNtEDNcq+/dbU6CklYNVA9YHWmRckqLRvHNYmHUW6VCbBCyvQoWd3utOTeWqZKhsO sPNh8wp1sEtKzyJZnhMdvK3bYI8RlBzbMvwXZ+uKHOObdnhvdxl7PmxeYMSi9y9FcxJy kirQ== X-Gm-Message-State: ANhLgQ0XdfNxFZWl4MJUxeQbRkEuCZBdP/q1Lq7/21sa6yyEPtYKUI6h aSYxqy2d2+ttgn1gnRygXBJSFKvK X-Google-Smtp-Source: ADFU+vtn/H1Rr4N8xJGOAMpoysNWyeAYKRZS5/t534BiZVh5eUVsFlPgSzT+0NZv0bXxoZvk0WFpPw== X-Received: by 2002:a1c:6285:: with SMTP id w127mr3455336wmb.133.1585658280183; Tue, 31 Mar 2020 05:38:00 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:37:59 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:35 +0200 Message-Id: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 00/10] libavformat/mux patches 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patchset is a slightly revised version of the remaining patches of a patchset I originally sent last August [1]. I resend it because Marton requested it [2]. I have also added three new patches at the end (but they actually don't depend on any of the earlier patches). This patchset intends to address two issues with the same root cause: After trying to put a packet in the interleavement queue (during av_interleaved_write_frame()), the packet is immediately zeroed and reinitialized. The first issue stemming from this is a memleak, because upon error the packet to be zeroed must be unreferenced first. The second issue is that upon success, both zeroing as well as reinitializing are usually redundant, because the packet is already blank (when no custom interleavement function is used). There is unfortunately an obstacle that complicates fixing the memleak: Uncoded frames. Using av_packet_unref() on a packet containing an uncoded frame leaks the frame. So one needs to check first whether it is an uncoded frame and therefore I have tried to concentrate the unreferencing code (with the checks) to as few places as possible by creating a contract for interleavement functions. Notice that there would be another way to handle this: Make the packets containing the uncoded frames reference-counted by creating a special AVBuffer with a custom free function. Then av_packet_unref() could be used to unreference this packet. But this would come at the cost of two more allocations per frame. (The write_uncoded_frame-functions currently have the right to keep the underlying AVFrame (it is transferred as an AVFrame **); this would have to changed -- the best a muxer could do to keep a frame would be to use av_frame_move_ref() to transfer it to another AVFrame. Currently no muxer with write_uncoded_frame support makes use of this right.) Finally, there is one potential memleak that I only noticed recently and that is not fixed in this patchset: If the muxer is closed without writing the header, uncoded frames in the muxing queue would leak, because ff_packet_list_free() is not aware of uncoded frames. Making the uncoded frames reference-counted would automatically fix this. The alternative would be to infect another place (besides libavformat/mux.c) with uncoded frames. - Andreas [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-August/248140.html [2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/259218.html Andreas Rheinhardt (10): avformat/mux: Only prepare input packet if there is a packet avformat/audiointerleave: Fix memleak avformat/avformat.h: Correct some comments avformat/mux: Fix leaks of uncoded frames on errors avformat/mux: Fix memleaks on errors II, improve documentation avformat/mux: Don't modify packets we don't own avformat/mux: Remove pointless timestamp backups avformat/avformat: Clarify documentation of av_interleaved_write_frame() fftools/ffmpeg, doc/examples/remuxing: Remove redundant av_packet_unref libavformat/mux, mxfenc: Don't initialize unnecessarily doc/APIchanges | 4 ++ doc/examples/remuxing.c | 1 - fftools/ffmpeg.c | 1 - libavformat/audiointerleave.c | 7 +- libavformat/audiointerleave.h | 4 ++ libavformat/avformat.h | 25 ++++--- libavformat/internal.h | 20 +++--- libavformat/mux.c | 118 +++++++++++++++++++--------------- libavformat/mxfenc.c | 1 - 9 files changed, 101 insertions(+), 80 deletions(-)