Skip to content

Commit

Permalink
avformat: Remove unnecessary av_packet_unref()
Browse files Browse the repository at this point in the history
Since bae8844 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 <[email protected]>
Signed-off-by: Marton Balint <[email protected]>
  • Loading branch information
mkver authored and cus committed Feb 10, 2020
1 parent bbea268 commit 6a67d51
Show file tree
Hide file tree
Showing 52 changed files with 17 additions and 108 deletions.
6 changes: 0 additions & 6 deletions libavformat/aacdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}

Expand Down Expand Up @@ -174,7 +173,6 @@ static int adts_aac_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret;

if (ret < ADTS_HEADER_SIZE) {
av_packet_unref(pkt);
return AVERROR(EIO);
}

Expand All @@ -185,7 +183,6 @@ static int adts_aac_read_packet(AVFormatContext *s, AVPacket *pkt)
av_assert2(append > 0);
ret = av_append_packet(s->pb, pkt, append);
if (ret != append) {
av_packet_unref(pkt);
return AVERROR(EIO);
}
if (!ff_id3v2_match(pkt->data, ID3v2_DEFAULT_MAGIC)) {
Expand All @@ -201,13 +198,10 @@ static int adts_aac_read_packet(AVFormatContext *s, AVPacket *pkt)

fsize = (AV_RB32(pkt->data + 3) >> 13) & 0x1FFF;
if (fsize < ADTS_HEADER_SIZE) {
av_packet_unref(pkt);
return AVERROR_INVALIDDATA;
}

ret = av_append_packet(s->pb, pkt, fsize - pkt->size);
if (ret < 0)
av_packet_unref(pkt);

return ret;
}
Expand Down
1 change: 0 additions & 1 deletion libavformat/adp.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)

if (ret != size) {
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}
av_shrink_packet(pkt, ret);
Expand Down
2 changes: 0 additions & 2 deletions libavformat/adxdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ static int adx_read_packet(AVFormatContext *s, AVPacket *pkt)

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

if (read != size - 1) {
av_packet_unref(pkt);
if (read < 0)
return read;
return AVERROR(EIO);
Expand Down
1 change: 0 additions & 1 deletion libavformat/ape.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip);
ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}

Expand Down
1 change: 0 additions & 1 deletion libavformat/avs.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ 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_packet_unref(pkt);
return AVERROR(EIO);
}

Expand Down
3 changes: 1 addition & 2 deletions libavformat/brstm.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
dst += size;
avio_skip(s->pb, skip);
if (ret != size) {
av_packet_unref(pkt);
break;
return AVERROR(EIO);
}
}
pkt->duration = samples;
Expand Down
13 changes: 3 additions & 10 deletions libavformat/c93.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,19 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)

ret = avio_read(pb, pkt->data + 1, datasize);
if (ret < datasize) {
ret = AVERROR(EIO);
goto fail;
return AVERROR(EIO);
}

datasize = avio_rl16(pb); /* palette size */
if (datasize) {
if (datasize != 768) {
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;
ret = avio_read(pb, pkt->data + pkt->size, datasize);
if (ret < datasize) {
ret = AVERROR(EIO);
goto fail;
return AVERROR(EIO);
}
pkt->size += 768;
}
Expand All @@ -186,10 +183,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
pkt->data[0] |= C93_FIRST_FRAME;
}
return 0;

fail:
av_packet_unref(pkt);
return ret;
}

AVInputFormat ff_c93_demuxer = {
Expand Down
1 change: 0 additions & 1 deletion libavformat/cdxl.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ 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_packet_unref(pkt);
return ret;
}
av_shrink_packet(pkt, CDXL_HEADER_SIZE + ret);
Expand Down
4 changes: 1 addition & 3 deletions libavformat/concatdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt)
if (ret < 0) {
av_log(avf, AV_LOG_ERROR, "h264_mp4toannexb filter "
"failed to send input packet\n");
av_packet_unref(pkt);
return ret;
}

