diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-03-08 17:28:42 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-03-08 19:12:03 +0100 |
commit | 2653e125204569b1e9439ee2671c6ebb23a94b80 (patch) | |
tree | 4176f76bccc8cdd1c85b9d329a82867eda37d397 /libavcodec/utils.c | |
parent | 532f31a695c9530ce67a847be00d72e6e8acfd11 (diff) | |
parent | 1afddbe59e96af75f1c07605afc95615569f388f (diff) | |
download | ffmpeg-2653e125204569b1e9439ee2671c6ebb23a94b80.tar.gz |
Merge commit '1afddbe59e96af75f1c07605afc95615569f388f'
* commit '1afddbe59e96af75f1c07605afc95615569f388f':
avpacket: use AVBuffer to allow refcounting the packets.
Conflicts:
libavcodec/avpacket.c
libavcodec/utils.c
libavdevice/v4l2.c
libavformat/avidec.c
libavformat/flacdec.c
libavformat/id3v2.c
libavformat/matroskaenc.c
libavformat/mux.c
libavformat/utils.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 72450decfd..c077b8a385 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1162,7 +1162,10 @@ int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size) } if (avpkt->data) { + AVBufferRef *buf = avpkt->buf; +#if FF_API_DESTRUCT_PACKET void *destruct = avpkt->destruct; +#endif if (avpkt->size < size) { av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", avpkt->size, size); @@ -1170,7 +1173,10 @@ int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size) } av_init_packet(avpkt); +#if FF_API_DESTRUCT_PACKET avpkt->destruct = destruct; +#endif + avpkt->buf = buf; avpkt->size = size; return 0; } else { @@ -1318,6 +1324,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, avpkt->size = user_pkt.size; ret = -1; } + avpkt->buf = user_pkt.buf; avpkt->data = user_pkt.data; avpkt->destruct = user_pkt.destruct; } else { @@ -1329,9 +1336,9 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, if (!ret) { if (needs_realloc && avpkt->data) { - uint8_t *new_data = av_realloc(avpkt->data, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); - if (new_data) - avpkt->data = new_data; + ret = av_buffer_realloc(&avpkt->buf, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); + if (ret >= 0) + avpkt->data = avpkt->buf->data; } avctx->frame_number++; @@ -1515,6 +1522,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, avpkt->size = user_pkt.size; ret = -1; } + avpkt->buf = user_pkt.buf; avpkt->data = user_pkt.data; avpkt->destruct = user_pkt.destruct; } else { @@ -1530,11 +1538,10 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, else if (!(avctx->codec->capabilities & CODEC_CAP_DELAY)) avpkt->pts = avpkt->dts = frame->pts; - if (needs_realloc && avpkt->data && - avpkt->destruct == av_destruct_packet) { - uint8_t *new_data = av_realloc(avpkt->data, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); - if (new_data) - avpkt->data = new_data; + if (needs_realloc && avpkt->data) { + ret = av_buffer_realloc(&avpkt->buf, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); + if (ret >= 0) + avpkt->data = avpkt->buf->data; } avctx->frame_number++; |