From patchwork Fri Sep 20 20:39:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15191 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 89FCD4498BB for ; Fri, 20 Sep 2019 23:40:05 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 737DF68A61A; Fri, 20 Sep 2019 23:40:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E5A968A574 for ; Fri, 20 Sep 2019 23:39:59 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id r5so8016126wrm.12 for ; Fri, 20 Sep 2019 13:39:59 -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=IRp30sJPQbVsp/iBKVnkf75KtUPvallG3FJhWv3gimo=; b=q1tPsfoglCNQTB1rfBbeYYOvWLUj/iU+IDpdI7gT7/U1oG+m5I7fEKc7n+N7ppNA9S SIcPM5ptyBg0qCOUpHFeJ8Abxg5uWZu6mGTc94/A49CxLvtayMPk2tXh39h6lRvt60sD IYKYJYt6IGKZHXQQXk7bVFyIvPDK0PsaVKu4/EbtN1LmHWY3WxGbWStGYeGrrLgH8ydQ 8iiWQeVgEJijUPSMUitbT5ym03EweMTvd/3LB8dISerFAlxJF6yI1vgjvWp2g8CSNCKR Qt9lITHvpx1RsOlj6YGIg3oCzf+beei5dY6mcfYjaSOVdRV+/+Lxg9hfUfnNp93UoiZt DbYA== 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=IRp30sJPQbVsp/iBKVnkf75KtUPvallG3FJhWv3gimo=; b=XwAIQW6DvGQGpE9nOM1JzYnWLVXvI5ProTWlZJEjAv57tipMcMeZhEfD2k/sNTq4qB 52ZVvPYMRA1DsS4XB+LznHS7DsgufDv9FjWNBTDCj2rAOrzYjsJi/eI+BikhBd6l39Fz u7gp9tQ0jBsIGglO/iFcZMBVHHrP19yeA/4TqqZIsPO76tRNlhtLi7Hiy1wFD4SCs3os sbMzWRxPMumM2XoxMJmgA4AMeu/taeddBekcu4cJYLiOwQQknZ9Sh1vi0q9m6K2omSG3 AUo+isQng5LKdAVtKE4P84u/56gcPdY4sjcuT133COqB9q4F5AbHTY1yw1WudPDu9cja h20A== X-Gm-Message-State: APjAAAW7KuJSk7ITy2nmB88wi7aa0x7SNrJKAeHTqjzXLJvwipJBWOPH 2uBV3r+V1nvUbnfhWevgHRpLSMzo X-Google-Smtp-Source: APXvYqwDhyO6UdswlcSKxyjEOGCppT9d1O5SGTBacPsp0uD/VIUPA/t+3H1LgYmo/NUI7DjSJIo26Q== X-Received: by 2002:a5d:5185:: with SMTP id k5mr12161725wrv.341.1569011998674; Fri, 20 Sep 2019 13:39:58 -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.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:58 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:15 +0200 Message-Id: <20190920203916.16904-9-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 8/9] avformat/utils: Improve parsing packets 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, parse_packet() used a stack packet in case the stream is flushed. But using such a packet is unnecessary as there is an AVPacket readily available, it just needs to be used. Whether flushing is intended or not will now be signalled by an explicit parameter rather than by whether the packet parameter is NULL. This removes a few checks in parse_packet(), gets rid of the initialization of the stack packet and also reduces usage of sizeof(AVPacket) in libavformat. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 291084f6de..28950b9290 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1439,28 +1439,26 @@ void ff_packet_list_free(AVPacketList **pkt_buf, AVPacketList **pkt_buf_end) /** * Parse a packet, add all split parts to parse_queue. * - * @param pkt Packet to parse, NULL when flushing the parser at end of stream. + * @param pkt Packet to parse; must not be NULL. + * @param flush Indicates whether to flush. If set, pkt must be blank. */ -static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) +static int parse_packet(AVFormatContext *s, AVPacket *pkt, + int stream_index, int flush) { - AVPacket out_pkt = { 0 }, flush_pkt = { 0 }; + AVPacket out_pkt = { 0 }; AVStream *st = s->streams[stream_index]; - uint8_t *data = pkt ? pkt->data : NULL; - int size = pkt ? pkt->size : 0; - int ret = 0, got_output = 0; + uint8_t *data = pkt->data; + int size = pkt->size; + int ret = 0, got_output = flush; av_init_packet(&out_pkt); - if (!pkt) { - av_init_packet(&flush_pkt); - pkt = &flush_pkt; - got_output = 1; - } else if (!size && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) { + if (!size && !flush && 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); } - while (size > 0 || (pkt == &flush_pkt && got_output)) { + while (size > 0 || (flush && got_output)) { int len; int64_t next_pts = pkt->pts; int64_t next_dts = pkt->dts; @@ -1544,7 +1542,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) } /* end of the stream => close and free the parser */ - if (pkt == &flush_pkt) { + if (flush) { av_parser_close(st->parser); st->parser = NULL; } @@ -1593,7 +1591,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) for (i = 0; i < s->nb_streams; i++) { st = s->streams[i]; if (st->parser && st->need_parsing) - parse_packet(s, NULL, st->index); + parse_packet(s, pkt, st->index, 1); } /* all remaining packets are now in parse_queue => * really terminate parsing */ @@ -1681,7 +1679,7 @@ FF_ENABLE_DEPRECATION_WARNINGS } got_packet = 1; } else if (st->discard < AVDISCARD_ALL) { - if ((ret = parse_packet(s, pkt, pkt->stream_index)) < 0) + if ((ret = parse_packet(s, pkt, pkt->stream_index, 0)) < 0) return ret; st->codecpar->sample_rate = st->internal->avctx->sample_rate; st->codecpar->bit_rate = st->internal->avctx->bit_rate;