diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-08-02 00:45:27 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-08-02 00:45:27 +0200 |
commit | 495bd6bed85c85650620dc2ae91f7f058ae2da5c (patch) | |
tree | 6029ae984bc3b76ab6d01cf7942abc650de25db2 /src/GsrInfo.cpp | |
parent | be0ad41e745c3e6177d1159e25f7d23e45b02738 (diff) |
Add audio devices
Diffstat (limited to 'src/GsrInfo.cpp')
-rw-r--r-- | src/GsrInfo.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/GsrInfo.cpp b/src/GsrInfo.cpp index 1534363..6aa1c17 100644 --- a/src/GsrInfo.cpp +++ b/src/GsrInfo.cpp @@ -176,4 +176,44 @@ namespace gsr { return GsrInfoExitStatus::FAILED_TO_RUN_COMMAND; } + + static AudioDevice parse_audio_device_line(const std::string &line) { + AudioDevice audio_device; + const size_t space_index = line.find(' '); + if(space_index == std::string::npos) + return audio_device; + + const std::string_view audio_input_name = {line.c_str(), space_index}; + const std::string_view audio_input_description = {line.c_str() + space_index + 1, line.size() - (space_index + 1)}; + audio_device.name.assign(audio_input_name.data(), audio_input_name.size()); + audio_device.description.assign(audio_input_description.data(), audio_input_description.size()); + return audio_device; + } + + std::vector<AudioDevice> get_audio_devices() { + std::vector<AudioDevice> audio_devices; + + FILE *f = popen("gpu-screen-recorder --list-audio-devices", "r"); + if(!f) { + fprintf(stderr, "error: 'gpu-screen-recorder --info' failed\n"); + return audio_devices; + } + + char output[16384]; + ssize_t bytes_read = fread(output, 1, sizeof(output) - 1, f); + if(bytes_read < 0 || ferror(f)) { + fprintf(stderr, "error: failed to read 'gpu-screen-recorder --info' output\n"); + pclose(f); + return audio_devices; + } + output[bytes_read] = '\0'; + + string_split_char(output, '\n', [&](std::string_view line) { + const std::string line_str(line.data(), line.size()); + audio_devices.push_back(parse_audio_device_line(line_str)); + return true; + }); + + return audio_devices; + } }
\ No newline at end of file |