From 44559d594e78477e2c1c51bd395fc7f92053b716 Mon Sep 17 00:00:00 2001
From: Josh Allmann <joshua.allmann@gmail.com>
Date: Thu, 1 Jul 2010 09:01:05 -0700
Subject: [PATCH 2/2] Pad the buffer in url_close_dyn_buf.

---
 libavformat/avio.h    |    5 ++++-
 libavformat/aviobuf.c |    7 ++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavformat/avio.h b/libavformat/avio.h
index dc8fdd6..a955048 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -530,7 +530,10 @@ int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size);
 
 /**
  * Return the written size and a pointer to the buffer. The buffer
- *  must be freed with av_free().
+ * must be freed with av_free(). If the buffer is opened with
+ * url_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is
+ * added; if opened with url_open_dyn_packet_buf, no padding is added.
+ *
  * @param s IO context
  * @param pbuffer pointer to a byte buffer
  * @return the length of the byte buffer
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 8684903..d9eb422 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -894,6 +894,11 @@ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
 {
     DynBuffer *d = s->opaque;
     int size;
+    static const char padbuf[FF_INPUT_BUFFER_PADDING_SIZE] = {0};
+
+    /* don't attempt to pad fixed-size packet buffers */
+    if (!s->max_packet_size)
+        put_buffer(s, padbuf, sizeof(padbuf));
 
     put_flush_packet(s);
 
@@ -901,6 +906,6 @@ int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)
     size = d->size;
     av_free(d);
     av_free(s);
-    return size;
+    return size - (s->max_packet_size ? 0 : FF_INPUT_BUFFER_PADDING_SIZE);
 }
 #endif /* CONFIG_MUXERS || CONFIG_NETWORK */
-- 
1.7.0.4

