32#include <libavformat/avformat.h>
33#include <libswresample/swresample.h>
36namespace DiscordCoreInternal {
38 struct DiscordCoreAPI_Dll OpusDecoderWrapper {
39 struct DiscordCoreAPI_Dll OpusDecoderDeleter {
40 void operator()(OpusDecoder*)
noexcept;
45 std::basic_string_view<opus_int16> decodeData(std::basic_string_view<std::byte> dataToDecode);
48 std::unique_ptr<OpusDecoder, OpusDecoderDeleter> ptr{
nullptr, OpusDecoderDeleter{} };
49 std::vector<opus_int16> data{};
52 struct DiscordCoreAPI_Dll AVFrameWrapper {
53 struct DiscordCoreAPI_Dll AVFrameDeleter {
54 void operator()(AVFrame* other);
57 AVFrameWrapper& operator=(AVFrame* other);
59 AVFrameWrapper(AVFrame* other);
61 AVFrame* operator->();
65 AVFrameWrapper() noexcept = default;
68 std::unique_ptr<AVFrame, AVFrameDeleter> ptr{
nullptr, AVFrameDeleter{} };
71 struct DiscordCoreAPI_Dll AVCodecContextWrapper {
72 struct DiscordCoreAPI_Dll AVCodecContextDeleter {
73 void operator()(AVCodecContext* other);
76 AVCodecContextWrapper& operator=(AVCodecContext* other);
78 AVCodecContextWrapper(AVCodecContext* other);
80 AVCodecContext* operator->();
82 operator AVCodecContext*();
84 AVCodecContextWrapper() noexcept = default;
87 std::unique_ptr<AVCodecContext, AVCodecContextDeleter> ptr{
nullptr, AVCodecContextDeleter{} };
90 struct DiscordCoreAPI_Dll AVFormatContextWrapper01 {
91 AVFormatContextWrapper01() noexcept = default;
93 AVFormatContext* theContext{
nullptr };
94 bool didItInitialize{};
97 struct DiscordCoreAPI_Dll AVFormatContextWrapper {
98 struct DiscordCoreAPI_Dll AVFormatContextDeleter {
99 void operator()(AVFormatContextWrapper01* other);
102 AVFormatContextWrapper& operator=(AVFormatContext* other);
104 AVFormatContextWrapper(AVFormatContext* other);
108 AVFormatContext* operator->();
110 AVFormatContext** operator*();
112 operator AVFormatContext*();
114 AVFormatContextWrapper() noexcept = default;
117 std::unique_ptr<AVFormatContextWrapper01, AVFormatContextDeleter> ptr{ std::make_unique<AVFormatContextWrapper01>().release(),
118 AVFormatContextDeleter{} };
121 struct DiscordCoreAPI_Dll SwrContextWrapper {
122 struct DiscordCoreAPI_Dll SwrContextDeleter {
123 void operator()(SwrContext* other);
126 SwrContextWrapper& operator=(SwrContext* other);
128 SwrContextWrapper(SwrContext* other);
130 operator SwrContext*();
132 SwrContextWrapper() noexcept = default;
135 std::unique_ptr<SwrContext, SwrContextDeleter> ptr{
nullptr, SwrContextDeleter{} };
138 struct DiscordCoreAPI_Dll AVIOContextWrapper {
139 struct DiscordCoreAPI_Dll AVIOContextDeleter {
140 void operator()(AVIOContext* other);
143 AVIOContextWrapper& operator=(AVIOContext* other);
145 AVIOContextWrapper(AVIOContext* other);
147 AVIOContext* operator->();
149 operator AVIOContext*();
151 AVIOContextWrapper() noexcept = default;
154 std::unique_ptr<AVIOContext, AVIOContextDeleter> ptr{
nullptr, AVIOContextDeleter{} };
157 struct DiscordCoreAPI_Dll AVPacketWrapper {
158 struct DiscordCoreAPI_Dll AVPacketDeleter {
159 void operator()(AVPacket* other);
162 AVPacketWrapper& operator=(AVPacket* other);
164 AVPacketWrapper(AVPacket* other);
166 AVPacket* operator->();
168 operator AVPacket*();
170 AVPacketWrapper() noexcept = default;
173 std::unique_ptr<AVPacket, AVPacketDeleter> ptr{
nullptr, AVPacketDeleter{} };
176 struct DiscordCoreAPI_Dll BuildAudioDecoderData {
178 DiscordCoreAPI::ConfigManager* configManager{
nullptr };
179 int64_t totalFileSize{};
180 int64_t bufferMaxSize{};
183 class DiscordCoreAPI_Dll AudioDecoder {
185 AudioDecoder(
const BuildAudioDecoderData& dataPackage);
189 void submitDataForDecoding(std::string dataToDecode);
199 int64_t audioStreamIndex{}, bufferMaxSize{}, bytesRead{}, totalFileSize{};
201 DiscordCoreAPI::ConfigManager* configManager{
nullptr };
202 std::atomic_int32_t refreshTimeForBuffer{ 10000 };
203 AVCodecContextWrapper audioDecodeContext{};
204 AVFormatContextWrapper formatContext{};
205 std::atomic_bool haveWeFailedBool{};
206 AVFrameWrapper frame{}, newFrame{};
207 std::atomic_bool areWeQuitting{};
208 AVIOContextWrapper ioContext{};
209 SwrContextWrapper swrContext{};
210 std::string currentBuffer{};
211 AVPacketWrapper packet{};
212 AVStream* audioStream{};
215 std::unique_ptr<std::jthread> taskThread{
nullptr };
217 static int32_t ReadBufferData(
void* opaque, uint8_t* buf, int32_t);
219 void run(std::stop_token token);
Represents a single frame of audio data.
A thread-safe messaging block for data-structures.