summaryrefslogtreecommitdiff
path: root/libavcodec/avpacket.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-03-24 19:18:59 -0300
committerJames Almer <jamrial@gmail.com>2018-04-01 23:40:41 -0300
commit860086ee168866c8b7cdb5c1c13ac962c5f3efc4 (patch)
tree91acb5b03c1a16deb780fefa00de596927693643 /libavcodec/avpacket.c
parente0f32286861ddf7666ba92297686fa216d65968e (diff)
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@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/avpacket.c')
-rw-r--r--libavcodec/avpacket.c18
1 files changed, 18 insertions, 0 deletions
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;