mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
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:
parent
693fbf8e3b
commit
3ad6261208
@ -51,6 +51,7 @@ void decode_at3plus(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing,
|
|||||||
|
|
||||||
void reset_at3plus(VGMSTREAM *vgmstream) {
|
void reset_at3plus(VGMSTREAM *vgmstream) {
|
||||||
maiatrac3plus_codec_data *data = vgmstream->codec_data;
|
maiatrac3plus_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
if (data->handle)
|
if (data->handle)
|
||||||
Atrac3plusDecoder_closeContext(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 blocks_to_skip = num_sample / 2048;
|
||||||
int samples_to_discard = num_sample % 2048;
|
int samples_to_discard = num_sample % 2048;
|
||||||
maiatrac3plus_codec_data *data = (maiatrac3plus_codec_data *)(vgmstream->codec_data);
|
maiatrac3plus_codec_data *data = (maiatrac3plus_codec_data *)(vgmstream->codec_data);
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
vgmstream->loop_ch[0].offset =
|
vgmstream->loop_ch[0].offset =
|
||||||
vgmstream->loop_ch[0].channel_start_offset +
|
vgmstream->loop_ch[0].channel_start_offset +
|
||||||
vgmstream->interleave_block_size * blocks_to_skip;
|
vgmstream->interleave_block_size * blocks_to_skip;
|
||||||
|
@ -152,6 +152,7 @@ decode_fail:
|
|||||||
|
|
||||||
void reset_atrac9(VGMSTREAM *vgmstream) {
|
void reset_atrac9(VGMSTREAM *vgmstream) {
|
||||||
atrac9_codec_data *data = vgmstream->codec_data;
|
atrac9_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
if (!data->handle)
|
if (!data->handle)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -184,6 +185,7 @@ fail:
|
|||||||
|
|
||||||
void seek_atrac9(VGMSTREAM *vgmstream, int32_t num_sample) {
|
void seek_atrac9(VGMSTREAM *vgmstream, int32_t num_sample) {
|
||||||
atrac9_codec_data *data = vgmstream->codec_data;
|
atrac9_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
reset_atrac9(vgmstream);
|
reset_atrac9(vgmstream);
|
||||||
|
|
||||||
@ -196,8 +198,7 @@ void seek_atrac9(VGMSTREAM *vgmstream, int32_t num_sample) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void free_atrac9(atrac9_codec_data *data) {
|
void free_atrac9(atrac9_codec_data *data) {
|
||||||
if (!data)
|
if (!data) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (data->handle) Atrac9ReleaseHandle(data->handle);
|
if (data->handle) Atrac9ReleaseHandle(data->handle);
|
||||||
free(data->data_buffer);
|
free(data->data_buffer);
|
||||||
|
@ -534,6 +534,8 @@ static void flush_ea_mt_internal(VGMSTREAM *vgmstream, int is_start) {
|
|||||||
int i;
|
int i;
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
|
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
/* the decoder needs to be notified when offsets change */
|
/* the decoder needs to be notified when offsets change */
|
||||||
for (i = 0; i < vgmstream->channels; i++) {
|
for (i = 0; i < vgmstream->channels; i++) {
|
||||||
UTKContext *ctx = data->utk_context[i];
|
UTKContext *ctx = data->utk_context[i];
|
||||||
|
@ -706,6 +706,7 @@ end:
|
|||||||
|
|
||||||
void reset_ffmpeg(VGMSTREAM *vgmstream) {
|
void reset_ffmpeg(VGMSTREAM *vgmstream) {
|
||||||
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
if (data->formatCtx) {
|
if (data->formatCtx) {
|
||||||
avformat_seek_file(data->formatCtx, data->streamIndex, 0, 0, 0, AVSEEK_FLAG_ANY);
|
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) {
|
void seek_ffmpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
|
||||||
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
ffmpeg_codec_data *data = (ffmpeg_codec_data *) vgmstream->codec_data;
|
||||||
int64_t ts;
|
int64_t ts;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
/* Start from 0 and discard samples until loop_start (slower but not too noticeable).
|
/* 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). */
|
* Due to various FFmpeg quirks seeking to a sample is erratic in many formats (would need extra steps). */
|
||||||
|
@ -53,6 +53,7 @@ void decode_g719(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, int
|
|||||||
void reset_g719(VGMSTREAM *vgmstream) {
|
void reset_g719(VGMSTREAM *vgmstream) {
|
||||||
g719_codec_data *data = vgmstream->codec_data;
|
g719_codec_data *data = vgmstream->codec_data;
|
||||||
int i;
|
int i;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
for (i = 0; i < vgmstream->channels; i++)
|
for (i = 0; i < vgmstream->channels; i++)
|
||||||
{
|
{
|
||||||
|
@ -52,6 +52,7 @@ void decode_g7221(VGMSTREAM * vgmstream, sample * outbuf, int channelspacing, in
|
|||||||
void reset_g7221(VGMSTREAM *vgmstream) {
|
void reset_g7221(VGMSTREAM *vgmstream) {
|
||||||
g7221_codec_data *data = vgmstream->codec_data;
|
g7221_codec_data *data = vgmstream->codec_data;
|
||||||
int i;
|
int i;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
for (i = 0; i < vgmstream->channels; i++)
|
for (i = 0; i < vgmstream->channels; i++)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
void decode_hca(hca_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels) {
|
void decode_hca(hca_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels) {
|
||||||
int samples_done = 0;
|
int samples_done = 0;
|
||||||
|
|
||||||
int32_t samples_remain = clHCA_samplesPerBlock - data->sample_ptr;
|
int32_t samples_remain = clHCA_samplesPerBlock - data->sample_ptr;
|
||||||
|
|
||||||
void *hca_data = NULL;
|
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) {
|
void reset_hca(VGMSTREAM *vgmstream) {
|
||||||
hca_codec_data *data = vgmstream->codec_data;
|
hca_codec_data *data = vgmstream->codec_data;
|
||||||
/*clHCA *hca = (clHCA *)(data + 1);*/
|
if (!data) return;
|
||||||
|
|
||||||
data->curblock = 0;
|
data->curblock = 0;
|
||||||
data->sample_ptr = clHCA_samplesPerBlock;
|
data->sample_ptr = clHCA_samplesPerBlock;
|
||||||
data->samples_discard = 0;
|
data->samples_discard = 0;
|
||||||
@ -92,6 +92,8 @@ void reset_hca(VGMSTREAM *vgmstream) {
|
|||||||
|
|
||||||
void loop_hca(VGMSTREAM *vgmstream) {
|
void loop_hca(VGMSTREAM *vgmstream) {
|
||||||
hca_codec_data *data = (hca_codec_data *)(vgmstream->codec_data);
|
hca_codec_data *data = (hca_codec_data *)(vgmstream->codec_data);
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
data->curblock = data->info.loopStart;
|
data->curblock = data->info.loopStart;
|
||||||
data->sample_ptr = clHCA_samplesPerBlock;
|
data->sample_ptr = clHCA_samplesPerBlock;
|
||||||
data->samples_discard = 0;
|
data->samples_discard = 0;
|
||||||
|
@ -86,6 +86,8 @@ void decode_mp4_aac(mp4_aac_codec_data * data, sample * outbuf, int32_t samples_
|
|||||||
|
|
||||||
void reset_mp4_aac(VGMSTREAM *vgmstream) {
|
void reset_mp4_aac(VGMSTREAM *vgmstream) {
|
||||||
mp4_aac_codec_data *data = vgmstream->codec_data;
|
mp4_aac_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
data->sampleId = 0;
|
data->sampleId = 0;
|
||||||
data->sample_ptr = data->samples_per_frame;
|
data->sample_ptr = data->samples_per_frame;
|
||||||
data->samples_discard = 0;
|
data->samples_discard = 0;
|
||||||
@ -93,6 +95,8 @@ void reset_mp4_aac(VGMSTREAM *vgmstream) {
|
|||||||
|
|
||||||
void seek_mp4_aac(VGMSTREAM *vgmstream, int32_t num_sample) {
|
void seek_mp4_aac(VGMSTREAM *vgmstream, int32_t num_sample) {
|
||||||
mp4_aac_codec_data *data = (mp4_aac_codec_data *)(vgmstream->codec_data);
|
mp4_aac_codec_data *data = (mp4_aac_codec_data *)(vgmstream->codec_data);
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
data->sampleId = 0;
|
data->sampleId = 0;
|
||||||
data->sample_ptr = data->samples_per_frame;
|
data->sample_ptr = data->samples_per_frame;
|
||||||
data->samples_discard = num_sample;
|
data->samples_discard = num_sample;
|
||||||
|
@ -500,6 +500,7 @@ void free_mpeg(mpeg_codec_data *data) {
|
|||||||
void reset_mpeg(VGMSTREAM *vgmstream) {
|
void reset_mpeg(VGMSTREAM *vgmstream) {
|
||||||
off_t input_offset;
|
off_t input_offset;
|
||||||
mpeg_codec_data *data = vgmstream->codec_data;
|
mpeg_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
/* reset multistream */ //todo check if stream offsets are properly reset
|
/* 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) {
|
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
|
||||||
off_t input_offset;
|
off_t input_offset;
|
||||||
mpeg_codec_data *data = vgmstream->codec_data;
|
mpeg_codec_data *data = vgmstream->codec_data;
|
||||||
|
if (!data) return;
|
||||||
|
|
||||||
/* seek multistream */
|
/* seek multistream */
|
||||||
if (!data->custom) {
|
if (!data->custom) {
|
||||||
|
@ -22,15 +22,21 @@ void decode_ogg_vorbis(ogg_vorbis_codec_data * data, sample * outbuf, int32_t sa
|
|||||||
|
|
||||||
|
|
||||||
void reset_ogg_vorbis(VGMSTREAM *vgmstream) {
|
void reset_ogg_vorbis(VGMSTREAM *vgmstream) {
|
||||||
|
OggVorbis_File *ogg_vorbis_file;
|
||||||
ogg_vorbis_codec_data *data = vgmstream->codec_data;
|
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);
|
ov_pcm_seek(ogg_vorbis_file, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void seek_ogg_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
|
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);
|
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);
|
ov_pcm_seek_lap(ogg_vorbis_file, num_sample);
|
||||||
}
|
}
|
||||||
|
@ -207,6 +207,7 @@ void free_vorbis_custom(vorbis_custom_codec_data * data) {
|
|||||||
|
|
||||||
void reset_vorbis_custom(VGMSTREAM *vgmstream) {
|
void reset_vorbis_custom(VGMSTREAM *vgmstream) {
|
||||||
vorbis_custom_codec_data *data = vgmstream->codec_data;
|
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.
|
/* 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 */
|
* 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) {
|
void seek_vorbis_custom(VGMSTREAM *vgmstream, int32_t num_sample) {
|
||||||
vorbis_custom_codec_data *data = vgmstream->codec_data;
|
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.
|
/* 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 */
|
* To avoid having to parse different formats we'll just discard until the expected sample */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user