From: rcombs via ffmpeg-devel <ffmpeg-devel@ffmpeg.org> To: ffmpeg-devel@ffmpeg.org Cc: rcombs <rcombs@rcombs.me> Subject: [FFmpeg-devel] [PATCH 1/2] lavf/avio_internal: add ffio_write_lines for line ending normalization Date: Sun, 28 Jan 2024 14:38:27 -0800 Message-ID: <20240128223830.57736-1-rcombs@rcombs.me> (raw) --- libavformat/avio_internal.h | 11 +++++++++++ libavformat/aviobuf.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/libavformat/avio_internal.h b/libavformat/avio_internal.h index f2e4ff30cb..16cf6ce016 100644 --- a/libavformat/avio_internal.h +++ b/libavformat/avio_internal.h @@ -156,6 +156,17 @@ unsigned int ffio_read_leb(AVIOContext *s); void ffio_write_leb(AVIOContext *s, unsigned val); +/** + * Write a sequence of text lines, converting line endings. + * All input line endings (LF, CRLF, CR) are converted to the configured line ending. + * @param s The AVIOContext to write to + * @param buf The buffer to write + * @param size The size of the buffer, or <0 to use the full length of a null-terminated string + * @param ending The line ending sequence to convert to, or NULL for \n + */ +void ffio_write_lines(AVIOContext *s, const unsigned char *buf, int size, + const unsigned char *ending); + /** * Read size bytes from AVIOContext into buf. * Check that exactly size bytes have been read. diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 5a329ce465..76780bc852 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1004,6 +1004,37 @@ void ffio_write_leb(AVIOContext *s, unsigned val) } } +void ffio_write_lines(AVIOContext *s, const unsigned char *buf, int size, + const unsigned char *ending) +{ + int ending_len = ending ? strlen(ending) : 1; + if (!ending) + ending = "\n"; + if (size < 0) + size = strlen(buf); + + while (size > 0) { + size_t len = 0; + char last = 0; + for (; len < size; len++) { + last = buf[len]; + if (last == '\r' || last == '\n') + break; + } + + avio_write(s, buf, len); + avio_write(s, ending, ending_len); + + buf += len + 1; + size -= len + 1; + + if (size > 0 && last == '\r' && buf[0] == '\n') { + buf++; + size--; + } + } +} + int ffio_fdopen(AVIOContext **s, URLContext *h) { uint8_t *buffer = NULL; -- 2.42.0 _______________________________________________ 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".
next reply other threads:[~2024-01-28 22:39 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-01-28 22:38 rcombs via ffmpeg-devel [this message] 2024-01-28 22:38 ` [FFmpeg-devel] [PATCH 2/2] lavf/assenc: normalize line endings to \n rcombs via ffmpeg-devel
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=20240128223830.57736-1-rcombs@rcombs.me \ --to=ffmpeg-devel@ffmpeg.org \ --cc=rcombs@rcombs.me \ /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