diff options
Diffstat (limited to 'gr-audio/lib/gr_audio_registry.cc')
-rw-r--r-- | gr-audio/lib/gr_audio_registry.cc | 212 |
1 files changed, 117 insertions, 95 deletions
diff --git a/gr-audio/lib/gr_audio_registry.cc b/gr-audio/lib/gr_audio_registry.cc index e07bf844ac..5446eb09bb 100644 --- a/gr-audio/lib/gr_audio_registry.cc +++ b/gr-audio/lib/gr_audio_registry.cc @@ -1,5 +1,5 @@ /* - * Copyright 2011 Free Software Foundation, Inc. + * Copyright 2011,2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -26,107 +26,129 @@ #include <vector> #include <iostream> -/*********************************************************************** - * Create registries - **********************************************************************/ - -struct source_entry_t{ - reg_prio_type prio; - std::string arch; - source_factory_t source; -}; - -static std::vector<source_entry_t> &get_source_registry(void){ - static std::vector<source_entry_t> _registry; - return _registry; -} - -struct sink_entry_t{ - reg_prio_type prio; - std::string arch; - sink_factory_t sink; -}; - -static std::vector<sink_entry_t> &get_sink_registry(void){ - static std::vector<sink_entry_t> _registry; - return _registry; -} - -/*********************************************************************** - * Register functions - **********************************************************************/ -void audio_register_source( - reg_prio_type prio, const std::string &arch, source_factory_t source -){ - source_entry_t entry; - entry.prio = prio; - entry.arch = arch; - entry.source = source; - get_source_registry().push_back(entry); -} - -void audio_register_sink( - reg_prio_type prio, const std::string &arch, sink_factory_t sink -){ - sink_entry_t entry; - entry.prio = prio; - entry.arch = arch; - entry.sink = sink; - get_sink_registry().push_back(entry); -} - -/*********************************************************************** - * Factory functions - **********************************************************************/ -static std::string default_arch_name(void){ - return gr_prefs::singleton()->get_string("audio", "audio_module", "auto"); -} - -static void do_arch_warning(const std::string &arch){ - if (arch == "auto") return; //no warning when arch not specified - 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 source factories"); +namespace gr { + namespace audio { + + /*********************************************************************** + * Create registries + **********************************************************************/ + + struct source_entry_t { + reg_prio_type prio; + std::string arch; + source_factory_t source; + }; + + static std::vector<source_entry_t> &get_source_registry(void) + { + static std::vector<source_entry_t> d_registry; + return d_registry; + } + + struct sink_entry_t + { + reg_prio_type prio; + std::string arch; + sink_factory_t sink; + }; + + static std::vector<sink_entry_t> &get_sink_registry(void) + { + static std::vector<sink_entry_t> d_registry; + return d_registry; } - std::string arch = default_arch_name(); - source_entry_t entry = get_source_registry().front(); + /*********************************************************************** + * Register functions + **********************************************************************/ + void + register_source(reg_prio_type prio, + const std::string &arch, + source_factory_t source) + { + source_entry_t entry; + entry.prio = prio; + entry.arch = arch; + entry.source = source; + get_source_registry().push_back(entry); + } + + void register_sink(reg_prio_type prio, + const std::string &arch, + sink_factory_t sink) + { + sink_entry_t entry; + entry.prio = prio; + entry.arch = arch; + entry.sink = sink; + get_sink_registry().push_back(entry); + } + + /*********************************************************************** + * Factory functions + **********************************************************************/ + static std::string default_arch_name(void) + { + return gr_prefs::singleton()->get_string("audio", "audio_module", "auto"); + } - BOOST_FOREACH(const source_entry_t &e, get_source_registry()){ - if (e.prio > entry.prio) entry = e; //entry is highest prio - if (arch != e.arch) continue; //continue when no match + static void do_arch_warning(const std::string &arch) + { + if(arch == "auto") + return; //no warning when arch not specified + std::cerr << "Could not find audio architecture \"" << arch + << "\" in registry." << std::endl; + std::cerr << " Defaulting to the first available architecture..." << std::endl; + } + + source::sptr + source::make(int sampling_rate, + const std::string device_name, + bool ok_to_block) + { + if(get_source_registry().empty()) { + throw std::runtime_error("no available audio source factories"); + } + + std::string arch = default_arch_name(); + source_entry_t entry = get_source_registry().front(); + + BOOST_FOREACH(const source_entry_t &e, get_source_registry()) { + if(e.prio > entry.prio) + entry = e; //entry is highest prio + if(arch != e.arch) + continue; //continue when no match return e.source(sampling_rate, device_name, ok_to_block); + } + + //std::cout << "Audio source arch: " << entry.name << std::endl; + return entry.source(sampling_rate, device_name, ok_to_block); } - //std::cout << "Audio source arch: " << entry.name << std::endl; - return entry.source(sampling_rate, device_name, ok_to_block); -} - -audio_sink::sptr audio_make_sink( - int sampling_rate, - const std::string device_name, - bool ok_to_block -){ - if (get_sink_registry().empty()){ + + sink::sptr + sink::make(int sampling_rate, + const std::string device_name, + bool ok_to_block) + { + if(get_sink_registry().empty()) { throw std::runtime_error("no available audio sink factories"); - } + } - std::string arch = default_arch_name(); - sink_entry_t entry = get_sink_registry().front(); + std::string arch = default_arch_name(); + sink_entry_t entry = get_sink_registry().front(); - BOOST_FOREACH(const sink_entry_t &e, get_sink_registry()){ - if (e.prio > entry.prio) entry = e; //entry is highest prio - if (arch != e.arch) continue; //continue when no match + BOOST_FOREACH(const sink_entry_t &e, get_sink_registry()) { + if(e.prio > entry.prio) + entry = e; //entry is highest prio + if(arch != e.arch) + continue; //continue when no match return e.sink(sampling_rate, device_name, ok_to_block); + } + + do_arch_warning(arch); + //std::cout << "Audio sink arch: " << entry.name << std::endl; + return entry.sink(sampling_rate, device_name, ok_to_block); } - do_arch_warning(arch); - //std::cout << "Audio sink arch: " << entry.name << std::endl; - return entry.sink(sampling_rate, device_name, ok_to_block); -} + + } /* namespace audio */ +} /* namespace gr */ |