AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
ntv2debugmacros.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #ifndef DEBUGMACROS_H
9 #define DEBUGMACROS_H
10 
11 
12 
13 // Macros common to all platforms
14 
15  // Decompose a UInt32 (or Mac "OSType") into 4 ASCII characters
16  // Example: printf ("Type = %c%c%c%c\n", Make4CC(myType) );
17 //#define Make4CC(my4CC) ((char*)(&my4CC))[0], ((char*)(&my4CC))[1], ((char*)(&my4CC))[2], ((char*)(&my4CC))[3]
18 
19  // Advanced form: if the 'type' is a numeric value (i.e. 0 - 63), print as a decimal number.
20  // Otherwise print as 4 characters.
21 #ifndef Make4CC
22  #if TARGET_OS_WIN32 || TARGET_CPU_X86
23  #define Make4CC(my4CC) ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[3]), \
24  ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[2]), \
25  ((my4CC < 0x40) ? ('0' + (char)(my4CC / 10)) : ((char*)(&my4CC))[1]), \
26  ((my4CC < 0x40) ? ('0' + (char)(my4CC % 10)) : ((char*)(&my4CC))[0])
27  #else
28  #define Make4CC(my4CC) ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[0]), \
29  ((my4CC < 0x40) ? ' ' : ((char*)(&my4CC))[1]), \
30  ((my4CC < 0x40) ? ('0' + (char)(my4CC / 10)) : ((char*)(&my4CC))[2]), \
31  ((my4CC < 0x40) ? ('0' + (char)(my4CC % 10)) : ((char*)(&my4CC))[3])
32  #endif
33 #endif
34 
35 
36 // Ping selectors
37 #define kPingOff 0
38 
39  // Muxer
40 #define kPingMuxerVBI 1
41 #define kPingAcThread 2
42 #define kPingDma 3
43 #define kPingMuxerAudioVox 4
44 #define kPingMuxerVideoVox 5
45 
46  // VideoOut
47 #define kPingFrameNotification 6
48 #define kPingCopyDrpToFrame 7
49 #define kPingEchoPortOut 8
50 #define kPingQTCallback 9
51 
52 #define kPingAVSync 10
53 
54  // Transfer Codec
55 #define kPingXfrBandDecomp 11
56 
57 
58  // VDig
59 #define kPingVDigFrameNotify 12
60 #define kPingVDigCompressOne 13
61 #define kPingVDigCompressDone 14
62 
63  // Use these for quickie tests
64 #define kPingTest1 15
65 #define kPingTest2 16
66 #define kPingTest3 17
67 #define kPingTest4 18
68 
69 
70 
71 // Platform-specific macros
72 
73 #ifdef AJAMac
74 
75 
76  // For simple cases of measuring durations using the Mac "Microseconds" timer
77  //
78  // This assumes a pair of matching calls: "StartUSTimer(foo)" and "EndUSTimer(foo)", both within the
79  // same scope (which rules out starting in one routine and ending in another - for that you have to
80  // find global memory to hold the "start time"). Typical use is as follows:
81  //
82  // TimerStart(foo)
83  // (code happens)
84  // TimerStop(foo)
85  //
86  // and you'll get a printf that looks like:
87  // foo duration = xxx usecs
88  //
89  // Note: no terminating ";" Also, the variable passes to matching TimerStart() and TimerStop() calls must match.
90  // You may, however, use different variables in overlapping calls, such as:
91  //
92  // TimerStart(foo)
93  // (code happens)
94  // TimerStart(bar)
95  // (more code happens)
96  // TimerStop(foo)
97  // (yet more...)
98  // TimerStop(bar)
99  //
100  // You may use TimerLimit() instead of TimerStop() to specify a "limit" duration: the printf will only happen
101  // if the measured duration EXCEEDS the specified limit.
102 
103  #if (DEBUG)
104  // normal printf's
105  #define TimerStart(a) UInt64 _startTime_##a, _endTime_##a; \
106  int _delta_##a; \
107  Microseconds((UnsignedWide*)&_startTime_##a);
108 
109  #define TimerStop(a) Microseconds((UnsignedWide*)&_endTime_##a); \
110  _delta_##a = (int)U64Subtract(_endTime_##a, _startTime_##a); \
111  printf (#a " duration = %d usecs\n", _delta_##a);
112 
113  #define TimerLimit(a,max) Microseconds((UnsignedWide*)&_endTime_##a); \
114  _delta_##a = (int)U64Subtract(_endTime_##a, _startTime_##a); \
115  if (_delta_##a >= max) \
116  printf (#a " duration = %d usecs\n", _delta_##a);
117 
118  // uses "dprintf" - which is assumed to be locally #define'd for LogProducer LogMsg
119  #define LogTimerStart(a) UInt64 _startTime_##a, _endTime_##a; \
120  int _delta_##a; \
121  Microseconds((UnsignedWide*)&_startTime_##a);
122 
123  #define LogTimerStop(a) Microseconds((UnsignedWide*)&_endTime_##a); \
124  _delta_##a = (int)U64Subtract(_endTime_##a, _startTime_##a); \
125  dprintf (LOG_DEBUG, #a " duration = %d usecs\n", _delta_##a);
126 
127  // Mark time between successive function calls
128  #define MarkTimeDelta(a) static UInt64 _savedTime_##a = 0; UInt64 _currTime_##a; int _delta_##a; \
129  Microseconds((UnsignedWide*)&_currTime_##a); \
130  _delta_##a = (int)U64Subtract(_currTime_##a, _savedTime_##a); \
131  printf (#a " duration = %d usecs\n", _delta_##a); \
132  _savedTime_##a = _currTime_##a;
133 
134  #else
135  // disable for deployment builds
136  #define TimerStart(a)
137  #define TimerStop(a)
138  #define TimerLimit(a,b)
139 
140  #define LogTimerStart(a)
141  #define LogTimerStop(a)
142 
143  #define MarkTimeDelta(a)
144  #endif
145 
146 
147  // Sleazy (but quick) ways to tell if a Mac keyboard key is pressed
148  #if (DEBUG)
149  #define shiftIsDown ( (GetCurrentKeyModifiers() & shiftKey) != 0 )
150  #define capsLockIsDown ( (GetCurrentKeyModifiers() & alphaLock) != 0 )
151  #define optionIsDown ( (GetCurrentKeyModifiers() & optionKey) != 0 )
152  #define controlIsDown ( (GetCurrentKeyModifiers() & controlKey) != 0 )
153  #define commandIsDown ( (GetCurrentKeyModifiers() & cmdKey) != 0 )
154  #else // !DEBUG
155  #define shiftIsDown false
156  #define capsLockIsDown false
157  #define optionIsDown false
158  #define controlIsDown false
159  #define commandIsDown false
160  #endif
161 
162 
163 #else // !AJAMac
164 
165 
166  #define TimerStart(a)
167  #define TimerStop(a)
168 
169  #define shiftIsDown false
170  #define capsLockIsDown false
171  #define optionIsDown false
172  #define controlIsDown false
173  #define commandIsDown false
174 
175  #if DEBUG
176  #define printf debugPrintf
177  void debugPrintf (char *format, ...);
178  #else
179  #define printf dummyPrintf
180  void dummyPrintf (char *format, ...); // see SoftwareCodec.cpp
181  #endif
182 
183 #endif
184 
185 
186 #endif // DEBUGMACROS_H