Skip to content

Commit

Permalink
Merge commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457'
Browse files Browse the repository at this point in the history
* commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457':
  avpacket: Replace av_free_packet with av_packet_unref

Merged-by: Hendrik Leppkes <[email protected]>
  • Loading branch information
Nevcairiel committed Oct 27, 2015
2 parents 856b19d + ce70f28 commit 7f5af80
Show file tree
Hide file tree
Showing 73 changed files with 154 additions and 138 deletions.
4 changes: 4 additions & 0 deletions doc/APIchanges
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ libavutil: 2015-08-28

API changes, most recent first:

2015-10-27 - xxxxxxx - lavc 57.12.100 / 57.8.0 - avcodec.h
Deprecate av_free_packet(). Use av_packet_unref() as replacement,
it resets the packet in a more consistent way.

2015-10-22 - xxxxxxx - lavc 57.9.100 / lavc 57.5.0 - avcodec.h
Add data and linesize array to AVSubtitleRect, to be used instead of
the ones from the embedded AVPicture.
Expand Down
6 changes: 3 additions & 3 deletions doc/examples/decoding_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static void audio_encode_example(const char *filename)

if (got_output) {
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
}
fclose(f);
Expand Down Expand Up @@ -454,7 +454,7 @@ static void video_encode_example(const char *filename, int codec_id)
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
}

Expand All @@ -471,7 +471,7 @@ static void video_encode_example(const char *filename, int codec_id)
if (got_output) {
printf("Write frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
}

Expand Down
10 changes: 5 additions & 5 deletions doc/examples/transcode_aac.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ static int decode_audio_frame(AVFrame *frame,
data_present, &input_packet)) < 0) {
fprintf(stderr, "Could not decode frame (error '%s')\n",
get_error_text(error));
av_free_packet(&input_packet);
av_packet_unref(&input_packet);
return error;
}

Expand All @@ -342,7 +342,7 @@ static int decode_audio_frame(AVFrame *frame,
*/
if (*finished && *data_present)
*finished = 0;
av_free_packet(&input_packet);
av_packet_unref(&input_packet);
return 0;
}

Expand Down Expand Up @@ -571,7 +571,7 @@ static int encode_audio_frame(AVFrame *frame,
frame, data_present)) < 0) {
fprintf(stderr, "Could not encode frame (error '%s')\n",
get_error_text(error));
av_free_packet(&output_packet);
av_packet_unref(&output_packet);
return error;
}

Expand All @@ -580,11 +580,11 @@ static int encode_audio_frame(AVFrame *frame,
if ((error = av_write_frame(output_format_context, &output_packet)) < 0) {
fprintf(stderr, "Could not write frame (error '%s')\n",
get_error_text(error));
av_free_packet(&output_packet);
av_packet_unref(&output_packet);
return error;
}

av_free_packet(&output_packet);
av_packet_unref(&output_packet);
}

return 0;
Expand Down
33 changes: 19 additions & 14 deletions libavcodec/avcodec.h
Original file line number Diff line number Diff line change
Expand Up @@ -1367,15 +1367,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 {
/**
Expand Down Expand Up @@ -3899,7 +3903,7 @@ 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
/**
* Copy packet, including contents
*
Expand All @@ -3917,10 +3921,13 @@ int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src);
/**
* 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.
*
Expand Down Expand Up @@ -4563,8 +4570,7 @@ AVCodec *avcodec_find_encoder_by_name(const char *name);
* of the 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.
Expand Down Expand Up @@ -4605,8 +4611,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.
Expand Down
6 changes: 5 additions & 1 deletion libavcodec/avpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int av_copy_packet_side_data(AVPacket *pkt, const AVPacket *src)
return 0;

failed_alloc:
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR(ENOMEM);
}

Expand Down Expand Up @@ -234,6 +234,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) {
Expand All @@ -245,6 +247,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)
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/jpeglsenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,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);
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/libxvid.c
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,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,
Expand Down
2 changes: 1 addition & 1 deletion libavcodec/mpegvideo_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame)
return ret;

ret = pkt.size;
av_free_packet(&pkt);
av_packet_unref(&pkt);
return ret;
}

Expand Down
8 changes: 4 additions & 4 deletions libavcodec/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,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;
}
Expand Down Expand Up @@ -1799,7 +1799,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;
}
Expand Down Expand Up @@ -1839,7 +1839,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avctx->stats_out[0] = '\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;
Expand Down Expand Up @@ -1893,7 +1893,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;
Expand Down
5 changes: 4 additions & 1 deletion libavcodec/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "libavutil/version.h"

#define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 11
#define LIBAVCODEC_VERSION_MINOR 12
#define LIBAVCODEC_VERSION_MICRO 100

#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
Expand Down Expand Up @@ -191,5 +191,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 */
4 changes: 2 additions & 2 deletions libavdevice/alsa_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)

while ((res = snd_pcm_readi(s->h, pkt->data, s->period_size)) < 0) {
if (res == -EAGAIN) {
av_free_packet(pkt);
av_packet_unref(pkt);

return AVERROR(EAGAIN);
}
if (ff_alsa_xrun_recover(s1, res) < 0) {
av_log(s1, AV_LOG_ERROR, "ALSA read error: %s\n",
snd_strerror(res));
av_free_packet(pkt);
av_packet_unref(pkt);

return AVERROR(EIO);
}
Expand Down
2 changes: 1 addition & 1 deletion libavdevice/jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static void free_pkt_fifo(AVFifoBuffer **fifo)
AVPacket pkt;
while (av_fifo_size(*fifo)) {
av_fifo_generic_read(*fifo, &pkt, sizeof(pkt), NULL);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
av_fifo_freep(fifo);
}
Expand Down
2 changes: 1 addition & 1 deletion libavdevice/oss_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)

ret = read(s->fd, pkt->data, pkt->size);
if (ret <= 0){
av_free_packet(pkt);
av_packet_unref(pkt);
pkt->size = 0;
if (ret<0) return AVERROR(errno);
else return AVERROR_EOF;
Expand Down
2 changes: 1 addition & 1 deletion libavdevice/sndio_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)

ret = sio_read(s->hdl, pkt->data, pkt->size);
if (ret == 0 || sio_eof(s->hdl)) {
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR_EOF;
}

Expand Down
2 changes: 1 addition & 1 deletion libavdevice/v4l2.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)

res = enqueue_buffer(s, &buf);
if (res) {
av_free_packet(pkt);
av_packet_unref(pkt);
return res;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion libavdevice/vfwcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static int vfw_read_close(AVFormatContext *s)
pktl = ctx->pktl;
while (pktl) {
AVPacketList *next = pktl->next;
av_free_packet(&pktl->pkt);
av_packet_unref(&pktl->pkt);
av_free(pktl);
pktl = next;
}
Expand Down
2 changes: 1 addition & 1 deletion libavformat/4xm.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static int fourxm_read_packet(AVFormatContext *s,
ret = avio_read(s->pb, &pkt->data[8], size);

if (ret < 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
} else {
packet_read = 1;
av_shrink_packet(pkt, ret + 8);
Expand Down
4 changes: 2 additions & 2 deletions libavformat/adxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = av_get_packet(s->pb, pkt, size);
if (ret != size) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO);
}
if (AV_RB16(pkt->data) & 0x8000) {
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR_EOF;
}
pkt->size = size;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/amr.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt)
read = avio_read(s->pb, pkt->data + 1, size - 1);

if (read != size - 1) {
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR(EIO);
}

Expand Down
Loading

0 comments on commit 7f5af80

Please sign in to comment.