summaryrefslogtreecommitdiff
path: root/src
diff options
authorMaciej Kisielewski <maciej.kisielewski@canonical.com>2019-09-13 18:12:45 +0200
committerMaciej Kisielewski <maciej.kisielewski@canonical.com>2019-09-13 18:12:45 +0200
commitc9956610c0a67d91dac8d0744666f77c5e1368b9 (patch)
tree7c443bd63da1fb48e7631505927300056ce852d3 /src
parentbfd58c26d50754cd7b362252608c3e0fa88eccb2 (diff)
alsa_test: add list-devices subcmd
Diffstat (limited to 'src')
-rw-r--r--src/alsa_test.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/alsa_test.cpp b/src/alsa_test.cpp
index 58a66e8d..deb2d6da 100644
--- a/src/alsa_test.cpp
+++ b/src/alsa_test.cpp
@@ -322,6 +322,31 @@ private:
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t* elem;
};
+
+std::vector<std::string> get_devices(std::string io) {
+ std::vector<std::string> result;
+ void **out;
+ int err = snd_device_name_hint(-1 /* all cards */, "pcm", &out);
+ if (err) {
+ logger.normal() << "Couldn't get the device hints" << std::endl;
+ return result;
+ }
+ while (*out) {
+ const char *name = snd_device_name_get_hint(*out, "NAME");
+ const char *desc = snd_device_name_get_hint(*out, "DESC");
+ const char *ioid = snd_device_name_get_hint(*out, "IOID");
+ if (ioid == nullptr) ioid = "Both";
+ logger.info() << "Got a device hint. Name: " << name
+ << " Description: " << desc
+ << " IOID: " << ioid << std::endl;
+ std::string direction{ioid};
+ if (direction == io) {
+ result.push_back(std::string{name});
+ }
+ out++;
+ }
+ return result;
+}
}; //namespace Alsa
template<class storage_type>
@@ -407,6 +432,24 @@ int list_formats(){
std::cout << "description: " << format.second << std::endl;
std::cout << std::endl;
}
+ return 0;
+}
+
+int list_devices() {
+ auto playback = Alsa::get_devices("Output");
+ auto record = Alsa::get_devices("Input");
+ auto both = Alsa::get_devices("Both");
+ std::copy(both.begin(), both.end(), std::back_inserter(playback));
+ std::copy(both.begin(), both.end(), std::back_inserter(record));
+ std::cout << "Playback devices: " << std::endl;
+ for (auto i = playback.cbegin(); i != playback.cend(); ++i) {
+ std::cout << *i << std::endl;
+ }
+ std::cout << "\n\nRecording devices: " << std::endl;
+ for (auto i = record.cbegin(); i != record.cend(); ++i) {
+ std::cout << *i << std::endl;
+ }
+ return 0;
}
void set_volumes(const std::string playback_pcm, const std::string capture_pcm) {
@@ -503,6 +546,9 @@ int main(int argc, char *argv[]) {
else if (scenario == "list-formats") {
return list_formats();
}
+ else if (scenario == "list-devices") {
+ return list_devices();
+ }
if (scenarios.find(args[1]) == scenarios.end()) {
std::cerr << args[1] << " scenario not found!" << std::endl;
return 1;