diff mbox

[FFmpeg-devel,1/2] libavformat/avio: Add avio_get_dyn_buf function

Message ID MWHPR13MB16785A36FEB37C00C600A5A8BA600@MWHPR13MB1678.namprd13.prod.outlook.com
State Superseded
Headers show

Commit Message

Soft Works Jan. 5, 2017, 6:06 p.m. UTC
This commit adds the avio_get_dyn_buf function which allows accessing the
content of a DynBuffer without destroying it.

This is required in matroskaenc for preliminary writing (correct) mkv headers.

Context for this change is fixing regression bug #5977.
---
 libavformat/avio.h    | 12 ++++++++++++
 libavformat/aviobuf.c | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Michael Niedermayer Jan. 6, 2017, 11:09 a.m. UTC | #1
On Thu, Jan 05, 2017 at 06:06:27PM +0000, Soft Works wrote:
> This commit adds the avio_get_dyn_buf function which allows accessing the
> content of a DynBuffer without destroying it.
> 
> This is required in matroskaenc for preliminary writing (correct) mkv headers.
> 
> Context for this change is fixing regression bug #5977.
> ---
>  libavformat/avio.h    | 12 ++++++++++++
>  libavformat/aviobuf.c | 17 +++++++++++++++++
>  2 files changed, 29 insertions(+)
> 
> diff --git a/libavformat/avio.h b/libavformat/avio.h
> index b1ce1d1..f2b9a6f 100644
> --- a/libavformat/avio.h
> +++ b/libavformat/avio.h
> @@ -704,6 +704,18 @@ int avio_closep(AVIOContext **s);
>  int avio_open_dyn_buf(AVIOContext **s);
>  
>  /**
> + * Return the written size and a pointer to the buffer. 
> + * The AVIOContext stream is left intact.
> + * The buffer must NOT be freed. 
> + * No padding is added to the buffer.
> + *
> + * @param s IO context
> + * @param pbuffer pointer to a byte buffer
> + * @return the length of the byte buffer
> + */
> +int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer);

adding a public function (av*)
needs minor version bump (libavformat/version.h) and
doc/APIchanges entry

thx

[...]
diff mbox

Patch

diff --git a/libavformat/avio.h b/libavformat/avio.h
index b1ce1d1..f2b9a6f 100644
--- a/libavformat/avio.h
+++ b/libavformat/avio.h
@@ -704,6 +704,18 @@  int avio_closep(AVIOContext **s);
 int avio_open_dyn_buf(AVIOContext **s);
 
 /**
+ * Return the written size and a pointer to the buffer. 
+ * The AVIOContext stream is left intact.
+ * The buffer must NOT be freed. 
+ * No padding is added to the buffer.
+ *
+ * @param s IO context
+ * @param pbuffer pointer to a byte buffer
+ * @return the length of the byte buffer
+ */
+int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer);
+
+/**
  * Return the written size and a pointer to the buffer. The buffer
  * must be freed with av_free().
  * Padding of AV_INPUT_BUFFER_PADDING_SIZE is added to the buffer.
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 134d627..bf7e5f8 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1277,6 +1277,23 @@  int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
     return url_open_dyn_buf_internal(s, max_packet_size);
 }
 
+int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
+{
+    DynBuffer *d;
+
+    if (!s) {
+        *pbuffer = NULL;
+        return 0;
+    }
+
+    avio_flush(s);
+
+    d = s->opaque;
+    *pbuffer = d->buffer;
+
+    return d->size;
+}
+
 int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
 {
     DynBuffer *d;