[FFmpeg-cvslog] avcodec/avpacket: add av_packet_make_refcounted()

James Almer git at videolan.org
Mon Apr 2 06:49:58 EEST 2018


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sat Mar 24 19:18:59 2018 -0300| [860086ee168866c8b7cdb5c1c13ac962c5f3efc4] | committer: James Almer

avcodec/avpacket: add av_packet_make_refcounted()

It works as a drop in replacement for the deprecated av_dup_packet(),
to ensure a packet is reference counted.

Reviewed-by: Michael Niedermayer <michael at niedermayer.cc>
Signed-off-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=860086ee168866c8b7cdb5c1c13ac962c5f3efc4
---

 doc/APIchanges        |  3 +++
 libavcodec/avcodec.h  | 18 +++++++++++++++++-
 libavcodec/avpacket.c | 18 ++++++++++++++++++
 libavcodec/version.h  |  2 +-
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index adc8b1d0c8..121fbee9ce 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-04-01 - xxxxxxx - lavc 58.17.100 - avcodec.h
+  Add av_packet_make_refcounted().
+
 2018-xx-xx - xxxxxxx - lavfi 7.14.100 - avfilter.h
   Deprecate use of avfilter_register(), avfilter_register_all(),
   avfilter_next(). Add av_filter_iterate().
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 3306910dd2..fb0c6fae70 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4365,7 +4365,7 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size);
  * @warning This is a hack - the packet memory allocation stuff is broken. The
  * packet is allocated if it was not really allocated.
  *
- * @deprecated Use av_packet_ref
+ * @deprecated Use av_packet_ref or av_packet_make_refcounted
  */
 attribute_deprecated
 int av_dup_packet(AVPacket *pkt);
@@ -4537,6 +4537,22 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src);
 int av_packet_copy_props(AVPacket *dst, const AVPacket *src);
 
 /**
+ * Ensure the data described by a given packet is reference counted.
+ *
+ * @note This function does not ensure that the reference will be writable.
+ *       Use av_packet_make_writable instead for that purpose.
+ *
+ * @see av_packet_ref
+ * @see av_packet_make_writable
+ *
+ * @param pkt packet whose data should be made reference counted.
+ *
+ * @return 0 on success, a negative AVERROR on error. On failure, the
+ *         packet is unchanged.
+ */
+int av_packet_make_refcounted(AVPacket *pkt);
+
+/**
  * Create a writable reference for the data described by a given packet,
  * avoiding data copy if possible.
  *
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 0993481961..99a0c1383b 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -652,6 +652,24 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src)
     src->size = 0;
 }
 
+int av_packet_make_refcounted(AVPacket *pkt)
+{
+    int ret;
+
+    if (pkt->buf)
+        return 0;
+
+    ret = packet_alloc(&pkt->buf, pkt->size);
+    if (ret < 0)
+        return ret;
+    if (pkt->size)
+        memcpy(pkt->buf->data, pkt->data, pkt->size);
+
+    pkt->data = pkt->buf->data;
+
+    return 0;
+}
+
 int av_packet_make_writable(AVPacket *pkt)
 {
     AVBufferRef *buf = NULL;
diff --git a/libavcodec/version.h b/libavcodec/version.h
index 8ac4626da7..e59215dfed 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  16
+#define LIBAVCODEC_VERSION_MINOR  17
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \



More information about the ffmpeg-cvslog mailing list