minor refactoring

This commit is contained in:
Devaev Maxim 2018-09-25 00:25:57 +03:00
parent 8152d35bb3
commit 1d0591caa0
8 changed files with 58 additions and 36 deletions

View File

@ -27,12 +27,12 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <linux/videodev2.h>
#include "tools.h"
#include "logging.h"
#include "xioctl.h"
#include "device.h"

View File

@ -23,6 +23,7 @@
#include <assert.h>
#include "tools.h"
#include "logging.h"
#include "device.h"
#include "encoder.h"

View File

@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <getopt.h>

View File

@ -19,8 +19,6 @@
*****************************************************************************/
#include <unistd.h>
#include <IL/OMX_Core.h>
#include <IL/OMX_Component.h>

View File

@ -22,9 +22,7 @@
#pragma once
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <IL/OMX_IVCommon.h>

View File

@ -19,7 +19,6 @@
*****************************************************************************/
#include <unistd.h>
#include <errno.h>
#include <time.h>
#include <assert.h>
@ -31,6 +30,7 @@
#include "tools.h"
#include "logging.h"
#include "xioctl.h"
#include "device.h"
#include "encoder.h"
#include "stream.h"

View File

@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <math.h>
#include <pthread.h>
@ -31,11 +30,8 @@
#include <assert.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/syscall.h>
#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;
}

55
src/xioctl.h Normal file
View File

@ -0,0 +1,55 @@
/*****************************************************************************
# uStreamer - Lightweight and fast MJPG-HTTP streamer. #
# #
# Copyright (C) 2018 Maxim Devaev <mdevaev@gmail.com> #
# #
# 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 <https://www.gnu.org/licenses/>. #
# #
*****************************************************************************/
#pragma once
#include <errno.h>
#include <sys/ioctl.h>
#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;
}