[002/264] lavc: add stream-global packet side data

Message ID 1447012658-16819-3-git-send-email-anton@khirnov.net
State Committed
Headers show

Commit Message

Anton Khirnov Nov. 8, 2015, 7:57 p.m.
This is similar to what is done for AVStream.
---
 doc/APIchanges       |  5 +++--
 libavcodec/avcodec.h | 10 ++++++++++
 libavcodec/utils.c   |  9 ++++++++-
 3 files changed, 21 insertions(+), 3 deletions(-)

Comments

Luca Barbato Nov. 8, 2015, 8:15 p.m. | #1
On 08/11/15 20:57, Anton Khirnov wrote:
> This is similar to what is done for AVStream.
> ---
>  doc/APIchanges       |  5 +++--
>  libavcodec/avcodec.h | 10 ++++++++++
>  libavcodec/utils.c   |  9 ++++++++-
>  3 files changed, 21 insertions(+), 3 deletions(-)
> 

Ok.

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 8c12284..6ea75e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,8 +13,9 @@  libavutil:     2015-08-28
 
 API changes, most recent first:
 
-2015-xx-xx - xxxxxxx - lavc 57.9.0 - avcodec.h
-  Add av_packet_add_side_data().
+2015-xx-xx - lavc 57.9.0 - avcodec.h
+  xxxxxxx - Add av_packet_add_side_data().
+  xxxxxxx - Add AVCodecContext.coded_side_data.
 
 2015-xx-xx - lavc 57.7.0 - avcodec.h
   xxxxxx - Deprecate av_free_packet(). Use av_packet_unref() as replacement,
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index a139113..78e5aab 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2911,6 +2911,16 @@  typedef struct AVCodecContext {
      * - decoding: Set by libavcodec before calling get_format()
      */
     enum AVPixelFormat sw_pix_fmt;
+
+    /**
+     * Additional data associated with the entire coded stream.
+     *
+     * - decoding: unused
+     * - encoding: may be set by libavcodec after avcodec_open2().
+     */
+    AVPacketSideData *coded_side_data;
+    int            nb_coded_side_data;
+
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ad00a92..f3361a0 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1603,9 +1603,11 @@  void avsubtitle_free(AVSubtitle *sub)
 
 av_cold int avcodec_close(AVCodecContext *avctx)
 {
+    int i;
+
     if (avcodec_is_open(avctx)) {
         FramePool *pool = avctx->internal->pool;
-        int i;
+
         if (HAVE_THREADS && avctx->internal->thread_ctx)
             ff_thread_free(avctx);
         if (avctx->codec && avctx->codec->close)
@@ -1622,6 +1624,11 @@  av_cold int avcodec_close(AVCodecContext *avctx)
         av_freep(&avctx->internal);
     }
 
+    for (i = 0; i < avctx->nb_coded_side_data; i++)
+        av_freep(&avctx->coded_side_data[i].data);
+    av_freep(&avctx->coded_side_data);
+    avctx->nb_coded_side_data = 0;
+
     if (avctx->priv_data && avctx->codec && avctx->codec->priv_class)
         av_opt_free(avctx->priv_data);
     av_opt_free(avctx);