[FFmpeg-devel] [PATCH 1/2] avformat: add limit_transfer_len option

Michael Niedermayer michaelni at gmx.at
Sun Mar 30 20:20:33 CEST 2014


This allows forcing smaller chunks to be read for debuging demuxers
and the avformat core

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavformat/avio.c |   14 +++++++++++++-
 libavformat/url.h  |    1 +
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/libavformat/avio.c b/libavformat/avio.c
index 4edaaa6..53b9624 100644
--- a/libavformat/avio.c
+++ b/libavformat/avio.c
@@ -72,7 +72,16 @@ static const AVClass *urlcontext_child_class_next(const AVClass *prev)
     return NULL;
 }
 
-static const AVOption options[] = { { NULL } };
+#define OFFSET(x) offsetof(URLContext, x)
+//these names are too long to be readable
+#define E AV_OPT_FLAG_ENCODING_PARAM
+#define D AV_OPT_FLAG_DECODING_PARAM
+
+static const AVOption options[] = {
+    {"limit_transfer_len", "maximum number of bytes tranfered with a single read/write call", OFFSET(limit_transfer_len), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, D|E},
+    { NULL }
+};
+
 const AVClass ffurl_context_class = {
     .class_name       = "URLContext",
     .item_name        = urlcontext_to_name,
@@ -296,6 +305,9 @@ static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf,
     int fast_retries = 5;
     int64_t wait_since = 0;
 
+    if (h->limit_transfer_len && h->limit_transfer_len < size)
+        size = FFMAX(size_min, h->limit_transfer_len);
+
     len = 0;
     while (len < size_min) {
         if (ff_check_interrupt(&h->interrupt_callback))
diff --git a/libavformat/url.h b/libavformat/url.h
index 712ea0f..4a4221b 100644
--- a/libavformat/url.h
+++ b/libavformat/url.h
@@ -49,6 +49,7 @@ typedef struct URLContext {
     int is_connected;
     AVIOInterruptCB interrupt_callback;
     int64_t rw_timeout;         /**< maximum time to wait for (network) read/write operation completion, in mcs */
+    int limit_transfer_len;     /**< maximum number of bytes tranfered with a single read/write call */
 } URLContext;
 
 typedef struct URLProtocol {
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list