AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
ntv2qtmultiinput.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ntv2qtmultiinput.h"
9 #include "ntv2devicefeatures.h"
10 
11 //
12 // This array maps SDI input numbers 0 thru 3 to an NTV2InputSource...
13 //
15 {
24 
25 };
26 
27 
28 NTV2QtMultiInput::NTV2QtMultiInput (QWidget * parent, Qt::WindowFlags flags)
29  : QDialog (parent, flags)
30 {
31  ULWord initialBoardIndex (0);
32  CNTV2DeviceScanner deviceScanner;
33  const ULWord numDevicesFound (ULWord(deviceScanner.GetNumDevices()));
34 
35  ::memset (mDeviceInputCounts, 0, sizeof (mDeviceInputCounts));
36  ::memset (mFrameGrabbers, 0, sizeof (mFrameGrabbers));
37 
38  //
39  // Build the device selector popup menu...
40  //
41  mDeviceChoicePopupMenu = new QComboBox;
42  if (numDevicesFound == 0)
43  mDeviceChoicePopupMenu->addItem (tr ("No Devices Found"));
44  else
45  {
46  NTV2DeviceInfoList & boardList (deviceScanner.GetDeviceInfoList ());
47  for (NTV2DeviceInfoListConstIter iter (boardList.begin ()); iter != boardList.end (); iter++)
48  {
49  mDeviceInputCounts [iter->deviceIndex] = ::NTV2DeviceGetNumVideoInputs (iter->deviceID);
50  mDeviceChoicePopupMenu->addItem (tr (iter->deviceIdentifier.c_str ()));
51  } // for each AJA device found
52  } // else at least one AJA device found
53 
54  //
55  // Default to the first quad-input device (if any)...
56  //
57  uint32_t numInputs = 4;
58 
59  for (ULWord ndx (0); ndx < numDevicesFound; ndx++)
60  if (mDeviceInputCounts [ndx] == 8)
61  numInputs = 8; // NOTE: hardcode for now
62  initialBoardIndex = 0;
63  QObject::connect (mDeviceChoicePopupMenu, SIGNAL (currentIndexChanged (int)), this, SLOT (RequestDeviceChange (const int)));
64  mDeviceChoicePopupMenu->setCurrentIndex (initialBoardIndex);
65 
66  //
67  // Set up each of the preview widgets and frame grabber threads...
68  //
69  QSignalMapper * signalMapper = new QSignalMapper (this);
70  for (uint32_t inputNumber = 0; inputNumber < numInputs; inputNumber++)
71  {
72  mPreviewGroupBoxes [inputNumber] = new QGroupBox (this);
73 
74  mPreviewWidgets [inputNumber] = new AJAPreviewWidget (this);
75  mPreviewWidgets [inputNumber]->setMinimumWidth (AJAPREVIEW_WIDGET_X / (numInputs/2));
76  mPreviewWidgets [inputNumber]->setMinimumHeight (AJAPREVIEW_WIDGET_Y / (numInputs/2));
77  mPreviewWidgets [inputNumber]->setSizePolicy(QSizePolicy ::Expanding, QSizePolicy ::Expanding);
78 
79  mFrameGrabbers [inputNumber] = new NTV2FrameGrabber (this);
80  mInputLabels [inputNumber] = new QLabel("",this);
81  mWithAudioCheckBoxes [inputNumber] = new QCheckBox ("Audio", this);
82  signalMapper->setMapping (mWithAudioCheckBoxes [inputNumber], inputNumber);
83  #if defined (INCLUDE_AJACC)
84  mWithCaptionsCheckBoxes [inputNumber] = new QCheckBox ("CC", this);
85  #endif
86 
87  QVBoxLayout * layout = new QVBoxLayout;
88  layout->addWidget (mPreviewWidgets [inputNumber]);
89  layout->addWidget (mInputLabels [inputNumber]);
90 
91  QHBoxLayout * bottomLayout (new QHBoxLayout);
92  bottomLayout->setContentsMargins (0, 0, 0, 0);
93  bottomLayout->addWidget (mWithAudioCheckBoxes [inputNumber]);
94  #if defined (INCLUDE_AJACC)
95  bottomLayout->addWidget (mWithCaptionsCheckBoxes [inputNumber]);
96  #endif
97  layout->addLayout (bottomLayout);
98 
99  mPreviewGroupBoxes [inputNumber]->setLayout (layout);
100 
101  connect (mFrameGrabbers [inputNumber], SIGNAL (newFrame (const QImage &, bool)),
102  mPreviewWidgets [inputNumber], SLOT (updateFrame (const QImage &, bool)));
103 
104  connect (mFrameGrabbers [inputNumber], SIGNAL (newStatusString (const QString)),
105  mInputLabels [inputNumber], SLOT (setText (const QString)));
106 
107  connect (mWithAudioCheckBoxes [inputNumber], SIGNAL (clicked ()), signalMapper, SLOT (map ()));
108  #if defined (INCLUDE_AJACC)
109  //connect (mWithCaptionsCheckBoxes [inputNumber], SIGNAL (clicked ()), signalMapper, SLOT (map ()));
110  #endif
111  } // for each video input
112 
113  //
114  // Map all "with audio" checkbox clicks to a single handler...
115  //
116 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
117  connect (signalMapper, SIGNAL (mappedInt (int)), this, SLOT (SlotAudioCheckBox (int)));
118 #else
119  connect (signalMapper, SIGNAL (mapped (int)), this, SLOT (SlotAudioCheckBox (int)));
120 #endif
121 
122  //
123  // Lay out everything...
124  //
125  QGridLayout * glayout = new QGridLayout;
126  if (numInputs == 4)
127  {
128  glayout->addWidget (mPreviewGroupBoxes [0], 0, 0);
129  glayout->addWidget (mPreviewGroupBoxes [1], 0, 1);
130  glayout->addWidget (mPreviewGroupBoxes [2], 1, 0);
131  glayout->addWidget (mPreviewGroupBoxes [3], 1, 1);
132  }
133  else
134  {
135  glayout->addWidget (mPreviewGroupBoxes [0], 0, 0);
136  glayout->addWidget (mPreviewGroupBoxes [1], 0, 1);
137  glayout->addWidget (mPreviewGroupBoxes [2], 0, 2);
138  glayout->addWidget (mPreviewGroupBoxes [3], 0, 3);
139  glayout->addWidget (mPreviewGroupBoxes [4], 1, 0);
140  glayout->addWidget (mPreviewGroupBoxes [5], 1, 1);
141  glayout->addWidget (mPreviewGroupBoxes [6], 1, 2);
142  glayout->addWidget (mPreviewGroupBoxes [7], 1, 3);
143  }
144 
145  QVBoxLayout * vlayout = new QVBoxLayout;
146  vlayout->addWidget (mDeviceChoicePopupMenu);
147  vlayout->addLayout (glayout);
148 
149  setLayout (vlayout);
150 
151 
152  //
153  // Set up the frame grabber threads...
154  //
155  for (uint32_t inputNumber (0); inputNumber < numInputs; inputNumber++)
156  {
157  mFrameGrabbers [inputNumber]->SetInputSource (gInputNumberToInputSource [inputNumber]);
158  mFrameGrabbers [inputNumber]->SetWithAudio (false);
159  mFrameGrabbers [inputNumber]->start ();
160  }
161 
162  RequestDeviceChange (initialBoardIndex);
163 
164 } // constructor
165 
166 
168 {
169  qDebug ("## NOTE: Leaving");
170 }
171 
172 
173 void NTV2QtMultiInput::SlotAudioCheckBox (const int inputNum)
174 {
175  mFrameGrabbers [inputNum]->SetWithAudio (mWithAudioCheckBoxes [inputNum]->isChecked ());
176 }
177 
178 
179 void NTV2QtMultiInput::SlotCaptionsCheckBox (const int inputNum)
180 {
181  (void) inputNum;
182  //mFrameGrabbers [inputNum]->changeCaptionChannel (mWithAudioCheckBoxes [inputNum]->isChecked () ? NTV2_CC608_CC1 : NTV2_CC608_ChannelInvalid);
183 }
184 
185 
186 void NTV2QtMultiInput::RequestDeviceChange (const int inDeviceIndexNum)
187 {
188  // Get the board number and type...
189  CNTV2DeviceScanner scanner;
190  if (scanner.GetNumDevices ())
191  {
192  NTV2DeviceInfo deviceInfo (scanner.GetDeviceInfoList () [inDeviceIndexNum]);
193 
194  // Notify each frame grabber to change devices...
195  for (uint32_t inputNumber (0); inputNumber < mDeviceInputCounts [inDeviceIndexNum]; inputNumber++)
196  if (mFrameGrabbers [inputNumber])
197  mFrameGrabbers [inputNumber]->SetDeviceIndex (deviceInfo.deviceIndex);
198  qDebug ("## NOTE: Device changed to %d", inDeviceIndexNum);
199  }
200 
201 } // RequestDeviceChange
gInputNumberToInputSource
static const NTV2InputSource gInputNumberToInputSource[]
Definition: ntv2qtmultiinput.cpp:14
NTV2_INPUTSOURCE_SDI4
@ NTV2_INPUTSOURCE_SDI4
Identifies the 4th SDI video input.
Definition: ntv2enums.h:1231
NTV2QtMultiInput::SlotAudioCheckBox
void SlotAudioCheckBox(const int inputNum)
This gets called when any "audio" checkbox is clicked.
Definition: ntv2qtmultiinput.cpp:173
NTV2_INPUTSOURCE_SDI6
@ NTV2_INPUTSOURCE_SDI6
Identifies the 6th SDI video input.
Definition: ntv2enums.h:1233
ntv2devicefeatures.h
Declares device capability functions.
CNTV2DeviceScanner
This class is used to enumerate AJA devices that are attached and known to the local host computer.
Definition: ntv2devicescanner.h:208
NTV2_INPUTSOURCE_SDI7
@ NTV2_INPUTSOURCE_SDI7
Identifies the 7th SDI video input.
Definition: ntv2enums.h:1234
NTV2DeviceInfoList
std::vector< NTV2DeviceInfo > NTV2DeviceInfoList
I am an ordered list of NTV2DeviceInfo structs.
Definition: ntv2devicescanner.h:154
CNTV2DeviceScanner::GetDeviceInfoList
virtual NTV2DeviceInfoList & GetDeviceInfoList(void)
Returns an NTV2DeviceInfoList that can be "walked" using standard C++ vector iteration techniques.
Definition: ntv2devicescanner.h:369
NTV2QtMultiInput::RequestDeviceChange
void RequestDeviceChange(const int inDeviceIndexNum)
This gets called when the user selects a different device from the device selector popup menu.
Definition: ntv2qtmultiinput.cpp:186
NTV2_INPUTSOURCE_SDI1
@ NTV2_INPUTSOURCE_SDI1
Identifies the 1st SDI video input.
Definition: ntv2enums.h:1228
NTV2QtMultiInput::SlotCaptionsCheckBox
void SlotCaptionsCheckBox(const int inputNum)
This gets called when any "CC" checkbox is clicked.
Definition: ntv2qtmultiinput.cpp:179
NTV2FrameGrabber::SetWithAudio
void SetWithAudio(const bool inWithAudio)
Enables or disables host audio playback.
Definition: ntv2framegrabber.h:70
ULWord
uint32_t ULWord
Definition: ajatypes.h:246
NTV2QtMultiInput::~NTV2QtMultiInput
~NTV2QtMultiInput()
Definition: ntv2qtmultiinput.cpp:167
NTV2_INPUTSOURCE_SDI5
@ NTV2_INPUTSOURCE_SDI5
Identifies the 5th SDI video input.
Definition: ntv2enums.h:1232
NTV2DeviceGetNumVideoInputs
UWord NTV2DeviceGetNumVideoInputs(const NTV2DeviceID inDeviceID)
Definition: ntv2devicefeatures.hpp:11923
AJAPREVIEW_WIDGET_X
#define AJAPREVIEW_WIDGET_X
Definition: ajapreviewwidget.h:22
NTV2InputSource
NTV2InputSource
Identifies a specific video input source.
Definition: ntv2enums.h:1221
NTV2DeviceInfoListConstIter
NTV2DeviceInfoList::const_iterator NTV2DeviceInfoListConstIter
Definition: ntv2devicescanner.h:155
NTV2DeviceInfo::deviceIndex
ULWord deviceIndex
Device index number – this will be phased out someday.
Definition: ntv2devicescanner.h:40
NTV2FrameGrabber
A QThread that captures audio/video from NTV2-compatible AJA devices and uses Qt signals to emit ARGB...
Definition: ntv2framegrabber.h:46
NTV2QtMultiInput::NTV2QtMultiInput
NTV2QtMultiInput(QWidget *parent=0, Qt::WindowFlags flags=Qt::WindowFlags())
Definition: ntv2qtmultiinput.cpp:28
NTV2_INPUTSOURCE_SDI8
@ NTV2_INPUTSOURCE_SDI8
Identifies the 8th SDI video input.
Definition: ntv2enums.h:1235
NTV2DeviceInfo
Definition: ntv2devicescanner.h:37
NTV2FrameGrabber::SetInputSource
void SetInputSource(const NTV2InputSource inInputSource)
Sets the input to be used for capture on the AJA device being used.
Definition: ntv2framegrabber.cpp:77
NTV2_INPUTSOURCE_SDI2
@ NTV2_INPUTSOURCE_SDI2
Identifies the 2nd SDI video input.
Definition: ntv2enums.h:1229
AJAPREVIEW_WIDGET_Y
#define AJAPREVIEW_WIDGET_Y
Definition: ajapreviewwidget.h:23
CNTV2DeviceScanner::GetNumDevices
virtual size_t GetNumDevices(void) const
Returns the number of AJA devices found on the local host.
Definition: ntv2devicescanner.h:346
AJAPreviewWidget
Definition: ajapreviewwidget.h:36
NTV2FrameGrabber::SetDeviceIndex
void SetDeviceIndex(const UWord inDeviceIndex)
Sets the AJA device to be used for capture.
Definition: ntv2framegrabber.cpp:91
ntv2qtmultiinput.h
Header file for NTV2QtMultiInput demonstration application. Demonstrates how to capture several SDI A...
NTV2_INPUTSOURCE_SDI3
@ NTV2_INPUTSOURCE_SDI3
Identifies the 3rd SDI video input.
Definition: ntv2enums.h:1230