aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/avpacket.c
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2018-03-19 12:39:08 -0300
committerJames Almer <jamrial@gmail.com>2018-03-21 22:17:40 -0300
commitf14ca600015d234f383e9ea5ba5c9f9830271cb3 (patch)
tree3a975ea16cbe70b340afca7d932e31ba286634ac /libavcodec/avpacket.c
parent28aaed773712d170e13f35658aac685dd8b7db44 (diff)
downloadffmpeg-f14ca600015d234f383e9ea5ba5c9f9830271cb3.tar.gz
avcodec/avpacket: add av_packet_make_writable()
Useful as well to quickly make a packet reference counted when it isn't already so. Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec/avpacket.c')
-rw-r--r--libavcodec/avpacket.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index fe8113ab76..0693ca6f62 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -652,6 +652,30 @@ void av_packet_move_ref(AVPacket *dst, AVPacket *src)
src->size = 0;
}
+int av_packet_make_writable(AVPacket *pkt)
+{
+ AVBufferRef *buf = NULL;
+ int ret;
+
+ if (pkt->buf && av_buffer_is_writable(pkt->buf))
+ return 0;
+
+ if (!pkt->data)
+ return AVERROR(EINVAL);
+
+ ret = packet_alloc(&buf, pkt->size);
+ if (ret < 0)
+ return ret;
+ if (pkt->size)
+ memcpy(buf->data, pkt->data, pkt->size);
+
+ av_buffer_unref(&pkt->buf);
+ pkt->buf = buf;
+ pkt->data = buf->data;
+
+ return 0;
+}
+
void av_packet_rescale_ts(AVPacket *pkt, AVRational src_tb, AVRational dst_tb)
{
if (pkt->pts != AV_NOPTS_VALUE)