History

Merge commit 'a9a60106370f862e191dea58e748626da6a8fe97'

* commit 'a9a60106370f862e191dea58e748626da6a8fe97': avpacket: Provide an alloc and a free function for the struct

Hendrik Leppkes committed 11 years ago

Commit 3ec049b2 parents 87a6f53 a9a60103 files · +69 −0Browse files

Unified · Split

3 files
  1. doc/APIchanges +2 −0
  2. libavcodec/avcodec.h +34 −0
  3. libavcodec/avpacket.c +33 −0
doc/APIchanges+2−0
@@ -20,6 +20,8 @@ API changes, most recent first: · 19 unmodified lines
2020 it resets the packet in a more consistent way.
2121 xxxxxx - Deprecate av_dup_packet(), it is a no-op for most cases.
2222 Use av_packet_ref() to make a non-refcounted AVPacket refcounted.
23+ xxxxxx - Add av_packet_alloc(), av_packet_clone(), av_packet_free().
24+ They match the AVFrame functions with the same name.
2325
2426 2015-10-27 - xxxxxxx - lavu 55.5.100 - cpu.h
2527 Add AV_CPU_FLAG_AESNI.
libavcodec/avcodec.h+34−0
@@ -3847,6 +3847,40 @@ void avsubtitle_free(AVSubtitle *sub); · 3846 unmodified lines
38473847 * @{
38483848 */
38493849
3850+/**
3851+ * Allocate an AVPacket and set its fields to default values. The resulting
3852+ * struct must be freed using av_packet_free().
3853+ *
3854+ * @return An AVPacket filled with default values or NULL on failure.
3855+ *
3856+ * @note this only allocates the AVPacket itself, not the data buffers. Those
3857+ * must be allocated through other means such as av_new_packet.
3858+ *
3859+ * @see av_new_packet
3860+ */
3861+AVPacket *av_packet_alloc(void);
3862+
3863+/**
3864+ * Create a new packet that references the same data as src.
3865+ *
3866+ * This is a shortcut for av_packet_alloc()+av_packet_ref().
3867+ *
3868+ * @return newly created AVPacket on success, NULL on error.
3869+ *
3870+ * @see av_packet_alloc
3871+ * @see av_packet_ref
3872+ */
3873+AVPacket *av_packet_clone(AVPacket *src);
3874+
3875+/**
3876+ * Free the packet, if the packet is reference counted, it will be
3877+ * unreferenced first.
3878+ *
3879+ * @param packet packet to be freed. The pointer will be set to NULL.
3880+ * @note passing NULL is a no-op.
3881+ */
3882+void av_packet_free(AVPacket **pkt);
3883+
38503884 /**
38513885 * Initialize optional fields of a packet with default values.
38523886 *
libavcodec/avpacket.c+33−0
@@ -48,6 +48,26 @@ FF_ENABLE_DEPRECATION_WARNINGS · 47 unmodified lines
4848 pkt->side_data_elems = 0;
4949 }
5050
51+AVPacket *av_packet_alloc(void)
52+{
53+ AVPacket *pkt = av_mallocz(sizeof(AVPacket));
54+ if (!pkt)
55+ return pkt;
56+
57+ av_packet_unref(pkt);
58+
59+ return pkt;
60+}
61+
62+void av_packet_free(AVPacket **pkt)
63+{
64+ if (!pkt || !*pkt)
65+ return;
66+
67+ av_packet_unref(*pkt);
68+ av_freep(pkt);
69+}
70+
5171 static int packet_alloc(AVBufferRef **buf, int size)
5272 {
5373 int ret;
@@ -542,6 +562,19 @@ fail: · 488 unmodified lines
542562 return ret;
543563 }
544564
565+AVPacket *av_packet_clone(AVPacket *src)
566+{
567+ AVPacket *ret = av_packet_alloc();
568+
569+ if (!ret)
570+ return ret;
571+
572+ if (av_packet_ref(ret, src))
573+ av_packet_free(&ret);
574+
575+ return ret;
576+}
577+
545578 void av_packet_move_ref(AVPacket *dst, AVPacket *src)
546579 {
547580 *dst = *src;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t