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 "ntv2llburn.h"
12 #include <signal.h>
13 #include <iostream>
14 #include <iomanip>
15 
16 using namespace std;
17 
18 
19 // Globals
20 static bool gGlobalQuit (false);
21 
22 
23 static void SignalHandler (int inSignal)
24 {
25  (void) inSignal;
26  gGlobalQuit = true;
27 }
28 
29 
36 int main (int argc, const char ** argv)
37 {
38  char * pDeviceSpec (AJA_NULL); // Which device to use
39  char * pInputSrcSpec (AJA_NULL); // SDI source spec
40  char * pTcSource (AJA_NULL); // Time code source string
41  char * pPixelFormat (AJA_NULL); // Pixel format spec
42  int doMultiFormat (0); // MultiFormat mode?
43  int showVersion (0); // Show version?
44  int noAudio (0); // Disable audio?
45  int doAnc (0); // Use the Anc Extractor/Inserter
46  int doHanc (0); // Use the Anc Extractor/Inserter with Audio
48 
49  // Command line option descriptions:
50  const struct poptOption optionsTable [] =
51  {
52  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
53  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
54  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
55  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
56  {"input", 'i', POPT_ARG_STRING, &pInputSrcSpec, 0, "SDI input to use", "1-8, ?=list" },
57  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio?", AJA_NULL },
58  {"anc", 'a', POPT_ARG_NONE, &doAnc, 0, "use Anc ext/ins", AJA_NULL },
59  {"hanc", 'h', POPT_ARG_NONE, &doHanc, 0, "use Anc ext/ins with audio", AJA_NULL },
60  {"tcsource", 't', POPT_ARG_STRING, &pTcSource, 0, "time code source", "'?' to list" },
63  };
64  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
65  if (!popt)
66  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
67  if (showVersion)
68  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
69 
70 
71  // Device
72  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
73  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
74  return 1;
75 
76  BurnConfig config(deviceSpec);
77 
78  // Input source
79  const string inputSourceStr (pInputSrcSpec ? CNTV2DemoCommon::ToLower(string(pInputSrcSpec)) : "");
80  const string legalSources (CNTV2DemoCommon::GetInputSourceStrings(NTV2_IOKINDS_ALL, pDeviceSpec ? deviceSpec : ""));
81  config.fInputSource = CNTV2DemoCommon::GetInputSourceFromString(inputSourceStr, NTV2_IOKINDS_ALL, pDeviceSpec ? deviceSpec : "");
82  if (inputSourceStr == "?" || inputSourceStr == "list")
83  {cout << legalSources << endl; return 0;}
84  if (!inputSourceStr.empty() && !NTV2_IS_VALID_INPUT_SOURCE(config.fInputSource))
85  {cerr << "## ERROR: Input source '" << inputSourceStr << "' not one of:" << endl << legalSources << endl; return 1;}
86 
87  // Pixel Format
88  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
89  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
90  if (pixelFormatStr == "?" || pixelFormatStr == "list")
91  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
92  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
93  {
94  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
96  return 2;
97  }
98 
99  // Timecode source...
100  const string tcSourceStr (pTcSource ? CNTV2DemoCommon::ToLower(pTcSource) : "");
101  const string legalTCSources (CNTV2DemoCommon::GetTCIndexStrings(TC_INDEXES_ALL, pDeviceSpec ? deviceSpec : ""));
103  if (tcSourceStr == "?" || tcSourceStr == "list")
104  {cout << legalTCSources << endl; return 0;}
105  if (!tcSourceStr.empty() && !NTV2_IS_VALID_TIMECODE_INDEX(config.fTimecodeSource))
106  {cerr << "## ERROR: Timecode source '" << tcSourceStr << "' not one of these:" << endl << legalTCSources << endl; return 1;}
107 
108  config.fDoMultiFormat = doMultiFormat ? true : false;
109  config.fSuppressAudio = noAudio ? true : false;
110  config.fWithAnc = doAnc ? true : false;
111  config.fWithHanc = doHanc ? true : false;
112 
113  // Instantiate the NTV2LLBurn object...
114  NTV2LLBurn burner (config);
115 
116  ::signal (SIGINT, SignalHandler);
117  #if defined (AJAMac)
118  ::signal (SIGHUP, SignalHandler);
119  ::signal (SIGQUIT, SignalHandler);
120  #endif
121 
122  // Initialize the NTV2LLBurn instance...
123  AJAStatus status (burner.Init());
124  if (AJA_FAILURE (status))
125  {cerr << "## ERROR: Initialization failed, status=" << status << endl; return 4;}
126 
127  // Start the burner's capture and playout threads...
128  burner.Run();
129 
130  // Loop until told to stop...
131  cout << " Frames Frames" << endl
132  << "Processed Dropped" << endl;
133  do
134  {
135  ULWord framesProcessed, framesDropped;
136  burner.GetStatus (framesProcessed, framesDropped);
137  cout << setw(9) << framesProcessed
138  << setw(9) << framesDropped
139  << "\r" << flush;
140  AJATime::Sleep(2000);
141  } while (!gGlobalQuit); // loop until signaled
142 
143  cout << endl;
144  return 0;
145 
146 } // main
poptOption
Definition: options_popt.h:148
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
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
NTV2_IS_VALID_TIMECODE_INDEX
#define NTV2_IS_VALID_TIMECODE_INDEX(__x__)
Definition: ntv2enums.h:3937
BurnConfig::fDoMultiFormat
bool fDoMultiFormat
If true, enables device-sharing; otherwise takes exclusive control of the device.
Definition: ntv2democommon.h:398
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
gGlobalQuit
static bool gGlobalQuit((0))
ntv2llburn.h
Header file for the low latency NTV2Burn demonstration class.
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
BurnConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:396
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
ULWord
uint32_t ULWord
Definition: ajatypes.h:255
CNTV2DemoCommon::ToLower
static std::string ToLower(const std::string &inStr)
Returns the given string after converting it to lower case.
Definition: ntv2democommon.cpp:1033
BurnConfig::fWithHanc
bool fWithHanc
If true, capture & play HANC data, including audio (LLBurn). Defaults to false.
Definition: ntv2democommon.h:404
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:605
NTV2_IS_VALID_INPUT_SOURCE
#define NTV2_IS_VALID_INPUT_SOURCE(_inpSrc_)
Definition: ntv2enums.h:1266
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
NTV2LLBurn::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2llburn.cpp:503
NTV2LLBurn::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2llburn.cpp:80
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::fWithAnc
bool fWithAnc
If true, capture & play anc data (LLBurn). Defaults to false.
Definition: ntv2democommon.h:402
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:199
BurnConfig::fInputSource
NTV2InputSource fInputSource
The device input connector to use.
Definition: ntv2democommon.h:392
CNTV2DemoCommon::GetInputSourceStrings
static std::string GetInputSourceStrings(const NTV2IOKinds inKinds=NTV2_IOKINDS_ALL, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:689
NTV2_IOKINDS_ALL
@ NTV2_IOKINDS_ALL
Specifies any/all input/output kinds.
Definition: ntv2enums.h:1277
std
Definition: json.hpp:5362
NTV2LLBurn
Captures video and audio from a signal provided to an input of an AJA device, burns timecode into the...
Definition: ntv2llburn.h:32
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
NTV2LLBurn::GetStatus
virtual void GetStatus(ULWord &outFramesProcessed, ULWord &outFramesDropped)
Provides status information about my input (capture) and output (playout) processes.
Definition: ntv2llburn.cpp:897
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
CNTV2DemoCommon::GetInputSourceFromString
static NTV2InputSource GetInputSourceFromString(const std::string &inStr, const NTV2IOKinds inKinds=NTV2_IOKINDS_ALL, const std::string inDevSpec=std::string())
Returns the NTV2InputSource that matches the given string.
Definition: ntv2democommon.cpp:721
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
Configures an NTV2Burn or NTV2FieldBurn instance.
Definition: ntv2democommon.h:385
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
TC_INDEXES_ALL
@ TC_INDEXES_ALL
Definition: ntv2democommon.h:267
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:252