Commit 43136abb authored by michael's avatar michael

tcp select() check and enables pressing 'q' when reading/(writing) from

tcp/http in ffmpeg.c patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@2891 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 6e9c0ade
...@@ -193,6 +193,7 @@ static int using_stdin = 0; ...@@ -193,6 +193,7 @@ static int using_stdin = 0;
static int using_vhook = 0; static int using_vhook = 0;
static int verbose = 1; static int verbose = 1;
static int thread_count= 1; static int thread_count= 1;
static int q_pressed = 0;
#define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass" #define DEFAULT_PASS_LOGFILENAME "ffmpeg2pass"
...@@ -322,6 +323,11 @@ static int read_key(void) ...@@ -322,6 +323,11 @@ static int read_key(void)
return -1; return -1;
} }
static int decode_interrupt_cb(void)
{
return q_pressed || (q_pressed = read_key() == 'q');
}
#else #else
static volatile int received_sigterm = 0; static volatile int received_sigterm = 0;
...@@ -1411,8 +1417,10 @@ static int av_encode(AVFormatContext **output_files, ...@@ -1411,8 +1417,10 @@ static int av_encode(AVFormatContext **output_files,
} }
#ifndef CONFIG_WIN32 #ifndef CONFIG_WIN32
if ( !using_stdin ) if ( !using_stdin ) {
fprintf(stderr, "Press [q] to stop encoding\n"); fprintf(stderr, "Press [q] to stop encoding\n");
url_set_interrupt_cb(decode_interrupt_cb);
}
#endif #endif
term_init(); term_init();
...@@ -1427,6 +1435,8 @@ static int av_encode(AVFormatContext **output_files, ...@@ -1427,6 +1435,8 @@ static int av_encode(AVFormatContext **output_files,
redo: redo:
/* if 'q' pressed, exits */ /* if 'q' pressed, exits */
if (!using_stdin) { if (!using_stdin) {
if (q_pressed)
break;
/* read_key() returns 0 on EOF */ /* read_key() returns 0 on EOF */
key = read_key(); key = read_key();
if (key == 'q') if (key == 'q')
......
...@@ -141,7 +141,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) ...@@ -141,7 +141,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
static int tcp_read(URLContext *h, uint8_t *buf, int size) static int tcp_read(URLContext *h, uint8_t *buf, int size)
{ {
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
int len, fd_max; int len, fd_max, ret;
fd_set rfds; fd_set rfds;
struct timeval tv; struct timeval tv;
...@@ -153,28 +153,31 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size) ...@@ -153,28 +153,31 @@ static int tcp_read(URLContext *h, uint8_t *buf, int size)
FD_SET(s->fd, &rfds); FD_SET(s->fd, &rfds);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 100 * 1000; tv.tv_usec = 100 * 1000;
select(fd_max + 1, &rfds, NULL, NULL, &tv); ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
#ifdef __BEOS__ #ifdef __BEOS__
len = recv(s->fd, buf, size, 0); len = recv(s->fd, buf, size, 0);
#else #else
len = read(s->fd, buf, size); len = read(s->fd, buf, size);
#endif #endif
if (len < 0) { if (len < 0) {
if (errno != EINTR && errno != EAGAIN) if (errno != EINTR && errno != EAGAIN)
#ifdef __BEOS__ #ifdef __BEOS__
return errno; return errno;
#else #else
return -errno; return -errno;
#endif #endif
} else break; } else return len;
} else if (ret < 0) {
return -1;
}
} }
return len;
} }
static int tcp_write(URLContext *h, uint8_t *buf, int size) static int tcp_write(URLContext *h, uint8_t *buf, int size)
{ {
TCPContext *s = h->priv_data; TCPContext *s = h->priv_data;
int ret, size1, fd_max; int ret, size1, fd_max, len;
fd_set wfds; fd_set wfds;
struct timeval tv; struct timeval tv;
...@@ -187,24 +190,28 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size) ...@@ -187,24 +190,28 @@ static int tcp_write(URLContext *h, uint8_t *buf, int size)
FD_SET(s->fd, &wfds); FD_SET(s->fd, &wfds);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 100 * 1000; tv.tv_usec = 100 * 1000;
select(fd_max + 1, NULL, &wfds, NULL, &tv); ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
#ifdef __BEOS__ #ifdef __BEOS__
ret = send(s->fd, buf, size, 0); len = send(s->fd, buf, size, 0);
#else #else
ret = write(s->fd, buf, size); len = write(s->fd, buf, size);
#endif #endif
if (ret < 0) { if (len < 0) {
if (errno != EINTR && errno != EAGAIN) { if (errno != EINTR && errno != EAGAIN) {
#ifdef __BEOS__ #ifdef __BEOS__
return errno; return errno;
#else #else
return -errno; return -errno;
#endif #endif
}
continue;
} }
continue; size -= len;
buf += len;
} else if (ret < 0) {
return -1;
} }
size -= ret;
buf += ret;
} }
return size1 - size; return size1 - size;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment