[FFmpeg-devel] [PATCH 1/2] lavf/avio: add avio_vprintf()

Stefano Sabatini stefasab at gmail.com
Mon Apr 19 00:30:57 EEST 2021


This new function makes it possible to use avio_printf() functionality from
a function taking a variable list of arguments.
---
 doc/APIchanges        |  3 +++
 libavformat/avio.h    |  6 ++++++
 libavformat/aviobuf.c | 17 +++++++++++++----
 libavformat/version.h |  2 +-
 4 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index b41dadee8d..08fec7c234 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2021-04-18 - xxxxxxxxxx - lavf 58.78.100 - avio.h
+  Add avio_vprintf(), similar to avio_printf().
+
 2021-03-21 - xxxxxxxxxx - lavu 56.72.100 - frame.h
   Deprecated av_get_colorspace_name().
   Use av_color_space_name() instead.
diff --git a/libavformat/avio.h b/libavformat/avio.h
index d022820a6e..24f6839522 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -571,6 +571,12 @@ int64_t avio_size(AVIOContext *s);
  */
 int avio_feof(AVIOContext *s);
 
+/**
+ * Writes a formatted string to the context taking a va_list.
+ * @return number of bytes written, < 0 on error.
+ */
+int avio_vprintf(AVIOContext *s, const char *fmt, va_list ap);
+
 /**
  * Writes a formatted string to the context.
  * @return number of bytes written, < 0 on error.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 518cb11129..289da796c8 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1196,15 +1196,12 @@ int avio_closep(AVIOContext **s)
     return ret;
 }
 
-int avio_printf(AVIOContext *s, const char *fmt, ...)
+int avio_vprintf(AVIOContext *s, const char *fmt, va_list ap)
 {
-    va_list ap;
     AVBPrint bp;
 
     av_bprint_init(&bp, 0, INT_MAX);
-    va_start(ap, fmt);
     av_vbprintf(&bp, fmt, ap);
-    va_end(ap);
     if (!av_bprint_is_complete(&bp)) {
         av_bprint_finalize(&bp, NULL);
         s->error = AVERROR(ENOMEM);
@@ -1215,6 +1212,18 @@ int avio_printf(AVIOContext *s, const char *fmt, ...)
     return bp.len;
 }
 
+int avio_printf(AVIOContext *s, const char *fmt, ...)
+{
+    va_list ap;
+    int ret;
+
+    va_start(ap, fmt);
+    ret = avio_vprintf(s, fmt, ap);
+    va_end(ap);
+
+    return ret;
+}
+
 void avio_print_string_array(AVIOContext *s, const char *strings[])
 {
     for(; *strings; strings++)
diff --git a/libavformat/version.h b/libavformat/version.h
index ced5600034..b6023f9d2e 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  77
+#define LIBAVFORMAT_VERSION_MINOR  78
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
-- 
2.25.1



More information about the ffmpeg-devel mailing list