AJA NTV2 SDK  18.1.0.2439
NTV2 SDK 18.1.0.2439
ntv2capture.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 //#define AJA_RAW_AUDIO_RECORD // Uncomment to record captured raw audio into binary data file
9 //#define AJA_WAV_AUDIO_RECORD // Uncomment to record captured audio into WAV file
10 #include "ntv2capture.h"
11 #include "ntv2devicescanner.h"
12 #include "ntv2utils.h"
13 #include "ntv2devicefeatures.h"
14 #include "ajabase/system/process.h"
15 #include <iterator> // for inserter
16 #include <fstream> // for ofstream
17 
18 using namespace std;
19 
20 #define NTV2_BUFFER_LOCK
21 
22 
24 
26  : mConsumerThread (AJAThread()),
27  mProducerThread (AJAThread()),
28  mConfig (inConfig),
30  mSavedTaskMode (NTV2_DISABLE_TASKS),
31  mAudioSystem (inConfig.fWithAudio ? NTV2_AUDIOSYSTEM_1 : NTV2_AUDIOSYSTEM_INVALID),
32  mHostBuffers (),
33  mAVCircularBuffer (),
34  mGlobalQuit (false)
35 {
36 } // constructor
37 
38 
40 {
41  // Stop my capture and consumer threads, then destroy them...
42  Quit();
43 
44  // Unsubscribe from VBI events...
47 
48 } // destructor
49 
50 
51 void NTV2Capture::Quit (void)
52 {
53  // Set the global 'quit' flag, and wait for the threads to go inactive...
54  mGlobalQuit = true;
55 
56  while (mConsumerThread.Active())
57  AJATime::Sleep(10);
58 
59  while (mProducerThread.Active())
60  AJATime::Sleep(10);
61 
62  // Restore some of the device's former state...
63  if (!mConfig.fDoMultiFormat)
64  {
66  mDevice.SetTaskMode(mSavedTaskMode); // Restore prior task mode
67  }
68 
69 } // Quit
70 
71 
73 {
75 
76  // Open the device...
78  { if (aja::lower(mConfig.fDeviceSpec) != "list" && mConfig.fDeviceSpec != "?")
79  cerr << "## ERROR: Device '" << mConfig.fDeviceSpec << "' not found" << endl;
80  return AJA_STATUS_OPEN;
81  }
82  if (!mDevice.IsDeviceReady())
83  {cerr << "## ERROR: '" << mDevice.GetDescription() << "' not ready" << endl; return AJA_STATUS_INITIALIZE;}
84 
85  const bool isKonaHDMI (mDevice.features().GetNumHDMIVideoInputs() > 1);
86  const NTV2IOKinds inputType (isKonaHDMI ? NTV2_IOKINDS_HDMI : NTV2_IOKINDS_SDI);
87  if (!mDevice.features().CanDoCapture())
88  {cerr << "## ERROR: '" << mDevice.GetDescription() << "' is playback-only" << endl; return AJA_STATUS_FEATURE;}
89 
90  if (!mDevice.features().CanDoFrameBufferFormat(mConfig.fPixelFormat))
91  { cerr << "## ERROR: '" << mDevice.GetDescription() << "' doesn't support '"
92  << ::NTV2FrameBufferFormatToString(mConfig.fPixelFormat, true) << "' ("
93  << ::NTV2FrameBufferFormatToString(mConfig.fPixelFormat, false) << ", " << DEC(mConfig.fPixelFormat) << ")" << endl;
95  }
96 
97  ULWord appSignature (0);
98  int32_t appPID (0);
99  mDevice.GetStreamingApplication (appSignature, appPID); // Who currently "owns" the device?
100  mDevice.GetTaskMode(mSavedTaskMode); // Save the current device state
101  if (!mConfig.fDoMultiFormat)
102  {
104  {
105  cerr << "## ERROR: Unable to acquire '" << mDevice.GetDescription() << "' because another app (pid " << appPID << ") owns it" << endl;
106  return AJA_STATUS_BUSY; // Another app is using the device
107  }
108  }
109  mDevice.SetTaskMode(NTV2_OEM_TASKS); // Prevent interference from AJA retail services
110 
111  if (mDevice.features().CanDoMultiFormat())
112  mDevice.SetMultiFormatMode(mConfig.fDoMultiFormat);
113 
114  // This demo permits input source and channel to be specified independently.
116  mConfig.fInputChannel = NTV2_CHANNEL1; // Neither -i or -c specified: default to Ch1
118  mConfig.fInputChannel = ::NTV2InputSourceToChannel(mConfig.fInputSource); // Only -i specified: use that channel
120  mConfig.fInputSource = ::NTV2ChannelToInputSource ( mConfig.fInputChannel, inputType); // Only -c specified: use that input source
121  // On KonaHDMI, map specified SDI input to equivalent HDMI input...
122  if (isKonaHDMI && NTV2_INPUT_SOURCE_IS_SDI(mConfig.fInputSource))
124  if (!mDevice.features().CanDoInputSource(mConfig.fInputSource))
125  {
126  cerr << "## ERROR: No such input '" << ::NTV2InputSourceToString(mConfig.fInputSource, /*compact?*/true)
127  << "' on '" << mDevice.GetDescription() << "'" << endl;
128  return AJA_STATUS_UNSUPPORTED;
129  }
130  if (mConfig.fWithAnc && !mDevice.features().CanDoCustomAnc())
131  {cerr << "## ERROR: Anc capture requested, but '" << mDevice.GetDescription() << "' has no anc extractors"; return AJA_STATUS_UNSUPPORTED;}
132 
133  // Set up the video and audio...
134  status = SetupVideo();
135  if (AJA_FAILURE(status))
136  return status;
137 
138  if (mConfig.fWithAudio)
139  status = SetupAudio();
140  if (AJA_FAILURE(status))
141  return status;
142 
143  // Set up the circular buffers, the device signal routing, and both playout and capture AutoCirculate...
145  if (!RouteInputSignal())
146  return AJA_STATUS_FAIL;
147 
148  #if defined(_DEBUG)
149  cerr << mConfig
150  << "Device Description: " << mDevice.GetDescription() << endl
151  << endl;
152  #endif // defined(_DEBUG)
153  return AJA_STATUS_SUCCESS;
154 
155 } // Init
156 
157 
159 {
160  // Enable the FrameStore we intend to use...
161  mDevice.EnableChannel(mConfig.fInputChannel);
162 
163  // Enable and subscribe to VBIs (critical on Windows)...
164  mDevice.EnableInputInterrupt(mConfig.fInputChannel);
167 
168  // If the device supports bi-directional SDI and the requested input is SDI,
169  // ensure the SDI connector(s) are configured to receive...
171  {
172  mDevice.SetSDITransmitEnable (mConfig.fInputChannel, false); // Set SDI connector(s) to receive
173  mDevice.WaitForOutputVerticalInterrupt (NTV2_CHANNEL1, 10); // Wait 10 VBIs to allow reciever to lock
174  }
175 
176  // Determine the input video signal format...
177  mVideoFormat = mDevice.GetInputVideoFormat(mConfig.fInputSource);
178  if (mVideoFormat == NTV2_FORMAT_UNKNOWN)
179  {cerr << "## ERROR: No input signal or unknown format" << endl; return AJA_STATUS_NOINPUT;}
180  if (!mDevice.features().CanDoVideoFormat(mVideoFormat))
181  {
182  cerr << "## ERROR: '" << mDevice.GetDescription() << "' cannot handle " << ::NTV2VideoFormatToString(mVideoFormat) << endl;
183  return AJA_STATUS_UNSUPPORTED; // Device can't handle this format
184  }
185  if (NTV2_IS_4K_VIDEO_FORMAT(mVideoFormat) || NTV2_IS_QUAD_QUAD_FORMAT(mVideoFormat))
186  {
187  cerr << "## ERROR: 'ntv2capture' cannot handle " << ::NTV2VideoFormatToString(mVideoFormat)
188  << " input signal -- try 'ntv2capture4k' or 'ntv2capture8k' demo" << endl;
189  return AJA_STATUS_UNSUPPORTED; // This demo can't handle this format
190  }
191  CAPNOTE(::NTV2VideoFormatToString(mVideoFormat) << " detected on " << ::NTV2InputSourceToString(mConfig.fInputSource,true) << " on " << mDevice.GetDescription());
192  mFormatDesc = NTV2FormatDescriptor(mVideoFormat, mConfig.fPixelFormat);
193 
194  // Setting SDI output clock timing/reference is unimportant for capture-only apps...
195  if (!mConfig.fDoMultiFormat) // ...if not sharing the device...
196  mDevice.SetReference(NTV2_REFERENCE_FREERUN); // ...let it free-run
197 
198  // Set the device video format to whatever was detected at the input...
199  mDevice.SetVideoFormat (mVideoFormat, false, false, mConfig.fInputChannel);
200  mDevice.SetVANCMode (NTV2_VANCMODE_OFF, mConfig.fInputChannel); // Disable VANC
201 
202  // Set the frame buffer pixel format for the FrameStore to be used on the device...
203  mDevice.SetFrameBufferFormat (mConfig.fInputChannel, mConfig.fPixelFormat);
204  return AJA_STATUS_SUCCESS;
205 
206 } // SetupVideo
207 
208 
210 {
211  // In multiformat mode, base the audio system on the channel...
212  if (mConfig.fDoMultiFormat)
213  if (mDevice.features().GetNumAudioSystems() > 1)
214  if (UWord(mConfig.fInputChannel) < mDevice.features().GetNumAudioSystems())
215  mAudioSystem = ::NTV2ChannelToAudioSystem(mConfig.fInputChannel);
216 
217  NTV2AudioSystemSet audSystems (::NTV2MakeAudioSystemSet (mAudioSystem, 1));
218  CNTV2DemoCommon::ConfigureAudioSystems (mDevice, mConfig, audSystems);
219  return AJA_STATUS_SUCCESS;
220 
221 } // SetupAudio
222 
223 
225 {
226  // Let my circular buffer know when it's time to quit...
227  mAVCircularBuffer.SetAbortFlag(&mGlobalQuit);
228 
229  ULWord F1AncSize(0), F2AncSize(0);
230  if (mConfig.fWithAnc)
231  { // Use the max anc size stipulated by the AncFieldOffset VReg values...
232  ULWord F1OffsetFromEnd(0), F2OffsetFromEnd(0);
233  mDevice.ReadRegister(kVRegAncField1Offset, F1OffsetFromEnd); // # bytes from end of 8MB/16MB frame
234  mDevice.ReadRegister(kVRegAncField2Offset, F2OffsetFromEnd); // # bytes from end of 8MB/16MB frame
235  // Based on the offsets, calculate the max anc capacity
236  F1AncSize = F2OffsetFromEnd > F1OffsetFromEnd ? 0 : F1OffsetFromEnd - F2OffsetFromEnd;
237  F2AncSize = F2OffsetFromEnd > F1OffsetFromEnd ? F2OffsetFromEnd - F1OffsetFromEnd : F2OffsetFromEnd;
238  }
239 
240  // Allocate and add each in-host NTV2FrameData to my circular buffer member variable...
241  const size_t audioBufferSize (NTV2_AUDIOSIZE_MAX);
242  mHostBuffers.reserve(size_t(CIRCULAR_BUFFER_SIZE));
243  while (mHostBuffers.size() < size_t(CIRCULAR_BUFFER_SIZE))
244  {
245  mHostBuffers.push_back(NTV2FrameData());
246  NTV2FrameData & frameData(mHostBuffers.back());
247  frameData.fVideoBuffer.Allocate(mFormatDesc.GetVideoWriteSize());
248  frameData.fAudioBuffer.Allocate(NTV2_IS_VALID_AUDIO_SYSTEM(mAudioSystem) ? audioBufferSize : 0);
249  frameData.fAncBuffer.Allocate(F1AncSize);
250  frameData.fAncBuffer2.Allocate(F2AncSize);
251  mAVCircularBuffer.Add(&frameData);
252 
253 #ifdef NTV2_BUFFER_LOCK
254  // Page lock the memory
255  if (frameData.fVideoBuffer)
256  mDevice.DMABufferLock(frameData.fVideoBuffer, true);
257  if (frameData.fAudioBuffer)
258  mDevice.DMABufferLock(frameData.fAudioBuffer, true);
259  if (frameData.fAncBuffer)
260  mDevice.DMABufferLock(frameData.fAncBuffer, true);
261 #endif
262  } // for each NTV2FrameData
263 
264 } // SetupHostBuffers
265 
266 
268 {
272 
273  const bool isInputRGB (inputColorSpace == NTV2_LHIHDMIColorSpaceRGB);
275 
276  return CNTV2DemoCommon::GetInputRouting (connections, mConfig, isInputRGB)
277  && mDevice.ApplySignalRoute(connections, !mConfig.fDoMultiFormat);
278 
279 } // RouteInputSignal
280 
281 
283 {
284  // Start the playout and capture threads...
287  return AJA_STATUS_SUCCESS;
288 
289 } // Run
290 
291 
293 
294 // This starts the consumer thread
296 {
297  // Create and start the consumer thread...
298  mConsumerThread.Attach(ConsumerThreadStatic, this);
299  mConsumerThread.SetPriority(AJA_ThreadPriority_High);
300  mConsumerThread.Start();
301 
302 } // StartConsumerThread
303 
304 
305 // The consumer thread function
306 void NTV2Capture::ConsumerThreadStatic (AJAThread * pThread, void * pContext) // static
307 {
308  (void) pThread;
309 
310  // Grab the NTV2Capture instance pointer from the pContext parameter,
311  // then call its ConsumeFrames method...
312  NTV2Capture * pApp (reinterpret_cast<NTV2Capture*>(pContext));
313  pApp->ConsumeFrames();
314 
315 } // ConsumerThreadStatic
316 
317 
319 {
320  CAPNOTE("Thread started");
321  AJA_NTV2_AUDIO_RECORD_BEGIN // Active when AJA_RAW_AUDIO_RECORD or AJA_WAV_AUDIO_RECORD defined
322  uint64_t ancTally(0);
323  ofstream * pOFS(mConfig.fAncDataFilePath.empty() ? AJA_NULL : new ofstream(mConfig.fAncDataFilePath.c_str(), ios::binary));
324  while (!mGlobalQuit)
325  {
326  // Wait for the next frame to become ready to "consume"...
327  NTV2FrameData * pFrameData(mAVCircularBuffer.StartConsumeNextBuffer());
328  if (pFrameData)
329  {
330  // Do something useful with the frame data...
331  // . . . . . . . . . . . .
332  // . . . . . . . . . . . .
333  // . . . . . . . . . . . .
334  AJA_NTV2_AUDIO_RECORD_DO // Active when AJA_RAW_AUDIO_RECORD or AJA_WAV_AUDIO_RECORD defined
335  if (pOFS && !ancTally++)
336  cerr << "Writing raw anc to '" << mConfig.fAncDataFilePath << "', "
337  << DEC(pFrameData->AncBufferSize() + pFrameData->AncBuffer2Size())
338  << " bytes per frame" << endl;
339  if (pOFS && pFrameData->AncBuffer())
340  pOFS->write(pFrameData->AncBuffer(), streamsize(pFrameData->AncBufferSize()));
341  if (pOFS && pFrameData->AncBuffer2())
342  pOFS->write(pFrameData->AncBuffer2(), streamsize(pFrameData->AncBuffer2Size()));
343 
344  // Now release and recycle the buffer...
345  mAVCircularBuffer.EndConsumeNextBuffer();
346  } // if pFrameData
347  } // loop til quit signaled
348  if (pOFS)
349  {delete pOFS; cerr << "Wrote " << DEC(ancTally) << " frames of raw anc data" << endl;}
350  AJA_NTV2_AUDIO_RECORD_END // Active when AJA_RAW_AUDIO_RECORD or AJA_WAV_AUDIO_RECORD defined
351  CAPNOTE("Thread completed, will exit");
352 
353 } // ConsumeFrames
354 
355 
357 
358 // This starts the capture (producer) thread
360 {
361  // Create and start the capture thread...
362  mProducerThread.Attach(ProducerThreadStatic, this);
363  mProducerThread.SetPriority(AJA_ThreadPriority_High);
364  mProducerThread.Start();
365 
366 } // StartProducerThread
367 
368 
369 // The capture thread function
370 void NTV2Capture::ProducerThreadStatic (AJAThread * pThread, void * pContext) // static
371 {
372  (void) pThread;
373 
374  // Grab the NTV2Capture instance pointer from the pContext parameter,
375  // then call its CaptureFrames method...
376  NTV2Capture * pApp (reinterpret_cast<NTV2Capture*>(pContext));
377  pApp->CaptureFrames ();
378 
379 } // ProducerThreadStatic
380 
381 
383 {
384  AUTOCIRCULATE_TRANSFER inputXfer; // AutoCirculate input transfer info
385  NTV2AudioChannelPairs nonPcmPairs, oldNonPcmPairs;
386  ULWord acOptions (AUTOCIRCULATE_WITH_RP188), overruns(0);
387  UWord sdiSpigot (UWord(::NTV2InputSourceToChannel(mConfig.fInputSource)));
388  if (mConfig.fWithAnc)
389  acOptions |= AUTOCIRCULATE_WITH_ANC;
390 
391  CAPNOTE("Thread started");
392 
393  // Initialize and start capture AutoCirculate...
394  mDevice.AutoCirculateStop(mConfig.fInputChannel); // Just in case
395  if (!mDevice.AutoCirculateInitForInput (mConfig.fInputChannel, mConfig.fFrames, mAudioSystem, acOptions))
396  mGlobalQuit = true;
397  if (!mGlobalQuit && !mDevice.AutoCirculateStart(mConfig.fInputChannel))
398  mGlobalQuit = true;
399 
400  // Ingest frames til Quit signaled...
401  while (!mGlobalQuit)
402  {
403  AUTOCIRCULATE_STATUS acStatus;
404  mDevice.AutoCirculateGetStatus (mConfig.fInputChannel, acStatus);
405 
406  if (acStatus.IsRunning() && acStatus.HasAvailableInputFrame())
407  {
408  // At this point, there's at least one fully-formed frame available in the device's
409  // frame buffer to transfer to the host. Reserve an NTV2FrameData to "produce", and
410  // use it in the next transfer from the device...
411  NTV2FrameData * pFrameData (mAVCircularBuffer.StartProduceNextBuffer());
412  if (!pFrameData)
413  continue;
414 
415  NTV2FrameData & frameData (*pFrameData);
416  inputXfer.SetVideoBuffer (frameData.VideoBuffer(), frameData.VideoBufferSize());
417  if (acStatus.WithAudio())
418  inputXfer.SetAudioBuffer (frameData.AudioBuffer(), frameData.AudioBufferSize());
419  if (acStatus.WithCustomAnc())
420  inputXfer.SetAncBuffers (frameData.AncBuffer(), frameData.AncBufferSize(),
421  frameData.AncBuffer2(), frameData.AncBuffer2Size());
422 
423  // Transfer video/audio/anc from the device into our host buffers...
424  mDevice.AutoCirculateTransfer (mConfig.fInputChannel, inputXfer);
425 
426  // Remember the actual amount of audio captured...
427  if (acStatus.WithAudio())
428  frameData.fNumAudioBytes = inputXfer.GetCapturedAudioByteCount();
429 
430  // If capturing Anc, clear stale anc data from the anc buffers...
431  if (acStatus.WithCustomAnc() && frameData.AncBuffer())
432  { bool overrun(false);
433  mDevice.AncExtractGetBufferOverrun (sdiSpigot, overrun);
434  if (overrun)
435  {overruns++; CAPWARN(overruns << " anc overrun(s)");}
436  frameData.fNumAncBytes = inputXfer.GetCapturedAncByteCount(/*isF2*/false);
437  NTV2Buffer stale (frameData.fAncBuffer.GetHostAddress(frameData.fNumAncBytes),
438  frameData.fAncBuffer.GetByteCount() - frameData.fNumAncBytes);
439  stale.Fill(uint8_t(0));
440  }
441  if (acStatus.WithCustomAnc() && frameData.AncBuffer2())
442  {
443  frameData.fNumAnc2Bytes = inputXfer.GetCapturedAncByteCount(/*isF2*/true);
444  NTV2Buffer stale (frameData.fAncBuffer2.GetHostAddress(frameData.fNumAnc2Bytes),
445  frameData.fAncBuffer2.GetByteCount() - frameData.fNumAnc2Bytes);
446  stale.Fill(uint8_t(0));
447  }
448 
449  // Grab all valid timecodes that were captured...
450  inputXfer.GetInputTimeCodes (frameData.fTimecodes, mConfig.fInputChannel, /*ValidOnly*/ true);
451 
452  if (acStatus.WithAudio())
453  // Look for PCM/NonPCM changes in the audio stream...
454  if (mDevice.GetInputAudioChannelPairsWithoutPCM (mConfig.fInputChannel, nonPcmPairs))
455  {
456  NTV2AudioChannelPairs becomingNonPCM, becomingPCM;
457  set_difference (oldNonPcmPairs.begin(), oldNonPcmPairs.end(), nonPcmPairs.begin(), nonPcmPairs.end(), inserter(becomingPCM, becomingPCM.begin()));
458  set_difference (nonPcmPairs.begin(), nonPcmPairs.end(), oldNonPcmPairs.begin(), oldNonPcmPairs.end(), inserter(becomingNonPCM, becomingNonPCM.begin()));
459  if (!becomingNonPCM.empty())
460  CAPNOTE("Audio channel pair(s) '" << becomingNonPCM << "' now non-PCM");
461  if (!becomingPCM.empty())
462  CAPNOTE("Audio channel pair(s) '" << becomingPCM << "' now PCM");
463  oldNonPcmPairs = nonPcmPairs;
464  }
465 
466  // Signal that we're done "producing" the frame, making it available for future "consumption"...
467  mAVCircularBuffer.EndProduceNextBuffer();
468  } // if A/C running and frame(s) are available for transfer
469  else
470  {
471  // Either AutoCirculate is not running, or there were no frames available on the device to transfer.
472  // Rather than waste CPU cycles spinning, waiting until a frame becomes available, it's far more
473  // efficient to wait for the next input vertical interrupt event to get signaled...
475  }
476 
477  // Log SDI input CRC/VPID/TRS errors...
479  {
480  NTV2SDIInStatistics sdiStats;
481  if (mDevice.ReadSDIStatistics(sdiStats))
482  {
483  NTV2SDIInputStatus inputStatus;
484  sdiStats.GetSDIInputStatus(inputStatus, UWord(::GetIndexForNTV2InputSource(mConfig.fInputSource)));
485  if (!inputStatus.isLocked())
486  CAPWARN(inputStatus);
487  }
488  }
489  } // loop til quit signaled
490 
491  // Stop AutoCirculate...
492  mDevice.AutoCirculateStop(mConfig.fInputChannel);
493  CAPNOTE("Thread completed, will exit");
494 
495 } // CaptureFrames
496 
497 
498 void NTV2Capture::GetACStatus (ULWord & outGoodFrames, ULWord & outDroppedFrames, ULWord & outBufferLevel)
499 {
500  AUTOCIRCULATE_STATUS status;
501  mDevice.AutoCirculateGetStatus(mConfig.fInputChannel, status);
502  outGoodFrames = status.GetProcessedFrameCount();
503  outDroppedFrames = status.GetDroppedFrameCount();
504  outBufferLevel = status.GetBufferLevel();
505 }
NTV2Channel NTV2InputSourceToChannel(const NTV2InputSource inInputSource)
Converts a given NTV2InputSource to its equivalent NTV2Channel value.
Definition: ntv2utils.cpp:5051
Anc Field2 byte offset from end of frame buffer (GUMP on all boards except RTP for SMPTE2022/IP) ...
ULWord GetVideoWriteSize(ULWord inPageSize=4096UL) const
virtual bool SetTaskMode(const NTV2TaskMode inMode)
Sets the device&#39;s task mode.
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
Definition: ntv2capture.h:19
For devices that support it (see NTV2DeviceCanDoSDIErrorChecks ), this struct reports SDI input error...
Specifies SDI input/output kinds.
Definition: ntv2enums.h:1296
bool Allocate(const size_t inByteCount, const bool inPageAligned=false)
Allocates (or re-allocates) my user-space storage using the given byte count. I assume full responsib...
Specifies the device&#39;s internal clock.
Definition: ntv2enums.h:1464
virtual bool SetReference(const NTV2ReferenceSource inRefSource, const bool inKeepFramePulseSelect=(0))
Sets the device&#39;s clock reference source. See Video Output Clocking & Synchronization for more inform...
virtual bool ReleaseStreamForApplication(ULWord inApplicationType, int32_t inProcessID)
Releases exclusive use of the AJA device for the given process, permitting other processes to acquire...
bool WithCustomAnc(void) const
AJAStatus Add(FrameDataPtr pInFrameData)
Appends a new frame buffer to me, increasing my frame storage capacity by one frame.
Declares the NTV2Capture class.
ULWord AncBuffer2Size(void) const
virtual bool SetVideoFormat(const NTV2VideoFormat inVideoFormat, const bool inIsAJARetail=(!(0)), const bool inKeepVancSettings=(0), const NTV2Channel inChannel=NTV2_CHANNEL1)
Configures the AJA device to handle a specific video format.
AJAStatus
Definition: types.h:380
ULWord VideoBufferSize(void) const
bool fDoMultiFormat
If true, use multi-format/multi-channel mode, if device supports it; otherwise normal mode...
ULWord GetCapturedAudioByteCount(void) const
virtual bool IsDeviceReady(const bool inCheckValid=(0))
ULWord AudioBufferSize(void) const
static uint64_t GetPid()
Definition: process.cpp:35
ULWord GetBufferLevel(void) const
virtual AJAStatus SetupVideo(void)
Sets up everything I need for capturing video.
#define AJA_FAILURE(_status_)
Definition: types.h:373
virtual bool SubscribeOutputVerticalEvent(const NTV2Channel inChannel=NTV2_CHANNEL1)
Causes me to be notified when an output vertical blanking interrupt is generated for the given output...
Definition: ntv2card.h:2763
NTV2InputSource NTV2ChannelToInputSource(const NTV2Channel inChannel, const NTV2IOKinds inKinds=NTV2_IOKINDS_SDI)
Definition: ntv2utils.cpp:5136
ULWord GetByteCount(void) const
bool WithAudio(void) const
#define NTV2_IS_4K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:787
NTV2AudioSystemSet NTV2MakeAudioSystemSet(const NTV2AudioSystem inFirstAudioSystem, const UWord inCount=1)
virtual AJAStatus SetPriority(AJAThreadPriority priority)
Definition: thread.cpp:133
Specifies HDMI input/output kinds.
Definition: ntv2enums.h:1297
virtual bool GetInputAudioChannelPairsWithoutPCM(const NTV2Channel inSDIInputConnector, NTV2AudioChannelPairs &outChannelPairs)
For the given SDI input (specified as a channel number), returns the set of audio channel pairs that ...
Definition: ntv2audio.cpp:1604
FrameDataPtr StartConsumeNextBuffer(void)
The thread that&#39;s responsible for processing incoming frames – the consumer – calls this function t...
bool fWithAnc
If true, also capture Anc.
virtual AJAStatus SetupAudio(void)
Sets up everything I need for capturing audio.
ULWord fNumAudioBytes
Actual number of captured audio bytes.
Definition: json.hpp:5362
virtual AJAStatus Start()
Definition: thread.cpp:91
virtual bool EnableInputInterrupt(const NTV2Channel channel=NTV2_CHANNEL1)
Allows the CNTV2Card instance to wait for and respond to input vertical blanking interrupts originati...
void EndConsumeNextBuffer(void)
The consumer thread calls this function to signal that it has finished processing the frame it obtain...
#define false
uint32_t ULWord
Definition: ajatypes.h:236
virtual bool AutoCirculateGetStatus(const NTV2Channel inChannel, AUTOCIRCULATE_STATUS &outStatus)
Returns the current AutoCirculate status for the given channel.
virtual bool SetFrameBufferFormat(NTV2Channel inChannel, NTV2FrameBufferFormat inNewFormat, bool inIsAJARetail=(!(0)), NTV2HDRXferChars inXferChars=NTV2_VPID_TC_SDR_TV, NTV2HDRColorimetry inColorimetry=NTV2_VPID_Color_Rec709, NTV2HDRLuminance inLuminance=NTV2_VPID_Luminance_YCbCr)
Sets the frame buffer format for the given FrameStore on the AJA device.
mVideoFormat
Definition: ntv2vcam.cpp:801
virtual class DeviceCapabilities & features(void)
Definition: ntv2card.h:148
bool CanDoInputSource(const NTV2InputSource inSrc)
virtual bool SetMultiFormatMode(const bool inEnable)
Enables or disables multi-format (per channel) device operation. If enabled, each device channel can ...
virtual bool GetHDMIInputColor(NTV2LHIHDMIColorSpace &outValue, const NTV2Channel inHDMIInput=NTV2_CHANNEL1)
Answers with the current colorspace for the given HDMI input.
Definition: ntv2hdmi.cpp:70
std::set< NTV2AudioChannelPair > NTV2AudioChannelPairs
A set of distinct NTV2AudioChannelPair values.
virtual AJAStatus Run(void)
Runs me.
ULWord GetProcessedFrameCount(void) const
bool fWithAudio
If true, also capture Audio.
virtual bool RouteInputSignal(void)
Sets up device routing for capture.
virtual void GetACStatus(ULWord &outGoodFrames, ULWord &outDroppedFrames, ULWord &outBufferLevel)
Provides status information about my input (capture) process.
int32_t appPID(0)
Anc Field1 byte offset from end of frame buffer (GUMP on all boards except RTP for SMPTE2022/IP) ...
#define NTV2_AUDIOSIZE_MAX
NTV2Channel fInputChannel
The device channel to use.
virtual bool Active()
Definition: thread.cpp:116
static void ConsumerThreadStatic(AJAThread *pThread, void *pContext)
This is the consumer thread&#39;s static callback function that gets called when the consumer thread runs...
bool Fill(const T &inValue)
Fills me with the given scalar value.
virtual bool GetTaskMode(NTV2TaskMode &outMode)
Retrieves the device&#39;s current task mode.
#define AJA_NTV2_AUDIO_RECORD_END
std::string NTV2InputSourceToString(const NTV2InputSource inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:7043
0: Disabled (never recommended): device configured exclusively by client application(s).
virtual void CaptureFrames(void)
Repeatedly captures frames using AutoCirculate (until global quit flag set).
virtual std::string GetDescription(void) const
Definition: ntv2card.cpp:139
std::string fAncDataFilePath
Optional path to Anc binary data file.
This class is used to configure an NTV2Capture instance.
ULWord AncBufferSize(void) const
static bool GetFirstDeviceFromArgument(const std::string &inArgument, CNTV2Card &outDevice)
Rescans the host, and returns an open CNTV2Card instance for the AJA device that matches a command li...
virtual bool SetSDITransmitEnable(const NTV2Channel inChannel, const bool inEnable)
Sets the specified bidirectional SDI connector to act as an input or an output.
virtual void StartProducerThread(void)
Starts my capture thread.
#define NTV2_INPUT_SOURCE_IS_HDMI(_inpSrc_)
Definition: ntv2enums.h:1285
virtual bool AutoCirculateTransfer(const NTV2Channel inChannel, AUTOCIRCULATE_TRANSFER &transferInfo)
Transfers all or part of a frame as specified in the given AUTOCIRCULATE_TRANSFER object to/from the ...
virtual bool AcquireStreamForApplication(ULWord inApplicationType, int32_t inProcessID)
Reserves exclusive use of the AJA device for a given process, preventing other processes on the host ...
virtual bool DMABufferLock(const NTV2Buffer &inBuffer, bool inMap=(0), bool inRDMA=(0))
Page-locks the given host buffer to reduce transfer time and CPU usage of DMA transfers.
Definition: ntv2dma.cpp:429
NTV2Buffer & AncBuffer2(void)
#define AJA_NULL
Definition: ajatypes.h:180
NTV2LHIHDMIColorSpace inputColorSpace(NTV2_LHIHDMIColorSpaceYCbCr)
void SetAbortFlag(const bool *pAbortFlag)
Tells me the boolean variable I should monitor such that when it gets set to "true" will cause any th...
NTV2Buffer & AncBuffer(void)
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...
Definition: ntv2card.h:2787
virtual NTV2VideoFormat GetInputVideoFormat(const NTV2InputSource inVideoSource=NTV2_INPUTSOURCE_SDI1, const bool inIsProgressive=(0))
Returns the video format of the signal that is present on the given input source. ...
Describes a video frame for a given video standard or format and pixel format, including the total nu...
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
2: OEM (recommended): device configured by client application(s) with some driver involvement...
virtual bool ApplySignalRoute(const CNTV2SignalRouter &inRouter, const bool inReplace=(0))
Applies the given routing table to the AJA device.
ULWord GetIndexForNTV2InputSource(const NTV2InputSource inValue)
Definition: ntv2utils.cpp:5278
NTV2XptConnections connections
Definition: ntv2vcam.cpp:1011
std::set< NTV2AudioSystem > NTV2AudioSystemSet
A set of distinct NTV2AudioSystem values. New in SDK 16.2.
std::string NTV2VideoFormatToString(const NTV2VideoFormat inValue, const bool inUseFrameRate=false)
Definition: ntv2utils.cpp:6750
NTV2Buffer & VideoBuffer(void)
ULWord GetDroppedFrameCount(void) const
NTV2Buffer fAncBuffer
Host ancillary data buffer.
#define AUTOCIRCULATE_WITH_ANC
Use this to AutoCirculate with ancillary data.
ULWord fNumAnc2Bytes
Actual number of captured F2 anc bytes.
virtual void Quit(void)
Gracefully stops me from running.
Definition: ntv2capture.cpp:51
Declares the CNTV2DeviceScanner class.
NTV2Buffer fAncBuffer2
Additional "F2" host anc buffer.
virtual bool ReadRegister(const ULWord inRegNum, ULWord &outValue, const ULWord inMask=0xFFFFFFFF, const ULWord inShift=0)
Reads all or part of the 32-bit contents of a specific register (real or virtual) on the AJA device...
virtual bool AutoCirculateStop(const NTV2Channel inChannel, const bool inAbort=(0))
Stops AutoCirculate for the given channel, and releases the on-device frame buffers that were allocat...
#define NTV2_IS_VALID_CHANNEL(__x__)
Definition: ntv2enums.h:1375
Declares the AJAProcess class.
Describes a user-space buffer on the host computer. I have an address and a length, plus some optional attributes (allocated by SDK?, page-aligned? etc.).
virtual bool UnsubscribeOutputVerticalEvent(const NTV2Channel inChannel)
Unregisters me so I&#39;m no longer notified when an output VBI is signaled on the given output channel...
Definition: ntv2card.h:2819
ULWord fNumAncBytes
Actual number of captured F1 anc bytes.
NTV2Buffer & AudioBuffer(void)
This object specifies the information that will be transferred to or from the AJA device in the CNTV2...
bool GetSDIInputStatus(NTV2SDIInputStatus &outStatus, const UWord inSDIInputIndex0=0)
Answers with the NTV2SDIInputStatus for the given SDI input spigot.
NTV2InputSource fInputSource
The device input connector to use.
#define DEC(__x__)
virtual void ConsumeFrames(void)
Repeatedly consumes frames from the circular buffer (until global quit flag set). ...
void EndProduceNextBuffer(void)
The producer thread calls this function to signal that it has finished populating the frame it obtain...
This identifies the first Audio System.
Definition: ntv2enums.h:3903
virtual void SetupHostBuffers(void)
Sets up my circular buffers.
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 ...
#define NTV2_IS_VALID_INPUT_SOURCE(_inpSrc_)
Definition: ntv2enums.h:1288
static const size_t CIRCULAR_BUFFER_SIZE(10)
Number of NTV2FrameData&#39;s in our ring.
static const ULWord kDemoAppSignature((((uint32_t)( 'D'))<< 24)|(((uint32_t)( 'E'))<< 16)|(((uint32_t)( 'M'))<< 8)|(((uint32_t)( 'O'))<< 0))
Declares numerous NTV2 utility functions.
virtual AJAStatus Attach(AJAThreadFunction *pThreadFunction, void *pUserContext)
Definition: thread.cpp:169
FrameDataPtr StartProduceNextBuffer(void)
The thread that&#39;s responsible for providing frames – the producer – calls this function to populate...
bool GetInputTimeCodes(NTV2TimeCodeList &outValues) const
Intended for capture, answers with the timecodes captured in my acTransferStatus member&#39;s acFrameStam...
static void ProducerThreadStatic(AJAThread *pThread, void *pContext)
This is the capture thread&#39;s static callback function that gets called when the capture thread runs...
#define NTV2_IS_QUAD_QUAD_FORMAT(__f__)
Definition: ntv2enums.h:823
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
uint16_t UWord
Definition: ajatypes.h:234
virtual bool AncExtractGetBufferOverrun(const UWord inSDIInput, bool &outIsOverrun, const UWord inField=0)
Answers whether or not the given SDI input&#39;s Anc extractor reached its buffer limits. (Call NTV2DeviceCanDoCustomAnc to determine if the device supports Anc extractor firmware.)
Definition: ntv2anc.cpp:1016
#define CAPWARN(_expr_)
Specifies channel or FrameStore 1 (or the first item).
Definition: ntv2enums.h:1363
virtual bool UnsubscribeInputVerticalEvent(const NTV2Channel inChannel=NTV2_CHANNEL1)
Unregisters me so I&#39;m no longer notified when an input VBI is signaled on the given input channel...
Definition: ntv2card.h:2837
virtual bool AutoCirculateStart(const NTV2Channel inChannel, const ULWord64 inStartTime=0)
Starts AutoCirculate streaming for the specified channel that was previously initialized by CNTV2Card...
bool CanDoFrameBufferFormat(const NTV2PixelFormat inPF)
ULWord appSignature(0)
bool isLocked(void) const
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
NTV2PixelFormat fPixelFormat
Pixel format to use.
static bool GetInputRouting(NTV2XptConnections &outConnections, const CaptureConfig &inConfig, const bool isInputRGB=(0))
Answers with the crosspoint connections needed to implement the given capture configuration.
#define NTV2_IS_VALID_AUDIO_SYSTEM(__x__)
Definition: ntv2enums.h:3920
bool SetAncBuffers(ULWord *pInANCBuffer, const ULWord inANCByteCount, ULWord *pInANCF2Buffer=NULL, const ULWord inANCF2ByteCount=0)
Sets my ancillary data buffers for use in a subsequent call to CNTV2Card::AutoCirculateTransfer.
std::string NTV2FrameBufferFormatToString(const NTV2FrameBufferFormat inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:6940
I encapsulate the video, audio and anc host buffers used in the AutoCirculate demos. I&#39;m a more modern version of the AVDataBuffer.
virtual void StartConsumerThread(void)
Starts my frame consumer thread.
NTV2Buffer fVideoBuffer
Host video buffer.
NTV2AudioSystem NTV2ChannelToAudioSystem(const NTV2Channel inChannel)
Converts the given NTV2Channel value into its equivalent NTV2AudioSystem.
Definition: ntv2utils.cpp:4873
bool HasAvailableInputFrame(void) const
static bool ConfigureAudioSystems(CNTV2Card &inDevice, const CaptureConfig &inConfig, const NTV2AudioSystemSet inAudioSystems)
Configures capture audio systems.
bool IsRunning(void) const
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2capture.cpp:72
std::string fDeviceSpec
The AJA device to use.
std::map< NTV2InputXptID, NTV2OutputXptID > NTV2XptConnections
This is used by the CNTV2Card::ReadSDIStatistics function.
#define AJA_NTV2_AUDIO_RECORD_DO
ULWord GetCapturedAncByteCount(const bool inField2=false) const
bool CanDoVideoFormat(const NTV2VideoFormat inVF)
virtual bool AutoCirculateInitForInput(const NTV2Channel inChannel, const UWord inFrameCount=7, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_INVALID, const ULWord inOptionFlags=0, const UByte inNumChannels=1, const UWord inStartFrameNumber=0, const UWord inEndFrameNumber=0)
Prepares for subsequent AutoCirculate ingest streaming, designating a contiguous block of frame buffe...
#define AUTOCIRCULATE_WITH_RP188
Use this to AutoCirculate with RP188.
#define NTV2_INPUT_SOURCE_IS_SDI(_inpSrc_)
Definition: ntv2enums.h:1287
std::string & lower(std::string &str)
Definition: common.cpp:436
void * GetHostAddress(const ULWord inByteOffset, const bool inFromEnd=false) const
bool SetAudioBuffer(ULWord *pInAudioBuffer, const ULWord inAudioByteCount)
Sets my audio buffer for use in a subsequent call to CNTV2Card::AutoCirculateTransfer.
NTV2Capture(const CaptureConfig &inConfig)
Constructs me using the given settings.
Definition: ntv2capture.cpp:25
#define CAPNOTE(_expr_)
virtual bool SetVANCMode(const NTV2VANCMode inVancMode, const NTV2Channel inChannel=NTV2_CHANNEL1)
Sets the VANC mode for the given FrameStore.
#define AJA_NTV2_AUDIO_RECORD_BEGIN
virtual bool GetStreamingApplication(ULWord &outAppType, int32_t &outProcessID)
Answers with the four-CC type and process ID of the application that currently "owns" the AJA device ...
NTV2TimeCodes fTimecodes
Map of TC indexes to NTV2_RP188 values.
Declares device capability functions.
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 ...
This identifies the mode in which there are no VANC lines in the frame buffer.
Definition: ntv2enums.h:3805
bool SetVideoBuffer(ULWord *pInVideoBuffer, const ULWord inVideoByteCount)
Sets my video buffer for use in a subsequent call to CNTV2Card::AutoCirculateTransfer.
virtual bool ReadSDIStatistics(NTV2SDIInStatistics &outStats)
For devices that support it (see the NTV2DeviceCanDoSDIErrorChecks function in "ntv2devicefeatures.h"), this function fetches the SDI statistics for all SDI input spigots.
NTV2LHIHDMIColorSpace
Definition: ntv2enums.h:3684
virtual ~NTV2Capture()
Definition: ntv2capture.cpp:39
ULWord NTV2IOKinds
Definition: ntv2enums.h:1314
virtual bool EnableChannel(const NTV2Channel inChannel)
Enables the given FrameStore.