From patchwork Fri Sep 20 20:39:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15189 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 DC1A74498BB for ; Fri, 20 Sep 2019 23:40:03 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C8F6C68A588; Fri, 20 Sep 2019 23:40:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE1A968A4D4 for ; Fri, 20 Sep 2019 23:39:54 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id y135so10350608wmc.1 for ; Fri, 20 Sep 2019 13:39:54 -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=K1kafkWStdD4xwTztCixE5Nwe7d+u0CBBURvI0cJ8Ro=; b=mrdy1hQxDHjGDbWp0W9tRxZoajjZkrgwQzv+DtF7L/wvLBoZeLDGwQrJT0Oakc4b1p VInxQxyhVo/HyPL4fCeksbRZRxkZt/FdkpwnZXmsN9e/1SBXfbKzzw2QLiU0zvjg6hHq HxFTTsue0sZGO+5DOIyjpueYQr7nxgJmtfpkuYlxuSTxLrh7yppR25KoYf94wFDm/QMH Y/0Morv3b0SwzY06J3ysA/dH2eMKbqfTN4hw0z8XX9zMQNDynV2xYJraDEG4DFSV3kWf 7L23g5gBehgtn210/TwjqVdeU4xN75Ug469UhUlFxUWIf1vbsqgT0ylUBgxVTVOkDFJX 9Krg== 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=K1kafkWStdD4xwTztCixE5Nwe7d+u0CBBURvI0cJ8Ro=; b=VdZ6k5thv7STdU7cYLDCwa5z8r+hkvKcpCe/3qss1zXpVBXweJljXWnUI/9cdnAZwa GGvRaWgq3lDo4w+bfvxACWMdIL4306M8vXguoibzKcIW7m2XmzaCcwsQhxjx6corxPna QImESKgTszoHj/YTIXKseAdt/pUXf7ci+o7oVYvPsecIO+lpJgE9u1kP39VT7H/pEu1P LqFM9YHLWRx++RNK8P6QA4mqhpzkl4bQ83B5PJwd3bTf/b1BuTu+1fbCC4aLVtpdmvkO X9OzKOp6I7gbfjlQ6LSrtNpqgy0I0mJc0fWhlyURSrLaaitpmpzAo5T16d9HCDScRuDl 2fWw== X-Gm-Message-State: APjAAAXf98wP6swATFMiKO5+9BliyC6ADJgYSyxBk7QvjD6qIs3RC6m4 bO7kN8HqfH5Axyz/sic8yYVxM34S X-Google-Smtp-Source: APXvYqyqmVd9Bf9jqJB/Od15OSI7fZgl/OQM6y3+8Wr9Fj8Ez4vLcqf0lNayxKWbglPQ+4VlBqMGNA== X-Received: by 2002:a7b:cf12:: with SMTP id l18mr5168583wmg.25.1569011994145; Fri, 20 Sep 2019 13:39:54 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2019 13:39:53 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 20 Sep 2019 22:39:10 +0200 Message-Id: <20190920203916.16904-4-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 3/9] avformat/utils: Move the reference to the packet list 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, ff_packet_list_put had a flaw: When it moved a packet to the list (meaning, when it ought to move the reference to the packet list instead of creating a new one via av_packet_ref), it did not reset the original packet, confusing the ownership of the data in the packet. This has been done because some callers of this function were not compatible with resetting the packet. This commit changes these callers and fixes this flaw. In order to indicate that the ownership of the packet has moved to the packet list, pointers to constant AVPackets are used whenever the target of the pointer might already be owned by the packet list. Signed-off-by: Andreas Rheinhardt --- libavformat/utils.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index e348df3269..58e0db61da 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -460,10 +460,7 @@ int ff_packet_list_put(AVPacketList **packet_buffer, return ret; } } else { - // TODO: Adapt callers in this file so the line below can use - // av_packet_move_ref() to effectively move the reference - // to the list. - pktl->pkt = *pkt; + av_packet_move_ref(&pktl->pkt, pkt); } if (*packet_buffer) @@ -835,6 +832,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) for (;;) { AVPacketList *pktl = s->internal->raw_packet_buffer; + const AVPacket *pkt1; if (pktl) { st = s->streams[pktl->pkt.stream_index]; @@ -925,9 +923,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) av_packet_unref(pkt); return err; } - s->internal->raw_packet_buffer_remaining_size -= pkt->size; + pkt1 = &s->internal->raw_packet_buffer_end->pkt; + s->internal->raw_packet_buffer_remaining_size -= pkt1->size; - if ((err = probe_codec(s, st, pkt)) < 0) + if ((err = probe_codec(s, st, pkt1)) < 0) return err; } } @@ -3035,8 +3034,8 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) } /* returns 1 or 0 if or if not decoded data was returned, or a negative error */ -static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, - AVDictionary **options) +static int try_decode_frame(AVFormatContext *s, AVStream *st, + const AVPacket *avpkt, AVDictionary **options) { AVCodecContext *avctx = st->internal->avctx; const AVCodec *codec; @@ -3528,7 +3527,7 @@ fail: return ret; } -static int extract_extradata(AVStream *st, AVPacket *pkt) +static int extract_extradata(AVStream *st, const AVPacket *pkt) { AVStreamInternal *sti = st->internal; AVPacket *pkt_ref; @@ -3591,7 +3590,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) int64_t read_size; AVStream *st; AVCodecContext *avctx; - AVPacket pkt1, *pkt; + AVPacket pkt1; int64_t old_offset = avio_tell(ic->pb); // new streams might appear, no options for those int orig_nb_streams = ic->nb_streams; @@ -3710,6 +3709,7 @@ FF_ENABLE_DEPRECATION_WARNINGS read_size = 0; for (;;) { + const AVPacket *pkt; int analyzed_all_streams; if (ff_check_interrupt(&ic->interrupt_callback)) { ret = AVERROR_EXIT; @@ -3803,14 +3803,16 @@ FF_ENABLE_DEPRECATION_WARNINGS break; } - pkt = &pkt1; - if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { ret = ff_packet_list_put(&ic->internal->packet_buffer, &ic->internal->packet_buffer_end, - pkt, 0); + &pkt1, 0); if (ret < 0) goto find_stream_info_err; + + pkt = &ic->internal->packet_buffer_end->pkt; + } else { + pkt = &pkt1; } st = ic->streams[pkt->stream_index]; @@ -3888,7 +3890,7 @@ FF_ENABLE_DEPRECATION_WARNINGS limit, t, pkt->stream_index); if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(pkt); + av_packet_unref(&pkt1); break; } if (pkt->duration) { @@ -3925,7 +3927,7 @@ FF_ENABLE_DEPRECATION_WARNINGS (options && i < orig_nb_streams) ? &options[i] : NULL); if (ic->flags & AVFMT_FLAG_NOBUFFER) - av_packet_unref(pkt); + av_packet_unref(&pkt1); st->codec_info_nb_frames++; count++;