AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 // Includes
10 #include "ntv2capture4k.h"
11 #include <signal.h>
12 
13 using namespace std;
14 
15 
16 // Globals
17 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
18 
19 
20 static void SignalHandler (int inSignal)
21 {
22  (void) inSignal;
23  gGlobalQuit = true;
24 }
25 
26 
27 int main (int argc, const char ** argv)
28 {
29  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
30  char * pPixelFormat (AJA_NULL); // Pixel format argument
31  int channelNumber (1); // Channel/FrameStore to use
32  int doMultiFormat (0); // MultiFormat mode?
33  int showVersion (0); // Show version?
34  int doQuadRouting (0); // Quad/Square routing (i.e. not TSI)?
35  int numAudioLinks (1); // Number of audio systems for multi-link audio
37 
38  // Command line option descriptions:
39  const CNTV2DemoCommon::PoptOpts optionsTable [] =
40  {
41  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
42  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
43  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
44  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
45  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
46  {"squares", 's', POPT_ARG_NONE, &doQuadRouting, 0, "use quad routing?", AJA_NULL },
47  {"audioLinks", 0, POPT_ARG_INT, &numAudioLinks, 0, "# multilink aud systems", "0=silence or 1-4" },
50  };
51  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
52  if (!popt)
53  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
54  if (showVersion)
55  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
56 
57  // Device
58  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
59  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
60  return 1;
61 
62  CaptureConfig config(deviceSpec);
63 
64  // Channel
65  if ((channelNumber < 1) || (channelNumber > 8))
66  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
67  config.fInputChannel = NTV2Channel(channelNumber - 1);
68 
69  // Pixel Format
70  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
71  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
72  if (pixelFormatStr == "?" || pixelFormatStr == "list")
73  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
74  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
75  {
76  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
78  return 2;
79  }
80 
81  // Audio
82  if (numAudioLinks < 0)
83  {cerr << "## ERROR: invalid '--audioLinks' value '" << numAudioLinks << "' -- negative" << endl; return 1;}
84  if (numAudioLinks > 4)
85  {cerr << "## ERROR: invalid '--audioLinks' value '" << numAudioLinks << "' -- exceeds 4" << endl; return 1;}
86  if (numAudioLinks != 1)
87  config.fNumAudioLinks = UWord(numAudioLinks);
88 
89  config.fWithAudio = config.fNumAudioLinks ? true : false; // Enable audio if numLinks > 0, disable if zero
90  config.fDoTSIRouting = !doQuadRouting; // TSI?
91  config.fWithAnc = true; // Always capture anc
92  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
93 
94  // Instantiate and initialize the NTV2Capture4K object...
95  NTV2Capture4K capturer(config);
96  AJAStatus status = capturer.Init();
97  if (AJA_FAILURE(status))
98  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
99 
100  ::signal (SIGINT, SignalHandler);
101  #if defined(AJAMac)
102  ::signal (SIGHUP, SignalHandler);
103  ::signal (SIGQUIT, SignalHandler);
104  #endif
105 
106  // Run it...
107  capturer.Run();
108 
109  cout << " Frames Frames Buffer" << endl
110  << " Captured Dropped Level" << endl;
111  do
112  { // Poll its status until stopped...
113  ULWord framesProcessed, framesDropped, bufferLevel;
114  capturer.GetACStatus (framesProcessed, framesDropped, bufferLevel);
115  cout << setw(9) << framesProcessed << setw(9) << framesDropped << setw(9) << bufferLevel << "\r" << flush;
116  AJATime::Sleep(2000);
117  } while (!gGlobalQuit); // loop til done
118 
119  cout << endl;
120  return 0;
121 
122 } // main
ntv2capture4k.h
Declares the NTV2Capture class.
CaptureConfig::fDoMultiFormat
bool fDoMultiFormat
If true, use multi-format/multi-channel mode, if device supports it; otherwise normal mode.
Definition: ntv2democommon.h:276
poptOption
Definition: options_popt.h:148
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific Frame Store. They're also commonly used to i...
Definition: ntv2enums.h:1305
CaptureConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
Pixel format to use.
Definition: ntv2democommon.h:273
main
int main(int argc, const char **argv)
Definition: main.cpp:30
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
CaptureConfig::fWithAnc
bool fWithAnc
If true, also capture Anc.
Definition: ntv2democommon.h:277
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
CNTV2DemoCommon::IsValidDevice
static bool IsValidDevice(const std::string &inDeviceSpec)
Definition: ntv2democommon.cpp:433
AJAStatus
AJAStatus
Definition: types.h:365
NTV2Capture4K::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2capture4k.cpp:71
AJATime::Sleep
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
ULWord
uint32_t ULWord
Definition: ajatypes.h:246
CaptureConfig
This class is used to configure an NTV2Capture instance.
Definition: ntv2democommon.h:265
CNTV2DemoCommon::GetPixelFormatFromString
static NTV2FrameBufferFormat GetPixelFormatFromString(const std::string &inStr)
Returns the NTV2FrameBufferFormat that matches the given string.
Definition: ntv2democommon.cpp:660
NTV2Capture4K
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
Definition: ntv2capture4k.h:19
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:240
UWord
uint16_t UWord
Definition: ajatypes.h:244
NTV2_FBF_8BIT_YCBCR
@ NTV2_FBF_8BIT_YCBCR
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:211
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:801
CNTV2DemoCommon::Popt::errorStr
virtual const std::string & errorStr(void) const
Definition: ntv2democommon.h:809
NTV2Version
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
SignalHandler
static void SignalHandler(int inSignal)
Definition: main.cpp:20
NTV2Capture4K::GetACStatus
virtual void GetACStatus(ULWord &outGoodFrames, ULWord &outDroppedFrames, ULWord &outBufferLevel)
Provides status information about my input (capture) process.
Definition: ntv2capture4k.cpp:483
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
CaptureConfig::fInputChannel
NTV2Channel fInputChannel
The device channel to use.
Definition: ntv2democommon.h:270
NTV2Capture4K::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2capture4k.cpp:315
CaptureConfig::fDoTSIRouting
bool fDoTSIRouting
If true, do TSI routing; otherwise squares.
Definition: ntv2democommon.h:279
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:980
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:603
CaptureConfig::fNumAudioLinks
UWord fNumAudioLinks
Number of audio links to capture.
Definition: ntv2democommon.h:274
NTV2_IS_VALID_FRAME_BUFFER_FORMAT
#define NTV2_IS_VALID_FRAME_BUFFER_FORMAT(__s__)
Definition: ntv2enums.h:251
gGlobalQuit
static bool gGlobalQuit(false)
AJA_FAILURE
#define AJA_FAILURE(_status_)
Definition: types.h:358
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
CaptureConfig::fWithAudio
bool fWithAudio
If true, also capture Audio.
Definition: ntv2democommon.h:278