AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 // Includes
10 #include "ntv2capture8k.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)?
36 
37  // Command line option descriptions:
38  const CNTV2DemoCommon::PoptOpts optionsTable [] =
39  {
40  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
41  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
42  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
43  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
44  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
45  {"squares", 's', POPT_ARG_NONE, &doQuadRouting, 0, "use quad routing?", AJA_NULL },
48  };
49  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
50  if (!popt)
51  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
52  if (showVersion)
53  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
54 
55  // Device
56  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
57  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
58  return 1;
59 
60  CaptureConfig config(deviceSpec);
61 
62  // Channel
63  if ((channelNumber < 1) || (channelNumber > 8))
64  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
65  config.fInputChannel = NTV2Channel(channelNumber - 1);
66 
67  // Pixel Format
68  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
69  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
70  if (pixelFormatStr == "?" || pixelFormatStr == "list")
71  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
72  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
73  {
74  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
76  return 2;
77  }
78 
79  config.fDoTSIRouting = !doQuadRouting; // TSI?
80  config.fWithAnc = true; // Always capture anc
81  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
82 
83  // Instantiate and initialize the NTV2Capture8K object...
84  NTV2Capture8K capturer(config);
85  AJAStatus status = capturer.Init();
86  if (AJA_FAILURE(status))
87  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
88 
89  ::signal (SIGINT, SignalHandler);
90  #if defined(AJAMac)
91  ::signal (SIGHUP, SignalHandler);
92  ::signal (SIGQUIT, SignalHandler);
93  #endif
94 
95  // Run it...
96  capturer.Run();
97 
98  cout << " Frames Frames Buffer" << endl
99  << " Captured Dropped Level" << endl;
100  do
101  { // Poll its status until stopped...
102  ULWord framesProcessed, framesDropped, bufferLevel;
103  capturer.GetACStatus (framesProcessed, framesDropped, bufferLevel);
104  cout << setw(9) << framesProcessed << setw(9) << framesDropped << setw(9) << bufferLevel << "\r" << flush;
105  AJATime::Sleep(2000);
106  } while (!gGlobalQuit); // loop til done
107 
108  cout << endl;
109  return 0;
110 
111 } // main
CaptureConfig::fDoMultiFormat
bool fDoMultiFormat
If true, use multi-format/multi-channel mode, if device supports it; otherwise normal mode.
Definition: ntv2democommon.h:276
NTV2Capture8K::GetACStatus
virtual void GetACStatus(ULWord &outGoodFrames, ULWord &outDroppedFrames, ULWord &outBufferLevel)
Provides status information about my input (capture) process.
Definition: ntv2capture8k.cpp:425
poptOption
Definition: options_popt.h:148
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1305
gGlobalQuit
static bool gGlobalQuit((0))
SignalHandler
static void SignalHandler(int inSignal)
Definition: main.cpp:20
CaptureConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
Pixel format to use.
Definition: ntv2democommon.h:273
main
int main(int argc, const char **argv)
Definition: main.cpp:30
NTV2Capture8K::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2capture8k.cpp:69
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::void
j template void())
Definition: json.hpp:4893
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
ntv2capture8k.h
Declares the NTV2Capture class.
CNTV2DemoCommon::IsValidDevice
static bool IsValidDevice(const std::string &inDeviceSpec)
Definition: ntv2democommon.cpp:430
AJAStatus
AJAStatus
Definition: types.h:378
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:253
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:653
NTV2Capture8K
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
Definition: ntv2capture8k.h:19
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:240
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
NTV2Capture8K::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2capture8k.cpp:270
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:197
CaptureConfig::fInputChannel
NTV2Channel fInputChannel
The device channel to use.
Definition: ntv2democommon.h:270
CaptureConfig::fDoTSIRouting
bool fDoTSIRouting
If true, do TSI routing; otherwise squares.
Definition: ntv2democommon.h:279
std
Definition: json.hpp:5362
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:981
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:600
NTV2_IS_VALID_FRAME_BUFFER_FORMAT
#define NTV2_IS_VALID_FRAME_BUFFER_FORMAT(__s__)
Definition: ntv2enums.h:251
AJA_FAILURE
#define AJA_FAILURE(_status_)
Definition: types.h:371
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56