diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 24669423..ad047d6a 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -87,6 +87,7 @@ endif() set(SOURCES ${CMAKE_BINARY_DIR}/version.c src/app.c + src/downsample_parser.c ) add_subdirectory("${PROJECT_TOP}/common" "${CMAKE_BINARY_DIR}/common") diff --git a/host/include/downsample_parser.h b/host/include/downsample_parser.h new file mode 100644 index 00000000..ef428279 --- /dev/null +++ b/host/include/downsample_parser.h @@ -0,0 +1,48 @@ +/** + * looking glass + * copyright © 2017-2023 the looking glass authors + * https://looking-glass.io + * + * this program is free software; you can redistribute it and/or modify it + * under the terms of the gnu general public license as published by the free + * software foundation; either version 2 of the license, or (at your option) + * any later version. + * + * this program is distributed in the hope that it will be useful, but without + * any warranty; without even the implied warranty of merchantability or + * fitness for a particular purpose. see the gnu general public license for + * more details. + * + * you should have received a copy of the gnu general public license along + * with this program; if not, write to the free software foundation, inc., 59 + * temple place, suite 330, boston, ma 02111-1307 usa + */ + +#include +#include "common/option.h" +#include "common/vector.h" + +typedef struct +{ + unsigned int id; + bool greater; + unsigned int x; + unsigned int y; + unsigned int targetX; + unsigned int targetY; +} +DownsampleRule; + +extern Vector downsampleRules; + +bool downsampleParser(struct Option * opt, const char * str); + +#define DOWNSAMPLE_PARSER(moduleName) \ +{ \ + .module = moduleName, \ + .name = "downsample", \ + .description = "Downsample rules, format: [>](width)x(height):(toWidth)x(toHeight)", \ + .type = OPTION_TYPE_STRING, \ + .value.x_string = NULL, \ + .parser = downsampleParser \ +} diff --git a/host/platform/Windows/capture/NVFBC/src/nvfbc.c b/host/platform/Windows/capture/NVFBC/src/nvfbc.c index 65173be4..1a86bd9c 100644 --- a/host/platform/Windows/capture/NVFBC/src/nvfbc.c +++ b/host/platform/Windows/capture/NVFBC/src/nvfbc.c @@ -38,6 +38,8 @@ #include #include +#include "downsample_parser.h" + #include #include "wrapper.h" @@ -51,17 +53,6 @@ struct FrameInfo uint8_t * diffMap; }; -typedef struct -{ - unsigned int id; - bool greater; - unsigned int x; - unsigned int y; - unsigned int targetX; - unsigned int targetY; -} -DownsampleRule; - struct iface { bool stop; @@ -101,8 +92,6 @@ struct iface struct FrameInfo frameInfo[LGMP_Q_FRAME_LEN]; }; -static Vector downsampleRules = {0}; - static struct iface * this = NULL; static bool nvfbc_deinit(void); @@ -144,78 +133,11 @@ static const char * nvfbc_getName(void) return "NVFBC"; }; -static bool downsampleOptParser(struct Option * opt, const char * str) -{ - if (!str) - return false; - - opt->value.x_string = strdup(str); - - if (downsampleRules.data) - vector_destroy(&downsampleRules); - - if (!vector_create(&downsampleRules, sizeof(DownsampleRule), 10)) - { - DEBUG_ERROR("Failed to allocate ram"); - return false; - } - - char * tmp = strdup(str); - char * token = strtok(tmp, ","); - int count = 0; - while(token) - { - DownsampleRule rule = {0}; - if (token[0] == '>') - { - rule.greater = true; - ++token; - } - - if (sscanf(token, "%ux%u:%ux%u", - &rule.x, - &rule.y, - &rule.targetX, - &rule.targetY) != 4) - { - DEBUG_INFO("Unable to parse NvFBC downsample rules"); - return false; - } - - rule.id = count++; - - DEBUG_INFO( - "Rule %u: %ux%u IF X %s %4u %s Y %s %4u", - rule.id, - rule.targetX, - rule.targetY, - rule.greater ? "> " : "==", - rule.x, - rule.greater ? "OR " : "AND", - rule.greater ? "> " : "==", - rule.y - ); - vector_push(&downsampleRules, &rule); - - token = strtok(NULL, ","); - } - free(tmp); - - return true; -} - static void nvfbc_initOptions(void) { struct Option options[] = { - { - .module = "nvfbc", - .name = "downsample", //dxgi:downsample=>1920x1080:1920x1080 - .description = "Downsample rules, format: [>](width)x(height):(toWidth)x(toHeight)", - .type = OPTION_TYPE_STRING, - .value.x_string = NULL, - .parser = downsampleOptParser - }, + DOWNSAMPLE_PARSER("nvfbc"), { .module = "nvfbc", .name = "decoupleCursor", diff --git a/host/src/downsample_parser.c b/host/src/downsample_parser.c new file mode 100644 index 00000000..69aa80cd --- /dev/null +++ b/host/src/downsample_parser.c @@ -0,0 +1,86 @@ +/** + * looking glass + * copyright © 2017-2023 the looking glass authors + * https://looking-glass.io + * + * this program is free software; you can redistribute it and/or modify it + * under the terms of the gnu general public license as published by the free + * software foundation; either version 2 of the license, or (at your option) + * any later version. + * + * this program is distributed in the hope that it will be useful, but without + * any warranty; without even the implied warranty of merchantability or + * fitness for a particular purpose. see the gnu general public license for + * more details. + * + * you should have received a copy of the gnu general public license along + * with this program; if not, write to the free software foundation, inc., 59 + * temple place, suite 330, boston, ma 02111-1307 usa + */ + +#include "downsample_parser.h" +#include "common/debug.h" + +#include + +Vector downsampleRules = {0}; + +bool downsampleParser(struct Option * opt, const char * str) +{ + if (!str) + return false; + + opt->value.x_string = strdup(str); + + if (downsampleRules.data) + vector_destroy(&downsampleRules); + + if (!vector_create(&downsampleRules, sizeof(DownsampleRule), 10)) + { + DEBUG_ERROR("Failed to allocate ram"); + return false; + } + + char * tmp = strdup(str); + char * token = strtok(tmp, ","); + int count = 0; + while(token) + { + DownsampleRule rule = {0}; + if (token[0] == '>') + { + rule.greater = true; + ++token; + } + + if (sscanf(token, "%ux%u:%ux%u", + &rule.x, + &rule.y, + &rule.targetX, + &rule.targetY) != 4) + { + DEBUG_INFO("Unable to parse downsample rules"); + return false; + } + + rule.id = count++; + + DEBUG_INFO( + "Rule %u: %ux%u IF X %s %4u %s Y %s %4u", + rule.id, + rule.targetX, + rule.targetY, + rule.greater ? "> " : "==", + rule.x, + rule.greater ? "OR " : "AND", + rule.greater ? "> " : "==", + rule.y + ); + vector_push(&downsampleRules, &rule); + + token = strtok(NULL, ","); + } + free(tmp); + + return true; +}