From 3a3f605a564bf5b05569ce3e52474775e89eb7bb Mon Sep 17 00:00:00 2001 From: Tim Sweet Date: Fri, 11 Mar 2022 18:24:16 -0600 Subject: [PATCH] decoder/opus: Implement bitrate calculation --- NEWS | 2 ++ src/decoder/plugins/OpusDecoderPlugin.cxx | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index d51ab7bce..43dc6795e 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ ver 0.24 (not yet released) - filter "prio" (for "playlistfind"/"playlistsearch") * archive - add option to disable archive plugins in mpd.conf +* decoder + - opus: implement bitrate calculation * player - add option "mixramp_analyzer" to scan MixRamp tags on-the-fly * tags diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 18216ed31..c35914236 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -327,6 +327,13 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) return; } + /* Formula for calculation of bitrate of the current opus packet: + bits_sent_into_decoder = packet.bytes * 8 + 1/seconds_decoded = opus_sample_rate / nframes + kbits = bits_sent_into_decoder * 1/seconds_decoded / 1000 + */ + uint16_t kbits = (unsigned int)packet.bytes*8 * opus_sample_rate / nframes / 1000; + /* apply the "skip" value */ if (skip >= (unsigned)nframes) { skip -= nframes; @@ -361,7 +368,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) const size_t nbytes = nframes * frame_size; auto cmd = client.SubmitData(input_stream, data, nbytes, - 0); + kbits); if (cmd != DecoderCommand::NONE) throw cmd;