From c37ccb985125f5efdf7600989331085f60d8a973 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 10 Aug 2023 21:34:48 +1000 Subject: Reintroduce track timer, now relying more on codecs --- src/codecs/opus.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/codecs/opus.cpp') diff --git a/src/codecs/opus.cpp b/src/codecs/opus.cpp index c0727c6b..f5ff471a 100644 --- a/src/codecs/opus.cpp +++ b/src/codecs/opus.cpp @@ -122,9 +122,24 @@ auto XiphOpusDecoder::OpenStream(std::shared_ptr input) return cpp::fail(Error::kMalformedData); } + auto l = op_pcm_total(opus_, -1); + std::optional length; + if (l > 0) { + // Output is always downmixed to two channels, but the pcm count does not + // reflect this. + int channels = op_channel_count(opus_, -1); + if (channels == 1) { + l *= 2; + } else if (channels > 2) { + l /= channels * 2; + } + length = l; + } + return OutputFormat{ .num_channels = 2, .sample_rate_hz = 48000, + .total_samples = length, }; } -- cgit v1.2.3