11 #if defined (INCLUDE_AJACC)
17 #define NTV2_NUM_IMAGES (10)
20 #define FGFAIL(_expr_) AJA_sERROR (AJA_DebugUnit_DemoCapture, AJAFUNC << ": " << _expr_)
21 #define FGWARN(_expr_) AJA_sWARNING(AJA_DebugUnit_DemoCapture, AJAFUNC << ": " << _expr_)
22 #define FGDBG(_expr_) AJA_sDEBUG (AJA_DebugUnit_DemoCapture, AJAFUNC << ": " << _expr_)
23 #define FGNOTE(_expr_) AJA_sNOTICE (AJA_DebugUnit_DemoCapture, AJAFUNC << ": " << _expr_)
24 #define FGINFO(_expr_) AJA_sINFO (AJA_DebugUnit_DemoCapture, AJAFUNC << ": " << _expr_)
35 mbFixedReference (
false),
45 mFormatIsProgressive (
true),
48 mDoMultiChannel (
false),
52 mNumAudioChannels (0),
76 if (inInputSource != mInputSource)
80 mInputSource = inInputSource;
90 if (inDeviceIndex != mBoardNumber)
93 mBoardNumber = inDeviceIndex;
102 if (inTCIndex != mTimeCodeSource)
105 mTimeCodeSource = inTCIndex;
115 const UWord result (mBoardNumber);
121 #if defined (INCLUDE_AJACC)
123 static const UWord gTest [15][32] =
126 {{0x250C, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014,
127 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2510},
128 {0x007C, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E,
129 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x007C},
130 {0x007C, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005D,
131 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x007C},
132 {0x007C, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x0020, 0x00E1, 0x00E9, 0x00ED,
133 0x00F3, 0x00FA, 0x00E7, 0x00F7, 0x00D1, 0x00E1, 0x00F1, 0x2588, 0x00AE, 0x00B0, 0x00BD, 0x00BF, 0x2122, 0x00A2, 0x00A3, 0x007C},
134 {0x007C, 0x266A, 0x00E0, 0x00A0, 0x00E8, 0x00E2, 0x00EA, 0x00EE, 0x00F4, 0x00FB, 0x00C1, 0x00C9, 0x00D3, 0x00DA, 0x00DC, 0x00FC,
135 0x2018, 0x00A1, 0x002A, 0x2019, 0x2014, 0x00A9, 0x2120, 0x2022, 0x201C, 0x201D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x007C},
136 {0x007C, 0x00C0, 0x00C2, 0x00C7, 0x00C8, 0x00CA, 0x00CB, 0x00EB, 0x00CE, 0x00CF, 0x00EF, 0x00D4, 0x00D9, 0x00F9, 0x00DB, 0x00AB,
137 0x00BB, 0x0020, 0x0020, 0x00C3, 0x00E3, 0x00CD, 0x00CC, 0x00EC, 0x00D2, 0x00F2, 0x00D5, 0x00F5, 0x007B, 0x007D, 0x005C, 0x007C},
138 {0x007C, 0x005E, 0x005F, 0x007C, 0x007E, 0x0020, 0x0020, 0x00C4, 0x00E4, 0x00D6, 0x00F6, 0x00DF, 0x00A5, 0x00A4, 0x007C, 0x00C5,
139 0x00E5, 0x00D8, 0x00F8, 0x00C4, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x007C},
140 {0x007C, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020,
141 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x007C},
142 {0x007C, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E,
143 0x003F, 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x007C},
144 {0x007C, 0x004E, 0x004F, 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005D,
145 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x007C},
146 {0x007C, 0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x0020, 0x00E1, 0x00E9, 0x00ED,
147 0x00F3, 0x00FA, 0x00E7, 0x00F7, 0x00D1, 0x00E1, 0x00F1, 0x2588, 0x00AE, 0x00B0, 0x00BD, 0x00BF, 0x2122, 0x00A2, 0x00A3, 0x007C},
148 {0x007C, 0x266A, 0x00E0, 0x00A0, 0x00E8, 0x00E2, 0x00EA, 0x00EE, 0x00F4, 0x00FB, 0x00C1, 0x00C9, 0x00D3, 0x00DA, 0x00DC, 0x00FC,
149 0x2018, 0x00A1, 0x002A, 0x2019, 0x2014, 0x00A9, 0x2120, 0x2022, 0x201C, 0x201D, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x007C},
150 {0x007C, 0x00C0, 0x00C2, 0x00C7, 0x00C8, 0x00CA, 0x00CB, 0x00EB, 0x00CE, 0x00CF, 0x00EF, 0x00D4, 0x00D9, 0x00F9, 0x00DB, 0x00AB,
151 0x00BB, 0x0020, 0x0020, 0x00C3, 0x00E3, 0x00CD, 0x00CC, 0x00EC, 0x00D2, 0x00F2, 0x00D5, 0x00F5, 0x007B, 0x007D, 0x005C, 0x007C},
152 {0x007C, 0x005E, 0x005F, 0x007C, 0x007E, 0x0020, 0x0020, 0x00C4, 0x00E4, 0x00D6, 0x00F6, 0x00DF, 0x00A5, 0x00A4, 0x007C, 0x00C5,
153 0x00E5, 0x00D8, 0x00F8, 0x00C4, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x0020, 0x007C},
154 {0x2514, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014,
155 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2014, 0x2518}};
157 #endif // defined (INCLUDE_AJACC)
162 #if defined (INCLUDE_AJACC)
165 mScreenBuffer [row-1][col-1] = 0x0020;
169 (
void) inNotifyClients;
176 #if defined (INCLUDE_AJACC)
180 if (mNTV2Card.
features().CanDoCustomAnc())
182 bool gotCaptionPacket (
false);
196 if (ancCEA708DataIn.
GetPayloadData () && ancCEA708DataIn.GetPayloadByteCount ())
197 gotCaptionPacket = m708Decoder ? m708Decoder->SetSMPTE334AncData (ancCEA708DataIn.
GetPayloadData (), ancCEA708DataIn.GetPayloadByteCount ()) :
false;
203 if (ancCEA608DataIn.
GetPayloadData () && ancCEA608DataIn.GetPayloadByteCount ())
204 gotCaptionPacket = m708Decoder ? m708Decoder->SetSMPTE334AncData (ancCEA608DataIn.
GetPayloadData (), ancCEA608DataIn.GetPayloadByteCount ()) :
false;
212 gotCaptionPacket =
true;
220 gotCaptionPacket =
true;
226 if (gotCaptionPacket && m708Decoder && m708Decoder->ParseSMPTE334AncPacket ())
227 captionData = m708Decoder->GetCC608CaptionData ();
234 m608Decoder->ProcessNew608FrameData (captionData);
238 #endif // defined (INCLUDE_AJACC)
242 void NTV2FrameGrabber::changeCaptionChannel (
int inNewCaptionChannelId)
244 #if defined (INCLUDE_AJACC)
252 m608Decoder->SubscribeChangeNotification (Caption608Changed,
this);
253 m608Decoder->SetDisplayChannel (chosenCaptionChannel);
259 else if (m608Decoder)
264 else if (m608Decoder->GetDisplayChannel () != chosenCaptionChannel)
265 m608Decoder->SetDisplayChannel (chosenCaptionChannel);
269 (
void) inNewCaptionChannelId;
270 #endif // defined (INCLUDE_AJACC)
278 ULWord framesCaptured (0);
286 if (mNTV2Card.
Open(mBoardNumber))
300 if (mNTV2Card.
features().HasBiDirectionalSDI())
302 bool waitForInput =
false;
303 for (
unsigned offset(0); offset < 8; offset++)
332 currentImage->load (
":/resources/splash.png");
334 emit
newFrame (*currentImage,
true);
343 if (mNTV2Card.IsOpen())
345 if (!mDoMultiChannel)
355 if (mNTV2Card.
Open(mBoardNumber))
362 currentImage->fill(Qt::lightGray);
363 QString status (QString(
"%1 is busy").arg(mNTV2Card.
GetDisplayName().c_str()));
376 if (mNTV2Card.
features().CanDoMultiFormat())
383 currentImage->fill(Qt::lightGray);
384 QString status (QString(
"%1 is not ready").arg(mNTV2Card.
GetDisplayName().c_str()));
389 else if (!mNTV2Card.
features().CanDoCapture())
393 currentImage->fill(qRgba(40, 40, 40, 255));
394 QString status (QString(
"%1 is output-only device").arg(mNTV2Card.
GetDisplayName().c_str()));
399 else if (!mNTV2Card.
features().GetNumCSCs())
403 currentImage->fill(qRgba(40, 40, 40, 255));
404 QString status (QString(
"%1 has no CSCs, won't work for this demo").arg(mNTV2Card.
GetDisplayName().c_str()));
417 ULWord startFrameBuffer = (numFrameBuffersAvailable / mNTV2Card.
features().GetNumFrameStores()) *
ULWord(mChannel);
419 acOptions, 1, startFrameBuffer, startFrameBuffer+7);
423 mAudioDevice = mAudioOutput->start();
433 images[i] =
new QImage (mFrameDimensions.Width(), mFrameDimensions.Height(), QImage::Format_RGB32);
455 currentImage->fill(qRgba(40, 40, 40, 255));
470 #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
476 if (!mFormatIsProgressive && mDeinterlace)
480 if (currentImage->height() ==
int(mFrameDimensions.Height()) && currentImage->width() ==
int(mFrameDimensions.Width()))
481 for (
ULWord line (0); line < mFrameDimensions.Height(); line += 2)
482 ::memcpy (currentImage->scanLine (
int(line) + 1), currentImage->scanLine(
int(line)), mFrameDimensions.Width() * 4);
488 CRP188 tc (tcValues.at(mTimeCodeSource));
489 if (!tcValues.at (mTimeCodeSource).IsValid())
499 outString.append (
" ");
501 outString.append (
" ");
502 outString.append (mTimeCode.c_str());
506 emit
newFrame (*currentImage, (framesCaptured == 0) ?
true :
false);
516 if (mNTV2Card.IsOpen ())
520 if (!mDoMultiChannel)
538 if (!mNTV2Card.IsOpen())
548 bool waitForInput(
false);
549 if (mNTV2Card.
features().HasBiDirectionalSDI())
550 for (
unsigned offset(0); offset < 4; offset++)
572 mNTV2Card.
SetVideoFormat (mCurrentVideoFormat,
false,
false, mChannel);
578 FGDBG(
"mInputSource=" << mChannel <<
" mCurrentVideoFormat=" << vfString.toStdString()
579 <<
" wdth=" << mFrameDimensions.Width() <<
" hght=" << mFrameDimensions.Height());
582 if (!mbFixedReference)
590 bool is6g(
false), is12g(
false);
594 if (mNTV2Card.
features().CanDo12gRouting() && (is6g || is12g))
602 else for (
unsigned offset(0); offset < 4; offset++)
624 if (!mbFixedReference)
634 if (!mbFixedReference)
638 if (mNTV2Card.
features().CanDo12gRouting())
741 if (mNTV2Card.
features().GetHDMIVersion() == 2)
745 FGWARN(
"Bad mInputSource value " <<
DEC(mInputSource));
754 if (mNTV2Card.IsOpen())
758 bool tsiEnable(
false);
760 for (
ULWord i(0); i < (tsiEnable ? 2 : mNumChannels); i++)
775 mCurrentVideoFormat = videoFormat;
779 if ((mCurrentVideoFormat != videoFormat) || (mCurrentColorSpace != colorSpace))
781 if (mDebounceCounter == 0)
784 mLastVideoFormat = videoFormat;
787 else if (mDebounceCounter == 6)
791 mCurrentVideoFormat = videoFormat;
792 mDebounceCounter = 0;
796 if (mLastVideoFormat == videoFormat)
799 mDebounceCounter = 0;
811 if (!mNTV2Card.IsOpen())
819 bool is6g (
false), is12g(
false);
823 if (mNTV2Card.
features().CanDo12gRouting() && (is6g || is12g))
830 switch (mInputSource)
841 if (videoFormatNext == videoFormat)
844 if (videoFormatNext == videoFormat)
847 if (videoFormatNext == videoFormat)
889 if (!mNTV2Card.IsOpen())
908 mNumAudioChannels = mNTV2Card.
features().GetMaxAudioChannels();
916 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
917 mFormat.setSampleRate(48000);
918 mFormat.setChannelCount(2);
919 mFormat.setSampleSize(16);
920 mFormat.setCodec(
"audio/pcm");
921 mFormat.setByteOrder(QAudioFormat::LittleEndian);
922 mFormat.setSampleType(QAudioFormat::SignedInt);
924 mFormat.setSampleRate(48000);
925 mFormat.setChannelCount(2);
926 mFormat.setSampleFormat(QAudioFormat::Int16);
929 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
930 QAudioDeviceInfo audioDeviceInfo (QAudioDeviceInfo::defaultOutputDevice());
931 if (audioDeviceInfo.isFormatSupported(mFormat))
932 mAudioOutput =
new QAudioOutput (mFormat,
AJA_NULL);
934 QAudioDevice deviceInfo (QMediaDevices::defaultAudioOutput());
935 if (deviceInfo.isFormatSupported(mFormat))
936 mAudioOutput =
new QAudioSink(deviceInfo, mFormat,
AJA_NULL);
943 const ULWord nBytesPerAJASample (4);
944 unsigned channel (0);
945 UWord qtSampleNdx (0);
946 const ULWord totalSamples (inNumValidBytes / mNumAudioChannels);
947 const ULWord totalAjaSamples (inNumValidBytes / nBytesPerAJASample);
948 UWord * pQtAudioBuffer (
reinterpret_cast<UWord*
>(pInOutBuffer));
956 for (
unsigned ajaSampleNdx(0); ajaSampleNdx < totalAjaSamples; ajaSampleNdx++)
960 pQtAudioBuffer [qtSampleNdx] = pInOutBuffer [ajaSampleNdx] >> 16;
965 if (channel == mNumAudioChannels)
970 mAudioDevice->write (
reinterpret_cast<const char*
>(pQtAudioBuffer), totalSamples);
975 #if defined (INCLUDE_AJACC)
980 pFG->caption608Changed (inChangeInfo);
986 bool changed (
false);
990 ushort utf16Char (m608Decoder ? m608Decoder->GetOnAirUTF16CharacterWithAttributes (row, col, attrs) : 0x0020);
993 if (utf16Char != mScreenBuffer [row-1][col-1])
995 mScreenBuffer [row-1][col-1] = utf16Char;
1002 #endif // defined (INCLUDE_AJACC)