diff --git a/src/device.c b/src/device.c index a262728..fca871d 100644 --- a/src/device.c +++ b/src/device.c @@ -27,12 +27,12 @@ #include #include -#include #include #include #include "tools.h" #include "logging.h" +#include "xioctl.h" #include "device.h" diff --git a/src/encoder.c b/src/encoder.c index ae49e5b..f90f0bd 100644 --- a/src/encoder.c +++ b/src/encoder.c @@ -23,6 +23,7 @@ #include #include "tools.h" +#include "logging.h" #include "device.h" #include "encoder.h" diff --git a/src/main.c b/src/main.c index 6e6fdcb..251acbb 100644 --- a/src/main.c +++ b/src/main.c @@ -26,7 +26,6 @@ #include #include -#include #include #include diff --git a/src/omx/component.c b/src/omx/component.c index ea7db98..9317d7c 100644 --- a/src/omx/component.c +++ b/src/omx/component.c @@ -19,8 +19,6 @@ *****************************************************************************/ -#include - #include #include diff --git a/src/omx/formatters.h b/src/omx/formatters.h index 66313a4..e015103 100644 --- a/src/omx/formatters.h +++ b/src/omx/formatters.h @@ -22,9 +22,7 @@ #pragma once #include -#include -#include #include #include diff --git a/src/stream.c b/src/stream.c index f4a11a7..f127633 100644 --- a/src/stream.c +++ b/src/stream.c @@ -19,7 +19,6 @@ *****************************************************************************/ -#include #include #include #include @@ -31,6 +30,7 @@ #include "tools.h" #include "logging.h" +#include "xioctl.h" #include "device.h" #include "encoder.h" #include "stream.h" diff --git a/src/tools.h b/src/tools.h index 62eef8d..ed2107c 100644 --- a/src/tools.h +++ b/src/tools.h @@ -23,7 +23,6 @@ #include #include -#include #include #include #include @@ -31,11 +30,8 @@ #include #include -#include #include -#include "logging.h" - #define A_PTHREAD_CREATE(_tid, _func, _arg) assert(!pthread_create(_tid, NULL, _func, _arg)) #define A_PTHREAD_JOIN(_tid) assert(!pthread_join(_tid, NULL)) @@ -61,9 +57,6 @@ #define UNUSED __attribute__((unused)) -#define XIOCTL_RETRIES 4 - - INLINE unsigned max_u(unsigned a, unsigned b) { return (a > b ? a : b); } @@ -88,25 +81,3 @@ INLINE long double now_ms_ld(void) { now_ms(&sec, &msec); return (long double)sec + ((long double)msec) / 1000; } - -INLINE int xioctl(const int fd, const int request, void *arg) { - int retries = XIOCTL_RETRIES; - int retval = -1; - - do { - retval = ioctl(fd, request, arg); - } while ( - retval - && retries-- - && ( - errno == EINTR - || errno == EAGAIN - || errno == ETIMEDOUT - ) - ); - - if (retval && retries <= 0) { - LOG_PERROR("ioctl(%d) retried %d times; giving up", request, XIOCTL_RETRIES); - } - return retval; -} diff --git a/src/xioctl.h b/src/xioctl.h new file mode 100644 index 0000000..6a978d6 --- /dev/null +++ b/src/xioctl.h @@ -0,0 +1,55 @@ +/***************************************************************************** +# uStreamer - Lightweight and fast MJPG-HTTP streamer. # +# # +# Copyright (C) 2018 Maxim Devaev # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +*****************************************************************************/ + + +#pragma once + +#include + +#include + +#include "tools.h" +#include "logging.h" + + +#define XIOCTL_RETRIES 4 + + +INLINE int xioctl(const int fd, const int request, void *arg) { + int retries = XIOCTL_RETRIES; + int retval = -1; + + do { + retval = ioctl(fd, request, arg); + } while ( + retval + && retries-- + && ( + errno == EINTR + || errno == EAGAIN + || errno == ETIMEDOUT + ) + ); + + if (retval && retries <= 0) { + LOG_PERROR("ioctl(%d) retried %d times; giving up", request, XIOCTL_RETRIES); + } + return retval; +}