output/Registry: replace output_plugins_for_each() with a container class
This commit is contained in:
parent
29747a213f
commit
cf5970a6e1
|
@ -173,8 +173,9 @@ static void version()
|
|||
#endif
|
||||
"\n\n"
|
||||
"Output plugins:\n");
|
||||
audio_output_plugins_for_each(plugin)
|
||||
fmt::print(" {}", plugin->name);
|
||||
for (const auto &plugin : GetAllAudioOutputPlugins()) {
|
||||
fmt::print(" {}", plugin.name);
|
||||
}
|
||||
fmt::print("\n"
|
||||
|
||||
#ifdef ENABLE_ENCODER
|
||||
|
|
|
@ -51,15 +51,15 @@ audio_output_detect()
|
|||
{
|
||||
LogInfo(output_domain, "Attempt to detect audio output device");
|
||||
|
||||
audio_output_plugins_for_each(plugin) {
|
||||
if (plugin->test_default_device == nullptr)
|
||||
for (const auto &plugin : GetAllAudioOutputPlugins()) {
|
||||
if (plugin.test_default_device == nullptr)
|
||||
continue;
|
||||
|
||||
FmtInfo(output_domain,
|
||||
"Attempting to detect a {:?} audio device",
|
||||
plugin->name);
|
||||
if (ao_plugin_test_default_device(plugin))
|
||||
return plugin;
|
||||
plugin.name);
|
||||
if (ao_plugin_test_default_device(&plugin))
|
||||
return &plugin;
|
||||
}
|
||||
|
||||
throw std::runtime_error("Unable to detect an audio device");
|
||||
|
|
|
@ -92,9 +92,10 @@ constinit const AudioOutputPlugin *const audio_output_plugins[] = {
|
|||
const AudioOutputPlugin *
|
||||
GetAudioOutputPluginByName(const char *name) noexcept
|
||||
{
|
||||
audio_output_plugins_for_each(plugin)
|
||||
if (StringIsEqual(plugin->name, name))
|
||||
return plugin;
|
||||
for (const auto &plugin : GetAllAudioOutputPlugins()) {
|
||||
if (StringIsEqual(plugin.name, name))
|
||||
return &plugin;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_OUTPUT_LIST_HXX
|
||||
#define MPD_OUTPUT_LIST_HXX
|
||||
#pragma once
|
||||
|
||||
#include "util/DereferenceIterator.hxx"
|
||||
#include "util/TerminatedArray.hxx"
|
||||
|
||||
struct AudioOutputPlugin;
|
||||
|
||||
extern const AudioOutputPlugin *const audio_output_plugins[];
|
||||
|
||||
static inline auto
|
||||
GetAllAudioOutputPlugins() noexcept
|
||||
{
|
||||
return DereferenceContainerAdapter{TerminatedArray<const AudioOutputPlugin *const, nullptr>{audio_output_plugins}};
|
||||
}
|
||||
|
||||
[[gnu::pure]]
|
||||
const AudioOutputPlugin *
|
||||
GetAudioOutputPluginByName(const char *name) noexcept;
|
||||
|
||||
#define audio_output_plugins_for_each(plugin) \
|
||||
for (const AudioOutputPlugin *plugin, \
|
||||
*const*output_plugin_iterator = &audio_output_plugins[0]; \
|
||||
(plugin = *output_plugin_iterator) != nullptr; ++output_plugin_iterator)
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue