From patchwork Fri Sep 20 20:39:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15190 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 C944A4498BB for ; Fri, 20 Sep 2019 23:40:04 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BC8C768A59B; Fri, 20 Sep 2019 23:40:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1BE1468A55D for ; Fri, 20 Sep 2019 23:40:00 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id o18so8022239wrv.13 for ; Fri, 20 Sep 2019 13:40:00 -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=da1ZrfMM9sdHnr5THeavSH99vvvtI3HQfmpxcndVRnU=; b=cbrPXCCmKR4DzaszBuiMe1RimxBkZWn7LJ0hUQlGHpVr6dmUE/huIMY8YVuU7ZaxJc JEMM7I4p5yInBc2OsJ5CvQBi7JpHNoXzoFBdfYAzeeLG+Ge72LmF5wV8qawVb+HfC+Nk sxOtIqoiT2RqunlUkF9OihhgWPgHBsz7T3wXru8wz+u4rmQczW0TrCiGMz1NGjvnnxM4 kKILdinnIVVu8Zt29KDroec6KJIC/D/6K9oDh6p+ATTE588uzO1qlVlKvRXt/Prq0lY6 zgkPzJeXFPZ/jNnoghIfMGje9cOLiguSCKxql651uGnX0o00tHJGzI/Dd/Rmpg1/TTN3 db/g== 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=da1ZrfMM9sdHnr5THeavSH99vvvtI3HQfmpxcndVRnU=; b=qXwHghJz3sAsqSdumLoU3aHOnVkU2OhjlaxcB28CYf9hSV+Qj+oG3Y8k+VTmlYV97+ R2u1Oo6ZnD+cb6THPI0XVNry6AZkZVhUjExbmDHeqRby4mQ/T75uv+wPIO9ta5ATer0h zZqGKGjXJ2NCVy1axqncrKocevkb/iCkF5qhWnkmHHQpIla0I4k6msqHWxHXEoYZnbmM skAf+urngYzuldA9q0qziJvGI3j7mx1FtSWyVbrHuopJrDDFTHJ5TjqpN9Pl3rbpMgOs 7jYdoqDy/w/7NpIMvH1gZWk9s6NxrRr0jqAVPQf/k254D3DekAPu111Hfxx9MEpIrb0/ NvCA== X-Gm-Message-State: APjAAAXvgZph3pi3MFW0XEP2TSba/YABXdcd/2tnh/fKlyBlcNJsbIMs AXqztZCb6sfiXtijpWa+T9JndRZI X-Google-Smtp-Source: APXvYqz0V7p5nIOi5vF6SuZgGXaNIhNJg72FSz9NE2HFmYc1AqLuRvWG4Nz1CN4P/tz65f/hiOyHqw== X-Received: by 2002:adf:ea88:: with SMTP id s8mr13426841wrm.114.1569011999439; Fri, 20 Sep 2019 13:39:59 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:59 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:16 +0200 Message-Id: <20190920203916.16904-10-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 9/9] avformat/utils: Remove unnecessary initializations 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" Up until now, read_frame_internal always initialized the packet it received. But since the recent changes to ff_read_packet, this is no longer needed: If the parsing queue is initially empty upon entering read_frame_internal, the packet will now either contain content upon success or be blank upon failure of ff_read_packet. If the parsing queue is initially not empty, the packet will be overwritten with the oldest one from the parsing queue. Similarly, it is unnecessary to initialize ret in read_frame_internal. In parse_packet, it is easily possible to only initialize the packet used as temporary storage for the output if said packet is used at all; furthermore, this packet doesn't need to be zero-initialized, because av_init_packet will initialize every field except size and data and those fields will be set by av_parser_parse2. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 28950b9290..b1a79dd54e 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1445,15 +1445,15 @@ void ff_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end) static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index, int flush) { - AVPacket out_pkt = { 0 }; + AVPacket out_pkt; AVStream *st = s->streams[stream_index]; uint8_t *data = pkt->data; int size = pkt->size; int ret = 0, got_output = flush; - av_init_packet(&out_pkt); - - if (!size && !flush && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { + if (size || flush) { + av_init_packet(&out_pkt); + } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { // preserve 0-size sync packets compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE); } @@ -1574,11 +1574,9 @@ static int64_t ts_to_samples(AVStream *st, int64_t ts) static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) { - int ret = 0, i, got_packet = 0; + int ret, i, got_packet = 0; AVDictionary *metadata = NULL; - av_init_packet(pkt); - while (!got_packet && !s->internal->parse_queue) { AVStream *st;