Updated. It uses side-data now.
>From 013579699644c801ed696f61848eabb327e41b89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20K=C3=BChnel?= <[email protected]>
Date: Mon, 26 Sep 2011 22:26:13 +0200
Subject: [PATCH 1/3] avcodec: add side-data to AVFrame

---
 doc/APIchanges       |    8 +++++
 libavcodec/Makefile  |    1 +
 libavcodec/avcodec.h |   49 ++++++++++++++++++++++++++++
 libavcodec/avframe.c |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++
 libavcodec/version.h |    2 +-
 5 files changed, 145 insertions(+), 1 deletions(-)
 create mode 100644 libavcodec/avframe.c

diff --git a/doc/APIchanges b/doc/APIchanges
index bd55cb0..01ae80b 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,14 @@ libavutil:   2011-04-18
 
 API changes, most recent first:
 
+2011-10-xx - xxxxxxx - lavc 53.15.0
+  Introduce AVFrame.side-data and AVFrame.side_data_elems.
+  Add av_frame_free_side_data(), av_frame_new_side_data() and
+      av_frame_get_side_data().
+  Add AV_FRAME_SIDE_DATA_OVERWRITE and AV_FRAME_SIDE_DATA_APPEND flags for
+      av_frame_new_side_data() function.
+  Add AVFrameSideDataType enum.
+
 2011-10-xx - xxxxxxx - lavf 53.10.0
   Add avformat_new_stream(). Deprecate av_new_stream().
 
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 81881e4..3078112 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -6,6 +6,7 @@ HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vdpau.h version.h xvmc.h
 OBJS = allcodecs.o                                                      \
        audioconvert.o                                                   \
        avpacket.o                                                       \
+       avframe.o                                                        \
        bitstream.o                                                      \
        bitstream_filter.o                                               \
        dsputil.o                                                        \
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 28dde3f..05f0128 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -806,6 +806,13 @@ enum AVPacketSideDataType {
     AV_PKT_DATA_PALETTE,
 };
 
+enum AVFrameSideDataType {
+    AV_FRAME_DATA_METADATA, ///< metadata dictionary, size has to be sizeof(AVDictionary)
+};
+
+#define AV_FRAME_SIDE_DATA_OVERWRITE 1
+#define AV_FRAME_SIDE_DATA_APPEND    2
+
 typedef struct AVPacket {
     /**
      * Presentation timestamp in AVStream->time_base units; the time at which
@@ -1138,6 +1145,18 @@ typedef struct AVFrame {
      * - decoding: Set by libavcodec.
      */
     void *thread_opaque;
+
+    /**
+     * Side-data.
+     * - encoding: Set by user.
+     * - decoding: Set by libavcodec.
+     */
+    struct {
+        uint8_t *data;
+        int      size;
+        enum AVFrameSideDataType type;
+    } *side_data;
+    int side_data_elems;
 } AVFrame;
 
 /**
@@ -3691,6 +3710,36 @@ void avcodec_get_frame_defaults(AVFrame *pic);
  */
 AVFrame *avcodec_alloc_frame(void);
 
+/**
+ * Free side information from frame.
+ *
+ * @param frm The AVFrame of which the side information should be freed.
+ */
+void av_frame_free_side_data(AVFrame *frm);
+
+/**
+ * Allocate new information of a frame.
+ *
+ * @param frm frame
+ * @param type side information type
+ * @param size side information size
+ * @param flags flags to modify the treatment of already existing entrys with the same type
+ * @return pointer to fresh allocated data or NULL otherwise
+ */
+uint8_t* av_frame_new_side_data(AVFrame *frm, enum AVFrameSideDataType type,
+                                int size, int flags);
+
+/**
+ * Get side information from frame.
+ *
+ * @param frm frame
+ * @param type desired side information type
+ * @param size pointer for side information size to store (optional)
+ * @return pointer to data if present or NULL otherwise
+ */
+uint8_t* av_frame_get_side_data(AVFrame *frm, enum AVFrameSideDataType type,
+                                int *size);
+
 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic);
 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic);
 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic);
diff --git a/libavcodec/avframe.c b/libavcodec/avframe.c
new file mode 100644
index 0000000..8b64064
--- /dev/null
+++ b/libavcodec/avframe.c
@@ -0,0 +1,86 @@
+#include "avcodec.h"
+
+void av_frame_free_side_data(AVFrame *frm)
+{
+    int i;
+
+    for (i = 0; i < frm->side_data_elems; i++)
+        if (frm->side_data[i].type == AV_FRAME_DATA_METADATA)
+            av_dict_free((AVDictionary**)&frm->side_data[i].data);
+        else
+            av_free(frm->side_data[i].data);
+    av_freep(&frm->side_data);
+    frm->side_data_elems = 0;
+}
+
+uint8_t* av_frame_new_side_data(AVFrame *frm, enum AVFrameSideDataType type,
+                                int size, int flags)
+{
+    int i;
+    int elems = frm->side_data_elems;
+    int old_size = 0;
+    void *tmp;
+
+    if ((unsigned)elems + 1 > INT_MAX / sizeof(*frm->side_data))
+        return NULL;
+    if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE)
+        return NULL;
+    if (type == AV_FRAME_DATA_METADATA && size != sizeof(AVDictionary))
+        return NULL;
+
+    for (i = 0; i < elems; i++)
+        if (frm->side_data[i].type == type)
+            break;
+    if (i < elems) {
+        if (!flags & (AV_FRAME_SIDE_DATA_OVERWRITE | AV_FRAME_SIDE_DATA_APPEND))
+            return NULL;
+
+        if (flags & AV_FRAME_SIDE_DATA_OVERWRITE) {
+            if (type == AV_FRAME_DATA_METADATA)
+                av_dict_free((AVDictionary**)&frm->side_data[i].data);
+            else
+                av_freep(&frm->side_data[i].data);
+            frm->side_data[i].size = 0;
+        }
+        if (type == AV_FRAME_DATA_METADATA && frm->side_data[i].size > 0)
+            return NULL;
+        tmp = av_realloc(frm->side_data[i].data, frm->side_data[i].size + size);
+        if (!tmp)
+            return NULL;
+        frm->side_data[i].data = tmp;
+        old_size = frm->side_data[i].size;
+        frm->side_data[i].size += size;
+        return &frm->side_data[i].data[old_size];
+    } else {
+        tmp = av_realloc(frm->side_data, (elems + 1) * sizeof(*frm->side_data));
+        if (!tmp)
+            return NULL;
+        frm->side_data = tmp;
+
+        frm->side_data[elems].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE);
+        if (!frm->side_data[elems].data) {
+            frm->side_data[elems].size = 0;
+            return NULL;
+        }
+        frm->side_data[elems].size = size;
+        frm->side_data[elems].type = type;
+        frm->side_data_elems++;
+
+        return frm->side_data[elems].data;
+    }
+}
+
+uint8_t* av_frame_get_side_data(AVFrame *frm, enum AVFrameSideDataType type,
+                                int *size)
+{
+    int i;
+
+    for (i = 0; i < frm->side_data_elems; i++) {
+        if (frm->side_data[i].type == type) {
+            if (size)
+                *size = frm->side_data[i].size;
+            return frm->side_data[i].data;
+        }
+    }
+    return NULL;
+}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a361bbd..3b54bc5 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
 #define AVCODEC_VERSION_H
 
 #define LIBAVCODEC_VERSION_MAJOR 53
-#define LIBAVCODEC_VERSION_MINOR  14
+#define LIBAVCODEC_VERSION_MINOR  15
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
-- 
1.7.7

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to