summaryrefslogtreecommitdiff
path: root/src/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'src/codecs')
-rw-r--r--src/codecs/foxenflac.cpp2
-rw-r--r--src/codecs/include/codec.hpp2
-rw-r--r--src/codecs/mad.cpp4
-rw-r--r--src/codecs/opus.cpp15
-rw-r--r--src/codecs/vorbis.cpp7
5 files changed, 26 insertions, 4 deletions
diff --git a/src/codecs/foxenflac.cpp b/src/codecs/foxenflac.cpp
index eef8225a..b1ba348a 100644
--- a/src/codecs/foxenflac.cpp
+++ b/src/codecs/foxenflac.cpp
@@ -64,7 +64,7 @@ auto FoxenFlacDecoder::OpenStream(std::shared_ptr<IStream> input)
uint64_t num_samples = fx_flac_get_streaminfo(flac_, FLAC_KEY_N_SAMPLES);
if (num_samples > 0) {
- format.duration_seconds = num_samples / fs;
+ format.total_samples = num_samples / fs;
}
return format;
diff --git a/src/codecs/include/codec.hpp b/src/codecs/include/codec.hpp
index ece3d4fe..2f95389c 100644
--- a/src/codecs/include/codec.hpp
+++ b/src/codecs/include/codec.hpp
@@ -91,7 +91,7 @@ class ICodec {
struct OutputFormat {
uint8_t num_channels;
uint32_t sample_rate_hz;
- std::optional<uint32_t> duration_seconds;
+ std::optional<uint32_t> total_samples;
bool operator==(const OutputFormat&) const = default;
};
diff --git a/src/codecs/mad.cpp b/src/codecs/mad.cpp
index ce3a9cac..dfa568d4 100644
--- a/src/codecs/mad.cpp
+++ b/src/codecs/mad.cpp
@@ -92,7 +92,7 @@ auto MadMp3Decoder::OpenStream(std::shared_ptr<IStream> input)
auto vbr_length = GetVbrLength(header);
if (vbr_length) {
- output.duration_seconds = vbr_length;
+ output.total_samples = vbr_length;
}
return output;
}
@@ -234,7 +234,7 @@ auto MadMp3Decoder::GetVbrLength(const mad_header& header)
return {};
}
- return (double)(frames_count * samples_per_frame) / header.samplerate;
+ return (double)(frames_count * samples_per_frame);
}
} // namespace codecs
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<IStream> input)
return cpp::fail(Error::kMalformedData);
}
+ auto l = op_pcm_total(opus_, -1);
+ std::optional<uint32_t> 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,
};
}
diff --git a/src/codecs/vorbis.cpp b/src/codecs/vorbis.cpp
index aa367e02..cf783978 100644
--- a/src/codecs/vorbis.cpp
+++ b/src/codecs/vorbis.cpp
@@ -118,9 +118,16 @@ auto TremorVorbisDecoder::OpenStream(std::shared_ptr<IStream> input)
return cpp::fail(Error::kMalformedData);
}
+ auto l = ov_pcm_total(&vorbis_, -1);
+ std::optional<uint32_t> length;
+ if (l > 0) {
+ length = l;
+ }
+
return OutputFormat{
.num_channels = static_cast<uint8_t>(info->channels),
.sample_rate_hz = static_cast<uint32_t>(info->rate),
+ .total_samples = length,
};
}