载入中...
搜索中...
未找到
Decoder.cpp
浏览该文件的文档.
1#include "Decoder.h"
2
3#include "common/Exception.h"
4#include "medialoader/sound/Decoder.h"
5
6namespace eve {
7namespace sound {
8
9Decoder::Decoder(std::unique_ptr<medialoader::Decoder> impl, std::vector<char> ownedData)
10 : Decoder(std::move(impl), std::make_shared<const std::vector<char>>(std::move(ownedData))) {}
11
12Decoder::Decoder(std::unique_ptr<medialoader::Decoder> impl, std::shared_ptr<const std::vector<char>> ownedData)
13 : ownedData(std::move(ownedData)), impl(std::move(impl)) {
14 if (!this->impl)
15 throw eve::Exception("Invalid sound decoder");
16}
17
18Decoder::~Decoder() = default;
19
21 auto cloned = std::unique_ptr<medialoader::Decoder>(impl->clone());
22 if (!cloned)
23 throw eve::Exception("Could not clone sound decoder");
24 // Provider clones retain the original pointer rather than rebinding it to
25 // a byte-for-byte copy. Keep that exact allocation alive for every clone.
26 return new Decoder(std::move(cloned), ownedData);
27}
28
29int Decoder::decode() { return impl->decode(); }
30int Decoder::getSize() const { return impl->getSize(); }
31void *Decoder::getBuffer() const { return impl->getBuffer(); }
32bool Decoder::seek(double seconds) { return impl->seek(seconds); }
33bool Decoder::rewind() { return impl->rewind(); }
34bool Decoder::isSeekable() { return impl->isSeekable(); }
35bool Decoder::isFinished() { return impl->isFinished(); }
36int Decoder::getChannelCount() const { return impl->getChannelCount(); }
37int Decoder::getBitDepth() const { return impl->getBitDepth(); }
38int Decoder::getSampleRate() const { return impl->getSampleRate(); }
39double Decoder::getDuration() { return impl->getDuration(); }
40
41} // namespace sound
42} // namespace eve
void * impl
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Streaming audio decoder (medialoader-backed). Owns the raw encoded bytes and decodes incrementally vi...
Definition Decoder.h:22
void * getBuffer() const
Internal decoded buffer.
Definition Decoder.cpp:31
double getDuration()
Total duration in seconds.
Definition Decoder.cpp:39
bool isFinished()
True when the stream is fully decoded.
Definition Decoder.cpp:35
int getSampleRate() const
Returns the sample rate.
Definition Decoder.cpp:38
bool isSeekable()
True when seeking is supported.
Definition Decoder.cpp:34
int getChannelCount() const
Format metadata.
Definition Decoder.cpp:36
Decoder(std::unique_ptr< medialoader::Decoder > impl, std::vector< char > ownedData)
Wraps a medialoader decoder and the encoded bytes it needs.
Definition Decoder.cpp:9
Decoder * clone() const
Creates a caller-owned decoder positioned at the start of the stream.
Definition Decoder.cpp:20
bool rewind()
Rewinds to the start; false when unsupported.
Definition Decoder.cpp:33
bool seek(double seconds)
Seeks to a time in seconds; false when unsupported.
Definition Decoder.cpp:32
int getSize() const
Bytes decoded so far into the internal buffer.
Definition Decoder.cpp:30
int getBitDepth() const
Returns the bit depth.
Definition Decoder.cpp:37
int decode()
Decodes the next chunk; returns bytes produced (0 = end/error).
Definition Decoder.cpp:29
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16