- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <signal.h>
- #include <sys/time.h>
- static long begin_time;
- static long end_time;
- static long frame_counter;
- void conv_fps2itimerval(int fps, struct itimerval *value)
- {
- value->it_value.tv_sec = 0;
- value->it_value.tv_usec = 1000000/fps;
- value->it_interval.tv_sec = 0;
- value->it_interval.tv_usec = 1000000/fps;
- }
- void *sigroutine(int signo)
- {
- if (SIGALRM == signo) {
- //
- // 在这里动态调整fps,请问相关的算法什么呀,谢啦~
- //
- ++frame_counter;
- struct timeval val;
- if (-1 == gettimeofday(&val, NULL)) {
- perror("gettimeofday");
- exit(1);
- }
- end_time = val.tv_sec*1000000 + val.tv_usec;
- long gap_time = end_time - begin_time;
- if (gap_time > 1000000) {
- printf("current fps is: %.3lf\n", frame_counter*1000000/(double) gap_time);
- begin_time = end_time;
- frame_counter = 0;
- }
- }
- return (void *) NULL;
- }
- int main(int argc, char **argv)
- {
- struct itimerval value;
- if (SIG_ERR == signal(SIGALRM, (__sighandler_t) sigroutine)) {
- perror("signal");
- exit(1);
- }
- conv_fps2itimerval(25, &value); // 设置每秒钟产生25次中断
- if (-1 == setitimer(ITIMER_REAL, &value, NULL)) {
- perror("setitimer");
- exit(1);
- }
- for ( ; ; ) {
- usleep(10);
- }
- return 0;
- }
复制代码 程序中设置了每秒钟产生25次中断,模拟25fps的情况。现在求一个算法,
把25fps降到一个特定值(例如10fps),~~~
{:3_200:} |
|