| common.h - blind - suckless command-line video editing utility | |
| git clone git://git.suckless.org/blind | |
| Log | |
| Files | |
| Refs | |
| README | |
| LICENSE | |
| --- | |
| common.h (4899B) | |
| --- | |
| 1 /* See LICENSE file for copyright and license details. */ | |
| 2 #if defined(__clang__) | |
| 3 # pragma clang diagnostic ignored "-Wdisabled-macro-expansion" | |
| 4 # pragma clang diagnostic ignored "-Wcomma" | |
| 5 # pragma clang diagnostic ignored "-Wcast-align" | |
| 6 # pragma clang diagnostic ignored "-Wassign-enum" | |
| 7 # pragma clang diagnostic ignored "-Wfloat-equal" | |
| 8 # pragma clang diagnostic ignored "-Wformat-nonliteral" | |
| 9 # pragma clang diagnostic ignored "-Wcovered-switch-default" | |
| 10 # pragma clang diagnostic ignored "-Wfloat-conversion" | |
| 11 # pragma clang diagnostic ignored "-Wabsolute-value" | |
| 12 # pragma clang diagnostic ignored "-Wconditional-uninitialized" | |
| 13 # pragma clang diagnostic ignored "-Wunreachable-code-return" | |
| 14 #elif defined(__GNUC__) | |
| 15 # pragma GCC diagnostic ignored "-Wfloat-equal" | |
| 16 # pragma GCC diagnostic ignored "-Wunsafe-loop-optimizations" | |
| 17 # pragma GCC diagnostic ignored "-Wfloat-conversion" | |
| 18 #endif | |
| 19 | |
| 20 #include "../build/platform.h" | |
| 21 #include "stream.h" | |
| 22 #include "util.h" | |
| 23 #include "video-math.h" | |
| 24 | |
| 25 #include <arpa/inet.h> | |
| 26 #if defined(HAVE_EPOLL) | |
| 27 # include <sys/epoll.h> | |
| 28 #endif | |
| 29 #include <sys/mman.h> | |
| 30 #if defined(HAVE_SENDFILE) | |
| 31 # include <sys/sendfile.h> | |
| 32 #endif | |
| 33 #include <sys/stat.h> | |
| 34 #include <sys/socket.h> | |
| 35 #include <sys/uio.h> | |
| 36 #include <sys/un.h> | |
| 37 #include <sys/wait.h> | |
| 38 #include <alloca.h> | |
| 39 #include <ctype.h> | |
| 40 #include <errno.h> | |
| 41 #include <fcntl.h> | |
| 42 #include <inttypes.h> | |
| 43 #include <limits.h> | |
| 44 #include <signal.h> | |
| 45 #include <stdarg.h> | |
| 46 #include <stdio.h> | |
| 47 #include <stdlib.h> | |
| 48 #include <string.h> | |
| 49 #include <strings.h> | |
| 50 #include <unistd.h> | |
| 51 | |
| 52 #ifndef CMSG_ALIGN | |
| 53 # ifdef __sun__ | |
| 54 # define CMSG_ALIGN _CMSG_DATA_ALIGN | |
| 55 # else | |
| 56 # define CMSG_ALIGN(len) (((len) + sizeof(long) - 1) & ~(sizeof(long) -… | |
| 57 # endif | |
| 58 #endif | |
| 59 | |
| 60 #ifndef CMSG_SPACE | |
| 61 # define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIG… | |
| 62 #endif | |
| 63 | |
| 64 #ifndef CMSG_LEN | |
| 65 # define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) | |
| 66 #endif | |
| 67 | |
| 68 #if !defined(PIPE_BUF) | |
| 69 # define PIPE_BUF 512 | |
| 70 #endif | |
| 71 | |
| 72 #ifndef DONT_INCLUDE_FLOAT | |
| 73 # define SELECT_PROCESS_FUNCTION_FLOAT(stream) else if ((stream)->encodi… | |
| 74 #else | |
| 75 # define SELECT_PROCESS_FUNCTION_FLOAT(stream) else if (0) | |
| 76 #endif | |
| 77 | |
| 78 #ifndef DONT_INCLUDE_DOUBLE | |
| 79 # define SELECT_PROCESS_FUNCTION_DOUBLE(stream) else if ((stream)->encod… | |
| 80 #else | |
| 81 # define SELECT_PROCESS_FUNCTION_DOUBLE(stream) else if (0) | |
| 82 #endif | |
| 83 | |
| 84 #ifdef INCLUDE_LONG_DOUBLE | |
| 85 # define SELECT_PROCESS_FUNCTION_LONG_DOUBLE(stream) else if ((stream)->… | |
| 86 #else | |
| 87 # define SELECT_PROCESS_FUNCTION_LONG_DOUBLE(stream) else if (0) | |
| 88 #endif | |
| 89 | |
| 90 #ifdef INCLUDE_UINT8 | |
| 91 # define SELECT_PROCESS_FUNCTION_UINT8(stream) else if ((stream)->encodi… | |
| 92 #else | |
| 93 # define SELECT_PROCESS_FUNCTION_UINT8(stream) else if (0) | |
| 94 #endif | |
| 95 | |
| 96 #ifdef INCLUDE_UINT16 | |
| 97 # define SELECT_PROCESS_FUNCTION_UINT16(stream) else if ((stream)->encod… | |
| 98 #else | |
| 99 # define SELECT_PROCESS_FUNCTION_UINT16(stream) else if (0) | |
| 100 #endif | |
| 101 | |
| 102 #ifdef INCLUDE_UINT32 | |
| 103 # define SELECT_PROCESS_FUNCTION_UINT32(stream) else if ((stream)->encod… | |
| 104 #else | |
| 105 # define SELECT_PROCESS_FUNCTION_UINT32(stream) else if (0) | |
| 106 #endif | |
| 107 | |
| 108 #ifdef INCLUDE_UINT64 | |
| 109 # define SELECT_PROCESS_FUNCTION_UINT64(stream) else if ((stream)->encod… | |
| 110 #else | |
| 111 # define SELECT_PROCESS_FUNCTION_UINT64(stream) else if (0) | |
| 112 #endif | |
| 113 | |
| 114 #define SELECT_PROCESS_FUNCTION(stream)\ | |
| 115 do {\ | |
| 116 if ((stream)->endian != HOST)\ | |
| 117 eprintf("pixel format %s is not supported, try x… | |
| 118 SELECT_PROCESS_FUNCTION_FLOAT(stream);\ | |
| 119 SELECT_PROCESS_FUNCTION_DOUBLE(stream);\ | |
| 120 SELECT_PROCESS_FUNCTION_LONG_DOUBLE(stream);\ | |
| 121 SELECT_PROCESS_FUNCTION_UINT8(stream);\ | |
| 122 SELECT_PROCESS_FUNCTION_UINT16(stream);\ | |
| 123 SELECT_PROCESS_FUNCTION_UINT32(stream);\ | |
| 124 SELECT_PROCESS_FUNCTION_UINT64(stream);\ | |
| 125 else\ | |
| 126 eprintf("pixel format %s is not supported, try x… | |
| 127 } while (0) | |
| 128 | |
| 129 #define CHECK_ALPHA_CHAN(stream)\ | |
| 130 do {\ | |
| 131 if ((stream)->alpha_chan != 3)\ | |
| 132 eprintf("pixel format %s is not supported, try x… | |
| 133 } while (0) | |
| 134 | |
| 135 #define CHECK_CHANS(stream, ALPHA, LUMA)\ | |
| 136 do {\ | |
| 137 if (!(((stream)->alpha_chan ALPHA) && ((stream)->luma_ch… | |
| 138 eprintf("pixel format %s is not supported, try x… | |
| 139 } while (0) | |
| 140 | |
| 141 #define CHECK_ALPHA(stream)\ | |
| 142 do {\ | |
| 143 if ((stream)->alpha != UNPREMULTIPLIED)\ | |
| 144 eprintf("pixel format %s is not supported, try x… | |
| 145 } while (0) | |
| 146 | |
| 147 #define CHECK_COLOUR_SPACE(stream, colour_space)\ | |
| 148 do {\ | |
| 149 if ((stream)->space != (colour_space))\ | |
| 150 eprintf("pixel format %s is not supported, try x… | |
| 151 } while (0) | |
| 152 | |
| 153 #define CHECK_N_CHAN(stream, low, high)\ | |
| 154 do {\ | |
| 155 if ((stream)->n_chan < (low) || (stream)->n_chan > (high… | |
| 156 eprintf("pixel format %s is not supported, try x… | |
| 157 } while (0) |