From patchwork Fri Sep 20 20:39:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15187 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 5141E4495B9 for ; Fri, 20 Sep 2019 23:39:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 34D2F68A538; Fri, 20 Sep 2019 23:39:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C788368A435 for ; Fri, 20 Sep 2019 23:39:57 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id y19so8078969wrd.3 for ; Fri, 20 Sep 2019 13:39: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=eQedL4H0W9yrNVTejjfHjvzRcPwJOWioQNX1CKJ205E=; b=LIDbF2dv/JZWDUbqWl6NQmYPJMhAUTYx4JNM/kE2TxPEK1K8U7PbE59gk224n/4YyW rb7Nt2RXej7zfG7UQjumDwfwIowvYc6uopHzX955/1+JNuL677lwVje38jEqrpjs+B5m OFEwkMRgbXW0XWX2XVkd/MjNXKucfPNIDSt/tES7eCaVLHQRLd0McdxyAzZ+25Y5dkmg 7/ncp6e+dMXI9URvu+8tJDq4fYs3nWkmH0enDvV52uSXhNefHL114FjJjFpy86jb99Hu K8cpkBmOEHeo4LolVE0cySdjYkhywf6O8z0LB7eBI9nr11aG7sXaGz91Fk8pRvVW9ExF kX9A== 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=eQedL4H0W9yrNVTejjfHjvzRcPwJOWioQNX1CKJ205E=; b=LLaS8sxAig4FRfkFe5Z7B7UGsJ4h94K3KYqb4Omtj6Frlt7PxLU+o4cKWUJF4/ZtGC cJmKLm1sRglsoj33Mlfbz1nwA019ni0vLiRqQ0dVkjlCgau05nwv3ZeNIkjUOeiT2HiJ XCeQphBEFkHwPUUPCkIaatgaNIKVn+V/JfKLPOnTf2CKo94nUmeGzv4G9x+8hH9ztSjt dr32hMY5hpUgc+6pREdYuH4axJGVZ8/gZ+uddG2IQmtLaIlYUjJ7oOHYH5srWxHyAgNr hipfM1V+Vhx3Jx9VBIWGEyExwMYQd/ZuPBAvQNJz78twWiq+57LWDGVlN96CKJI244wZ f9uQ== X-Gm-Message-State: APjAAAXSgTn5VbhgNdgTwgP24f7lUDhM44ybsGZynsqOYWU5x3yfB6j9 si1xhEDcgLGeOJKGIKkJ9ZCrlsUd X-Google-Smtp-Source: APXvYqxv0aUAeafy4gRgl1vXK7Fjz1B41Lwwec/lgTkKG4VymwsEez+lQbCyfuOH/TBZgkoMK9CCbg== X-Received: by 2002:a5d:4041:: with SMTP id w1mr13209695wrp.313.1569011996937; Fri, 20 Sep 2019 13:39:56 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc0f857.dynamic.kabel-deutschland.de. [188.192.248.87]) by smtp.gmail.com with ESMTPSA id m62sm3734041wmm.35.2019.09.20.13.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:56 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:13 +0200 Message-Id: <20190920203916.16904-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190920203916.16904-1-andreas.rheinhardt@gmail.com> References: <20190920203916.16904-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v4 6/9] 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 701e9ea030..4eb063c54a 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1856,10 +1856,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: