| Message ID | 20190813024726.6596-1-andreas.rheinhardt@gmail.com |
|---|---|
| State | Accepted |
| Headers |
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org> 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 1FD2E447E79 for <patchwork@ffaux-bg.ffmpeg.org>; Tue, 13 Aug 2019 05:48:13 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E000A68A7C9; Tue, 13 Aug 2019 05:48:12 +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 B0E9A68A42C for <ffmpeg-devel@ffmpeg.org>; Tue, 13 Aug 2019 05:48:06 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id n9so106441079wru.0 for <ffmpeg-devel@ffmpeg.org>; Mon, 12 Aug 2019 19:48:06 -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:mime-version :content-transfer-encoding; bh=si9OPi6S6jzXUT0njFQMdSpdJFe+cfH67iHP9B1oxHc=; b=Flqh/iZWBgm/GGvpxPydure4W0WF2CGfua6FSfI8cpDBOjhw6Dls0jjqIuqNgMrMfJ Bj7wEZzPYJnXSffe8a+iDuqETwIzTbZn2wTkRCQmr7CLFEJa/i1kRDPSPyDe3VW58IHn B4Llm7CiaJMYdDuowG2oRwUUEXZ7Chm2G/xG54Uvmi2rtM55DM7rEkILX7rpZTcaa8ws xwa8UUva0aoChJSX21qanGxYHkej7m3uobp7BtmEGvHVUoHOvgWiGXvirDOlpwCrFKw5 cvlO/+7w6NW8reldZK5L6uiz78K7otoKOnZLJxWfmPwLkKShsX11Cion20VGCJAL/+2P gWMw== 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:mime-version :content-transfer-encoding; bh=si9OPi6S6jzXUT0njFQMdSpdJFe+cfH67iHP9B1oxHc=; b=n74T/FA0BN46wOFtCrFdnCnbPEHD6gO6lwRX6wEOsNY0Bmj9d0hDwDI9O6cXj+NE8I ietSZo5HgSirL2d6JO9r4wNTHjMUX4ucFYn1foS/wGbaLIiJBCjlUELucPgSdZZbYrNG /WKaDau3ekZ51Gr5THNzbKiz+yr0yw4DSYId79hQYM7Vnohiq9hgjh7QJ960ODidads6 Ovk9EqZhqBAeeMs6DgBqQsc+Cu+GKGEVw5WdFe7nGqUtGSQoSTMtxQxY6yKsal1uysvY z2lf8G4aPb5Ngzh89RYZOrTVR+P81J1+urQGfcKpD2cP1B8fRi2+gM6tebBhLP3v/GvT FndA== X-Gm-Message-State: APjAAAWLpn1T0MRSzQc51JChU4eYL3HYgVL8+GA9dbR/6XEZ9VC+cA5z 5MPjgsNW1YAC6mO4w33QndCjvYib X-Google-Smtp-Source: APXvYqzQGBSd7f4/7HSJtfU6CdSXbfN13ruEwJHGnzd0qrga1jK4G04CC9zLUfeTt5Eq0HRIEt+b7w== X-Received: by 2002:adf:f204:: with SMTP id p4mr45274937wro.317.1565664486041; Mon, 12 Aug 2019 19:48:06 -0700 (PDT) Received: from localhost.localdomain (ipbcc06ceb.dynamic.kabel-deutschland.de. [188.192.108.235]) by smtp.gmail.com with ESMTPSA id k13sm25020613wro.97.2019.08.12.19.48.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 19:48:05 -0700 (PDT) From: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Aug 2019 04:47:14 +0200 Message-Id: <20190813024726.6596-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/13] avformat/mux: Move packet references X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org> List-Unsubscribe: <http://ffmpeg.org/mailman/options/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe> List-Archive: <http://ffmpeg.org/pipermail/ffmpeg-devel/> List-Post: <mailto:ffmpeg-devel@ffmpeg.org> List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help> List-Subscribe: <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>, <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe> Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Cc: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org> |
Commit Message
Andreas Rheinhardt
Aug. 13, 2019, 2:47 a.m. UTC
In the common case that the input packet was already refcounted,
ff_interleave_add_packet would allocate a new AVPacketList, use
av_packet_ref to create a new reference to the buffer for the
AVPacketList's packet, interleave the packet and finally unreference
the original input packet.
This commit changes this: It uses av_packet_move_ref to transfer
the packet to its destination. In case the input packet is refcounted,
this saves an allocation and a free (of an AVBufferRef); if not, the
packet is made refcounted before moving it. When the input packet has
side data, one saves even more than one allocation+free.
Furthermore, when the packet is in reality an uncoded frame, a hacky
ad-hoc variant of av_packet_move_ref has been employed. Not any more.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
libavformat/mux.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
Comments
Andreas Rheinhardt: > In the common case that the input packet was already refcounted, > ff_interleave_add_packet would allocate a new AVPacketList, use > av_packet_ref to create a new reference to the buffer for the > AVPacketList's packet, interleave the packet and finally unreference > the original input packet. > This commit changes this: It uses av_packet_move_ref to transfer > the packet to its destination. In case the input packet is refcounted, > this saves an allocation and a free (of an AVBufferRef); if not, the > packet is made refcounted before moving it. When the input packet has > side data, one saves even more than one allocation+free. > > Furthermore, when the packet is in reality an uncoded frame, a hacky > ad-hoc variant of av_packet_move_ref has been employed. Not any more. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavformat/mux.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) > > diff --git a/libavformat/mux.c b/libavformat/mux.c > index 8ab5ea8c2b..ac370fb24d 100644 > --- a/libavformat/mux.c > +++ b/libavformat/mux.c > @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, > if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { > av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); > av_assert0(((AVFrame *)pkt->data)->buf); > - this_pktl->pkt = *pkt; > - pkt->buf = NULL; > - pkt->side_data = NULL; > - pkt->side_data_elems = 0; > } else { > - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { > + if ((ret = av_packet_make_refcounted(pkt)) < 0) { > av_free(this_pktl); > return ret; > } > } > > + av_packet_move_ref(&this_pktl->pkt, pkt); > + pkt = &this_pktl->pkt; > + > if (s->streams[pkt->stream_index]->last_in_packet_buffer) { > next_point = &(st->last_in_packet_buffer->next); > } else { > @@ -989,8 +988,6 @@ next_non_null: > s->streams[pkt->stream_index]->last_in_packet_buffer = > *next_point = this_pktl; > > - av_packet_unref(pkt); > - > return 0; > } > > Ping for this patch and the remaining unmerged patches in this patchset (patches 1, 2, 4, 5, 7-13). - Andreas
Andreas Rheinhardt: > Andreas Rheinhardt: >> In the common case that the input packet was already refcounted, >> ff_interleave_add_packet would allocate a new AVPacketList, use >> av_packet_ref to create a new reference to the buffer for the >> AVPacketList's packet, interleave the packet and finally unreference >> the original input packet. >> This commit changes this: It uses av_packet_move_ref to transfer >> the packet to its destination. In case the input packet is refcounted, >> this saves an allocation and a free (of an AVBufferRef); if not, the >> packet is made refcounted before moving it. When the input packet has >> side data, one saves even more than one allocation+free. >> >> Furthermore, when the packet is in reality an uncoded frame, a hacky >> ad-hoc variant of av_packet_move_ref has been employed. Not any more. >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> >> --- >> libavformat/mux.c | 11 ++++------- >> 1 file changed, 4 insertions(+), 7 deletions(-) >> >> diff --git a/libavformat/mux.c b/libavformat/mux.c >> index 8ab5ea8c2b..ac370fb24d 100644 >> --- a/libavformat/mux.c >> +++ b/libavformat/mux.c >> @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, >> if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { >> av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); >> av_assert0(((AVFrame *)pkt->data)->buf); >> - this_pktl->pkt = *pkt; >> - pkt->buf = NULL; >> - pkt->side_data = NULL; >> - pkt->side_data_elems = 0; >> } else { >> - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { >> + if ((ret = av_packet_make_refcounted(pkt)) < 0) { >> av_free(this_pktl); >> return ret; >> } >> } >> >> + av_packet_move_ref(&this_pktl->pkt, pkt); >> + pkt = &this_pktl->pkt; >> + >> if (s->streams[pkt->stream_index]->last_in_packet_buffer) { >> next_point = &(st->last_in_packet_buffer->next); >> } else { >> @@ -989,8 +988,6 @@ next_non_null: >> s->streams[pkt->stream_index]->last_in_packet_buffer = >> *next_point = this_pktl; >> >> - av_packet_unref(pkt); >> - >> return 0; >> } >> >> > Ping for this patch and the remaining unmerged patches in this > patchset (patches 1, 2, 4, 5, 7-13). > > - Andreas > Another ping. - Andreas
Andreas Rheinhardt: > Andreas Rheinhardt: >> In the common case that the input packet was already refcounted, >> ff_interleave_add_packet would allocate a new AVPacketList, use >> av_packet_ref to create a new reference to the buffer for the >> AVPacketList's packet, interleave the packet and finally unreference >> the original input packet. >> This commit changes this: It uses av_packet_move_ref to transfer >> the packet to its destination. In case the input packet is refcounted, >> this saves an allocation and a free (of an AVBufferRef); if not, the >> packet is made refcounted before moving it. When the input packet has >> side data, one saves even more than one allocation+free. >> >> Furthermore, when the packet is in reality an uncoded frame, a hacky >> ad-hoc variant of av_packet_move_ref has been employed. Not any more. >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> >> --- >> libavformat/mux.c | 11 ++++------- >> 1 file changed, 4 insertions(+), 7 deletions(-) >> >> diff --git a/libavformat/mux.c b/libavformat/mux.c >> index 8ab5ea8c2b..ac370fb24d 100644 >> --- a/libavformat/mux.c >> +++ b/libavformat/mux.c >> @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, >> if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { >> av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); >> av_assert0(((AVFrame *)pkt->data)->buf); >> - this_pktl->pkt = *pkt; >> - pkt->buf = NULL; >> - pkt->side_data = NULL; >> - pkt->side_data_elems = 0; >> } else { >> - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { >> + if ((ret = av_packet_make_refcounted(pkt)) < 0) { >> av_free(this_pktl); >> return ret; >> } >> } >> >> + av_packet_move_ref(&this_pktl->pkt, pkt); >> + pkt = &this_pktl->pkt; >> + >> if (s->streams[pkt->stream_index]->last_in_packet_buffer) { >> next_point = &(st->last_in_packet_buffer->next); >> } else { >> @@ -989,8 +988,6 @@ next_non_null: >> s->streams[pkt->stream_index]->last_in_packet_buffer = >> *next_point = this_pktl; >> >> - av_packet_unref(pkt); >> - >> return 0; >> } >> >> > Ping for this patch and the remaining unmerged patches in this > patchset (patches 1, 2, 4, 5, 7-13). > > - Andreas > Another ping. - Andreas
On Tue, Oct 8, 2019 at 12:42 PM Andreas Rheinhardt < andreas.rheinhardt@gmail.com> wrote: > Andreas Rheinhardt: > > Andreas Rheinhardt: > >> In the common case that the input packet was already refcounted, > >> ff_interleave_add_packet would allocate a new AVPacketList, use > >> av_packet_ref to create a new reference to the buffer for the > >> AVPacketList's packet, interleave the packet and finally unreference > >> the original input packet. > >> This commit changes this: It uses av_packet_move_ref to transfer > >> the packet to its destination. In case the input packet is refcounted, > >> this saves an allocation and a free (of an AVBufferRef); if not, the > >> packet is made refcounted before moving it. When the input packet has > >> side data, one saves even more than one allocation+free. > >> > >> Furthermore, when the packet is in reality an uncoded frame, a hacky > >> ad-hoc variant of av_packet_move_ref has been employed. Not any more. > >> > >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > >> --- > >> libavformat/mux.c | 11 ++++------- > >> 1 file changed, 4 insertions(+), 7 deletions(-) > >> > >> diff --git a/libavformat/mux.c b/libavformat/mux.c > >> index 8ab5ea8c2b..ac370fb24d 100644 > >> --- a/libavformat/mux.c > >> +++ b/libavformat/mux.c > >> @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, > AVPacket *pkt, > >> if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { > >> av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); > >> av_assert0(((AVFrame *)pkt->data)->buf); > >> - this_pktl->pkt = *pkt; > >> - pkt->buf = NULL; > >> - pkt->side_data = NULL; > >> - pkt->side_data_elems = 0; > >> } else { > >> - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { > >> + if ((ret = av_packet_make_refcounted(pkt)) < 0) { > >> av_free(this_pktl); > >> return ret; > >> } > >> } > >> > >> + av_packet_move_ref(&this_pktl->pkt, pkt); > >> + pkt = &this_pktl->pkt; > >> + > >> if (s->streams[pkt->stream_index]->last_in_packet_buffer) { > >> next_point = &(st->last_in_packet_buffer->next); > >> } else { > >> @@ -989,8 +988,6 @@ next_non_null: > >> s->streams[pkt->stream_index]->last_in_packet_buffer = > >> *next_point = this_pktl; > >> > >> - av_packet_unref(pkt); > >> - > >> return 0; > >> } > >> > >> > > Ping for this patch and the remaining unmerged patches in this > > patchset (patches 1, 2, 4, 5, 7-13). > > > > - Andreas > > > Another ping. > > - Andreas > Another ping. - Andreas
On Wed, Jan 15, 2020 at 10:41 PM Andreas Rheinhardt < andreas.rheinhardt@gmail.com> wrote: > On Tue, Oct 8, 2019 at 12:42 PM Andreas Rheinhardt < > andreas.rheinhardt@gmail.com> wrote: > >> Andreas Rheinhardt: >> > Andreas Rheinhardt: >> >> In the common case that the input packet was already refcounted, >> >> ff_interleave_add_packet would allocate a new AVPacketList, use >> >> av_packet_ref to create a new reference to the buffer for the >> >> AVPacketList's packet, interleave the packet and finally unreference >> >> the original input packet. >> >> This commit changes this: It uses av_packet_move_ref to transfer >> >> the packet to its destination. In case the input packet is refcounted, >> >> this saves an allocation and a free (of an AVBufferRef); if not, the >> >> packet is made refcounted before moving it. When the input packet has >> >> side data, one saves even more than one allocation+free. >> >> >> >> Furthermore, when the packet is in reality an uncoded frame, a hacky >> >> ad-hoc variant of av_packet_move_ref has been employed. Not any more. >> >> >> >> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> >> >> --- >> >> libavformat/mux.c | 11 ++++------- >> >> 1 file changed, 4 insertions(+), 7 deletions(-) >> >> >> >> diff --git a/libavformat/mux.c b/libavformat/mux.c >> >> index 8ab5ea8c2b..ac370fb24d 100644 >> >> --- a/libavformat/mux.c >> >> +++ b/libavformat/mux.c >> >> @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, >> AVPacket *pkt, >> >> if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { >> >> av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); >> >> av_assert0(((AVFrame *)pkt->data)->buf); >> >> - this_pktl->pkt = *pkt; >> >> - pkt->buf = NULL; >> >> - pkt->side_data = NULL; >> >> - pkt->side_data_elems = 0; >> >> } else { >> >> - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { >> >> + if ((ret = av_packet_make_refcounted(pkt)) < 0) { >> >> av_free(this_pktl); >> >> return ret; >> >> } >> >> } >> >> >> >> + av_packet_move_ref(&this_pktl->pkt, pkt); >> >> + pkt = &this_pktl->pkt; >> >> + >> >> if (s->streams[pkt->stream_index]->last_in_packet_buffer) { >> >> next_point = &(st->last_in_packet_buffer->next); >> >> } else { >> >> @@ -989,8 +988,6 @@ next_non_null: >> >> s->streams[pkt->stream_index]->last_in_packet_buffer = >> >> *next_point = this_pktl; >> >> >> >> - av_packet_unref(pkt); >> >> - >> >> return 0; >> >> } >> >> >> >> >> > Ping for this patch and the remaining unmerged patches in this >> > patchset (patches 1, 2, 4, 5, 7-13). >> > >> > - Andreas >> > >> Another ping. >> >> - Andreas >> > > Another ping. > > - Andreas > > Ping. - Andreas
On Tue, Aug 13, 2019 at 04:47:14AM +0200, Andreas Rheinhardt wrote: > In the common case that the input packet was already refcounted, > ff_interleave_add_packet would allocate a new AVPacketList, use > av_packet_ref to create a new reference to the buffer for the > AVPacketList's packet, interleave the packet and finally unreference > the original input packet. > This commit changes this: It uses av_packet_move_ref to transfer > the packet to its destination. In case the input packet is refcounted, > this saves an allocation and a free (of an AVBufferRef); if not, the > packet is made refcounted before moving it. When the input packet has > side data, one saves even more than one allocation+free. > > Furthermore, when the packet is in reality an uncoded frame, a hacky > ad-hoc variant of av_packet_move_ref has been employed. Not any more. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavformat/mux.c | 11 ++++------- > 1 file changed, 4 insertions(+), 7 deletions(-) will apply [...]
diff --git a/libavformat/mux.c b/libavformat/mux.c index 8ab5ea8c2b..ac370fb24d 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -930,17 +930,16 @@ int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, if ((pkt->flags & AV_PKT_FLAG_UNCODED_FRAME)) { av_assert0(pkt->size == UNCODED_FRAME_PACKET_SIZE); av_assert0(((AVFrame *)pkt->data)->buf); - this_pktl->pkt = *pkt; - pkt->buf = NULL; - pkt->side_data = NULL; - pkt->side_data_elems = 0; } else { - if ((ret = av_packet_ref(&this_pktl->pkt, pkt)) < 0) { + if ((ret = av_packet_make_refcounted(pkt)) < 0) { av_free(this_pktl); return ret; } } + av_packet_move_ref(&this_pktl->pkt, pkt); + pkt = &this_pktl->pkt; + if (s->streams[pkt->stream_index]->last_in_packet_buffer) { next_point = &(st->last_in_packet_buffer->next); } else { @@ -989,8 +988,6 @@ next_non_null: s->streams[pkt->stream_index]->last_in_packet_buffer = *next_point = this_pktl; - av_packet_unref(pkt); - return 0; }