AJA NTV2 SDK  18.1.0.2262
NTV2 SDK 18.1.0.2262
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 (!popt.otherArgs().empty())
55  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
56  if (showVersion)
57  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
58 
59  // Device
60  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
61  CaptureConfig config(deviceSpec);
62 
63  // Channel
64  if ((channelNumber < 1) || (channelNumber > 8))
65  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
66  config.fInputChannel = NTV2Channel(channelNumber - 1);
67 
68  // Pixel Format
69  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
70  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
71  if (pixelFormatStr == "?" || pixelFormatStr == "list")
72  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
73  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
74  {
75  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
77  return 2;
78  }
79 
80  // Audio
81  if (numAudioLinks < 0)
82  {cerr << "## ERROR: invalid '--audioLinks' value '" << numAudioLinks << "' -- negative" << endl; return 1;}
83  if (numAudioLinks > 4)
84  {cerr << "## ERROR: invalid '--audioLinks' value '" << numAudioLinks << "' -- exceeds 4" << endl; return 1;}
85  if (numAudioLinks != 1)
86  config.fNumAudioLinks = UWord(numAudioLinks);
87 
88  config.fWithAudio = config.fNumAudioLinks ? true : false; // Enable audio if numLinks > 0, disable if zero
89  config.fDoTSIRouting = !doQuadRouting; // TSI?
90  config.fWithAnc = true; // Always capture anc
91  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
92 
93  { // Instantiate and initialize the NTV2Capture4K object...
94  NTV2Capture4K capturer(config);
95  AJAStatus status = capturer.Init();
96  if (AJA_FAILURE(status))
97  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
98 
99  ::signal (SIGINT, SignalHandler);
100  #if defined(AJAMac)
101  ::signal (SIGHUP, SignalHandler);
102  ::signal (SIGQUIT, SignalHandler);
103  #endif
104 
105  // Run it...
106  capturer.Run();
107 
108  cout << " Frames Frames Buffer" << endl
109  << " Captured Dropped Level" << endl;
110  do
111  { // Poll its status until stopped...
112  ULWord framesProcessed, framesDropped, bufferLevel;
113  capturer.GetACStatus (framesProcessed, framesDropped, bufferLevel);
114  cout << setw(9) << framesProcessed << setw(9) << framesDropped << setw(9) << bufferLevel << "\r" << flush;
115  AJATime::Sleep(2000);
116  } while (!gGlobalQuit); // loop til done
117  cout << endl;
118  } // NTV2Capture4K scope
119  return 0;
120 
121 } // main
int main(int argc, const char **argv)
Definition: main.cpp:30
AJAStatus
Definition: types.h:380
bool fDoMultiFormat
If true, use multi-format/multi-channel mode, if device supports it; otherwise normal mode...
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
Declares the NTV2Capture class.
#define AJA_FAILURE(_status_)
Definition: types.h:373
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
bool fWithAnc
If true, also capture Anc.
Definition: json.hpp:5362
#define POPT_ARG_INT
Definition: options_popt.h:58
uint32_t ULWord
Definition: ajatypes.h:236
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1359
bool fWithAudio
If true, also capture Audio.
#define POPT_AUTOHELP
Definition: options_popt.h:227
NTV2Channel fInputChannel
The device channel to use.
static void SignalHandler(int inSignal)
Definition: main.cpp:20
#define true
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
This class is used to configure an NTV2Capture instance.
virtual void GetACStatus(ULWord &outGoodFrames, ULWord &outDroppedFrames, ULWord &outBufferLevel)
Provides status information about my input (capture) process.
#define AJA_NULL
Definition: ajatypes.h:180
virtual const NTV2StringList & otherArgs(void) const
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
Definition: ntv2capture4k.h:19
virtual const std::string & errorStr(void) const
UWord fNumAudioLinks
Number of audio links to capture.
static bool gGlobalQuit((0))
#define POPT_TABLEEND
Definition: options_popt.h:222
uint16_t UWord
Definition: ajatypes.h:234
NTV2PixelFormat fPixelFormat
Pixel format to use.
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:987
std::string join(const std::vector< std::string > &parts, const std::string &delim)
Definition: common.cpp:468
virtual AJAStatus Run(void)
Runs me.
#define NTV2_IS_VALID_FRAME_BUFFER_FORMAT(__s__)
Definition: ntv2enums.h:265
#define POPT_ARG_STRING
Definition: options_popt.h:57
#define POPT_ARG_NONE
Definition: options_popt.h:56
static NTV2PixelFormat GetPixelFormatFromString(const std::string &inStr, const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
Returns the NTV2PixelFormat that matches the given string.
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:225
bool fDoTSIRouting
If true, do TSI routing; otherwise squares.