From ce70f28a1732c74a9cd7fec2d56178750bd6e457 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 23 Oct 2015 11:11:31 +0200 Subject: avpacket: Replace av_free_packet with av_packet_unref `av_packet_unref` matches the AVFrame ref-counted API and can be used as a drop in replacement. Deprecate `av_free_packet`. --- libavcodec/avcodec.h | 33 +++++++++++++++++++-------------- libavcodec/avpacket.c | 6 +++++- libavcodec/jpeglsenc.c | 2 +- libavcodec/libxvid.c | 2 +- libavcodec/mpegvideo_enc.c | 2 +- libavcodec/utils.c | 8 ++++---- libavcodec/version.h | 5 ++++- 7 files changed, 35 insertions(+), 23 deletions(-) (limited to 'libavcodec') diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index cf8cc5a5d7..dfd18ba866 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1151,15 +1151,19 @@ typedef struct AVPacketSideData { * ABI. Thus it may be allocated on stack and no new fields can be added to it * without libavcodec and libavformat major bump. * - * The semantics of data ownership depends on the buf or destruct (deprecated) - * fields. If either is set, the packet data is dynamically allocated and is - * valid indefinitely until av_free_packet() is called (which in turn calls - * av_buffer_unref()/the destruct callback to free the data). If neither is set, - * the packet data is typically backed by some static buffer somewhere and is - * only valid for a limited time (e.g. until the next read call when demuxing). + * The semantics of data ownership depends on the buf field. + * If it is set, the packet data is dynamically allocated and is + * valid indefinitely until a call to av_packet_unref() reduces the + * reference count to 0. * - * The side data is always allocated with av_malloc() and is freed in - * av_free_packet(). + * If the buf field is not set av_packet_ref() would make a copy instead + * of increasing the reference count. + * + * The side data is always allocated with av_malloc(), copied by + * av_packet_ref() and freed by av_packet_unref(). + * + * @see av_packet_ref + * @see av_packet_unref */ typedef struct AVPacket { /** @@ -3477,14 +3481,17 @@ int av_packet_from_data(AVPacket *pkt, uint8_t *data, int size); * packet is allocated if it was not really allocated. */ int av_dup_packet(AVPacket *pkt); - +#if FF_API_AVPACKET_OLD_API /** * Free a packet. * + * @deprecated Use av_packet_unref + * * @param pkt packet to free */ +attribute_deprecated void av_free_packet(AVPacket *pkt); - +#endif /** * Allocate new information of a packet. * @@ -4070,8 +4077,7 @@ AVCodec *avcodec_find_encoder_by_name(const char *name); * output packet. * * If this function fails or produces no output, avpkt will be - * freed using av_free_packet() (i.e. avpkt->destruct will be - * called to free the user supplied buffer). + * freed using av_packet_unref(). * @param[in] frame AVFrame containing the raw audio data to be encoded. * May be NULL when flushing an encoder that has the * AV_CODEC_CAP_DELAY capability set. @@ -4112,8 +4118,7 @@ int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, * caller, he is responsible for freeing it. * * If this function fails or produces no output, avpkt will be - * freed using av_free_packet() (i.e. avpkt->destruct will be - * called to free the user supplied buffer). + * freed using av_packet_unref(). * @param[in] frame AVFrame containing the raw video data to be encoded. * May be NULL when flushing an encoder that has the * AV_CODEC_CAP_DELAY capability set. diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c index e762a8782a..eaea061c54 100644 --- a/libavcodec/avpacket.c +++ b/libavcodec/avpacket.c @@ -184,7 +184,7 @@ int av_dup_packet(AVPacket *pkt) return 0; failed_alloc: - av_free_packet(pkt); + av_packet_unref(pkt); return AVERROR(ENOMEM); } @@ -197,6 +197,8 @@ void av_packet_free_side_data(AVPacket *pkt) pkt->side_data_elems = 0; } +#if FF_API_AVPACKET_OLD_API +FF_DISABLE_DEPRECATION_WARNINGS void av_free_packet(AVPacket *pkt) { if (pkt) { @@ -208,6 +210,8 @@ void av_free_packet(AVPacket *pkt) av_packet_free_side_data(pkt); } } +FF_ENABLE_DEPRECATION_WARNINGS +#endif uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size) diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c index 7fb4bde238..1f32928cb3 100644 --- a/libavcodec/jpeglsenc.c +++ b/libavcodec/jpeglsenc.c @@ -406,7 +406,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt, return 0; memfail: - av_free_packet(pkt); + av_packet_unref(pkt); av_freep(&buf2); av_freep(&state); av_freep(&zero); diff --git a/libavcodec/libxvid.c b/libavcodec/libxvid.c index 4b24ca6292..e7473748c1 100644 --- a/libavcodec/libxvid.c +++ b/libavcodec/libxvid.c @@ -811,7 +811,7 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } else { if (!user_packet) - av_free_packet(pkt); + av_packet_unref(pkt); if (!xerr) return 0; av_log(avctx, AV_LOG_ERROR, diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 44c93953c3..ab4fb32bed 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1146,7 +1146,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame) return ret; ret = pkt.size; - av_free_packet(&pkt); + av_packet_unref(&pkt); return ret; } diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 63f09ff15b..ad00a9215a 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1200,7 +1200,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, *got_packet_ptr = 0; if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { - av_free_packet(avpkt); + av_packet_unref(avpkt); av_init_packet(avpkt); return 0; } @@ -1276,7 +1276,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, } if (ret < 0 || !*got_packet_ptr) { - av_free_packet(avpkt); + av_packet_unref(avpkt); av_init_packet(avpkt); goto end; } @@ -1307,7 +1307,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, *got_packet_ptr = 0; if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { - av_free_packet(avpkt); + av_packet_unref(avpkt); av_init_packet(avpkt); avpkt->size = 0; return 0; @@ -1335,7 +1335,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, } if (ret < 0 || !*got_packet_ptr) - av_free_packet(avpkt); + av_packet_unref(avpkt); emms_c(); return ret; diff --git a/libavcodec/version.h b/libavcodec/version.h index 22b0f3df57..bd75525ec6 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #include "libavutil/version.h" #define LIBAVCODEC_VERSION_MAJOR 57 -#define LIBAVCODEC_VERSION_MINOR 7 +#define LIBAVCODEC_VERSION_MINOR 8 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -174,5 +174,8 @@ #ifndef FF_API_AVPICTURE #define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59) #endif +#ifndef FF_API_AVPACKET_OLD_API +#define FF_API_AVPACKET_OLD_API (LIBAVCODEC_VERSION_MAJOR < 59) +#endif #endif /* AVCODEC_VERSION_H */ -- cgit v1.2.3