summaryrefslogtreecommitdiffstats
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-10-31 08:53:18 +0100
committerAnton Khirnov <anton@khirnov.net>2013-03-08 07:33:45 +0100
commit1afddbe59e96af75f1c07605afc95615569f388f (patch)
tree0e8223d9813de6976ec50dc1a5a7c7bf9a099450 /libavcodec/utils.c
parent1cec0624d0e6f48590283a57169b58b9fe8449d3 (diff)
downloadffmpeg-streaming-1afddbe59e96af75f1c07605afc95615569f388f.zip
ffmpeg-streaming-1afddbe59e96af75f1c07605afc95615569f388f.tar.gz
avpacket: use AVBuffer to allow refcounting the packets.
This will allow us to avoid copying the packets in many cases. This breaks ABI.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2a78f7f..091d34c 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -887,13 +887,19 @@ int ff_alloc_packet(AVPacket *avpkt, int size)
return AVERROR(EINVAL);
if (avpkt->data) {
+ AVBufferRef *buf = avpkt->buf;
+#if FF_API_DESTRUCT_PACKET
void *destruct = avpkt->destruct;
+#endif
if (avpkt->size < size)
return AVERROR(EINVAL);
av_init_packet(avpkt);
+#if FF_API_DESTRUCT_PACKET
avpkt->destruct = destruct;
+#endif
+ avpkt->buf = buf;
avpkt->size = size;
return 0;
} else {
@@ -1020,9 +1026,9 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
}
if (!user_packet && avpkt->size) {
- uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
- if (new_data)
- avpkt->data = new_data;
+ ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
+ if (ret >= 0)
+ avpkt->data = avpkt->buf->data;
}
avctx->frame_number++;
@@ -1197,9 +1203,9 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avpkt->pts = avpkt->dts = frame->pts;
if (!user_packet && avpkt->size) {
- uint8_t *new_data = av_realloc(avpkt->data, avpkt->size);
- if (new_data)
- avpkt->data = new_data;
+ ret = av_buffer_realloc(&avpkt->buf, avpkt->size);
+ if (ret >= 0)
+ avpkt->data = avpkt->buf->data;
}
avctx->frame_number++;
OpenPOWER on IntegriCloud