AJA NTV2 SDK  17.5.0.1242
NTV2 SDK 17.5.0.1242
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 // Includes
11 #include "ajatypes.h"
13 #include "ntv2burn4kquadrant.h"
14 #include <signal.h>
15 #include <iostream>
16 #include <iomanip>
17 
18 using namespace std;
19 
20 
21 // Globals
22 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
23 
24 
25 static void SignalHandler (int inSignal)
26 {
27  (void) inSignal;
28  gGlobalQuit = true;
29 }
30 
31 
32 int main (int argc, const char ** argv)
33 {
34  char * pDeviceSpec (AJA_NULL); // Which device to use for input
35  char * pOutDevSpec (AJA_NULL); // Which device to use for output
36  char * pTcSource (AJA_NULL); // Timecode source spec
37  char * pPixelFormat (AJA_NULL); // Pixel format spec
38  int showVersion (0); // Show version?
39  int noAudio (0); // Disable audio?
41 
42  // Command line option descriptions:
43  const struct poptOption optionsTable [] =
44  {
45  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
46  {"input", 'i', POPT_ARG_STRING, &pDeviceSpec, 0, "input device to use", "index#, serial#, or model" },
47  {"output", 'o', POPT_ARG_STRING, &pOutDevSpec, 0, "output device", "index#, serial#, or model" },
48  {"tcsource", 't', POPT_ARG_STRING, &pTcSource, 0, "timecode source", "'?' or 'list' to list" },
49  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio?", AJA_NULL },
50  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
53  };
54  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
55  if (!popt)
56  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
57  if (showVersion)
58  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
59 
60  // Device
61  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
62  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
63  return 1;
64 
65  BurnConfig config (deviceSpec);
66 
67  // Devices
68  config.fDeviceSpec2 = pOutDevSpec ? pOutDevSpec : "1";
70  {cout << "## ERROR: No such output device '" << config.fDeviceSpec2 << "'" << endl; return 1;}
71 
72  // Pixel Format
73  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
74  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
75  if (pixelFormatStr == "?" || pixelFormatStr == "list")
76  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
77  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
78  {
79  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
81  return 2;
82  }
83 
84  // Timecode source...
85  const string tcSourceStr (pTcSource ? CNTV2DemoCommon::ToLower(pTcSource) : "");
86  const string legalTCSources (CNTV2DemoCommon::GetTCIndexStrings(TC_INDEXES_ALL, pDeviceSpec ? deviceSpec : ""));
88  if (tcSourceStr == "?" || tcSourceStr == "list")
89  {cout << legalTCSources << endl; return 0;}
90  if (!tcSourceStr.empty() && !NTV2_IS_VALID_TIMECODE_INDEX(config.fTimecodeSource))
91  {cerr << "## ERROR: Timecode source '" << tcSourceStr << "' not one of these:" << endl << legalTCSources << endl; return 1;}
92 
93  config.fSuppressAudio = noAudio ? true : false;
94  config.fInputFrames.setCountOnly(5);
95  config.fOutputFrames.setCountOnly(5);
96 
97  // Instantiate the NTV2Burn4KQuadrant object...
98  NTV2Burn4KQuadrant burner (config);
99 
100  ::signal (SIGINT, SignalHandler);
101  #if defined (AJAMac)
102  ::signal (SIGHUP, SignalHandler);
103  ::signal (SIGQUIT, SignalHandler);
104  #endif
105 
106  // Initialize the NTV2Burn4KQuadrant instance...
107  AJAStatus status (burner.Init());
108  if (AJA_FAILURE(status))
109  {cerr << "## ERROR: Initialization failed, status=" << status << endl; return 4;}
110 
111  // Start the burner's capture and playout threads...
112  burner.Run();
113 
114  // Loop until someone tells us to stop...
115  cout << " Capture Playout Capture Playout" << endl
116  << " Frames Frames Frames Buffer Buffer" << endl
117  << "Processed Dropped Dropped Level Level" << endl;
118  do
119  {
120  AUTOCIRCULATE_STATUS inputStatus, outputStatus;
121  burner.GetACStatus (inputStatus, outputStatus);
122  cout << setw(9) << inputStatus.acFramesProcessed
123  << setw(9) << inputStatus.acFramesDropped
124  << setw(9) << outputStatus.acFramesDropped
125  << setw(9) << inputStatus.acBufferLevel
126  << setw(9) << outputStatus.acBufferLevel
127  << "\r" << flush;
128  AJATime::Sleep(1000);
129  } while (!gGlobalQuit); // loop until signaled
130 
131  cout << endl;
132  return 0;
133 
134 } // main
AUTOCIRCULATE_STATUS::acFramesProcessed
ULWord acFramesProcessed
Total number of frames successfully processed since CNTV2Card::AutoCirculateStart called.
Definition: ntv2publicinterface.h:7204
poptOption
Definition: options_popt.h:148
NTV2Burn4KQuadrant::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2burn4kquadrant.cpp:72
CNTV2DemoCommon::GetPixelFormatFromString
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.
Definition: ntv2democommon.cpp:637
NTV2_IS_VALID_TIMECODE_INDEX
#define NTV2_IS_VALID_TIMECODE_INDEX(__x__)
Definition: ntv2enums.h:3937
BurnConfig::fSuppressAudio
bool fSuppressAudio
If true, suppress audio; otherwise include audio.
Definition: ntv2democommon.h:399
BurnConfig::fTimecodeSource
NTV2TCIndex fTimecodeSource
Timecode source to use.
Definition: ntv2democommon.h:397
main
int main(int argc, const char **argv)
Definition: main.cpp:30
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
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
BurnConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:396
BurnConfig::fOutputFrames
NTV2ACFrameRange fOutputFrames
Playout frame count or range.
Definition: ntv2democommon.h:395
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
CNTV2DemoCommon::IsValidDevice
static bool IsValidDevice(const std::string &inDeviceSpec)
Definition: ntv2democommon.cpp:455
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
SignalHandler
static void SignalHandler(int inSignal)
Definition: main.cpp:25
CNTV2DemoCommon::ToLower
static std::string ToLower(const std::string &inStr)
Returns the given string after converting it to lower case.
Definition: ntv2democommon.cpp:1033
AUTOCIRCULATE_STATUS
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
Definition: ntv2publicinterface.h:7193
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:605
ntv2burn4kquadrant.h
Header file for the NTV2Burn4KQuadrant demonstration class.
options_popt.h
NTV2_FBF_8BIT_YCBCR
@ NTV2_FBF_8BIT_YCBCR
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:214
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:848
CNTV2DemoCommon::Popt::errorStr
virtual const std::string & errorStr(void) const
Definition: ntv2democommon.h:856
NTV2Version
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
CNTV2DemoCommon::GetTCIndexStrings
static std::string GetTCIndexStrings(const NTV2TCIndexKinds inKinds=TC_INDEXES_ALL, const std::string inDeviceSpecifier=std::string(), const bool inIsInputOnly=(!(0)))
Definition: ntv2democommon.cpp:852
BurnConfig::fDeviceSpec2
std::string fDeviceSpec2
Second AJA device to use (Burn4KQuadrant or BurnBoardToBoard only)
Definition: ntv2democommon.h:389
NTV2Burn4KQuadrant::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2burn4kquadrant.cpp:545
AUTOCIRCULATE_STATUS::acBufferLevel
ULWord acBufferLevel
Number of buffered frames in driver ready to capture or play.
Definition: ntv2publicinterface.h:7206
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:199
std
Definition: json.hpp:5362
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
NTV2Burn4KQuadrant
Instances of me can capture 4K/UHD video from one 4-channel AJA device, burn timecode into one quadra...
Definition: ntv2burn4kquadrant.h:33
NTV2Burn4KQuadrant::GetACStatus
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outInputStatus, AUTOCIRCULATE_STATUS &outOutputStatus)
Provides status information about my input (capture) and output (playout) processes.
Definition: ntv2burn4kquadrant.cpp:788
CNTV2DemoCommon::GetTCIndexFromString
static NTV2TCIndex GetTCIndexFromString(const std::string &inStr, const NTV2TCIndexKinds inKinds=TC_INDEXES_ALL, const std::string inDevSpec=std::string())
Returns the NTV2TCIndex that matches the given string.
Definition: ntv2democommon.cpp:887
AUTOCIRCULATE_STATUS::acFramesDropped
ULWord acFramesDropped
Total number of frames dropped since CNTV2Card::AutoCirculateStart called.
Definition: ntv2publicinterface.h:7205
NTV2_IS_VALID_FRAME_BUFFER_FORMAT
#define NTV2_IS_VALID_FRAME_BUFFER_FORMAT(__s__)
Definition: ntv2enums.h:254
AJA_FAILURE
#define AJA_FAILURE(_status_)
Definition: types.h:371
BurnConfig::fInputFrames
NTV2ACFrameRange fInputFrames
Ingest frame count or range.
Definition: ntv2democommon.h:394
BurnConfig
Configures an NTV2Burn or NTV2FieldBurn instance.
Definition: ntv2democommon.h:385
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
NTV2ACFrameRange::setCountOnly
bool setCountOnly(const UWord inCount)
Definition: ntv2utils.h:1013
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
gGlobalQuit
static bool gGlobalQuit((0))
TC_INDEXES_ALL
@ TC_INDEXES_ALL
Definition: ntv2democommon.h:267
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:252