1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Merge commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457'

* commit 'ce70f28a1732c74a9cd7fec2d56178750bd6e457':
  avpacket: Replace av_free_packet with av_packet_unref

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
This commit is contained in:
Hendrik Leppkes 2015-10-27 14:28:56 +01:00
commit 7f5af80ba4
73 changed files with 154 additions and 138 deletions

View File

@ -15,6 +15,10 @@ libavutil: 2015-08-28
API changes, most recent first: 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 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 Add data and linesize array to AVSubtitleRect, to be used instead of
the ones from the embedded AVPicture. the ones from the embedded AVPicture.

View File

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

View File

@ -332,7 +332,7 @@ static int decode_audio_frame(AVFrame *frame,
data_present, &input_packet)) < 0) { data_present, &input_packet)) < 0) {
fprintf(stderr, "Could not decode frame (error '%s')\n", fprintf(stderr, "Could not decode frame (error '%s')\n",
get_error_text(error)); get_error_text(error));
av_free_packet(&input_packet); av_packet_unref(&input_packet);
return error; return error;
} }
@ -342,7 +342,7 @@ static int decode_audio_frame(AVFrame *frame,
*/ */
if (*finished && *data_present) if (*finished && *data_present)
*finished = 0; *finished = 0;
av_free_packet(&input_packet); av_packet_unref(&input_packet);
return 0; return 0;
} }
@ -571,7 +571,7 @@ static int encode_audio_frame(AVFrame *frame,
frame, data_present)) < 0) { frame, data_present)) < 0) {
fprintf(stderr, "Could not encode frame (error '%s')\n", fprintf(stderr, "Could not encode frame (error '%s')\n",
get_error_text(error)); get_error_text(error));
av_free_packet(&output_packet); av_packet_unref(&output_packet);
return error; return error;
} }
@ -580,11 +580,11 @@ static int encode_audio_frame(AVFrame *frame,
if ((error = av_write_frame(output_format_context, &output_packet)) < 0) { if ((error = av_write_frame(output_format_context, &output_packet)) < 0) {
fprintf(stderr, "Could not write frame (error '%s')\n", fprintf(stderr, "Could not write frame (error '%s')\n",
get_error_text(error)); get_error_text(error));
av_free_packet(&output_packet); av_packet_unref(&output_packet);
return error; return error;
} }
av_free_packet(&output_packet); av_packet_unref(&output_packet);
} }
return 0; return 0;

View File

