[FFmpeg-cvslog] avformat/aviobuf: add a full string reading mode to read_line_to_bprint

Jan Ekström git at videolan.org
Mon Oct 4 18:25:03 EEST 2021


ffmpeg | branch: master | Jan Ekström <jan.ekstrom at 24i.com> | Mon Sep 20 14:22:43 2021 +0300| [94f227bac1c0189d5a270322398bfa4ffa6ad196] | committer: Jan Ekström

avformat/aviobuf: add a full string reading mode to read_line_to_bprint

Additionally:
* rename it to read_string_to_bprint
* split most of ff_read_line_to_bprint_overwrite into an internal
  function which can then be utilized to implement other
  functionality without duplicating code.

Signed-off-by: Jan Ekström <jan.ekstrom at 24i.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=94f227bac1c0189d5a270322398bfa4ffa6ad196
---

 libavformat/aviobuf.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index d79e41ca77..f846a2fd6a 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -803,7 +803,13 @@ int ff_get_chomp_line(AVIOContext *s, char *buf, int maxlen)
     return len;
 }
 
-static int64_t read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
+typedef enum FFBPrintReadStringMode {
+    FFBPrintReadString = 0,
+    FFBPrintReadLine   = 1,
+} FFBPrintReadStringMode;
+
+static int64_t read_string_to_bprint(AVIOContext *s, AVBPrint *bp,
+                                     FFBPrintReadStringMode mode)
 {
     int len, end;
     int64_t read = 0;
@@ -814,7 +820,8 @@ static int64_t read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
         len = 0;
         do {
             c = avio_r8(s);
-            end = (c == '\r' || c == '\n' || c == '\0');
+            end = ((mode == FFBPrintReadLine && (c == '\r' || c == '\n')) ||
+                   c == '\0');
             if (!end)
                 tmp[len++] = c;
         } while (!end && len < sizeof(tmp));
@@ -822,7 +829,8 @@ static int64_t read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
         read += len;
     } while (!end);
 
-    if (c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
+    if (mode == FFBPrintReadLine &&
+        c == '\r' && avio_r8(s) != '\n' && !avio_feof(s))
         avio_skip(s, -1);
 
     if (!c && s->error)
@@ -834,12 +842,13 @@ static int64_t read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
     return read;
 }
 
-int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
+static int64_t read_string_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp,
+                                               FFBPrintReadStringMode mode)
 {
     int64_t ret;
 
     av_bprint_clear(bp);
-    ret = read_line_to_bprint(s, bp);
+    ret = read_string_to_bprint(s, bp, mode);
     if (ret < 0)
         return ret;
 
@@ -849,6 +858,11 @@ int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
     return bp->len;
 }
 
+int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, AVBPrint *bp)
+{
+    return read_string_to_bprint_overwrite(s, bp, FFBPrintReadLine);
+}
+
 int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
 {
     int i;



More information about the ffmpeg-cvslog mailing list