summaryrefslogtreecommitdiff
path: root/src/codecs/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-08 23:14:42 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-08 23:14:42 +1000
commit1b6811663caf07717ce15f3d3bbb1195397a1a33 (patch)
tree2babe8ab0769d97cd8a785b26c3dfc499a6924d8 /src/codecs/include
parent6c3501dbcbd1095293d8a4d4b83311e94a7df9a8 (diff)
downloadtangara-fw-1b6811663caf07717ce15f3d3bbb1195397a1a33.tar.gz
Add libogg for handling opus streams reasonably
Diffstat (limited to 'src/codecs/include')
-rw-r--r--src/codecs/include/ogg.hpp36
-rw-r--r--src/codecs/include/opus.hpp3
2 files changed, 39 insertions, 0 deletions
diff --git a/src/codecs/include/ogg.hpp b/src/codecs/include/ogg.hpp
new file mode 100644
index 00000000..2d6ea8c5
--- /dev/null
+++ b/src/codecs/include/ogg.hpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <sys/_stdint.h>
+#include <cstddef>
+#include <cstdint>
+#include <optional>
+
+#include "ogg/ogg.h"
+#include "span.hpp"
+
+namespace codecs {
+
+class OggContainer {
+ public:
+ 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>;
+
+ private:
+ ogg_sync_state sync_;
+ ogg_stream_state stream_;
+ ogg_page page_;
+ ogg_packet packet_;
+};
+
+} // namespace codecs \ No newline at end of file
diff --git a/src/codecs/include/opus.hpp b/src/codecs/include/opus.hpp
index f824a7cb..50717b73 100644
--- a/src/codecs/include/opus.hpp
+++ b/src/codecs/include/opus.hpp
@@ -13,6 +13,8 @@
#include <string>
#include <utility>
+#include "ogg.hpp"
+#include "ogg/ogg.h"
#include "opus.h"
#include "sample.hpp"
#include "span.hpp"
@@ -44,6 +46,7 @@ class XiphOpusDecoder : public ICodec {
-> Result<void> override;
private:
+ OggContainer ogg_;
OpusDecoder* opus_;
cpp::span<int16_t> sample_buffer_;
int32_t pos_in_buffer_;