output/alsa: add "allowed_formats" setting

Allows defining a list of supported audio formats, and allows
switching on and off DoP with certain formats.

This is a first rough draft.  The setting syntax and its semantics may
still be redesigned.
This commit is contained in:
Max Kellermann
2017-10-26 09:06:40 +02:00
parent 967d81b782
commit 44c60567dd
5 changed files with 190 additions and 8 deletions

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* 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.
*
* 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.
*/
#include "config.h"
#include "AllowedFormat.hxx"
#include "AudioParser.hxx"
#include "util/IterableSplitString.hxx"
#include <stdexcept>
namespace Alsa {
AllowedFormat::AllowedFormat(StringView s)
{
#ifdef ENABLE_DSD
const StringView dop_tail("=dop");
if (s.EndsWith(dop_tail)) {
dop = true;
s.size -= dop_tail.size;
} else
dop = false;
#endif
char buffer[64];
if (s.size >= sizeof(buffer))
throw std::runtime_error("Failed to parse audio format");
memcpy(buffer, s.data, s.size);
buffer[s.size] = 0;
format = ParseAudioFormat(buffer, true);
#ifdef ENABLE_DSD
if (dop && format.format != SampleFormat::DSD)
throw std::runtime_error("DoP works only with DSD");
#endif
}
std::forward_list<AllowedFormat>
AllowedFormat::ParseList(StringView s)
{
std::forward_list<AllowedFormat> list;
auto tail = list.before_begin();
for (const auto i : IterableSplitString(s, ' '))
if (!i.empty())
tail = list.emplace_after(tail, i);
return list;
}
} // namespace Alsa

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2003-2017 The Music Player Daemon Project
* 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.
*
* 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.
*/
#ifndef MPD_ALSA_ALLOWED_FORMAT_HXX
#define MPD_ALSA_ALLOWED_FORMAT_HXX
#include "check.h"
#include "AudioFormat.hxx"
#include <forward_list>
struct StringView;
namespace Alsa {
struct AllowedFormat {
AudioFormat format;
#ifdef ENABLE_DSD
bool dop;
#endif
explicit AllowedFormat(StringView s);
static std::forward_list<AllowedFormat> ParseList(StringView s);
};
} // namespace Alsa
#endif