@ -1367,15 +1367,19 @@ typedef struct AVPacketSideData {
* ABI. Thus it may be allocated on stack and no new fields can be added to it * ABI. Thus it may be allocated on stack and no new fields can be added to it
* without libavcodec and libavformat major bump. * without libavcodec and libavformat major bump.
* *
* The semantics of data ownership depends on the buf or destruct (deprecated) * The semantics of data ownership depends on the buf field.
* fields. If either is set, the packet data is dynamically allocated and is * If it is set, the packet data is dynamically allocated and is
* valid indefinitely until av_free_packet() is called (which in turn calls * valid indefinitely until a call to av_packet_unref() reduces the
* av_buffer_unref()/the destruct callback to free the data). If neither is set, * reference count to 0.
* 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 side data is always allocated with av_malloc() and is freed in * If the buf field is not set av_packet_ref() would make a copy instead
* av_free_packet(). * 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 { typedef struct AVPacket {
/** /**
@ -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. * packet is allocated if it was not really allocated.
*/ */
int av_dup_packet(AVPacket *pkt); int av_dup_packet(AVPacket *pkt);
#if FF_API_AVPACKET_OLD_API
/** /**
* Copy packet, including contents * Copy packet, including contents
* *
@ -3917,10 +3921,13 @@ int av_copy_packet_side_data(AVPacket *dst, const AVPacket *src);
/** /**
* Free a packet. * Free a packet.
* *
* @deprecated Use av_packet_unref
*
* @param pkt packet to free * @param pkt packet to free
*/ */
attribute_deprecated
void av_free_packet(AVPacket *pkt); void av_free_packet(AVPacket *pkt);
#endif
/** /**
* Allocate new information of a packet. * Allocate new information of a packet.
* *
@ -4563,8 +4570,7 @@ AVCodec *avcodec_find_encoder_by_name(const char *name);
* of the output packet. * of the output packet.
* *
* If this function fails or produces no output, avpkt will be * If this function fails or produces no output, avpkt will be
* freed using av_free_packet() (i.e. avpkt->destruct will be * freed using av_packet_unref().
* called to free the user supplied buffer).
* @param[in] frame AVFrame containing the raw audio data to be encoded. * @param[in] frame AVFrame containing the raw audio data to be encoded.
* May be NULL when flushing an encoder that has the * May be NULL when flushing an encoder that has the
* AV_CODEC_CAP_DELAY capability set. * AV_CODEC_CAP_DELAY capability set.
@ -4605,8 +4611,7 @@ int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt,
* caller, he is responsible for freeing it. * caller, he is responsible for freeing it.
* *
* If this function fails or produces no output, avpkt will be * If this function fails or produces no output, avpkt will be
* freed using av_free_packet() (i.e. avpkt->destruct will be * freed using av_packet_unref().
* called to free the user supplied buffer).
* @param[in] frame AVFrame containing the raw video data to be encoded. * @param[in] frame AVFrame containing the raw video data to be encoded.
* May be NULL when flushing an encoder that has the * May be NULL when flushing an encoder that has the
* AV_CODEC_CAP_DELAY capability set. * AV_CODEC_CAP_DELAY capability set.

View File

@ -204,7 +204,7 @@ int av_copy_packet_side_data(AVPacket *pkt, const AVPacket *src)
return 0; return 0;
failed_alloc: failed_alloc:
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
@ -234,6 +234,8 @@ void av_packet_free_side_data(AVPacket *pkt)
pkt->side_data_elems = 0; pkt->side_data_elems = 0;
} }
#if FF_API_AVPACKET_OLD_API
FF_DISABLE_DEPRECATION_WARNINGS
void av_free_packet(AVPacket *pkt) void av_free_packet(AVPacket *pkt)
{ {
if (pkt) { if (pkt) {
@ -245,6 +247,8 @@ void av_free_packet(AVPacket *pkt)
av_packet_free_side_data(pkt); av_packet_free_side_data(pkt);
} }
} }
FF_ENABLE_DEPRECATION_WARNINGS
#endif
uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type,
int size) int size)

View File

@ -405,7 +405,7 @@ static int encode_picture_ls(AVCodecContext *avctx, AVPacket *pkt,
return 0; return 0;
memfail: memfail:
av_free_packet(pkt); av_packet_unref(pkt);
av_freep(&buf2); av_freep(&buf2);
av_freep(&state); av_freep(&state);
av_freep(&zero); av_freep(&zero);

View File

@ -841,7 +841,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
return 0; return 0;
} else { } else {
if (!user_packet) if (!user_packet)
av_free_packet(pkt); av_packet_unref(pkt);
if (!xerr) if (!xerr)
return 0; return 0;
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,

View File

@ -1320,7 +1320,7 @@ static int encode_frame(AVCodecContext *c, AVFrame *frame)
return ret; return ret;
ret = pkt.size; ret = pkt.size;
av_free_packet(&pkt); av_packet_unref(&pkt);
return ret; return ret;
} }

View File

@ -1693,7 +1693,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
*got_packet_ptr = 0; *got_packet_ptr = 0;
if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
av_free_packet(avpkt); av_packet_unref(avpkt);
av_init_packet(avpkt); av_init_packet(avpkt);
return 0; return 0;
} }
@ -1799,7 +1799,7 @@ int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
} }
if (ret < 0 || !*got_packet_ptr) { if (ret < 0 || !*got_packet_ptr) {
av_free_packet(avpkt); av_packet_unref(avpkt);
av_init_packet(avpkt); av_init_packet(avpkt);
goto end; goto end;
} }
@ -1839,7 +1839,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
avctx->stats_out[0] = '\0'; avctx->stats_out[0] = '\0';
if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) { if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
av_free_packet(avpkt); av_packet_unref(avpkt);
av_init_packet(avpkt); av_init_packet(avpkt);
avpkt->size = 0; avpkt->size = 0;
return 0; return 0;
@ -1893,7 +1893,7 @@ int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
} }
if (ret < 0 || !*got_packet_ptr) if (ret < 0 || !*got_packet_ptr)
av_free_packet(avpkt); av_packet_unref(avpkt);
emms_c(); emms_c();
return ret; return ret;

View File

@ -29,7 +29,7 @@
#include "libavutil/version.h" #include "libavutil/version.h"
#define LIBAVCODEC_VERSION_MAJOR 57 #define LIBAVCODEC_VERSION_MAJOR 57
#define LIBAVCODEC_VERSION_MINOR 11 #define LIBAVCODEC_VERSION_MINOR 12
#define LIBAVCODEC_VERSION_MICRO 100 #define LIBAVCODEC_VERSION_MICRO 100
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@ -191,5 +191,8 @@
#ifndef FF_API_AVPICTURE #ifndef FF_API_AVPICTURE
#define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59) #define FF_API_AVPICTURE (LIBAVCODEC_VERSION_MAJOR < 59)
#endif #endif
#ifndef FF_API_AVPACKET_OLD_API
#define FF_API_AVPACKET_OLD_API (LIBAVCODEC_VERSION_MAJOR < 59)
#endif
#endif /* AVCODEC_VERSION_H */ #endif /* AVCODEC_VERSION_H */

View File

@ -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) { while ((res = snd_pcm_readi(s->h, pkt->data, s->period_size)) < 0) {
if (res == -EAGAIN) { if (res == -EAGAIN) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EAGAIN); return AVERROR(EAGAIN);
} }
if (ff_alsa_xrun_recover(s1, res) < 0) { if (ff_alsa_xrun_recover(s1, res) < 0) {
av_log(s1, AV_LOG_ERROR, "ALSA read error: %s\n", av_log(s1, AV_LOG_ERROR, "ALSA read error: %s\n",
snd_strerror(res)); snd_strerror(res));
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -218,7 +218,7 @@ static void free_pkt_fifo(AVFifoBuffer **fifo)
AVPacket pkt; AVPacket pkt;
while (av_fifo_size(*fifo)) { while (av_fifo_size(*fifo)) {
av_fifo_generic_read(*fifo, &pkt, sizeof(pkt), NULL); av_fifo_generic_read(*fifo, &pkt, sizeof(pkt), NULL);
av_free_packet(&pkt); av_packet_unref(&pkt);
} }
av_fifo_freep(fifo); av_fifo_freep(fifo);
} }

View File

@ -84,7 +84,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
ret = read(s->fd, pkt->data, pkt->size); ret = read(s->fd, pkt->data, pkt->size);
if (ret <= 0){ if (ret <= 0){
av_free_packet(pkt); av_packet_unref(pkt);
pkt->size = 0; pkt->size = 0;
if (ret<0) return AVERROR(errno); if (ret<0) return AVERROR(errno);
else return AVERROR_EOF; else return AVERROR_EOF;

View File

@ -67,7 +67,7 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
ret = sio_read(s->hdl, pkt->data, pkt->size); ret = sio_read(s->hdl, pkt->data, pkt->size);
if (ret == 0 || sio_eof(s->hdl)) { if (ret == 0 || sio_eof(s->hdl)) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR_EOF; return AVERROR_EOF;
} }

View File

@ -550,7 +550,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
res = enqueue_buffer(s, &buf); res = enqueue_buffer(s, &buf);
if (res) { if (res) {
av_free_packet(pkt); av_packet_unref(pkt);
return res; return res;
} }
} else { } else {

View File

@ -234,7 +234,7 @@ static int vfw_read_close(AVFormatContext *s)
pktl = ctx->pktl; pktl = ctx->pktl;
while (pktl) { while (pktl) {
AVPacketList *next = pktl->next; AVPacketList *next = pktl->next;
av_free_packet(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_free(pktl); av_free(pktl);
pktl = next; pktl = next;
} }

View File

@ -321,7 +321,7 @@ static int fourxm_read_packet(AVFormatContext *s,
ret = avio_read(s->pb, &pkt->data[8], size); ret = avio_read(s->pb, &pkt->data[8], size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
} else { } else {
packet_read = 1; packet_read = 1;
av_shrink_packet(pkt, ret + 8); av_shrink_packet(pkt, ret + 8);

View File

@ -52,11 +52,11 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, size); ret = av_get_packet(s->pb, pkt, size);
if (ret != size) { if (ret != size) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO); return ret < 0 ? ret : AVERROR(EIO);
} }
if (AV_RB16(pkt->data) & 0x8000) { if (AV_RB16(pkt->data) & 0x8000) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR_EOF; return AVERROR_EOF;
} }
pkt->size = size; pkt->size = size;

View File

@ -155,7 +155,7 @@ static int amr_read_packet(AVFormatContext *s, AVPacket *pkt)
read = avio_read(s->pb, pkt->data + 1, size - 1); read = avio_read(s->pb, pkt->data + 1, size - 1);
if (read != size - 1) { if (read != size - 1) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -444,7 +444,7 @@ static int asf_read_picture(AVFormatContext *s, int len)
fail: fail:
av_freep(&desc); av_freep(&desc);
av_free_packet(&pkt); av_packet_unref(&pkt);
return ret; return ret;
} }
@ -1128,7 +1128,7 @@ static void reset_packet(ASFPacket *asf_pkt)
asf_pkt->flags = 0; asf_pkt->flags = 0;
asf_pkt->dts = 0; asf_pkt->dts = 0;
asf_pkt->duration = 0; asf_pkt->duration = 0;
av_free_packet(&asf_pkt->avpkt); av_packet_unref(&asf_pkt->avpkt);
av_init_packet(&asf_pkt->avpkt); av_init_packet(&asf_pkt->avpkt);
} }
@ -1395,7 +1395,7 @@ static int asf_deinterleave(AVFormatContext *s, ASFPacket *asf_pkt, int st_num)
if (p > asf_pkt->avpkt.data + asf_pkt->data_size) if (p > asf_pkt->avpkt.data + asf_pkt->data_size)
break; break;
} }
av_free_packet(&asf_pkt->avpkt); av_packet_unref(&asf_pkt->avpkt);
asf_pkt->avpkt = pkt; asf_pkt->avpkt = pkt;
return 0; return 0;
@ -1485,7 +1485,7 @@ static int asf_read_close(AVFormatContext *s)
for (i = 0; i < ASF_MAX_STREAMS; i++) { for (i = 0; i < ASF_MAX_STREAMS; i++) {
av_dict_free(&asf->asf_sd[i].asf_met); av_dict_free(&asf->asf_sd[i].asf_met);
if (i < asf->nb_streams) { if (i < asf->nb_streams) {
av_free_packet(&asf->asf_st[i]->pkt.avpkt); av_packet_unref(&asf->asf_st[i]->pkt.avpkt);
av_freep(&asf->asf_st[i]); av_freep(&asf->asf_st[i]);
} }
} }
@ -1521,7 +1521,7 @@ static void reset_packet_state(AVFormatContext *s)
pkt->flags = 0; pkt->flags = 0;
pkt->dts = 0; pkt->dts = 0;
pkt->duration = 0; pkt->duration = 0;
av_free_packet(&pkt->avpkt); av_packet_unref(&pkt->avpkt);
av_init_packet(&pkt->avpkt); av_init_packet(&pkt->avpkt);
} }
} }
@ -1588,11 +1588,11 @@ static int64_t asf_read_timestamp(AVFormatContext *s, int stream_index,
} }
if (st_found) if (st_found)
break; break;
av_free_packet(&pkt); av_packet_unref(&pkt);
} }
*pos = pkt_pos; *pos = pkt_pos;
av_free_packet(&pkt); av_packet_unref(&pkt);
return dts; return dts;
} }

