ffmpeg键盘命令响应程序详解
- #include <termios.h>
- struct termios {
- tcflag_t c_iflag;
- tcflag_t c_oflag;
- tcflag_t c_cflag;
- tcflag_t c_lflag;
- cc_t c_cc[NCCS];
- };
- #include <termios.h>
- int tcgetattr(int fd, struct termios *termios_p);
- #include <termios.h>
- int tcsetattr(int fd, int actions, const struct termios *termios_p);
- #include <termios.h>
- speed_t cfgetispeed(const struct termios *);
- speed_t cfgetospeed(const struct termios *);
- int cfsetispeed(struct termios *, speed_t speed);
- int cfsetospeed(struct termios *, speed_t speed);
- #include <termios.h>
- int tcdrain(int fd);
- int tcflow(int fd, int flowtype);
- int tcflush(int fd, int in_out_selector);
- /*
- * \File
- * main.c
- * \Descript
- * Taken from ffmpeg,
- * implement for signal response function
- * \Author
- * Neo Yan
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <limits.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <sys/time.h>
- #include <termios.h>
- static struct termios oldtty;
- static int q_pressed = 0;
- static int verbose = 1;
- static int using_stdin = 0;
- static int run_as_daemon = 0;
- static volatile int received_sigterm = 0;
- static void term_init(void);
- static void term_exit(void);
- static void sigterm_handler(int sig);
- static int read_key(void);
- /*
- * \Func
- * main
- * \Descript
- *
- */
- int main(int argc, char **argv)
- {
- int index = 0;
- int key;
- if (!using_stdin)
- {
- if (verbose >= 0)
- printf("Perss [q] to stop, [?] for help\n");
- }
- term_init();
- for ( ; received_sigterm == 0; )
- {
- /* if 'q' pressed, exits */
- if (!using_stdin)
- {
- if (q_pressed)
- break;
- /* read_key() returns 0 on EOF */
- key = read_key();
- if (key == 'q')
- {
- printf("quit\n");
- break;
- }
- if (key == '+')
- {
- verbose++;
- printf("verbose = %d\n", verbose);
- }
- if (key == '-')
- {
- verbose--;
- printf("verbose = %d\n", verbose);
- }
- if (key == '?')
- {
- printf("key function\n"
- "? show this help\n"
- "+ increase verbosity\n"
- "- decrease verbosity\n"
- "q quit\n"
- );
- }
- }
- printf("index = %d\n", index++);
- sleep(1);
- }
- return 0;
- }
- static void term_init(void)
- {
- if (!run_as_daemon)
- {
- struct termios tty;
- tcgetattr(0, &tty);
- oldtty = tty;
- atexit(term_exit);
- tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP
- |INLCR|IGNCR|ICRNL|IXON);
- tty.c_oflag |= OPOST;
- tty.c_lflag &= ~(ECHO|ECHONL|ICANON|IEXTEN);
- tty.c_cflag &= ~(CSIZE|PARENB);
- tty.c_cflag |= CS8;
- tty.c_cc[VMIN] = 1;
- tty.c_cc[VTIME] = 0;
- tcsetattr (0, TCSANOW, &tty);
- /* Quit (POSIX). */
- signal(SIGQUIT, sigterm_handler);
- }
- signal(SIGINT , sigterm_handler);
- signal(SIGTERM, sigterm_handler);
- }
- static void term_exit(void)
- {
- printf("%s\n", "TERMINATION");
- if (!run_as_daemon)
- tcsetattr(0, TCSANOW, &oldtty);
- }
- static void sigterm_handler(int sig)
- {
- received_sigterm = sig;
- q_pressed++;
- term_exit();
- }
- /*
- * \Func
- * read_key
- * \Descript
- * read a key without blocking
- */
- static int read_key(void)
- {
- int n = 1;
- unsigned char ch;
- struct timeval tv;
- fd_set rfds;
- if (run_as_daemon)
- return -1;
- FD_ZERO(&rfds);
- FD_SET(0, &rfds);
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- n = select(1, &rfds, NULL, NULL, &tv);
- if (n > 0)
- {
- n = read(0, &ch, 1);
- if (n == 1)
- return ch;
- return n;
- }
- return -1;
- }
- OBJECTS = main.o
- CC = gcc
- CFLAG = -g
- ffmpeg_signal : $(OBJECTS)
- $(CC) $(CFLAG) -o ffmpeg_signal $(OBJECTS)
- main.o:
- .PHONY:clean
- clean:
- rm ffmpeg_signal $(OBJECTS)
转载:http://blog.chinaunix.net/uid-26000296-id-3429028.html
ffmpeg键盘命令响应程序详解的更多相关文章
- telnet 命令使用方法详解,telnet命令怎么用
telnet 命令使用方法详解,telnet命令怎么用? 文章类型:电脑教程 原创:天诺时空 什么是Telnet? 对于Telnet的认识,不同的人持有不同的观点,可以把Telnet当成一种通信协 ...
- Linux开机启动程序详解
Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...
- Linux开机启动程序详解[转]
Linux开机启动程序详解 我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤 ...
- linux系统设置服务开机启动3种方法,Linux开机启动程序详解
linux系统设置服务开机启动 方法1:.利用ntsysv伪图形进行设置,利用root登陆 终端命令下输入ntsysv 回车:如下图 方法2:利用命令行chkconfig命令进行设置 简要说明 ...
- Linux如何实现开机启动程序详解(转)
Linux开机启动程序详解我们假设大家已经熟悉其它操作系统的引导过程,了解硬件的自检引导步骤,就只从Linux操作系统的引导加载程序(对个人电脑而言通常是LILO)开始,介绍Linux开机引导的步骤. ...
- VLC命令行参数详解
VLC命令行参数详解 2012-11-29 14:00 6859人阅读 评论(0) 收藏 举报 Usage: vlc [options] [stream] ...You can specify mul ...
- FFmpeg开发笔记(五):ffmpeg解码的基本流程详解(ffmpeg3新解码api)
若该文为原创文章,未经允许不得转载原博主博客地址:https://blog.csdn.net/qq21497936原博主博客导航:https://blog.csdn.net/qq21497936/ar ...
- ping命令执行过程详解
[TOC] ping命令执行过程详解 机器A ping 机器B 同一网段 ping通知系统建立一个固定格式的ICMP请求数据包 ICMP协议打包这个数据包和机器B的IP地址转交给IP协议层(一组后台运 ...
- Linux命令工具 top详解
Linux命令工具 top详解 top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器.top是一个动态显示过程,即可以通过用户按键来不 ...
随机推荐
- Vue的前端路由
vue-router-- 根据不同的地址找到不同的页面 (单页面应用:无需频繁的从后台刷新页面) 1,安装路由-->导 ...
- spring IOC(DI)和AOP
软件152谭智馗 IOC(Inversion of Control,控制倒转)Ioc意味着将你设计好的对象交给容器控制,而不是传统的在你的对象内部直接控制. DI—Dependency Injecti ...
- switch穿透中语句的执行顺序
Day04_SHJavaTraing_4-6-2017 计算下列switch语句的运行结果 1. int x = 2,y=3; switch(x){ default: y++; case 3: y++ ...
- spring cloud(三) config
spring cloud 配置中心 config 搭建过程 1.搭建config-server 服务端 1.1. 新建boot工程 pom引入依赖 <!-- config配置中心 --> ...
- Zabbix4.0 Web管理界面中文乱码解决方法(转)
Zabbix安装好之后,监控图形页面出现字符集乱码 解决方法:1.复制本地电脑C:\Windows\Fonts\simkai.ttf(楷体)上传到zabbix服务器网站目录的fonts目录下 2.za ...
- MooFest 树状数组 + 前缀和
比较友好的数据结构题 建议读者好好思考思考--. 可以分析出与前缀和的关系, 之后就愉快的套起树状数组辣 #include <cstdio> #include<queue> # ...
- SpringMVC源码阅读
在研究SpringMVC工作流程的同时记录下过程,以便以后浏览. 版本号:5.0.4 前沿:我们在使用SpringMVC的时候会在web.xml中配置以下servlet <!-- 配置sprin ...
- nginx日志按天自动切割
1.编写shell脚本,创建nginx_log.sh文件#!/bin/bashsource /etc/profile#设置Nginx日志文件存放目录log_path="/usr/local/ ...
- C++基础 (3) 第三天 构造函数 构造函数初始化列表 拷贝构造函数 析构函数 静态成员变量
// 同类之间无私处 2构造函数 3析构函数 4构造函数的种类和析构函数的顺序 结论:析构函数的调用顺序,跟对象的构造顺序相反,谁先构造,谁最后一个被析构. 拷贝构造函数: 注意: 等号写在下面和写在 ...
- Project Euler 21 Distinct primes factors( 整数因子和 )
题意: 记d(n)为n的所有真因数(小于n且整除n的正整数)之和. 如果d(a) = b且d(b) = a,且a ≠ b,那么a和b构成一个亲和数对,a和b被称为亲和数. 例如,220的真因数包括1. ...