Skip to content

Commit

Permalink
Fix writing "PCM device not found" for file player
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Apr 30, 2021
1 parent 376ca7f commit c88b2d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
13 changes: 13 additions & 0 deletions client/player/file_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ namespace player
static constexpr auto LOG_TAG = "FilePlayer";
static constexpr auto kDefaultBuffer = 50ms;

static constexpr auto kDescription = "Raw PCM file output";

std::vector<PcmDevice> FilePlayer::pcm_list(const std::string& parameter)
{
auto params = utils::string::split_pairs(parameter, ',', '=');
string filename;
if (params.find("filename") != params.end())
filename = params["filename"];
if (filename.empty())
filename = "stdout";
return {PcmDevice{0, filename, kDescription}};
}


FilePlayer::FilePlayer(boost::asio::io_context& io_context, const ClientSettings::Player& settings, std::shared_ptr<Stream> stream)
: Player(io_context, settings, stream), timer_(io_context), file_(nullptr)
Expand Down
3 changes: 3 additions & 0 deletions client/player/file_player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class FilePlayer : public Player
void start() override;
void stop() override;

/// List the dummy file PCM device
static std::vector<PcmDevice> pcm_list(const std::string& parameter);

protected:
void requestAudio();
void loop();
Expand Down
8 changes: 6 additions & 2 deletions client/snapclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static constexpr auto LOG_TAG = "Snapclient";

PcmDevice getPcmDevice(const std::string& player, const std::string& parameter, const std::string& soundcard)
{
LOG(DEBUG, LOG_TAG) << "Trying to get PCM device for player: " << player << ", parameter: "
<< ", card: " << soundcard << "\n";
#if defined(HAS_ALSA) || defined(HAS_PULSE) || defined(HAS_WASAPI)
vector<PcmDevice> pcm_devices;
#if defined(HAS_ALSA)
Expand All @@ -73,6 +75,8 @@ PcmDevice getPcmDevice(const std::string& player, const std::string& parameter,
if (player == player::WASAPI)
pcm_devices = WASAPIPlayer::pcm_list();
#endif
if (player == player::FILE)
return FilePlayer::pcm_list(parameter).front();
try
{
int soundcardIdx = cpt::stoi(soundcard);
Expand Down Expand Up @@ -386,8 +390,8 @@ int main(int argc, char** argv)
#if defined(HAS_ALSA)
if (settings.player.pcm_device.idx == -1)
{
cout << "PCM device \"" << pcm_device << "\" not found\n";
// exit(EXIT_FAILURE);
LOG(ERROR, LOG_TAG) << "PCM device \"" << pcm_device << "\" not found\n";
// exit(EXIT_FAILURE);
}
#endif

Expand Down

0 comments on commit c88b2d1

Please sign in to comment.