View File

@ -165,7 +165,7 @@
* until the next av_read_frame() call or closing the file. If the caller * until the next av_read_frame() call or closing the file. If the caller
* requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy * requires a longer lifetime, av_dup_packet() will make an av_malloc()ed copy
* of it. * of it.
* In both cases, the packet must be freed with av_free_packet() when it is no * In both cases, the packet must be freed with av_packet_unref() when it is no
* longer needed. * longer needed.
* *
* @section lavf_decoding_seek Seeking * @section lavf_decoding_seek Seeking
@ -2138,7 +2138,7 @@ int av_find_best_stream(AVFormatContext *ic,
* If pkt->buf is NULL, then the packet is valid until the next * If pkt->buf is NULL, then the packet is valid until the next
* av_read_frame() or until avformat_close_input(). Otherwise the packet * av_read_frame() or until avformat_close_input(). Otherwise the packet
* is valid indefinitely. In both cases the packet must be freed with * is valid indefinitely. In both cases the packet must be freed with
* av_free_packet when it is no longer needed. For video, the packet contains * av_packet_unref when it is no longer needed. For video, the packet contains
* exactly one frame. For audio, it contains an integer number of frames if each * exactly one frame. For audio, it contains an integer number of frames if each
* frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames * frame has a known fixed size (e.g. PCM or ADPCM data). If the audio frames
* have a variable size (e.g. MPEG audio), then it contains one frame. * have a variable size (e.g. MPEG audio), then it contains one frame.

View File

@ -1431,7 +1431,7 @@ resync:
pkt->buf = avbuf; pkt->buf = avbuf;
pkt->flags |= AV_PKT_FLAG_KEY; pkt->flags |= AV_PKT_FLAG_KEY;
if (size < 0) if (size < 0)
av_free_packet(pkt); av_packet_unref(pkt);
} else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE && } else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE &&
!st->codec->codec_tag && read_gab2_sub(s, st, pkt)) { !st->codec->codec_tag && read_gab2_sub(s, st, pkt)) {
ast->frame_offset++; ast->frame_offset++;
@ -1750,7 +1750,7 @@ static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
{ {
AVIStream *ast2 = st2->priv_data; AVIStream *ast2 = st2->priv_data;
int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base); int64_t ts2 = av_rescale_q(timestamp, st->time_base, st2->time_base);
av_free_packet(&ast2->sub_pkt); av_packet_unref(&ast2->sub_pkt);
if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 || if (avformat_seek_file(ast2->sub_ctx, 0, INT64_MIN, ts2, ts2, 0) >= 0 ||
avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0) avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt); ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
@ -1888,7 +1888,7 @@ static int avi_read_close(AVFormatContext *s)
avformat_close_input(&ast->sub_ctx); avformat_close_input(&ast->sub_ctx);
} }
av_freep(&ast->sub_buffer); av_freep(&ast->sub_buffer);
av_free_packet(&ast->sub_pkt); av_packet_unref(&ast->sub_pkt);
} }
} }

