decoder/vorbis: initialize before entering the loop
Call decoder_initialize() before entering the loop. We don't need to call ov_read() before ov_info(). When the stream number changes, check if the audio format is still the same.
This commit is contained in:
parent
4f38cc9cae
commit
4c6a8e3ca5
@ -271,6 +271,7 @@ vorbis_stream_decode(struct decoder *decoder,
|
|||||||
ov_callbacks callbacks;
|
ov_callbacks callbacks;
|
||||||
struct vorbis_decoder_data data;
|
struct vorbis_decoder_data data;
|
||||||
struct audio_format audio_format;
|
struct audio_format audio_format;
|
||||||
|
float total_time;
|
||||||
int current_section;
|
int current_section;
|
||||||
int prev_section = -1;
|
int prev_section = -1;
|
||||||
long ret;
|
long ret;
|
||||||
@ -278,8 +279,7 @@ vorbis_stream_decode(struct decoder *decoder,
|
|||||||
long bitRate = 0;
|
long bitRate = 0;
|
||||||
long test;
|
long test;
|
||||||
struct replay_gain_info *replay_gain_info = NULL;
|
struct replay_gain_info *replay_gain_info = NULL;
|
||||||
char **comments;
|
const vorbis_info *vi;
|
||||||
bool initialized = false;
|
|
||||||
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
||||||
|
|
||||||
if (ogg_stream_type_detect(input_stream) != VORBIS)
|
if (ogg_stream_type_detect(input_stream) != VORBIS)
|
||||||
@ -306,6 +306,28 @@ vorbis_stream_decode(struct decoder *decoder,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vi = ov_info(&vf, -1);
|
||||||
|
if (vi == NULL) {
|
||||||
|
g_warning("ov_info() has failed");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
audio_format_init(&audio_format, vi->rate, 16, vi->channels);
|
||||||
|
|
||||||
|
if (!audio_format_valid(&audio_format)) {
|
||||||
|
g_warning("Invalid audio format: %u:%u:%u\n",
|
||||||
|
audio_format.sample_rate,
|
||||||
|
audio_format.bits,
|
||||||
|
audio_format.channels);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
total_time = ov_time_total(&vf, -1);
|
||||||
|
if (total_time < 0)
|
||||||
|
total_time = 0;
|
||||||
|
|
||||||
|
decoder_initialized(decoder, &audio_format, data.seekable, total_time);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (cmd == DECODE_COMMAND_SEEK) {
|
if (cmd == DECODE_COMMAND_SEEK) {
|
||||||
double seek_where = decoder_seek_where(decoder);
|
double seek_where = decoder_seek_where(decoder);
|
||||||
@ -324,29 +346,23 @@ vorbis_stream_decode(struct decoder *decoder,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (current_section != prev_section) {
|
if (current_section != prev_section) {
|
||||||
/*printf("new song!\n"); */
|
char **comments;
|
||||||
vorbis_info *vi = ov_info(&vf, -1);
|
|
||||||
struct replay_gain_info *new_rgi;
|
struct replay_gain_info *new_rgi;
|
||||||
|
|
||||||
audio_format_init(&audio_format, vi->rate, 16, vi->channels);
|
vi = ov_info(&vf, -1);
|
||||||
|
if (vi == NULL) {
|
||||||
if (!audio_format_valid(&audio_format)) {
|
g_warning("ov_info() has failed");
|
||||||
g_warning("Invalid audio format: %u:%u:%u\n",
|
|
||||||
audio_format.sample_rate,
|
|
||||||
audio_format.bits,
|
|
||||||
audio_format.channels);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!initialized) {
|
if (vi->rate != audio_format.sample_rate ||
|
||||||
float total_time = ov_time_total(&vf, -1);
|
vi->channels != audio_format.channels) {
|
||||||
if (total_time < 0)
|
/* we don't support audio format
|
||||||
total_time = 0;
|
change yet */
|
||||||
decoder_initialized(decoder, &audio_format,
|
g_warning("audio format change, stopping here");
|
||||||
data.seekable,
|
break;
|
||||||
total_time);
|
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
comments = ov_comment(&vf, -1)->user_comments;
|
comments = ov_comment(&vf, -1)->user_comments;
|
||||||
vorbis_send_comments(decoder, input_stream, comments);
|
vorbis_send_comments(decoder, input_stream, comments);
|
||||||
new_rgi = vorbis_comments_to_replay_gain(comments);
|
new_rgi = vorbis_comments_to_replay_gain(comments);
|
||||||
@ -355,9 +371,9 @@ vorbis_stream_decode(struct decoder *decoder,
|
|||||||
replay_gain_info_free(replay_gain_info);
|
replay_gain_info_free(replay_gain_info);
|
||||||
replay_gain_info = new_rgi;
|
replay_gain_info = new_rgi;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
prev_section = current_section;
|
prev_section = current_section;
|
||||||
|
}
|
||||||
|
|
||||||
if ((test = ov_bitrate_instant(&vf)) > 0)
|
if ((test = ov_bitrate_instant(&vf)) > 0)
|
||||||
bitRate = test / 1000;
|
bitRate = test / 1000;
|
||||||
|
Loading…
Reference in New Issue
Block a user