Fix segfault when resetting non-looping Vorbis/MPEG files

Also, apparently reset shouldn't reset the streamfiles
This commit is contained in:
bnnm 2017-04-14 01:22:53 +02:00
parent e5f2ab0236
commit 54d1995dc8
3 changed files with 24 additions and 7 deletions

View File

@ -411,7 +411,14 @@ void free_fsb_vorbis(vorbis_codec_data * data) {
}
void reset_fsb_vorbis(VGMSTREAM *vgmstream) {
seek_fsb_vorbis(vgmstream, 0);
#if FSB_VORBIS_ON
vorbis_codec_data *data = vgmstream->codec_data;
/* Seeking is provided by the Ogg layer, so with raw vorbis we need seek tables instead.
* To avoid having to parse different formats we'll just discard until the expected sample */
vorbis_synthesis_restart(&data->vd);
data->samples_to_discard = 0;
#endif
}
void seek_fsb_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
@ -422,7 +429,8 @@ void seek_fsb_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
* To avoid having to parse different formats we'll just discard until the expected sample */
vorbis_synthesis_restart(&data->vd);
data->samples_to_discard = num_sample;
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset;
if (vgmstream->loop_ch)
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset;
#endif
}

View File

@ -685,7 +685,6 @@ void reset_mpeg(VGMSTREAM *vgmstream) {
int i;
for (i=0; i < data->ms_size; i++) {
mpg123_feedseek(data->ms[i],0,SEEK_SET,&input_offset);
vgmstream->loop_ch[i].offset = vgmstream->loop_ch[i].channel_start_offset + input_offset;
}
data->bytes_in_interleave_buffer = 0;
@ -701,13 +700,15 @@ void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
/* seek multistream */
if (!data->interleaved) {
mpg123_feedseek(data->m, num_sample,SEEK_SET,&input_offset);
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset + input_offset;
if (vgmstream->loop_ch)
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset + input_offset;
} else {
int i;
/* re-start from 0 */
for (i=0; i < data->ms_size; i++) {
mpg123_feedseek(data->ms[i],0,SEEK_SET,&input_offset);
vgmstream->loop_ch[i].offset = vgmstream->loop_ch[i].channel_start_offset;
if (vgmstream->loop_ch)
vgmstream->loop_ch[i].offset = vgmstream->loop_ch[i].channel_start_offset;
}
/* manually add skip samples, since we don't really know the correct offset */
data->samples_to_discard = num_sample;

View File

@ -294,7 +294,14 @@ void free_wwise_vorbis(vorbis_codec_data * data) {
}
void reset_wwise_vorbis(VGMSTREAM *vgmstream) {
seek_wwise_vorbis(vgmstream, 0);
#if WWISE_VORBIS_ON
vorbis_codec_data *data = vgmstream->codec_data;
/* Seeking is provided by the Ogg layer, so with raw vorbis we need seek tables instead.
* To avoid having to parse different formats we'll just discard until the expected sample */
vorbis_synthesis_restart(&data->vd);
data->samples_to_discard = 0;
#endif
}
void seek_wwise_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
@ -305,7 +312,8 @@ void seek_wwise_vorbis(VGMSTREAM *vgmstream, int32_t num_sample) {
* To avoid having to parse different formats we'll just discard until the expected sample */
vorbis_synthesis_restart(&data->vd);
data->samples_to_discard = num_sample;
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset;
if (vgmstream->loop_ch) /* this func is only using for looping though */
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset;
#endif
}