mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-10 23:56:43 +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
|
||||
{
|
||||
|
||||
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 codecOptions;
|
||||
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(":")));
|
||||
}
|
||||
if (codec == "pcm")
|
||||
encoder = new PcmEncoder(codecOptions);
|
||||
return std::make_unique<PcmEncoder>(codecOptions);
|
||||
#if defined(HAS_OGG) && defined(HAS_VORBIS) && defined(HAS_VORBIS_ENC)
|
||||
else if (codec == "ogg")
|
||||
encoder = new OggEncoder(codecOptions);
|
||||
return std::make_unique<OggEncoder>(codecOptions);
|
||||
#endif
|
||||
#if defined(HAS_FLAC)
|
||||
else if (codec == "flac")
|
||||
encoder = new FlacEncoder(codecOptions);
|
||||
return std::make_unique<FlacEncoder>(codecOptions);
|
||||
#endif
|
||||
#if defined(HAS_OPUS)
|
||||
else if (codec == "opus")
|
||||
encoder = new OpusEncoder(codecOptions);
|
||||
return std::make_unique<OpusEncoder>(codecOptions);
|
||||
#endif
|
||||
else
|
||||
{
|
||||
throw SnapException("unknown codec: " + codec);
|
||||
}
|
||||
|
||||
return encoder;
|
||||
/* try
|
||||
{
|
||||
encoder->init(NULL, format, codecOptions);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
cout << "Error: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
throw SnapException("unknown codec: " + codec);
|
||||
}
|
||||
|
||||
} // namespace encoder
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define ENCODER_FACTORY_H
|
||||
|
||||
#include "encoder.hpp"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace encoder
|
||||
|
@ -11,7 +12,7 @@ class EncoderFactory
|
|||
{
|
||||
public:
|
||||
// EncoderFactory(const std::string& codecSettings);
|
||||
Encoder* createEncoder(const std::string& codecSettings) const;
|
||||
std::unique_ptr<Encoder> createEncoder(const std::string& codecSettings) const;
|
||||
};
|
||||
|
||||
} // namespace encoder
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue