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是一个动态显示过程,即可以通过用户按键来不 ...
随机推荐
- es6学习 http://es6.ruanyifeng.com/
基础学习 http://es6.ruanyifeng.com/ 够了 1字符串 字符串的遍历器接口 for (let codePoint of 'foo') { console.log(code ...
- vue-cli 安装
1 node 下载 http://nodejs.cn/download/ 安装 2 npm install vue-cli -g 3 vue init <template-n ...
- Spring 获取propertise文件中的值
Spring 获取propertise文件中的值 Spring 获取propertise的方式,除了之前的博文提到的使用@value的注解注入之外,还可以通过编码的方式获取,这里主要说的是要使用Emb ...
- adb使用实践
目录 1. adb 端口占用 2. 查看包名和MainAcitivity =============================================================== ...
- ZBrush细说3D海盗角色的创建艺术
一提到海盗,就不由自主想到了<加勒比海盗>,那个帅得一塌糊涂的杰克船长更是让人夜不能寐寝难安,但在艺术的世界里,角色无美丑,今天我们要讲的这位海盗,就与“帅气”八竿子打不着了,它甚至有点古 ...
- Python基础:条件判断 &&循环
1:条件判断 2:循环 2.1:for 2.2 while 小结: continue :跳出本次循环 进行下次循环, break :结束循环体.
- 【转】Oracle基础结构认知—进程及逻辑结构 礼记八目 2017-12-17 19:33:21
原文地址:https://www.toutiao.com/i6500477672349499917/ 一. Process Structure进程结构 Oracle有两种类型的进程: 服务器进程和后台 ...
- 【数据分析学习】Pandas思维导图
点我查看原版
- 打包c++项目
InstallShield Limited Edition for Visual Studio 2013 图文教程(教你如何打包.NET程序) InstallShield 2015 Limited E ...
- 沃通SSL证书、代码签名证书应用于机器人安全防护
近两年,扫地机器人.智能音箱等消费级机器人产品逐渐走入大众生活的中.随着人工智能技术的迅猛发展,预计2023年全球消费级机器人市场规模将达到150亿美元.然而,产业的迅猛发展却伴随着安全防护的缺失,安 ...