On Sun, 11 Feb 2018, Nicolas George wrote:
Marton Balint (2018-02-10):
To be able to read lines longer than a static buffer size.
Signed-off-by: Marton Balint <c...@passwd.hu>
---
libavformat/aviobuf.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
libavformat/internal.h | 26 ++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 86eb6579f4..12cd73745d 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -821,6 +821,52 @@ int ff_get_line(AVIOContext *s, char *buf, int maxlen)
return i;
}
+int64_t ff_read_line_to_bprint(AVIOContext *s, AVBPrint *bp)
+{
+ int len, end;
+ int64_t read = 0;
+ char tmp[1024];
+ char c;
+
+ do {
+ len = 0;
+ do {
+ c = avio_r8(s);
+ end = (c == '\r' || c == '\n' || c == '\0');
+ if (!end)
+ tmp[len++] = c;
+ } while (!end && len < sizeof(tmp));
+ av_bprint_append_data(bp, tmp, len);
+ read += len;
+ } while (!end);
I think the code would be much simpler if you just call
av_bprint_chars() for each read character. The loop-within-loop makes
the logic a little hard to understand.
If speed is critic, then you could read directly into the bprint buffer,
but I do not think this is necessary.
It is a 500% speed improvement on a 260 MB line compared to using
av_bprint_chars, so I'd rather leave it as is. I can add a comment saying
"for performance reasons we fill a temporary buffer, and use av_bprint
functions on chunks of data".
Regards,
Marton
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel