Commit ce70f28a authored by Luca Barbato's avatar Luca Barbato

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`.
parent a5d42043
......@@ -270,7 +270,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
*/
if (!(avctx->codec_type == AVMEDIA_TYPE_VIDEO && avctx->codec)) {
if (ost->frame_number >= ost->max_frames) {
av_free_packet(pkt);
av_packet_unref(pkt);
return;
}
ost->frame_number++;
......@@ -288,7 +288,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost)
pkt->data, pkt->size,
pkt->flags & AV_PKT_FLAG_KEY);
if (a > 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
new_pkt.buf = av_buffer_create(new_pkt.data, new_pkt.size,
av_buffer_default_free, NULL, 0);
if (!new_pkt.buf)
......@@ -2158,7 +2158,7 @@ static void free_input_threads(void)
pthread_mutex_lock(&f->fifo_lock);
while (av_fifo_size(f->fifo)) {
av_fifo_generic_read(f->fifo, &pkt, sizeof(pkt), NULL);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
pthread_cond_signal(&f->fifo_cond);
pthread_mutex_unlock(&f->fifo_lock);
......@@ -2168,7 +2168,7 @@ static void free_input_threads(void)
while (av_fifo_size(f->fifo)) {
av_fifo_generic_read(f->fifo, &pkt, sizeof(pkt), NULL);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
av_fifo_free(f->fifo);
}
......@@ -2483,7 +2483,7 @@ static int process_input(void)
process_input_packet(ist, &pkt, 0);
discard_packet:
av_free_packet(&pkt);
av_packet_unref(&pkt);
return 0;
}
......
......@@ -299,7 +299,7 @@ static void packet_queue_flush(PacketQueue *q)
SDL_LockMutex(q->mutex);
for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
pkt1 = pkt->next;
av_free_packet(&pkt->pkt);
av_packet_unref(&pkt->pkt);
av_freep(&pkt);
}
q->last_pkt = NULL;
......@@ -1617,7 +1617,7 @@ static int video_thread(void *arg)
while (is->paused && !is->videoq.abort_request)
SDL_Delay(10);
av_free_packet(&pkt);
av_packet_unref(&pkt);
ret = get_video_frame(is, frame, &pts_int, &pkt);
if (ret < 0)
......@@ -1684,7 +1684,7 @@ static int video_thread(void *arg)
av_freep(&vfilters);
avfilter_graph_free(&graph);
#endif
av_free_packet(&pkt);
av_packet_unref(&pkt);
av_frame_free(&frame);
return 0;
}
......@@ -1753,7 +1753,7 @@ static int subtitle_thread(void *arg)
is->subpq_size++;
SDL_UnlockMutex(is->subpq_mutex);
}
av_free_packet(pkt);
av_packet_unref(pkt);
}
return 0;
}
......@@ -1984,7 +1984,7 @@ static int audio_decode_frame(VideoState *is, double *pts_ptr)
/* free the current packet */
if (pkt->data)
av_free_packet(pkt);
av_packet_unref(pkt);
memset(pkt_temp, 0, sizeof(*pkt_temp));
if (is->paused || is->audioq.abort_request) {
......@@ -2181,7 +2181,7 @@ static void stream_component_close(VideoState *is, int stream_index)
SDL_CloseAudio();
packet_queue_end(&is->audioq);
av_free_packet(&is->audio_pkt);
av_packet_unref(&is->audio_pkt);
if (is->avr)
avresample_free(&is->avr);
av_freep(&is->audio_buf1);
......@@ -2490,7 +2490,7 @@ static int decode_thread(void *arg)
} else if (pkt->stream_index == is->subtitle_stream && pkt_in_play_range) {
packet_queue_put(&is->subtitleq, pkt);
} else {
av_free_packet(pkt);
av_packet_unref(pkt);
}
}
/* wait until the end */
......
......@@ -13,6 +13,10 @@ libavutil: 2015-08-28
API changes, most recent first:
2015-xx-xx - xxxxxxx - lavc 57.7.0 - avcodec.h
Deprecate av_free_packet(). Use av_packet_unref() as replacement,
it resets the packet in a more consistent way.
2015-xx-xx - xxxxxxx - lavc 57.5.0 - avcodec.h
Add data and linesize array to AVSubtitleRect, to be used instead of
the ones from the embedded AVPicture.
......
......@@ -206,7 +206,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);
......@@ -403,7 +403,7 @@ static void video_encode_example(const char *filename)
if (got_output) {
printf("encoding frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
}
......@@ -420,7 +420,7 @@ static void video_encode_example(const char *filename)
if (got_output) {
printf("encoding frame %3d (size=%5d)\n", i, pkt.size);
fwrite(pkt.data, 1, pkt.size, f);
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
}
......
......@@ -337,7 +337,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;
}
......@@ -347,7 +347,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;
}
......@@ -585,7 +585,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;
}
......@@ -594,11 +594,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;
......
......@@ -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.
......
......@@ -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)
......
......@@ -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);
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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 */
......@@ -128,14 +128,14 @@ static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt)
while ((res = snd_pcm_readi(s->h, pkt->data, pkt->size / s->frame_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);
}
......
......@@ -220,7 +220,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_free(fifo);
}
......
......@@ -82,7 +82,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;
......
......@@ -133,7 +133,7 @@ static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt)
if ((pa_simple_read(pd->s, pkt->data, pkt->size, &res)) < 0) {
av_log(s, AV_LOG_ERROR, "pa_simple_read failed: %s\n",
pa_strerror(res));
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR(EIO);
}
......
......@@ -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;
}
......
......@@ -508,7 +508,7 @@ static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt)
if (res < 0) {
res = AVERROR(errno);
av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");
av_free_packet(pkt);
av_packet_unref(pkt);
return res;
}
avpriv_atomic_int_add_and_fetch(&s->buffers_queued, 1);
......
......@@ -233,7 +233,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;
}
......
......@@ -230,13 +230,13 @@ static int movie_get_frame(AVFilterLink *outlink)
movie->frame->sample_aspect_ratio.num,
movie->frame->sample_aspect_ratio.den);
// We got it. Free the packet since we are returning
av_free_packet(&pkt);
av_packet_unref(&pkt);
return 0;
}
}
// Free the packet that was allocated by av_read_frame
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
// On multi-frame source we should stop the mixing process when
......
......@@ -308,7 +308,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;
break;
......
......@@ -47,11 +47,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;
......
......@@ -148,7 +148,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);
}
......
......@@ -444,7 +444,7 @@ static int asf_read_picture(AVFormatContext *s, int len)
fail:
av_freep(&desc);
av_free_packet(&pkt);
av_packet_unref(&pkt);
return ret;
}
......@@ -1128,7 +1128,7 @@ static void reset_packet(ASFPacket *asf_pkt)
asf_pkt->flags = 0;
asf_pkt->dts = 0;
asf_pkt->duration = 0;
av_free_packet(&asf_pkt->avpkt);
av_packet_unref(&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)
break;
}
av_free_packet(&asf_pkt->avpkt);
av_packet_unref(&asf_pkt->avpkt);
asf_pkt->avpkt = pkt;
return 0;
......@@ -1485,7 +1485,7 @@ static int asf_read_close(AVFormatContext *s)
for (i = 0; i < ASF_MAX_STREAMS; i++) {
av_dict_free(&asf->asf_sd[i].asf_met);
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]);
}
}
......@@ -1521,7 +1521,7 @@ static void reset_packet_state(AVFormatContext *s)
pkt->flags = 0;
pkt->dts = 0;
pkt->duration = 0;
av_free_packet(&pkt->avpkt);
av_packet_unref(&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)
break;
av_free_packet(&pkt);
av_packet_unref(&pkt);
}
*pos = pkt_pos;
av_free_packet(&pkt);
av_packet_unref(&pkt);
return dts;
}
......
......@@ -165,7 +165,7 @@
* 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
* 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.
*
* @section lavf_decoding_seek Seeking
......@@ -1491,7 +1491,7 @@ int av_find_best_stream(AVFormatContext *ic,
* If pkt->buf is NULL, then the packet is valid until the next
* av_read_frame() or until avformat_close_input(). Otherwise the packet
* 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
* 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.
......
......@@ -1215,7 +1215,7 @@ resync:
pkt->buf = avbuf;
pkt->flags |= AV_PKT_FLAG_KEY;
if (size < 0)
av_free_packet(pkt);
av_packet_unref(pkt);
} else if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE &&
!st->codec->codec_tag && read_gab2_sub(st, pkt)) {
ast->frame_offset++;
......@@ -1470,7 +1470,7 @@ static void seek_subtitle(AVStream *st, AVStream *st2, int64_t timestamp)
{
AVIStream *ast2 = st2->priv_data;
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 ||
avformat_seek_file(ast2->sub_ctx, 0, ts2, ts2, INT64_MAX, 0) >= 0)
ff_read_packet(ast2->sub_ctx, &ast2->sub_pkt);
......@@ -1587,7 +1587,7 @@ static int avi_read_close(AVFormatContext *s)
avformat_close_input(&ast->sub_ctx);
}
av_free(ast->sub_buffer);
av_free_packet(&ast->sub_pkt);
av_packet_unref(&ast->sub_pkt);
}
}
......
......@@ -108,7 +108,7 @@ avs_read_video_packet(AVFormatContext * s, AVPacket * pkt,
pkt->data[palette_size + 3] = (size >> 8) & 0xFF;
ret = avio_read(s->pb, pkt->data + palette_size + 4, size - 4) + 4;
if (ret < size) {
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR(EIO);
}
......
......@@ -188,7 +188,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
return 0;
fail:
av_free_packet(pkt);
av_packet_unref(pkt);
return ret;
}
......
......@@ -62,7 +62,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE);
if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND)
break;
av_free_packet(pkt);
av_packet_unref(pkt);
}
if (!priv->got_first_packet) {
......
......@@ -146,7 +146,7 @@ static int cdxl_read_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data, cdxl->header, CDXL_HEADER_SIZE);
ret = avio_read(pb, pkt->data + CDXL_HEADER_SIZE, video_size);
if (ret < 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret;
}
av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret);
......
......@@ -82,7 +82,7 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!first) {
ret = av_append_packet(pb, pkt, 12);
if (ret < 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret;
}
} else
......@@ -103,7 +103,7 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
}
ret = av_append_packet(pb, pkt, frame_size);
if (ret < 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret;
}
}
......
......@@ -197,7 +197,7 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(pb, &pkt->data[4], pkt_size);
if (ret < 0) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret;
}
if (ret < pkt_size)
......
......@@ -256,7 +256,7 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt)
return pkt->size;
error_eof:
av_free_packet(pkt);
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}
......@@ -294,7 +294,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data + offset,
size2 - offset);
if (ret < size2 - offset) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}
......@@ -304,7 +304,7 @@ static int dss_723_1_read_packet(AVFormatContext *s, AVPacket *pkt)
ret = avio_read(s->pb, pkt->data + offset, size - offset);
if (ret < size - offset) {
av_free_packet(pkt);
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}
......
......@@ -201,7 +201,7 @@ static int dxa_read_packet(AVFormatContext *s, AVPacket *pkt)
memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE);
ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size);
if(ret != size){
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR(EIO);
}
if(pal_size) memcpy(pkt->data, pal, pal_size);
......
......@@ -567,7 +567,7 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt)
case AV_CODEC_ID_ADPCM_EA_R3:
if (pkt->size < 4) {
av_log(s, AV_LOG_ERROR, "Packet is too short\n");
av_free_packet(pkt);
av_packet_unref(pkt);
return AVERROR_INVALIDDATA;
}
if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3)
......
......@@ -228,7 +228,7 @@ static int flic_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE,
size - FLIC_PREAMBLE_SIZE);
if (ret != size - FLIC_PREAMBLE_SIZE) {
av_free_packet(pkt);
av_packet_unref(pkt);
ret = AVERROR(EIO);
}
packet_read = 1;
......@@ -246,7 +246,7 @@ static int flic_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data, size);
if (ret != size) {
av_free_packet(pkt);