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 */
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 (!popt.otherArgs().empty())
58  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
59  if (showVersion)
60  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
61 
62  // Devices
63  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
64  BurnConfig config (deviceSpec);
65  config.fDeviceSpec2 = pOutDevSpec ? pOutDevSpec : "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, pDeviceSpec ? 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  // Timecode source...
80  const string tcSourceStr (pTcSource ? CNTV2DemoCommon::ToLower(pTcSource) : "");
81  const string legalTCSources (CNTV2DemoCommon::GetTCIndexStrings(TC_INDEXES_ALL, pDeviceSpec ? deviceSpec : ""));
83  if (tcSourceStr == "?" || tcSourceStr == "list")
84  {cout << legalTCSources << endl; return 0;}
85  if (!tcSourceStr.empty() && !NTV2_IS_VALID_TIMECODE_INDEX(config.fTimecodeSource))
86  {cerr << "## ERROR: Timecode source '" << tcSourceStr << "' not one of these:" << endl << legalTCSources << endl; return 1;}
87 
88  config.fSuppressAudio = noAudio ? true : false;
89  config.fInputFrames.setCountOnly(5);
90  config.fOutputFrames.setCountOnly(5);
91 
92  { // Instantiate and initialize the NTV2Burn4KQuadrant object...
93  NTV2Burn4KQuadrant burner (config);
94 
95  ::signal (SIGINT, SignalHandler);
96  #if defined (AJAMac)
97  ::signal (SIGHUP, SignalHandler);
98  ::signal (SIGQUIT, SignalHandler);
99  #endif
100 
101  // Initialize the NTV2Burn4KQuadrant instance...
102  AJAStatus status (burner.Init());
103  if (AJA_FAILURE(status))
104  {cerr << "## ERROR: Initialization failed, status=" << status << endl; return 4;}
105 
106  // Start the burner's capture and playout threads...
107  burner.Run();
108 
109  // Loop until someone tells us to stop...
110  cout << " Capture Playout Capture Playout" << endl
111  << " Frames Frames Frames Buffer Buffer" << endl
112  << "Processed Dropped Dropped Level Level" << endl;
113  do
114  {
115  AUTOCIRCULATE_STATUS inputStatus, outputStatus;
116  burner.GetACStatus (inputStatus, outputStatus);
117  cout << setw(9) << inputStatus.acFramesProcessed
118  << setw(9) << inputStatus.acFramesDropped
119  << setw(9) << outputStatus.acFramesDropped
120  << setw(9) << inputStatus.acBufferLevel
121  << setw(9) << outputStatus.acBufferLevel
122  << "\r" << flush;
123  AJATime::Sleep(1000);
124  } while (!gGlobalQuit); // loop until signaled
125  cout << endl;
126  } // NTV2Burn4KQuadrant scope
127  return 0;
128 
129 } // main
int main(int argc, const char **argv)
Definition: main.cpp:30
bool setCountOnly(const UWord inCount)
Definition: ntv2utils.h:1015
AJAStatus
Definition: types.h:380
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
#define AJA_FAILURE(_status_)
Definition: types.h:373
bool fSuppressAudio
If true, suppress audio; otherwise include audio.
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
#define NTV2_IS_VALID_TIMECODE_INDEX(__x__)
Definition: ntv2enums.h:3987
Definition: json.hpp:5362
std::string fDeviceSpec2
Second AJA device to use (Burn4KQuadrant or BurnBoardToBoard only)
#define POPT_AUTOHELP
Definition: options_popt.h:227
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
NTV2ACFrameRange fOutputFrames
Playout frame count or range.
NTV2PixelFormat fPixelFormat
The pixel format to use.
#define true
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
Header file for the NTV2Burn4KQuadrant demonstration class.
#define AJA_NULL
Definition: ajatypes.h:180
virtual const NTV2StringList & otherArgs(void) const
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
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.
static std::string ToLower(const std::string &inStr)
Returns the given string after converting it to lower case.
virtual const std::string & errorStr(void) const
virtual AJAStatus Run(void)
Runs me.
Configures an NTV2Burn or NTV2FieldBurn instance.
Instances of me can capture 4K/UHD video from one 4-channel AJA device, burn timecode into one quadra...
static void SignalHandler(int inSignal)
Definition: main.cpp:25
ULWord acBufferLevel
Number of buffered frames in driver ready to capture or play.
#define POPT_TABLEEND
Definition: options_popt.h:222
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
NTV2ACFrameRange fInputFrames
Ingest frame count or range.
ULWord acFramesDropped
Total number of frames dropped since CNTV2Card::AutoCirculateStart called.
static bool gGlobalQuit((0))
NTV2TCIndex fTimecodeSource
Timecode source to use.
std::string join(const std::vector< std::string > &parts, const std::string &delim)
Definition: common.cpp:468
#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.
ULWord acFramesProcessed
Total number of frames successfully processed since CNTV2Card::AutoCirculateStart called...
static std::string GetTCIndexStrings(const NTV2TCIndexKinds inKinds=TC_INDEXES_ALL, const std::string inDeviceSpecifier=std::string(), const bool inIsInputOnly=(!(0)))
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outInputStatus, AUTOCIRCULATE_STATUS &outOutputStatus)
Provides status information about my input (capture) and output (playout) processes.
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:225