From patchwork Tue Mar 31 12:37:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18531 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 B74D244B0FC for ; Tue, 31 Mar 2020 15:38:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A163568B128; Tue, 31 Mar 2020 15:38:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4662F68B06C for ; Tue, 31 Mar 2020 15:38:28 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id j17so25636346wru.13 for ; Tue, 31 Mar 2020 05:38:28 -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=8OcZCIJ02zLA3wXZXZh9IkxPIZcx/4Vc/bsCnqLJCck=; b=vE9oirDge6X7iRCMA4UjhQmdqrfwV08Z+YeuJThcQ1+jo0bCvQHU6z6h+vtSaE4R6F aeEvn/BPxFVh9cZ5pDgbaW/eCNyl9TY+Jxk+QuXBcZW2MgApKcYT0DsBEU9QKSLpFtTO G54TnSlhL1UirNvqqOZC9tR4x+ELFvnYVQH6qZtoB2oxMwZHAAJgo2snbeUSKdm5iimm Dou4BOyKkLnJGZ4a/6QiwTkW1872Ih7RC/m2Cn4gSvvAVJnAF5sKObapVd5GqRsgNtWv 1br9iPE7fUhwWVsXiplphLF1WPgtKE2XTGdOqIVaJrm0C9ZSI0rrcXS4HgGK10XXPR+H Wdcg== 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=8OcZCIJ02zLA3wXZXZh9IkxPIZcx/4Vc/bsCnqLJCck=; b=fS46KP+AXPX05uzxt/WvdwdWF6Q6nn7+CyYrNGfPF+JBeYk0BAlBEzjKKIdhqpmqPh dj7V47GpryTOoqoBqfhSei0MRMT8xyf/s84IjLec9K3VgzTCNqIn6kTOUrjLMWkj/mCA QQ9e6SfvkF3+sgOQD6ZeLfxN/ORQzYaRrTTs/Q9WbwSTk5xnul52gNOfWqnhxArtZsXU jNNpyCKdgLH/Dv5AKOUttdT0aKR2FjcaoXLI4MXJMFbU99rEEr13DCHs1KJOv76vfZbQ x7H9RcMUoyIo5KwGcLL5m536Qb/VC2XowFDwmZU4A9/z3tndCxxIhFwrMOg7pYmE5lV4 HQvQ== X-Gm-Message-State: ANhLgQ2VgBpWb5Gbm0HMIgz9Tpcz8ndfkn5FwRVEjgaeZS7bIo8oC3yT 7pD92rBS16FzygAVz+evR11wbDo/ X-Google-Smtp-Source: ADFU+vtOqz3WqHcfcF6LRoBeKgw8EvmjNTYZ5d6E4aHOrIJvmVUylET/Fw3UCP7cJX95vmYsxWMiWA== X-Received: by 2002:adf:dd06:: with SMTP id a6mr20656358wrm.189.1585658307419; Tue, 31 Mar 2020 05:38:27 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:26 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:36 +0200 Message-Id: <20200331123745.6461-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/10] avformat/mux: Only prepare input packet if there is a packet 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" It is unnecessary to call prepare_input_packet if there is no packet as it doesn't do anything, except when the currently inactive code guarded by !FF_API_COMPUTE_PKT_FIELDS2 || !FF_API_LAVF_AVCTX becomes active: Then attempting to access pkt->stream_index will crash. Signed-off-by: Andreas Rheinhardt --- This works very well together with Marton's patch #4 [1]: write_packets_common(): The prepare_input_packet() call can be moved into write_packets_common(). Unfortunately, it's not compatible with #5 [2] as-is, but I think I have a solution for this. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/259203.html [2]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/259204.html libavformat/mux.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index bfd1bf491b..814d773b9d 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -771,9 +771,6 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) static int check_packet(AVFormatContext *s, AVPacket *pkt) { - if (!pkt) - return 0; - if (pkt->stream_index < 0 || pkt->stream_index >= s->nb_streams) { av_log(s, AV_LOG_ERROR, "Invalid packet stream index: %d\n", pkt->stream_index); @@ -887,10 +884,6 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) { int ret; - ret = prepare_input_packet(s, pkt); - if (ret < 0) - return ret; - if (!pkt) { if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { ret = s->oformat->write_packet(s, NULL); @@ -902,6 +895,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) return 1; } + ret = prepare_input_packet(s, pkt); + if (ret < 0) + return ret; + ret = do_packet_auto_bsf(s, pkt); if (ret <= 0) return ret; @@ -1191,12 +1188,12 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) { int ret, flush = 0; - ret = prepare_input_packet(s, pkt); - if (ret < 0) - goto fail; - if (pkt) { - AVStream *st = s->streams[pkt->stream_index]; + AVStream *st; + + ret = prepare_input_packet(s, pkt); + if (ret < 0) + goto fail; ret = do_packet_auto_bsf(s, pkt); if (ret == 0) @@ -1209,6 +1206,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) pkt->size, av_ts2str(pkt->dts), av_ts2str(pkt->pts)); #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX + st = s->streams[pkt->stream_index]; if ((ret = compute_muxer_pkt_fields(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) goto fail; #endif From patchwork Tue Mar 31 12:37:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18538 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 B9B9244AF30 for ; Tue, 31 Mar 2020 15:46:18 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9F11C68B1AF; Tue, 31 Mar 2020 15:46:18 +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 880D668B14F for ; Tue, 31 Mar 2020 15:46:11 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id c195so1061074wme.1 for ; Tue, 31 Mar 2020 05:46:11 -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=Racd5NPeWUvS3Mod1mgqBV6dFj8nFq60AjMoNz9485s=; b=WoDEPayvIxlYUvGdaRf+xtvnnIaaAzihvkQi/+pQDMN1pgZSwIIYca1atMSW0mlukS VcFiBn75qej9tubc6brd2EF9PD2iNCY+U1Qi6vyheUno8ACX+YM+yBNxvGCtA/8IZL7b u+rNHQEb1K6xBERCu4fRCsulj9cgsnfhhg5L1z0uJX4nGs6En1t3YXQ53/0Kbtt5wjOf wtwHju5BjxAD7Dc5VIwXHmm+OlhjHRKqt5N+cISTrPSrHLsfqQNPDOhsiaaa7BkZiCHE fFzz8s94MLw/Ned7m1rWqoCitUz97dp10gso5/HRDJveJN18KJHdbLfbs8uR1MczA9Gi j/2g== 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=Racd5NPeWUvS3Mod1mgqBV6dFj8nFq60AjMoNz9485s=; b=fCqSY3N8bRPj/unBPvM9ffb4AT7c195ELDiAKanzDhrVRvDncM6BzlvHJ3o5IRCemQ r3IUOlVY2D4EhDzHfIrfZqhm8YJRB0q8qfDz9TXKEjgmrje1Akgp6SVcn3Sxa7j/tXgz CxWnZqzODZNNeLuFj/zCuXgcCyhcePcmMhBCoDBcCq2/CCZG3Cf3vWCIDTNRByz7jfKd RjMP82AwNrqYvQXbphqfwDvyAT0d/8A+OzRlAn45Z3F4oD+LOA8dC0fuWmQEYcaq37BG jEuOQ5GLtWL6+0Yd+eVlXCv/zRn9yoop4gKW2L7LPCbbN+WrfbCyp4imyfjRUyrbbNP0 JaHQ== X-Gm-Message-State: ANhLgQ3BAEVM/cx8//1FTfKWXzd+Z1aPZZc2RVteOOev91qVKoTj6Pfl JnGk2oK6r3NwOeDtz0TR8GW0+z/h X-Google-Smtp-Source: ADFU+vuA6lBP7SZ7BwqnArMxVSKQkoz0ZiL7sVp88zc4B7b+YVxkvI185XDfM0rOX0G1mqpRcnUOzA== X-Received: by 2002:a1c:5506:: with SMTP id j6mr3339348wmb.127.1585658308381; Tue, 31 Mar 2020 05:38:28 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:27 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:37 +0200 Message-Id: <20200331123745.6461-3-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/10] avformat/audiointerleave: Fix memleak 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" If ff_interleave_add_packet failed, the content of the newly created packet new_pkt would leak. Also, it is unnecessary to zero-initialize a packet that will be put into av_new_packet lateron as the latter already initializes the packet. Therefore this has been removed, too. Signed-off-by: Andreas Rheinhardt --- libavformat/audiointerleave.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index 2e83031bd6..f10c83d7c9 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -134,10 +134,12 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - AVPacket new_pkt = { 0 }; + AVPacket new_pkt; while ((ret = interleave_new_audio_packet(s, &new_pkt, i, flush)) > 0) { - if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) + if ((ret = ff_interleave_add_packet(s, &new_pkt, compare_ts)) < 0) { + av_packet_unref(&new_pkt); return ret; + } } if (ret < 0) return ret; From patchwork Tue Mar 31 12:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18536 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 8C0EE44B734 for ; Tue, 31 Mar 2020 15:44:57 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 71DA968B149; Tue, 31 Mar 2020 15:44:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6354668AF8C for ; Tue, 31 Mar 2020 15:44:51 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id z7so345447wmk.1 for ; Tue, 31 Mar 2020 05:44:51 -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=3En9AlFMLFS9kfDm6Xbg1TwhUMSdfyiSVO7rg8J4VDE=; b=urWWReelx+isQzBd/j3YO2Lqf5k4uQUX3nQEJIBRWLaqPSCSPstKq/ver3FFKD9WwJ bt11sFGs/WegrxMqkYRf5oyTVZ0bAVdIwP18hqWci9T+F7K4bCrs56jtdJCh2tadvNsh E14mRlmanNjwRGQ6wKyNghGX1YF7FpD2tHX2q+I1EyLRMXg9s7Z5kgqQnjFEro1eVrBp OgrV8rEHFk8SYk7mNI/4NLjs7q/io4N0NY75MjBigV1hjz89auryM5DEpYXnrWnJmbad rem8Zr3cH6kQHKfG90BbChcLr6nsWbMesnzmFR/7+RoyZB5SCDQRG2HLcht7J+WGSMss XnWA== 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=3En9AlFMLFS9kfDm6Xbg1TwhUMSdfyiSVO7rg8J4VDE=; b=qkLCVpfpdejdDwOVNr5l/CXk8ObPxFV04BzWnoX1Arq4HEblMq/gAvfToueGXU+LP9 UuZ4Sl9zu+9yEf3REbbTTfmWKdvHJGAjk5YmmGAp+shohy/de763ytcX6qOxPc7CTaDH HguyuEhHALMofgYfdroW3cVApGSMoyZPEh5qvUmrIfadTGBsAoswQAoy1mQMwvvWrGr4 p00KzAW1x3ZezDlAIesIPodOW8DAirDbmkiDmWkZgoTlDcHDL2t0tTNIVFV8UW1om1Pc MX0dlpOsQlvIdUOghGVE4gyYmfkVo09fnQ6kBF6Klpp2iOuUy2VmoExSiIMob1yp5l0r BIaA== X-Gm-Message-State: ANhLgQ0q8ovQXON3B9CaWTfb81COlp4rm27d3drU1wExZPUTaFv8qxxv TAvOtxql9riihAIUxm9gNEEvIjPa X-Google-Smtp-Source: ADFU+vuUhHxOA/iHtv9sbXl1pIDOxQzDX+vus6O08tJYxqDzuLyXEOzn5emCew3TNeXDC8tVCzuPhg== X-Received: by 2002:a1c:7301:: with SMTP id d1mr3464255wmb.26.1585658309599; Tue, 31 Mar 2020 05:38:29 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:38 +0200 Message-Id: <20200331123745.6461-4-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 03/10] avformat/avformat.h: Correct some comments 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" 1. When set_parameters was removed from AVOutputFormat in 2fb75019, it was forgotten to remove the comment pertaining to it. Said comment now appeared to apply to interleave_packet(); it is of course nonsense and has been replaced by an accurate description. 2. The description of av_write_uncoded_frame() suggested av_interleaved_write_frame() as a replacement if the input is not already correctly interleaved; it also referred to said function for details. Given that said function can't write AVFrames and that the specifics of writing uncoded frames are explained in the description of av_interleaved_write_uncoded_frame(), both references have been fixed. 3. Removed an outdated comment about avformat_seek_file(). Signed-off-by: Andreas Rheinhardt --- libavformat/avformat.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavformat/avformat.h b/libavformat/avformat.h index e906d7b7e9..39b99b4481 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -551,7 +551,8 @@ typedef struct AVOutputFormat { int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); int (*write_trailer)(struct AVFormatContext *); /** - * Currently only used to set pixel format if not YUV420P. + * A format-specific function for interleavement. + * If unset, packets will be interleaved by dts. */ int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush); @@ -2453,8 +2454,6 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, * @return >=0 on success, error code otherwise * * @note This is part of the new seek API which is still under construction. - * Thus do not use this yet. It may change at any time, do not expect - * ABI compatibility yet! */ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); @@ -2641,9 +2640,9 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt); * Write an uncoded frame to an output media file. * * The frame must be correctly interleaved according to the container - * specification; if not, then av_interleaved_write_frame() must be used. + * specification; if not, av_interleaved_write_uncoded_frame() must be used. * - * See av_interleaved_write_frame() for details. + * See av_interleaved_write_uncoded_frame() for details. */ int av_write_uncoded_frame(AVFormatContext *s, int stream_index, AVFrame *frame); From patchwork Tue Mar 31 12:37:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18539 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 1268E44AF30 for ; Tue, 31 Mar 2020 15:46:51 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED85768B2DB; Tue, 31 Mar 2020 15:46:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7C16268B303 for ; Tue, 31 Mar 2020 15:46:44 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id z14so1990296wmf.0 for ; Tue, 31 Mar 2020 05:46:44 -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=VLwy7pPjPjRov5XfUkv4/g5s3fDHC/TLCEaornXk9ls=; b=XNP5a5FaLdvMZSOZNE/mOy0fVGEMWNU01ZAQr3J2kWa84CaH/smRrL8+UIHHrMH82H 7DZlPXiQxdXHnISsCTVqA3UKcTe6tB5oMY5D/eVG0bRbG8T9+H9ws3z1Ah8znaSfrlWC v4o2ezkuD8QXNEyeZ7n4LCcRTKHwsC3rrlW3m7SazcQdJ59W/RpzOFAjMo/pWe+DSNPt X1o6E5RTng3vuaFU6xaVz2Iqj7bzSETZdZjhfa72scNzG/fKsC6kcXw+r7A76/ijwsmW rZU+G5+nNeyUTAE660uM7Cq6xZnL+P/P6C0Kyes/rx3eHouxLKqOOG0NlEeHgB5UONzn eqFw== 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=VLwy7pPjPjRov5XfUkv4/g5s3fDHC/TLCEaornXk9ls=; b=i5f4hYYRp7CNxuvcI7LYd11vGIbFm3rpaSTOJdYWk1MjlElcWABjennLdebY5n1kdB 7qmn3u2+E/s+BL0b5VLWtBRqHVoJn3d7xTRkJKiaf30ZqjS+dF6s1n980wms+MYJHZle a55K6dzGHYX2lc/g+J6qgLwNmkC6zanLOOp7lCTwfkes86pEuIt+e9pyApsJM9gS6KZv KWI/WmDHxMJHfE6k/AylqZ4FmH1dO72h6dmXGc8YGsga17Ws2ikN3UNDAEkj+69n2qhE hdo6WuIhpSG/Nw4cchVckaSNyTCjsOb0m4e+Wvok0kuog2JotyGYjqHdfsJK2g6wlXtm 1OBw== X-Gm-Message-State: ANhLgQ2JFnNcIwGhncCW4fKA8ey55HWxof3LiHeBBTq+kis1hvzdN0XH +plth7bxBNUsibfaNEUc+2Bje2pL X-Google-Smtp-Source: ADFU+vuK22gbuOxDM1SlP6AQBDbHjY2sVNbfu7MZOD/uLogFOrh4iN4BP/0RlNVPgDEXYui/jxvQlA== X-Received: by 2002:a1c:e442:: with SMTP id b63mr3403157wmh.174.1585658310691; Tue, 31 Mar 2020 05:38:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:39 +0200 Message-Id: <20200331123745.6461-5-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 04/10] avformat/mux: Fix leaks of uncoded frames on errors 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" If writing an uncoded frame fails at the preparatory steps of av_[interleaved_]write_frame(), the frame would be either not freed at all in case of av_write_frame() or would leak when the fake packet would be unreferenced like an ordinary packet. There is also a memleak when the output format is not suited for writing uncoded frames as the documentation states that ownership of the frame passes to av_[interleaved_]write_uncoded_frame(). Both of these memleaks have been fixed. Signed-off-by: Andreas Rheinhardt --- libavformat/mux.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 814d773b9d..a0ebcec119 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1239,7 +1239,11 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) return ret; } fail: - av_packet_unref(pkt); + // This is a deviation from the usual behaviour + // of av_interleaved_write_frame: We leave cleaning + // up uncoded frames to write_uncoded_frame_internal. + if (!(pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) + av_packet_unref(pkt); return ret; } @@ -1324,10 +1328,13 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, AVFrame *frame, int interleaved) { AVPacket pkt, *pktp; + int ret; av_assert0(s->oformat); - if (!s->oformat->write_uncoded_frame) - return AVERROR(ENOSYS); + if (!s->oformat->write_uncoded_frame) { + ret = AVERROR(ENOSYS); + goto free; + } if (!frame) { pktp = NULL; @@ -1343,8 +1350,14 @@ static int write_uncoded_frame_internal(AVFormatContext *s, int stream_index, pkt.flags |= AV_PKT_FLAG_UNCODED_FRAME; } - return interleaved ? av_interleaved_write_frame(s, pktp) : - av_write_frame(s, pktp); + ret = interleaved ? av_interleaved_write_frame(s, pktp) : + av_write_frame(s, pktp); + if (ret < 0 && pktp) { + frame = (AVFrame*)pktp->data; + free: + av_frame_free(&frame); + } + return ret; } int av_write_uncoded_frame(AVFormatContext *s, int stream_index, From patchwork Tue Mar 31 12:37:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18532 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 A1A3544B0FC for ; Tue, 31 Mar 2020 15:38:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8536068B1AF; Tue, 31 Mar 2020 15:38:39 +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 206AF68B070 for ; Tue, 31 Mar 2020 15:38:33 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id w10so25793495wrm.4 for ; Tue, 31 Mar 2020 05:38:33 -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=gyKqgnvbp85utBbEr3KKhcwQ/0hnO3yATuKHjWqfajI=; b=A+qrU/p9owP2o0y2LmGFkdhVwExDTWIcfnsQKjawko50BTG6Dla/pjxuCNl9NeaCD1 O5cdn/uQl3smxjJ0n5aHw9lb1nLGpbxGkXEBW0XeExN0gaHqgXvhL0ByTMcXi1Q3hvuM scnI8UZMmnaSpqVwgCyIyupu+kC214ndzNkPg7TwF9MR3yMCUbsZlAjAPVsUrvbpEUYB fFMz8JoCabG7QRkFl3CGZDI38+v+3TQMTiHCfGTuDwg5s5KvZejjlhKdCRZZBiiz2t8s NUgZGFf4p4/8+EgeKqmkxH1teDpDTbTwHAal+Z0gbIJ3Khv6DbLyNOnxEI6V7MyWCslI DM0g== 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=gyKqgnvbp85utBbEr3KKhcwQ/0hnO3yATuKHjWqfajI=; b=G+NOMGGFm6whj5dxHej+iXEZm78U3E7sJAlM0YFCm43HjT6bdChzm07cFY5l3D64Ph qKi5XWyXtY035Mawn7x5KSCwd1AIaAgHO6+23Ok2OakOqzQ/k+Oh8jYRcnkr+KJeF9w+ /nhXtJLe8ZKTI32K5vqLIYbwKxmAg4O3Yb6BzygEMSg0zWsewCSCOUhlFrvr1+yWvBij dINSBckCCfzWoujqC8OYIppLtLkFduhpOvpbKqPtmnev3Zc/EELBXadjntF1qugc+6J/ /8klpxO1HddPxx9MdP6tZnBbDr8Bd7y3qa4TF+rAJqcgPGpsW5V9WLkZRFW06gheRcpB iL0Q== X-Gm-Message-State: ANhLgQ2rlg0R2IKsm3hplxQX8mmgRHK6XyzHYOPlvS9DFK86RZgvih9K QNMA2SM84YgA6Poged+gEli4NTsB X-Google-Smtp-Source: ADFU+vtlkTLv+PbB9DnALxd8S6VT4hf8AzG1qq/mrH1nGcyFbpnnPjsT3yp3ffAss2NmXyKODVZ/Ew== X-Received: by 2002:adf:9526:: with SMTP id 35mr21531140wrs.164.1585658311983; Tue, 31 Mar 2020 05:38:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:31 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:40 +0200 Message-Id: <20200331123745.6461-6-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 05/10] avformat/mux: Fix memleaks on errors II, improve documentation 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" 1. When an error happened in ff_interleave_add_packet() during interleaving a packet for output, said packet would not be unreferenced in ff_interleave_add_packet(), but would be zeroed in av_interleaved_write_frame(), which results in a memleak. 2. When no error happened in ff_interleave_add_packet() during interleaving a packet for output, the input packet will already be blank (as if av_packet_unref() had been applied to it), but it will nevertheless be zeroed and initialized again. This is unnecessary. Given the possibility of using other functions for interleavement than ff_interleave_packet_per_dts(), this commit sets and documents what interleavement functions need to do: On success, the input packet (if given) should be a blank packet on return. On failure, cleaning up will be done by av_interleave_write_frame() (where the already existing code for error handling can be reused). ff_audio_rechunk_interleave() has been changed to abide by this. In order to keep these requirements consistent, they are kept in one place that is referenced by the other documentations. Updating the documentation incidentally also removed another reference to AVPacket's destructor. Signed-off-by: Andreas Rheinhardt --- libavformat/audiointerleave.c | 1 + libavformat/audiointerleave.h | 4 ++++ libavformat/avformat.h | 1 + libavformat/internal.h | 16 +++++++--------- libavformat/mux.c | 30 +++++++++++------------------- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c index f10c83d7c9..d3b35d804e 100644 --- a/libavformat/audiointerleave.c +++ b/libavformat/audiointerleave.c @@ -121,6 +121,7 @@ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt aic->fifo_size = new_size; } av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL); + av_packet_unref(pkt); } else { // rewrite pts and dts to be decoded time line position pkt->pts = pkt->dts = aic->dts; diff --git a/libavformat/audiointerleave.h b/libavformat/audiointerleave.h index 0933310f4c..d21647b6b1 100644 --- a/libavformat/audiointerleave.h +++ b/libavformat/audiointerleave.h @@ -48,6 +48,10 @@ void ff_audio_interleave_close(AVFormatContext *s); * * @param get_packet function will output a packet when streams are correctly interleaved. * @param compare_ts function will compare AVPackets and decide interleaving order. + * + * Apart from these two functions, this function behaves like ff_interleave_packet_per_dts. + * + * @note This function must not be used with uncoded audio frames. */ int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush, int (*get_packet)(AVFormatContext *, AVPacket *, AVPacket *, int), diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 39b99b4481..8f7466931a 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -553,6 +553,7 @@ typedef struct AVOutputFormat { /** * A format-specific function for interleavement. * If unset, packets will be interleaved by dts. + * See the description of ff_interleave_packet_per_dts for details. */ int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, AVPacket *in, int flush); diff --git a/libavformat/internal.h b/libavformat/internal.h index 332477a532..a861acdc2a 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -230,9 +230,9 @@ char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase); int ff_hex_to_data(uint8_t *data, const char *p); /** - * Add packet to AVFormatContext->packet_buffer list, determining its + * Add packet to an AVFormatContext's packet_buffer list, determining its * interleaved position using compare() function argument. - * @return 0, or < 0 on error + * @return 0, or < 0 on error. On success, pkt will be blank (as if unreferenced). */ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *)); @@ -495,15 +495,13 @@ int ff_framehash_write_header(AVFormatContext *s); int ff_read_packet(AVFormatContext *s, AVPacket *pkt); /** - * Interleave a packet per dts in an output media file. - * - * Packets with pkt->destruct == av_destruct_packet will be freed inside this - * function, so they cannot be used after it. Note that calling av_packet_unref() - * on them is still safe. + * Interleave an AVPacket per dts so it can be muxed. * - * @param s media file handle + * @param s an AVFormatContext for output. in resp. out will be added to + * resp. taken from its packet buffer. * @param out the interleaved packet will be output here - * @param pkt the input packet + * @param in the input packet. If not NULL will be a blank packet + * (as if unreferenced) on success. * @param flush 1 if no further packets are available as input and all * remaining packets should be output * @return 1 if a packet was output, 0 if no packet could be output, diff --git a/libavformat/mux.c b/libavformat/mux.c index a0ebcec119..79731d3008 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1166,20 +1166,13 @@ int ff_interleaved_peek(AVFormatContext *s, int stream, /** * Interleave an AVPacket correctly so it can be muxed. - * @param out the interleaved packet will be output here - * @param in the input packet - * @param flush 1 if no further packets are available as input and all - * remaining packets should be output - * @return 1 if a packet was output, 0 if no packet could be output, - * < 0 if an error occurred + * + * See the description of ff_interleave_packet_per_dts for details. */ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush) { if (s->oformat->interleave_packet) { - int ret = s->oformat->interleave_packet(s, out, in, flush); - if (in) - av_packet_unref(in); - return ret; + return s->oformat->interleave_packet(s, out, in, flush); } else return ff_interleave_packet_per_dts(s, out, in, flush); } @@ -1222,14 +1215,13 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) for (;; ) { AVPacket opkt; - int ret = interleave_packet(s, &opkt, pkt, flush); - if (pkt) { - memset(pkt, 0, sizeof(*pkt)); - av_init_packet(pkt); - pkt = NULL; - } - if (ret <= 0) //FIXME cleanup needed for ret<0 ? - return ret; + ret = interleave_packet(s, &opkt, pkt, flush); + if (ret < 0) + goto fail; + if (!ret) + return 0; + + pkt = NULL; ret = write_packet(s, &opkt); @@ -1242,7 +1234,7 @@ fail: // This is a deviation from the usual behaviour // of av_interleaved_write_frame: We leave cleaning // up uncoded frames to write_uncoded_frame_internal. - if (!(pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) + if (pkt && !(pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) av_packet_unref(pkt); return ret; } From patchwork Tue Mar 31 12:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18533 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 883D544B0FC for ; Tue, 31 Mar 2020 15:38:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7142E68B1A2; Tue, 31 Mar 2020 15:38:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2948568B12E for ; Tue, 31 Mar 2020 15:38:34 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id w10so25793572wrm.4 for ; Tue, 31 Mar 2020 05:38:34 -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=6R8+Kr9hrOWT+vnM3paFM9n5w1lmbEh26KAsRMViRH0=; b=TZeBqaRqT6ZryE+XxFxfphx4zdq06pTa7iF6y2NM/wvtjDoYRqH0lezX6UeAlh9vKJ ClFONr7Ae6uRBNAgbxDFqcyL8si5lIQvykbJkReg4nlRtj6AXqDRtx/vgGOlYKjpapgm SZpRx1JFZurFYcRrc8Bm0TG0uvNjvHVpnEQxn1qqv8JqWgbuzH+Tp7ck9ggOBHtNWSsk bazDuUMOYN+6/GQoin7f2hERVQSAmLWMWupHsWsHzmq3EwZvH7aBAvbXyS35CRqsL8jj b0UwES8b/hX7FKn+vqJzdMC/v/Irhjc5gFOMUccPfZElXHgvw5+Th+1g67SKVjbRS9Hp zZGg== 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=6R8+Kr9hrOWT+vnM3paFM9n5w1lmbEh26KAsRMViRH0=; b=by5hztjA8Crf7SZCwDqbJmm5D4sLSP9nD5NDmL+1KpoisDftsa8FZ8i1abDhOjs62G 9HvZ9Z4leFEpIz4K7d1uUPoOCJDRpKlGEsquD4DUk/pFUhGry6dnzzWKIAC9zFB0VPcA RUGxvfkaYpYbgmrZS1W2D+bfob+cxxFtf8mQwuxgNzF96TUOLHK6VopMxkF3I1mwFZTe mMUCTqeCEXsvPi/FroqTX6oOKM9MMMzS01naRkEM0N0kRcA37sY765CrRWTFc+uK4mNZ 4E2NHtEDW73l0uGv5Dg+/pSLnM0e9iMS2yIS9/U/we1QdHxd1pnbqL6etRyHaC/ZFztS YQZw== X-Gm-Message-State: ANhLgQ2xLImkjatPjuAlG9M8ynzYguEv9a+vK2wOwEvrwKZ6ukTd5KTq gXY9tAMTLunrTDStqdZkOb97UHBL X-Google-Smtp-Source: ADFU+vswniNXXu4+3gTksSVA93YKHvW6nMlidBl/df7GBVfEdaWYDpk/B5/FWT7FFq11ZLLgcUc6vA== X-Received: by 2002:a5d:4bc1:: with SMTP id l1mr21753064wrt.103.1585658313167; Tue, 31 Mar 2020 05:38:33 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:32 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:41 +0200 Message-Id: <20200331123745.6461-7-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 06/10] avformat/mux: Don't modify packets we don't own 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" The documentation of av_write_frame() explicitly states that the function doesn't take ownership of the packets sent to it; while av_write_frame() does not directly unreference the packets after having written them, it nevertheless modifies the packet in various ways: 1. The timestamps might be modified either by prepare_input_packet or compute_muxer_pkt_fields. 2. If a bitstream filter gets applied, it takes ownership of the reference and the side-data in the packet sent to it in av_bsf_send_packet. In case of do_packet_auto_bsf, the end result is that the returned packet contains the output of the last bsf in the chain. If an error happens, an empty packet will be returned; a packet may also simply not lead to any output (vp9_superframe). This also implies that side data needs to be really copied and can't be shared with the input packet. The method choosen here minimizes copying of data: When the input isn't refcounted and no bitstream filter is applied, the packet's data will not be copied. Signed-off-by: Andreas Rheinhardt --- Whether a commit like this is necessary depends upon the meaning of "ownership" (whether not having ownership disallows one from modifying a packet) and of the user's expectations (namely if the av_write_frame() should attempt to not modify the user-provided packet even if it were allowed to). Furthermore, this commit has the downside of adding an AVPacket on the stack. libavformat/mux.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 79731d3008..be7652c97b 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -880,11 +880,12 @@ static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) { return 1; } -int av_write_frame(AVFormatContext *s, AVPacket *pkt) +int av_write_frame(AVFormatContext *s, AVPacket *in) { + AVPacket local_pkt, *pkt = &local_pkt; int ret; - if (!pkt) { + if (!in) { if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { ret = s->oformat->write_packet(s, NULL); flush_if_needed(s); @@ -895,22 +896,43 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt) return 1; } + /* We don't own in, so we have to make sure not to modify it. + * The following avoids copying in's data unnecessarily. + * Copying side data is unavoidable as a bitstream filter + * may change it, e.g. free it on errors. */ + pkt->data = in->data; + pkt->size = in->size; + if (in->buf) { + pkt->buf = av_buffer_ref(in->buf); + if (!pkt->buf) + return AVERROR(ENOMEM); + } else { + pkt->buf = NULL; + } + ret = av_packet_copy_props(pkt, in); + if (ret < 0) + goto fail; + ret = prepare_input_packet(s, pkt); if (ret < 0) - return ret; + goto fail; ret = do_packet_auto_bsf(s, pkt); if (ret <= 0) - return ret; + goto fail; #if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt); if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) - return ret; + goto fail; #endif - return write_packet(s, pkt); + ret = write_packet(s, pkt); + +fail: + av_packet_unref(pkt); + return ret; } #define CHUNK_START 0x1000 From patchwork Tue Mar 31 12:37:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18534 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 43D0144B0FC for ; Tue, 31 Mar 2020 15:38:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3251668B2CA; Tue, 31 Mar 2020 15:38:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F06E68B1DE for ; Tue, 31 Mar 2020 15:38:35 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id h9so25690689wrc.8 for ; Tue, 31 Mar 2020 05:38:35 -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=W4BmtlxF+CP71EAJeSxGUL0QUSmodVGtxBFDBTcoBJ0=; b=hNOc6ueBZVD8Bitrk6srsxWMbyvLL+ebvuKMn+KlCVhmmT3GoX5q+EYi58hPieXOSw TdYkGThwP2DQ0FgPtug5ofMcjEYCMHMrSH1dS1Hx3WNjYLA9CIuQsRw5+FxmJB45NXG4 j3UbhJbwkhOcvLpF7wqvJnG32WnqyM+NMJyZonumOQjLilF95M+sw0IWmXjXbgWa/SLn JBvWyyD2clBLkMBNi16IqYpSNdus64pk6eGT1uW7FBPnHLlHpK7+HTS89h/YqrNWdI+O hni2BNQNuJx+5daTGx/ha26zuzJe6WPFNyG6+LX3uZskw2q/LPHetnJr/uo92g/scEXs 2uZQ== 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=W4BmtlxF+CP71EAJeSxGUL0QUSmodVGtxBFDBTcoBJ0=; b=JJNKGI+8ePd1vTIeSKwvVXF9/1IevfRYnRM/h6FVEPMsIxW/vx2WOikgAlVDx6GirD PraDNL0wCg8KlkU0FJCwiZCQoTSdHTgEH98+1WuWEHlKizQ1qcqsps5vuZsJ3Hlpc074 b2hlMcMgTZzUqaWwRTEXgSLitGUZSHmWO2EO2tR+RMpxd3V+mLgZG0zUBzJg+Md/LsoG ABxhHqS5jqpi73kAM7u3FDuQaNhzZO6vUMlm4r+3Vxt8y3GQNnbJmDjph/jzWIpqk3cG npUYFD9WMfq2hci3HFRevaGRXykIPfMEVnsukqRjCzJQaw5sPA/dU5J2+DJGToMYgZxd 26pg== X-Gm-Message-State: ANhLgQ1cBz0Hnj2ECH0vWZzDJkQY69F5UjlqAIPggxmU2RE+XZzS1OQC Rx7GhiFbgOsdCwAUgHu2E50SMCKT X-Google-Smtp-Source: ADFU+vvt+tzpfUoChF/bvh8TJachTlRajzsrs5PoKbLtpidpr82GvpuyZxQLzxcCM5E0JUJ3loK/og== X-Received: by 2002:adf:f48d:: with SMTP id l13mr20713457wro.96.1585658314411; Tue, 31 Mar 2020 05:38:34 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:33 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:42 +0200 Message-Id: <20200331123745.6461-8-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/10] avformat/mux: Remove pointless timestamp backups 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" write_packet() currently saves the original timestamps of the packet it got and restores them in case writing fails. This is unnecessary as none of write_packet()'s callers make any use of these timestamps at all. So remove this and add a general comment to the function that timestamps may be modified; also remove a long outdated comment about side data. Signed-off-by: Andreas Rheinhardt --- Actually, doing the timestamp backups in write_packet() never made much sense: Timestamps may also be modified before the packet reaches write_packet(). Furthermore, backups for av_interleaved_write_frame() don't make sense at all, so these backups should have been performed in av_write_frame(). libavformat/mux.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index be7652c97b..acb71b30c9 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -670,8 +670,7 @@ FF_ENABLE_DEPRECATION_WARNINGS #endif /** - * Make timestamps non negative, move side data from payload to internal struct, call muxer, and restore - * sidedata. + * Make timestamps non negative and call muxer; the original pts/dts are not kept. * * FIXME: this function should NEVER get undefined pts/dts beside when the * AVFMT_NOTIMESTAMPS is set. @@ -681,10 +680,6 @@ FF_ENABLE_DEPRECATION_WARNINGS static int write_packet(AVFormatContext *s, AVPacket *pkt) { int ret; - int64_t pts_backup, dts_backup; - - pts_backup = pkt->pts; - dts_backup = pkt->dts; // If the timestamp offsetting below is adjusted, adjust // ff_interleaved_peek similarly. @@ -760,10 +755,7 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) ret = s->pb->error; } - if (ret < 0) { - pkt->pts = pts_backup; - pkt->dts = dts_backup; - } else + if (ret >= 0) s->streams[pkt->stream_index]->nb_frames++; return ret; From patchwork Tue Mar 31 12:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18537 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 8E8CE44B82D for ; Tue, 31 Mar 2020 15:45:37 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 669B168B16A; Tue, 31 Mar 2020 15:45:37 +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 84E4668B133 for ; Tue, 31 Mar 2020 15:45:30 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id j19so2447731wmi.2 for ; Tue, 31 Mar 2020 05:45:30 -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=kP6r5X602DKIG6fkyARYJGooJVR0mC5ZIOKyGG23NGM=; b=rYgZgeNd/sBUy9Mqq9+4jrCJ/B2hcfhB8TidQ2Ogtp31qkRg6XmiJCb9wjeK3rSeY2 zQJPvkt9OiI987DXYo8vr2EsOnyxQLAhJ73khzV1vl9KdOfykffd8/3pnqpveLmtLlfW hx/cZjWhHD2LscUB2J5DDwkiM/pU/0oj8565Ur3xzq49wMmRa81E2G6HSXZzoUqzSQrV Wjh9spL0Nt4/kmkGcv58EumMyRMW1CeV1srw7nHfwCm2iwUS5zMyQ87YIRUtRIFqGdC7 dwZNAsYnqUPujIILYjLRQAnFA43HTr0Og9yBn3GCM2iCq6DmNkUoOnkw18vaqtucKoBP aNPg== 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=kP6r5X602DKIG6fkyARYJGooJVR0mC5ZIOKyGG23NGM=; b=Bl/RDoDeOaqBrTkTrbo+RfAqjFm6UXaVyhWxhBpfl3+C8eWOzslMj/cqYU8mW0bn6f QN8fm71NVsLMJZNGDZlUTNohpiGV0pFdCM54OL+bkJUH2N9fazXfuwEreVT3aLccjP0f Rr5NqrY1AKoKExAZmybMteEi8eBL+sTF0pvYXJcrnRJPJP9I8oWkF+UrFXMUMRqk/S8l mwf+yKNeFVH24Hu2TbalrXRfpUl3rxH+rmH1br+SitxtOGbWoKtgD70GAWIpeMuDJEmA Z7F4u639wejzK3JCxOvBwpVEHBEZrH+9uM0mMg4cyr0D/KwSqXi72AVr6Zo4zE2IF+cd 0MFA== X-Gm-Message-State: ANhLgQ2ikhsO36OTC9blNV6qLcWftRhdLOiIJPxzWC+qS0b+jLSfBU+o UAGqNDxz+3Aji4ZBW7WWZ2uwGv6/ X-Google-Smtp-Source: ADFU+vsJWGkCKrGl2aLR7pFEnUhAeYlKU3DiMaVXJS4SdGyTBI7ZgjYcQCl44vZGAI1IwJlPw2SCDQ== X-Received: by 2002:a1c:7719:: with SMTP id t25mr3393985wmi.144.1585658315491; Tue, 31 Mar 2020 05:38:35 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:34 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:43 +0200 Message-Id: <20200331123745.6461-9-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/10] avformat/avformat: Clarify documentation of av_interleaved_write_frame() 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" The earlier documentation claimed that av_interleaved_write_frame() always orders by dts, which is not necessarily true when using muxers with custom interleavement functions or the audio_preload option. Furthermore, the documentation stated that libavformat takes ownership of the reference of the provided packet (if it is refcounted) and that the caller may not access the data through this reference after the function returns. This suggests that the returned packet is not blank, but instead still contains some set, but invalid fields, which implies that it would be dangerous to unreference this packet again. But this is not true: av_interleaved_write_frame()'s actual behaviour is to always output blank packet (even on error). This commit documents this fact so that callers know that they can directly reuse this packet. Signed-off-by: Andreas Rheinhardt --- doc/APIchanges | 4 ++++ libavformat/avformat.h | 15 +++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index f1d7eac2ee..31dc6c6c16 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,10 @@ libavutil: 2017-10-21 API changes, most recent first: +2020-03-31 - xxxxxxxxxx - lavf 58.42.100 - avformat.h + av_interleaved_write_frame() now guarantees to always return + blank packets, even on failure. + 2020-03-29 - xxxxxxxxxx - lavf 58.42.100 - avformat.h av_read_frame() now guarantees to handle uninitialized input packets and to return refcounted packets on success. diff --git a/libavformat/avformat.h b/libavformat/avformat.h index 8f7466931a..9669ded1cd 100644 --- a/libavformat/avformat.h +++ b/libavformat/avformat.h @@ -2596,7 +2596,7 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); * Write a packet to an output media file ensuring correct interleaving. * * This function will buffer the packets internally as needed to make sure the - * packets in the output file are properly interleaved in the order of + * packets in the output file are properly interleaved, usually ordered by * increasing dts. Callers doing their own interleaving should call * av_write_frame() instead of this function. * @@ -2609,10 +2609,10 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); *
* If the packet is reference-counted, this function will take * ownership of this reference and unreference it later when it sees - * fit. - * The caller must not access the data through this reference after - * this function returns. If the packet is not reference-counted, - * libavformat will make a copy. + * fit. If the packet is not reference-counted, libavformat will + * make a copy. + * The returned packet will be blank (as if returned from + * av_packet_alloc()), even on error. *
* This parameter can be NULL (at any time, not just at the end), to * flush the interleaving queues. @@ -2628,10 +2628,9 @@ int av_write_frame(AVFormatContext *s, AVPacket *pkt); * The dts for subsequent packets in one stream must be strictly * increasing (unless the output format is flagged with the * AVFMT_TS_NONSTRICT, then they merely have to be nondecreasing). - * @ref AVPacket.duration "duration") should also be set if known. + * @ref AVPacket.duration "duration" should also be set if known. * - * @return 0 on success, a negative AVERROR on error. Libavformat will always - * take care of freeing the packet, even if this function fails. + * @return 0 on success, a negative AVERROR on error. * * @see av_write_frame(), AVFormatContext.max_interleave_delta */ From patchwork Tue Mar 31 12:37:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18535 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 2019344B0FC for ; Tue, 31 Mar 2020 15:38:45 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 08E9768B2E0; Tue, 31 Mar 2020 15:38:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 89A0668B135 for ; Tue, 31 Mar 2020 15:38:37 +0300 (EEST) Received: by mail-wr1-f51.google.com with SMTP id p10so25725603wrt.6 for ; Tue, 31 Mar 2020 05:38:37 -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=XP1ubETjnzpSxnpZ5qv31Js2t215mvREeKmj1pDBZB0=; b=e5d1Lrr1vNL7u606au8TnNhZxYOpWmxp4vkyaigjetciLMTFI4OXUVYCUbOorzuPZ1 Zu+95r6TOt30vuP/VanDvj5VZqjQKN+Xd+Z7TTkaMkbEDOW5DdEUv3s3IyXlyX+Gn56o c0IB9TA1EEqx90YomOL3HizCZC83k1Nhe6wq41t7lAYgFDtMbzQWn/0ANKVBflEIYIZL OJb/h6YkJQGWRUASeWGz5ytM/IsmDfLr+CdUFuI4IExnLTZcWvOTFAWBUfHbP9h0lhZx NtqyNR8wi0gYHKARUhAW1OWSP3LvuAc/sZDl4b0PNjb0mr/M1PRJ8avlRPNz33thwkb6 AZ1g== 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=XP1ubETjnzpSxnpZ5qv31Js2t215mvREeKmj1pDBZB0=; b=ivJf5yMHblW5FOBAZvrQx5XivbeMEKmfbWr2nPyXjkny/qorrT6x8BgAh9vIucBs1L O3oklxNkqvg+Q7n879+GF5g3dtCnXjyKnWLPz4UNXrGmguKENbuFk02j49IaqYeOWYfH W9jGqljSnee2RZfLaPpD+cuD7wjS/5A1kjzAhQuwZBGg1iT6+pomHbWt+AxI0QHQrrka zUsbXuhoqOmNkcMv+lbUTeKtU7XosXIMvazRu6ZzkwrpS/DeR3FyKl5e0s88vzSnbXPm 9FfdaY7NhsRpVTD5+03XtqriIR5WBlHe4dth4wF56e5ilQu6NNFLiOLd/C1YY98s2A6r I6Lg== X-Gm-Message-State: ANhLgQ0GL9RiV0VHjuNKRRsX/tY07Ux/AOmf5wpUeDZ3EHw8/ip7eqeP PgRGsNYM9HLszjQ3aN+ar8ezgIpe X-Google-Smtp-Source: ADFU+vu4Qp+LiNf5lvJtXQq5x4/zNPRMDxm5Zg+PrOBLn+gCQ1ubnrn8IIVkRU5YLrDB3zzTI8IIzg== X-Received: by 2002:adf:ab5a:: with SMTP id r26mr21173022wrc.313.1585658316567; Tue, 31 Mar 2020 05:38:36 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:35 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:44 +0200 Message-Id: <20200331123745.6461-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/10] fftools/ffmpeg, doc/examples/remuxing: Remove redundant av_packet_unref 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" av_interleaved_write_frame() already returns blank packets. Signed-off-by: Andreas Rheinhardt --- doc/examples/remuxing.c | 1 - fftools/ffmpeg.c | 1 - 2 files changed, 2 deletions(-) diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c index 9e4d1031b4..13469d55ef 100644 --- a/doc/examples/remuxing.c +++ b/doc/examples/remuxing.c @@ -167,7 +167,6 @@ int main(int argc, char **argv) fprintf(stderr, "Error muxing packet\n"); break; } - av_packet_unref(&pkt); } av_write_trailer(ofmt_ctx); diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index aaaf241314..c088d134de 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -827,7 +827,6 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u main_return_code = 1; close_all_output_streams(ost, MUXER_FINISHED | ENCODER_FINISHED, ENCODER_FINISHED); } - av_packet_unref(pkt); } static void close_output_stream(OutputStream *ost) From patchwork Tue Mar 31 12:37:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 18540 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 2243544AF30 for ; Tue, 31 Mar 2020 15:46:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 025A268B3FF; Tue, 31 Mar 2020 15:46:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EC953687F83 for ; Tue, 31 Mar 2020 15:46:51 +0300 (EEST) Received: by mail-wm1-f68.google.com with SMTP id f6so2442261wmj.3 for ; Tue, 31 Mar 2020 05:46:51 -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=73nGi3LFAYMP8av6MCoc8FPukLJVT2nIptqZSydlo7k=; b=HyYknrDbWqu7DrSTXnpC4Nm1TqACFznW9C7nxtu5kcUt72h643c4BAcVXGKNzDnkCl wIGwoKka4JZFe44PBXNUle6ykNAfQYZKk/YrdU8uyUN7XsxXjQYaTpVfLcB0aVxHoLVI jfEwvg/As5uW4SqrcDYBFrdcSj2t0XaULDDhrx/TrkOEk/7HRdOdb9erg5Q073gDq4GY CE8QmTKfvOE1mil4yEx+X4E+HftJpEkxT47dq5bCSPcVCFlEHo0fb8qbiMlb3Em/R7Zl 0m8Uy0+T/8VEuQkrRs0bj7/AoFM2DNdjm4pmSvgNzf+d1w8GWV9CvFHoghDwMpz/ckg3 CXjg== 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=73nGi3LFAYMP8av6MCoc8FPukLJVT2nIptqZSydlo7k=; b=Q19laCg2RKGfpuNWrqL0zYV6uBQ/jlD/0yd3GSRACwffrJANBL21mDZJQMyWGSKBAp NFLWfCCs/zFzUbFd5TLi4Mo+gX/3U5VUG7LIYoaHwjhkiR8ufKAKjb+nsKtkUQFyphuD RljX3WcLxnm12BBnv5q0ufURY/gnERuyOnTqlSIx+hi1wZOUMP/0bObQdiE8gHX//uWz vSEGQwF2VWIKZ/AKLOChQycu+JEK5wEJCy4nlp5Tu4eYad6yPdvC1FGO1dslVMlTaZ0S 02Gew+4ECykEjYGqLdqg7dX7VD+X0NP6oniMLALvkxJtxPGugsojGlpqSj0LMEX5cX3Q 3uIA== X-Gm-Message-State: ANhLgQ3bAhGjNy2aKVl9H+x5x+nYfiDadI/rV7X2CVCdAT9OEWg4y64R KTk6fKk1M9eg/nIG+agzwPp3LGNc X-Google-Smtp-Source: ADFU+vuBchFAQ0jcrEnu1YleNHznrIk5362hVrs31XEcL0UGUuzyczbCuu/zJWGvzjNhHtAXIXlyrw== X-Received: by 2002:a1c:6285:: with SMTP id w127mr3458043wmb.133.1585658317611; Tue, 31 Mar 2020 05:38:37 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id p13sm26301532wru.3.2020.03.31.05.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Mar 2020 05:38:36 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 31 Mar 2020 14:37:45 +0200 Message-Id: <20200331123745.6461-11-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> References: <20200331123745.6461-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/10] libavformat/mux, mxfenc: Don't initialize unnecessarily 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" When no packet could be output, the interleavement functions nevertheless initialized the packet destined for output (with the exception of the data and size fields, making the initialization pointless), although it will not be used at all. So remove the initializations. Signed-off-by: Andreas Rheinhardt --- libavformat/internal.h | 4 ++-- libavformat/mux.c | 1 - libavformat/mxfenc.c | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libavformat/internal.h b/libavformat/internal.h index a861acdc2a..7a01c25ea1 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -504,8 +504,8 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt); * (as if unreferenced) on success. * @param flush 1 if no further packets are available as input and all * remaining packets should be output - * @return 1 if a packet was output, 0 if no packet could be output, - * < 0 if an error occurred + * @return 1 if a packet was output, 0 if no packet could be output + * (in which case out may be uninitialized), < 0 if an error occurred */ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush); diff --git a/libavformat/mux.c b/libavformat/mux.c index acb71b30c9..034cc0b0ab 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -1147,7 +1147,6 @@ int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, return 1; } else { - av_init_packet(out); return 0; } } diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index bfce531f54..23147e9b84 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -3070,7 +3070,6 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket return 1; } else { out: - av_init_packet(out); return 0; } }