载入中...
搜索中...
未找到
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 : impl(std::move(impl)), ownedData(std::move(ownedData)) {
11 if (!this->impl)
12 throw eve::Exception("Invalid sound decoder");
13}
14
15Decoder::~Decoder() = default;
16
18 auto *cloned = impl->clone();
19 if (!cloned)
20 throw eve::Exception("Could not clone sound decoder");
21 // medialoader clone reuses the same data pointer; keep a copy of owned bytes.
22 return new Decoder(std::unique_ptr<medialoader::Decoder>(cloned), ownedData);
23}
24
25int Decoder::decode() { return impl->decode(); }
26int Decoder::getSize() const { return impl->getSize(); }
27void *Decoder::getBuffer() const { return impl->getBuffer(); }
28bool Decoder::seek(double seconds) { return impl->seek(seconds); }
29bool Decoder::rewind() { return impl->rewind(); }
30bool Decoder::isSeekable() { return impl->isSeekable(); }
31bool Decoder::isFinished() { return impl->isFinished(); }
32int Decoder::getChannelCount() const { return impl->getChannelCount(); }
33int Decoder::getBitDepth() const { return impl->getBitDepth(); }
34int Decoder::getSampleRate() const { return impl->getSampleRate(); }
35double Decoder::getDuration() { return impl->getDuration(); }
36
37} // namespace sound
38} // namespace eve
void * impl
Streaming audio decoder (medialoader-backed). Owns the raw encoded bytes and decodes incrementally vi...
Definition Decoder.h:20
void * getBuffer() const
Internal decoded buffer.
Definition Decoder.cpp:27
double getDuration()
Total duration in seconds.
Definition Decoder.cpp:35
bool isFinished()
True when the stream is fully decoded.
Definition Decoder.cpp:31
int getSampleRate() const
Definition Decoder.cpp:34
bool isSeekable()
True when seeking is supported.
Definition Decoder.cpp:30
int getChannelCount() const
Format metadata.
Definition Decoder.cpp:32
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
Duplicates the decoder (each clone keeps its own position).
Definition Decoder.cpp:17
bool rewind()
Rewinds to the start; false when unsupported.
Definition Decoder.cpp:29
bool seek(double seconds)
Seeks to a time in seconds; false when unsupported.
Definition Decoder.cpp:28
int getSize() const
Bytes decoded so far into the internal buffer.
Definition Decoder.cpp:26
int getBitDepth() const
Definition Decoder.cpp:33
int decode()
Decodes the next chunk; returns bytes produced (0 = end/error).
Definition Decoder.cpp:25
Definition Build.cpp:11