View File

@ -108,7 +108,7 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt,
pkt->data[palette_size + 3] = (size >> 8) & 0xFF; pkt->data[palette_size + 3] = (size >> 8) & 0xFF;
ret = avio_read(s->pb, pkt->data + palette_size + 4, size - 4) + 4; ret = avio_read(s->pb, pkt->data + palette_size + 4, size - 4) + 4;
if (ret < size) { if (ret < size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -188,7 +188,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
return 0; return 0;
fail: fail:
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }

View File

@ -63,7 +63,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE); ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND) if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
break; break;
av_free_packet(pkt); av_packet_unref(pkt);
} }
if (!priv->got_first_packet) { if (!priv->got_first_packet) {

View File

@ -202,7 +202,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE); memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE);
ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size); ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret); av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret);

View File

@ -93,7 +93,7 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!first) { if (!first) {
ret = av_append_packet(pb, pkt, 12); ret = av_append_packet(pb, pkt, 12);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
} else } else
@ -114,7 +114,7 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
} }
ret = av_append_packet(pb, pkt, frame_size); ret = av_append_packet(pb, pkt, frame_size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
} }

View File

@ -200,7 +200,7 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(pb, &pkt->data[4], pkt_size); ret = avio_read(pb, &pkt->data[4], pkt_size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
if (ret < pkt_size) if (ret < pkt_size)

View File

@ -267,7 +267,7 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
return pkt->size; return pkt->size;
error_eof: error_eof:
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF; return ret < 0 ? ret : AVERROR_EOF;
} }
@ -309,7 +309,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data + offset, ret = avio_read(s->pb, pkt->data + offset,
size2 - offset); size2 - offset);
if (ret < size2 - offset) { if (ret < size2 - offset) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF; return ret < 0 ? ret : AVERROR_EOF;
} }
@ -319,7 +319,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data + offset, size - offset); ret = avio_read(s->pb, pkt->data + offset, size - offset);
if (ret < size - offset) { if (ret < size - offset) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF; return ret < 0 ? ret : AVERROR_EOF;
} }

View File

@ -207,7 +207,7 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE); memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE);
ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size);
if(ret != size){ if(ret != size){
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }
if(pal_size) memcpy(pkt->data, pal, pal_size); if(pal_size) memcpy(pkt->data, pal, pal_size);

View File

@ -632,7 +632,7 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt)
case AV_CODEC_ID_ADPCM_EA_R3: case AV_CODEC_ID_ADPCM_EA_R3:
if (pkt->size < 4) { if (pkt->size < 4) {
av_log(s, AV_LOG_ERROR, "Packet is too short\n"); av_log(s, AV_LOG_ERROR, "Packet is too short\n");
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3) if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3)

View File

@ -227,7 +227,7 @@ static int flic_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE, ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE,
size - FLIC_PREAMBLE_SIZE); size - FLIC_PREAMBLE_SIZE);
if (ret != size - FLIC_PREAMBLE_SIZE) { if (ret != size - FLIC_PREAMBLE_SIZE) {
av_free_packet(pkt); av_packet_unref(pkt);
ret = AVERROR(EIO); ret = AVERROR(EIO);
} }
packet_read = 1; packet_read = 1;
@ -245,7 +245,7 @@ static int flic_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data, size); ret = avio_read(pb, pkt->data, size);
if (ret != size) { if (ret != size) {
av_free_packet(pkt); av_packet_unref(pkt);
ret = AVERROR(EIO); ret = AVERROR(EIO);
} }

View File

@ -69,7 +69,7 @@ static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data + 1, size - 1); ret = avio_read(s->pb, pkt->data + 1, size - 1);
if (ret < size - 1) { if (ret < size - 1) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF; return ret < 0 ? ret : AVERROR_EOF;
} }

View File

@ -45,7 +45,7 @@ static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, size); ret = av_get_packet(s->pb, pkt, size);
if (ret < GSM_BLOCK_SIZE) { if (ret < GSM_BLOCK_SIZE) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO); return ret < 0 ? ret : AVERROR(EIO);
} }
pkt->duration = 1; pkt->duration = 1;

View File

@ -243,7 +243,7 @@ static void free_playlist_list(HLSContext *c)
av_dict_free(&pls->id3_initial); av_dict_free(&pls->id3_initial);
ff_id3v2_free_extra_meta(&pls->id3_deferred_extra); ff_id3v2_free_extra_meta(&pls->id3_deferred_extra);
av_freep(&pls->init_sec_buf); av_freep(&pls->init_sec_buf);
av_free_packet(&pls->pkt); av_packet_unref(&pls->pkt);
av_freep(&pls->pb.buffer); av_freep(&pls->pb.buffer);
if (pls->input) if (pls->input)
ffurl_close(pls->input); ffurl_close(pls->input);
@ -1824,7 +1824,7 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
break; break;
} }
} }
av_free_packet(&pls->pkt); av_packet_unref(&pls->pkt);
reset_packet(&pls->pkt); reset_packet(&pls->pkt);
} }
} }
@ -1926,7 +1926,7 @@ static int hls_read_seek(AVFormatContext *s, int stream_index,
ffurl_close(pls->input); ffurl_close(pls->input);
pls->input = NULL; pls->input = NULL;
} }
av_free_packet(&pls->pkt); av_packet_unref(&pls->pkt);
reset_packet(&pls->pkt); reset_packet(&pls->pkt);
pls->pb.eof_reached = 0; pls->pb.eof_reached = 0;
/* Clear any buffered data */ /* Clear any buffered data */

View File

@ -190,7 +190,7 @@ static int hnm_read_close(AVFormatContext *s)
Hnm4DemuxContext *hnm = s->priv_data; Hnm4DemuxContext *hnm = s->priv_data;
if (hnm->vpkt.size > 0) if (hnm->vpkt.size > 0)
av_free_packet(&hnm->vpkt); av_packet_unref(&hnm->vpkt);
return 0; return 0;
} }

View File

