diff options
author | Max Kellermann <max@musicpd.org> | 2017-11-10 21:37:56 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2017-11-10 21:54:57 +0100 |
commit | 6464b4b3720d91d07c99bf8411a95ec7e3c35eb2 (patch) | |
tree | 7ac43e8ed563add4a42375f24fe8ce3d919ac32d /src/output/plugins | |
parent | fef9747fbf351bcd43259b0dc2f4fde4c93dcf6c (diff) |
encoder/Configured: glue code to initialize PreparedEncoder
Diffstat (limited to 'src/output/plugins')
-rw-r--r-- | src/output/plugins/RecorderOutputPlugin.cxx | 17 | ||||
-rw-r--r-- | src/output/plugins/ShoutOutputPlugin.cxx | 27 | ||||
-rw-r--r-- | src/output/plugins/httpd/HttpdOutputPlugin.cxx | 15 |
3 files changed, 8 insertions, 51 deletions
diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx index 1e561fb39..4d39df9e2 100644 --- a/src/output/plugins/RecorderOutputPlugin.cxx +++ b/src/output/plugins/RecorderOutputPlugin.cxx @@ -23,14 +23,12 @@ #include "tag/Format.hxx" #include "encoder/ToOutputStream.hxx" #include "encoder/EncoderInterface.hxx" -#include "encoder/EncoderPlugin.hxx" -#include "encoder/EncoderList.hxx" +#include "encoder/Configured.hxx" #include "config/ConfigError.hxx" #include "config/ConfigPath.hxx" #include "Log.hxx" #include "fs/AllocatedPath.hxx" #include "fs/io/FileOutputStream.hxx" -#include "util/RuntimeError.hxx" #include "util/Domain.hxx" #include "util/ScopeExit.hxx" @@ -109,16 +107,11 @@ private: }; RecorderOutput::RecorderOutput(const ConfigBlock &block) - :AudioOutput(0) + :AudioOutput(0), + prepared_encoder(CreateConfiguredEncoder(block)) { /* read configuration */ - const char *encoder_name = - block.GetBlockValue("encoder", "vorbis"); - const auto encoder_plugin = encoder_plugin_get(encoder_name); - if (encoder_plugin == nullptr) - throw FormatRuntimeError("No such encoder: %s", encoder_name); - path = block.GetPath("path"); const char *fmt = block.GetBlockValue("format_path", nullptr); @@ -130,10 +123,6 @@ RecorderOutput::RecorderOutput(const ConfigBlock &block) if (!path.IsNull() && fmt != nullptr) throw std::runtime_error("Cannot have both 'path' and 'format_path'"); - - /* initialize encoder */ - - prepared_encoder.reset(encoder_init(*encoder_plugin, block)); } inline void diff --git a/src/output/plugins/ShoutOutputPlugin.cxx b/src/output/plugins/ShoutOutputPlugin.cxx index b30dae91d..6485e4140 100644 --- a/src/output/plugins/ShoutOutputPlugin.cxx +++ b/src/output/plugins/ShoutOutputPlugin.cxx @@ -21,8 +21,7 @@ #include "ShoutOutputPlugin.hxx" #include "../OutputAPI.hxx" #include "encoder/EncoderInterface.hxx" -#include "encoder/EncoderPlugin.hxx" -#include "encoder/EncoderList.hxx" +#include "encoder/Configured.hxx" #include "util/RuntimeError.hxx" #include "util/Domain.hxx" #include "util/StringAPI.hxx" @@ -88,17 +87,6 @@ require_block_string(const ConfigBlock &block, const char *name) return value; } -static const EncoderPlugin * -shout_encoder_plugin_get(const char *name) -{ - if (strcmp(name, "ogg") == 0) - name = "vorbis"; - else if (strcmp(name, "mp3") == 0) - name = "lame"; - - return encoder_plugin_get(name); -} - static void ShoutSetAudioInfo(shout_t *shout_conn, const AudioFormat &audio_format) { @@ -114,7 +102,8 @@ ShoutSetAudioInfo(shout_t *shout_conn, const AudioFormat &audio_format) ShoutOutput::ShoutOutput(const ConfigBlock &block) :AudioOutput(FLAG_PAUSE), shout_conn(shout_new()), - shout_meta(shout_metadata_new()) + shout_meta(shout_metadata_new()), + prepared_encoder(CreateConfiguredEncoder(block, true)) { NeedFullyDefinedAudioFormat(); @@ -156,16 +145,6 @@ ShoutOutput::ShoutOutput(const ConfigBlock &block) throw std::runtime_error("bitrate must be a positive integer"); } - const char *encoding = block.GetBlockValue("encoder", nullptr); - if (encoding == nullptr) - encoding = block.GetBlockValue("encoding", "vorbis"); - const auto encoder_plugin = shout_encoder_plugin_get(encoding); - if (encoder_plugin == nullptr) - throw FormatRuntimeError("couldn't find shout encoder plugin \"%s\"", - encoding); - - prepared_encoder.reset(encoder_init(*encoder_plugin, block)); - const char *const mime_type = prepared_encoder->GetMimeType(); unsigned shout_format; diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index 49a7c8f5b..731a5053a 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -23,15 +23,13 @@ #include "HttpdClient.hxx" #include "output/OutputAPI.hxx" #include "encoder/EncoderInterface.hxx" -#include "encoder/EncoderPlugin.hxx" -#include "encoder/EncoderList.hxx" +#include "encoder/Configured.hxx" #include "net/UniqueSocketDescriptor.hxx" #include "net/SocketAddress.hxx" #include "net/ToString.hxx" #include "Page.hxx" #include "IcyMetaDataServer.hxx" #include "event/Call.hxx" -#include "util/RuntimeError.hxx" #include "util/Domain.hxx" #include "util/DeleteDisposer.hxx" #include "Log.hxx" @@ -52,6 +50,7 @@ inline HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block) :AudioOutput(FLAG_ENABLE_DISABLE|FLAG_PAUSE), ServerSocket(_loop), + prepared_encoder(CreateConfiguredEncoder(block)), defer_broadcast(_loop, BIND_THIS_METHOD(OnDeferredBroadcast)) { /* read configuration */ @@ -61,12 +60,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block) unsigned port = block.GetBlockValue("port", 8000u); - const char *encoder_name = - block.GetBlockValue("encoder", "vorbis"); - const auto encoder_plugin = encoder_plugin_get(encoder_name); - if (encoder_plugin == nullptr) - throw FormatRuntimeError("No such encoder: %s", encoder_name); - clients_max = block.GetBlockValue("max_clients", 0u); /* set up bind_to_address */ @@ -77,10 +70,6 @@ HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block) else AddPort(port); - /* initialize encoder */ - - prepared_encoder.reset(encoder_init(*encoder_plugin, block)); - /* determine content type */ content_type = prepared_encoder->GetMimeType(); if (content_type == nullptr) |