|
| 1 | +#pragma once |
| 2 | + |
| 3 | +/** @file common.h |
| 4 | + * @brief Global constants for liblsl */ |
| 5 | + |
| 6 | +#if defined(LIBLSL_FFI) |
| 7 | +// Skip any typedefs that might confuse a FFI header parser, e.g. cffi |
| 8 | +#elif defined(_MSC_VER) && _MSC_VER < 1600 |
| 9 | +typedef signed char int8_t; |
| 10 | +typedef signed short int16_t; |
| 11 | +typedef signed int int32_t; |
| 12 | +typedef signed long long int64_t; |
| 13 | +typedef unsigned int uint32_t; |
| 14 | +#else |
| 15 | +#include <stdint.h> |
| 16 | +#endif |
| 17 | + |
| 18 | +#if defined(_MSC_VER) && _MSC_VER < 1900 |
| 19 | +#define __func__ __FUNCTION__ |
| 20 | +#endif |
| 21 | + |
| 22 | +/// LIBLSL_C_API expands function attributes needed for the linker |
| 23 | +#if defined(LIBLSL_STATIC) || defined(LIBLSL_FFI) |
| 24 | +#define LIBLSL_C_API |
| 25 | +#elif defined _WIN32 || defined __CYGWIN__ |
| 26 | +#if defined LIBLSL_EXPORTS |
| 27 | +#define LIBLSL_C_API __declspec(dllexport) |
| 28 | +#else |
| 29 | +#define LIBLSL_C_API __declspec(dllimport) |
| 30 | +#ifdef _WIN64 |
| 31 | +#define LSLBITS "64" |
| 32 | +#else |
| 33 | +#define LSLBITS "32" |
| 34 | +#endif |
| 35 | +#if defined _DEBUG && defined LSL_DEBUG_BINDINGS |
| 36 | +#define LSLLIBPOSTFIX "-debug" |
| 37 | +#else |
| 38 | +#define LSLLIBPOSTFIX "" |
| 39 | +#endif |
| 40 | +#ifndef LSLNOAUTOLINK |
| 41 | +#pragma comment(lib, "liblsl" LSLBITS LSLLIBPOSTFIX ".lib") |
| 42 | +#endif |
| 43 | +#endif |
| 44 | +#pragma warning(disable : 4275) |
| 45 | +#else // Linux / OS X |
| 46 | +#define LIBLSL_C_API __attribute__((visibility("default"))) |
| 47 | +#endif |
| 48 | + |
| 49 | +//! Constant to indicate that a stream has variable sampling rate. |
| 50 | +#define LSL_IRREGULAR_RATE 0.0 |
| 51 | + |
| 52 | +/** Constant to indicate that a sample has the next successive time stamp. |
| 53 | + * |
| 54 | + * This is an optional optimization to transmit less data per sample. |
| 55 | + * The stamp is then deduced from the preceding one according to the stream's |
| 56 | + * sampling rate (in the case of an irregular rate, the same time stamp as |
| 57 | + * before will is assumed). */ |
| 58 | +#define LSL_DEDUCED_TIMESTAMP -1.0 |
| 59 | + |
| 60 | +//! A very large time value (ca. 1 year); can be used in timeouts. |
| 61 | +#define LSL_FOREVER 32000000.0 |
| 62 | + |
| 63 | +/** |
| 64 | + * Constant to indicate that there is no preference about how a data stream |
| 65 | + * shall be chunked for transmission. |
| 66 | + * (can be used for the chunking parameters in the inlet or the outlet). |
| 67 | + */ |
| 68 | +#define LSL_NO_PREFERENCE 0 |
| 69 | + |
| 70 | +//! Data format of a channel (each transmitted sample holds an array of channels). |
| 71 | +typedef enum { |
| 72 | + /*! For up to 24-bit precision measurements in the appropriate physical unit (e.g., microvolts). |
| 73 | + * Integers from -16777216 to 16777216 are represented accurately. */ |
| 74 | + cft_float32 = 1, |
| 75 | + |
| 76 | + /*! For universal numeric data as long as permitted by network & disk budget. |
| 77 | + * The largest representable integer is 53-bit. */ |
| 78 | + cft_double64 = 2, |
| 79 | + |
| 80 | + /*! For variable-length ASCII strings or data blobs, such as video frames, complex event |
| 81 | + descriptions, etc. */ |
| 82 | + cft_string = 3, |
| 83 | + |
| 84 | + /*! For high-rate digitized formats that require 32-bit precision. |
| 85 | + * Depends critically on meta-data to represent meaningful units. |
| 86 | + * Useful for application event codes or other coded data. */ |
| 87 | + cft_int32 = 4, |
| 88 | + |
| 89 | + /*! For very high rate signals (40Khz+) or consumer-grade audio. |
| 90 | + * For professional audio float is recommended. */ |
| 91 | + cft_int16 = 5, |
| 92 | + |
| 93 | + /*! For binary signals or other coded data. Not recommended for encoding string data. */ |
| 94 | + cft_int8 = 6, |
| 95 | + |
| 96 | + /*! For now only for future compatibility. Support for this type is not yet |
| 97 | + exposed in all languages. Also, some builds of liblsl will not be able |
| 98 | + to send or receive data of this type.*/ |
| 99 | + cft_int64 = 7, |
| 100 | + |
| 101 | + //! Can not be transmitted. |
| 102 | + cft_undefined = 0 |
| 103 | +} lsl_channel_format_t; |
| 104 | + |
| 105 | +//! Post-processing options for stream inlets. |
| 106 | +typedef enum { |
| 107 | + /*! No automatic post-processing; return the ground-truth time stamps for manual |
| 108 | + * post-processing. This is the default behavior of the inlet. */ |
| 109 | + proc_none = 0, |
| 110 | + |
| 111 | + /*! Perform automatic clock synchronization; |
| 112 | + * equivalent to manually adding the time_correction() value to the received time stamps. */ |
| 113 | + proc_clocksync = 1, |
| 114 | + |
| 115 | + /*! Remove jitter from time stamps.<br> |
| 116 | + * This will apply a smoothing algorithm to the received time stamps; |
| 117 | + * the smoothing needs to see a minimum number of samples (30-120 seconds worst-case) |
| 118 | + * until the remaining jitter is consistently below 1ms. */ |
| 119 | + proc_dejitter = 2, |
| 120 | + |
| 121 | + /*! Force the time-stamps to be monotonically ascending.<br> |
| 122 | + * Only makes sense if timestamps are dejittered. */ |
| 123 | + proc_monotonize = 4, |
| 124 | + |
| 125 | + /*! Post-processing is thread-safe (same inlet can be read from by multiple threads); |
| 126 | + * uses somewhat more CPU. */ |
| 127 | + proc_threadsafe = 8, |
| 128 | + |
| 129 | + //! The combination of all possible post-processing options. |
| 130 | + proc_ALL = 1 | 2 | 4 | 8 |
| 131 | +} lsl_processing_options_t; |
| 132 | + |
| 133 | +/// Possible error codes. |
| 134 | +typedef enum { |
| 135 | + //! No error occurred |
| 136 | + lsl_no_error = 0, |
| 137 | + |
| 138 | + //! The operation failed due to a timeout. |
| 139 | + lsl_timeout_error = -1, |
| 140 | + |
| 141 | + //! The stream has been lost. |
| 142 | + lsl_lost_error = -2, |
| 143 | + |
| 144 | + //! An argument was incorrectly specified (e.g., wrong format or wrong length). |
| 145 | + lsl_argument_error = -3, |
| 146 | + |
| 147 | + //! Some other internal error has happened. |
| 148 | + lsl_internal_error = -4 |
| 149 | +} lsl_error_code_t; |
| 150 | + |
| 151 | + |
| 152 | +/** LSL version the binary was compiled against |
| 153 | + * |
| 154 | + * Used either to check if the same version is used |
| 155 | + * (`if(lsl_protocol_version()!=LIBLSL_COMPILE_HEADER_VERSION`) … |
| 156 | + * or to require a certain set of features: |
| 157 | + * ``` |
| 158 | + * #if LIBLSL_COMPILE_HEADER_VERSION > 113 |
| 159 | + * do_stuff(); |
| 160 | + * #endif |
| 161 | + * ``` |
| 162 | + * */ |
| 163 | +#define LIBLSL_COMPILE_HEADER_VERSION 114 |
| 164 | + |
| 165 | +/** Protocol version. |
| 166 | + * |
| 167 | + * The major version is `protocol_version() / 100;` |
| 168 | + * The minor version is `protocol_version() % 100;` |
| 169 | + * |
| 170 | + * Clients with different minor versions are protocol-compatible while clients |
| 171 | + * with different major versions will refuse to work together. |
| 172 | + */ |
| 173 | +extern LIBLSL_C_API int32_t lsl_protocol_version(); |
| 174 | + |
| 175 | +/** Version of the liblsl library. |
| 176 | + * |
| 177 | + * The major version is `library_version() / 100;` |
| 178 | + * The minor version is `library_version() % 100;` |
| 179 | + */ |
| 180 | +extern LIBLSL_C_API int32_t lsl_library_version(); |
| 181 | + |
| 182 | +/** Get a string containing library information. |
| 183 | + * |
| 184 | + * The format of the string shouldn't be used for anything important except giving a debugging |
| 185 | + * person a good idea which exact library version is used. */ |
| 186 | +extern LIBLSL_C_API const char *lsl_library_info(); |
| 187 | + |
| 188 | +/** Obtain a local system time stamp in seconds. |
| 189 | + * |
| 190 | + * The resolution is better than a millisecond. |
| 191 | + * This reading can be used to assign time stamps to samples as they are being acquired. |
| 192 | + * If the "age" of a sample is known at a particular time (e.g., from USB transmission |
| 193 | + * delays), it can be used as an offset to lsl_local_clock() to obtain a better estimate of |
| 194 | + * when a sample was actually captured. See lsl_push_sample() for a use case. |
| 195 | + */ |
| 196 | +extern LIBLSL_C_API double lsl_local_clock(); |
| 197 | + |
| 198 | +/** Deallocate a string that has been transferred to the application. |
| 199 | + * |
| 200 | + * Rarely used: the only use case is to deallocate the contents of |
| 201 | + * string-valued samples received from LSL in an application where |
| 202 | + * no free() method is available (e.g., in some scripting languages). |
| 203 | + */ |
| 204 | +extern LIBLSL_C_API void lsl_destroy_string(char *s); |
0 commit comments