aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-03-30 20:45:23 +0000
committermichux <michux@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2009-03-30 20:45:23 +0000
commit485253143e580e0347c04a04cc40c3298dfea3a9 (patch)
tree512776a072c80396c85f9eb286ecf173cfe819a8
parenta4601a3a9382a083f232e7b74213e0e836643297 (diff)
downloadlcd4linux-485253143e580e0347c04a04cc40c3298dfea3a9.tar.gz
add fps limiter
git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1017 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
-rw-r--r--drv_vnc.c34
-rw-r--r--lcd4linux.conf.sample1
2 files changed, 33 insertions, 2 deletions
diff --git a/drv_vnc.c b/drv_vnc.c
index 147b7dc..cd34d08 100644
--- a/drv_vnc.c
+++ b/drv_vnc.c
@@ -61,11 +61,11 @@
#include "drv_generic_graphic.h"
#include "drv_generic_keypad.h"
-//todo: fps limiter
-// key widget text
+//todo: key widget text
#define NO_MOUSE_BUTTON_PRESSED 0
#define LEFT_MOUSE_BUTTON_PRESSED 1
+#define SLEEP_STEPS 1000
static char Name[] = "VNC";
@@ -92,7 +92,10 @@ static int mouse_x = 0;
static int mouse_y = 0;
static int mouse_stat_old = 0;
static int process_event = 0;
+static long frames = 0;
static char *password;
+static struct timeval startDriver;
+static int maxfps = -1;
/* draws a simple rect, used to display keypad */
int draw_rect(int x, int y, int size, unsigned char col, char *buffer)
@@ -282,6 +285,9 @@ static int drv_vnc_open(const char *Section)
if (cfg_number(Section, "Port", 5900, 1, 65535, &port) < 1) {
info("[DRV_VNC] no '%s.Port' entry from %s using default %d", Section, cfg_source(), port);
}
+ if (cfg_number(Section, "Maxfps", -1, -1, 512, &maxfps) < 1) {
+ info("[DRV_VNC] no '%s.Maxfps' entry from %s using default %d", Section, cfg_source(), maxfps);
+ }
password = cfg_get(Section, "Password", NULL);
if (password != NULL) {
info("[DRV_VNC] password enabled");
@@ -302,6 +308,7 @@ static int drv_vnc_close(void)
/* actual blitting method */
static void drv_vnc_blit_it(const int row, const int col, const int height, const int width, unsigned char *buffer)
{
+ static int sleep = 0;
int r, c, ofs;
RGBA p;
@@ -329,8 +336,28 @@ static void drv_vnc_blit_it(const int row, const int col, const int height, cons
show_keypad_osd = 0;
}
}
+ frames++;
+ if ((frames % 10) == 0 && maxfps > 0) {
+ struct timeval blittime;
+ gettimeofday(&blittime, NULL);
+ int time_since_start =
+ (blittime.tv_sec - startDriver.tv_sec) * 1000 + (blittime.tv_usec - startDriver.tv_usec) / 1000;
+ int fps = (int) (1000 * frames / time_since_start);
+ //info("time :%d, frames: %d, fps: %d, sleep: %d", time_since_start, frames, fps, sleep);
+
+ if (fps > maxfps) {
+ sleep += SLEEP_STEPS;
+ }
+
+ if (fps < maxfps && sleep > SLEEP_STEPS) {
+ sleep -= SLEEP_STEPS;
+ }
+ }
+ usleep(sleep);
+
}
+
static void drv_vnc_blit(const int row, const int col, const int height, const int width)
{
@@ -397,6 +424,9 @@ static int drv_vnc_start(const char *section)
DROWS = yres;
DCOLS = xres;
+ /* set timestamp */
+ gettimeofday(&startDriver, NULL);
+
return 0;
}
diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample
index 9c0ed4d..191de0a 100644
--- a/lcd4linux.conf.sample
+++ b/lcd4linux.conf.sample
@@ -519,6 +519,7 @@ Display VNC {
Keypadcol '8745877'
Osd_showtime '2000'
# Password 'password'
+ Maxfps '25'
}
#Plugin KVV {