summaryrefslogtreecommitdiff
path: root/src/encoder
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-11-10 21:37:56 +0100
committerMax Kellermann <max@musicpd.org>2017-11-10 21:54:57 +0100
commit6464b4b3720d91d07c99bf8411a95ec7e3c35eb2 (patch)
tree7ac43e8ed563add4a42375f24fe8ce3d919ac32d /src/encoder
parentfef9747fbf351bcd43259b0dc2f4fde4c93dcf6c (diff)
encoder/Configured: glue code to initialize PreparedEncoder
Diffstat (limited to 'src/encoder')
-rw-r--r--src/encoder/Configured.cxx57
-rw-r--r--src/encoder/Configured.hxx39
2 files changed, 96 insertions, 0 deletions
diff --git a/src/encoder/Configured.cxx b/src/encoder/Configured.cxx
new file mode 100644
index 000000000..4e6c900f8
--- /dev/null
+++ b/src/encoder/Configured.cxx
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2003-2017 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+#include "Configured.hxx"
+#include "EncoderList.hxx"
+#include "EncoderPlugin.hxx"
+#include "config/Block.hxx"
+#include "util/StringAPI.hxx"
+#include "util/RuntimeError.hxx"
+
+static const EncoderPlugin &
+GetConfiguredEncoderPlugin(const ConfigBlock &block, bool shout_legacy)
+{
+ const char *name = block.GetBlockValue("encoder", nullptr);
+ if (name == nullptr && shout_legacy)
+ name = block.GetBlockValue("encoding", nullptr);
+
+ if (name == nullptr)
+ name = "vorbis";
+
+ if (shout_legacy) {
+ if (StringIsEqual(name, "ogg"))
+ name = "vorbis";
+ else if (StringIsEqual(name, "mp3"))
+ name = "lame";
+ }
+
+ const auto plugin = encoder_plugin_get(name);
+ if (plugin == nullptr)
+ throw FormatRuntimeError("No such encoder: %s", name);
+
+ return *plugin;
+}
+
+PreparedEncoder *
+CreateConfiguredEncoder(const ConfigBlock &block, bool shout_legacy)
+{
+ return encoder_init(GetConfiguredEncoderPlugin(block, shout_legacy),
+ block);
+}
diff --git a/src/encoder/Configured.hxx b/src/encoder/Configured.hxx
new file mode 100644
index 000000000..b2ebd2d7d
--- /dev/null
+++ b/src/encoder/Configured.hxx
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2003-2017 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_ENCODER_CONFIGURED_HXX
+#define MPD_ENCODER_CONFIGURED_HXX
+
+struct ConfigBlock;
+class PreparedEncoder;
+
+/**
+ * Create a #PreparedEncoder instance from the settings in the
+ * #ConfigBlock. Its "encoder" setting is used to choose the encoder
+ * plugin.
+ *
+ * Throws an exception on error.
+ *
+ * @param shout_legacy enable the "shout" plugin legacy configuration?
+ * i.e. fall back to setting "encoding" instead of "encoder"
+ */
+PreparedEncoder *
+CreateConfiguredEncoder(const ConfigBlock &block, bool shout_legacy=false);
+
+#endif