Expand Down Expand Up @@ -592,7 +591,6 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
if (ret < 0)
return ret;
if ((ret = match_streams(avf)) < 0) {
av_packet_unref(pkt);
return ret;
}
if (packet_after_outpoint(cat, pkt)) {
Expand All @@ -608,7 +606,7 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
}
break;
}
if ((ret = filter_packet(avf, cs, pkt)))
if ((ret = filter_packet(avf, cs, pkt)) < 0)
return ret;

st = cat->avf->streams[pkt->stream_index];
Expand Down
3 changes: 0 additions & 3 deletions libavformat/dfa.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,13 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!first) {
ret = av_append_packet(pb, pkt, 12);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}
} else
first = 0;
frame_size = AV_RL32(pkt->data + pkt->size - 8);
if (frame_size > INT_MAX - 4) {
av_log(s, AV_LOG_ERROR, "Too large chunk size: %"PRIu32"\n", frame_size);
av_packet_unref(pkt);
return AVERROR(EIO);
}
if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) {
Expand All @@ -115,7 +113,6 @@ static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt)
}
ret = av_append_packet(pb, pkt, frame_size);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}
}
Expand Down
1 change: 0 additions & 1 deletion libavformat/dsicin.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ static int cin_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = avio_read(pb, &pkt->data[4], pkt_size);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}
if (ret < pkt_size)
Expand Down
6 changes: 1 addition & 5 deletions libavformat/dss.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

if (ctx->dss_sp_swap_byte < 0) {
ret = AVERROR(EAGAIN);
goto error_eof;
return AVERROR(EAGAIN);
}

return pkt->size;

error_eof:
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}

Expand Down Expand Up @@ -308,7 +306,6 @@ 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_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}

Expand All @@ -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);
if (ret < size - offset) {
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}

Expand Down
1 change: 0 additions & 1 deletion libavformat/dxa.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ 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_packet_unref(pkt);
return AVERROR(EIO);
}
if(pal_size) memcpy(pkt->data, pal, pal_size);
Expand Down
3 changes: 0 additions & 3 deletions libavformat/electronicarts.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ 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_packet_unref(pkt);
return AVERROR_INVALIDDATA;
}
if (ea->audio_codec == AV_CODEC_ID_ADPCM_EA_R3)
Expand Down Expand Up @@ -736,8 +735,6 @@ static int ea_read_packet(AVFormatContext *s, AVPacket *pkt)
}
}

if (ret < 0 && partial_packet)
av_packet_unref(pkt);
if (ret >= 0 && hit_end && !packet_read)
return AVERROR(EAGAIN);

Expand Down
2 changes: 0 additions & 2 deletions libavformat/fitsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = av_bprint_finalize(&avbuf, &buf);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}

Expand All @@ -192,7 +191,6 @@ static int fits_read_packet(AVFormatContext *s, AVPacket *pkt)
av_freep(&buf);
ret = avio_read(s->pb, pkt->data + pkt->size, size);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}

Expand Down
3 changes: 1 addition & 2 deletions libavformat/flic.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ 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_packet_unref(pkt);
ret = AVERROR(EIO);
}
packet_read = 1;
Expand All @@ -241,8 +240,8 @@ static int flic_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data, size);

if (ret != size) {
av_packet_unref(pkt);
ret = AVERROR(EIO);
break;
}

packet_read = 1;
Expand Down
1 change: 0 additions & 1 deletion libavformat/g723_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = avio_read(s->pb, pkt->data + 1, size - 1);
if (ret < size - 1) {
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_EOF;
}

