Since bae8844e
the packet will always be unreferenced when a demuxer
returns an error, so that a lot of calls to av_packet_unref() in lots of
demuxers are now redundant and can be removed.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
tags/n4.3
@@ -141,7 +141,6 @@ static int handle_id3(AVFormatContext *s, AVPacket *pkt) | |||||
ret = av_append_packet(s->pb, pkt, ff_id3v2_tag_len(pkt->data) - pkt->size); | ret = av_append_packet(s->pb, pkt, ff_id3v2_tag_len(pkt->data) - pkt->size); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -174,7 +173,6 @@ retry: | |||||
return ret; | return ret; | ||||
if (ret < ADTS_HEADER_SIZE) { | if (ret < ADTS_HEADER_SIZE) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -185,7 +183,6 @@ retry: | |||||
av_assert2(append > 0); | av_assert2(append > 0); | ||||
ret = av_append_packet(s->pb, pkt, append); | ret = av_append_packet(s->pb, pkt, append); | ||||
if (ret != append) { | if (ret != append) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
if (!ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) { | if (!ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) { | ||||
@@ -201,13 +198,10 @@ retry: | |||||
fsize = (AV_RB32(pkt->data + 3) >> 13) & 0x1FFF; | fsize = (AV_RB32(pkt->data + 3) >> 13) & 0x1FFF; | ||||
if (fsize < ADTS_HEADER_SIZE) { | if (fsize < ADTS_HEADER_SIZE) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR_INVALIDDATA; | return AVERROR_INVALIDDATA; | ||||
} | } | ||||
ret = av_append_packet(s->pb, pkt, fsize - pkt->size); | ret = av_append_packet(s->pb, pkt, fsize - pkt->size); | ||||
if (ret < 0) | |||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -78,7 +78,6 @@ static int adp_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (ret != size) { | if (ret != size) { | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
av_shrink_packet(pkt, ret); | av_shrink_packet(pkt, ret); | ||||
@@ -65,11 +65,9 @@ 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_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_packet_unref(pkt); | |||||
return AVERROR_EOF; | return AVERROR_EOF; | ||||
} | } | ||||
pkt->size = size; | pkt->size = size; | ||||
@@ -153,7 +153,6 @@ 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_packet_unref(pkt); | |||||
if (read < 0) | if (read < 0) | ||||
return read; | return read; | ||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
@@ -419,7 +419,6 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) | |||||
AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); | AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); | ||||
ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); | ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -114,7 +114,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -422,8 +422,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
dst += size; | dst += size; | ||||
avio_skip(s->pb, skip); | avio_skip(s->pb, skip); | ||||
if (ret != size) { | if (ret != size) { | ||||
av_packet_unref(pkt); | |||||
break; | |||||
return AVERROR(EIO); | |||||
} | } | ||||
} | } | ||||
pkt->duration = samples; | pkt->duration = samples; | ||||
@@ -158,22 +158,19 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
ret = avio_read(pb, pkt->data + 1, datasize); | ret = avio_read(pb, pkt->data + 1, datasize); | ||||
if (ret < datasize) { | if (ret < datasize) { | ||||
ret = AVERROR(EIO); | |||||
goto fail; | |||||
return AVERROR(EIO); | |||||
} | } | ||||
datasize = avio_rl16(pb); /* palette size */ | datasize = avio_rl16(pb); /* palette size */ | ||||
if (datasize) { | if (datasize) { | ||||
if (datasize != 768) { | if (datasize != 768) { | ||||
av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); | av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); | ||||
ret = AVERROR_INVALIDDATA; | |||||
goto fail; | |||||
return AVERROR_INVALIDDATA; | |||||
} | } | ||||
pkt->data[0] |= C93_HAS_PALETTE; | pkt->data[0] |= C93_HAS_PALETTE; | ||||
ret = avio_read(pb, pkt->data + pkt->size, datasize); | ret = avio_read(pb, pkt->data + pkt->size, datasize); | ||||
if (ret < datasize) { | if (ret < datasize) { | ||||
ret = AVERROR(EIO); | |||||
goto fail; | |||||
return AVERROR(EIO); | |||||
} | } | ||||
pkt->size += 768; | pkt->size += 768; | ||||
} | } | ||||
@@ -186,10 +183,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
pkt->data[0] |= C93_FIRST_FRAME; | pkt->data[0] |= C93_FIRST_FRAME; | ||||
} | } | ||||
return 0; | return 0; | ||||
fail: | |||||
av_packet_unref(pkt); | |||||
return ret; | |||||
} | } | ||||
AVInputFormat ff_c93_demuxer = { | AVInputFormat ff_c93_demuxer = { | ||||
@@ -207,7 +207,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret); | av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret); | ||||
@@ -542,7 +542,6 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt) | |||||
if (ret < 0) { | if (ret < 0) { | ||||
av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb filter " | av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb filter " | ||||
"failed to send input packet\n"); | "failed to send input packet\n"); | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -592,7 +591,6 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) | |||||
if (ret < 0) | if (ret < 0) | ||||
return ret; | return ret; | ||||
if ((ret = match_streams(avf)) < 0) { | if ((ret = match_streams(avf)) < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
if (packet_after_outpoint(cat, pkt)) { | if (packet_after_outpoint(cat, pkt)) { | ||||
@@ -608,7 +606,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt) | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
if ((ret = filter_packet(avf, cs, pkt))) | |||||
if ((ret = filter_packet(avf, cs, pkt)) < 0) | |||||
return ret; | return ret; | ||||
st = cat->avf->streams[pkt->stream_index]; | st = cat->avf->streams[pkt->stream_index]; | ||||
@@ -93,7 +93,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
} else | } else | ||||
@@ -101,7 +100,6 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
frame_size = AV_RL32(pkt->data + pkt->size - 8); | frame_size = AV_RL32(pkt->data + pkt->size - 8); | ||||
if (frame_size > INT_MAX - 4) { | if (frame_size > INT_MAX - 4) { | ||||
av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size); | av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size); | ||||
av_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) { | if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) { | ||||
@@ -115,7 +113,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
@@ -200,7 +200,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
if (ret < pkt_size) | if (ret < pkt_size) | ||||
@@ -259,14 +259,12 @@ static int dss_sp_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
dss_sp_byte_swap(ctx, pkt->data, ctx->dss_sp_buf); | dss_sp_byte_swap(ctx, pkt->data, ctx->dss_sp_buf); | ||||
if (ctx->dss_sp_swap_byte < 0) { | if (ctx->dss_sp_swap_byte < 0) { | ||||
ret = AVERROR(EAGAIN); | |||||
goto error_eof; | |||||
return AVERROR(EAGAIN); | |||||
} | } | ||||
return pkt->size; | return pkt->size; | ||||
error_eof: | error_eof: | ||||
av_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR_EOF; | return ret < 0 ? ret : AVERROR_EOF; | ||||
} | } | ||||
@@ -308,7 +306,6 @@ 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_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR_EOF; | return ret < 0 ? ret : AVERROR_EOF; | ||||
} | } | ||||
@@ -318,7 +315,6 @@ 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_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR_EOF; | return ret < 0 ? ret : AVERROR_EOF; | ||||
} | } | ||||
@@ -210,7 +210,6 @@ 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_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); | ||||
@@ -633,7 +633,6 @@ 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_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) | ||||
@@ -736,8 +735,6 @@ get_video_packet: | |||||
} | } | ||||
} | } | ||||
if (ret < 0 && partial_packet) | |||||
av_packet_unref(pkt); | |||||
if (ret >= 0 && hit_end && !packet_read) | if (ret >= 0 && hit_end && !packet_read) | ||||
return AVERROR(EAGAIN); | return AVERROR(EAGAIN); | ||||
@@ -183,7 +183,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
ret = av_bprint_finalize(&avbuf, &buf); | ret = av_bprint_finalize(&avbuf, &buf); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -192,7 +191,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
av_freep(&buf); | av_freep(&buf); | ||||
ret = avio_read(s->pb, pkt->data + pkt->size, size); | ret = avio_read(s->pb, pkt->data + pkt->size, size); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -225,7 +225,6 @@ 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_packet_unref(pkt); | |||||
ret = AVERROR(EIO); | ret = AVERROR(EIO); | ||||
} | } | ||||
packet_read = 1; | packet_read = 1; | ||||
@@ -241,8 +240,8 @@ 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_packet_unref(pkt); | |||||
ret = AVERROR(EIO); | ret = AVERROR(EIO); | ||||
break; | |||||
} | } | ||||
packet_read = 1; | packet_read = 1; | ||||
@@ -69,7 +69,6 @@ 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_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR_EOF; | return ret < 0 ? ret : AVERROR_EOF; | ||||
} | } | ||||
@@ -182,7 +182,6 @@ static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt) | |||||
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_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
} | } | ||||
memcpy(pal, gdv->pal, AVPALETTE_SIZE); | memcpy(pal, gdv->pal, AVPALETTE_SIZE); | ||||
@@ -62,7 +62,6 @@ 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_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR(EIO); | return ret < 0 ? ret : AVERROR(EIO); | ||||
} | } | ||||
pkt->duration = 1; | pkt->duration = 1; | ||||
@@ -2225,7 +2225,6 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (ist->codecpar->codec_id != st->codecpar->codec_id) { | if (ist->codecpar->codec_id != st->codecpar->codec_id) { | ||||
ret = set_stream_info_from_input_stream(st, pls, ist); | ret = set_stream_info_from_input_stream(st, pls, ist); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
@@ -185,7 +185,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
bytestream_put_le32(&buf, 0); | bytestream_put_le32(&buf, 0); | ||||
if ((ret = avio_read(pb, buf, image->size)) != image->size) { | if ((ret = avio_read(pb, buf, image->size)) != image->size) { | ||||
av_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR_INVALIDDATA; | return ret < 0 ? ret : AVERROR_INVALIDDATA; | ||||
} | } | ||||
@@ -313,7 +313,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
if (command == 1) { | if (command == 1) { | ||||
@@ -322,7 +321,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
} | } | ||||
memcpy(pal, palette, AVPALETTE_SIZE); | memcpy(pal, palette, AVPALETTE_SIZE); | ||||
@@ -224,8 +224,7 @@ static int roq_read_packet(AVFormatContext *s, | |||||
ret = avio_read(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, | ret = avio_read(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, | ||||
chunk_size); | chunk_size); | ||||
if (ret != chunk_size) { | if (ret != chunk_size) { | ||||
av_packet_unref(pkt); | |||||
ret = AVERROR(EIO); | |||||
return AVERROR(EIO); | |||||
} | } | ||||
packet_read = 1; | packet_read = 1; | ||||
@@ -111,7 +111,6 @@ static int ilbc_read_packet(AVFormatContext *s, | |||||
pkt->pos = avio_tell(s->pb); | pkt->pos = avio_tell(s->pb); | ||||
pkt->duration = par->block_align == 38 ? 160 : 240; | pkt->duration = par->block_align == 38 ? 160 : 240; | ||||
if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) { | if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) { | ||||
av_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR(EIO); | return ret < 0 ? ret : AVERROR(EIO); | ||||
} | } | ||||
@@ -542,7 +542,6 @@ 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_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) { | ||||
@@ -92,7 +92,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
} | } | ||||
@@ -327,7 +327,6 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE); | pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE); | ||||
if (pkt->size <= 0) { | if (pkt->size <= 0) { | ||||
av_packet_unref(pkt); | |||||
return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO); | return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO); | ||||
} | } | ||||
return 0; | return 0; | ||||
@@ -316,7 +316,6 @@ 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_packet_unref(pkt); | |||||
return ret2 < 0 ? ret2 : AVERROR_EOF; | return ret2 < 0 ? ret2 : AVERROR_EOF; | ||||
} | } | ||||
@@ -7890,7 +7890,6 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
ret = cenc_filter(mov, st, sc, pkt, current_index); | ret = cenc_filter(mov, st, sc, pkt, current_index); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -169,7 +169,6 @@ 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_packet_unref(pkt); | |||||
return ret < 0 ? ret : AVERROR(EIO); | return ret < 0 ? ret : AVERROR(EIO); | ||||
} | } | ||||
pkt->size = ret + 4; | pkt->size = ret + 4; | ||||
@@ -3133,7 +3133,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
if (data != pkt->data) | if (data != pkt->data) | ||||
@@ -359,8 +359,6 @@ static int mpjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
/* error or EOF occurred */ | /* error or EOF occurred */ | ||||
if (ret == AVERROR_EOF) { | if (ret == AVERROR_EOF) { | ||||
ret = pkt->size > 0 ? pkt->size : AVERROR_EOF; | ret = pkt->size > 0 ? pkt->size : AVERROR_EOF; | ||||
} else { | |||||
av_packet_unref(pkt); | |||||
} | } | ||||
} | } | ||||
@@ -83,7 +83,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -284,7 +284,6 @@ 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_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
if (ret < size) | if (ret < size) | ||||
@@ -851,7 +851,7 @@ retry: | |||||
AV_PKT_DATA_SKIP_SAMPLES, | AV_PKT_DATA_SKIP_SAMPLES, | ||||
10); | 10); | ||||
if(!side_data) | if(!side_data) | ||||
goto fail; | |||||
return AVERROR(ENOMEM); | |||||
AV_WL32(side_data + 4, os->end_trimming); | AV_WL32(side_data + 4, os->end_trimming); | ||||
os->end_trimming = 0; | os->end_trimming = 0; | ||||
} | } | ||||
@@ -861,7 +861,7 @@ retry: | |||||
AV_PKT_DATA_METADATA_UPDATE, | AV_PKT_DATA_METADATA_UPDATE, | ||||
os->new_metadata_size); | os->new_metadata_size); | ||||
if(!side_data) | if(!side_data) | ||||
goto fail; | |||||
return AVERROR(ENOMEM); | |||||
memcpy(side_data, os->new_metadata, os->new_metadata_size); | memcpy(side_data, os->new_metadata, os->new_metadata_size); | ||||
av_freep(&os->new_metadata); | av_freep(&os->new_metadata); | ||||
@@ -869,9 +869,6 @@ retry: | |||||
} | } | ||||
return psize; | return psize; | ||||
fail: | |||||
av_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | |||||
} | } | ||||
static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, | static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, | ||||
@@ -140,7 +140,6 @@ static int redspark_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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -256,7 +256,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -338,7 +338,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
pkt->duration = 1; | pkt->duration = 1; | ||||
@@ -355,7 +354,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -174,7 +174,6 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
pkt->pos = pos; | pkt->pos = pos; | ||||
if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { | if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR_EOF; | return AVERROR_EOF; | ||||
} | } | ||||
@@ -186,7 +185,6 @@ static int s337m_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (!s->nb_streams) { | if (!s->nb_streams) { | ||||
AVStream *st = avformat_new_stream(s, NULL); | AVStream *st = avformat_new_stream(s, NULL); | ||||
if (!st) { | if (!st) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
} | } | ||||
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | ||||
@@ -225,7 +225,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
} | } | ||||
st->id = i; | st->id = i; | ||||
@@ -95,7 +95,6 @@ static int sdr2_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
memcpy(pkt->data, header, 24); | memcpy(pkt->data, header, 24); | ||||
ret = avio_read(s->pb, pkt->data + 24, next - 52); | ret = avio_read(s->pb, pkt->data + 24, next - 52); | ||||
if (ret < 0) { | if (ret < 0) { | ||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
av_shrink_packet(pkt, ret + 24); | av_shrink_packet(pkt, ret + 24); | ||||
@@ -295,7 +295,6 @@ static int vmd_read_packet(AVFormatContext *s, | |||||
frame->frame_size); | frame->frame_size); | ||||
if (ret != frame->frame_size) { | if (ret != frame->frame_size) { | ||||
av_packet_unref(pkt); | |||||
ret = AVERROR(EIO); | ret = AVERROR(EIO); | ||||
} | } | ||||
pkt->stream_index = frame->stream_index; | pkt->stream_index = frame->stream_index; | ||||
@@ -220,7 +220,6 @@ static int siff_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (c->gmcsize) | if (c->gmcsize) | ||||
memcpy(pkt->data + 2, c->gmc, c->gmcsize); | memcpy(pkt->data + 2, c->gmc, c->gmcsize); | ||||
if (avio_read(s->pb, pkt->data + 2 + c->gmcsize, size) != size) { | if (avio_read(s->pb, pkt->data + 2 + c->gmcsize, size) != size) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR_INVALIDDATA; | return AVERROR_INVALIDDATA; | ||||
} | } | ||||
pkt->stream_index = 0; | pkt->stream_index = 0; | ||||
@@ -197,15 +197,13 @@ 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_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); | ||||
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) { | |||||
av_packet_unref(pkt); | |||||
if (ret < 0) { | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -216,7 +214,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(ENOMEM); | return AVERROR(ENOMEM); | ||||
} | } | ||||
st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | ||||
@@ -399,7 +399,6 @@ static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (linesize * height > pkt->size) { | if (linesize * height > pkt->size) { | ||||
res = AVERROR_INVALIDDATA; | res = AVERROR_INVALIDDATA; | ||||
av_packet_unref(pkt); | |||||
goto bitmap_end; | goto bitmap_end; | ||||
} | } | ||||
@@ -489,7 +488,6 @@ bitmap_end_skip: | |||||
if ((res = av_new_packet(pkt, len)) < 0) | if ((res = av_new_packet(pkt, len)) < 0) | ||||
return res; | return res; | ||||
if (avio_read(pb, pkt->data, 4) != 4) { | if (avio_read(pb, pkt->data, 4) != 4) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR_INVALIDDATA; | return AVERROR_INVALIDDATA; | ||||
} | } | ||||
if (AV_RB32(pkt->data) == 0xffd8ffd9 || | if (AV_RB32(pkt->data) == 0xffd8ffd9 || | ||||
@@ -506,7 +504,6 @@ bitmap_end_skip: | |||||
} | } | ||||
if (res != pkt->size) { | if (res != pkt->size) { | ||||
if (res < 0) { | if (res < 0) { | ||||
av_packet_unref(pkt); | |||||
return res; | return res; | ||||
} | } | ||||
av_shrink_packet(pkt, res); | av_shrink_packet(pkt, res); | ||||
@@ -181,7 +181,6 @@ static int thp_read_packet(AVFormatContext *s, | |||||
if (ret < 0) | if (ret < 0) | ||||
return ret; | return ret; | ||||
if (ret != size) { | if (ret != size) { | ||||
av_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -191,7 +190,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -273,32 +273,28 @@ restart: | |||||
} | } | ||||
if ((ret = av_get_packet(pb, pkt, vivo->length)) < 0) | if ((ret = av_get_packet(pb, pkt, vivo->length)) < 0) | ||||
goto fail; | |||||
return ret; | |||||
// get next packet header | // get next packet header | ||||
if ((ret = vivo_get_packet_header(s)) < 0) | if ((ret = vivo_get_packet_header(s)) < 0) | ||||
goto fail; | |||||
return ret; | |||||
while (vivo->sequence == old_sequence && | while (vivo->sequence == old_sequence && | ||||
(((vivo->type - 1) >> 1) == ((old_type - 1) >> 1))) { | (((vivo->type - 1) >> 1) == ((old_type - 1) >> 1))) { | ||||
if (avio_feof(pb)) { | if (avio_feof(pb)) { | ||||
ret = AVERROR_EOF; | |||||
break; | |||||
return AVERROR_EOF; | |||||
} | } | ||||
if ((ret = av_append_packet(pb, pkt, vivo->length)) < 0) | if ((ret = av_append_packet(pb, pkt, vivo->length)) < 0) | ||||
break; | |||||
return ret; | |||||
// get next packet header | // get next packet header | ||||
if ((ret = vivo_get_packet_header(s)) < 0) | if ((ret = vivo_get_packet_header(s)) < 0) | ||||
break; | |||||
return ret; | |||||
} | } | ||||
pkt->stream_index = stream_index; | pkt->stream_index = stream_index; | ||||
fail: | |||||
if (ret < 0) | |||||
av_packet_unref(pkt); | |||||
return ret; | return ret; | ||||
} | } | ||||
@@ -93,9 +93,7 @@ static int vpk_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
ret = avio_read(s->pb, pkt->data + i * size, size); | ret = avio_read(s->pb, pkt->data + i * size, size); | ||||
avio_skip(s->pb, skip); | avio_skip(s->pb, skip); | ||||
if (ret != size) { | if (ret != size) { | ||||
av_packet_unref(pkt); | |||||
ret = AVERROR(EIO); | |||||
break; | |||||
return AVERROR(EIO); | |||||
} | } | ||||
} | } | ||||
pkt->stream_index = 0; | pkt->stream_index = 0; | ||||
@@ -249,7 +249,6 @@ 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_packet_unref(pkt); | |||||
return AVERROR(EIO); | return AVERROR(EIO); | ||||
} | } | ||||
@@ -287,25 +287,21 @@ 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_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_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_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_packet_unref(pkt); | |||||
return (ret < 0) ? ret : AVERROR_EOF; | return (ret < 0) ? ret : AVERROR_EOF; | ||||
} | } | ||||
} | } | ||||
@@ -314,7 +314,6 @@ static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) | |||||
if (ret < 0) | if (ret < 0) | ||||
return ret; | return ret; | ||||
else if (ret != s->packet_size - Y4M_FRAME_MAGIC_LEN) { | else if (ret != s->packet_size - Y4M_FRAME_MAGIC_LEN) { | ||||
av_packet_unref(pkt); | |||||
return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO); | return s->pb->eof_reached ? AVERROR_EOF : AVERROR(EIO); | ||||
} | } | ||||
pkt->stream_index = 0; | pkt->stream_index = 0; | ||||