mirror of
https://github.com/vgmstream/vgmstream.git
synced 2025-01-17 23:36:41 +01:00
Fix mpeg_bytes_to_samples in newer libmpg123, by saving initial info
This commit is contained in:
parent
c60efdfbdf
commit
48795333e1
@ -177,7 +177,6 @@ void free_mpeg(mpeg_codec_data *data);
|
|||||||
void flush_mpeg(mpeg_codec_data * data);
|
void flush_mpeg(mpeg_codec_data * data);
|
||||||
|
|
||||||
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data);
|
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data);
|
||||||
void mpeg_set_error_logging(mpeg_codec_data * data, int enable);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VGM_USE_G7221
|
#ifdef VGM_USE_G7221
|
||||||
|
@ -101,6 +101,8 @@ mpeg_codec_data *init_mpeg_codec_data(STREAMFILE *streamfile, off_t start_offset
|
|||||||
if (channels_per_frame != channels)
|
if (channels_per_frame != channels)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
|
/* copy current as open_feed may invalidate until data is fed */
|
||||||
|
memcpy(&data->mi, &mi, sizeof(struct mpg123_frameinfo));
|
||||||
|
|
||||||
/* reinit, to ignore the reading done */
|
/* reinit, to ignore the reading done */
|
||||||
mpg123_open_feed(main_m);
|
mpg123_open_feed(main_m);
|
||||||
@ -592,23 +594,20 @@ void flush_mpeg(mpeg_codec_data * data) {
|
|||||||
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data) {
|
long mpeg_bytes_to_samples(long bytes, const mpeg_codec_data *data) {
|
||||||
/* if not found just return 0 and expect to fail (if used for num_samples) */
|
/* if not found just return 0 and expect to fail (if used for num_samples) */
|
||||||
if (!data->custom) {
|
if (!data->custom) {
|
||||||
struct mpg123_frameinfo mi;
|
|
||||||
mpg123_handle *m = data->m;
|
|
||||||
|
|
||||||
if (m == NULL || MPG123_OK != mpg123_info(m, &mi))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* We would need to read all VBR frames headers to count samples */
|
/* We would need to read all VBR frames headers to count samples */
|
||||||
if (mi.vbr != MPG123_CBR) //maybe abr_rate could be used to get an approx
|
if (data->mi.vbr != MPG123_CBR) { //maybe abr_rate could be used to get an approx
|
||||||
|
VGM_LOG("MPEG: vbr mp3 can't do bytes_to_samples\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return (int64_t)bytes * mi.rate * 8 / (mi.bitrate * 1000);
|
return (int64_t)bytes * data->mi.rate * 8 / (data->mi.bitrate * 1000);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0; /* a bit too complex for what is worth */
|
return 0; /* a bit too complex for what is worth */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* disables/enables stderr output, for MPEG known to contain recoverable errors */
|
/* disables/enables stderr output, for MPEG known to contain recoverable errors */
|
||||||
void mpeg_set_error_logging(mpeg_codec_data * data, int enable) {
|
void mpeg_set_error_logging(mpeg_codec_data * data, int enable) {
|
||||||
if (!data->custom) {
|
if (!data->custom) {
|
||||||
@ -621,5 +620,5 @@ void mpeg_set_error_logging(mpeg_codec_data * data, int enable) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
@ -934,6 +934,7 @@ typedef struct {
|
|||||||
int buffer_full; /* raw buffer has been filled */
|
int buffer_full; /* raw buffer has been filled */
|
||||||
int buffer_used; /* raw buffer has been fed to the decoder */
|
int buffer_used; /* raw buffer has been fed to the decoder */
|
||||||
mpg123_handle *m; /* MPEG decoder */
|
mpg123_handle *m; /* MPEG decoder */
|
||||||
|
struct mpg123_frameinfo mi; /* start info, so it's available even when resetting */
|
||||||
|
|
||||||
/* for internal use, assumed to be constant for all frames */
|
/* for internal use, assumed to be constant for all frames */
|
||||||
int channels_per_frame;
|
int channels_per_frame;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user