]> git.sesse.net Git - ffmpeg/commitdiff
avpacket: add a function for wrapping existing data as side data
authorAnton Khirnov <anton@khirnov.net>
Sun, 4 Oct 2015 10:08:20 +0000 (12:08 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sun, 6 Dec 2015 09:22:18 +0000 (10:22 +0100)
doc/APIchanges
libavcodec/avcodec.h
libavcodec/avpacket.c
libavcodec/version.h

index ecbe8b537cbb0c62db0618c250b39f3488572cfa..0979930aacfff930df9e76e7e7c02149c3aa0b5b 100644 (file)
@@ -13,6 +13,9 @@ libavutil:     2015-08-28
 
 API changes, most recent first:
 
+2015-xx-xx - xxxxxxx - lavc 57.11.0 - avcodec.h
+  Add av_packet_add_side_data().
+
 2015-xx-xx - xxxxxxx - lavc 57.9.1 - avcodec.h
   Deprecate rtp_callback without replacement, i.e. it won't be possible to
   get image slices before the full frame is encoded any more. The libavformat
index e888952d4dcfe8f2af49ff064d59258c5d471841..5ed13de81ca14261d3df87e11997aea3ae7e4998 100644 (file)
@@ -3556,6 +3556,22 @@ void av_free_packet(AVPacket *pkt);
 uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
                                  int size);
 
+/**
+ * Wrap an existing array as a packet side data.
+ *
+ * @param pkt packet
+ * @param type side information type
+ * @param data the side data array. It must be allocated with the av_malloc()
+ *             family of functions. The ownership of the data is transferred to
+ *             pkt.
+ * @param size side information size
+ * @return a non-negative number on success, a negative AVERROR code on
+ *         failure. On failure, the packet is unchanged and the data remains
+ *         owned by the caller.
+ */
+int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                            uint8_t *data, size_t size);
+
 /**
  * Shrink the already allocated side data buffer
  *
index a6eb24178507671d801b2921bd1532d3a8cd6d3b..f8268b9401a781f482b63b1c5d29f7fd66b8fe8e 100644 (file)
@@ -237,29 +237,47 @@ void av_free_packet(AVPacket *pkt)
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
 
-uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
-                                 int size)
+int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                            uint8_t *data, size_t size)
 {
     int elems = pkt->side_data_elems;
 
     if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data))
-        return NULL;
-    if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
-        return NULL;
+        return AVERROR(EOVERFLOW);
 
     pkt->side_data = av_realloc(pkt->side_data,
                                 (elems + 1) * sizeof(*pkt->side_data));
     if (!pkt->side_data)
-        return NULL;
+        return AVERROR(ENOMEM);
 
-    pkt->side_data[elems].data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
-    if (!pkt->side_data[elems].data)
-        return NULL;
+    pkt->side_data[elems].data = data;
     pkt->side_data[elems].size = size;
     pkt->side_data[elems].type = type;
     pkt->side_data_elems++;
 
-    return pkt->side_data[elems].data;
+    return 0;
+}
+
+
+uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
+                                 int size)
+{
+    int ret;
+    uint8_t *data;
+
+    if ((unsigned)size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
+        return NULL;
+    data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE);
+    if (!data)
+        return NULL;
+
+    ret = av_packet_add_side_data(pkt, type, data, size);
+    if (ret < 0) {
+        av_freep(&data);
+        return NULL;
+    }
+
+    return data;
 }
 
 uint8_t *av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
index 29bc4b7e54a3625eda17302373a7cdcd45e8314d..0e42e6cbe4507d8090878a81c7dc790510afbd9b 100644 (file)
@@ -29,7 +29,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR 57
-#define LIBAVCODEC_VERSION_MINOR 10
+#define LIBAVCODEC_VERSION_MINOR 11
 #define LIBAVCODEC_VERSION_MICRO  0
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \