summaryrefslogtreecommitdiff
path: root/libavcodec
diff options
context:
space:
mode:
authorHendrik Leppkes <h.leppkes@gmail.com>2015-10-29 14:18:03 +0100
committerHendrik Leppkes <h.leppkes@gmail.com>2015-10-29 14:18:03 +0100
commit3ec049b85dacdb5e3f598e4ddab87b1d5a877783 (patch)
tree9f2b1b7d6a9c0715155d162f5bd993b945361e71 /libavcodec
parent87a6f532b46fb16eea07943325f5d322d08e13ed (diff)
parenta9a60106370f862e191dea58e748626da6a8fe97 (diff)
Merge commit 'a9a60106370f862e191dea58e748626da6a8fe97'
* commit 'a9a60106370f862e191dea58e748626da6a8fe97': avpacket: Provide an alloc and a free function for the struct Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h34
-rw-r--r--libavcodec/avpacket.c33
2 files changed, 67 insertions, 0 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 936d9fe240..3a91cfd7f2 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3848,6 +3848,40 @@ void avsubtitle_free(AVSubtitle *sub);
*/
/**
+ * Allocate an AVPacket and set its fields to default values. The resulting
+ * struct must be freed using av_packet_free().
+ *
+ * @return An AVPacket filled with default values or NULL on failure.
+ *
+ * @note this only allocates the AVPacket itself, not the data buffers. Those
+ * must be allocated through other means such as av_new_packet.
+ *
+ * @see av_new_packet
+ */
+AVPacket *av_packet_alloc(void);
+
+/**
+ * Create a new packet that references the same data as src.
+ *
+ * This is a shortcut for av_packet_alloc()+av_packet_ref().
+ *
+ * @return newly created AVPacket on success, NULL on error.
+ *
+ * @see av_packet_alloc
+ * @see av_packet_ref
+ */
+AVPacket *av_packet_clone(AVPacket *src);
+
+/**
+ * Free the packet, if the packet is reference counted, it will be
+ * unreferenced first.
+ *
+ * @param packet packet to be freed. The pointer will be set to NULL.
+ * @note passing NULL is a no-op.
+ */
+void av_packet_free(AVPacket **pkt);
+
+/**
* Initialize optional fields of a packet with default values.
*
* Note, this does not touch the data and size members, which have to be
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 34ef2659ef..1cc10eba05 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -48,6 +48,26 @@ FF_ENABLE_DEPRECATION_WARNINGS
pkt->side_data_elems = 0;
}
+AVPacket *av_packet_alloc(void)
+{
+ AVPacket *pkt = av_mallocz(sizeof(AVPacket));
+ if (!pkt)
+ return pkt;
+
+ av_packet_unref(pkt);
+
+ return pkt;
+}
+
+void av_packet_free(AVPacket **pkt)
+{
+ if (!pkt || !*pkt)
+ return;
+
+ av_packet_unref(*pkt);
+ av_freep(pkt);
+}
+
static int packet_alloc(AVBufferRef **buf, int size)
{
int ret;
@@ -542,6 +562,19 @@ fail:
return ret;
}
+AVPacket *av_packet_clone(AVPacket *src)
+{
+ AVPacket *ret = av_packet_alloc();
+
+ if (!ret)
+ return ret;
+
+ if (av_packet_ref(ret, src))
+ av_packet_free(&ret);
+
+ return ret;
+}
+
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
{
*dst = *src;