Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 7/7] avformat/matroskaenc: Reuse dynamic buffer
Date: Tue, 21 Jun 2022 05:22:07 +0200
Message-ID: <DB6PR0101MB2214C7BCFB6101F8B0696B5D8FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <DB6PR0101MB2214886E62B7920390D6D89F8FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>

Avoids some allocations.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/matroskaenc.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index acb50017b6..bfc397dbe6 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -222,7 +222,8 @@ typedef struct MatroskaMuxContext {
      * to write the length field of EBML Masters.
      * Every user has to reset the buffer after using it and
      * different uses may not overlap. It is currently used in
-     * mkv_write_tag(). */
+     * mkv_write_tag(), in mkv_assemble_cues() as well as in
+     * mkv_update_codecprivate() and mkv_write_track(). */
     AVIOContext        *tmp_bc;
 
     AVPacket           *cur_audio_pkt;
@@ -941,17 +942,10 @@ static int mkv_add_cuepoint(MatroskaMuxContext *mkv, int stream, int64_t ts,
     return 0;
 }
 
-static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
+static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp, AVIOContext *cuepoint,
                              const mkv_cues *cues, mkv_track *tracks, int num_tracks,
                              uint64_t offset)
 {
-    AVIOContext *cuepoint;
-    int ret;
-
-    ret = avio_open_dyn_buf(&cuepoint);
-    if (ret < 0)
-        return ret;
-
     for (mkv_cuepoint *entry = cues->entries, *end = entry + cues->num_entries;
          entry < end;) {
         uint64_t pts = entry->pts;
@@ -981,14 +975,13 @@ static int mkv_assemble_cues(AVStream **streams, AVIOContext *dyn_cp,
             end_ebml_master(cuepoint, track_positions);
         } while (++entry < end && entry->pts == pts);
         size = avio_get_dyn_buf(cuepoint, &buf);
-        if ((ret = cuepoint->error) < 0)
-            break;
+        if (cuepoint->error < 0)
+            return cuepoint->error;
         put_ebml_binary(dyn_cp, MATROSKA_ID_POINTENTRY, buf, size);
         ffio_reset_dyn_buf(cuepoint);
     }
-    ffio_free_dyn_buf(&cuepoint);
 
-    return ret;
+    return 0;
 }
 
 static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb,
@@ -2964,7 +2957,7 @@ redo_cues:
         if (ret < 0)
             return ret;
 
-        ret = mkv_assemble_cues(s->streams, cues, &mkv->cues,
+        ret = mkv_assemble_cues(s->streams, cues, mkv->tmp_bc, &mkv->cues,
                                 mkv->tracks, s->nb_streams, offset);
         if (ret < 0) {
             ffio_free_dyn_buf(&cues);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-06-21  3:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  2:30 [FFmpeg-devel] [PATCH 1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it Andreas Rheinhardt
2022-06-21  2:34 ` [FFmpeg-devel] [PATCH 2/6] avformat/matroskaenc: Avoid swapping codecpar->extradata temporarily Andreas Rheinhardt
2022-06-21  2:34 ` [FFmpeg-devel] [PATCH 3/6] avformat/matroskaenc: Split updating CodecPrivate from writing it Andreas Rheinhardt
2022-06-21 15:22   ` Michael Niedermayer
2022-06-21 21:45     ` Andreas Rheinhardt
2022-06-21  2:34 ` [FFmpeg-devel] [PATCH 4/6] avcodec/av1: Add upper bound for the size of a sane sequence header Andreas Rheinhardt
2022-06-21  2:34 ` [FFmpeg-devel] [PATCH 5/6] avformat/matroskaenc: Improve handling of AV1 extradata Andreas Rheinhardt
2022-06-21  2:34 ` [FFmpeg-devel] [PATCH 6/6] avformat/matroskaenc: Fix outdated comment Andreas Rheinhardt
2022-06-21  3:22 ` Andreas Rheinhardt [this message]
2022-06-24  9:50 ` [FFmpeg-devel] [PATCH 1/6] avformat/matroskaenc: Split assembling CodecPrivate from writing it Andreas Rheinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB6PR0101MB2214C7BCFB6101F8B0696B5D8FB39@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git