Expand Down
1 change: 0 additions & 1 deletion libavformat/gdv.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt)
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
AVPALETTE_SIZE);
if (!pal) {
av_packet_unref(pkt);
return AVERROR(ENOMEM);
}
memcpy(pal, gdv->pal, AVPALETTE_SIZE);
Expand Down
1 change: 0 additions & 1 deletion libavformat/gsmdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = av_get_packet(s->pb, pkt, size);
if (ret < GSM_BLOCK_SIZE) {
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO);
}
pkt->duration = 1;
Expand Down
1 change: 0 additions & 1 deletion libavformat/hls.c
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,6 @@ static int hls_read_packet(AVFormatContext *s, AVPacket *pkt)
if (ist->codecpar->codec_id != st->codecpar->codec_id) {
ret = set_stream_info_from_input_stream(st, pls, ist);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}
}
Expand Down
1 change: 0 additions & 1 deletion libavformat/icodec.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
bytestream_put_le32(&buf, 0);

if ((ret = avio_read(pb, buf, image->size)) != image->size) {
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR_INVALIDDATA;
}

Expand Down
2 changes: 0 additions & 2 deletions libavformat/idcin.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ static int idcin_read_packet(AVFormatContext *s,
return ret;
else if (ret != chunk_size) {
av_log(s, AV_LOG_ERROR, "incomplete packet\n");
av_packet_unref(pkt);
return AVERROR(EIO);
}
if (command == 1) {
Expand All @@ -322,7 +321,6 @@ static int idcin_read_packet(AVFormatContext *s,
pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
AVPALETTE_SIZE);
if (!pal) {
av_packet_unref(pkt);
return AVERROR(ENOMEM);
}
memcpy(pal, palette, AVPALETTE_SIZE);
Expand Down
3 changes: 1 addition & 2 deletions libavformat/idroqdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ static int roq_read_packet(AVFormatContext *s,
ret = avio_read(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE,
chunk_size);
if (ret != chunk_size) {
av_packet_unref(pkt);
ret = AVERROR(EIO);
return AVERROR(EIO);
}

packet_read = 1;
Expand Down
1 change: 0 additions & 1 deletion libavformat/ilbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ static int ilbc_read_packet(AVFormatContext *s,
pkt->pos = avio_tell(s->pb);
pkt->duration = par->block_align == 38 ? 160 : 240;
if ((ret = avio_read(s->pb, pkt->data, par->block_align)) != par->block_align) {
av_packet_unref(pkt);
return ret < 0 ? ret : AVERROR(EIO);
}

Expand Down
1 change: 0 additions & 1 deletion libavformat/img2dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,6 @@ int ff_img_read_packet(AVFormatContext *s1, AVPacket *pkt)
}

if (ret[0] <= 0 || ret[1] < 0 || ret[2] < 0) {
av_packet_unref(pkt);
if (ret[0] < 0) {
res = ret[0];
} else if (ret[1] < 0) {
Expand Down
1 change: 0 additions & 1 deletion libavformat/iv8.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ static int read_packet(AVFormatContext *s, AVPacket *pkt)
ret = av_append_packet(s->pb, pkt, size);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "failed to grow packet\n");
av_packet_unref(pkt);
return ret;
}
}
Expand Down
1 change: 0 additions & 1 deletion libavformat/libmodplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt)

pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE);
if (pkt->size <= 0) {
av_packet_unref(pkt);
return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO);
}
return 0;
Expand Down
1 change: 0 additions & 1 deletion libavformat/lxfdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ static int lxf_read_packet(AVFormatContext *s, AVPacket *pkt)
return ret2;

if ((ret2 = avio_read(pb, pkt->data, ret)) != ret) {
av_packet_unref(pkt);
return ret2 < 0 ? ret2 : AVERROR_EOF;
}

Expand Down
1 change: 0 additions & 1 deletion libavformat/mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -7890,7 +7890,6 @@ static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)

ret = cenc_filter(mov, st, sc, pkt, current_index);
if (ret < 0) {
av_packet_unref(pkt);
return ret;
}

Expand Down
Loading

0 comments on commit 6a67d51

Please sign in to comment.