aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder/_flac_common.c13
-rw-r--r--src/decoder/_flac_common.h4
-rw-r--r--src/decoder/flac_plugin.c23
-rw-r--r--src/decoder/oggflac_plugin.c2
4 files changed, 25 insertions, 17 deletions
diff --git a/src/decoder/_flac_common.c b/src/decoder/_flac_common.c
index fbeab43a7..0755ef641 100644
--- a/src/decoder/_flac_common.c
+++ b/src/decoder/_flac_common.c
@@ -40,7 +40,6 @@ flac_data_init(struct flac_data *data, struct decoder * decoder,
data->time = 0;
data->position = 0;
- data->bit_rate = 0;
data->decoder = decoder;
data->input_stream = input_stream;
data->replay_gain_info = NULL;
@@ -110,12 +109,14 @@ void flac_error_common_cb(const char *plugin,
FLAC__StreamDecoderWriteStatus
flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
- const FLAC__int32 *const buf[])
+ const FLAC__int32 *const buf[],
+ FLAC__uint64 nbytes)
{
enum decoder_command cmd;
size_t buffer_size = frame->header.blocksize *
audio_format_frame_size(&data->audio_format);
void *buffer;
+ unsigned bit_rate;
buffer = pcm_buffer_get(&data->buffer, buffer_size);
@@ -123,9 +124,15 @@ flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
data->audio_format.bits, buf,
0, frame->header.blocksize);
+ if (nbytes > 0)
+ bit_rate = nbytes * 8 * frame->header.sample_rate /
+ (1000 * frame->header.blocksize);
+ else
+ bit_rate = 0;
+
cmd = decoder_data(data->decoder, data->input_stream,
buffer, buffer_size,
- data->time, data->bit_rate,
+ data->time, bit_rate,
data->replay_gain_info);
data->next_frame += frame->header.blocksize;
switch (cmd) {
diff --git a/src/decoder/_flac_common.h b/src/decoder/_flac_common.h
index 895cdf1b9..aa17c55ae 100644
--- a/src/decoder/_flac_common.h
+++ b/src/decoder/_flac_common.h
@@ -57,7 +57,6 @@ struct flac_data {
FLAC__uint64 next_frame;
float time;
- unsigned int bit_rate;
struct audio_format audio_format;
FLAC__uint64 position;
struct decoder *decoder;
@@ -83,7 +82,8 @@ void flac_error_common_cb(const char *plugin,
FLAC__StreamDecoderWriteStatus
flac_common_write(struct flac_data *data, const FLAC__Frame * frame,
- const FLAC__int32 *const buf[]);
+ const FLAC__int32 *const buf[],
+ FLAC__uint64 nbytes);
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
diff --git a/src/decoder/flac_plugin.c b/src/decoder/flac_plugin.c
index 7a4f11451..afc134077 100644
--- a/src/decoder/flac_plugin.c
+++ b/src/decoder/flac_plugin.c
@@ -194,22 +194,23 @@ flac_write_cb(const FLAC__StreamDecoder *dec, const FLAC__Frame *frame,
FLAC__uint32 samples = frame->header.blocksize;
struct flac_data *data = (struct flac_data *) vdata;
float timeChange;
- FLAC__uint64 newPosition = 0;
+ FLAC__uint64 nbytes = 0;
timeChange = ((float)samples) / frame->header.sample_rate;
data->time += timeChange;
- FLAC__stream_decoder_get_decode_position(dec, &newPosition);
- if (data->position && newPosition >= data->position) {
- assert(timeChange >= 0);
-
- data->bit_rate =
- ((newPosition - data->position) * 8.0 / timeChange)
- / 1000 + 0.5;
- }
- data->position = newPosition;
+ if (FLAC__stream_decoder_get_decode_position(dec, &nbytes)) {
+ if (data->position > 0 && nbytes > data->position) {
+ nbytes -= data->position;
+ data->position += nbytes;
+ } else {
+ data->position = nbytes;
+ nbytes = 0;
+ }
+ } else
+ nbytes = 0;
- return flac_common_write(data, frame, buf);
+ return flac_common_write(data, frame, buf, nbytes);
}
static struct tag *
diff --git a/src/decoder/oggflac_plugin.c b/src/decoder/oggflac_plugin.c
index ffd622600..d9a5b9226 100644
--- a/src/decoder/oggflac_plugin.c
+++ b/src/decoder/oggflac_plugin.c
@@ -161,7 +161,7 @@ oggflac_write_cb(G_GNUC_UNUSED const OggFLAC__SeekableStreamDecoder *decoder,
time_change = ((float)samples) / frame->header.sample_rate;
data->time += time_change;
- return flac_common_write(data, frame, buf);
+ return flac_common_write(data, frame, buf, 0);
}
/* used by TagDup */