Add move semantics to memory buffer decoders

pull/35/head
Avaer Kazmer 8 years ago
parent 9ce7f0cf34
commit 2ce6909240

@ -53,7 +53,7 @@ struct LoadBufferNotImplEx : public std::runtime_error
struct BaseDecoder struct BaseDecoder
{ {
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) = 0; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) = 0;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) = 0; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) = 0;
virtual std::vector<std::string> GetSupportedFileExtensions() = 0; virtual std::vector<std::string> GetSupportedFileExtensions() = 0;
}; };
@ -67,7 +67,7 @@ public:
~NyquistIO(); ~NyquistIO();
void Load(AudioData * data, const std::string & path); void Load(AudioData * data, const std::string & path);
void Load(AudioData *data, std::string extension, const std::vector<uint8_t> & buffer); void Load(AudioData *data, std::string extension, std::vector<uint8_t> & buffer);
bool IsFileSupported(const std::string path) const; bool IsFileSupported(const std::string path) const;
@ -88,4 +88,4 @@ private:
} // end namespace nqr } // end namespace nqr
#endif #endif

@ -36,10 +36,10 @@ struct CAFDecoder : public nqr::BaseDecoder
CAFDecoder() {}; CAFDecoder() {};
virtual ~CAFDecoder() {}; virtual ~CAFDecoder() {};
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };
} // end namespace nqr } // end namespace nqr
#endif #endif

@ -56,7 +56,7 @@ struct FlacDecoder : public nqr::BaseDecoder
FlacDecoder() {} FlacDecoder() {}
virtual ~FlacDecoder() {} virtual ~FlacDecoder() {}
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };

@ -36,10 +36,10 @@ struct ModplugDecoder : public nqr::BaseDecoder
ModplugDecoder() {}; ModplugDecoder() {};
virtual ~ModplugDecoder() {}; virtual ~ModplugDecoder() {};
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };
} // end namespace nqr } // end namespace nqr
#endif #endif

@ -36,10 +36,10 @@ struct MusepackDecoder : public nqr::BaseDecoder
MusepackDecoder() {}; MusepackDecoder() {};
virtual ~MusepackDecoder() {}; virtual ~MusepackDecoder() {};
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };
} // end namespace nqr } // end namespace nqr
#endif #endif

@ -41,7 +41,7 @@ struct OpusDecoder : public nqr::BaseDecoder
OpusDecoder() {} OpusDecoder() {}
virtual ~OpusDecoder() {} virtual ~OpusDecoder() {}
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };

@ -36,9 +36,9 @@ struct VorbisDecoder : public nqr::BaseDecoder
VorbisDecoder() {} VorbisDecoder() {}
virtual ~VorbisDecoder() {} virtual ~VorbisDecoder() {}
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };
} // end namespace nqr } // end namespace nqr
#endif #endif

@ -173,7 +173,7 @@ struct WavDecoder : public nqr::BaseDecoder
WavDecoder() {} WavDecoder() {}
virtual ~WavDecoder() {} virtual ~WavDecoder() {}
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };

@ -36,7 +36,7 @@ struct WavPackDecoder : public nqr::BaseDecoder
WavPackDecoder() {}; WavPackDecoder() {};
virtual ~WavPackDecoder() {}; virtual ~WavPackDecoder() {};
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) override;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) override; virtual void LoadFromBuffer(nqr::AudioData * data, std::vector<uint8_t> & memory) override;
virtual std::vector<std::string> GetSupportedFileExtensions() override; virtual std::vector<std::string> GetSupportedFileExtensions() override;
}; };

