diff --git a/libcommlitchee.c b/libcommlitchee.c index 1c77d66..a9a4cee 100644 --- a/libcommlitchee.c +++ b/libcommlitchee.c @@ -4,12 +4,15 @@ #include "libcommlitchee.h" #include +#include #include #define CONFIG_FILE "/etc/libcommlitchee.conf" #define COMM_LITCHEE_MAX_FPS_TOK "MAX_FPS=" +static int do_fps_filter=0; +static struct sigaction sigaction_fps; static int comm_litchee_max_fps = 25; /* Default value */ static void read_config(void); @@ -95,6 +98,7 @@ LITCHEE_ENTRY_POINT comm_handle_t* comm_exec_app(comm_param_t * com_param) LITCHEE_ENTRY_POINT void comm_read_current_buffer(comm_handle_t* tt, char * z_buffer) { + if(!tt) { return; } @@ -151,6 +155,11 @@ LITCHEE_ENTRY_POINT void comm_close_current_app(comm_handle_t* tt) free(tt); } + +void do_fps_filtering() { + do_fps_filter=0; +} + comm_handle_t* comm_init(char * name) { int nbbytes = 0; @@ -191,6 +200,11 @@ comm_handle_t* comm_init(char * name) nbbytes += read(STDIN, com->tsc_events+nbbytes, sizeof(char)); } + if (comm_litchee_max_fps > 0) { + sigaction_fps.sa_handler = do_fps_filtering; + sigaction_fps.sa_flags=0; + sigaction(SIGALRM, &sigaction_fps, NULL); + } return com; } @@ -216,21 +230,18 @@ void * comm_get_buffer(comm_handle_t* com) int comm_commit_buffer(comm_handle_t* com) { int ret = 0; - struct timeval tv; - long long diff; if(com->soc < 0) { return -1; } if(comm_litchee_max_fps > 0) { - gettimeofday(&tv, NULL); - diff = (tv.tv_sec * 1000000 + tv.tv_usec) - - (com->last_commit.tv_sec * 1000000 + com->last_commit.tv_usec); - - if(diff > 0 && diff < (1000000 / comm_litchee_max_fps)) - /* Don't block game, ignore frame */ + /* Don't block game, ignore frame */ + if (do_fps_filter == 1 ) return 0; + + do_fps_filter=1; + ualarm(1000*1000/comm_litchee_max_fps, 0); } pthread_mutex_lock(&(com->shm->mut)); @@ -243,9 +254,6 @@ int comm_commit_buffer(comm_handle_t* com) if(ret == -1) return errno; - if(comm_litchee_max_fps > 0) - gettimeofday(&com->last_commit, NULL); - return 0; }