AJA NTV2 SDK  18.1.0.2149
NTV2 SDK 18.1.0.2149
types.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef AJA_TYPES_H
9 #define AJA_TYPES_H
10 
11 /**************************************************************************************************************
12  AJA_USE_CPLUSPLUS11 When defined (the default), the 'ajabase' portion of the SDK will use C++
13  language and/or STL features that require a C++11 compiler.
14 
15  When undefined, the 'ajabase' portion of the SDK will not use C++11 features.
16 
17  NOTE: This macro will be deprecated in a future SDK, when it will no longer
18  be possible to build the SDK without a C++11-capable compiler.
19 
20  See also: NTV2_USE_CPLUSPLUS11 in 'ajantv2/include/ajatypes.h'
21 
22  Introduced in SDK 16.0.
23 **************************************************************************************************************/
24 #if !defined(AJA_USE_CPLUSPLUS11)
25  #define AJA_USE_CPLUSPLUS11 // If defined, use C++11 features (requires C++11 compiler)
26 #endif // !defined(AJA_USE_CPLUSPLUS11)
27 
28 #include "ntv2deprecate.h"
29 
30 #if defined(AJA_WINDOWS)
31 
32  #if !defined(NULL)
33  #define NULL (0)
34  #endif
35 
36  #define AJA_PAGE_SIZE (4096)
37 
38  #define AJA_MAX_PATH (256)
39 
40  typedef signed __int8 int8_t;
41  typedef signed __int16 int16_t;
42  typedef signed __int32 int32_t;
43  typedef signed __int64 int64_t;
44  typedef unsigned __int8 uint8_t;
45  typedef unsigned __int16 uint16_t;
46  typedef unsigned __int32 uint32_t;
47  typedef unsigned __int64 uint64_t;
48 
49  #if defined(_WIN64)
50  typedef signed __int64 intptr_t;
51  typedef unsigned __int64 uintptr_t;
52  #define AJA_OS_64
53  #else
54  typedef signed __int32 intptr_t;
55  typedef unsigned __int32 uintptr_t;
56  #define AJA_OS_32
57  #endif
58  #define AJA_LITTLE_ENDIAN
59 
60  // This adds the ability to format 64-bit entities
61  #if defined(_MSC_VER) && _MSC_VER >= 1900 // VS2015 or later:
62  #include <inttypes.h> // Prevent duplicate macro definition warnings
63  #endif
64  # define __PRI64_PREFIX "ll"
65 
66  // Macros for printing format specifiers.
67  #ifndef PRId64
68  #define PRId64 __PRI64_PREFIX "d"
69  #endif
70  #ifndef PRIi64
71  #define PRIi64 __PRI64_PREFIX "i"
72  #endif
73  #ifndef PRIu64
74  #define PRIu64 __PRI64_PREFIX "u"
75  #endif
76  #ifndef PRIo64
77  #define PRIo64 __PRI64_PREFIX "o"
78  #endif
79  #ifndef PRIx64
80  #define PRIx64 __PRI64_PREFIX "x"
81  #endif
82 
83  // Synonyms for library functions with different names on different platforms
84  #define ajasnprintf(_str_, _maxbytes_, _format_, ...) _snprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
85  #define ajavsnprintf(_str_, _maxbytes_, _format_, ...) vsprintf_s( _str_, _maxbytes_, _format_, __VA_ARGS__ )
86  #define ajastrcasecmp(_str1_, _str2_) _stricmp( _str1_, _str2_ )
87  #define ajawcscasecmp(_str1_, _str2_) _wcsicmp( _str1_, _str2_ )
88 
89 #endif // defined(AJA_WINDOWS)
90 
91 #if defined(AJA_LINUX)
92 
93  #if !defined(NULL)
94  #define NULL (0)
95  #endif
96 
97  #define AJA_PAGE_SIZE (4096)
98 
99  #define AJA_MAX_PATH (4096)
100 
101  #if defined(MODULE)
102  // We're building the code as a kernel module
103  #include <linux/kernel.h>
104  #include <linux/string.h> // memset, etc.
105  #include <linux/version.h>
106  #if defined(x86_64)
107  typedef long int intptr_t;
108  // Not sure which version number should be used here
109  #if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,18))
110  typedef unsigned long int uintptr_t;
111  #endif
112  #elif !defined(powerpc)
113  typedef int intptr_t;
114  typedef unsigned int uintptr_t;
115  #endif
116  #else
117  #include <endian.h>
118  #include <stdint.h> // Pull in userland defines
119 
120  #ifdef __x86_64__
121  #define AJA_OS_64
122  #else
123  #define AJA_OS_32
124  #endif
125 
126  #if __BYTE_ORDER == __LITTLE_ENDIAN
127  #define AJA_LITTLE_ENDIAN
128  #else
129  #define AJA_BIG_ENDIAN
130  #endif
131 
132  // This adds the ability to format 64-bit entities
133  #if CPU_ARCH == x86_64
134  # define __PRI64_PREFIX "l"
135  # define __PRIPTR_PREFIX "l"
136  #else
137  # define __PRI64_PREFIX "ll"
138  # define __PRIPTR_PREFIX
139  #endif
140 
141  // Macros for printing format specifiers.
142  #ifndef PRId64
143  #define PRId64 __PRI64_PREFIX "d"
144  #endif
145  #ifndef PRIi64
146  #define PRIi64 __PRI64_PREFIX "i"
147  #endif
148  #ifndef PRIu64
149  #define PRIu64 __PRI64_PREFIX "u"
150  #endif
151  #ifndef PRIo64
152  #define PRIo64 __PRI64_PREFIX "o"
153  #endif
154  #ifndef PRIx64
155  #define PRIx64 __PRI64_PREFIX "x"
156  #endif
157  #endif // MODULE
158 
159  // Synonyms for library functions with different names on different platforms
160  #define ajasnprintf(_str_, _maxbytes_, _format_, ...) snprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
161  #define ajavsnprintf(_str_, _maxbytes_, _format_, ...) vsnprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
162  #define ajastrcasecmp(_str1_, _str2_) strcasecmp( _str1_, _str2_ )
163  #define ajawcscasecmp(_str1_, _str2_) wcscasecmp( _str1_, _str2_ )
164 
165 #endif // defined(AJA_LINUX)
166 
167 // NOTE:
168 // In order to get universal binaries compiling need to add the following defines
169 // to the project that uses this file.
170 // PER_ARCH_CFLAGS_i386 = -Dx86=1
171 // PER_ARCH_CFLAGS_x86_64 = -Dx86_64=1
172 // see: http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/64bitPorting/building/building.html
173 #if defined(AJA_MAC)
174 
175  #define AJA_PAGE_SIZE (4096)
176  #define AJA_MAX_PATH (1024)
177  #define AJA_LITTLE_ENDIAN
178 
179  #include <stdint.h>
180  #ifdef __LP64__
181  #define AJA_OS_64
182  #else
183  #define AJA_OS_32
184  #endif
185 
186  // This adds the ability to format 64-bit entities
187  #ifdef x86_64
188  # define __PRI64_PREFIX "l"
189  # define __PRIPTR_PREFIX "l"
190  #else
191  # define __PRI64_PREFIX "ll"
192  # define __PRIPTR_PREFIX
193  #endif
194 
195  // Macros for printing format specifiers.
196  #ifndef PRId64
197  #define PRId64 __PRI64_PREFIX "d"
198  #endif
199  #ifndef PRIi64
200  #define PRIi64 __PRI64_PREFIX "i"
201  #endif
202  #ifndef PRIu64
203  #define PRIu64 __PRI64_PREFIX "u"
204  #endif
205  #ifndef PRIo64
206  #define PRIo64 __PRI64_PREFIX "o"
207  #endif
208  #ifndef PRIx64
209  #define PRIx64 __PRI64_PREFIX "x"
210  #endif
211 
212  // Synonyms for library functions with different names on different platforms
213  #define ajasnprintf(_str_, _maxbytes_, _format_, ...) snprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
214  #define ajavsnprintf(_str_, _maxbytes_, _format_, ...) vsnprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
215  #define ajastrcasecmp(_str1_, _str2_) strcasecmp( _str1_, _str2_ )
216  #define ajawcscasecmp(_str1_, _str2_) wcscasecmp( _str1_, _str2_ )
217 
218  #ifndef EXCLUDE_WCHAR
219  #include <wchar.h>
220 
221  inline wchar_t wcstoupper(wchar_t c)
222  {
223  // probably needs to be more robust
224  wchar_t newChar = c;
225 
226  if (c >= (wchar_t)L'a' && c <= (wchar_t)L'z')
227  newChar = c - (L'a' - L'A');
228 
229  return newChar;
230  }
231 
232  inline int wcscasecmp(const wchar_t *string1,const wchar_t *string2)
233  {
234  int retVal = 0;
235 
236  int str1Len = (int)wcslen(string1);
237  int str2Len = (int)wcslen(string2);
238 
239  if(str1Len > str2Len)
240  retVal = 1;
241  else if(str1Len < str2Len)
242  retVal = -1;
243  else //same length
244  {
245  bool match = true;
246  for(int i=0;i<str1Len;i++)
247  {
248  if(wcstoupper(string1[i]) != wcstoupper(string2[i]))
249  {
250  match = false;
251  break;
252  }
253  }
254 
255  if(!match)
256  retVal = -1; //or could be 1 not sure which is best
257  }
258  return retVal;
259  }
260  #endif
261 
262 #endif // defined(AJA_MAC)
263 
264 #if defined(AJA_BAREMETAL)
265 
266  #if !defined(NULL)
267  #define NULL (0)
268  #endif
269 
270  #if defined(AJA_USE_CPLUSPLUS11)
271 // #undef AJA_USE_CPLUSPLUS11 // Linux c++11-in-SDK TBD
272  #endif
273 
274  #define AJA_PAGE_SIZE (4096)
275 
276  #define AJA_MAX_PATH (4096)
277 
278  #if defined(MODULE)
279  // We're building the code as a kernel module
280  #else
281  #include <stdint.h> // Pull in userland defines
282 
283  #define AJA_OS_32
284 
285  #define AJA_LITTLE_ENDIAN
286 
287  #define __bswap16(_x) __builtin_bswap16(_x)
288  #define __bswap32(_x) __builtin_bswap32(_x)
289  #define __bswap64(_x) __builtin_bswap64(_x)
290 
291  #define htonl(_x) __bswap32(_x)
292  #define htons(_x) __bswap16(_x)
293  #define ntohl(_x) __bswap32(_x)
294  #define ntohs(_x) __bswap16(_x)
295 
296  // This adds the ability to format 64-bit entities
297  # define __PRI64_PREFIX "ll"
298  # define __PRIPTR_PREFIX
299 
300  // Macros for printing format specifiers.
301  #ifndef PRId64
302  #define PRId64 __PRI64_PREFIX "d"
303  #endif
304  #ifndef PRIi64
305  #define PRIi64 __PRI64_PREFIX "i"
306  #endif
307  #ifndef PRIu64
308  #define PRIu64 __PRI64_PREFIX "u"
309  #endif
310  #ifndef PRIo64
311  #define PRIo64 __PRI64_PREFIX "o"
312  #endif
313  #ifndef PRIx64
314  #define PRIx64 __PRI64_PREFIX "x"
315  #endif
316  #endif // MODULE
317 
318  // Synonyms for library functions with different names on different platforms
319  #define ajasnprintf(_str_, _maxbytes_, _format_, ...) snprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
320  #define ajavsnprintf(_str_, _maxbytes_, _format_, ...) vsnprintf( _str_, _maxbytes_, _format_, __VA_ARGS__ )
321  #define ajastrcasecmp(_str1_, _str2_) strcasecmp( _str1_, _str2_ )
322  #define ajawcscasecmp(_str1_, _str2_) wcscasecmp( _str1_, _str2_ )
323 
324 #endif // defined(AJA_BAREMETAL)
325 
326 #if !defined(NULL_PTR)
327  #define NULL_PTR (0)
328 #endif
329 
330 
334 #if defined(AJA_LITTLE_ENDIAN)
335 #define AJA_FCC(a) \
336 ( ((uint32_t)(((uint8_t *)(a))[3]) << 0) + \
337  ((uint32_t)(((uint8_t *)(a))[2]) << 8) + \
338  ((uint32_t)(((uint8_t *)(a))[1]) << 16) + \
339  ((uint32_t)(((uint8_t *)(a))[0]) << 24) )
340 #else
341 #define AJA_FCC(a) \
342 ( ((uint32_t)(((uint8_t *)(a))[0]) << 0) + \
343  ((uint32_t)(((uint8_t *)(a))[1]) << 8) + \
344  ((uint32_t)(((uint8_t *)(a))[2]) << 16) + \
345  ((uint32_t)(((uint8_t *)(a))[3]) << 24) )
346 #endif
347 
352 #if defined(AJA_LITTLE_ENDIAN)
353 #define AJA_FOURCC(a,b,c,d) \
354 ( (((uint32_t)(a)) << 24) + \
355  (((uint32_t)(b)) << 16) + \
356  (((uint32_t)(c)) << 8) + \
357  (((uint32_t)(d)) << 0) )
358 #else
359 #define AJA_FOURCC(a,b,c,d) \
360 ( (((uint32_t)(a)) << 0) + \
361  (((uint32_t)(b)) << 8) + \
362  (((uint32_t)(c)) << 16) + \
363  (((uint32_t)(d)) << 24) )
364 #endif
365 #define AJA_FOURCC_2(a) (AJA_FOURCC(a,0,0,0))
366 
367 
372 #define AJA_SUCCESS(_status_) (_status_ >= 0)
373 #define AJA_FAILURE(_status_) (_status_ < 0)
374 
379 typedef enum
381 {
406 // Sequence errors
407 
418 // Other
422 } AJAStatus;
424 
425 // Use to silence "unused parameter" warnings
426 #define AJA_UNUSED(_x_) (void)_x_;
427 
428 #define AJA_CHECK_NULL(_ptr_, _res_) { if (__ptr__ == NULL) { return _res_; } }
429 #define AJA_RETURN_STATUS(_status_) { const AJAStatus s = _status_; if (s != AJA_STATUS_SUCCESS) { return s; } }
430 
431 #ifndef NUMELMS
432  #define NUMELMS(aa) (sizeof(aa)/sizeof((aa)[0]))
433 #endif
434 
435 #define AJA_ENDIAN_SWAP16(_data_) ( ((uint16_t(_data_) << 8) & uint16_t(0xff00)) | \
436  ((uint16_t(_data_) >> 8) & uint16_t(0x00ff)) )
437 #define AJA_ENDIAN_SWAP32(_data_) ( ((uint32_t(_data_) << 24) & uint32_t(0xff000000)) | \
438  ((uint32_t(_data_) << 8) & uint32_t(0x00ff0000)) | \
439  ((uint32_t(_data_) >> 8) & uint32_t(0x0000ff00)) | \
440  ((uint32_t(_data_) >> 24) & uint32_t(0x000000ff)) )
441 #define AJA_ENDIAN_SWAP64(_data_) ( ((uint64_t(_data_) << 56) & uint64_t(0xff00000000000000)) | \
442  ((uint64_t(_data_) << 40) & uint64_t(0x00ff000000000000)) | \
443  ((uint64_t(_data_) << 24) & uint64_t(0x0000ff0000000000)) | \
444  ((uint64_t(_data_) << 8) & uint64_t(0x000000ff00000000)) | \
445  ((uint64_t(_data_) >> 8) & uint64_t(0x00000000ff000000)) | \
446  ((uint64_t(_data_) >> 24) & uint64_t(0x0000000000ff0000)) | \
447  ((uint64_t(_data_) >> 40) & uint64_t(0x000000000000ff00)) | \
448  ((uint64_t(_data_) >> 56) & uint64_t(0x00000000000000ff)) )
449 
450 #endif // AJA_TYPES_H
AJAStatus
Definition: types.h:380
Deprecation control macros.
else retVal
Definition: ntv2vcam.cpp:1100