AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
ntv2streampreview.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 "ntv2streampreview.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 NTV2StreamPreview::NTV2StreamPreview (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  for (ULWord ndx(0); ndx < 100; ndx++)
36  {
37  CNTV2Card device;
38  if (CNTV2DeviceScanner::GetDeviceAtIndex (ndx, device))
39  mBoardChoiceCombo->addItem(device.GetDisplayName().c_str());
40  else if (ndx == 0)
41  {mBoardChoiceCombo->addItem("No Devices Found"); break;}
42  else
43  break;
44  }
45  mBoardChoiceCombo->setCurrentIndex (0);
46 
47  // Input selection radio button group...
48  mInputButtonGroup = new QButtonGroup ();
49  mInputButtonGroup->addButton (new QRadioButton (tr ("Off")), NTV2_INPUTSOURCE_INVALID);
50  for (unsigned ndx (0); ndx < 8; ndx++)
51  mInputButtonGroup->addButton (new QRadioButton ((QString ("SDI %1").arg (string (1, char (ndx + '1')).c_str ()))), ::GetNTV2InputSourceForIndex(ndx, NTV2_IOKINDS_SDI));
52  for (unsigned ndx (0); ndx < 4; ndx++)
53  mInputButtonGroup->addButton (new QRadioButton ((QString ("HDMI %1").arg (string (1, char (ndx + '1')).c_str ()))), ::GetNTV2InputSourceForIndex(ndx, NTV2_IOKINDS_HDMI));
54  mInputButtonGroup->addButton (new QRadioButton (tr ("Analog")), ::GetNTV2InputSourceForIndex(0, NTV2_IOKINDS_ANALOG));
55  mInputButtonGroup->button (NTV2_INPUTSOURCE_INVALID)->setChecked (true);
56 
57  // Checkboxes...
58  mCheckFixedReference = new QCheckBox ("Fixed Reference", this);
59 
60  mVideoPreviewWidget = new AJAPreviewWidget (this);
61  mVideoPreviewWidget->setFixedWidth (STREAMPREVIEW_WIDGET_X);
62  mVideoPreviewWidget->setFixedHeight (STREAMPREVIEW_WIDGET_Y);
63 
64  mStreamGrabber = new NTV2StreamGrabber (this);
65  mStreamGrabber->SetDeviceIndex (mBoardChoiceCombo->currentIndex ());
66  mStreamGrabber->SetInputSource (NTV2_INPUTSOURCE_SDI1);
67 
68  QVBoxLayout * layout (new QVBoxLayout);
69  layout->addWidget (mBoardChoiceCombo);
70  layout->addWidget (mVideoPreviewWidget);
71 
72  for (QButtonIterator iter (mInputButtonGroup->buttons()); iter.hasNext (); )
73  layout->addWidget (iter.next());
74  layout->addWidget (mCheckFixedReference);
75 
76  layout->addStretch (1);
77  setLayout (layout);
78 
79  QObject::connect (mBoardChoiceCombo, SIGNAL (currentIndexChanged (int)), this, SLOT (RequestDeviceChange (const int)));
80  QObject::connect (mInputButtonGroup, SIGNAL (buttonReleased (int)), this, SLOT (inputChanged (int)));
81  QObject::connect (mCheckFixedReference, SIGNAL (toggled (bool)), this, SLOT (fixedRefChanged (bool)));
82  connect (mStreamGrabber, SIGNAL (newFrame (const QImage &, bool)), mVideoPreviewWidget, SLOT (updateFrame (const QImage &, bool)));
83  connect (mStreamGrabber, SIGNAL (newStatusString (const QString)), mVideoPreviewWidget, SLOT (updateStatusString (const QString)));
84 
85  mStreamGrabber->SetInputSource (NTV2_NUM_INPUTSOURCES);
86  mStreamGrabber->start ();
87  mTimerID = startTimer (100);
88 
89  mPnp.Install (PnpCallback, this, AJA_Pnp_PciVideoDevices);
90 
91 } // constructor
92 
93 
95 {
96  mPnp.Uninstall ();
97  delete mStreamGrabber;
98 
99 } // destructor
100 
101 
102 void NTV2StreamPreview::RequestDeviceChange (const int inDeviceIndexNum)
103 {
104  // Notify my frame grabber to change devices...
105  if (mStreamGrabber)
106  mStreamGrabber->SetDeviceIndex (inDeviceIndexNum);
107  qDebug ("## NOTE: Device changed to %d", inDeviceIndexNum);
108 
109 } // RequestDeviceChange
110 
111 
112 void NTV2StreamPreview::inputChanged (int inputRadioButtonId)
113 {
114  const NTV2InputSource chosenInputSource (static_cast <NTV2InputSource> (inputRadioButtonId));
115 
116  CNTV2Card device;
117  CNTV2DeviceScanner::GetDeviceAtIndex (mBoardChoiceCombo->currentIndex(), device);
118 
119  if (!NTV2_IS_VALID_INPUT_SOURCE (chosenInputSource))
120  {
121  mStreamGrabber->SetInputSource (NTV2_INPUTSOURCE_INVALID);
122  qDebug ("## DEBUG: NTV2StreamPreview::inputChanged: off");
123  }
124  else if (device.features().CanDoInputSource(chosenInputSource))
125  {
126  mStreamGrabber->SetInputSource (chosenInputSource);
127  cerr << "## DEBUG: NTV2StreamPreview::inputChanged: " << ::NTV2InputSourceToString (chosenInputSource) << endl;
128  }
129 } // inputChanged
130 
131 
132 void NTV2StreamPreview::fixedRefChanged (bool checked)
133 {
134  mStreamGrabber->SetFixedReference(checked);
135 
136 } // fixedRefChanged
137 
138 
139 void NTV2StreamPreview::updateInputs (void)
140 {
141  CNTV2Card ntv2Card (mBoardChoiceCombo->currentIndex());
142  if (ntv2Card.IsOpen())
143  {
144  for (QButtonIterator iter (mInputButtonGroup->buttons()); iter.hasNext(); )
145  {
146  QRadioButton * pButton (reinterpret_cast<QRadioButton*>(iter.next()));
147  const NTV2InputSource inputSource (NTV2InputSource(mInputButtonGroup->id(pButton)));
148  if (NTV2_IS_VALID_INPUT_SOURCE (inputSource))
149  {
150  const bool hasInputSource (ntv2Card.features().CanDoInputSource(inputSource));
151  const string videoFormatStr (hasInputSource ? ::NTV2VideoFormatToString(ntv2Card.GetInputVideoFormat(inputSource)) : "");
152  const QString buttonLabel (QString("%1 %2").arg(::NTV2InputSourceToString(inputSource, true).c_str(), videoFormatStr.empty() ? "No Detected Input" : videoFormatStr.c_str()));
153  pButton->setText (buttonLabel);
154  pButton->setEnabled (hasInputSource);
155  }
156  }
157  } // if board opened ok
158 
159 } // updateInputs
160 
161 
162 void NTV2StreamPreview::timerEvent (QTimerEvent * event)
163 {
164  if (event->timerId() == mTimerID)
165  updateInputs();
166  else
167  QWidget::timerEvent(event);
168 
169 } // timerEvent
170 
171 
172 void NTV2StreamPreview::devicesChanged (void)
173 {
174  qDebug () << QString ("devicesChanged");
175  mInputButtonGroup->button (NTV2_INPUTSOURCE_INVALID)->setChecked (true);
176  inputChanged (NTV2_INPUTSOURCE_INVALID); // necessary?
177 
178  mBoardChoiceCombo->clear ();
179  for (ULWord ndx (0); ndx < 100; ndx++)
180  {
181  CNTV2Card device;
182  if (CNTV2DeviceScanner::GetDeviceAtIndex (ndx, device))
183  mBoardChoiceCombo->addItem (tr (device.GetDisplayName ().c_str ()));
184  else if (ndx == 0)
185  {mBoardChoiceCombo->addItem (tr ("No Devices Found")); break;}
186  else
187  break;
188  }
189  mBoardChoiceCombo->setCurrentIndex (0);
190 
191 } // devicesChanged
192 
193 
194 void NTV2StreamPreview::PnpCallback (AJAPnpMessage inMessage, void * pUserData) // static
195 {
196  if (pUserData)
197  {
198  if (inMessage == AJA_Pnp_DeviceAdded || inMessage == AJA_Pnp_DeviceRemoved)
199  {
200  NTV2StreamPreview * pMainWindow (reinterpret_cast <NTV2StreamPreview *>(pUserData));
201  pMainWindow->devicesChanged ();
202  }
203  }
204 
205 } // PnpCallback
NTV2_IOKINDS_HDMI
@ NTV2_IOKINDS_HDMI
Specifies HDMI input/output kinds.
Definition: ntv2enums.h:1275
ntv2devicefeatures.h
Declares device capability functions.
types.h
Declares common types used in the ajabase library.
AJAPnpMessage
AJAPnpMessage
Definition: pnp.h:22
AJA_Pnp_PciVideoDevices
@ AJA_Pnp_PciVideoDevices
Definition: pnp.h:16
NTV2_IOKINDS_ANALOG
@ NTV2_IOKINDS_ANALOG
Specifies analog input/output kinds.
Definition: ntv2enums.h:1276
ntv2streampreview.h
Header file for NTV2StreamPreview demo application. Demonstrates how to capture audio/video from NTV2...
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
NTV2StreamPreview
I am a QDialog that displays whatever video is present on the SDI inputs of an AJA streaming device....
Definition: ntv2streampreview.h:30
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
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
NTV2StreamGrabber::SetFixedReference
void SetFixedReference(bool fixed)
Definition: ntv2streamgrabber.h:69
NTV2_INPUTSOURCE_INVALID
@ NTV2_INPUTSOURCE_INVALID
The invalid video input.
Definition: ntv2enums.h:1259
QButtonIterator
QListIterator< QAbstractButton * > QButtonIterator
Definition: ntv2streampreview.cpp:25
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
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
NTV2StreamPreview::~NTV2StreamPreview
~NTV2StreamPreview()
Definition: ntv2streampreview.cpp:94
NTV2InputSource
NTV2InputSource
Identifies a specific video input source.
Definition: ntv2enums.h:1244
NTV2StreamGrabber::SetInputSource
void SetInputSource(const NTV2InputSource inInputSource)
Sets the input to be used for capture on the AJA device being used.
Definition: ntv2streamgrabber.cpp:64
NTV2StreamGrabber
A QThread that captures audio/video from NTV2-compatible AJA devices and uses Qt signals to emit ARGB...
Definition: ntv2streamgrabber.h:41
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
std
Definition: json.hpp:5362
NTV2StreamPreview::NTV2StreamPreview
NTV2StreamPreview(QWidget *parent=NULL, Qt::WindowFlags flags=Qt::WindowFlags())
Definition: ntv2streampreview.cpp:28
AJAPreviewWidget
Definition: ajapreviewwidget.h:36
STREAMPREVIEW_WIDGET_Y
#define STREAMPREVIEW_WIDGET_Y
Definition: ntv2streamgrabber.h:31
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
NTV2StreamGrabber::SetDeviceIndex
void SetDeviceIndex(const UWord inDeviceIndex)
Sets the AJA device to be used for capture.
Definition: ntv2streamgrabber.cpp:78
STREAMPREVIEW_WIDGET_X
#define STREAMPREVIEW_WIDGET_X
Definition: ntv2streamgrabber.h:30