mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-14 00:58:38 +02:00
avformat/aaxdec: 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:
parent
b09b166829
commit
822be43849
@ -151,26 +151,20 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
a->xcolumns = av_calloc(a->columns, sizeof(*a->xcolumns));
|
a->xcolumns = av_calloc(a->columns, sizeof(*a->xcolumns));
|
||||||
if (!a->xcolumns) {
|
if (!a->xcolumns)
|
||||||
ret = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
a->string_table = av_calloc(a->strings_size + 1, sizeof(*a->string_table));
|
a->string_table = av_calloc(a->strings_size + 1, sizeof(*a->string_table));
|
||||||
if (!a->string_table) {
|
if (!a->string_table)
|
||||||
ret = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int c = 0; c < a->columns; c++) {
|
for (int c = 0; c < a->columns; c++) {
|
||||||
uint8_t info = avio_r8(pb);
|
uint8_t info = avio_r8(pb);
|
||||||
uint32_t offset = avio_rb32(pb);
|
uint32_t offset = avio_rb32(pb);
|
||||||
int value_size;
|
int value_size;
|
||||||
|
|
||||||
if (offset >= a->strings_size) {
|
if (offset >= a->strings_size)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
a->xcolumns[c].flag = info >> 4;
|
a->xcolumns[c].flag = info >> 4;
|
||||||
a->xcolumns[c].type = info & 0x0F;
|
a->xcolumns[c].type = info & 0x0F;
|
||||||
@ -197,8 +191,7 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
value_size = 0x10;
|
value_size = 0x10;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a->xcolumns[c].size = value_size;
|
a->xcolumns[c].size = value_size;
|
||||||
@ -221,14 +214,13 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
|
|
||||||
ret = ret64 = avio_seek(pb, a->strings_offset, SEEK_SET);
|
ret = ret64 = avio_seek(pb, a->strings_offset, SEEK_SET);
|
||||||
if (ret64 < 0)
|
if (ret64 < 0)
|
||||||
goto fail;
|
return ret;
|
||||||
|
|
||||||
ret = avio_read(pb, a->string_table, a->strings_size);
|
ret = avio_read(pb, a->string_table, a->strings_size);
|
||||||
if (ret != a->strings_size) {
|
if (ret != a->strings_size) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto fail;
|
return ret;
|
||||||
ret = AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c = 0; c < a->columns; c++) {
|
for (int c = 0; c < a->columns; c++) {
|
||||||
@ -248,14 +240,12 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
data_offset = a->schema_offset + col_offset;
|
data_offset = a->schema_offset + col_offset;
|
||||||
} else if (flag & COLUMN_FLAG_ROW) {
|
} else if (flag & COLUMN_FLAG_ROW) {
|
||||||
data_offset = a->rows_offset + r * a->row_width + col_offset;
|
data_offset = a->rows_offset + r * a->row_width + col_offset;
|
||||||
} else {
|
} else
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = ret64 = avio_seek(pb, data_offset, SEEK_SET);
|
ret = ret64 = avio_seek(pb, data_offset, SEEK_SET);
|
||||||
if (ret64 < 0)
|
if (ret64 < 0)
|
||||||
goto fail;
|
return ret;
|
||||||
|
|
||||||
if (type == COLUMN_TYPE_VLDATA) {
|
if (type == COLUMN_TYPE_VLDATA) {
|
||||||
int64_t start, size;
|
int64_t start, size;
|
||||||
@ -264,23 +254,17 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
size = avio_rb32(pb);
|
size = avio_rb32(pb);
|
||||||
a->segments[r].start = start + a->data_offset;
|
a->segments[r].start = start + a->data_offset;
|
||||||
a->segments[r].end = a->segments[r].start + size;
|
a->segments[r].end = a->segments[r].start + size;
|
||||||
} else {
|
} else
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!a->segments[0].end) {
|
if (!a->segments[0].end)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
st = avformat_new_stream(s, NULL);
|
st = avformat_new_stream(s, NULL);
|
||||||
if (!st) {
|
if (!st)
|
||||||
ret = AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
st->start_time = 0;
|
st->start_time = 0;
|
||||||
par = s->streams[0]->codecpar;
|
par = s->streams[0]->codecpar;
|
||||||
par->codec_type = AVMEDIA_TYPE_AUDIO;
|
par->codec_type = AVMEDIA_TYPE_AUDIO;
|
||||||
@ -289,42 +273,28 @@ static int aax_read_header(AVFormatContext *s)
|
|||||||
if (!strcmp(codec, "AAX")) {
|
if (!strcmp(codec, "AAX")) {
|
||||||
par->codec_id = AV_CODEC_ID_ADPCM_ADX;
|
par->codec_id = AV_CODEC_ID_ADPCM_ADX;
|
||||||
ret64 = avio_seek(pb, a->segments[0].start, SEEK_SET);
|
ret64 = avio_seek(pb, a->segments[0].start, SEEK_SET);
|
||||||
if (ret64 < 0 || avio_rb16(pb) != 0x8000) {
|
if (ret64 < 0 || avio_rb16(pb) != 0x8000)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
extradata_size = avio_rb16(pb) + 4;
|
extradata_size = avio_rb16(pb) + 4;
|
||||||
if (extradata_size < 12) {
|
if (extradata_size < 12)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
avio_seek(pb, -4, SEEK_CUR);
|
avio_seek(pb, -4, SEEK_CUR);
|
||||||
ret = ff_get_extradata(s, par, pb, extradata_size);
|
ret = ff_get_extradata(s, par, pb, extradata_size);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
goto fail;
|
return ret;
|
||||||
}
|
|
||||||
par->channels = AV_RB8 (par->extradata + 7);
|
par->channels = AV_RB8 (par->extradata + 7);
|
||||||
par->sample_rate = AV_RB32(par->extradata + 8);
|
par->sample_rate = AV_RB32(par->extradata + 8);
|
||||||
if (!par->channels || !par->sample_rate) {
|
if (!par->channels || !par->sample_rate)
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
avpriv_set_pts_info(st, 64, 32, par->sample_rate);
|
avpriv_set_pts_info(st, 64, 32, par->sample_rate);
|
||||||
/*} else if (!strcmp(codec, "HCA") ){
|
/*} else if (!strcmp(codec, "HCA") ){
|
||||||
par->codec_id = AV_CODEC_ID_HCA;*/
|
par->codec_id = AV_CODEC_ID_HCA;*/
|
||||||
} else {
|
} else {
|
||||||
ret = AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
goto fail;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
fail:
|
|
||||||
av_freep(&a->string_table);
|
|
||||||
av_freep(&a->xcolumns);
|
|
||||||
av_freep(&a->segments);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aax_read_packet(AVFormatContext *s, AVPacket *pkt)
|
static int aax_read_packet(AVFormatContext *s, AVPacket *pkt)
|
||||||
@ -413,6 +383,7 @@ const AVInputFormat ff_aax_demuxer = {
|
|||||||
.name = "aax",
|
.name = "aax",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("CRI AAX"),
|
.long_name = NULL_IF_CONFIG_SMALL("CRI AAX"),
|
||||||
.priv_data_size = sizeof(AAXContext),
|
.priv_data_size = sizeof(AAXContext),
|
||||||
|
.flags_internal = FF_FMT_INIT_CLEANUP,
|
||||||
.read_probe = aax_probe,
|
.read_probe = aax_probe,
|
||||||
.read_header = aax_read_header,
|
.read_header = aax_read_header,
|
||||||
.read_packet = aax_read_packet,
|
.read_packet = aax_read_packet,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user