DecoderPlugin.hxx 4.28 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * 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.
14 15 16 17
 *
 * 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.
18 19
 */

20 21
#ifndef MPD_DECODER_PLUGIN_HXX
#define MPD_DECODER_PLUGIN_HXX
22

23 24
#include "Compiler.h"

25 26
#include <forward_list>

27
struct ConfigBlock;
28
class InputStream;
29
class TagHandler;
30
class Path;
31
class DecoderClient;
32
class DetachedSong;
33

34
struct DecoderPlugin {
35 36 37
	const char *name;

	/**
38 39
	 * Initialize the decoder plugin.  Optional method.
	 *
Max Kellermann's avatar
Max Kellermann committed
40
	 * @param param a configuration block for this plugin, or nullptr
41 42 43
	 * if none is configured
	 * @return true if the plugin was initialized successfully,
	 * false if the plugin is not available
44
	 */
45
	bool (*init)(const ConfigBlock &block);
46 47

	/**
48 49
	 * Deinitialize a decoder plugin which was initialized
	 * successfully.  Optional method.
50
	 */
51
	void (*finish)() noexcept;
52 53

	/**
54
	 * Decode a stream (data read from an #InputStream object).
55
	 *
56 57 58
	 * Either implement this method or file_decode().  If
	 * possible, it is recommended to implement this method,
	 * because it is more versatile.
59
	 */
60
	void (*stream_decode)(DecoderClient &client, InputStream &is);
61 62

	/**
63
	 * Decode a local file.
64
	 *
65
	 * Either implement this method or stream_decode().
66
	 */
67
	void (*file_decode)(DecoderClient &client, Path path_fs);
68 69

	/**
70
	 * Scan metadata of a file.
71
	 *
72
	 * @return false if the operation has failed
73
	 */
74
	bool (*scan_file)(Path path_fs, TagHandler &handler) noexcept;
75

76
	/**
77
	 * Scan metadata of a file.
78
	 *
79
	 * @return false if the operation has failed
80
	 */
81
	bool (*scan_stream)(InputStream &is, TagHandler &handler) noexcept;
82

83 84 85
	/**
	 * @brief Return a "virtual" filename for subtracks in
	 * container formats like flac
86
	 * @param path_fs full pathname for the file on fs
87
	 *
88 89
	 * @return an empty list if there are no multiple files
	 * a filename for every single track;
90 91
	 * do not include full pathname here, just the "virtual" file
	 */
92
	std::forward_list<DetachedSong> (*container_scan)(Path path_fs);
93

Max Kellermann's avatar
Max Kellermann committed
94
	/* last element in these arrays must always be a nullptr: */
95 96 97
	const char *const*suffixes;
	const char *const*mime_types;

98 99 100
	/**
	 * Initialize a decoder plugin.
	 *
Max Kellermann's avatar
Max Kellermann committed
101
	 * @param block a configuration block for this plugin
102 103 104
	 * @return true if the plugin was initialized successfully, false if
	 * the plugin is not available
	 */
105
	bool Init(const ConfigBlock &block) const {
106
		return init != nullptr
107
			? init(block)
108 109
			: true;
	}
110

111 112 113 114 115 116 117
	/**
	 * Deinitialize a decoder plugin which was initialized successfully.
	 */
	void Finish() const {
		if (finish != nullptr)
			finish();
	}
118

119 120 121
	/**
	 * Decode a stream.
	 */
122 123
	void StreamDecode(DecoderClient &client, InputStream &is) const {
		stream_decode(client, is);
124
	}
125

126 127 128
	/**
	 * Decode a file.
	 */
129
	template<typename P>
130 131
	void FileDecode(DecoderClient &client, P path_fs) const {
		file_decode(client, path_fs);
132
	}
133

134 135 136
	/**
	 * Read the tag of a file.
	 */
137
	template<typename P>
138
	bool ScanFile(P path_fs, TagHandler &handler) const noexcept {
139
		return scan_file != nullptr
140
			? scan_file(path_fs, handler)
141 142
			: false;
	}
143

144 145 146
	/**
	 * Read the tag of a stream.
	 */
147
	bool ScanStream(InputStream &is, TagHandler &handler) const noexcept {
148
		return scan_stream != nullptr
149
			? scan_stream(is, handler)
150 151
			: false;
	}
152

153 154 155
	/**
	 * return "virtual" tracks in a container
	 */
156 157
	template<typename P>
	char *ContainerScan(P path, const unsigned int tnum) const {
158 159
		return container_scan(path, tnum);
	}
160

161 162 163 164
	/**
	 * Does the plugin announce the specified file name suffix?
	 */
	gcc_pure gcc_nonnull_all
165
	bool SupportsSuffix(const char *suffix) const noexcept;
166

167 168 169 170
	/**
	 * Does the plugin announce the specified MIME type?
	 */
	gcc_pure gcc_nonnull_all
171
	bool SupportsMimeType(const char *mime_type) const noexcept;
172
};
173

174
#endif