@ -70,7 +70,7 @@ void NyquistIO::Load(AudioData * data, const std::string & path)
} }
} }
void NyquistIO::Load(AudioData * data, std::string extension, const std::vector<uint8_t> & buffer) void NyquistIO::Load(AudioData * data, std::string extension, std::vector<uint8_t> & buffer)
{ {
if (decoderTable.find(extension) == decoderTable.end()) if (decoderTable.find(extension) == decoderTable.end())
{ {
@ -148,4 +148,4 @@ void NyquistIO::BuildDecoderTable()
AddDecoderToTable(std::make_shared<CAFDecoder>()); AddDecoderToTable(std::make_shared<CAFDecoder>());
AddDecoderToTable(std::make_shared<MusepackDecoder>()); AddDecoderToTable(std::make_shared<MusepackDecoder>());
AddDecoderToTable(std::make_shared<ModplugDecoder>()); AddDecoderToTable(std::make_shared<ModplugDecoder>());
} }

@ -36,7 +36,7 @@ void CAFDecoder::LoadFromPath(AudioData * data, const std::string & path)
throw LoadPathNotImplEx(); throw LoadPathNotImplEx();
} }
void CAFDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void CAFDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
throw LoadBufferNotImplEx(); throw LoadBufferNotImplEx();
} }
@ -44,4 +44,4 @@ void CAFDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & m
std::vector<std::string> CAFDecoder::GetSupportedFileExtensions() std::vector<std::string> CAFDecoder::GetSupportedFileExtensions()
{ {
return {}; return {};
} }

@ -38,7 +38,7 @@ class FlacDecoderInternal
public: public:
// FLAC is a big-endian format. All values are unsigned. // FLAC is a big-endian format. All values are unsigned.
FlacDecoderInternal(AudioData * d, std::string filepath) : d(d) FlacDecoderInternal(AudioData * d, const std::string & filepath) : d(d)
{ {
///////////////////////////// /////////////////////////////
@ -90,7 +90,7 @@ public:
} }
FlacDecoderInternal(AudioData * d, const std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0) FlacDecoderInternal(AudioData * d, std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0)
{ {
///////////////////////////// /////////////////////////////
@ -268,7 +268,7 @@ void FlacDecoder::LoadFromPath(AudioData * data, const std::string & path)
FlacDecoderInternal decoder(data, path); FlacDecoderInternal decoder(data, path);
} }
void FlacDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void FlacDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
FlacDecoderInternal decoder(data, memory); FlacDecoderInternal decoder(data, memory);
} }

@ -38,7 +38,7 @@ class ModplugInternal
public: public:
ModplugInternal(AudioData * d, const std::vector<uint8_t> & fileData) : d(d) ModplugInternal(AudioData * d, std::vector<uint8_t> & fileData) : d(d)
{ {
ModPlug_Settings mps; ModPlug_Settings mps;
ModPlug_GetSettings(&mps); ModPlug_GetSettings(&mps);
@ -119,7 +119,7 @@ void ModplugDecoder::LoadFromPath(AudioData * data, const std::string & path)
ModplugInternal decoder(data, fileBuffer.buffer); ModplugInternal decoder(data, fileBuffer.buffer);
} }
void ModplugDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void ModplugDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
ModplugInternal decoder(data, memory); ModplugInternal decoder(data, memory);
} }

@ -92,7 +92,7 @@ class MusepackInternal
public: public:
// Musepack is a purely variable bitrate format and does not work at a constant bitrate. // Musepack is a purely variable bitrate format and does not work at a constant bitrate.
MusepackInternal(AudioData * d, const std::vector<uint8_t> & fileData) : d(d) MusepackInternal(AudioData * d, std::vector<uint8_t> & fileData) : d(d)
{ {
decoderMemory = std::make_shared<mpc_reader_state>(); decoderMemory = std::make_shared<mpc_reader_state>();
@ -182,7 +182,7 @@ void MusepackDecoder::LoadFromPath(AudioData * data, const std::string & path)
MusepackInternal decoder(data, fileBuffer.buffer); MusepackInternal decoder(data, fileBuffer.buffer);
} }
void MusepackDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void MusepackDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
MusepackInternal decoder(data, memory); MusepackInternal decoder(data, memory);
} }
@ -190,4 +190,4 @@ void MusepackDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t
std::vector<std::string> MusepackDecoder::GetSupportedFileExtensions() std::vector<std::string> MusepackDecoder::GetSupportedFileExtensions()
{ {
return {"mpc", "mpp"}; return {"mpc", "mpp"};
} }

