Skip to content

Commit

Permalink
debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
f0e committed Oct 6, 2023
1 parent f29f4da commit 42fc022
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ void c_config::create(const std::filesystem::path& filepath, s_blur_settings cur
output << "gpu type (nvidia/amd/intel): " << current_settings.gpu_type << "\n";
output << "video container: " << current_settings.video_container << "\n";
output << "custom ffmpeg filters: " << current_settings.ffmpeg_override << "\n";
output << "debug: " << (current_settings.debug ? "true" : "false") << "\n";

output << "\n";
output << "- advanced blur" << "\n";
Expand All @@ -57,7 +58,7 @@ void c_config::create(const std::filesystem::path& filepath, s_blur_settings cur
output << "interpolation block size: " << current_settings.interpolation_blocksize << "\n";
output << "interpolation speed: " << current_settings.interpolation_speed << "\n";
output << "interpolation mask area: " << current_settings.interpolation_mask_area << "\n";

if (current_settings.manual_svp) {
output << "\n";
output << "- manual svp override" << "\n";
Expand Down Expand Up @@ -162,6 +163,7 @@ s_blur_settings c_config::parse(const std::filesystem::path& config_filepath) {
config_get_str("gpu type (nvidia/amd/intel)", settings.gpu_type);
config_get("video container", settings.video_container);
config_get_str("custom ffmpeg filters", settings.ffmpeg_override);
config_get("debug", settings.debug);

config_get("blur weighting gaussian std dev", settings.blur_weighting_gaussian_std_dev);
config_get("blur weighting triangle reverse", settings.blur_weighting_triangle_reverse);
Expand Down
1 change: 1 addition & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct s_blur_settings {
std::string gpu_type = "nvidia";
std::string video_container = "mp4";
std::string ffmpeg_override = "";
bool debug = false;

float blur_weighting_gaussian_std_dev = 2.f;
bool blur_weighting_triangle_reverse = false;
Expand Down
2 changes: 1 addition & 1 deletion src/common/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace helpers {
template<typename... args_t>
inline void debug_log(std::string_view str, args_t&&... args) {
#ifdef _DEBUG
std::cout << "[debug]";
std::cout << "[debug] ";
printf(str.data(), std::forward<args_t>(args)...);
putchar('\n');
#endif
Expand Down
18 changes: 18 additions & 0 deletions src/common/rendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#include "script_handler.h"
#include "preview.h"

#ifdef BLUR_GUI
#include <gui/console.h>
#endif

void c_rendering::render_videos() {
if (!queue.empty()) {
current_render = queue.front();
Expand Down Expand Up @@ -200,6 +204,7 @@ bool c_render::do_render(s_render_command render_command) {
vspipe_si.hStdError = hPipeWriteErr;

std::wstring vspipe_command = render_command.pipe_command;
wprintf(L"%s\n", vspipe_command.c_str());
BOOL bSuccess = CreateProcess(nullptr, vspipe_command.data(), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &vspipe_si, &rendering.vspipe_pi);

CloseHandle(rendering.vspipe_pi.hThread);
Expand All @@ -225,6 +230,7 @@ bool c_render::do_render(s_render_command render_command) {
ffmpeg_si.dwFlags = STARTF_USESTDHANDLES;

std::wstring ffmpeg_command = render_command.ffmpeg_command;
wprintf(L"%s\n", ffmpeg_command.c_str());
bool success = CreateProcess(nullptr, ffmpeg_command.data(), nullptr, nullptr, TRUE, CREATE_NO_WINDOW, nullptr, nullptr, &ffmpeg_si, &rendering.ffmpeg_pi);

CloseHandle(rendering.ffmpeg_pi.hThread);
Expand Down Expand Up @@ -281,6 +287,18 @@ void c_render::render() {

wprintf(L"Rendering '%s'\n", video_name.c_str());

#ifndef _DEBUG
#ifdef BLUR_GUI
if (settings.debug) {
console::init();
}
else {
// todo: close console
// console::close();
}
#endif
#endif

if (blur.verbose) {
printf("Render settings:\n");
printf("Source video at %.2f timescale\n", settings.input_timescale);
Expand Down
4 changes: 4 additions & 0 deletions src/common/rendering.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class c_render {
return output_path;
}

s_blur_settings get_settings() {
return settings;
}

public:
void render();

Expand Down
26 changes: 20 additions & 6 deletions src/gui/console.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
#include "console.h"

bool console::init() {
if (initialised)
return false;

if (!AllocConsole())
return false;

atexit([]() {
FreeConsole();
console::close();
});

if (freopen_s(&stream, "CONOUT$", "w", stdout) != 0)
if (freopen_s(&stream, "CONOUT$", "w", stdout) != NO_ERROR)
return false;

atexit([]() {
fclose(stream);
});

initialised = true;
return true;
}

bool console::close() {
if (!initialised)
return false;

if (!FreeConsole())
return false;

if (stream) {
if (fclose(stream) != NO_ERROR)
return false;
}

initialised = false;
return true;
}
1 change: 1 addition & 0 deletions src/gui/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ namespace console {
inline FILE* stream;

bool init();
bool close();
}

0 comments on commit 42fc022

Please sign in to comment.