From patchwork Mon Aug 19 21:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14594 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 6EF2C444AEE for ; Tue, 20 Aug 2019 01:04:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 50A0A68AB65; Tue, 20 Aug 2019 01:04:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BF04268AABC for ; Tue, 20 Aug 2019 01:03:57 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id p77so979017wme.0 for ; Mon, 19 Aug 2019 15:03:57 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=seKU3PtOBb67hGSgLpaBsXeR7h6Rpd8GNFQCRfb4XkI=; b=T9aRQY4OJKXUklxGFKu3/B1OZpttKzs1VgZwHoZVl2zKNnzZECbQqNX9IhC1mXGGNh sH2na5wr+ZTsl5ONpOZnk5PFRHNk1nZwxKw0kb6I8M+eXlaOGz4AoD+67zdqOaIwTEQJ EaQ1FNbwbgUITmq8bpPPTDAycC45yhLiE8E2v49GNghrM1ZDu0/2Q+qseWHTsYMk1qnx 029bLRGzZFjuUqlO/BpwYFH0kR0TeHLmLTZHyCj5bv4sAose6Z7TvRK3TFPPTY1FzHob 8/u2fF3PZkRNmkiA15E9LHIsHU3iNb9siNE2FMZ7whpLeelUqlHJRUhcJxcxVtteHPgy Hr7A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=seKU3PtOBb67hGSgLpaBsXeR7h6Rpd8GNFQCRfb4XkI=; b=lxNubAKcx0Kt1Xo1pefDfwbt36qyWj/oNfrMnndBxsTUh+ftXTwLb0dE8CA3nFEYuz 00DEphx5AUeYGWjzhCk0p3um0NXIsO8fz/6CMQAI3MjSwNmmPXtV/uGv08v+iYQdCuvE 0hf7Knhbkfg2RtelykpUf9Mi9X9C9CYgLuOH373XIHJYXoYpLed0VpGQ2LzfCGn3PZXd Fd6CYBFT/34bGdEPf4Xsf3t7YGukRcLi8UY30R7oS7qoGnv2v+5rbRaY/0TlICaoGo+Y EvULvYgqLCvROlZ+jzEGv/Gr7D/p8Wzy5Zrz2MIZp3vkiKEuAjXiGqtls2TA3Ebup516 Qfmw== X-Gm-Message-State: APjAAAU4in8nkErcdqoBXLQYMMkWZcYNsIRU6UEIiA15dnZgvUeKljHB tfnH8ADLafaYoT2L4rshhPpUMGu3 X-Google-Smtp-Source: APXvYqzkgwOHB1Dsy9iDla/EMAzf5JvMlTm0vK2OwXfnfjL3lKBNDn0cJQqfshpvqQDrmmgSnqMjnw== X-Received: by 2002:a1c:b6d4:: with SMTP id g203mr22174404wmf.100.1566252236988; Mon, 19 Aug 2019 15:03:56 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c5c.dynamic.kabel-deutschland.de. [188.192.140.92]) by smtp.gmail.com with ESMTPSA id s64sm32952293wmf.16.2019.08.19.15.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 15:03:56 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Aug 2019 23:56:22 +0200 Message-Id: <20190819215624.49795-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> References: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/8] avformat/utils: Don't create unnecessary references 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" When AVFMT_FLAG_GENPTS is set, av_read_frame would put a reference to a packet in the packet list (via av_packet_ref) and then immediately thereafter unreference the original packet. This has been changed to move the reference instead. Given that the packet originated from read_frame_internal, it is already reference counted*, so that the outcome of the new code is equivalent to the old code. *: Packets from read_frame_internal either come directly from ff_read_packet or from parse_packet; the latter makes sure that the packet is reference counted. Packets from the former have been either directly read or come from the raw_packet_buffer. The directly read packets have been made refcounted and the other packets originate either from directly read ones or from attached pics which are inserted into the packet list via av_packet_ref. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 96c02bb7fc..db0f53869f 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1847,10 +1847,11 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) ret = ff_packet_list_put(&s->internal->packet_buffer, &s->internal->packet_buffer_end, - pkt, FF_PACKETLIST_FLAG_REF_PACKET); - av_packet_unref(pkt); - if (ret < 0) + pkt, 0); + if (ret < 0) { + av_packet_unref(pkt); return ret; + } } return_packet: