add interactive support for MinGW
patch by Ramiro Polla % ramiro A lisha P ufsc P br % Orignial thread: date: Nov 5, 2006 1:55 AM subject: [Ffmpeg-devel] [PATCH] MinGW interactive support Originally committed as revision 7155 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:

committed by
Guillaume Poirier

parent
8cff89be43
commit
d86b83f8ab
43
ffmpeg.c
43
ffmpeg.c
@@ -19,6 +19,7 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
#define HAVE_AV_CONFIG_H
|
#define HAVE_AV_CONFIG_H
|
||||||
|
#include <signal.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "avformat.h"
|
#include "avformat.h"
|
||||||
#include "swscale.h"
|
#include "swscale.h"
|
||||||
@@ -27,14 +28,15 @@
|
|||||||
#include "opt.h"
|
#include "opt.h"
|
||||||
#include "fifo.h"
|
#include "fifo.h"
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
#ifdef __MINGW32__
|
||||||
|
#include <conio.h>
|
||||||
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <signal.h>
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_OS2
|
#ifdef CONFIG_OS2
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -292,10 +294,13 @@ typedef struct AVInputFile {
|
|||||||
|
|
||||||
/* init terminal so that we can grab keys */
|
/* init terminal so that we can grab keys */
|
||||||
static struct termios oldtty;
|
static struct termios oldtty;
|
||||||
|
#endif
|
||||||
|
|
||||||
static void term_exit(void)
|
static void term_exit(void)
|
||||||
{
|
{
|
||||||
|
#ifndef __MINGW32__
|
||||||
tcsetattr (0, TCSANOW, &oldtty);
|
tcsetattr (0, TCSANOW, &oldtty);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile sig_atomic_t received_sigterm = 0;
|
static volatile sig_atomic_t received_sigterm = 0;
|
||||||
@@ -309,6 +314,7 @@ sigterm_handler(int sig)
|
|||||||
|
|
||||||
static void term_init(void)
|
static void term_init(void)
|
||||||
{
|
{
|
||||||
|
#ifndef __MINGW32__
|
||||||
struct termios tty;
|
struct termios tty;
|
||||||
|
|
||||||
tcgetattr (0, &tty);
|
tcgetattr (0, &tty);
|
||||||
@@ -324,9 +330,10 @@ static void term_init(void)
|
|||||||
tty.c_cc[VTIME] = 0;
|
tty.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
tcsetattr (0, TCSANOW, &tty);
|
tcsetattr (0, TCSANOW, &tty);
|
||||||
|
signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
|
||||||
|
#endif
|
||||||
|
|
||||||
signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
|
signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */
|
||||||
signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */
|
|
||||||
signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
|
signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */
|
||||||
/*
|
/*
|
||||||
register a function to be called at normal program termination
|
register a function to be called at normal program termination
|
||||||
@@ -340,6 +347,10 @@ static void term_init(void)
|
|||||||
/* read a key without blocking */
|
/* read a key without blocking */
|
||||||
static int read_key(void)
|
static int read_key(void)
|
||||||
{
|
{
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
if(kbhit())
|
||||||
|
return(getch());
|
||||||
|
#else
|
||||||
int n = 1;
|
int n = 1;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
#ifndef CONFIG_BEOS_NETSERVER
|
#ifndef CONFIG_BEOS_NETSERVER
|
||||||
@@ -359,6 +370,7 @@ static int read_key(void)
|
|||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -367,26 +379,6 @@ static int decode_interrupt_cb(void)
|
|||||||
return q_pressed || (q_pressed = read_key() == 'q');
|
return q_pressed || (q_pressed = read_key() == 'q');
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static volatile int received_sigterm = 0;
|
|
||||||
|
|
||||||
/* no interactive support */
|
|
||||||
static void term_exit(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static void term_init(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static int read_key(void)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int read_ffserver_streams(AVFormatContext *s, const char *filename)
|
static int read_ffserver_streams(AVFormatContext *s, const char *filename)
|
||||||
{
|
{
|
||||||
int i, err;
|
int i, err;
|
||||||
@@ -1832,12 +1824,10 @@ static int av_encode(AVFormatContext **output_files,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
|
||||||
if ( !using_stdin && verbose >= 0) {
|
if ( !using_stdin && verbose >= 0) {
|
||||||
fprintf(stderr, "Press [q] to stop encoding\n");
|
fprintf(stderr, "Press [q] to stop encoding\n");
|
||||||
url_set_interrupt_cb(decode_interrupt_cb);
|
url_set_interrupt_cb(decode_interrupt_cb);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
term_init();
|
term_init();
|
||||||
|
|
||||||
stream_no_data = 0;
|
stream_no_data = 0;
|
||||||
@@ -3971,14 +3961,13 @@ int main(int argc, char **argv)
|
|||||||
powerpc_display_perf_report();
|
powerpc_display_perf_report();
|
||||||
#endif /* POWERPC_PERFORMANCE_REPORT */
|
#endif /* POWERPC_PERFORMANCE_REPORT */
|
||||||
|
|
||||||
#ifndef __MINGW32__
|
|
||||||
if (received_sigterm) {
|
if (received_sigterm) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Received signal %d: terminating.\n",
|
"Received signal %d: terminating.\n",
|
||||||
(int) received_sigterm);
|
(int) received_sigterm);
|
||||||
exit (255);
|
exit (255);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
exit(0); /* not all OS-es handle main() return value */
|
exit(0); /* not all OS-es handle main() return value */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user