From patchwork Mon Aug 19 21:56:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 14593 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 9C961444AEE for ; Tue, 20 Aug 2019 01:04:01 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 84B8868A996; Tue, 20 Aug 2019 01:04:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06AD8689D73 for ; Tue, 20 Aug 2019 01:03:56 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id k1so582204wmi.1 for ; Mon, 19 Aug 2019 15:03:56 -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=2lW1B6cUrZdhL5jHIsTJDMm9Xs2Ybd85wDjx64vGzL0=; b=XAI8G4KMSrG7zuF1Kk5NEvDI9JGbU5v1iyj7k421juR01WEjVC4YrSN3gIRhEkl/2G Rxs+/ClhRn5RAuEoFXNcwgv5Tyk4oR3+QDugYFI+xnNy5bnV8N9sikvCwoFzECbme+dj hlGuULr3ojAjy8blLi9IPtaYvNw5mqyTV03LOkHw3DSTSZ9pWGnXNadxC0kUA50yqQ9P mNsZQn8QyJHuqtVoQVP775vZEhV5LFSk6pFXIYoQR5FyXR/AGO7JXYf7jNxH1D7GErBN iB7l0DdqlPT1ntGn7QnwfHGy7G/dh3T8rXpNWG0d2BP4h069qZXagE9/lzO1okWgBEVM Cp0Q== 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=2lW1B6cUrZdhL5jHIsTJDMm9Xs2Ybd85wDjx64vGzL0=; b=lOA61A6hZnnuzJU1ryP39gVnYyYgNmWZRYMz7ourWfecXBCZSUu9GhTHWrD1fcPaSs HF2EZoQSk1K8tbdjqpW5Jyo7jweHS90PQJgjYBFMnNJpacdqScSvEMvxFyn/e8w6qF5F UPxYtWfQCPh+GSaRpg0HE4vL+ovUe96BlqgxgMp1eaHYY4IVVdBC+sYdzV5gs5ZEPEvj DrfFNhobVPr7NrlD7ACF8FiKiQTQwk2BKiQ0gyw9Eg4QNPcodh9FtPFM9OzkhMx/Z7Az og8VqMI0k/qEiEdjRJcTs5vQy/DEAF1WgdVPDWZD/KM6PYQUvpAEeOMBxaF4KyqRTnzZ OQjQ== X-Gm-Message-State: APjAAAX11kUPSnLNduZBdUi1FvfC1riakfoUvIbOvvhy/0b3Xk6W8XAN eS/GcsP8srpuMX6zc949UonRQZ7B X-Google-Smtp-Source: APXvYqzEUx4mgh/xUJOs6EHUQW4XwTmRmdhAfjan5853jz8c2weEhaV5a4gFchgtH0cDbi3wr/Y35g== X-Received: by 2002:a1c:721a:: with SMTP id n26mr21709599wmc.88.1566252235267; Mon, 19 Aug 2019 15:03:55 -0700 (PDT) Received: from localhost.localdomain (ipbcc08c5c.dynamic.kabel-deutschland.de. [188.192.140.92]) by smtp.gmail.com with ESMTPSA id s64sm32952293wmf.16.2019.08.19.15.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Aug 2019 15:03:54 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 19 Aug 2019 23:56:20 +0200 Message-Id: <20190819215624.49795-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> References: <20190819215624.49795-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 4/8] 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 b93d80588d..bae2f9e0db 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]; @@ -923,9 +921,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; } } @@ -3028,8 +3027,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; @@ -3521,7 +3520,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; @@ -3584,7 +3583,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; @@ -3703,6 +3702,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; @@ -3796,14 +3796,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]; @@ -3881,7 +3883,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) { @@ -3918,7 +3920,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++;