@ -313,7 +313,7 @@ static int idcin_read_packet(AVFormatContext *s,
return ret; return ret;
else if (ret != chunk_size) { else if (ret != chunk_size) {
av_log(s, AV_LOG_ERROR, "incomplete packet\n"); av_log(s, AV_LOG_ERROR, "incomplete packet\n");
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }
if (command == 1) { if (command == 1) {
@ -322,7 +322,7 @@ static int idcin_read_packet(AVFormatContext *s,
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
AVPALETTE_SIZE); AVPALETTE_SIZE);
if (!pal) { if (!pal) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
memcpy(pal, palette, AVPALETTE_SIZE); memcpy(pal, palette, AVPALETTE_SIZE);

View File

@ -112,7 +112,7 @@ static int ilbc_read_packet(AVFormatContext *s,
pkt->pos = avio_tell(s->pb); pkt->pos = avio_tell(s->pb);
pkt->duration = enc->block_align == 38 ? 160 : 240; pkt->duration = enc->block_align == 38 ? 160 : 240;
if ((ret = avio_read(s->pb, pkt->data, enc->block_align)) != enc->block_align) { if ((ret = avio_read(s->pb, pkt->data, enc->block_align)) != enc->block_align) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO); return ret < 0 ? ret : AVERROR(EIO);
} }

View File

@ -487,7 +487,7 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
} }
if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) { if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
if (ret[0] < 0) { if (ret[0] < 0) {
res = ret[0]; res = ret[0];
} else if (ret[1] < 0) { } else if (ret[1] < 0) {

View File

@ -376,7 +376,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
* Interleave a packet per dts in an output media file. * Interleave a packet per dts in an output media file.
* *
* Packets with pkt->destruct == av_destruct_packet will be freed inside this * Packets with pkt->destruct == av_destruct_packet will be freed inside this
* function, so they cannot be used after it. Note that calling av_free_packet() * function, so they cannot be used after it. Note that calling av_packet_unref()
* on them is still safe. * on them is still safe.
* *
* @param s media file handle * @param s media file handle

View File

@ -180,7 +180,7 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,
if (avio_read(pb, pkt->data, s->decode_map_chunk_size) != if (avio_read(pb, pkt->data, s->decode_map_chunk_size) !=
s->decode_map_chunk_size) { s->decode_map_chunk_size) {
av_free_packet(pkt); av_packet_unref(pkt);
return CHUNK_EOF; return CHUNK_EOF;
} }
@ -189,7 +189,7 @@ static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb,
if (avio_read(pb, pkt->data + s->decode_map_chunk_size, if (avio_read(pb, pkt->data + s->decode_map_chunk_size,
s->video_chunk_size) != s->video_chunk_size) { s->video_chunk_size) != s->video_chunk_size) {
av_free_packet(pkt); av_packet_unref(pkt);
return CHUNK_EOF; return CHUNK_EOF;
} }

View File

@ -92,7 +92,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_append_packet(s->pb, pkt, size); ret = av_append_packet(s->pb, pkt, size);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, "failed to grow packet\n"); av_log(s, AV_LOG_ERROR, "failed to grow packet\n");
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
} }

View File

@ -317,7 +317,7 @@ static int lxf_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret2; return ret2;
if ((ret2 = avio_read(pb, pkt->data, ret)) != ret) { if ((ret2 = avio_read(pb, pkt->data, ret)) != ret) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret2 < 0 ? ret2 : AVERROR_EOF; return ret2 < 0 ? ret2 : AVERROR_EOF;
} }

View File

@ -2292,7 +2292,7 @@ static void matroska_clear_queue(MatroskaDemuxContext *matroska)
if (matroska->packets) { if (matroska->packets) {
int n; int n;
for (n = 0; n < matroska->num_packets; n++) { for (n = 0; n < matroska->num_packets; n++) {
av_free_packet(matroska->packets[n]); av_packet_unref(matroska->packets[n]);
av_freep(&matroska->packets[n]); av_freep(&matroska->packets[n]);
} }
av_freep(&matroska->packets); av_freep(&matroska->packets);

View File

@ -1934,7 +1934,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt)
// for DASH audio, a CuePoint has to be added when there is a new cluster. // for DASH audio, a CuePoint has to be added when there is a new cluster.
ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt,
mkv->is_dash ? start_new_cluster : 0); mkv->is_dash ? start_new_cluster : 0);
av_free_packet(&mkv->cur_audio_pkt); av_packet_unref(&mkv->cur_audio_pkt);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Could not write cached audio packet ret:%d\n", ret); "Could not write cached audio packet ret:%d\n", ret);
@ -1993,7 +1993,7 @@ static int mkv_write_trailer(AVFormatContext *s)
// check if we have an audio packet cached // check if we have an audio packet cached
if (mkv->cur_audio_pkt.size > 0) { if (mkv->cur_audio_pkt.size > 0) {
ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, 0); ret = mkv_write_packet_internal(s, &mkv->cur_audio_pkt, 0);
av_free_packet(&mkv->cur_audio_pkt); av_packet_unref(&mkv->cur_audio_pkt);
if (ret < 0) { if (ret < 0) {
av_log(s, AV_LOG_ERROR, av_log(s, AV_LOG_ERROR,
"Could not write cached audio packet ret:%d\n", ret); "Could not write cached audio packet ret:%d\n", ret);

View File

@ -365,7 +365,7 @@ static int mp3_queue_flush(AVFormatContext *s)
while ((pktl = mp3->queue)) { while ((pktl = mp3->queue)) {
if (write && (ret = mp3_write_audio_packet(s, &pktl->pkt)) < 0) if (write && (ret = mp3_write_audio_packet(s, &pktl->pkt)) < 0)
write = 0; write = 0;
av_free_packet(&pktl->pkt); av_packet_unref(&pktl->pkt);
mp3->queue = pktl->next; mp3->queue = pktl->next;
av_freep(&pktl); av_freep(&pktl);
} }

View File

@ -166,7 +166,7 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
if(c->curbits) if(c->curbits)
avio_seek(s->pb, -4, SEEK_CUR); avio_seek(s->pb, -4, SEEK_CUR);
if(ret < size){ if(ret < size){
av_free_packet(pkt); av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO); return ret < 0 ? ret : AVERROR(EIO);
} }
pkt->size = ret + 4; pkt->size = ret + 4;
@ -217,7 +217,7 @@ static int mpc_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
c->curframe = lastframe; c->curframe = lastframe;
return ret; return ret;
} }
av_free_packet(pkt); av_packet_unref(pkt);
} }
return 0; return 0;
} }

View File

