AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
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
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 ...
NTV2FieldID
These values are used to identify fields for interlaced video. See Field/Frame Interrupts and CNTV2Ca...
Definition: ntv2enums.h:1840
NTV2ChannelSet::const_iterator NTV2ChannelSetConstIter
A handy const iterator into an NTV2ChannelSet.
#define NTV2_IS_VALID_INTERRUPT_ENUM(__e__)
Definition: json.hpp:5362
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...
uint32_t ULWord
Definition: ajatypes.h:223
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1357
virtual bool SubscribeEvent(const INTERRUPT_ENUMS inEventCode)
Causes me to be notified when the given event/interrupt is triggered for the AJA device.
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...
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...
enum _INTERRUPT_ENUMS_ INTERRUPT_ENUMS
static INTERRUPT_ENUMS gChannelToInputVerticalInterrupt[]
virtual bool GetInputFieldID(const NTV2Channel inChannel, NTV2FieldID &outFieldID)
Returns the current field ID of the specified input channel.
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...
#define NTV2_IS_VALID_CHANNEL(__x__)
Definition: ntv2enums.h:1371
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...
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...
std::set< NTV2Channel > NTV2ChannelSet
A set of distinct NTV2Channel values.
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 ...
virtual bool GetOutputFieldID(const NTV2Channel inChannel, NTV2FieldID &outFieldID)
Returns the current field ID of the specified output channel.
virtual bool SetOutputVerticalEventCount(const ULWord inCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Resets my output interrupt event tally for the given channel.
uint16_t UWord
Definition: ajatypes.h:221
virtual bool SetInputVerticalEventCount(const ULWord inCount, const NTV2Channel inChannel=NTV2_CHANNEL1)
Resets my input interrupt event tally for the given channel.
virtual bool SubscribeOutputVerticalEvent(const NTV2Channel inChannel)
Causes me to be notified when an output vertical blanking interrupt is generated for the given output...
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...
Declares the CNTV2Card class.
#define NTV2_IS_VALID_FIELD(__x__)
Definition: ntv2enums.h:1847
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...
Identifies the first field in time for an interlaced video frame, or the first and only field in a pr...
Definition: ntv2enums.h:1842
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...
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 ...
static INTERRUPT_ENUMS gChannelToOutputVerticalInterrupt[]