summaryrefslogtreecommitdiff
path: root/src/codecs/include/mad.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-10 15:33:00 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-10 15:33:00 +1000
commitd8fc77101dcf80a3643a00b3446dca1e390ce997 (patch)
tree9e03881f3857c7b4c6a0b6e3a062947daecc69d1 /src/codecs/include/mad.hpp
parent67caeb6e3cda44205ba8fe783274b20dc7ea216e (diff)
downloadtangara-fw-d8fc77101dcf80a3643a00b3446dca1e390ce997.tar.gz
Give codecs complete control of their input files
Diffstat (limited to 'src/codecs/include/mad.hpp')
-rw-r--r--src/codecs/include/mad.hpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/codecs/include/mad.hpp b/src/codecs/include/mad.hpp
index b81e4acb..2a8813e9 100644
--- a/src/codecs/include/mad.hpp
+++ b/src/codecs/include/mad.hpp
@@ -14,6 +14,7 @@
#include "mad.h"
#include "sample.hpp"
+#include "source_buffer.hpp"
#include "span.hpp"
#include "codec.hpp"
@@ -25,33 +26,31 @@ class MadMp3Decoder : public ICodec {
MadMp3Decoder();
~MadMp3Decoder();
- /*
- * Returns the output format for the next frame in the stream. MP3 streams
- * may represent multiple distinct tracks, with different bitrates, and so we
- * handle the stream only on a frame-by-frame basis.
- */
- auto BeginStream(cpp::span<const std::byte>) -> Result<OutputFormat> override;
+ auto OpenStream(std::shared_ptr<IStream> input)
+ -> cpp::result<OutputFormat, Error> override;
- /*
- * Writes samples for the current frame.
- */
- auto ContinueStream(cpp::span<const std::byte> input,
- cpp::span<sample::Sample> output)
- -> Result<OutputInfo> override;
+ auto DecodeTo(cpp::span<sample::Sample> destination)
+ -> cpp::result<OutputInfo, Error> override;
- auto SeekStream(cpp::span<const std::byte> input, std::size_t target_sample)
- -> Result<void> override;
+ auto SeekTo(std::size_t target_sample) -> cpp::result<void, Error> override;
+
+ MadMp3Decoder(const MadMp3Decoder&) = delete;
+ MadMp3Decoder& operator=(const MadMp3Decoder&) = delete;
private:
auto GetVbrLength(const mad_header& header) -> std::optional<uint32_t>;
+ auto GetBytesUsed() -> std::size_t;
+
+ std::shared_ptr<IStream> input_;
+ SourceBuffer buffer_;
mad_stream stream_;
mad_frame frame_;
mad_synth synth_;
int current_sample_;
-
- auto GetBytesUsed(std::size_t) -> std::size_t;
+ bool is_eof_;
+ bool is_eos_;
};
} // namespace codecs