From 0ac77af7db957f8746282b60d57e04d65f7d9054 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 9 Mar 2011 12:31:28 -0800 Subject: audio: use conf files to specify default arch --- gr-audio/lib/gr_audio_registry.cc | 42 +++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'gr-audio/lib/gr_audio_registry.cc') diff --git a/gr-audio/lib/gr_audio_registry.cc b/gr-audio/lib/gr_audio_registry.cc index be1337101..7be652807 100644 --- a/gr-audio/lib/gr_audio_registry.cc +++ b/gr-audio/lib/gr_audio_registry.cc @@ -20,20 +20,25 @@ */ #include "gr_audio_registry.h" +#include +#include #include #include #include +#include /*********************************************************************** * Create registries **********************************************************************/ -static std::vector > &get_source_registry(void){ - static std::vector > _registry; +typedef std::pair source_pair_t; +static std::vector &get_source_registry(void){ + static std::vector _registry; return _registry; } -static std::vector > &get_sink_registry(void){ - static std::vector > _registry; +typedef std::pair sink_pair_t; +static std::vector &get_sink_registry(void){ + static std::vector _registry; return _registry; } @@ -51,15 +56,30 @@ void audio_register_sink(const std::string &name, sink_factory_t sink){ /*********************************************************************** * Factory functions **********************************************************************/ +static std::string default_arch_name(void){ + return gr_prefs::singleton()->get_string("audio", "default_arch", ""); +} + +static void do_arch_warning(const std::string &arch){ + std::cerr << "Could not find audio architecture \"" << arch << "\" in registry." << std::endl; + std::cerr << " Defaulting to the first available architecture..." << std::endl; +} + audio_source::sptr audio_make_source( int sampling_rate, const std::string device_name, bool ok_to_block ){ if (get_source_registry().empty()){ - throw std::runtime_error("no available audio factories"); + throw std::runtime_error("no available audio source factories"); + } + std::string arch = default_arch_name(); + BOOST_FOREACH(const source_pair_t &e, get_source_registry()){ + if (arch.empty() || arch == e.first){ + return e.second(sampling_rate, device_name, ok_to_block); + } } - //TODO we may prefer to use a specific entry in the registry + do_arch_warning(arch); return get_source_registry().front().second(sampling_rate, device_name, ok_to_block); } @@ -69,9 +89,15 @@ audio_sink::sptr audio_make_sink( bool ok_to_block ){ if (get_sink_registry().empty()){ - throw std::runtime_error("no available audio factories"); + throw std::runtime_error("no available audio sink factories"); + } + std::string arch = default_arch_name(); + BOOST_FOREACH(const sink_pair_t &e, get_sink_registry()){ + if (arch.empty() || arch == e.first){ + return e.second(sampling_rate, device_name, ok_to_block); + } } - //TODO we may prefer to use a specific entry in the registry + do_arch_warning(arch); return get_sink_registry().front().second(sampling_rate, device_name, ok_to_block); } -- cgit