diff options
Diffstat (limited to 'src/codecs/include')
| -rw-r--r-- | src/codecs/include/ogg.hpp | 15 | ||||
| -rw-r--r-- | src/codecs/include/stbvorbis.hpp | 42 | ||||
| -rw-r--r-- | src/codecs/include/types.hpp | 1 | ||||
| -rw-r--r-- | src/codecs/include/vorbis.hpp | 58 |
4 files changed, 70 insertions, 46 deletions
diff --git a/src/codecs/include/ogg.hpp b/src/codecs/include/ogg.hpp index 2d6ea8c5..a27e961e 100644 --- a/src/codecs/include/ogg.hpp +++ b/src/codecs/include/ogg.hpp @@ -21,16 +21,23 @@ class OggContainer { OggContainer(); ~OggContainer(); - auto AddBytes(cpp::span<const std::byte>) -> void; - auto HasNextPacket() -> bool; - auto NextPacket() -> cpp::span<uint8_t>; - auto PeekPacket() -> cpp::span<uint8_t>; + auto AddBytes(cpp::span<const std::byte>) -> bool; + + auto Next() -> bool; + auto Current() -> cpp::span<uint8_t>; + auto HasPacket() -> bool; private: + auto AdvancePage() -> bool; + auto AdvancePacket() -> bool; + ogg_sync_state sync_; ogg_stream_state stream_; ogg_page page_; ogg_packet packet_; + + bool has_stream_; + bool has_packet_; }; } // namespace codecs
\ No newline at end of file diff --git a/src/codecs/include/stbvorbis.hpp b/src/codecs/include/stbvorbis.hpp deleted file mode 100644 index 045e264e..00000000 --- a/src/codecs/include/stbvorbis.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2023 jacqueline <me@jacqueline.id.au> - * - * SPDX-License-Identifier: GPL-3.0-only - */ - -#pragma once - -#include <cstddef> -#include <cstdint> -#include <memory> -#include <optional> -#include <string> -#include <utility> - -#include "stb_vorbis.h" - -#include "codec.hpp" - -namespace codecs { - -class StbVorbisDecoder : public ICodec { - public: - StbVorbisDecoder(); - ~StbVorbisDecoder(); - - auto BeginStream(cpp::span<const std::byte>) -> Result<OutputFormat> override; - auto ContinueStream(cpp::span<const std::byte>, cpp::span<std::byte>) - -> Result<OutputInfo> override; - auto SeekStream(cpp::span<const std::byte> input, std::size_t target_sample) - -> Result<void> override; - - private: - stb_vorbis* vorbis_; - - int current_sample_; - int num_channels_; - int num_samples_; - float** samples_array_; -}; - -} // namespace codecs diff --git a/src/codecs/include/types.hpp b/src/codecs/include/types.hpp index 2f669448..e0bba47d 100644 --- a/src/codecs/include/types.hpp +++ b/src/codecs/include/types.hpp @@ -13,6 +13,7 @@ namespace codecs { enum class StreamType { kMp3, kPcm, + kVorbis, kFlac, kOpus, }; diff --git a/src/codecs/include/vorbis.hpp b/src/codecs/include/vorbis.hpp new file mode 100644 index 00000000..2804bb7c --- /dev/null +++ b/src/codecs/include/vorbis.hpp @@ -0,0 +1,58 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstddef> +#include <cstdint> +#include <memory> +#include <optional> +#include <string> +#include <utility> + +#include "ivorbisfile.h" +#include "ogg.hpp" +#include "ogg/ogg.h" +#include "opus.h" +#include "sample.hpp" +#include "span.hpp" + +#include "codec.hpp" + +namespace codecs { + +class TremorVorbisDecoder : public ICodec { + public: + TremorVorbisDecoder(); + ~TremorVorbisDecoder(); + + /* + * 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; + + /* + * Writes samples for the current frame. + */ + auto ContinueStream(cpp::span<const std::byte> input, + cpp::span<sample::Sample> output) + -> Result<OutputInfo> override; + + auto SeekStream(cpp::span<const std::byte> input, std::size_t target_sample) + -> Result<void> override; + + auto ReadCallback() -> cpp::span<const std::byte>; + auto AfterReadCallback(size_t bytes_read) -> void; + + private: + OggVorbis_File vorbis_; + cpp::span<const std::byte> input_; + size_t pos_in_input_; +}; + +} // namespace codecs |
