Move reset/seek/free MPEG code to mpeg_decoder (for later changes)

This commit is contained in:
bnnm 2017-02-17 17:20:40 +01:00
parent a7982bc743
commit df84602e85
3 changed files with 47 additions and 29 deletions

View File

@ -120,8 +120,14 @@ void decode_ogg_vorbis(ogg_vorbis_codec_data * data, sample * outbuf, int32_t sa
/* mpeg_decoder */
#ifdef VGM_USE_MPEG
mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset, long given_sample_rate, int given_channels, coding_t *coding_type, int * actual_sample_rate, int * actual_channels);
void decode_fake_mpeg2_l2(VGMSTREAMCHANNEL * stream, mpeg_codec_data * data, sample * outbuf, int32_t samples_to_do);
void decode_mpeg(VGMSTREAMCHANNEL * stream, mpeg_codec_data * data, sample * outbuf, int32_t samples_to_do, int channels);
void decode_fake_mpeg2_l2(VGMSTREAMCHANNEL * stream, mpeg_codec_data * data, sample * outbuf, int32_t samples_to_do);
void free_mpeg(mpeg_codec_data *data);
void reset_mpeg(VGMSTREAM *vgmstream);
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample);
long mpeg_bytes_to_samples(long bytes, const struct mpg123_frameinfo *mi);
void mpeg_set_error_logging(mpeg_codec_data * data, int enable);
#endif

View File

@ -222,11 +222,46 @@ void decode_mpeg(VGMSTREAMCHANNEL *stream,
}
}
void free_mpeg(mpeg_codec_data *data) {
if (!data)
return;
mpg123_delete(data->m);
free(data);
/* The astute reader will note that a call to mpg123_exit is never
* made. While is is evilly breaking our contract with mpg123, it
* doesn't actually do anything except set the "initialized" flag
* to 0. And if we exit we run the risk of turning it off when
* someone else in another thread is using it. */
}
void reset_mpeg(VGMSTREAM *vgmstream) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
/* 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);
data->buffer_full = data->buffer_used = 0;
}
void seek_mpeg(VGMSTREAM *vgmstream, int32_t num_sample) {
/* won't work for fake MPEG */
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
mpg123_feedseek(data->m, num_sample,SEEK_SET,&input_offset);
vgmstream->loop_ch[0].offset = vgmstream->loop_ch[0].channel_start_offset + input_offset;
data->buffer_full = 0;
data->buffer_used = 0;
}
long mpeg_bytes_to_samples(long bytes, const struct mpg123_frameinfo *mi) {
return (int64_t)bytes * mi->rate * 8 / (mi->bitrate * 1000);
}
/**
* disables/enables stderr output, useful for MPEG known to contain recoverable errors
*/

View File

@ -478,13 +478,7 @@ void reset_vgmstream(VGMSTREAM * vgmstream) {
#ifdef VGM_USE_MPEG
if (vgmstream->layout_type==layout_mpeg ||
vgmstream->layout_type==layout_fake_mpeg) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
/* 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);
data->buffer_full = data->buffer_used = 0;
reset_mpeg(vgmstream);
}
#endif
#ifdef VGM_USE_G7221
@ -702,18 +696,8 @@ void close_vgmstream(VGMSTREAM * vgmstream) {
#ifdef VGM_USE_MPEG
if (vgmstream->layout_type==layout_fake_mpeg||
vgmstream->layout_type==layout_mpeg) {
mpeg_codec_data *data = (mpeg_codec_data *) vgmstream->codec_data;
if (data) {
mpg123_delete(data->m);
free(vgmstream->codec_data);
vgmstream->codec_data = NULL;
/* The astute reader will note that a call to mpg123_exit is never
* made. While is is evilly breaking our contract with mpg123, it
* doesn't actually do anything except set the "initialized" flag
* to 0. And if we exit we run the risk of turning it off when
* someone else in another thread is using it. */
}
free_mpeg((mpeg_codec_data *)vgmstream->codec_data);
vgmstream->codec_data = NULL;
}
#endif
@ -1813,14 +1797,7 @@ int vgmstream_do_loop(VGMSTREAM * vgmstream) {
#ifdef VGM_USE_MPEG
/* won't work for fake MPEG */
if (vgmstream->layout_type==layout_mpeg) {
off_t input_offset;
mpeg_codec_data *data = vgmstream->codec_data;
mpg123_feedseek(data->m,vgmstream->loop_sample,
SEEK_SET,&input_offset);
vgmstream->loop_ch[0].offset =
vgmstream->loop_ch[0].channel_start_offset + input_offset;
data->buffer_full = data->buffer_used = 0;
seek_mpeg(vgmstream, vgmstream->loop_sample);
}
#endif