summaryrefslogtreecommitdiff
path: root/src/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'src/codecs')
-rw-r--r--src/codecs/include/codec.hpp2
-rw-r--r--src/codecs/mad.cpp5
2 files changed, 5 insertions, 2 deletions
diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp
index 36dda8ff..8aa391b6 100644
--- a/src/codecs/include/codec.hpp
+++ b/src/codecs/include/codec.hpp
@@ -49,6 +49,8 @@ class IStream {
virtual auto CurrentPosition() -> int64_t = 0;
+ virtual auto Size() -> std::optional<int64_t> = 0;
+
/*
* Called by codecs to indicate that they've finished parsing any header data
* within this stream, and are about to begin decoding.
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp
index 247e33bc..f36636a1 100644
--- a/src/codecs/mad.cpp
+++ b/src/codecs/mad.cpp
@@ -109,8 +109,9 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input)
auto vbr_length = GetVbrLength(header);
if (vbr_length) {
output.total_samples = vbr_length.value() * channels;
- } else {
- // FIXME: calculate length using the filesize, assuming CBR.
+ } else if (input->Size() && header.bitrate > 0) {
+ auto cbr_length = input->Size().value() / (header.bitrate / 8);
+ output.total_samples = cbr_length * output.sample_rate_hz * channels;
}
return output;
}