AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
ntv2subscriptions.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ntv2card.h"
9 
10 using namespace std;
11 
12 
15 
16 
17 // Subscribe to events
18 
20 {
21  return NTV2_IS_VALID_INTERRUPT_ENUM(inEventCode) && ConfigureSubscription (true, inEventCode, mInterruptEventHandles[inEventCode]);
22 }
23 
24 
26 {
27  return NTV2_IS_VALID_CHANNEL(inChannel) && SubscribeEvent(gChannelToOutputVerticalInterrupt[inChannel]);
28 }
29 
31 { UWord failures(0);
32  for (NTV2ChannelSetConstIter it(inChannels.begin()); it != inChannels.end(); ++it)
33  if (!SubscribeOutputVerticalEvent(*it))
34  failures++;
35  return !failures;
36 }
37 
38 
40 {
41  return NTV2_IS_VALID_CHANNEL(inChannel) && SubscribeEvent(gChannelToInputVerticalInterrupt[inChannel]);
42 }
43 
45 { UWord failures(0);
46  for (NTV2ChannelSetConstIter it(inChannels.begin()); it != inChannels.end(); ++it)
47  if (!SubscribeInputVerticalEvent(*it))
48  failures++;
49  return !failures;
50 }
51 
52 
53 // Unsubscribe from events
54 
56 {
57  return NTV2_IS_VALID_INTERRUPT_ENUM(inEventCode) && ConfigureSubscription (false, inEventCode, mInterruptEventHandles[inEventCode]);
58 }
59 
60 
62 {
63  return NTV2_IS_VALID_CHANNEL(inChannel) && UnsubscribeEvent(gChannelToOutputVerticalInterrupt[inChannel]);
64 }
65 
67 { UWord failures(0);
68  for (NTV2ChannelSetConstIter it(inChannels.begin()); it != inChannels.end(); ++it)
69  if (!UnsubscribeOutputVerticalEvent(*it))
70  failures++;
71  return !failures;
72 }
73 
74 
76 {
77  return NTV2_IS_VALID_CHANNEL(inChannel) && UnsubscribeEvent(gChannelToInputVerticalInterrupt[inChannel]);
78 }
79 
81 { UWord failures(0);
82  for (NTV2ChannelSetConstIter it(inChannels.begin()); it != inChannels.end(); ++it)
83  if (!UnsubscribeInputVerticalEvent(*it))
84  failures++;
85  return !failures;
86 }
87 
88 
89 // Get interrupt count
90 
92 {
93  outCount = 0;
94  return NTV2_IS_VALID_CHANNEL(inChannel) && GetInterruptCount (gChannelToOutputVerticalInterrupt[inChannel], outCount);
95 }
96 
97 
99 {
100  outCount = 0;
101  return NTV2_IS_VALID_CHANNEL(inChannel) && GetInterruptCount (gChannelToInputVerticalInterrupt[inChannel], outCount);
102 }
103 
104 
105 // Get event count
106 
108 {
109  outCount = NTV2_IS_VALID_CHANNEL(inChannel) ? mEventCounts.at(gChannelToOutputVerticalInterrupt[inChannel]) : 0;
110  return NTV2_IS_VALID_CHANNEL(inChannel);
111 }
112 
113 
114 bool CNTV2Card::GetInputVerticalEventCount (ULWord & outCount, const NTV2Channel inChannel)
115 {
116  outCount = NTV2_IS_VALID_CHANNEL(inChannel) ? mEventCounts.at(gChannelToInputVerticalInterrupt[inChannel]) : 0;
117  return NTV2_IS_VALID_CHANNEL(inChannel);
118 }
119 
120 
121 // Set event count
122 
123 bool CNTV2Card::SetOutputVerticalEventCount (const ULWord inCount, const NTV2Channel inChannel)
124 {
125  return NTV2_IS_VALID_CHANNEL(inChannel) && SetInterruptEventCount(gChannelToOutputVerticalInterrupt[inChannel], inCount);
126 }
127 
128 bool CNTV2Card::SetInputVerticalEventCount (const ULWord inCount, const NTV2Channel inChannel)
129 {
130  return NTV2_IS_VALID_CHANNEL(inChannel) && SetInterruptEventCount(gChannelToInputVerticalInterrupt[inChannel], inCount);
131 }
132 
133 
134 bool CNTV2Card::WaitForOutputVerticalInterrupt (const NTV2Channel inChannel, UWord inRepeatCount)
135 {
136  bool result (true);
137  if (!NTV2_IS_VALID_CHANNEL(inChannel))
138  return false;
139  if (!inRepeatCount)
140  return false;
141  do
142  {
143  result = WaitForInterrupt (gChannelToOutputVerticalInterrupt [inChannel]);
144  } while (--inRepeatCount && result);
145  return result;
146 }
147 
148 
149 bool CNTV2Card::WaitForInputVerticalInterrupt (const NTV2Channel inChannel, UWord inRepeatCount)
150 {
151  bool result (true);
152  if (!NTV2_IS_VALID_CHANNEL (inChannel))
153  return false;
154  if (!inRepeatCount)
155  return false;
156  do
157  {
158  result = WaitForInterrupt (gChannelToInputVerticalInterrupt [inChannel]);
159  } while (--inRepeatCount && result);
160  return result;
161 }
162 
163 
164 bool CNTV2Card::GetOutputFieldID (const NTV2Channel channel, NTV2FieldID & outFieldID)
165 {
166  // CHANNEL1 CHANNEL2 CHANNEL3 CHANNEL4 CHANNEL5 CHANNEL6 CHANNEL7 CHANNEL8
168  static ULWord bitShift [] = { 23, 5, 3, 1, 9, 7, 5, 3, 0};
169 
170  // Check status register to see if it is the one we want.
171  ULWord statusValue (0);
172  outFieldID = ReadRegister (regNum[channel], statusValue)
173  ? NTV2FieldID((statusValue >> bitShift[channel]) & 0x1)
175  return NTV2_IS_VALID_FIELD(outFieldID);
176 
177 } // GetOutputFieldID
178 
179 
180 bool CNTV2Card::WaitForOutputFieldID (const NTV2FieldID inFieldID, const NTV2Channel channel)
181 {
182  // Wait for next field interrupt...
183  bool bInterruptHappened (WaitForOutputVerticalInterrupt(channel));
184 
185  // Check status register to see if it is the one we want.
186  NTV2FieldID currentFieldID (NTV2_FIELD0);
187  GetOutputFieldID(channel, currentFieldID);
188 
189  // If not, wait for another field interrupt...
190  if (currentFieldID != inFieldID)
191  bInterruptHappened = WaitForOutputVerticalInterrupt(channel);
192 
193  return bInterruptHappened;
194 
195 } // WaitForOutputFieldID
196 
197 
198 bool CNTV2Card::GetInputFieldID (const NTV2Channel channel, NTV2FieldID & outFieldID)
199 {
200  // CHANNEL1 CHANNEL2 CHANNEL3 CHANNEL4 CHANNEL5 CHANNEL6 CHANNEL7 CHANNEL8
202  static ULWord bitShift [] = { 21, 19, 21, 19, 17, 15, 13, 3, 0};
203 
204  // See if the field ID of the last input vertical interrupt is the one of interest...
205  ULWord statusValue (0);
206  outFieldID = ReadRegister (regNum[channel], statusValue)
207  ? NTV2FieldID((statusValue >> bitShift[channel]) & 0x1)
209  return NTV2_IS_VALID_FIELD(outFieldID);
210 
211 } // GetInputFieldID
212 
213 
214 bool CNTV2Card::WaitForInputFieldID (const NTV2FieldID inFieldID, const NTV2Channel channel)
215 {
216  // Wait for next field interrupt...
217  bool bInterruptHappened (WaitForInputVerticalInterrupt(channel));
218 
219  // See if the field ID of the last input vertical interrupt is the one of interest...
220  NTV2FieldID currentFieldID (NTV2_FIELD0);
221  GetInputFieldID(channel, currentFieldID);
222 
223  // If not, wait for another field interrupt...
224  if (currentFieldID != inFieldID)
225  bInterruptHappened = WaitForInputVerticalInterrupt(channel);
226 
227  return bInterruptHappened;
228 
229 } // WaitForInputFieldID
CNTV2Card::SubscribeOutputVerticalEvent
virtual bool SubscribeOutputVerticalEvent(const NTV2Channel inChannel)
Causes me to be notified when an output vertical blanking interrupt is generated for the given output...
Definition: ntv2subscriptions.cpp:25
eInput3
@ eInput3
Definition: ntv2publicinterface.h:3770
NTV2_FIELD_INVALID
@ NTV2_FIELD_INVALID
Definition: ntv2enums.h:1819
CNTV2Card::GetOutputFieldID
virtual bool GetOutputFieldID(const NTV2Channel channel, NTV2FieldID &outFieldID)
Returns the current field ID of the specified output channel.
Definition: ntv2subscriptions.cpp:164
INTERRUPT_ENUMS
enum _INTERRUPT_ENUMS_ INTERRUPT_ENUMS
CNTV2Card::WaitForOutputFieldID
virtual bool WaitForOutputFieldID(const NTV2FieldID inFieldID, const NTV2Channel inChannel=NTV2_CHANNEL1)
Efficiently sleeps the calling thread/process until the next output VBI for the given field and outpu...
Definition: ntv2subscriptions.cpp:180
eOutput6
@ eOutput6
Definition: ntv2publicinterface.h:3786
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1334
CNTV2Card::WaitForInputVerticalInterrupt
virtual bool WaitForInputVerticalInterrupt(const NTV2Channel inChannel=NTV2_CHANNEL1, UWord inRepeatCount=1)
Efficiently sleeps the calling thread/process until the next one or more field (interlaced video) or ...
Definition: ntv2subscriptions.cpp:149
eInput2
@ eInput2
Definition: ntv2publicinterface.h:3747
eInput7
@ eInput7
Definition: ntv2publicinterface.h:3779
NTV2FieldID
NTV2FieldID
These values are used to identify fields for interlaced video. See Field/Frame Interrupts and CNTV2Ca...
Definition: ntv2enums.h:1815
NTV2ChannelSetConstIter
NTV2ChannelSet::const_iterator NTV2ChannelSetConstIter
A handy const iterator into an NTV2ChannelSet.
Definition: ntv2publicinterface.h:3855
NTV2_FIELD0
@ NTV2_FIELD0
Identifies the first field in time for an interlaced video frame, or the first and only field in a pr...
Definition: ntv2enums.h:1817
NTV2_IS_VALID_INTERRUPT_ENUM
#define NTV2_IS_VALID_INTERRUPT_ENUM(__e__)
Definition: ntv2publicinterface.h:3794
eInput4
@ eInput4
Definition: ntv2publicinterface.h:3771
CNTV2Card::SetOutputVerticalEventCount
virtual bool SetOutputVerticalEventCount(const ULWord inCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Resets my output interrupt event tally for the given channel.
Definition: ntv2subscriptions.cpp:123
eNumInterruptTypes
@ eNumInterruptTypes
Definition: ntv2publicinterface.h:3789
eOutput7
@ eOutput7
Definition: ntv2publicinterface.h:3787
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
CNTV2Card::SubscribeEvent
virtual bool SubscribeEvent(const INTERRUPT_ENUMS inEventCode)
Causes me to be notified when the given event/interrupt is triggered for the AJA device.
Definition: ntv2subscriptions.cpp:19
eInput8
@ eInput8
Definition: ntv2publicinterface.h:3780
eOutput2
@ eOutput2
Definition: ntv2publicinterface.h:3782
ntv2card.h
Declares the CNTV2Card class.
CNTV2Card::UnsubscribeInputVerticalEvent
virtual bool UnsubscribeInputVerticalEvent(const NTV2Channel inChannel=NTV2_CHANNEL1)
Unregisters me so I'm no longer notified when an input VBI is signaled on the given input channel.
Definition: ntv2subscriptions.cpp:75
CNTV2Card::GetInputFieldID
virtual bool GetInputFieldID(const NTV2Channel channel, NTV2FieldID &outFieldID)
Returns the current field ID of the specified input channel.
Definition: ntv2subscriptions.cpp:198
CNTV2Card::UnsubscribeOutputVerticalEvent
virtual bool UnsubscribeOutputVerticalEvent(const NTV2Channel inChannel)
Unregisters me so I'm no longer notified when an output VBI is signaled on the given output channel.
Definition: ntv2subscriptions.cpp:61
UWord
uint16_t UWord
Definition: ajatypes.h:253
eInput6
@ eInput6
Definition: ntv2publicinterface.h:3778
CNTV2Card::GetOutputVerticalEventCount
virtual bool GetOutputVerticalEventCount(ULWord &outCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Answers with the number of output interrupt events that I successfully waited for on the given channe...
Definition: ntv2subscriptions.cpp:107
kRegStatus2
@ kRegStatus2
Definition: ntv2publicinterface.h:388
NTV2ChannelSet
std::set< NTV2Channel > NTV2ChannelSet
A set of distinct NTV2Channel values.
Definition: ntv2publicinterface.h:3854
NTV2_IS_VALID_CHANNEL
#define NTV2_IS_VALID_CHANNEL(__x__)
Definition: ntv2enums.h:1348
gChannelToInputVerticalInterrupt
static INTERRUPT_ENUMS gChannelToInputVerticalInterrupt[]
Definition: ntv2subscriptions.cpp:14
kRegStatus
@ kRegStatus
Definition: ntv2publicinterface.h:124
CNTV2Card::GetInputVerticalEventCount
virtual bool GetInputVerticalEventCount(ULWord &outCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Answers with the number of input interrupt events that I successfully waited for on the given channel...
Definition: ntv2subscriptions.cpp:114
eInput1
@ eInput1
Definition: ntv2publicinterface.h:3746
CNTV2Card::WaitForOutputVerticalInterrupt
virtual bool WaitForOutputVerticalInterrupt(const NTV2Channel inChannel=NTV2_CHANNEL1, UWord inRepeatCount=1)
Efficiently sleeps the calling thread/process until the next one or more field (interlaced video) or ...
Definition: ntv2subscriptions.cpp:134
std
Definition: json.hpp:5362
CNTV2Card::SetInputVerticalEventCount
virtual bool SetInputVerticalEventCount(const ULWord inCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Resets my input interrupt event tally for the given channel.
Definition: ntv2subscriptions.cpp:128
NTV2_IS_VALID_FIELD
#define NTV2_IS_VALID_FIELD(__x__)
Definition: ntv2enums.h:1822
eOutput4
@ eOutput4
Definition: ntv2publicinterface.h:3784
CNTV2Card::UnsubscribeEvent
virtual bool UnsubscribeEvent(const INTERRUPT_ENUMS inEventCode)
Unregisters me so I'm no longer notified when the given event/interrupt is triggered on the AJA devic...
Definition: ntv2subscriptions.cpp:55
gChannelToOutputVerticalInterrupt
static INTERRUPT_ENUMS gChannelToOutputVerticalInterrupt[]
Definition: ntv2subscriptions.cpp:13
CNTV2Card::GetOutputVerticalInterruptCount
virtual bool GetOutputVerticalInterruptCount(ULWord &outCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Answers with the number of output vertical interrupts handled by the driver for the given output chan...
Definition: ntv2subscriptions.cpp:91
CNTV2Card::WaitForInputFieldID
virtual bool WaitForInputFieldID(const NTV2FieldID inFieldID, const NTV2Channel inChannel=NTV2_CHANNEL1)
Efficiently sleeps the calling thread/process until the next input VBI for the given field and input ...
Definition: ntv2subscriptions.cpp:214
eOutput5
@ eOutput5
Definition: ntv2publicinterface.h:3785
CNTV2Card::SubscribeInputVerticalEvent
virtual bool SubscribeInputVerticalEvent(const NTV2Channel inChannel=NTV2_CHANNEL1)
Causes me to be notified when an input vertical blanking interrupt occurs on the given input channel.
Definition: ntv2subscriptions.cpp:39
eInput5
@ eInput5
Definition: ntv2publicinterface.h:3777
eOutput1
@ eOutput1
Definition: ntv2publicinterface.h:3744
eOutput8
@ eOutput8
Definition: ntv2publicinterface.h:3788
CNTV2Card::GetInputVerticalInterruptCount
virtual bool GetInputVerticalInterruptCount(ULWord &outCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Answers with the number of input vertical interrupts handled by the driver for the given input channe...
Definition: ntv2subscriptions.cpp:98
eOutput3
@ eOutput3
Definition: ntv2publicinterface.h:3783