mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-03-31 09:17:04 +09:00
Add audio devices
This commit is contained in:
@@ -62,5 +62,12 @@ namespace gsr {
|
|||||||
NO_DRM_CARD
|
NO_DRM_CARD
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AudioDevice {
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
};
|
||||||
|
|
||||||
GsrInfoExitStatus get_gpu_screen_recorder_info(GsrInfo *gsr_info);
|
GsrInfoExitStatus get_gpu_screen_recorder_info(GsrInfo *gsr_info);
|
||||||
|
|
||||||
|
std::vector<AudioDevice> get_audio_devices();
|
||||||
}
|
}
|
||||||
@@ -15,5 +15,6 @@ namespace gsr {
|
|||||||
};
|
};
|
||||||
|
|
||||||
void init_theme(const gsr::GsrInfo &gsr_info);
|
void init_theme(const gsr::GsrInfo &gsr_info);
|
||||||
|
void deinit_theme();
|
||||||
const Theme& get_theme();
|
const Theme& get_theme();
|
||||||
}
|
}
|
||||||
@@ -176,4 +176,44 @@ namespace gsr {
|
|||||||
|
|
||||||
return GsrInfoExitStatus::FAILED_TO_RUN_COMMAND;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,32 +3,39 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
static Theme theme;
|
static Theme *theme = nullptr;
|
||||||
static bool initialized = false;
|
|
||||||
|
|
||||||
void init_theme(const gsr::GsrInfo &gsr_info) {
|
void init_theme(const gsr::GsrInfo &gsr_info) {
|
||||||
|
assert(!theme);
|
||||||
|
theme = new Theme();
|
||||||
|
|
||||||
switch(gsr_info.gpu_info.vendor) {
|
switch(gsr_info.gpu_info.vendor) {
|
||||||
case gsr::GpuVendor::UNKNOWN: {
|
case gsr::GpuVendor::UNKNOWN: {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case gsr::GpuVendor::AMD: {
|
case gsr::GpuVendor::AMD: {
|
||||||
theme.tint_color = mgl::Color(221, 0, 49);
|
theme->tint_color = mgl::Color(221, 0, 49);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case gsr::GpuVendor::INTEL: {
|
case gsr::GpuVendor::INTEL: {
|
||||||
theme.tint_color = mgl::Color(8, 109, 183);
|
theme->tint_color = mgl::Color(8, 109, 183);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case gsr::GpuVendor::NVIDIA: {
|
case gsr::GpuVendor::NVIDIA: {
|
||||||
theme.tint_color = mgl::Color(118, 185, 0);
|
theme->tint_color = mgl::Color(118, 185, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initialized = true;
|
}
|
||||||
|
|
||||||
|
void deinit_theme() {
|
||||||
|
assert(theme);
|
||||||
|
delete theme;
|
||||||
|
theme = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Theme& get_theme() {
|
const Theme& get_theme() {
|
||||||
assert(initialized);
|
assert(theme);
|
||||||
return theme;
|
return *theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
16
src/main.cpp
16
src/main.cpp
@@ -149,6 +149,9 @@ int main(int argc, char **argv) {
|
|||||||
fprintf(stderr, "error: failed to get gpu-screen-recorder info\n");
|
fprintf(stderr, "error: failed to get gpu-screen-recorder info\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::vector<gsr::AudioDevice> audio_devices = gsr::get_audio_devices();
|
||||||
|
|
||||||
gsr::init_theme(gsr_info);
|
gsr::init_theme(gsr_info);
|
||||||
|
|
||||||
std::string program_root_dir = dirname(argv[0]);
|
std::string program_root_dir = dirname(argv[0]);
|
||||||
@@ -482,6 +485,11 @@ int main(int argc, char **argv) {
|
|||||||
gsr::Page *settings_content_page = settings_content_pages[i];
|
gsr::Page *settings_content_page = settings_content_pages[i];
|
||||||
|
|
||||||
auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font);
|
auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font);
|
||||||
|
record_area_box->set_position(mgl::vec2f(50.0f, 50.0f));
|
||||||
|
|
||||||
|
const mgl::vec2f record_area_pos = record_area_box->get_position();
|
||||||
|
const mgl::vec2f record_area_size = record_area_box->get_size();
|
||||||
|
|
||||||
if(gsr_info.supported_capture_options.window)
|
if(gsr_info.supported_capture_options.window)
|
||||||
record_area_box->add_item("Window", "window");
|
record_area_box->add_item("Window", "window");
|
||||||
if(gsr_info.supported_capture_options.focused)
|
if(gsr_info.supported_capture_options.focused)
|
||||||
@@ -497,6 +505,13 @@ int main(int argc, char **argv) {
|
|||||||
record_area_box->add_item("Desktop portal", "portal");
|
record_area_box->add_item("Desktop portal", "portal");
|
||||||
settings_content_page->add_widget(std::move(record_area_box));
|
settings_content_page->add_widget(std::move(record_area_box));
|
||||||
|
|
||||||
|
auto audio_device_box = std::make_unique<gsr::ComboBox>(&title_font);
|
||||||
|
audio_device_box->set_position(record_area_pos + mgl::vec2f(0.0f, record_area_size.y + 50.0f));
|
||||||
|
for(const auto &audio_device : audio_devices) {
|
||||||
|
audio_device_box->add_item(audio_device.description, audio_device.name);
|
||||||
|
}
|
||||||
|
settings_content_page->add_widget(std::move(audio_device_box));
|
||||||
|
|
||||||
auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color);
|
auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color);
|
||||||
back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor());
|
back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor());
|
||||||
back_button->on_click = settings_back_button_callback;
|
back_button->on_click = settings_back_button_callback;
|
||||||
@@ -622,5 +637,6 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "shutting down!\n");
|
fprintf(stderr, "shutting down!\n");
|
||||||
|
gsr::deinit_theme();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user