@ -2611,7 +2611,7 @@ static int mpegts_raw_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = read_packet(s, pkt->data, ts->raw_packet_size, &data); ret = read_packet(s, pkt->data, ts->raw_packet_size, &data);
pkt->pos = avio_tell(s->pb); pkt->pos = avio_tell(s->pb);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
if (data != pkt->data) if (data != pkt->data)

View File

@ -923,7 +923,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
if (s->oformat->interleave_packet) { if (s->oformat->interleave_packet) {
int ret = s->oformat->interleave_packet(s, out, in, flush); int ret = s->oformat->interleave_packet(s, out, in, flush);
if (in) if (in)
av_free_packet(in); av_packet_unref(in);
return ret; return ret;
} else } else
return ff_interleave_packet_per_dts(s, out, in, flush); return ff_interleave_packet_per_dts(s, out, in, flush);
@ -971,7 +971,7 @@ int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
if (ret >= 0) if (ret >= 0)
s->streams[opkt.stream_index]->nb_frames++; s->streams[opkt.stream_index]->nb_frames++;
av_free_packet(&opkt); av_packet_unref(&opkt);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -999,7 +999,7 @@ int av_write_trailer(AVFormatContext *s)
if (ret >= 0) if (ret >= 0)
s->streams[pkt.stream_index]->nb_frames++; s->streams[pkt.stream_index]->nb_frames++;
av_free_packet(&pkt); av_packet_unref(&pkt);
if (ret < 0) if (ret < 0)
goto fail; goto fail;

View File

@ -2589,7 +2589,7 @@ static int mxf_interleave_get_packet(AVFormatContext *s, AVPacket *out, AVPacket
if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl) if(s->streams[pktl->pkt.stream_index]->last_in_packet_buffer == pktl)
s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL; s->streams[pktl->pkt.stream_index]->last_in_packet_buffer= NULL;
av_free_packet(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_freep(&pktl); av_freep(&pktl);
pktl = next; pktl = next;
} }

View File

@ -83,7 +83,7 @@ static int nc_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, size); ret = av_get_packet(s->pb, pkt, size);
if (ret != size) { if (ret != size) {
if (ret > 0) av_free_packet(pkt); if (ret > 0) av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -713,9 +713,9 @@ static int nsv_read_close(AVFormatContext *s)
av_freep(&nsv->nsvs_file_offset); av_freep(&nsv->nsvs_file_offset);
av_freep(&nsv->nsvs_timestamps); av_freep(&nsv->nsvs_timestamps);
if (nsv->ahead[0].data) if (nsv->ahead[0].data)
av_free_packet(&nsv->ahead[0]); av_packet_unref(&nsv->ahead[0]);
if (nsv->ahead[1].data) if (nsv->ahead[1].data)
av_free_packet(&nsv->ahead[1]); av_packet_unref(&nsv->ahead[1]);
return 0; return 0;
} }

View File

@ -275,7 +275,7 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data, hdr, copyhdrsize); memcpy(pkt->data, hdr, copyhdrsize);
ret = avio_read(pb, pkt->data + copyhdrsize, size); ret = avio_read(pb, pkt->data + copyhdrsize, size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
if (ret < size) if (ret < size)

View File

@ -218,7 +218,7 @@ static int str_read_packet(AVFormatContext *s,
if(pkt->size != sector_count*VIDEO_DATA_CHUNK_SIZE){ if(pkt->size != sector_count*VIDEO_DATA_CHUNK_SIZE){
if(pkt->data) if(pkt->data)
av_log(s, AV_LOG_ERROR, "missmatching sector_count\n"); av_log(s, AV_LOG_ERROR, "missmatching sector_count\n");
av_free_packet(pkt); av_packet_unref(pkt);
if (av_new_packet(pkt, sector_count*VIDEO_DATA_CHUNK_SIZE)) if (av_new_packet(pkt, sector_count*VIDEO_DATA_CHUNK_SIZE))
return AVERROR(EIO); return AVERROR(EIO);
memset(pkt->data, 0, sector_count*VIDEO_DATA_CHUNK_SIZE); memset(pkt->data, 0, sector_count*VIDEO_DATA_CHUNK_SIZE);
@ -298,7 +298,7 @@ static int str_read_close(AVFormatContext *s)
int i; int i;
for(i=0; i<32; i++){ for(i=0; i<32; i++){
if(str->channels[i].tmp_pkt.data) if(str->channels[i].tmp_pkt.data)
av_free_packet(&str->channels[i].tmp_pkt); av_packet_unref(&str->channels[i].tmp_pkt);
} }
return 0; return 0;

View File

@ -45,7 +45,7 @@ int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
pkt->stream_index = 0; pkt->stream_index = 0;
ret = ffio_read_partial(s->pb, pkt->data, size); ret = ffio_read_partial(s->pb, pkt->data, size);
if (ret < 0) { if (ret < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
av_shrink_packet(pkt, ret); av_shrink_packet(pkt, ret);

View File

@ -240,7 +240,7 @@ static int rl2_read_packet(AVFormatContext *s,
/** fill the packet */ /** fill the packet */
ret = av_get_packet(pb, pkt, sample->size); ret = av_get_packet(pb, pkt, sample->size);
if(ret != sample->size){ if(ret != sample->size){
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -120,7 +120,7 @@ RMStream *ff_rm_alloc_rmstream (void)
void ff_rm_free_rmstream (RMStream *rms) void ff_rm_free_rmstream (RMStream *rms)
{ {
av_free_packet(&rms->pkt); av_packet_unref(&rms->pkt);
} }
static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
@ -799,7 +799,7 @@ static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb,
} }
vst->slices = ((hdr & 0x3F) << 1) + 1; vst->slices = ((hdr & 0x3F) << 1) + 1;
vst->videobufsize = len2 + 8*vst->slices + 1; vst->videobufsize = len2 + 8*vst->slices + 1;
av_free_packet(&vst->pkt); //FIXME this should be output. av_packet_unref(&vst->pkt); //FIXME this should be output.
if(av_new_packet(&vst->pkt, vst->videobufsize) < 0) if(av_new_packet(&vst->pkt, vst->videobufsize) < 0)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
memset(vst->pkt.data, 0, vst->pkt.size); memset(vst->pkt.data, 0, vst->pkt.size);
@ -1047,7 +1047,7 @@ static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
if( (st->discard >= AVDISCARD_NONKEY && !(flags&2)) if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
|| st->discard >= AVDISCARD_ALL){ || st->discard >= AVDISCARD_ALL){
av_free_packet(pkt); av_packet_unref(pkt);
} else } else
break; break;
} }

View File

@ -311,7 +311,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret != frame_size) { if (ret != frame_size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }
pkt->duration = 1; pkt->duration = 1;
@ -328,7 +328,7 @@ static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret != index_entry->size) { if (ret != index_entry->size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -289,7 +289,7 @@ static int asfrtp_parse_packet(AVFormatContext *s, PayloadContext *asf,
return 1; // FIXME: return 0 if last packet return 1; // FIXME: return 0 if last packet
} }
} }
av_free_packet(pkt); av_packet_unref(pkt);
} }
return res == 1 ? -1 : res; return res == 1 ? -1 : res;

