AJA NTV2 SDK  18.1.0.2505
NTV2 SDK 18.1.0.2505
ntv2player.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ntv2player.h"
9 #include "ntv2debug.h"
10 #include "ntv2devicescanner.h"
11 #include "ntv2audiodefines.h"
12 #include "ntv2testpatterngen.h"
14 #include "ajabase/system/process.h"
15 #include "ajabase/system/file_io.h"
16 #include <fstream> // For ifstream
17 
18 using namespace std;
19 
20 //#define NTV2_BUFFER_LOCKING // Define this to pre-lock video/audio buffers in kernel
21 
22 // Convenience macros for EZ logging:
23 #define TCFAIL(_expr_) AJA_sERROR (AJA_DebugUnit_TimecodeGeneric, AJAFUNC << ": " << _expr_)
24 #define TCWARN(_expr_) AJA_sWARNING(AJA_DebugUnit_TimecodeGeneric, AJAFUNC << ": " << _expr_)
25 #define TCNOTE(_expr_) AJA_sNOTICE (AJA_DebugUnit_TimecodeGeneric, AJAFUNC << ": " << _expr_)
26 #define TCINFO(_expr_) AJA_sINFO (AJA_DebugUnit_TimecodeGeneric, AJAFUNC << ": " << _expr_)
27 #define TCDBG(_expr_) AJA_sDEBUG (AJA_DebugUnit_TimecodeGeneric, AJAFUNC << ": " << _expr_)
28 
34 static ULWord gAncMaxSizeBytes (NTV2_ANCSIZE_MAX); // Max per-frame anc buffer size, in bytes
35 
44 static const uint32_t gAudMaxSizeBytes (256 * 1024); // Max per-frame audio buffer size, in bytes
45 
46 static const bool BUFFER_PAGE_ALIGNED (true);
47 
48 static NTV2Channel GetRealVideoOutputChannel (CNTV2Card & inDevice, NTV2Channel inRequestedChannel)
49 {
50  if (!NTV2_IS_VALID_CHANNEL(inRequestedChannel))
51  return NTV2_CHANNEL1;
52  if (inDevice.features().GetNumVideoOutputs() <= 1)
53  return NTV2_CHANNEL1;
54  return inRequestedChannel;
55 }
56 
57 // Audio tone generator data
58 static const double gFrequencies [] = {250.0, 500.0, 1000.0, 2000.0};
59 static const ULWord gNumFrequencies (sizeof(gFrequencies) / sizeof(double));
60 static const double gAmplitudes [] = { 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
61  0.85, 0.80, 0.75, 0.70, 0.65, 0.60, 0.55, 0.50, 0.45, 0.40, 0.35, 0.30, 0.25, 0.20, 0.15, 0.10};
62 
63 
65  : mConfig (inConfig),
66  mConsumerThread (),
67  mProducerThread (),
68  mDevice (),
69  mSavedTaskMode (NTV2_TASK_MODE_INVALID),
70  mCurrentFrame (0),
71  mCurrentSample (0),
72  mToneFrequency (440.0),
73  mAudioSystem (NTV2_AUDIOSYSTEM_INVALID),
74  mFormatDesc (),
75  mTCIndexes (),
76  mGlobalQuit (false),
77  mTCBurner (),
78  mHostBuffers (),
79  mFrameDataRing (),
80  mTestPatRasters ()
81 {
82 }
83 
84 
86 {
87  // Stop my playout and producer threads, then destroy them...
88  Quit();
89 
90  mDevice.UnsubscribeOutputVerticalEvent(mConfig.fOutputChannel); // Unsubscribe from output VBI event
91 } // destructor
92 
93 
94 void NTV2Player::Quit (void)
95 {
96  // Set the global 'quit' flag, and wait for the threads to go inactive...
97  mGlobalQuit = true;
98 
99  while (mProducerThread.Active())
100  AJATime::Sleep(10);
101 
102  while (mConsumerThread.Active())
103  AJATime::Sleep(10);
104 
105 #if defined(NTV2_BUFFER_LOCKING)
106  mDevice.DMABufferUnlockAll();
107 #endif // NTV2_BUFFER_LOCKING
108  if (!mConfig.fDoMultiFormat && mDevice.IsOpen())
109  {
111  if (NTV2_IS_VALID_TASK_MODE(mSavedTaskMode))
112  mDevice.SetTaskMode(mSavedTaskMode); // Restore prior task mode
113  }
114 } // Quit
115 
116 
118 {
119  AJAStatus status (AJA_STATUS_SUCCESS);
120 
121  // Open the device...
123  { if (aja::lower(mConfig.fDeviceSpec) != "list" && mConfig.fDeviceSpec != "?")
124  cerr << "## ERROR: Device '" << mConfig.fDeviceSpec << "' not found" << endl;
125  return AJA_STATUS_OPEN;
126  }
127  if (!mDevice.IsDeviceReady(false))
128  {cerr << "## ERROR: Device '" << mDevice.GetDescription() << "' not ready" << endl; return AJA_STATUS_INITIALIZE;}
129  if (!mDevice.features().CanDoPlayback())
130  {cerr << "## ERROR: '" << mDevice.GetDescription() << "' is capture-only" << endl; return AJA_STATUS_FEATURE;}
131 
132  const UWord maxNumChannels (mDevice.features().GetNumFrameStores());
133 
134  // Beware -- some older devices (e.g. Corvid1) can only output from FrameStore 2...
135  if (mConfig.fOutputChannel == NTV2_CHANNEL1 && !mDevice.features().CanDoFrameStore1Display())
136  mConfig.fOutputChannel = NTV2_CHANNEL2;
137  if (UWord(mConfig.fOutputChannel) >= maxNumChannels)
138  {
139  cerr << "## ERROR: '" << mDevice.GetDescription() << "' can't use Ch" << DEC(mConfig.fOutputChannel+1)
140  << " -- only supports Ch1" << (maxNumChannels > 1 ? string("-Ch") + string(1, char(maxNumChannels+'0')) : "") << endl;
141  return AJA_STATUS_UNSUPPORTED;
142  }
143 
144  if (!mConfig.fAncDataFilePath.empty())
146  {
147  cerr << "## ERROR: Anc data file '" << mConfig.fAncDataFilePath << "' not found" << endl;
148  return AJA_STATUS_NOT_FOUND;
149  }
150 
151  if (!mConfig.fDoMultiFormat)
152  {
153  mDevice.GetTaskMode(mSavedTaskMode); // Save the current task mode
155  { cerr << "## ERROR: '" << mDevice.GetDescription() << "' is in use by another process" << endl;
156  return AJA_STATUS_BUSY; // Device is in use by another app -- fail
157  }
158  }
159  mDevice.SetTaskMode(NTV2_OEM_TASKS); // Set OEM service level
160 
161  if (mDevice.features().CanDoMultiFormat())
162  mDevice.SetMultiFormatMode(mConfig.fDoMultiFormat);
163  else
164  mConfig.fDoMultiFormat = false;
165 
166  // Set up the video and audio...
167  status = SetUpVideo();
168  if (AJA_FAILURE(status))
169  return status;
170  status = mConfig.WithAudio() ? SetUpAudio() : AJA_STATUS_SUCCESS;
171  if (AJA_FAILURE(status))
172  return status;
173 
174  // Set up the circular buffers, and the test pattern buffers...
175  status = SetUpHostBuffers();
176  if (AJA_FAILURE(status))
177  return status;
178  status = SetUpTestPatternBuffers();
179  if (AJA_FAILURE(status))
180  return status;
181 
182  // Set up the device signal routing...
183  RouteOutputSignal(); // (Ignore routing failures)
184 
185  // Lastly, prepare my AJATimeCodeBurn instance...
186  if (!mTCBurner.RenderTimeCodeFont (CNTV2DemoCommon::GetAJAPixelFormat(mConfig.fPixelFormat), mFormatDesc.numPixels, mFormatDesc.numLines))
187  {cerr << "## ERROR: RenderTimeCodeFont failed for: " << mFormatDesc << endl; return AJA_STATUS_UNSUPPORTED;}
188 
189  // Ready to go...
190  #if defined(_DEBUG)
191  cerr << mConfig
192  << "Device Description: " << mDevice.GetDescription() << endl
193  << endl;
194  #endif // defined(_DEBUG)
195  return AJA_STATUS_SUCCESS;
196 
197 } // Init
198 
199 
201 {
202  // Configure the device to output the requested video format...
203  if (mConfig.fVideoFormat == NTV2_FORMAT_UNKNOWN)
204  {cerr << "## ERROR: unknown video format" << endl; return AJA_STATUS_BAD_PARAM;}
205  if (!mDevice.features().CanDoVideoFormat(mConfig.fVideoFormat))
206  { cerr << "## ERROR: '" << mDevice.GetDescription() << "' doesn't support "
207  << ::NTV2VideoFormatToString(mConfig.fVideoFormat) << endl;
208  return AJA_STATUS_UNSUPPORTED;
209  }
210  if (!mDevice.features().CanDoFrameBufferFormat(mConfig.fPixelFormat))
211  { cerr << "## ERROR: '" << mDevice.GetDescription() << "' doesn't support "
212  << ::NTV2FrameBufferFormatString(mConfig.fPixelFormat) << endl;
213  return AJA_STATUS_UNSUPPORTED;
214  }
215 
216  // This demo doesn't playout dual-link RGB over SDI -- only YCbCr.
217  // Check that this device has a CSC to convert RGB to YUV...
218  if (::IsRGBFormat(mConfig.fPixelFormat) && UWord(mConfig.fOutputChannel) > mDevice.features().GetNumCSCs())
219  { cerr << "## ERROR: No CSC for channel " << DEC(mConfig.fOutputChannel+1) << " to convert RGB pixel format" << endl;
220  return AJA_STATUS_UNSUPPORTED;
221  }
222  if (!mDevice.features().CanDo3GLevelConversion() && mConfig.fDoABConversion && ::IsVideoFormatA(mConfig.fVideoFormat))
223  mConfig.fDoABConversion = false;
224  if (mConfig.fDoABConversion)
226 
227  // Keep the raster description handy...
228  mFormatDesc = NTV2FormatDescriptor(mConfig.fVideoFormat, mConfig.fPixelFormat);
229  if (!mFormatDesc.IsValid())
230  { cerr << "## ERROR: " << mDevice.GetDescription() << ": bad raster descriptor for " << ::NTV2VideoFormatToString(mConfig.fVideoFormat)
231  << " and " << ::NTV2FrameBufferFormatToString(mConfig.fPixelFormat) << endl;
232  return AJA_STATUS_FAIL;
233  }
234 
235  // If we own the whole device, make sure all FrameStores are disabled (good practice)
236  if (!mConfig.fDoMultiFormat)
237  {
238  NTV2ChannelSet enabledChannels;
239  mDevice.GetEnabledChannels(enabledChannels);
240  mDevice.DisableChannels(enabledChannels);
241  }
242 
243  // Turn on the FrameStore (to read frame buffer memory and transmit video)...
244  mDevice.EnableChannel(mConfig.fOutputChannel);
245 
246  // This demo assumes VANC is disabled...
247  mDevice.SetVANCMode(NTV2_VANCMODE_OFF, mConfig.fOutputChannel);
249 
250  // Set the FrameStore video format...
251  mDevice.SetVideoFormat (mConfig.fVideoFormat, false, false, mConfig.fOutputChannel);
252 
253  // Set the frame buffer pixel format for the device FrameStore...
254  mDevice.SetFrameBufferFormat (mConfig.fOutputChannel, mConfig.fPixelFormat);
255 
256  // The output interrupt is Enabled by default, but on some platforms, you must subscribe to it
257  // in order to be able to wait on its event/semaphore...
259 
260  // Get current per-field maximum Anc buffer size...
263 
264  // Set output clock reference...
266 
267  // At this point, video setup is complete (except for widget signal routing).
268  return AJA_STATUS_SUCCESS;
269 
270 } // SetUpVideo
271 
272 
274 {
275  uint16_t numAudioChannels (mDevice.features().GetMaxAudioChannels());
276  if (numAudioChannels > 8) // If audio system handles more than 8 channels...
277  if (!mDevice.features().CanDo2110()) // ...and SDI (i.e. not ST 2110 IP streaming)...
278  if (NTV2_IS_2K_1080_VIDEO_FORMAT(mConfig.fVideoFormat)) // ...and 2K (narrower HANC only fits 8 audio channels)
279  numAudioChannels = 8; // ...then reduce to 8 audio channels
280 
281  mAudioSystem = NTV2_AUDIOSYSTEM_1; // Use NTV2_AUDIOSYSTEM_1...
282  if (mDevice.features().GetNumAudioSystems() > 1) // ...but if the device has more than one audio system...
283  mAudioSystem = ::NTV2ChannelToAudioSystem(mConfig.fOutputChannel); // ...base it on the channel
284  // However, there are a few older devices that have only 1 audio system,
285  // yet 2 frame stores (or must use channel 2 for playout)...
286  if (!mDevice.features().CanDoFrameStore1Display())
287  mAudioSystem = NTV2_AUDIOSYSTEM_1;
288 
289  mDevice.SetNumberAudioChannels (numAudioChannels, mAudioSystem);
290  mDevice.SetAudioRate (NTV2_AUDIO_48K, mAudioSystem);
291 
292  // How big should the on-device audio buffer be? 1MB? 2MB? 4MB? 8MB?
293  // For this demo, 4MB will work best across all platforms (Windows, Mac & Linux)...
294  mDevice.SetAudioBufferSize (NTV2_AUDIO_BUFFER_BIG, mAudioSystem);
295 
296  // Set the SDI output audio embedders to embed audio samples from the output of mAudioSystem...
297  mDevice.SetSDIOutputAudioSystem (mConfig.fOutputChannel, mAudioSystem);
298  mDevice.SetSDIOutputDS2AudioSystem (mConfig.fOutputChannel, mAudioSystem);
299 
300  // If the last app using the device left it in E-E mode (input passthru), then loopback
301  // must be disabled --- otherwise the output audio will be pass-thru SDI input audio...
302  mDevice.SetAudioLoopBack (NTV2_AUDIO_LOOPBACK_OFF, mAudioSystem);
303 
304  if (!mConfig.fDoMultiFormat && mDevice.features().GetNumHDMIVideoOutputs())
305  {
309  }
310  return AJA_STATUS_SUCCESS;
311 
312 } // SetUpAudio
313 
314 
316 {
317  CNTV2DemoCommon::SetDefaultPageSize(); // Set host-specific page size
318 
319  // Let my circular buffer know when it's time to quit...
320  mFrameDataRing.SetAbortFlag (&mGlobalQuit);
321 
322  // Allocate and add each in-host NTV2FrameData to my circular buffer member variable...
323  mHostBuffers.reserve(CIRCULAR_BUFFER_SIZE);
324  while (mHostBuffers.size() < CIRCULAR_BUFFER_SIZE)
325  {
326  mHostBuffers.push_back(NTV2FrameData()); // Make a new NTV2FrameData...
327  NTV2FrameData & frameData(mHostBuffers.back()); // ...and get a reference to it
328 
329  // Allocate a page-aligned video buffer
330  if (mConfig.WithVideo())
331  if (!frameData.fVideoBuffer.Allocate (mFormatDesc.GetTotalBytes(), BUFFER_PAGE_ALIGNED))
332  {
333  PLFAIL("Failed to allocate " << xHEX0N(mFormatDesc.GetTotalBytes(),8) << "-byte video buffer");
334  return AJA_STATUS_MEMORY;
335  }
336  #ifdef NTV2_BUFFER_LOCKING
337  if (frameData.fVideoBuffer)
338  mDevice.DMABufferLock(frameData.fVideoBuffer, true);
339  #endif
340 
341  // Allocate a page-aligned audio buffer (if transmitting audio)
342  if (mConfig.WithAudio())
343  if (!frameData.fAudioBuffer.Allocate (gAudMaxSizeBytes, BUFFER_PAGE_ALIGNED))
344  {
345  PLFAIL("Failed to allocate " << xHEX0N(gAudMaxSizeBytes,8) << "-byte audio buffer");
346  return AJA_STATUS_MEMORY;
347  }
348  #ifdef NTV2_BUFFER_LOCKING
349  if (frameData.fAudioBuffer)
350  mDevice.DMABufferLock(frameData.fAudioBuffer, /*alsoPreLockSGL*/true);
351  #endif
352  mFrameDataRing.Add (&frameData);
353  } // for each NTV2FrameData
354 
355  return AJA_STATUS_SUCCESS;
356 
357 } // SetUpHostBuffers
358 
359 
361 {
362  vector<NTV2TestPatternSelect> testPatIDs;
363  testPatIDs.push_back(NTV2_TestPatt_ColorBars100);
364  testPatIDs.push_back(NTV2_TestPatt_ColorBars75);
365  testPatIDs.push_back(NTV2_TestPatt_Ramp);
366  testPatIDs.push_back(NTV2_TestPatt_MultiBurst);
367  testPatIDs.push_back(NTV2_TestPatt_LineSweep);
368  testPatIDs.push_back(NTV2_TestPatt_CheckField);
369  testPatIDs.push_back(NTV2_TestPatt_FlatField);
370  testPatIDs.push_back(NTV2_TestPatt_MultiPattern);
371 
372  mTestPatRasters.clear();
373  for (size_t tpNdx(0); tpNdx < testPatIDs.size(); tpNdx++)
374  mTestPatRasters.push_back(NTV2Buffer());
375 
376  NTV2_ASSERT(mFormatDesc.IsValid() && "Bad format descriptor"); // (Already checked in SetupVideo)
377  if (mFormatDesc.IsVANC())
378  {cerr << "## ERROR: VANC should have been disabled: " << mFormatDesc << endl; return AJA_STATUS_FAIL;}
379 
380  // Set up one video buffer for each test pattern...
381  for (size_t tpNdx(0); tpNdx < testPatIDs.size(); tpNdx++)
382  {
383  // Allocate the buffer memory...
384  if (!mTestPatRasters.at(tpNdx).Allocate (mFormatDesc.GetTotalBytes(), BUFFER_PAGE_ALIGNED))
385  { cerr << "## ERROR: Test pattern buffer " << DEC(tpNdx+1) << " of " << DEC(testPatIDs.size()) << ": "
386  << xHEX0N(mFormatDesc.GetTotalBytes(),8) << "-byte page-aligned alloc failed" << endl;
387  return AJA_STATUS_MEMORY;
388  }
389 
390  // Fill the buffer with test pattern...
391  NTV2TestPatternGen testPatternGen;
392  if (!testPatternGen.DrawTestPattern (testPatIDs.at(tpNdx), mFormatDesc, mTestPatRasters.at(tpNdx)))
393  {
394  cerr << "## ERROR: DrawTestPattern " << DEC(tpNdx) << " failed: " << mFormatDesc << endl;
395  return AJA_STATUS_FAIL;
396  }
397 
398  #ifdef NTV2_BUFFER_LOCKING
399  // Try to prelock the memory, including its scatter-gather list...
400  if (!mDevice.DMABufferLock(mTestPatRasters.at(tpNdx), /*alsoLockSegmentMap=*/true))
401  cerr << "## WARNING: Test pattern buffer " << DEC(tpNdx+1) << " of " << DEC(testPatIDs.size()) << " failed pre-lock" << endl;
402  #endif
403  } // loop for each predefined pattern
404 
405  return AJA_STATUS_SUCCESS;
406 
407 } // SetUpTestPatternBuffers
408 
409 
411 {
412  const NTV2Standard outputStandard (::GetNTV2StandardFromVideoFormat(mConfig.fVideoFormat));
413  const bool isRGB (::IsRGBFormat(mConfig.fPixelFormat));
414  const bool canVerify (mDevice.features().HasCrosspointConnectROM());
415  UWord connectFailures (0);
416 
417  // Since this function figures out which SDI spigots will be set up for output,
418  // it also sets the "mTCIndexes" member, which determines which timecodes will
419  // be transmitted (and on which SDI spigots)...
420  mTCIndexes.clear();
421 
422  const NTV2OutputXptID cscVidOutXpt(::GetCSCOutputXptFromChannel(mConfig.fOutputChannel, false/*isKey*/, !isRGB/*isRGB*/));
423  const NTV2OutputXptID fsVidOutXpt (::GetFrameStoreOutputXptFromChannel(mConfig.fOutputChannel, isRGB/*isRGB*/, false/*is425*/));
424  const NTV2InputXptID cscInputXpt (isRGB ? ::GetCSCInputXptFromChannel(mConfig.fOutputChannel, false/*isKeyInput*/) : NTV2_INPUT_CROSSPOINT_INVALID);
425  // This fixed the case with Kona1 two framestores but only one video out
426  const NTV2Channel sdiOutputChannel (GetRealVideoOutputChannel(mDevice, mConfig.fOutputChannel));
427 
428  if (!mConfig.fDoMultiFormat) // Not multiformat: We own the whole device...
429  mDevice.ClearRouting(); // Start with clean slate
430 
431  if (isRGB)
432  if (!mDevice.Connect (cscInputXpt, fsVidOutXpt, canVerify))
433  connectFailures++;
434 
435  if (mDevice.features().HasBiDirectionalSDI())
436  mDevice.SetSDITransmitEnable(sdiOutputChannel, true);
437 
438  if (!mDevice.Connect (::GetSDIOutputInputXpt (sdiOutputChannel, false/*isDS2*/), isRGB ? cscVidOutXpt : fsVidOutXpt, canVerify))
439  connectFailures++;
440 
441  mDevice.SetSDIOutputStandard (sdiOutputChannel, outputStandard);
442 
443  mTCIndexes.insert (::NTV2ChannelToTimecodeIndex(mConfig.fOutputChannel, /*inEmbeddedLTC=*/mConfig.fTransmitLTC));
444  // NOTE: No need to send VITC2 with VITC1 (for "i" formats) -- firmware does this automatically
445 
446  if (!mConfig.fDoMultiFormat) // Not multiformat: We own the whole device...
447  {
448  // Also connect analog video output, if the device has one...
449  if (mDevice.features().GetNumAnalogVideoOutputs() && mConfig.fOutputChannel == NTV2_CHANNEL1)
450  if (!mDevice.Connect (::GetOutputDestInputXpt(NTV2_OUTPUTDESTINATION_ANALOG1), isRGB ? cscVidOutXpt : fsVidOutXpt, canVerify))
451  connectFailures++;
452 
453  // Also connect HDMI video output, if the device has one...
454  if (mDevice.features().GetNumHDMIVideoOutputs() && mConfig.fOutputChannel == NTV2_CHANNEL1)
455  {
456  if (!mDevice.Connect (::GetOutputDestInputXpt(NTV2_OUTPUTDESTINATION_HDMI1), isRGB ? cscVidOutXpt : fsVidOutXpt, canVerify))
457  connectFailures++;
458  }
459  }
460  TCNOTE(mTCIndexes);
461  if (connectFailures)
462  PLWARN(DEC(connectFailures) << " 'Connect' call(s) failed");
463  return connectFailures == 0;
464 
465 } // RouteOutputSignal
466 
467 
469 {
470  // Start my consumer and producer threads...
473  return AJA_STATUS_SUCCESS;
474 
475 } // Run
476 
477 
478 
480 // This is where the play thread starts
481 
483 {
484  // Create and start the playout thread...
485  mConsumerThread.Attach (ConsumerThreadStatic, this);
486  mConsumerThread.SetPriority(AJA_ThreadPriority_High);
487  mConsumerThread.Start();
488 
489 } // StartConsumerThread
490 
491 
492 // The playout thread function
493 void NTV2Player::ConsumerThreadStatic (AJAThread * pThread, void * pContext) // static
494 { (void) pThread;
495  // Grab the NTV2Player instance pointer from the pContext parameter,
496  // then call its ConsumeFrames method...
497  NTV2Player * pApp (reinterpret_cast<NTV2Player*>(pContext));
498  if (pApp)
499  pApp->ConsumeFrames();
500 
501 } // ConsumerThreadStatic
502 
503 
504 static uint64_t sTotalAncFileBytes(0), sCurrentAncFileBytes(0);
505 
506 
508 {
509  ULWord acOptions (AUTOCIRCULATE_WITH_RP188);
510  AUTOCIRCULATE_TRANSFER outputXfer;
511  AUTOCIRCULATE_STATUS outputStatus;
512  ULWord goodXfers(0), badXfers(0), starves(0), noRoomWaits(0), startFrm(3);
513  ifstream * pAncStrm (AJA_NULL);
514 
515  // Stop AutoCirculate, just in case someone else left it running...
516  mDevice.AutoCirculateStop(mConfig.fOutputChannel);
517  mDevice.WaitForOutputVerticalInterrupt(mConfig.fOutputChannel, 4); // Let it stop
518  PLNOTE("Thread started");
519 
520  if (!mConfig.fAncDataFilePath.empty())
521  { // Open raw anc file for reading...
522  pAncStrm = new ifstream(mConfig.fAncDataFilePath.c_str(), ios::binary);
523  do
524  {
525  if (!pAncStrm->good())
526  { PLFAIL("Cannot open anc file '" << mConfig.fAncDataFilePath << "' -- anc insertion disabled");
527  delete pAncStrm; pAncStrm = AJA_NULL;
528  break;
529  }
530  pAncStrm->seekg(0, std::ios_base::end);
531  if (pAncStrm->tellg() == -1)
532  { PLFAIL("Cannot determine anc file size -- anc insertion disabled");
533  delete pAncStrm; pAncStrm = AJA_NULL;
534  break;
535  }
536  sTotalAncFileBytes = uint64_t(pAncStrm->tellg());
537  pAncStrm->seekg(0); // Rewind to start
539  { PLFAIL("anc buffer size " << DEC(gAncMaxSizeBytes*2) << " exceeds anc file size " << DEC(sTotalAncFileBytes)
540  << " -- anc insertion disabled");
541  delete pAncStrm; pAncStrm = AJA_NULL;
542  break;
543  }
544  // Allocate anc buffers...
545  bool ancOK = outputXfer.acANCBuffer.Allocate(gAncMaxSizeBytes, BUFFER_PAGE_ALIGNED);
548  if (!ancOK)
549  {
550  PLFAIL("Anc buffer " << xHEX0N(gAncMaxSizeBytes,8) << "(" << DEC(gAncMaxSizeBytes) << ")-byte"
551  " allocation failed -- anc insertion disabled");
552  outputXfer.acANCBuffer.Deallocate();
553  outputXfer.acANCField2Buffer.Deallocate();
554  delete pAncStrm;
555  pAncStrm = AJA_NULL;
556  break;
557  }
558  acOptions |= AUTOCIRCULATE_WITH_ANC;
559  break; // Good to go!
560  } while (false); // Once thru
561  }
562 #ifdef NTV2_BUFFER_LOCKING
563  if (outputXferInfo.acANCBuffer)
564  mDevice.DMABufferLock(outputXfer.acANCBuffer, /*alsoLockSGL*/true);
565  if (outputXferInfo.acANCField2Buffer)
566  mDevice.DMABufferLock(outputXfer.acANCField2Buffer, /*alsoLockSGL*/true);
567 #endif
568 
569  // Initialize & start AutoCirculate...
570  bool initOK = mDevice.AutoCirculateInitForOutput (mConfig.fOutputChannel, mConfig.fFrames, mAudioSystem, acOptions);
571  if (!initOK)
572  {PLFAIL("AutoCirculateInitForOutput failed"); mGlobalQuit = true;}
573  else if (!mConfig.WithVideo())
574  { // Video suppressed --
575  // Clear device frame buffers being AutoCirculated (prevent garbage output frames)
576  NTV2Buffer tmpFrame (mFormatDesc.GetTotalBytes());
577  NTV2TestPatternGen blackPatternGen;
578  if (tmpFrame
579  && blackPatternGen.DrawTestPattern (NTV2_TestPatt_Black, mFormatDesc, tmpFrame)
580  && mDevice.AutoCirculateGetStatus (mConfig.fOutputChannel, outputStatus))
581  for (uint16_t frmNum(outputStatus.GetStartFrame()); frmNum <= outputStatus.GetEndFrame(); frmNum++)
582  mDevice.DMAWriteFrame(ULWord(frmNum), tmpFrame, mFormatDesc.GetTotalBytes());
583  } // else if --novideo
584  if (initOK && mDevice.AutoCirculateGetStatus (mConfig.fOutputChannel, outputStatus))
585  { startFrm = outputStatus.GetFrameCount() - 1;
586  if (startFrm > 3)
587  startFrm = 3;
588  }
589 
590  while (!mGlobalQuit)
591  {
592  mDevice.AutoCirculateGetStatus (mConfig.fOutputChannel, outputStatus);
593 
594  // Check if there's room for another frame on the card...
595  if (outputStatus.CanAcceptMoreOutputFrames())
596  {
597  // Device has at least one free frame buffer that can be filled.
598  // Wait for the next frame in our ring to become ready to "consume"...
599  NTV2FrameData * pFrameData (mFrameDataRing.StartConsumeNextBuffer());
600  if (!pFrameData)
601  {starves++; continue;}
602 
603  outputXfer.SetOutputTimeCodes(pFrameData->fTimecodes);
604 
605  if (pFrameData->VideoBuffer()) // Transfer the timecode-burned frame to the device for playout...
606  outputXfer.SetVideoBuffer (pFrameData->VideoBuffer(), pFrameData->VideoBufferSize());
607  if (pFrameData->AudioBuffer()) // If also playing audio...
608  outputXfer.SetAudioBuffer (pFrameData->AudioBuffer(), pFrameData->fNumAudioBytes);
609 
610  if (pAncStrm && pAncStrm->good() && outputXfer.acANCBuffer)
611  { // Read pre-recorded anc from binary data file, and inject it into this frame...
612  pAncStrm->read(outputXfer.acANCBuffer, streamsize(outputXfer.acANCBuffer.GetByteCount()));
613  sCurrentAncFileBytes += pAncStrm->good() ? outputXfer.acANCBuffer.GetByteCount() : 0;
614  if (pAncStrm->good() && outputXfer.acANCField2Buffer)
615  {
616  pAncStrm->read(outputXfer.acANCField2Buffer, streamsize(outputXfer.acANCField2Buffer.GetByteCount()));
617  sCurrentAncFileBytes += pAncStrm->good() ? outputXfer.acANCField2Buffer.GetByteCount() : 0;
618  }
619  if (pAncStrm->eof())
620  { pAncStrm->clear();
621  pAncStrm->seekg(0); // Rewind upon EOF
623  PLDBG("Anc file rewound: " << DEC(goodXfers) << " goodXfers, " << DEC(badXfers) << " badXfers");
624  }
625  } // if playing anc from binary data file
626 
627  // Perform the DMA transfer to the device...
628  if (mDevice.AutoCirculateTransfer (mConfig.fOutputChannel, outputXfer))
629  { if (++goodXfers == startFrm)
630  mDevice.AutoCirculateStart(mConfig.fOutputChannel);
631  }
632  else
633  badXfers++;
634 
635  // Signal that the frame has been "consumed"...
636  mFrameDataRing.EndConsumeNextBuffer();
637  continue; // Back to top of while loop
638  } // if CanAcceptMoreOutputFrames
639 
640  // Wait for one or more buffers to become available on the device, which should occur at next VBI...
641  noRoomWaits++;
643  } // loop til quit signaled
644 
645  // Stop AutoCirculate...
646  mDevice.AutoCirculateStop(mConfig.fOutputChannel);
647  mDevice.AutoCirculateFlush(mConfig.fOutputChannel);
648  PLNOTE("Thread completed: " << DEC(goodXfers) << " xfers, " << DEC(badXfers) << " failed, "
649  << DEC(starves) << " starves, " << DEC(noRoomWaits) << " VBI waits");
650  if (pAncStrm)
651  delete pAncStrm;
652 
653 } // ConsumeFrames
654 
655 
656 
658 // This is where the producer thread starts
659 
661 {
662  // Create and start the producer thread...
663  mProducerThread.Attach(ProducerThreadStatic, this);
664  mProducerThread.SetPriority(AJA_ThreadPriority_High);
665  mProducerThread.Start();
666 
667 } // StartProducerThread
668 
669 
670 void NTV2Player::ProducerThreadStatic (AJAThread * pThread, void * pContext) // static
671 { (void) pThread;
672  NTV2Player * pApp (reinterpret_cast<NTV2Player*>(pContext));
673  if (pApp)
674  pApp->ProduceFrames();
675 
676 } // ProducerThreadStatic
677 
678 
680 {
681  ULWord freqNdx(0), testPatNdx(0), badTally(0);
682  double timeOfLastSwitch (0.0);
683 
686  const bool isInterlace (!NTV2_VIDEO_FORMAT_HAS_PROGRESSIVE_PICTURE(mConfig.fVideoFormat));
687  const bool isPAL (NTV2_IS_PAL_VIDEO_FORMAT(mConfig.fVideoFormat));
688  const NTV2FrameRate ntv2FrameRate (::GetNTV2FrameRateFromVideoFormat(mConfig.fVideoFormat));
689  const TimecodeFormat tcFormat (CNTV2DemoCommon::NTV2FrameRate2TimecodeFormat(ntv2FrameRate));
690 
691  PLNOTE("Thread started");
692  while (!mGlobalQuit)
693  {
694  NTV2FrameData * pFrameData (mFrameDataRing.StartProduceNextBuffer());
695  if (!pFrameData)
696  { badTally++; // No frame available!
697  AJATime::Sleep(10); // Wait a bit for the consumer thread to free one up for me...
698  continue; // ...then try again
699  }
700 
701  if (pFrameData->VideoBuffer()) // Copy fresh, unmodified, pre-rendered test pattern into this frame's video buffer...
702  pFrameData->fVideoBuffer.CopyFrom (mTestPatRasters.at(testPatNdx),
703  /*srcOffset*/ 0,
704  /*dstOffset*/ 0,
705  /*byteCount*/ ULWord(pFrameData->fVideoBuffer.GetByteCount()));
706 
707  const CRP188 rp188Info (mCurrentFrame++, 0, 0, 10, tcFormat);
708  NTV2_RP188 tcF1, tcF2;
709  string tcString;
710 
711  rp188Info.GetRP188Reg(tcF1);
712  rp188Info.GetRP188Str(tcString);
713 
714  // Include timecode in output signal...
715  tcF2 = tcF1;
716  if (isInterlace)
717  { // Set bit 27 of Hi word (PAL) or Lo word (NTSC)
718  if (isPAL) tcF2.fHi |= BIT(27); else tcF2.fLo |= BIT(27);
719  }
720 
721  // Add timecodes for each SDI output...
722  for (NTV2TCIndexesConstIter it(mTCIndexes.begin()); it != mTCIndexes.end(); ++it)
723  pFrameData->fTimecodes[*it] = NTV2_IS_ATC_VITC2_TIMECODE_INDEX(*it) ? tcF2 : tcF1;
724 
725  if (pFrameData->VideoBuffer()) // Burn current timecode into the video buffer...
726  mTCBurner.BurnTimeCode (pFrameData->VideoBuffer(), tcString.c_str(), 80);
727  TCDBG("F" << DEC0N(mCurrentFrame-1,6) << ": " << tcF1 << ": " << tcString);
728 
729  // If also playing audio...
730  if (pFrameData->AudioBuffer()) // ...then generate audio tone data for this frame...
731  pFrameData->fNumAudioBytes = AddTone(*pFrameData); // ...and remember number of audio bytes to xfer
732 
733  // Every few seconds, change the test pattern and tone frequency...
734  const double currentTime (timeBase.FramesToSeconds(mCurrentFrame));
735  if (currentTime > timeOfLastSwitch + 4.0)
736  {
737  freqNdx = (freqNdx + 1) % gNumFrequencies;
738  testPatNdx = (testPatNdx + 1) % ULWord(mTestPatRasters.size());
739  mToneFrequency = gFrequencies[freqNdx];
740  timeOfLastSwitch = currentTime;
741  if (sTotalAncFileBytes)
742  PLDBG("F" << DEC0N(mCurrentFrame,6) << ": " << tcString << ": tone=" << mToneFrequency << "Hz, pattern='"
743  << tpNames.at(testPatNdx) << "', anc file " << DEC(sCurrentAncFileBytes * 100ULL / sTotalAncFileBytes) << "%");
744  else
745  PLDBG("F" << DEC0N(mCurrentFrame,6) << ": " << tcString << ": tone=" << mToneFrequency << "Hz, pattern='"
746  << tpNames.at(testPatNdx) << "'");
747  } // if time to switch test pattern & tone frequency
748 
749  // Signal that I'm done producing this FrameData, making it immediately available for transfer/playout...
750  mFrameDataRing.EndProduceNextBuffer();
751 
752  } // loop til mGlobalQuit goes true
753  PLNOTE("Thread completed: " << DEC(mCurrentFrame) << " frame(s) produced, " << DEC(badTally) << " failed");
754 
755 } // ProduceFrames
756 
757 
758 uint32_t NTV2Player::AddTone (NTV2FrameData & inFrameData)
759 {
762  ULWord numChannels (0);
763 
764  mDevice.GetFrameRate (frameRate, mConfig.fOutputChannel);
765  mDevice.GetAudioRate (audioRate, mAudioSystem);
766  mDevice.GetNumberAudioChannels (numChannels, mAudioSystem);
767 
768  // Set per-channel tone frequencies...
769  double pFrequencies [kNumAudioChannelsMax];
770  pFrequencies[0] = (mToneFrequency / 2.0);
771  for (ULWord chan(1); chan < numChannels; chan++)
772  // The 1.154782 value is the 16th root of 10, to ensure that if mToneFrequency is 2000,
773  // that the calculated frequency of audio channel 16 will be 20kHz...
774  pFrequencies[chan] = pFrequencies[chan-1] * 1.154782;
775 
776  // Since audio on AJA devices use fixed sample rates (typically 48KHz), certain video frame rates will
777  // necessarily result in some frames having more audio samples than others. GetAudioSamplesPerFrame is
778  // called to calculate the correct sample count for the current frame...
779  const ULWord numSamples (::GetAudioSamplesPerFrame (frameRate, audioRate, mCurrentFrame));
780  const double sampleRateHertz (::GetAudioSamplesPerSecond(audioRate));
781 
782  return ::AddAudioTone ( inFrameData.AudioBuffer(), // audio buffer to fill
783  mCurrentSample, // which sample for continuing the waveform
784  numSamples, // number of samples to generate
785  sampleRateHertz, // sample rate [Hz]
786  gAmplitudes, // per-channel amplitudes
787  pFrequencies, // per-channel tone frequencies [Hz]
788  31, // bits per sample
789  false, // don't byte-swap
790  numChannels); // number of audio channels to generate
791 } // AddTone
792 
793 
795 {
796  mDevice.AutoCirculateGetStatus (mConfig.fOutputChannel, outStatus);
797 }
virtual bool AutoCirculateFlush(const NTV2Channel inChannel, const bool inClearDropCount=(0))
Flushes AutoCirculate for the given channel.
bool SetOutputTimeCodes(const NTV2TimeCodes &inValues)
Intended for playout, replaces the contents of my acOutputTimeCodes member.
NTV2FrameRate GetNTV2FrameRateFromVideoFormat(const NTV2VideoFormat inVideoFormat)
Definition: ntv2utils.cpp:3630
virtual void StartProducerThread(void)
Starts my producer thread.
Definition: ntv2player.cpp:660
double FramesToSeconds(int64_t frames) const
Definition: timebase.cpp:205
virtual bool SetTaskMode(const NTV2TaskMode inMode)
Sets the device&#39;s task mode.
#define NTV2_IS_VALID_TASK_MODE(__m__)
static const uint32_t gAudMaxSizeBytes(256 *1024)
The maximum number of bytes of 48KHz audio that can be transferred for a single frame. Worst case, assuming 16 channels of audio (max), 4 bytes per sample, and 67 msec per frame (assuming the lowest possible frame rate of 14.98 fps)... 48,000 samples per second requires 3,204 samples x 4 bytes/sample x 16 = 205,056 bytes 201K min will suffice, with 768 bytes to spare But it could be more efficient for page-aligned (and page-locked) memory to round to 256K.
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...
virtual bool SetAudioLoopBack(const NTV2AudioLoopBack inMode, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Enables or disables NTV2AudioLoopBack mode for the given NTV2AudioSystem.
Definition: ntv2audio.cpp:301
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...
virtual AJAStatus SetUpTestPatternBuffers(void)
Creates my test pattern buffers.
Definition: ntv2player.cpp:360
AJAStatus Add(FrameDataPtr pInFrameData)
Appends a new frame buffer to me, increasing my frame storage capacity by one frame.
The NTV2 test pattern generator.
#define DEC0N(__x__, __n__)
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
#define BIT(_x_)
Definition: ajatypes.h:496
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
virtual bool IsDeviceReady(const bool inCheckValid=(0))
static uint64_t GetPid()
Definition: process.cpp:35
#define AJA_FAILURE(_status_)
Definition: types.h:373
Declares the NTV2TestPatternGen class.
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
#define NTV2_VIDEO_FORMAT_HAS_PROGRESSIVE_PICTURE(__f__)
Definition: ntv2enums.h:1053
virtual bool GetAudioRate(NTV2AudioRate &outRate, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Returns the current NTV2AudioRate for the given Audio System.
Definition: ntv2audio.cpp:227
ULWord GetByteCount(void) const
virtual bool DMAWriteFrame(const ULWord inFrameNumber, const ULWord *pInFrameBuffer, const ULWord inByteCount)
Transfers a single frame from the host to the AJA device.
Definition: ntv2dma.cpp:65
virtual AJAStatus SetPriority(AJAThreadPriority priority)
Definition: thread.cpp:133
FrameDataPtr StartConsumeNextBuffer(void)
The thread that&#39;s responsible for processing incoming frames – the consumer – calls this function t...
if(!(riid==IID_IUnknown) &&!(riid==IID_IClassFactory))
Definition: dllentry.cpp:196
ULWord GetTotalBytes(void) const
bool CanAcceptMoreOutputFrames(void) const
#define NTV2_IS_2K_1080_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:767
bool fDoABConversion
If true, do level-A/B conversion; otherwise don&#39;t.
Definition: json.hpp:5362
virtual bool SetAudioRate(const NTV2AudioRate inRate, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Sets the NTV2AudioRate for the given Audio System.
Definition: ntv2audio.cpp:206
virtual AJAStatus Start()
Definition: thread.cpp:91
void EndConsumeNextBuffer(void)
The consumer thread calls this function to signal that it has finished processing the frame it obtain...
Declares common audio macros and structs used in the SDK.
std::string fDeviceSpec
The AJA device to use.
#define false
static NTV2Channel GetRealVideoOutputChannel(CNTV2Card &inDevice, NTV2Channel inRequestedChannel)
Definition: ntv2player.cpp:48
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.
static void ProducerThreadStatic(AJAThread *pThread, void *pContext)
This is the producer thread&#39;s static callback function that gets called when the producer thread star...
Definition: ntv2player.cpp:670
virtual bool GetEnabledChannels(NTV2ChannelSet &outChannels)
Answers with the set of channels that are currently enabled.
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.
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1361
virtual class DeviceCapabilities & features(void)
Definition: ntv2card.h:148
virtual bool GetAncRegionOffsetFromBottom(ULWord &outByteOffsetFromBottom, const NTV2AncillaryDataRegion inAncRegion=NTV2_AncRgn_All)
Answers with the byte offset to the start of an ancillary data region within a device frame buffer...
Definition: ntv2dma.cpp:601
virtual bool SetMultiFormatMode(const bool inEnable)
Enables or disables multi-format (per channel) device operation. If enabled, each device channel can ...
#define NTV2_ASSERT(_expr_)
Definition: ajatypes.h:489
virtual bool ClearRouting(void)
Removes all existing signal path connections between any and all widgets on the AJA device...
Declares the AJATimeBase class.
This struct replaces the old RP188_STRUCT.
static const double gFrequencies[]
Definition: ntv2player.cpp:58
NTV2TCIndex NTV2ChannelToTimecodeIndex(const NTV2Channel inChannel, const bool inEmbeddedLTC=false, const bool inIsF2=false)
Converts the given NTV2Channel value into the equivalent NTV2TCIndex value.
Definition: ntv2utils.cpp:4966
ULWord numPixels
Width – total number of pixels per line.
virtual bool Active()
Definition: thread.cpp:116
virtual bool GetTaskMode(NTV2TaskMode &outMode)
Retrieves the device&#39;s current task mode.
bool WithAudio(void) const
virtual bool SetHDMIOutAudioRate(const NTV2AudioRate inNewValue, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Sets the HDMI output&#39;s audio rate.
Definition: ntv2audio.cpp:1010
bool Deallocate(void)
Deallocates my user-space storage (if I own it – i.e. from a prior call to Allocate).
static AJA_PixelFormat GetAJAPixelFormat(const NTV2PixelFormat inFormat)
This selects audio channels 1 thru 8.
Definition: ntv2enums.h:3327
NTV2FrameRate
Identifies a particular video frame rate.
Definition: ntv2enums.h:416
bool fTransmitLTC
If true, embed LTC; otherwise embed VITC.
virtual bool DrawTestPattern(const std::string &inTPName, const NTV2FormatDescriptor &inFormatDesc, NTV2Buffer &inBuffer)
Renders the given test pattern or color into a host raster buffer.
NTV2Standard
Identifies a particular video standard.
Definition: ntv2enums.h:169
#define TCDBG(_expr_)
Definition: ntv2player.cpp:27
virtual std::string GetDescription(void) const
Definition: ntv2card.cpp:139
static TimecodeFormat NTV2FrameRate2TimecodeFormat(const NTV2FrameRate inFrameRate)
static const ULWord gNumFrequencies(sizeof(gFrequencies)/sizeof(double))
#define NTV2_IS_PAL_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:737
NTV2InputXptID GetOutputDestInputXpt(const NTV2OutputDestination inOutputDest, const bool inIsSDI_DS2=false, const UWord inHDMI_Quadrant=99)
virtual bool IsOpen(void) const
#define NTV2_IS_ATC_VITC2_TIMECODE_INDEX(__x__)
Definition: ntv2enums.h:3997
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 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
Declares the AJAFileIO class.
#define AJA_NULL
Definition: ajatypes.h:180
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...
NTV2InputXptID GetCSCInputXptFromChannel(const NTV2Channel inCSC, const bool inIsKeyInput=false)
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
NTV2PixelFormat fPixelFormat
The pixel format to use.
virtual void ProduceFrames(void)
My producer thread that repeatedly produces video frames.
Definition: ntv2player.cpp:679
2: OEM (recommended): device configured by client application(s) with some driver involvement...
static const double gAmplitudes[]
Definition: ntv2player.cpp:60
virtual bool SetSDIOutputAudioSystem(const NTV2Channel inSDIOutputConnector, const NTV2AudioSystem inAudioSystem)
Sets the device&#39;s NTV2AudioSystem that will provide audio for the given SDI output&#39;s audio embedder...
virtual uint32_t AddTone(NTV2FrameData &inFrameData)
Inserts audio tone (based on my current tone frequency) into the given NTV2FrameData&#39;s audio buffer...
Definition: ntv2player.cpp:758
virtual AJAStatus SetUpAudio(void)
Performs all audio setup.
Definition: ntv2player.cpp:273
#define PLNOTE(_xpr_)
NTV2VideoFormat fVideoFormat
The video format to use.
std::string NTV2VideoFormatToString(const NTV2VideoFormat inValue, const bool inUseFrameRate=false)
Definition: ntv2utils.cpp:6750
Embeds silence (zeroes) into the data stream.
Definition: ntv2enums.h:2035
virtual bool SetVANCShiftMode(NTV2Channel inChannel, NTV2VANCDataShiftMode inMode)
Enables or disables the "VANC Shift Mode" feature for the given channel.
static ULWord gAncMaxSizeBytes(NTV2_ANCSIZE_MAX)
The maximum number of bytes of ancillary data that can be transferred for a single field...
AJA_EXPORT bool RenderTimeCodeFont(AJA_PixelFormat pixelFormat, uint32_t numPixels, uint32_t numLines)
virtual bool DMABufferUnlockAll()
Unlocks all previously-locked buffers used for DMA transfers.
Definition: ntv2dma.cpp:457
Specifies the PTP source on SFP 1.
Definition: ntv2enums.h:1473
bool IsVideoFormatA(const NTV2VideoFormat format)
Definition: ntv2utils.cpp:5462
#define AUTOCIRCULATE_WITH_ANC
Use this to AutoCirculate with ancillary data.
Specifies channel or FrameStore 2 (or the 2nd item).
Definition: ntv2enums.h:1364
virtual AJAStatus SetUpVideo(void)
Performs all video setup.
Definition: ntv2player.cpp:200
virtual void ConsumeFrames(void)
My consumer thread that repeatedly plays frames using AutoCirculate (until quit). ...
Definition: ntv2player.cpp:507
Declares the CNTV2DeviceScanner class.
NTV2Player(const PlayerConfig &inConfig)
Constructs me using the given configuration settings.
Definition: ntv2player.cpp:64
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...
bool AddAudioTone(ULWord &outNumBytesWritten, NTV2Buffer &inAudioBuffer, ULWord &inOutCurrentSample, const ULWord inNumSamples, const double inSampleRate, const double inAmplitude, const double inFrequency, const ULWord inNumBits, const bool inByteSwap, const ULWord inNumChannels)
Fills the given buffer with 32-bit (ULWord) audio tone samples.
Definition: ntv2utils.cpp:4413
#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.).
#define PLFAIL(_xpr_)
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
virtual bool Connect(const NTV2InputCrosspointID inInputXpt, const NTV2OutputCrosspointID inOutputXpt, const bool inValidate=(0))
Connects the given widget signal input (sink) to the given widget signal output (source).
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
static NTV2TestPatternNames getTestPatternNames(void)
uint16_t GetEndFrame(void) const
NTV2Buffer & AudioBuffer(void)
bool IsRGBFormat(const NTV2FrameBufferFormat format)
Definition: ntv2utils.cpp:5414
virtual AJAStatus SetUpHostBuffers(void)
Sets up my host video & audio buffers.
Definition: ntv2player.cpp:315
This object specifies the information that will be transferred to or from the AJA device in the CNTV2...
static const bool BUFFER_PAGE_ALIGNED((!(0)))
virtual bool SetAudioBufferSize(const NTV2AudioBufferSize inValue, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Changes the size of the audio buffer that is used for a given Audio System in the AJA device...
Definition: ntv2audio.cpp:250
virtual bool GetNumberAudioChannels(ULWord &outNumChannels, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Returns the current number of audio channels being captured or played by a given Audio System on the ...
Definition: ntv2audio.cpp:181
I play out SD or HD test pattern (with timecode) to an output of an AJA device with or without audio ...
Definition: ntv2player.h:24
virtual ~NTV2Player(void)
Definition: ntv2player.cpp:85
#define DEC(__x__)
NTV2Buffer acANCField2Buffer
The host "Field 2" ancillary data buffer. This field is owned by the client application, and thus is responsible for allocating and/or freeing it. If the pointer is NULL or the size is zero, no "Field 2" ancillary data will be transferred. Use the AUTOCIRCULATE_TRANSFER::SetAncBuffers method to set or reset this field.
std::set< NTV2Channel > NTV2ChannelSet
A set of distinct NTV2Channel values.
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 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 TCNOTE(_expr_)
Definition: ntv2player.cpp:25
NTV2Channel fOutputChannel
The device channel to use.
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))
ULWord numLines
Height – total number of lines.
virtual bool DisableChannels(const NTV2ChannelSet &inChannels)
Disables the given FrameStore(s).
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...
double GetAudioSamplesPerSecond(const NTV2AudioRate inAudioRate)
Returns the audio sample rate as a number of audio samples per second.
Definition: ntv2utils.cpp:3303
Identifies the "normal" Field 2 ancillary data region.
Definition: ntv2enums.h:4236
mFormatDesc
Definition: ntv2vcam.cpp:942
virtual bool SetSDIOutLevelAtoLevelBConversion(const UWord inOutputSpigot, const bool inEnable)
Enables or disables 3G level A to 3G level B conversion at the SDI output widget (assuming the AJA de...
virtual bool SetHDMIOutAudioSource8Channel(const NTV2Audio8ChannelSelect inNewValue, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Changes the HDMI output&#39;s 8-channel audio source.
Definition: ntv2audio.cpp:936
ULWord GetFrameCount(void) const
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
NTV2OutputXptID GetFrameStoreOutputXptFromChannel(const NTV2Channel inFrameStore, const bool inIsRGB=false, const bool inIs425=false)
virtual bool SetHDMIOutAudioFormat(const NTV2AudioFormat inNewValue, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Sets the HDMI output&#39;s audio format.
Definition: ntv2audio.cpp:1032
uint16_t UWord
Definition: ajatypes.h:234
ULWord GetAudioSamplesPerFrame(const NTV2FrameRate inFrameRate, const NTV2AudioRate inAudioRate, ULWord inCadenceFrame=0, bool inIsSMPTE372Enabled=false)
Returns the number of audio samples for a given video frame rate, audio sample rate, and frame number. This is useful since AJA devices use fixed audio sample rates (typically 48KHz), and some video frame rates will necessarily result in some frames having more audio samples than others.
Definition: ntv2utils.cpp:2889
Specifies channel or FrameStore 1 (or the first item).
Definition: ntv2enums.h:1363
static bool FileExists(const std::wstring &fileName)
Definition: file_io.cpp:97
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)
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2player.cpp:468
virtual void Quit(void)
Gracefully stops me from running.
Definition: ntv2player.cpp:94
virtual bool AutoCirculateInitForOutput(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 playback streaming, designating a contiguous block of frame buf...
#define xHEX0N(__x__, __n__)
UWord GetNumAnalogVideoOutputs(void)
TimecodeFormat
Definition: ntv2rp188.h:22
virtual bool GetFrameRate(NTV2FrameRate &outValue, NTV2Channel inChannel=NTV2_CHANNEL1)
Returns the AJA device&#39;s currently configured frame rate via its "value" parameter.
std::string NTV2FrameBufferFormatToString(const NTV2FrameBufferFormat inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:6940
static AJA_FrameRate GetAJAFrameRate(const NTV2FrameRate inFrameRate)
static uint64_t sTotalAncFileBytes(0)
AJA_EXPORT bool BurnTimeCode(void *pBaseVideoAddress, const std::string &inTimeCodeStr, const uint32_t inYPercent)
I encapsulate the video, audio and anc host buffers used in the AutoCirculate demos. I&#39;m a more modern version of the AVDataBuffer.
NTV2AudioSystem NTV2ChannelToAudioSystem(const NTV2Channel inChannel)
Converts the given NTV2Channel value into its equivalent NTV2AudioSystem.
Definition: ntv2utils.cpp:4873
enum NTV2InputCrosspointID NTV2InputXptID
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
NTV2Standard GetNTV2StandardFromVideoFormat(const NTV2VideoFormat inVideoFormat)
Definition: ntv2utils.cpp:2375
virtual bool SetSDIOutputDS2AudioSystem(const NTV2Channel inSDIOutputConnector, const NTV2AudioSystem inAudioSystem)
Sets the Audio System that will supply audio for the given SDI output&#39;s audio embedder for Data Strea...
Configures an NTV2Player instance.
bool GetRP188Reg(RP188_STRUCT &outRP188) const
Definition: ntv2rp188.cpp:1241
NTV2AudioRate
Definition: ntv2enums.h:1933
ULWord fLo
| BG 4 | Secs10 | BG 3 | Secs 1 | BG 2 | Frms10 | BG 1 | Frms 1 |
virtual bool RouteOutputSignal(void)
Performs all widget/signal routing for playout.
Definition: ntv2player.cpp:410
static uint64_t sCurrentAncFileBytes(0)
static size_t SetDefaultPageSize(void)
#define PLWARN(_xpr_)
NTV2TCIndexes::const_iterator NTV2TCIndexesConstIter
std::vector< std::string > NTV2StringList
bool CanDoVideoFormat(const NTV2VideoFormat inVF)
#define AUTOCIRCULATE_WITH_RP188
Use this to AutoCirculate with RP188.
virtual void StartConsumerThread(void)
Starts my consumer thread.
Definition: ntv2player.cpp:482
const char * NTV2FrameBufferFormatString(NTV2FrameBufferFormat fmt)
Definition: ntv2debug.cpp:220
bool GetRP188Str(std::string &sRP188) const
Definition: ntv2rp188.cpp:918
std::string & lower(std::string &str)
Definition: common.cpp:436
bool WithVideo(void) const
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outStatus)
Provides status information about my output (playout) process.
Definition: ntv2player.cpp:794
bool SetAudioBuffer(ULWord *pInAudioBuffer, const ULWord inAudioByteCount)
Sets my audio buffer for use in a subsequent call to CNTV2Card::AutoCirculateTransfer.
virtual bool SetSDIOutputStandard(const UWord inOutputSpigot, const NTV2Standard inValue)
Sets the SDI output spigot&#39;s video standard.
NTV2Buffer acANCBuffer
The host ancillary data buffer. This field is owned by the client application, and thus is responsibl...
#define PLDBG(_xpr_)
NTV2InputXptID GetSDIOutputInputXpt(const NTV2Channel inSDIOutput, const bool inIsDS2=false)
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2player.cpp:117
virtual bool SetVANCMode(const NTV2VANCMode inVancMode, const NTV2Channel inChannel=NTV2_CHANNEL1)
Sets the VANC mode for the given FrameStore.
static void ConsumerThreadStatic(AJAThread *pThread, void *pContext)
This is the consumer thread&#39;s static callback function that gets called when the consumer thread star...
Definition: ntv2player.cpp:493
virtual bool SetNumberAudioChannels(const ULWord inNumChannels, const NTV2AudioSystem inAudioSystem=NTV2_AUDIOSYSTEM_1)
Sets the number of audio channels to be concurrently captured or played for a given Audio System on t...
Definition: ntv2audio.cpp:147
ULWord fHi
| BG 8 | Hrs 10 | BG 7 | Hrs 1 | BG 6 | Mins10 | BG 5 | Mins 1 |
enum NTV2OutputCrosspointID NTV2OutputXptID
uint16_t GetStartFrame(void) const
NTV2OutputXptID GetCSCOutputXptFromChannel(const NTV2Channel inCSC, const bool inIsKey=false, const bool inIsRGB=false)
#define NTV2_ANCSIZE_MAX
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.
std::string fAncDataFilePath
Optional path to Anc binary data file to playout.
virtual bool EnableChannel(const NTV2Channel inChannel)
Enables the given FrameStore.