On Sun, 18 Oct 2015 17:59:48 +0200
Luca Barbato <[email protected]> wrote:
> Pave the way for having the size of the AVPacket struct not part
> of the ABI.
> ---
> libavcodec/avcodec.h | 21 +++++++++++++++++++++
> libavcodec/avpacket.c | 22 ++++++++++++++++++++++
> 2 files changed, 43 insertions(+)
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index a370e3e..ecea1d6 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -3413,6 +3413,27 @@ void avsubtitle_free(AVSubtitle *sub);
> */
>
> /**
> + * Allocate an AVPacket and set its fields to default values. The resulting
> + * struct must be freed using av_packet_free().
> + *
> + * @return An AVPacket filled with default values or NULL on failure.
> + *
> + * @note this only allocates the AVPacket itself, not the data buffers. Those
> + * must be allocated through other means such as av_new_packet.
> + *
> + * @see av_new_packet
> + */
> +AVPacket *av_packet_alloc(void);
> +
> +/**
> + * Free the packet, if the packet is reference counted, it will be
> + * unreferenced first.
> + *
> + * @param packet packet to be freed. The pointer will be set to NULL.
Maybe document that passing NULL (or a pointer to NULL) is ok.
> + */
> +void av_packet_free(AVPacket **pkt);
> +
> +/**
> * Initialize optional fields of a packet with default values.
> *
> * Note, this does not touch the data and size members, which have to be
> diff --git a/libavcodec/avpacket.c b/libavcodec/avpacket.c
> index cec5bf8..d50b9c5 100644
> --- a/libavcodec/avpacket.c
> +++ b/libavcodec/avpacket.c
> @@ -46,6 +46,28 @@ FF_ENABLE_DEPRECATION_WARNINGS
> pkt->side_data_elems = 0;
> }
>
> +AVPacket *av_packet_alloc(void)
> +{
> + AVPacket *pkt = av_mallocz(sizeof(AVPacket));
> + if (!pkt)
> + return pkt;
> +
> + pkt->pts = AV_NOPTS_VALUE;
> + pkt->dts = AV_NOPTS_VALUE;
> + pkt->pos = -1;
Why not use av_packet_unref() to get default init?
> +
> + return pkt;
> +}
> +
> +void av_packet_free(AVPacket **pkt)
> +{
> + if (!pkt || !*pkt)
> + return;
> +
> + av_packet_unref(*pkt);
> + av_freep(pkt);
> +}
> +
> static int packet_alloc(AVBufferRef **buf, int size)
> {
> int ret;
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel