diff options
author | Josh Blum | 2011-03-09 13:39:07 -0800 |
---|---|---|
committer | Josh Blum | 2011-03-09 13:39:07 -0800 |
commit | 78f735f4174c2a0fe275da41252e227226af5b3b (patch) | |
tree | f8ab2f66667666e0baa532bf1a34d97397e929ec /gr-audio/lib | |
parent | 8bd65a04463692e6f179a5fc4f23d73782103781 (diff) | |
download | gnuradio-78f735f4174c2a0fe275da41252e227226af5b3b.tar.gz gnuradio-78f735f4174c2a0fe275da41252e227226af5b3b.tar.bz2 gnuradio-78f735f4174c2a0fe275da41252e227226af5b3b.zip |
audio: register arches with priorities, ex: prefer alsa over oss
Diffstat (limited to 'gr-audio/lib')
-rw-r--r-- | gr-audio/lib/alsa/audio_alsa_sink.cc | 2 | ||||
-rw-r--r-- | gr-audio/lib/alsa/audio_alsa_source.cc | 2 | ||||
-rw-r--r-- | gr-audio/lib/gr_audio_registry.cc | 74 | ||||
-rw-r--r-- | gr-audio/lib/gr_audio_registry.h | 32 | ||||
-rw-r--r-- | gr-audio/lib/oss/audio_oss_sink.cc | 2 | ||||
-rw-r--r-- | gr-audio/lib/oss/audio_oss_source.cc | 2 |
6 files changed, 75 insertions, 39 deletions
diff --git a/gr-audio/lib/alsa/audio_alsa_sink.cc b/gr-audio/lib/alsa/audio_alsa_sink.cc index af5cc02be..0728f421c 100644 --- a/gr-audio/lib/alsa/audio_alsa_sink.cc +++ b/gr-audio/lib/alsa/audio_alsa_sink.cc @@ -33,7 +33,7 @@ #include <stdexcept> #include <gri_alsa.h> -AUDIO_REGISTER_SINK(alsa)( +AUDIO_REGISTER_SINK(REG_PRIO_HIGH, alsa)( int sampling_rate, const std::string &device_name, bool ok_to_block ){ return audio_sink::sptr(new audio_alsa_sink(sampling_rate, device_name, ok_to_block)); diff --git a/gr-audio/lib/alsa/audio_alsa_source.cc b/gr-audio/lib/alsa/audio_alsa_source.cc index a8667361e..e46a7fdd4 100644 --- a/gr-audio/lib/alsa/audio_alsa_source.cc +++ b/gr-audio/lib/alsa/audio_alsa_source.cc @@ -33,7 +33,7 @@ #include <stdexcept> #include <gri_alsa.h> -AUDIO_REGISTER_SOURCE(alsa)( +AUDIO_REGISTER_SOURCE(REG_PRIO_HIGH, alsa)( int sampling_rate, const std::string &device_name, bool ok_to_block ){ return audio_source::sptr(new audio_alsa_source(sampling_rate, device_name, ok_to_block)); diff --git a/gr-audio/lib/gr_audio_registry.cc b/gr-audio/lib/gr_audio_registry.cc index 7be652807..7aa9dc7a4 100644 --- a/gr-audio/lib/gr_audio_registry.cc +++ b/gr-audio/lib/gr_audio_registry.cc @@ -24,33 +24,55 @@ #include <gr_prefs.h> #include <stdexcept> #include <vector> -#include <utility> #include <iostream> /*********************************************************************** * Create registries **********************************************************************/ -typedef std::pair<std::string, source_factory_t> source_pair_t; -static std::vector<source_pair_t> &get_source_registry(void){ - static std::vector<source_pair_t> _registry; + +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; } -typedef std::pair<std::string, sink_factory_t> sink_pair_t; -static std::vector<sink_pair_t> &get_sink_registry(void){ - static std::vector<sink_pair_t> _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(const std::string &name, source_factory_t source){ - get_source_registry().push_back(std::make_pair(name, source)); +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(const std::string &name, sink_factory_t sink){ - get_sink_registry().push_back(std::make_pair(name, sink)); +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); } /*********************************************************************** @@ -61,6 +83,7 @@ static std::string default_arch_name(void){ } static void do_arch_warning(const std::string &arch){ + if (arch.empty()) 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; } @@ -73,14 +96,17 @@ audio_source::sptr audio_make_source( if (get_source_registry().empty()){ 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); - } + 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); } - do_arch_warning(arch); - return get_source_registry().front().second(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( @@ -91,14 +117,18 @@ audio_sink::sptr audio_make_sink( if (get_sink_registry().empty()){ 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); - } + 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 + return e.sink(sampling_rate, device_name, ok_to_block); } do_arch_warning(arch); - return get_sink_registry().front().second(sampling_rate, device_name, ok_to_block); + //std::cout << "Audio sink arch: " << entry.name << std::endl; + return entry.sink(sampling_rate, device_name, ok_to_block); } /*********************************************************************** diff --git a/gr-audio/lib/gr_audio_registry.h b/gr-audio/lib/gr_audio_registry.h index 71f6ad11d..ec341e95e 100644 --- a/gr-audio/lib/gr_audio_registry.h +++ b/gr-audio/lib/gr_audio_registry.h @@ -29,21 +29,27 @@ typedef audio_source::sptr(*source_factory_t)(int, const std::string &, bool); typedef audio_sink::sptr(*sink_factory_t)(int, const std::string &, bool); -void audio_register_source(const std::string &name, source_factory_t source); -void audio_register_sink(const std::string &name, sink_factory_t sink); +enum reg_prio_type{ + REG_PRIO_LOW = 100, + REG_PRIO_MED = 200, + REG_PRIO_HIGH = 300 +}; + +void audio_register_source(reg_prio_type prio, const std::string &arch, source_factory_t source); +void audio_register_sink(reg_prio_type prio, const std::string &arch, sink_factory_t sink); #define AUDIO_REGISTER_FIXTURE(x) static struct x{x();}x;x::x() -#define AUDIO_REGISTER_SOURCE(name) \ - static audio_source::sptr name##_source_fcn(int, const std::string &, bool); \ - AUDIO_REGISTER_FIXTURE(name##_source_reg){ \ - audio_register_source(#name, &name##_source_fcn); \ - } static audio_source::sptr name##_source_fcn - -#define AUDIO_REGISTER_SINK(name) \ - static audio_sink::sptr name##_sink_fcn(int, const std::string &, bool); \ - AUDIO_REGISTER_FIXTURE(name##_sink_reg){ \ - audio_register_sink(#name, &name##_sink_fcn); \ - } static audio_sink::sptr name##_sink_fcn +#define AUDIO_REGISTER_SOURCE(prio, arch) \ + static audio_source::sptr arch##_source_fcn(int, const std::string &, bool); \ + AUDIO_REGISTER_FIXTURE(arch##_source_reg){ \ + audio_register_source(prio, #arch, &arch##_source_fcn); \ + } static audio_source::sptr arch##_source_fcn + +#define AUDIO_REGISTER_SINK(prio, arch) \ + static audio_sink::sptr arch##_sink_fcn(int, const std::string &, bool); \ + AUDIO_REGISTER_FIXTURE(arch##_sink_reg){ \ + audio_register_sink(prio, #arch, &arch##_sink_fcn); \ + } static audio_sink::sptr arch##_sink_fcn #endif /* INCLUDED_GR_AUDIO_REGISTRY_H */ diff --git a/gr-audio/lib/oss/audio_oss_sink.cc b/gr-audio/lib/oss/audio_oss_sink.cc index a33e569f6..4e9e7cd79 100644 --- a/gr-audio/lib/oss/audio_oss_sink.cc +++ b/gr-audio/lib/oss/audio_oss_sink.cc @@ -38,7 +38,7 @@ #include <iostream> #include <stdexcept> -AUDIO_REGISTER_SINK(oss)( +AUDIO_REGISTER_SINK(REG_PRIO_LOW, oss)( int sampling_rate, const std::string &device_name, bool ok_to_block ){ return audio_sink::sptr(new audio_oss_sink(sampling_rate, device_name, ok_to_block)); diff --git a/gr-audio/lib/oss/audio_oss_source.cc b/gr-audio/lib/oss/audio_oss_source.cc index f52af1bb8..b7d53931d 100644 --- a/gr-audio/lib/oss/audio_oss_source.cc +++ b/gr-audio/lib/oss/audio_oss_source.cc @@ -38,7 +38,7 @@ #include <iostream> #include <stdexcept> -AUDIO_REGISTER_SOURCE(oss)( +AUDIO_REGISTER_SOURCE(REG_PRIO_LOW, oss)( int sampling_rate, const std::string &device_name, bool ok_to_block ){ return audio_source::sptr(new audio_oss_source(sampling_rate, device_name, ok_to_block)); |