|
|
|
@ -48,6 +48,39 @@ static void convert_for_ffmpeg(const uint8_t *in, uint8_t *out,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int wait_fd_event(int fd, int events)
|
|
|
|
|
{
|
|
|
|
|
struct pollfd pfd;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
pfd.fd = fd;
|
|
|
|
|
pfd.events = events;
|
|
|
|
|
pfd.revents = 0;
|
|
|
|
|
|
|
|
|
|
ret = poll(&pfd, 1, -1);
|
|
|
|
|
|
|
|
|
|
if (ret > 0) {
|
|
|
|
|
if (pfd.revents & events)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (pfd.revents & (POLLERR | POLLHUP)) {
|
|
|
|
|
fputs("poll reported error\n", stderr);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
perror("poll");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int write_retry(int fd, const void *buffer, size_t size)
|
|
|
|
|
{
|
|
|
|
|
while (size > 0) {
|
|
|
|
@ -56,6 +89,13 @@ static int write_retry(int fd, const void *buffer, size_t size)
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (errno == EAGAIN) {
|
|
|
|
|
if (wait_fd_event(fd, POLLOUT))
|
|
|
|
|
return -1;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
perror("write");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|