25 #endif // WITH_SNDFILE 28 static const std::string DEFAULT_HOST =
"0.0.0.0";
31 static const std::string DEFAULT_PORT =
"1350";
34 static const std::map<std::string, Player::SourceFn> SOURCES = {
36 {
"mp3", &std::make_unique<Mp3AudioSource, const std::string &>},
40 {
"flac", &std::make_unique<SndfileAudioSource, const std::string &>},
41 {
"ogg", &std::make_unique<SndfileAudioSource, const std::string &>},
42 {
"wav", &std::make_unique<SndfileAudioSource, const std::string &>},
43 #endif // WITH_SNDFILE 54 std::vector<std::string> args;
55 for (
int i = 0; i < argc; i++) args.emplace_back(argv[i]);
67 if (args.size() < 2)
return -1;
72 id = std::stoi(args.at(1));
90 std::cerr <<
"usage: " << progname <<
" ID [HOST] [PORT]\n";
91 std::cerr <<
"where ID is one of the following numbers:\n";
95 for (
const auto &device : device_list) {
96 std::cerr <<
"\t" << device.first <<
": " << device.second
100 std::cerr <<
"default HOST: " << DEFAULT_HOST <<
"\n";
101 std::cerr <<
"default PORT: " << DEFAULT_PORT <<
"\n";
113 const std::vector<std::string> &args)
115 auto size = args.size();
116 return std::make_pair(size > 2 ? args.at(2) : DEFAULT_HOST,
117 size > 3 ? args.at(3) : DEFAULT_PORT);
127 const std::string &msg)
129 std::cerr <<
"Network error: " << msg <<
"\n";
130 std::cerr <<
"Is " << host <<
":" << port <<
" available?\n";
140 std::cerr <<
"Unhandled exception in main loop: " << msg << std::endl;
150 int main(
int argc,
char *argv[])
156 signal(SIGPIPE, SIG_IGN);
178 &std::make_unique<SdlAudioSink, const AudioSource &, int>,
static void CleanupLibrary()
Cleans up the AudioSink's libraries, if not cleaned up already.
Constant human-readable messages used within playd.
Declaration of the I/O classes used in playd.
Declaration of the Mp3AudioSource class.
const std::string & Message() const
The human-readable message for this error.
void ExitWithNetError(const std::string &host, const std::string &port, const std::string &msg)
Exits with an error message for a network error.
std::pair< std::string, std::string > GetHostAndPort(const std::vector< std::string > &args)
Gets the host and port from the program arguments.
static bool IsOutputDevice(int id)
Can a sound device output sound?
void Run(const std::string &host, const std::string &port)
Runs the reactor.
static void InitLibrary()
Initialises the AudioSink's libraries, if not initialised already.
Declaration of the Player class, and associated types.
int GetDeviceID(const std::vector< std::string > &args)
Tries to get the output device ID from program arguments.
Declaration of classes pertaining to responses to the client.
void ExitWithError(const std::string &msg)
Exits with an error message for an unhandled exception.
std::vector< std::string > MakeArgVector(int argc, char *argv[])
Creates a vector of strings from a C-style argument vector.
void ExitWithUsage(const std::string &progname)
Reports usage information and exits.
Declaration of the SndfileAudioSource class.
int main(int argc, char *argv[])
The main entry point.
static std::vector< std::pair< int, std::string > > GetDevicesInfo()
Gets the number and name of each output device entry in the AudioSystem.
A Player contains a loaded audio file and a command API for manipulating it.
The IO core, which services input, routes responses, and executes the Player update routine periodica...