Add null sink to file player

This commit is contained in:
badaix 2020-12-09 09:21:52 +01:00
parent 8eb2fbc212
commit 1da7681570
2 changed files with 7 additions and 4 deletions

View file

@ -47,7 +47,7 @@ FilePlayer::FilePlayer(boost::asio::io_context& io_context, const ClientSettings
{ {
file_.reset(stderr, [](auto p) { std::ignore = p; }); file_.reset(stderr, [](auto p) { std::ignore = p; });
} }
else else if (filename != "null")
{ {
std::string mode = "w"; std::string mode = "w";
if (params.find("mode") != params.end()) if (params.find("mode") != params.end())
@ -91,8 +91,11 @@ void FilePlayer::requestAudio()
{ {
adjustVolume(static_cast<char*>(buffer_.data()), numFrames); adjustVolume(static_cast<char*>(buffer_.data()), numFrames);
} }
fwrite(buffer_.data(), 1, needed, file_.get()); if (file_)
fflush(file_.get()); {
fwrite(buffer_.data(), 1, needed, file_.get());
fflush(file_.get());
}
loop(); loop();
} }

View file

@ -335,7 +335,7 @@ int main(int argc, char** argv)
if (settings.player.player_name == "file") if (settings.player.player_name == "file")
{ {
cout << "Options are a comma separated list of:\n" cout << "Options are a comma separated list of:\n"
<< " \"filename=<filename>\" - with <filename> = \"stdout\", \"stderr\" or a filename\n" << " \"filename=<filename>\" - with <filename> = \"stdout\", \"stderr\", \"null\" or a filename\n"
<< " \"mode=[w|a]\" - w: write (discarding the content), a: append (keeping the content)\n"; << " \"mode=[w|a]\" - w: write (discarding the content), a: append (keeping the content)\n";
} }
else if (settings.player.player_name == "pulse") else if (settings.player.player_name == "pulse")