View File

@ -136,7 +136,7 @@ static int mpa_robust_parse_packet(AVFormatContext *ctx, PayloadContext *data,
data->split_pos = 0; data->split_pos = 0;
if (!data->split_buf) { if (!data->split_buf) {
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n"); av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
memcpy(data->split_buf, buf, data->split_buf_size); memcpy(data->split_buf, buf, data->split_buf_size);

View File

@ -217,7 +217,7 @@ static int qt_rtp_parse_packet(AVFormatContext *s, PayloadContext *qt,
av_freep(&qt->pkt.data); av_freep(&qt->pkt.data);
qt->pkt.data = av_realloc(NULL, qt->remaining * qt->bytes_per_frame); qt->pkt.data = av_realloc(NULL, qt->remaining * qt->bytes_per_frame);
if (!qt->pkt.data) { if (!qt->pkt.data) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
qt->pkt.size = qt->remaining * qt->bytes_per_frame; qt->pkt.size = qt->remaining * qt->bytes_per_frame;

View File

@ -141,7 +141,7 @@ static int xiph_handle_packet(AVFormatContext *ctx, PayloadContext *data,
data->split_buf = av_malloc(data->split_buf_size); data->split_buf = av_malloc(data->split_buf_size);
if (!data->split_buf) { if (!data->split_buf) {
av_log(ctx, AV_LOG_ERROR, "Out of memory.\n"); av_log(ctx, AV_LOG_ERROR, "Out of memory.\n");
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
} }

View File

@ -220,7 +220,7 @@ static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt)
int i = s->nb_streams; int i = s->nb_streams;
AVStream *st = avformat_new_stream(s, NULL); AVStream *st = avformat_new_stream(s, NULL);
if (!st) { if (!st) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
st->id = i; st->id = i;

View File

@ -128,7 +128,7 @@ int main(int argc, char **argv)
ts_str(dts_buf, pkt.dts, st->time_base); ts_str(dts_buf, pkt.dts, st->time_base);
ts_str(ts_buf, pkt.pts, st->time_base); ts_str(ts_buf, pkt.pts, st->time_base);
printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size); printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size);
av_free_packet(&pkt); av_packet_unref(&pkt);
} else } else
printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace
printf("\n"); printf("\n");

View File

@ -288,7 +288,7 @@ static int vmd_read_packet(AVFormatContext *s,
frame->frame_size); frame->frame_size);
if (ret != frame->frame_size) { if (ret != frame->frame_size) {
av_free_packet(pkt); av_packet_unref(pkt);
ret = AVERROR(EIO); ret = AVERROR(EIO);
} }
pkt->stream_index = frame->stream_index; pkt->stream_index = frame->stream_index;

View File

@ -193,7 +193,7 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->pos = avio_tell(pb) - BURST_HEADER_SIZE; pkt->pos = avio_tell(pb) - BURST_HEADER_SIZE;
if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { if (avio_read(pb, pkt->data, pkt->size) < pkt->size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR_EOF; return AVERROR_EOF;
} }
ff_spdif_bswap_buf16((uint16_t *)pkt->data, (uint16_t *)pkt->data, pkt->size >> 1); ff_spdif_bswap_buf16((uint16_t *)pkt->data, (uint16_t *)pkt->data, pkt->size >> 1);
@ -201,7 +201,7 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = spdif_get_offset_and_codec(s, data_type, pkt->data, ret = spdif_get_offset_and_codec(s, data_type, pkt->data,
&offset, &codec_id); &offset, &codec_id);
if (ret) { if (ret) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
@ -212,7 +212,7 @@ int ff_spdif_read_packet(AVFormatContext *s, AVPacket *pkt)
/* first packet, create a stream */ /* first packet, create a stream */
AVStream *st = avformat_new_stream(s, NULL); AVStream *st = avformat_new_stream(s, NULL);
if (!st) { if (!st) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
st->codec->codec_type = AVMEDIA_TYPE_AUDIO; st->codec->codec_type = AVMEDIA_TYPE_AUDIO;

View File

@ -180,7 +180,7 @@ static int thp_read_packet(AVFormatContext *s,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret != size) { if (ret != size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }
@ -190,7 +190,7 @@ static int thp_read_packet(AVFormatContext *s,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret != thp->audiosize) { if (ret != thp->audiosize) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -237,7 +237,7 @@ static int append_packet_chunked(AVIOContext *s, AVPacket *pkt, int size)
pkt->pos = orig_pos; pkt->pos = orig_pos;
if (!pkt->size) if (!pkt->size)
av_free_packet(pkt); av_packet_unref(pkt);
return pkt->size > orig_size ? pkt->size - orig_size : ret; return pkt->size > orig_size ? pkt->size - orig_size : ret;
} }
@ -696,7 +696,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
av_log(s, AV_LOG_WARNING, av_log(s, AV_LOG_WARNING,
"Dropped corrupted packet (stream = %d)\n", "Dropped corrupted packet (stream = %d)\n",
pkt->stream_index); pkt->stream_index);
av_free_packet(pkt); av_packet_unref(pkt);
continue; continue;
} }
@ -1188,7 +1188,7 @@ static void free_packet_buffer(AVPacketList **pkt_buf, AVPacketList **pkt_buf_en
while (*pkt_buf) { while (*pkt_buf) {
AVPacketList *pktl = *pkt_buf; AVPacketList *pktl = *pkt_buf;
*pkt_buf = pktl->next; *pkt_buf = pktl->next;
av_free_packet(&pktl->pkt); av_packet_unref(&pktl->pkt);
av_freep(&pktl); av_freep(&pktl);
} }
*pkt_buf_end = NULL; *pkt_buf_end = NULL;
@ -1282,7 +1282,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
goto fail; goto fail;
if (!add_to_pktbuf(&s->internal->parse_queue, &out_pkt, &s->internal->parse_queue_end)) { if (!add_to_pktbuf(&s->internal->parse_queue, &out_pkt, &s->internal->parse_queue_end)) {
av_free_packet(&out_pkt); av_packet_unref(&out_pkt);
ret = AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
@ -1295,7 +1295,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
} }
fail: fail:
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
@ -1398,7 +1398,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt)
return ret; return ret;
} else { } else {
/* free packet */ /* free packet */
av_free_packet(&cur_pkt); av_packet_unref(&cur_pkt);
} }
if (pkt->flags & AV_PKT_FLAG_KEY) if (pkt->flags & AV_PKT_FLAG_KEY)
st->skip_to_keyframe = 0; st->skip_to_keyframe = 0;
@ -2131,7 +2131,7 @@ static int seek_frame_generic(AVFormatContext *s, int stream_index,
} while (read_status == AVERROR(EAGAIN)); } while (read_status == AVERROR(EAGAIN));
if (read_status < 0) if (read_status < 0)
break; break;
av_free_packet(&pkt); av_packet_unref(&pkt);
if (stream_index == pkt.stream_index && pkt.dts > timestamp) { if (stream_index == pkt.stream_index && pkt.dts > timestamp) {
if (pkt.flags & AV_PKT_FLAG_KEY) if (pkt.flags & AV_PKT_FLAG_KEY)
break; break;
@ -2535,7 +2535,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
st->info->last_duration = duration; st->info->last_duration = duration;
} }
} }
av_free_packet(pkt); av_packet_unref(pkt);
} }
/* check if all audio/video streams have valid duration */ /* check if all audio/video streams have valid duration */
@ -3664,7 +3664,7 @@ void ff_free_stream(AVFormatContext *s, AVStream *st) {
av_parser_close(st->parser); av_parser_close(st->parser);
} }
if (st->attached_pic.data) if (st->attached_pic.data)
av_free_packet(&st->attached_pic); av_packet_unref(&st->attached_pic);
av_dict_free(&st->metadata); av_dict_free(&st->metadata);
av_freep(&st->probe_data.buf); av_freep(&st->probe_data.buf);
av_freep(&st->index_entries); av_freep(&st->index_entries);

