From 6beb823f150c965adf057c3fd423aa23dcb77997 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 13 Dec 2018 16:23:31 -0500 Subject: audio_core: Make g_sink_details internally linked We can hide the direct array from external view and instead provide functions to retrieve the necessary info. This has the benefit of completely hiding the makeup of the SinkDetails structure from the rest of the code. Given that this makes the array hidden, we can also make the array constexpr by altering the members slightly. This gets rid of several static constructor calls related to std::vector and std::function. Now we don't have heap allocations here that need to occur before the program can even enter main(). It also has the benefit of saving a little bit of heap space, but this doesn't matter too much, since the savings in that regard are pretty tiny. --- src/audio_core/sink_details.h | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'src/audio_core/sink_details.h') diff --git a/src/audio_core/sink_details.h b/src/audio_core/sink_details.h index 03534b187..bc8786270 100644 --- a/src/audio_core/sink_details.h +++ b/src/audio_core/sink_details.h @@ -4,34 +4,21 @@ #pragma once -#include -#include #include #include -#include #include namespace AudioCore { class Sink; -struct SinkDetails { - using FactoryFn = std::function(std::string)>; - using ListDevicesFn = std::function()>; +/// Retrieves the IDs for all available audio sinks. +std::vector GetSinkIDs(); - SinkDetails(const char* id_, FactoryFn factory_, ListDevicesFn list_devices_) - : id(id_), factory(std::move(factory_)), list_devices(std::move(list_devices_)) {} +/// Gets the list of devices for a particular sink identified by the given ID. +std::vector GetDeviceListForSink(std::string_view sink_id); - /// Name for this sink. - const char* id; - /// A method to call to construct an instance of this type of sink. - FactoryFn factory; - /// A method to call to list available devices. - ListDevicesFn list_devices; -}; - -extern const std::vector g_sink_details; - -const SinkDetails& GetSinkDetails(std::string_view sink_id); +/// Creates an audio sink identified by the given device ID. +std::unique_ptr CreateSinkFromID(std::string_view sink_id, std::string_view device_id); } // namespace AudioCore -- cgit v1.2.3