Fix AWC MPEG not seeking back correctly

This commit is contained in:
bnnm 2018-12-28 11:04:18 +01:00
parent 1bd12e54c2
commit fa2f95739a

View File

@ -503,24 +503,29 @@ void free_mpeg(mpeg_codec_data *data) {
* someone else in another thread is using it. */
}
/* seeks stream to 0 */
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
if (!data->custom) {
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
mpg123_feedseek(data->m,0,SEEK_SET,&input_offset);
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
}
else {
int i;
/* re-start from 0 */
for (i=0; i < data->streams_size; i++) {
for (i = 0; i < data->streams_size; i++) {
mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset);
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
}
@ -528,29 +533,33 @@ void reset_mpeg(VGMSTREAM *vgmstream) {
}
}
/* seeks to a point */
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) {
mpg123_feedseek(data->m, num_sample,SEEK_SET,&input_offset);
/* force first offset as discard-looping needs to start from the beginning */
/* adjust loop with mpg123's offset (useful?) */
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->streams_size; i++) {
for (i = 0; i < data->streams_size; i++) {
mpg123_feedseek(data->streams[i]->m,0,SEEK_SET,&input_offset);
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->decode_to_discard = 0;
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
/* force first offset as discard-looping needs to start from the beginning */
if (vgmstream->loop_ch)
@ -562,33 +571,36 @@ void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
data->samples_to_discard += data->skip_samples;
}
data->bytes_in_buffer = 0;
data->buffer_full = 0;
data->buffer_used = 0;
}
/* resets mpg123 decoder and its internals (with mpg123_open_feed as mpg123_feedseek won't work) */
/* resets mpg123 decoder and its internals without seeking, useful when a new MPEG substream starts */
void flush_mpeg(mpeg_codec_data * data) {
if (!data)
return;
if (!data->custom) {
/* input_offset is ignored as we can assume it will be 0 for a seek to sample 0 */
mpg123_open_feed(data->m);
mpg123_open_feed(data->m); /* mpg123_feedseek won't work */
}
else {
int i;
/* re-start from 0 */
for (i=0; i < data->streams_size; i++) {
mpg123_open_feed(data->streams[i]->m);
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->decode_to_discard = 0;
data->streams[i]->bytes_in_buffer = 0;
data->streams[i]->buffer_full = 0;
data->streams[i]->buffer_used = 0;
data->streams[i]->samples_filled = 0;
data->streams[i]->samples_used = 0;
data->streams[i]->current_size_count = 0;
data->streams[i]->current_size_target = 0;
data->streams[i]->decode_to_discard = 0;
}
data->samples_to_discard = data->skip_samples; /* initial delay */
data->samples_to_discard = data->skip_samples;
}
data->bytes_in_buffer = 0;