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

avformat/pp_bnk: Simplify cleanup after read_header failure

by setting the FF_FMT_INIT_CLEANUP flag.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2020-03-21 18:31:06 +01:00
parent ae123057a3
commit b00c9c74af

View File

@ -144,7 +144,7 @@ static int pp_bnk_read_header(AVFormatContext *s)
ret = avio_read(s->pb, buf, PP_BNK_TRACK_SIZE); ret = avio_read(s->pb, buf, PP_BNK_TRACK_SIZE);
if (ret < 0 && ret != AVERROR_EOF) if (ret < 0 && ret != AVERROR_EOF)
goto fail; return ret;
/* Short byte-count or EOF, we have a truncated file. */ /* Short byte-count or EOF, we have a truncated file. */
if (ret != PP_BNK_TRACK_SIZE) { if (ret != PP_BNK_TRACK_SIZE) {
@ -157,15 +157,12 @@ static int pp_bnk_read_header(AVFormatContext *s)
pp_bnk_parse_track(&e, buf); pp_bnk_parse_track(&e, buf);
/* The individual sample rates of all tracks must match that of the file header. */ /* The individual sample rates of all tracks must match that of the file header. */
if (e.sample_rate != hdr.sample_rate) { if (e.sample_rate != hdr.sample_rate)
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto fail;
}
if (e.always1_1 != 1 || e.always1_2 != 1) { if (e.always1_1 != 1 || e.always1_2 != 1) {
avpriv_request_sample(s, "Non-one track header values"); avpriv_request_sample(s, "Non-one track header values");
ret = AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
goto fail;
} }
trk->data_offset = avio_tell(s->pb); trk->data_offset = avio_tell(s->pb);
@ -185,15 +182,13 @@ static int pp_bnk_read_header(AVFormatContext *s)
i, ctx->track_count); i, ctx->track_count);
break; break;
} else if (ret < 0) { } else if (ret < 0) {
goto fail; return ret;
} }
} }
/* File is only a header. */ /* File is only a header. */
if (ctx->track_count == 0) { if (ctx->track_count == 0)
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto fail;
}
ctx->is_music = (hdr.flags & PP_BNK_FLAG_MUSIC) && ctx->is_music = (hdr.flags & PP_BNK_FLAG_MUSIC) &&
(ctx->track_count == 2) && (ctx->track_count == 2) &&
@ -201,10 +196,8 @@ static int pp_bnk_read_header(AVFormatContext *s)
/* Build the streams. */ /* Build the streams. */
for (int i = 0; i < (ctx->is_music ? 1 : ctx->track_count); i++) { for (int i = 0; i < (ctx->is_music ? 1 : ctx->track_count); i++) {
if (!(st = avformat_new_stream(s, NULL))) { if (!(st = avformat_new_stream(s, NULL)))
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
}
par = st->codecpar; par = st->codecpar;
par->codec_type = AVMEDIA_TYPE_AUDIO; par->codec_type = AVMEDIA_TYPE_AUDIO;
@ -231,10 +224,6 @@ static int pp_bnk_read_header(AVFormatContext *s)
} }
return 0; return 0;
fail:
av_freep(&ctx->tracks);
return ret;
} }
static int pp_bnk_read_packet(AVFormatContext *s, AVPacket *pkt) static int pp_bnk_read_packet(AVFormatContext *s, AVPacket *pkt)
@ -336,6 +325,7 @@ const AVInputFormat ff_pp_bnk_demuxer = {
.name = "pp_bnk", .name = "pp_bnk",
.long_name = NULL_IF_CONFIG_SMALL("Pro Pinball Series Soundbank"), .long_name = NULL_IF_CONFIG_SMALL("Pro Pinball Series Soundbank"),
.priv_data_size = sizeof(PPBnkCtx), .priv_data_size = sizeof(PPBnkCtx),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = pp_bnk_probe, .read_probe = pp_bnk_probe,
.read_header = pp_bnk_read_header, .read_header = pp_bnk_read_header,
.read_packet = pp_bnk_read_packet, .read_packet = pp_bnk_read_packet,