Optimise usage of videodev2.h
header
This commit is contained in:
21
opts/fourcc.c
Normal file
21
opts/fourcc.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include "fourcc.h"
|
||||
|
||||
fourcc_string fourcc_to_string(unsigned format)
|
||||
{
|
||||
fourcc_string fourcc;
|
||||
char *ptr = fourcc.buf;
|
||||
*ptr++ = format & 0x7F;
|
||||
*ptr++ = (format >> 8) & 0x7F;
|
||||
*ptr++ = (format >> 16) & 0x7F;
|
||||
*ptr++ = (format >> 24) & 0x7F;
|
||||
if (format & ((unsigned)1 << 31)) {
|
||||
*ptr++ = '-';
|
||||
*ptr++ = 'B';
|
||||
*ptr++ = 'E';
|
||||
*ptr++ = '\0';
|
||||
} else {
|
||||
*ptr++ = '\0';
|
||||
}
|
||||
*ptr++ = 0;
|
||||
return fourcc;
|
||||
}
|
9
opts/fourcc.h
Normal file
9
opts/fourcc.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
typedef struct {
|
||||
char buf[10];
|
||||
} fourcc_string;
|
||||
|
||||
fourcc_string fourcc_to_string(unsigned format);
|
24
opts/log.c
24
opts/log.c
@ -82,3 +82,27 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv)
|
||||
{
|
||||
return get_time_us(CLOCK_MONOTONIC, ts, tv, 0);
|
||||
}
|
||||
|
||||
int xioctl(const char *name, int fd, 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
|
||||
)
|
||||
);
|
||||
|
||||
// cppcheck-suppress knownConditionTrueFalse
|
||||
if (retval && retries <= 0) {
|
||||
E_LOG_PERROR(NULL, "%s: ioctl(%08x) retried %u times; giving up", name, request, XIOCTL_RETRIES);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
28
opts/log.h
28
opts/log.h
@ -1,11 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define __FILENAME__ __FILE__
|
||||
|
||||
@ -35,3 +49,17 @@ bool filter_log(const char *filename);
|
||||
uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv);
|
||||
uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, int64_t delays_us);
|
||||
int shrink_to_block(int size, int block);
|
||||
|
||||
#ifndef CFG_XIOCTL_RETRIES
|
||||
# define CFG_XIOCTL_RETRIES 4
|
||||
#endif
|
||||
#define XIOCTL_RETRIES ((unsigned)(CFG_XIOCTL_RETRIES))
|
||||
|
||||
int xioctl(const char *name, int fd, int request, void *arg);
|
||||
|
||||
#define E_XIOCTL(dev, _fd, _request, _value, _msg, ...) do { \
|
||||
int ret; \
|
||||
if ((ret = xioctl(dev_name(dev), _fd, _request, _value)) < 0) { \
|
||||
E_LOG_ERROR(dev, "xioctl(ret=%d): " _msg, ret, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while(0)
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "opts.h"
|
||||
#include "device/hw/v4l2.h"
|
||||
#include "opts/log.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
Reference in New Issue
Block a user