mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 15:46:42 +02:00
EncoderFactory returns a unique_ptr
This commit is contained in:
parent
e9a5a36855
commit
3b9c2db79b
2 changed files with 8 additions and 22 deletions
|
@ -37,9 +37,8 @@ using namespace std;
|
||||||
namespace encoder
|
namespace encoder
|
||||||
{
|
{
|
||||||
|
|
||||||
Encoder* EncoderFactory::createEncoder(const std::string& codecSettings) const
|
std::unique_ptr<Encoder> EncoderFactory::createEncoder(const std::string& codecSettings) const
|
||||||
{
|
{
|
||||||
Encoder* encoder;
|
|
||||||
std::string codec(codecSettings);
|
std::string codec(codecSettings);
|
||||||
std::string codecOptions;
|
std::string codecOptions;
|
||||||
if (codec.find(":") != std::string::npos)
|
if (codec.find(":") != std::string::npos)
|
||||||
|
@ -48,35 +47,21 @@ Encoder* EncoderFactory::createEncoder(const std::string& codecSettings) const
|
||||||
codec = utils::string::trim_copy(codec.substr(0, codec.find(":")));
|
codec = utils::string::trim_copy(codec.substr(0, codec.find(":")));
|
||||||
}
|
}
|
||||||
if (codec == "pcm")
|
if (codec == "pcm")
|
||||||
encoder = new PcmEncoder(codecOptions);
|
return std::make_unique<PcmEncoder>(codecOptions);
|
||||||
#if defined(HAS_OGG) && defined(HAS_VORBIS) && defined(HAS_VORBIS_ENC)
|
#if defined(HAS_OGG) && defined(HAS_VORBIS) && defined(HAS_VORBIS_ENC)
|
||||||
else if (codec == "ogg")
|
else if (codec == "ogg")
|
||||||
encoder = new OggEncoder(codecOptions);
|
return std::make_unique<OggEncoder>(codecOptions);
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAS_FLAC)
|
#if defined(HAS_FLAC)
|
||||||
else if (codec == "flac")
|
else if (codec == "flac")
|
||||||
encoder = new FlacEncoder(codecOptions);
|
return std::make_unique<FlacEncoder>(codecOptions);
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAS_OPUS)
|
#if defined(HAS_OPUS)
|
||||||
else if (codec == "opus")
|
else if (codec == "opus")
|
||||||
encoder = new OpusEncoder(codecOptions);
|
return std::make_unique<OpusEncoder>(codecOptions);
|
||||||
#endif
|
#endif
|
||||||
else
|
|
||||||
{
|
|
||||||
throw SnapException("unknown codec: " + codec);
|
|
||||||
}
|
|
||||||
|
|
||||||
return encoder;
|
throw SnapException("unknown codec: " + codec);
|
||||||
/* try
|
|
||||||
{
|
|
||||||
encoder->init(NULL, format, codecOptions);
|
|
||||||
}
|
|
||||||
catch (const std::exception& e)
|
|
||||||
{
|
|
||||||
cout << "Error: " << e.what() << "\n";
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace encoder
|
} // namespace encoder
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define ENCODER_FACTORY_H
|
#define ENCODER_FACTORY_H
|
||||||
|
|
||||||
#include "encoder.hpp"
|
#include "encoder.hpp"
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace encoder
|
namespace encoder
|
||||||
|
@ -11,7 +12,7 @@ class EncoderFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// EncoderFactory(const std::string& codecSettings);
|
// EncoderFactory(const std::string& codecSettings);
|
||||||
Encoder* createEncoder(const std::string& codecSettings) const;
|
std::unique_ptr<Encoder> createEncoder(const std::string& codecSettings) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace encoder
|
} // namespace encoder
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue