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