From patchwork Wed Aug 7 19:50:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 14308 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 E5C02449C65 for ; Wed, 7 Aug 2019 22:50:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2DEA6800FF; Wed, 7 Aug 2019 22:50:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 190116800AD for ; Wed, 7 Aug 2019 22:50:52 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id ED647E3520; Wed, 7 Aug 2019 21:50:51 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PybKAS9jGgjJ; Wed, 7 Aug 2019 21:50:50 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 349EBE350B; Wed, 7 Aug 2019 21:50:50 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 7 Aug 2019 21:50:45 +0200 Message-Id: <20190807195045.25734-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: References: Subject: [FFmpeg-devel] [PATCHv2 1/3] avformat/avio: add avio_print_n_strings and avio_print 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" These functions can be used to print a variable number of strings consecutively to the IO context. Unlike av_bprintf, no temporary buffer is necessary. Signed-off-by: Marton Balint --- doc/APIchanges | 3 +++ libavformat/avio.h | 17 +++++++++++++++++ libavformat/aviobuf.c | 12 ++++++++++++ libavformat/version.h | 2 +- 4 files changed, 33 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 6603a8229e..0b19fb067d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -15,6 +15,9 @@ libavutil: 2017-10-21 API changes, most recent first: +2019-08-xx - xxxxxxxxxx - lavf 58.31.100 - avio.h + Add avio_print_n_strings and avio_print. + 2019-07-27 - xxxxxxxxxx - lavu 56.33.100 - tx.h Add AV_TX_DOUBLE_FFT and AV_TX_DOUBLE_MDCT diff --git a/libavformat/avio.h b/libavformat/avio.h index dcb8dcdf93..0c622f44bd 100644 --- a/libavformat/avio.h +++ b/libavformat/avio.h @@ -574,6 +574,23 @@ int avio_feof(AVIOContext *s); /** @warning Writes up to 4 KiB per call */ int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3); +/** + * Write nb_strings number of strings (const char *) to the context. + * This function is not to be used directly, use avio_print instead. + */ +void avio_print_n_strings(AVIOContext *s, int nb_strings, ...); + +/** + * Write strings (const char *) to the context. + * This is a macro around avio_print_n_strings but the number of strings to be + * written is determined automatically at compile time based on the number of + * parameters passed to this macro. For simple string concatenations this + * function is more performant than using avio_printf since it does not need a + * temporary buffer. + */ +#define avio_print(s, ...) \ + avio_print_n_strings(s, sizeof((const char*[]){__VA_ARGS__}) / sizeof(const char*), __VA_ARGS__) + /** * Force flushing of buffered data. * diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 2d011027c9..4a37a13d7a 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -1225,6 +1225,18 @@ int avio_printf(AVIOContext *s, const char *fmt, ...) return ret; } +void avio_print_n_strings(AVIOContext *s, int nb_strings, ...) +{ + va_list ap; + + va_start(ap, nb_strings); + for (int i = 0; i < nb_strings; i++) { + const char *str = va_arg(ap, const char *); + avio_write(s, (const unsigned char *)str, strlen(str)); + } + va_end(ap); +} + int avio_pause(AVIOContext *s, int pause) { if (!s->read_pause) diff --git a/libavformat/version.h b/libavformat/version.h index 45efaff9b9..feceaedc08 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,7 +32,7 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 58 -#define LIBAVFORMAT_VERSION_MINOR 30 +#define LIBAVFORMAT_VERSION_MINOR 31 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \