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是一个动态显示过程,即可以通过用户按键来不 ...
随机推荐
- Android ToolBar自定义图标,关联DrawerLayout
Android5.0出现了一个可以代替ActionBar的控件ToolBar,使用更加灵活,一般我们使用ToolBar来和DrawerLayout配合使用,官方提供了一个开关类ActionBarDra ...
- MacType 缺字问题【转】
- smarty 3 + codeigniter 2 + hmvc
参考资料 https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/src/fecd39ccdf56?at=defau ...
- js预览上传图片
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Java中数组遍历
就是将数组中的每个元素分别获取出来,就是遍历.遍历也是数组操作中的基石. 数组的索引是 0 到 lenght-1 ,可以作为循环的条件出现 public class ArrayDemo4 { publ ...
- Mybatis批量插入的代码实现
简单的学习总结一下,希望能帮到需要的同学! 1.mapper.xml文件sql语句如下: <insert id="insertBatch" parameterType=&qu ...
- element合并单元格方法及遇到问题的解决办法
效果如图: 代码如下 <!-- 查看选课 --> <template> <div> <el-table :data="listData" ...
- django-6-数据库配置及模型创建,激活(django模型系统1)
<<<数据库的连接配置>>> django配置mysql的流程: 1.创建数据库用户 (1)进入MySQL数据库 (2)创建有数据库权限的用户 (3)退出My ...
- 利用Tensorflow实现手写字符识别
模式识别领域应用机器学习的场景非常多,手写识别就是其中一种,最简单的数字识别是一个多类分类问题,我们借这个多类分类问题来介绍一下google最新开源的tensorflow框架,后面深度学习的内容都会基 ...
- PHP学习总结(2)——PHP入门篇之PHP代码标识
认识PHP代码标识 想在页面中编写PHP代码非常容易,如下面代码: <?php echo "想学习php吗?来慕课网吧";?> 就像你可以编写JavaScript脚本 ...