View File

@ -246,7 +246,7 @@ static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data+2, size); ret = avio_read(s->pb, pkt->data+2, size);
if (ret != size) { if (ret != size) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }

View File

@ -295,7 +295,7 @@ static int wc3_read_close(AVFormatContext *s)
Wc3DemuxContext *wc3 = s->priv_data; Wc3DemuxContext *wc3 = s->priv_data;
if (wc3->vpkt.size > 0) if (wc3->vpkt.size > 0)
av_free_packet(&wc3->vpkt); av_packet_unref(&wc3->vpkt);
return 0; return 0;
} }

View File

@ -273,25 +273,25 @@ static int wv_read_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data, wc->block_header, WV_HEADER_SIZE); memcpy(pkt->data, wc->block_header, WV_HEADER_SIZE);
ret = avio_read(s->pb, pkt->data + WV_HEADER_SIZE, wc->header.blocksize); ret = avio_read(s->pb, pkt->data + WV_HEADER_SIZE, wc->header.blocksize);
if (ret != wc->header.blocksize) { if (ret != wc->header.blocksize) {
av_free_packet(pkt); av_packet_unref(pkt);
return AVERROR(EIO); return AVERROR(EIO);
} }
while (!(wc->header.flags & WV_FLAG_FINAL_BLOCK)) { while (!(wc->header.flags & WV_FLAG_FINAL_BLOCK)) {
if ((ret = wv_read_block_header(s, s->pb)) < 0) { if ((ret = wv_read_block_header(s, s->pb)) < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
off = pkt->size; off = pkt->size;
if ((ret = av_grow_packet(pkt, WV_HEADER_SIZE + wc->header.blocksize)) < 0) { if ((ret = av_grow_packet(pkt, WV_HEADER_SIZE + wc->header.blocksize)) < 0) {
av_free_packet(pkt); av_packet_unref(pkt);
return ret; return ret;
} }
memcpy(pkt->data + off, wc->block_header, WV_HEADER_SIZE); memcpy(pkt->data + off, wc->block_header, WV_HEADER_SIZE);
ret = avio_read(s->pb, pkt->data + off + WV_HEADER_SIZE, wc->header.blocksize); ret = avio_read(s->pb, pkt->data + off + WV_HEADER_SIZE, wc->header.blocksize);
if (ret != wc->header.blocksize) { if (ret != wc->header.blocksize) {
av_free_packet(pkt); av_packet_unref(pkt);
return (ret < 0) ? ret : AVERROR_EOF; return (ret < 0) ? ret : AVERROR_EOF;
} }
} }

View File

@ -173,14 +173,14 @@ static int yop_read_packet(AVFormatContext *s, AVPacket *pkt)
return yop->audio_block_length; return yop->audio_block_length;
err_out: err_out:
av_free_packet(&yop->video_packet); av_packet_unref(&yop->video_packet);
return ret; return ret;
} }
static int yop_read_close(AVFormatContext *s) static int yop_read_close(AVFormatContext *s)
{ {
YopDecContext *yop = s->priv_data; YopDecContext *yop = s->priv_data;
av_free_packet(&yop->video_packet); av_packet_unref(&yop->video_packet);
return 0; return 0;
} }
@ -205,7 +205,7 @@ static int yop_read_seek(AVFormatContext *s, int stream_index,
if (avio_seek(s->pb, frame_pos, SEEK_SET) < 0) if (avio_seek(s->pb, frame_pos, SEEK_SET) < 0)
return -1; return -1;
av_free_packet(&yop->video_packet); av_packet_unref(&yop->video_packet);
yop->odd_frame = timestamp & 1; yop->odd_frame = timestamp & 1;
return 0; return 0;

View File

@ -122,7 +122,7 @@ int main(int argc, char **argv)
} }
close(fd); close(fd);
} }
av_free_packet(&pkt); av_packet_unref(&pkt);
pktnum++; pktnum++;
if (maxpkts && (pktnum >= maxpkts)) if (maxpkts && (pktnum >= maxpkts))
break; break;