[FFmpeg-devel] [PATCH 3/3] Add av_copy_packet()
Andrey Utkin
andrey.krieger.utkin at gmail.com
Mon Sep 17 18:55:03 CEST 2012
This function makes full deep copy of AVPacket contents
---
libavcodec/avcodec.h | 7 +++++++
libavcodec/avpacket.c | 22 ++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 62a261a..783ac96 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3666,6 +3666,13 @@ int av_grow_packet(AVPacket *pkt, int grow_by);
int av_dup_packet(AVPacket *pkt);
/**
+ * Copy packet, including contents
+ *
+ * @return 0 on success, negative AVERROR on fail
+ */
+int av_copy_packet(AVPacket *dst, AVPacket *src);
+
+/**
* Free a packet.
*
* @param pkt packet to free
diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
index 270fe7e..124024f 100644
--- a/libavcodec/avpacket.c
+++ b/libavcodec/avpacket.c
@@ -156,6 +156,28 @@ failed_alloc:
return AVERROR(ENOMEM);
}
+int av_copy_packet(AVPacket *dst, AVPacket *src) {
+ *dst = *src;
+ dst->destruct = av_destruct_packet;
+ if (src->size)
+ DUP_DATA(dst->data, src->data, src->size, 1);
+ if (src->side_data_elems) {
+ int i;
+ dst->side_data = av_mallocz(dst->side_data_elems * sizeof(*dst->side_data));
+ for (i = 0; i < src->side_data_elems; i++) {
+ DUP_DATA(dst->side_data[i].data, src->side_data[i].data,
+ src->side_data[i].size, 1);
+ dst->side_data[i].size = src->side_data[i].size;
+ dst->side_data[i].type = src->side_data[i].type;
+ }
+ }
+ return 0;
+
+failed_alloc:
+ av_destruct_packet(dst);
+ return AVERROR(ENOMEM);
+}
+
void av_free_packet(AVPacket *pkt)
{
if (pkt) {
--
1.7.8.6
More information about the ffmpeg-devel
mailing list