Add check when calling free/seek/reset codec

It's possible to set a "coding" that triggers calls to the above while
codec_data is still null, when using special layouts like AAX
This commit is contained in:
bnnm 2018-03-10 16:59:00 +01:00
parent 693fbf8e3b
commit 3ad6261208
11 changed files with 32 additions and 6 deletions

View File

@ -51,6 +51,7 @@ void decode_at3plus(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing,
void reset_at3plus(VGMSTREAM *vgmstream) {
maiatrac3plus_codec_data *data = vgmstream->codec_data;
if (!data) return;
if (data->handle)
Atrac3plusDecoder_closeContext(data->handle);
@ -62,6 +63,8 @@ void seek_at3plus(VGMSTREAM *vgmstream, int32_t num_sample) {
int blocks_to_skip = num_sample / 2048;
int samples_to_discard = num_sample % 2048;
maiatrac3plus_codec_data *data = (maiatrac3plus_codec_data *)(vgmstream->codec_data);
if (!data) return;
vgmstream->loop_ch[0].offset =
vgmstream->loop_ch[0].channel_start_offset +
vgmstream->interleave_block_size * blocks_to_skip;

View File

@ -152,6 +152,7 @@ decode_fail:
void reset_atrac9(VGMSTREAM *vgmstream) {
atrac9_codec_data *data = vgmstream->codec_data;
if (!data) return;
if (!data->handle)
goto fail;
@ -184,6 +185,7 @@ fail:
void seek_atrac9(VGMSTREAM *vgmstream, int32_t num_sample) {
atrac9_codec_data *data = vgmstream->codec_data;
if (!data) return;
reset_atrac9(vgmstream);
@ -196,8 +198,7 @@ void seek_atrac9(VGMSTREAM *vgmstream, int32_t num_sample) {
}
void free_atrac9(atrac9_codec_data *data) {
if (!data)
return;
if (!data) return;
if (data->handle) Atrac9ReleaseHandle(data->handle);
free(data->data_buffer);

View File

@ -534,6 +534,8 @@ static void flush_ea_mt_internal(VGMSTREAM *vgmstream, int is_start) {
int i;
size_t bytes;
if (!data) return;
/* the decoder needs to be notified when offsets change */
for (i = 0; i < vgmstream->channels; i++) {
UTKContext *ctx = data->utk_context[i];

View File

@ -706,6 +706,7 @@ end:
void reset_ffmpeg(VGMSTREAM *vgmstream) {
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
if (!data) return;
if (data->formatCtx) {
avformat_seek_file(data->formatCtx, data->streamIndex, 0, 0, 0, AVSEEK_FLAG_ANY);
@ -733,6 +734,7 @@ void reset_ffmpeg(VGMSTREAM *vgmstream) {
void seek_ffmpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
int64_t ts;
if (!data) return;
/* Start from 0 and discard samples until loop_start (slower but not too noticeable).
* Due to various FFmpeg quirks seeking to a sample is erratic in many formats (would need extra steps). */

View File

@ -53,6 +53,7 @@ void decode_g719(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int
void reset_g719(VGMSTREAM *vgmstream) {
g719_codec_data *data = vgmstream->codec_data;
int i;
if (!data) return;
for (i = 0; i < vgmstream->channels; i++)
{

View File

@ -52,6 +52,7 @@ void decode_g7221(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, in
void reset_g7221(VGMSTREAM *vgmstream) {
g7221_codec_data *data = vgmstream->codec_data;
int i;
if (!data) return;
for (i = 0; i < vgmstream->channels; i++)
{

View File

@ -2,7 +2,6 @@
void decode_hca(hca_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels) {
int samples_done = 0;
int32_t samples_remain = clHCA_samplesPerBlock - data->sample_ptr;
void *hca_data = NULL;
@ -84,7 +83,8 @@ void decode_hca(hca_codec_data * data, sample * outbuf, int32_t samples_to_do, i
void reset_hca(VGMSTREAM *vgmstream) {
hca_codec_data *data = vgmstream->codec_data;
/*clHCA *hca = (clHCA *)(data + 1);*/
if (!data) return;
data->curblock = 0;
data->sample_ptr = clHCA_samplesPerBlock;
data->samples_discard = 0;
@ -92,6 +92,8 @@ void reset_hca(VGMSTREAM *vgmstream) {
void loop_hca(VGMSTREAM *vgmstream) {
hca_codec_data *data = (hca_codec_data *)(vgmstream->codec_data);
if (!data) return;
data->curblock = data->info.loopStart;
data->sample_ptr = clHCA_samplesPerBlock;
data->samples_discard = 0;

View File

@ -86,6 +86,8 @@ void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_
void reset_mp4_aac(VGMSTREAM *vgmstream) {
mp4_aac_codec_data *data = vgmstream->codec_data;
if (!data) return;
data->sampleId = 0;
data->sample_ptr = data->samples_per_frame;
data->samples_discard = 0;
@ -93,6 +95,8 @@ void reset_mp4_aac(VGMSTREAM *vgmstream) {
void seek_mp4_aac(VGMSTREAM *vgmstream, int32_t num_sample) {
mp4_aac_codec_data *data = (mp4_aac_codec_data *)(vgmstream->codec_data);
if (!data) return;
data->sampleId = 0;
data->sample_ptr = data->samples_per_frame;
data->samples_discard = num_sample;

View File

@ -500,6 +500,7 @@ void free_mpeg(mpeg_codec_data *data) {
void reset_mpeg(VGMSTREAM *vgmstream) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* reset multistream */ //todo check if stream offsets are properly reset
@ -524,6 +525,7 @@ void reset_mpeg(VGMSTREAM *vgmstream) {
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* seek multistream */
if (!data->custom) {

View File

@ -22,15 +22,21 @@ void decode_ogg_vorbis(ogg_vorbis_codec_data * data, sample * outbuf, int32_t sa
void reset_ogg_vorbis(VGMSTREAM *vgmstream) {
OggVorbis_File *ogg_vorbis_file;
ogg_vorbis_codec_data *data = vgmstream->codec_data;
OggVorbis_File *ogg_vorbis_file = &(data->ogg_vorbis_file);
if (!data) return;
ogg_vorbis_file = &(data->ogg_vorbis_file);
ov_pcm_seek(ogg_vorbis_file, 0);
}
void seek_ogg_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
OggVorbis_File *ogg_vorbis_file;
ogg_vorbis_codec_data *data = (ogg_vorbis_codec_data *)(vgmstream->codec_data);
OggVorbis_File *ogg_vorbis_file = &(data->ogg_vorbis_file);
if (!data) return;
ogg_vorbis_file = &(data->ogg_vorbis_file);
ov_pcm_seek_lap(ogg_vorbis_file, num_sample);
}

View File

@ -207,6 +207,7 @@ void free_vorbis_custom(vorbis_custom_codec_data * data) {
void reset_vorbis_custom(VGMSTREAM *vgmstream) {
vorbis_custom_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* Seeking is provided by the Ogg layer, so with custom vorbis we'd need seek tables instead.
* To avoid having to parse different formats we'll just discard until the expected sample */
@ -216,6 +217,7 @@ void reset_vorbis_custom(VGMSTREAM *vgmstream) {
void seek_vorbis_custom(VGMSTREAM *vgmstream, int32_t num_sample) {
vorbis_custom_codec_data *data = vgmstream->codec_data;
if (!data) return;
/* Seeking is provided by the Ogg layer, so with custom vorbis we'd need seek tables instead.
* To avoid having to parse different formats we'll just discard until the expected sample */