@ -35,7 +35,7 @@ class OpusDecoderInternal
public: public:
OpusDecoderInternal(AudioData * d, const std::vector<uint8_t> & fileData) : d(d) OpusDecoderInternal(AudioData * d, std::vector<uint8_t> & fileData) : d(d)
{ {
/* @todo proper steaming support + classes /* @todo proper steaming support + classes
const opus_callbacks = { const opus_callbacks = {
@ -166,7 +166,7 @@ void nqr::OpusDecoder::LoadFromPath(AudioData * data, const std::string & path)
OpusDecoderInternal decoder(data, fileBuffer.buffer); OpusDecoderInternal decoder(data, fileBuffer.buffer);
} }
void nqr::OpusDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void nqr::OpusDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
OpusDecoderInternal decoder(data, memory); OpusDecoderInternal decoder(data, memory);
} }
@ -174,4 +174,4 @@ void nqr::OpusDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_
std::vector<std::string> nqr::OpusDecoder::GetSupportedFileExtensions() std::vector<std::string> nqr::OpusDecoder::GetSupportedFileExtensions()
{ {
return {"opus"}; return {"opus"};
} }

@ -35,7 +35,7 @@ class VorbisDecoderInternal
public: public:
VorbisDecoderInternal(AudioData * d, std::string filepath) : d(d) VorbisDecoderInternal(AudioData * d, const std::string & filepath) : d(d)
{ {
fileHandle = new OggVorbis_File(); fileHandle = new OggVorbis_File();
@ -96,7 +96,7 @@ public:
throw std::runtime_error("could not read any data"); throw std::runtime_error("could not read any data");
} }
VorbisDecoderInternal(AudioData * d, const std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0) VorbisDecoderInternal(AudioData * d, std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0)
{ {
fileHandle = new OggVorbis_File(); fileHandle = new OggVorbis_File();
@ -269,7 +269,7 @@ void VorbisDecoder::LoadFromPath(AudioData * data, const std::string & path)
VorbisDecoderInternal decoder(data, path); VorbisDecoderInternal decoder(data, path);
} }
void VorbisDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void VorbisDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
VorbisDecoderInternal decoder(data, memory); VorbisDecoderInternal decoder(data, memory);
} }

@ -40,7 +40,7 @@ void WavDecoder::LoadFromPath(AudioData * data, const std::string & path)
return LoadFromBuffer(data, fileBuffer.buffer); return LoadFromBuffer(data, fileBuffer.buffer);
} }
void WavDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void WavDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
////////////////////// //////////////////////
// Read RIFF Header // // Read RIFF Header //

@ -34,7 +34,7 @@ class WavPackInternal
public: public:
WavPackInternal(AudioData * d, const std::string path) : d(d) WavPackInternal(AudioData * d, const std::string & path) : d(d)
{ {
char errorStr[128]; char errorStr[128];
context = WavpackOpenFileInput(path.c_str(), errorStr, OPEN_WVC | OPEN_NORMALIZE, 0); context = WavpackOpenFileInput(path.c_str(), errorStr, OPEN_WVC | OPEN_NORMALIZE, 0);
@ -80,7 +80,7 @@ public:
} }
WavPackInternal(AudioData * d, const std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0) WavPackInternal(AudioData * d, std::vector<uint8_t> & memory) : d(d), data(std::move(memory)), dataPos(0)
{ {
WavpackStreamReader64 reader = { WavpackStreamReader64 reader = {
read_bytes, read_bytes,
@ -316,7 +316,7 @@ void WavPackDecoder::LoadFromPath(AudioData * data, const std::string & path)
WavPackInternal decoder(data, path); WavPackInternal decoder(data, path);
} }
void WavPackDecoder::LoadFromBuffer(AudioData * data, const std::vector<uint8_t> & memory) void WavPackDecoder::LoadFromBuffer(AudioData * data, std::vector<uint8_t> & memory)
{ {
WavPackInternal decoder(data, memory); WavPackInternal decoder(data, memory);
} }

Loading…
Cancel
Save