Skip to content

Commit

Permalink
Add a "no signal" message to the output window
Browse files Browse the repository at this point in the history
  • Loading branch information
leikareipa committed Nov 18, 2023
1 parent a8b036e commit dd2ab0b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
54 changes: 45 additions & 9 deletions src/scaler/scaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
#include "filter/filter.h"
#include "filter/abstract_filter.h"
#include "filter/filters/output_scaler/filter_output_scaler.h"
#include "filter/filters/render_text/font_10x6_serif.h"
#include "filter/filters/render_text/font_10x6_sans_serif.h"
#include "scaler/scaler.h"
#include "common/timer/timer.h"

// For keeping track of the number of frames scaled per second.
static unsigned NUM_FRAMES_SCALED_PER_SECOND = 0;

static std::string STATUS_MESSAGE = "";

// The image scalers available to VCS.
static const std::vector<image_scaler_s> KNOWN_SCALERS = {
{"Nearest", filter_output_scaler_c::nearest},
Expand Down Expand Up @@ -144,18 +148,35 @@ subsystem_releaser_t ks_initialize_scaler(void)

ev_new_captured_frame.listen([](const captured_frame_s &frame)
{
ks_scale_frame(frame);
if (kc_has_signal())
{
ks_scale_frame(frame);
}
else
{
DEBUG(("Was asked to scale a frame while there was no signal. Ignoring this."));
return;
}
});

ev_invalid_capture_signal.listen([]
{
ks_indicate_invalid_signal();
ks_indicate_status("INVALID SIGNAL");
ev_dirty_output_window.fire();
});

ev_new_output_resolution.listen([]
{
if (!kc_has_signal())
{
ks_indicate_status(STATUS_MESSAGE);
ev_dirty_output_window.fire();
}
});

ev_capture_signal_lost.listen([]
{
ks_indicate_no_signal();
ks_indicate_status("NO SIGNAL");
ev_dirty_output_window.fire();
});

Expand Down Expand Up @@ -213,6 +234,7 @@ void ks_scale_frame(const captured_frame_s &frame)
}
else if (!FRAME_BUFFER_PIXELS)
{
DEBUG(("Was asked to scale a frame before the scaler's frame buffer had been initialized. Ignoring it."));
return;
}
}
Expand Down Expand Up @@ -316,17 +338,31 @@ static void clear_frame_buffer(void)
return;
}

void ks_indicate_no_signal(void)
void ks_indicate_status(const std::string &message)
{
clear_frame_buffer();
STATUS_MESSAGE = message;

return;
}
const unsigned fontScale = 7;
static font_c *const font = new font_5x3_c;

void ks_indicate_invalid_signal(void)
{
clear_frame_buffer();

FRAME_BUFFER_RESOLUTION = ks_output_resolution();
image_s image = {
.pixels = FRAME_BUFFER_PIXELS,
.resolution = FRAME_BUFFER_RESOLUTION
};
font->render(
message,
&image,
(image.resolution.w / 2),
(image.resolution.h / 2) - ((font->height_of(message) * fontScale) / 2),
fontScale,
{0, 0, 0},
{160, 160, 160},
filter_render_text_c::ALIGN_CENTER
);

return;
}

Expand Down
10 changes: 2 additions & 8 deletions src/scaler/scaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,11 @@ void ks_set_base_resolution(const resolution_s &r);
// If disabled, the base resolution will be the resolution of the input frame.
void ks_set_base_resolution_enabled(const bool enabled);

// Draws a "no signal" image into the scaler subsystem's frame buffer, erasing
// Draws the given status message into the scaler subsystem's frame buffer, erasing
// any previous image there.
//
// A subsequent call to ks_scale_frame() will overwite the image.
void ks_indicate_no_signal(void);

// Draws an "invalid signal" image into the scaler subsystem's frame buffer,
// erasing any previous image there.
//
// A subsequent call to ks_scale_frame() will overwite the image.
void ks_indicate_invalid_signal(void);
void ks_indicate_status(const std::string &message);

// Returns a reference to the scaler subsystem's frame buffer.
//
Expand Down

0 comments on commit dd2ab0b

Please sign in to comment.