[FFmpeg-devel] [PATCH 05/10] avformat/nutenc: Create put_* functions by macro

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon May 4 21:22:45 EEST 2020


It allows to add analogous functions using e.g. the bytestream API
instead of using an AVIOContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/nutenc.c | 49 ++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 22 deletions(-)

diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index ca433038d4..a75d9282fe 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -290,25 +290,35 @@ static int get_v_length(uint64_t val)
     return i;
 }
 
-/**
- * Put val using a variable number of bytes.
- */
-static void put_v(AVIOContext *bc, uint64_t val)
-{
-    int i = get_v_length(val);
-
-    while (--i > 0)
-        avio_w8(bc, 128 | (uint8_t)(val >> (7*i)));
-
-    avio_w8(bc, val & 127);
+#define PUT_FUNCTIONS(type, write, suffix)                         \
+/**                                                                \
+ * Put val using a variable number of bytes.                       \
+ */                                                                \
+static void put_v##suffix(type dst, uint64_t val)                  \
+{                                                                  \
+    int i = get_v_length(val);                                     \
+                                                                   \
+    while (--i > 0)                                                \
+        write(dst, 128 | (uint8_t)(val >> (7*i)));                 \
+                                                                   \
+    write(dst, val & 127);                                         \
+}                                                                  \
+                                                                   \
+static void put_tt##suffix(NUTContext *nut, AVRational *time_base, \
+                           type dst, uint64_t val)                 \
+{                                                                  \
+    val *= nut->time_base_count;                                   \
+    val += time_base - nut->time_base;                             \
+    put_v##suffix(dst, val);                                       \
+}                                                                  \
+                                                                   \
+static void put_s##suffix(type dst, int64_t val)                   \
+{                                                                  \
+    put_v##suffix(dst, 2 * FFABS(val) - (val > 0));                \
 }
 
-static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val)
-{
-    val *= nut->time_base_count;
-    val += time_base - nut->time_base;
-    put_v(bc, val);
-}
+PUT_FUNCTIONS(AVIOContext *, avio_w8,)
+
 /**
  * Store a string as vb.
  */
@@ -320,11 +330,6 @@ static void put_str(AVIOContext *bc, const char *string)
     avio_write(bc, string, len);
 }
 
-static void put_s(AVIOContext *bc, int64_t val)
-{
-    put_v(bc, 2 * FFABS(val) - (val > 0));
-}
-
 static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
                        uint64_t startcode)
 {
-- 
2.20.1



More information about the ffmpeg-devel mailing list