AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
ntv2qtpreview.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 #include <QtCore>
10 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
11  #include <QtWidgets>
12 #else
13  #include <QtGui>
14 #endif
15 
16 #include "ntv2qtpreview.h"
17 #include "ntv2devicefeatures.h"
18 #include "ajabase/common/types.h"
19 #include "ntv2utils.h"
20 
21 
22 using namespace std;
23 
24 
25 typedef QListIterator <QAbstractButton *> QButtonIterator;
26 
27 
28 NTV2QtPreview::NTV2QtPreview (QWidget * parent, Qt::WindowFlags flags)
29  : QDialog (parent, flags)
30 {
31  if (objectName ().isEmpty ())
32  setObjectName (QString::fromUtf8 ("Dialog"));
33 
34  mBoardChoiceCombo = new QComboBox;
35 
36  // Input selection radio button group...
37  mInputButtonGroup = new QButtonGroup ();
38  mInputButtonGroup->addButton (new QRadioButton (tr ("Off")), NTV2_INPUTSOURCE_INVALID);
39  for (unsigned ndx (0); ndx < 8; ndx++)
40  mInputButtonGroup->addButton (new QRadioButton ((QString ("SDI %1").arg (string (1, char (ndx + '1')).c_str ()))), ::GetNTV2InputSourceForIndex(ndx, NTV2_IOKINDS_SDI));
41  for (unsigned ndx (0); ndx < 4; ndx++)
42  mInputButtonGroup->addButton (new QRadioButton ((QString ("HDMI %1").arg (string (1, char (ndx + '1')).c_str ()))), ::GetNTV2InputSourceForIndex(ndx, NTV2_IOKINDS_HDMI));
43  mInputButtonGroup->addButton (new QRadioButton (tr ("Analog")), ::GetNTV2InputSourceForIndex(0, NTV2_IOKINDS_ANALOG));
44  mInputButtonGroup->button (NTV2_INPUTSOURCE_INVALID)->setChecked (true);
45 
46  // Checkboxes...
47  mWithAudioCheckBox = new QCheckBox ("With Audio", this);
48  mCheckFor4kCheckBox = new QCheckBox ("Check for 4K Input", this);
49  mCheckFixedReference = new QCheckBox ("Fixed Reference", this);
50 
51  mVideoPreviewWidget = new AJAPreviewWidget (this);
52  mVideoPreviewWidget->setFixedWidth (QTPREVIEW_WIDGET_X);
53  mVideoPreviewWidget->setFixedHeight (QTPREVIEW_WIDGET_Y);
54 
55  mFrameGrabber = new NTV2FrameGrabber (this);
56  mFrameGrabber->SetDeviceIndex (mBoardChoiceCombo->currentIndex ());
57  mFrameGrabber->SetInputSource (NTV2_INPUTSOURCE_SDI1);
58 
59  QVBoxLayout * layout (new QVBoxLayout);
60  layout->addWidget (mBoardChoiceCombo);
61  layout->addWidget (mVideoPreviewWidget);
62 
63  #if defined (INCLUDE_AJACC)
64  QVBoxLayout * bottomLeftLayout (new QVBoxLayout);
65  bottomLeftLayout->setContentsMargins (0, 0, 0, 0);
66 
67  for (QButtonIterator iter (mInputButtonGroup->buttons()); iter.hasNext (); )
68  bottomLeftLayout->addWidget (iter.next());
69 
70  bottomLeftLayout->addWidget (mWithAudioCheckBox);
71  bottomLeftLayout->addWidget (mCheckFor4kCheckBox);
72  bottomLeftLayout->addStretch (1);
73 
74  QVBoxLayout * bottomRightLayout (new QVBoxLayout);
75  bottomRightLayout->setContentsMargins (0, 0, 0, 0);
76 
77  mCaptionButtonGroup = new QButtonGroup ();
78  mCaptionButtonGroup->addButton (new QRadioButton (tr ("CC Off")), NTV2_CC608_ChannelInvalid);
79  for (unsigned ndx (1); ndx <= 8; ndx++)
80  mCaptionButtonGroup->addButton (new QRadioButton (QString ("%1%2").arg (string (ndx < 5 ? "CC" : "TXT").c_str(), string (1, char ((ndx < 5 ? ndx : ndx - 4) + '0')).c_str())),
81  NTV2Line21Channel (ndx-1));
82  mCaptionButtonGroup->button (NTV2_CC608_ChannelInvalid)->setChecked (true);
83 
84  for (QButtonIterator iter (mCaptionButtonGroup->buttons()); iter.hasNext (); )
85  bottomRightLayout->addWidget (iter.next());
86 
87  QHBoxLayout * bottomLayout (new QHBoxLayout);
88  bottomLayout->setContentsMargins (0, 0, 0, 0);
89 
90  bottomLayout->addLayout (bottomLeftLayout);
91  bottomLayout->addLayout (bottomRightLayout);
92  layout->addLayout (bottomLayout);
93  #else // !defined (INCLUDE_AJACC)
94  for (QButtonIterator iter(mInputButtonGroup->buttons()); iter.hasNext(); )
95  layout->addWidget (iter.next());
96  layout->addWidget (mWithAudioCheckBox);
97  layout->addWidget (mCheckFor4kCheckBox);
98  layout->addWidget (mCheckFixedReference);
99  #endif // !defined (INCLUDE_AJACC)
100 
101  layout->addStretch (1);
102  setLayout (layout);
103 
104  QObject::connect (mBoardChoiceCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(RequestDeviceChange(const int)));
105  QObject::connect (mInputButtonGroup, SIGNAL(buttonReleased(int)), this, SLOT(inputChanged(int)));
106  QObject::connect (mWithAudioCheckBox, SIGNAL(stateChanged(int)), this, SLOT(withAudioChanged(int)));
107  QObject::connect (mCheckFixedReference, SIGNAL(toggled(bool)), this, SLOT(fixedRefChanged(bool)));
108  QObject::connect (mCheckFor4kCheckBox, SIGNAL(stateChanged(int)), this, SLOT(checkFor4kChanged(int)));
109  connect (mFrameGrabber, SIGNAL(newFrame(const QImage &, bool)), mVideoPreviewWidget, SLOT(updateFrame(const QImage &, bool)));
110  connect (mFrameGrabber, SIGNAL(newStatusString(const QString)), mVideoPreviewWidget, SLOT(updateStatusString(const QString)));
111  #if defined (INCLUDE_AJACC)
112  connect (mFrameGrabber, SIGNAL (captionScreenChanged (const ushort *)), mVideoPreviewWidget, SLOT (updateCaptionScreen (const ushort *)));
113  QObject::connect (mCaptionButtonGroup, SIGNAL (buttonReleased (int)), mFrameGrabber, SLOT (changeCaptionChannel (int)));
114  #endif // defined (INCLUDE_AJACC)
115 
116  mFrameGrabber->SetInputSource (NTV2_NUM_INPUTSOURCES);
117  mFrameGrabber->start ();
118  mTimerID = startTimer (100);
119 
120  mPnp.Install (PnpCallback, this, AJA_Pnp_PciVideoDevices);
121  devicesChanged();
122 
123 } // constructor
124 
125 
127 {
128  mPnp.Uninstall();
129  delete mFrameGrabber;
130 
131 } // destructor
132 
133 
134 void NTV2QtPreview::RequestDeviceChange (const int inDeviceIndexNum)
135 {
136  // Notify my frame grabber to change devices...
137  if (mFrameGrabber)
138  mFrameGrabber->SetDeviceIndex(inDeviceIndexNum);
139  qDebug ("## NOTE: Device changed to %d", inDeviceIndexNum);
140 
141 } // RequestDeviceChange
142 
143 
144 void NTV2QtPreview::inputChanged (int inputRadioButtonId)
145 {
146  const NTV2InputSource chosenInputSource(NTV2InputSource(inputRadioButtonId+0));
147 
148  CNTV2Card device;
149  CNTV2DeviceScanner::GetDeviceAtIndex (mBoardChoiceCombo->currentIndex(), device);
150 
151  if (!NTV2_IS_VALID_INPUT_SOURCE(chosenInputSource))
152  {
154  qDebug ("## DEBUG: NTV2QtPreview::inputChanged: off");
155  }
156  else if (device.features().CanDoInputSource(chosenInputSource))
157  {
158  mFrameGrabber->SetInputSource(chosenInputSource);
159  cerr << "## DEBUG: NTV2QtPreview::inputChanged: " << ::NTV2InputSourceToString(chosenInputSource) << endl;
160  }
161 
162 } // inputChanged
163 
164 
165 void NTV2QtPreview::withAudioChanged (int state)
166 {
167  mFrameGrabber->SetWithAudio (state == Qt::Checked ? true : false);
168 
169 } // withAudioChanged
170 
171 
172 void NTV2QtPreview::fixedRefChanged (bool checked)
173 {
174  mFrameGrabber->SetFixedReference(checked);
175 
176 }
177 
178 
179 void NTV2QtPreview::checkFor4kChanged (int state)
180 {
181  mFrameGrabber->CheckFor4kInput (state == Qt::Checked ? true : false);
182 
183 } // checkFor4kChanged
184 
185 
186 void NTV2QtPreview::updateInputs (void)
187 {
188  CNTV2Card ntv2Card (mBoardChoiceCombo->currentIndex());
189  if (ntv2Card.IsOpen())
190  {
191  for (QButtonIterator iter(mInputButtonGroup->buttons()); iter.hasNext(); )
192  {
193  QRadioButton * pButton (reinterpret_cast<QRadioButton*>(iter.next()));
194  const NTV2InputSource inputSource (NTV2InputSource(mInputButtonGroup->id(pButton)));
195  if (NTV2_IS_VALID_INPUT_SOURCE(inputSource))
196  {
197  const bool hasInputSource (ntv2Card.features().CanDoInputSource(inputSource));
198  const string videoFormatStr (hasInputSource ? ::NTV2VideoFormatToString(ntv2Card.GetInputVideoFormat(inputSource)) : "");
199  const QString buttonLabel (QString("%1 %2").arg(::NTV2InputSourceToString(inputSource, true).c_str(), videoFormatStr.empty() ? "No Detected Input" : videoFormatStr.c_str()));
200  pButton->setText(buttonLabel);
201  pButton->setEnabled(hasInputSource);
202  }
203  } // for each radio button
204  #if defined (INCLUDE_AJACC)
205  const bool hasCustomAnc (mDevice.features().CanDoCustomAnc());
206  for (QButtonIterator iter (mCaptionButtonGroup->buttons()); iter.hasNext(); )
207  iter.next()->setEnabled(hasCustomAnc);
208  #endif // defined (INCLUDE_AJACC)
209  } // if board opened ok
210 } // updateInputs
211 
212 
213 void NTV2QtPreview::timerEvent (QTimerEvent * event)
214 {
215  if (event->timerId() == mTimerID)
216  updateInputs();
217  else
218  QWidget::timerEvent(event);
219 } // timerEvent
220 
221 
222 void NTV2QtPreview::devicesChanged (void)
223 {
224  qDebug() << "devicesChanged";
225  mInputButtonGroup->button (NTV2_INPUTSOURCE_INVALID)->setChecked(true);
226  inputChanged (NTV2_INPUTSOURCE_INVALID); // necessary?
227 
228  mBoardChoiceCombo->clear();
229  for (ULWord ndx(0); ndx < 100; ndx++)
230  {
231  CNTV2Card device(ndx);
232  if (device.IsOpen())
233  mBoardChoiceCombo->addItem(tr(device.GetDisplayName().c_str()), QVariant());
234  else if (!ndx)
235  {mBoardChoiceCombo->addItem(tr("No Devices Found")); break;}
236  else
237  break;
238  }
239  mBoardChoiceCombo->setCurrentIndex(0);
240 } // devicesChanged
241 
242 
243 void NTV2QtPreview::PnpCallback (AJAPnpMessage inMessage, void * pUserData) // static
244 {
245  if (pUserData)
246  if (inMessage == AJA_Pnp_DeviceAdded || inMessage == AJA_Pnp_DeviceRemoved)
247  {
248  NTV2QtPreview * pMainWindow (reinterpret_cast<NTV2QtPreview*>(pUserData));
249  pMainWindow->devicesChanged();
250  }
251 } // PnpCallback
NTV2_IOKINDS_HDMI
@ NTV2_IOKINDS_HDMI
Specifies HDMI input/output kinds.
Definition: ntv2enums.h:1275
NTV2QtPreview
I am a QDialog that displays whatever video is present on the SDI inputs of an AJA device....
Definition: ntv2qtpreview.h:30
ntv2devicefeatures.h
Declares device capability functions.
types.h
Declares common types used in the ajabase library.
NTV2QtPreview::NTV2QtPreview
NTV2QtPreview(QWidget *parent=NULL, Qt::WindowFlags flags=Qt::WindowFlags())
Definition: ntv2qtpreview.cpp:28
AJAPnpMessage
AJAPnpMessage
Definition: pnp.h:22
NTV2QtPreview::~NTV2QtPreview
~NTV2QtPreview()
Definition: ntv2qtpreview.cpp:126
AJA_Pnp_PciVideoDevices
@ AJA_Pnp_PciVideoDevices
Definition: pnp.h:16
NTV2FrameGrabber::CheckFor4kInput
void CheckFor4kInput(const bool inCheckFor4K)
Enables or disables checking for 4K/UHD video (on devices that supported 4K/UHD).
Definition: ntv2framegrabber.h:86
NTV2_IOKINDS_ANALOG
@ NTV2_IOKINDS_ANALOG
Specifies analog input/output kinds.
Definition: ntv2enums.h:1276
CNTV2Card::features
virtual class DeviceCapabilities & features(void)
Definition: ntv2card.h:141
NTV2_INPUTSOURCE_SDI1
@ NTV2_INPUTSOURCE_SDI1
Identifies the 1st SDI video input.
Definition: ntv2enums.h:1251
CNTV2Card::GetDisplayName
virtual std::string GetDisplayName(void)
Answers with this device's display name.
Definition: ntv2card.cpp:86
AJAPnp::Uninstall
virtual AJAStatus Uninstall()
Uninstalls any previously-installed callback notifier.
Definition: pnp.cpp:45
NTV2_IOKINDS_SDI
@ NTV2_IOKINDS_SDI
Specifies SDI input/output kinds.
Definition: ntv2enums.h:1274
NTV2InputSourceToString
std::string NTV2InputSourceToString(const NTV2InputSource inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:7258
NTV2FrameGrabber::SetWithAudio
void SetWithAudio(const bool inWithAudio)
Enables or disables host audio playback.
Definition: ntv2framegrabber.h:70
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
NTV2_CC608_ChannelInvalid
@ NTV2_CC608_ChannelInvalid
Definition: ntv2caption608types.h:98
ntv2qtpreview.h
Header file for NTV2QtPreview demo application. Demonstrates how to capture audio/video from NTV2-bas...
NTV2_INPUTSOURCE_INVALID
@ NTV2_INPUTSOURCE_INVALID
The invalid video input.
Definition: ntv2enums.h:1259
NTV2_IS_VALID_INPUT_SOURCE
#define NTV2_IS_VALID_INPUT_SOURCE(_inpSrc_)
Definition: ntv2enums.h:1266
GetNTV2InputSourceForIndex
NTV2InputSource GetNTV2InputSourceForIndex(const ULWord inIndex0, const NTV2IOKinds inKinds=NTV2_IOKINDS_SDI)
Definition: ntv2utils.cpp:5284
ntv2utils.h
Declares numerous NTV2 utility functions.
NTV2VideoFormatToString
std::string NTV2VideoFormatToString(const NTV2VideoFormat inValue, const bool inUseFrameRate=false)
Definition: ntv2utils.cpp:6793
QTPREVIEW_WIDGET_Y
#define QTPREVIEW_WIDGET_Y
Definition: ntv2framegrabber.h:36
CNTV2Card
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
AJA_Pnp_DeviceRemoved
@ AJA_Pnp_DeviceRemoved
Definition: pnp.h:25
NTV2_NUM_INPUTSOURCES
@ NTV2_NUM_INPUTSOURCES
Definition: ntv2enums.h:1260
DeviceCapabilities::CanDoInputSource
bool CanDoInputSource(const NTV2InputSource inSrc)
Definition: ntv2devicecapabilities.h:233
NTV2InputSource
NTV2InputSource
Identifies a specific video input source.
Definition: ntv2enums.h:1244
NTV2FrameGrabber
A QThread that captures audio/video from NTV2-compatible AJA devices and uses Qt signals to emit ARGB...
Definition: ntv2framegrabber.h:46
CNTV2DeviceScanner::GetDeviceAtIndex
static bool GetDeviceAtIndex(const ULWord inDeviceIndexNumber, CNTV2Card &outDevice)
Rescans the host, and returns an open CNTV2Card instance for the AJA device having the given zero-bas...
Definition: ntv2devicescanner.cpp:274
QButtonIterator
QListIterator< QAbstractButton * > QButtonIterator
Definition: ntv2qtpreview.cpp:25
NTV2FrameGrabber::SetInputSource
void SetInputSource(const NTV2InputSource inInputSource)
Sets the input to be used for capture on the AJA device being used.
Definition: ntv2framegrabber.cpp:74
NTV2Line21Channel
NTV2Line21Channel
The CEA-608 caption channels: CC1 thru CC4, TX1 thru TX4, plus XDS.
Definition: ntv2caption608types.h:82
std
Definition: json.hpp:5362
AJAPreviewWidget
Definition: ajapreviewwidget.h:36
NTV2FrameGrabber::SetDeviceIndex
void SetDeviceIndex(const UWord inDeviceIndex)
Sets the AJA device to be used for capture.
Definition: ntv2framegrabber.cpp:88
AJAPnp::Install
virtual AJAStatus Install(AJAPnpCallback pInCallback, void *inRefCon=NULL, uint32_t inDeviceMask=0xFFFFFFFF)
Installs the given plug & play notification callback function, replacing any callback function that m...
Definition: pnp.cpp:38
AJA_Pnp_DeviceAdded
@ AJA_Pnp_DeviceAdded
Definition: pnp.h:24
NTV2FrameGrabber::SetFixedReference
void SetFixedReference(bool fixed)
Definition: ntv2framegrabber.h:96
QTPREVIEW_WIDGET_X
#define QTPREVIEW_WIDGET_X
Definition: ntv2framegrabber.h:35