From patchwork Fri Sep 20 20:39:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15192 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 463C34498BB for ; Fri, 20 Sep 2019 23:40:06 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3464168A61E; Fri, 20 Sep 2019 23:40:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D8AF468A581 for ; Fri, 20 Sep 2019 23:39:55 +0300 (EEST) Received: by mail-wm1-f66.google.com with SMTP id p7so3831676wmp.4 for ; Fri, 20 Sep 2019 13:39:55 -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=IjoNi0uz+JrPggvhyzC7PmIfQHXnKlYgNb7dCu0XSkY=; b=P5PJRlH3crJON37ZsjQv4gDzsr+w5hexiLQR3nEjcmIJpmXOsy+I675pSbiwbybqlW CXDHdd5ow3Eg2/DE8Uf2zR6W2re6TG6Lzf3n8pt/jHlJZfslD+qtstYfGU2zvfQeuhIN hVSIHWVbA7JiQ75LMdH6kT24u7VVvrsh0b26yIVLIFmVP1g3mhq0Es78aTi07jN7bqkD n+PgrFNX7zPTGF37M8QIE2pTe4myybltILMFT5dOIp3SDmzL13KylMH8btR++ekWBpLx eA43QX6jX5iaHc24XO6jAiovJgth+ad1LhJIRue1NQmYcQQ9V+SmT+jiLzf8VSZULCek N3rA== 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=IjoNi0uz+JrPggvhyzC7PmIfQHXnKlYgNb7dCu0XSkY=; b=cqfOfhTZlpobiHc9a1gOmIkajQF4SMdTpQLNjgjSOFEkwOckQXUd0RnGvBYAVeBOsK bUlvh8h3VCJCAK5vc/2xmoXo/nNh19YsArVcbYHjN5JdTkpyer9V20yes92U2BTLWfW9 IEs0HDMGz5Scv4WbJG/atTtKOHKLKo/RKaJl9WwRG62RafshxSH5tkLqGGHFCPetOxXx qBxgY0b63THVp5pOz/kGBwH1zDnto3TBR4emI019rnTX1JeSypqK8ZDBjic58B4cPTIr ndLyJlt8QgyfE3xtQLlF0K4nwVhKk76X/dVrYiHIj3QdsrfJEe9fHDoUFK0jXGT40sfo hg7g== X-Gm-Message-State: APjAAAUkQ3JK0I/M0vFjZ60M13DEBqJqaO2xv5alwRiFtF/DO85laJvc rE4q/48iDhUw5/dE3qy0qpWBNY0P X-Google-Smtp-Source: APXvYqyGR/rJSG6u7qarYi7R55eoMURLZNpJCk903nDZew+GAnJxSsqXxocq/fF81KX1oGFPBbVhHg== X-Received: by 2002:a1c:5fd6:: with SMTP id t205mr4731881wmb.124.1569011995231; Fri, 20 Sep 2019 13:39:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:54 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:11 +0200 Message-Id: <20190920203916.16904-5-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 4/9] avformat/utils: Don't initialize in loops 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" Since the recent changes to ff_packet_list_put, the source packet will be automatically reset when the reference is moved to the packet list, so that it is unnecessary to reinitialize the packet in the loops in parse_packet and ff_read_packet; initializing once at the beginning is enough. This also fixes a potential, but currently unexisting problem: If the raw packet buffer was initially not empty and probe_codec() failed, then the packet returned would not be initialized. But given that probe_codec() currently can't fail (always returns 0) this was not an acute danger. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 58e0db61da..cf326ad014 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -830,6 +830,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, i, err; AVStream *st; + pkt->data = NULL; + pkt->size = 0; + av_init_packet(pkt); + for (;;) { AVPacketList *pktl = s->internal->raw_packet_buffer; const AVPacket *pkt1; @@ -847,9 +851,6 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) } } - pkt->data = NULL; - pkt->size = 0; - av_init_packet(pkt); ret = s->iformat->read_packet(s, pkt); if (ret < 0) { av_packet_unref(pkt); @@ -1448,6 +1449,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) int size = pkt ? pkt->size : 0; int ret = 0, got_output = 0; + av_init_packet(&out_pkt); + if (!pkt) { av_init_packet(&flush_pkt); pkt = &flush_pkt; @@ -1462,7 +1465,6 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) int64_t next_pts = pkt->pts; int64_t next_dts = pkt->dts; - av_init_packet(&out_pkt); len = av_parser_parse2(st->parser, st->internal->avctx, &out_pkt.data, &out_pkt.size, data, size, pkt->pts, pkt->dts, pkt->pos);