MPD  0.20.15
DecoderPlugin.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_DECODER_PLUGIN_HXX
21 #define MPD_DECODER_PLUGIN_HXX
22 
23 #include "Compiler.h"
24 
25 #include <forward_list>
26 
27 struct ConfigBlock;
28 class InputStream;
29 struct TagHandler;
30 class Path;
31 class DecoderClient;
32 class DetachedSong;
33 
34 struct DecoderPlugin {
35  const char *name;
36 
45  bool (*init)(const ConfigBlock &block);
46 
51  void (*finish)();
52 
60  void (*stream_decode)(DecoderClient &client, InputStream &is);
61 
67  void (*file_decode)(DecoderClient &client, Path path_fs);
68 
74  bool (*scan_file)(Path path_fs,
75  const TagHandler &handler,
76  void *handler_ctx);
77 
83  bool (*scan_stream)(InputStream &is,
84  const TagHandler &handler,
85  void *handler_ctx);
86 
96  std::forward_list<DetachedSong> (*container_scan)(Path path_fs);
97 
98  /* last element in these arrays must always be a nullptr: */
99  const char *const*suffixes;
100  const char *const*mime_types;
101 
109  bool Init(const ConfigBlock &block) const {
110  return init != nullptr
111  ? init(block)
112  : true;
113  }
114 
118  void Finish() const {
119  if (finish != nullptr)
120  finish();
121  }
122 
126  void StreamDecode(DecoderClient &client, InputStream &is) const {
127  stream_decode(client, is);
128  }
129 
133  template<typename P>
134  void FileDecode(DecoderClient &client, P path_fs) const {
135  file_decode(client, path_fs);
136  }
137 
141  template<typename P>
142  bool ScanFile(P path_fs,
143  const TagHandler &handler, void *handler_ctx) const {
144  return scan_file != nullptr
145  ? scan_file(path_fs, handler, handler_ctx)
146  : false;
147  }
148 
153  const TagHandler &handler, void *handler_ctx) const {
154  return scan_stream != nullptr
155  ? scan_stream(is, handler, handler_ctx)
156  : false;
157  }
158 
162  template<typename P>
163  char *ContainerScan(P path, const unsigned int tnum) const {
164  return container_scan(path, tnum);
165  }
166 
171  bool SupportsSuffix(const char *suffix) const noexcept;
172 
177  bool SupportsMimeType(const char *mime_type) const noexcept;
178 };
179 
180 #endif
An interface between the decoder plugin and the MPD core.
Definition: Client.hxx:39
gcc_pure gcc_nonnull_all bool SupportsSuffix(const char *suffix) const noexcept
Does the plugin announce the specified file name suffix?
bool Init(const ConfigBlock &block) const
Initialize a decoder plugin.
#define gcc_nonnull_all
Definition: Compiler.h:122
void(* stream_decode)(DecoderClient &client, InputStream &is)
Decode a stream (data read from an InputStream object).
bool ScanFile(P path_fs, const TagHandler &handler, void *handler_ctx) const
Read the tag of a file.
std::forward_list< DetachedSong >(* container_scan)(Path path_fs)
Return a "virtual" filename for subtracks in container formats like flac.
A callback table for receiving metadata of a song.
Definition: TagHandler.hxx:32
const char *const * mime_types
void Finish() const
Deinitialize a decoder plugin which was initialized successfully.
char * ContainerScan(P path, const unsigned int tnum) const
return "virtual" tracks in a container
void StreamDecode(DecoderClient &client, InputStream &is) const
Decode a stream.
A path name in the native file system character set.
Definition: Path.hxx:39
gcc_pure gcc_nonnull_all bool SupportsMimeType(const char *mime_type) const noexcept
Does the plugin announce the specified MIME type?
void FileDecode(DecoderClient &client, P path_fs) const
Decode a file.
bool ScanStream(InputStream &is, const TagHandler &handler, void *handler_ctx) const
Read the tag of a stream.
bool(* scan_stream)(InputStream &is, const TagHandler &handler, void *handler_ctx)
Scan metadata of a file.
bool(* scan_file)(Path path_fs, const TagHandler &handler, void *handler_ctx)
Scan metadata of a file.
void(* finish)()
Deinitialize a decoder plugin which was initialized successfully.
void(* file_decode)(DecoderClient &client, Path path_fs)
Decode a local file.
bool(* init)(const ConfigBlock &block)
Initialize the decoder plugin.
#define gcc_pure
Definition: Compiler.h:116
const char *const * suffixes
const char * name