[FFmpeg-devel] [PATCH 1/2] avio: Introduce avio_read_to_bprint(avioctx, bp, max_size)
Andrey Utkin
andrey.krieger.utkin at gmail.com
Wed Jul 23 15:12:38 CEST 2014
---
libavformat/avio.h | 9 +++++++++
libavformat/aviobuf.c | 18 ++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/libavformat/avio.h b/libavformat/avio.h
index 4004b6f..9b16843 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -31,6 +31,7 @@
#include "libavutil/common.h"
#include "libavutil/dict.h"
#include "libavutil/log.h"
+#include "libavutil/bprint.h"
#include "libavformat/version.h"
@@ -500,4 +501,12 @@ int avio_pause(AVIOContext *h, int pause);
int64_t avio_seek_time(AVIOContext *h, int stream_index,
int64_t timestamp, int flags);
+/**
+ * Read contents of h into print buffer, up to max_size bytes, or up to EOF.
+ *
+ * @return 0 for success (max_size bytes read or EOF reached), negative error
+ * code otherwise
+ */
+int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size);
+
#endif /* AVFORMAT_AVIO_H */
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 738459e..463d90a 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -953,6 +953,24 @@ int64_t avio_seek_time(AVIOContext *s, int stream_index,
return ret;
}
+int avio_read_to_bprint(AVIOContext *h, AVBPrint *pb, size_t max_size)
+{
+ int ret;
+ char buf[1024];
+ while (max_size) {
+ ret = avio_read(h, buf, FFMIN(max_size, sizeof(buf)));
+ if (ret == AVERROR_EOF)
+ return 0;
+ if (ret <= 0)
+ return ret;
+ av_bprint_append_data(pb, buf, ret);
+ if (!av_bprint_is_complete(pb))
+ return AVERROR(ENOMEM);
+ max_size -= ret;
+ }
+ return 0;
+}
+
/* output in a dynamic buffer */
typedef struct DynBuffer {
--
1.8.5.5
More information about the ffmpeg-devel
mailing list