AJA NTV2 SDK  17.0.1.1246
NTV2 SDK 17.0.1.1246
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 // Includes
11 #include "ntv2burn.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 
30 int main (int argc, const char ** argv)
31 {
32  char * pDeviceSpec (AJA_NULL); // Which device to use
33  char * pInputSrcSpec (AJA_NULL); // SDI source spec
34  char * pTcSource (AJA_NULL); // Time code source string
35  char * pPixelFormat (AJA_NULL); // Pixel format spec
36  char * pInFramesSpec (AJA_NULL); // Input AutoCirculate frames spec
37  char * pOutFramesSpec (AJA_NULL); // Output AutoCirculate frames spec
38  int doMultiFormat (0); // MultiFormat mode?
39  int showVersion (0); // Show version?
40  int noAudio (0); // Disable audio?
41  int noVideo (0); // Disable video?
42  int noAnc (0); // Disable use of Anc Extractor/Inserter?
44 
45  // Command line option descriptions:
46  const struct poptOption optionsTable [] =
47  {
48  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
49  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
50  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
51  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
52  {"input", 'i', POPT_ARG_STRING, &pInputSrcSpec, 0, "SDI input to use", "1-8, ?=list" },
53  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio?", AJA_NULL },
54  {"novideo", 0, POPT_ARG_NONE, &noVideo, 0, "disable video?", AJA_NULL },
55  {"noanc", 0, POPT_ARG_NONE, &noAnc, 0, "disable anc?", AJA_NULL },
56  {"iframes", 0, POPT_ARG_STRING, &pInFramesSpec, 0, "input AutoCirc frames", "num[@min] or min-max" },
57  {"oframes", 0, POPT_ARG_STRING, &pOutFramesSpec,0, "output AutoCirc frames", "num[@min] or min-max" },
58  {"tcsource", 't', POPT_ARG_STRING, &pTcSource, 0, "time code source", "'?' to list" },
61  };
62  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
63  if (!popt)
64  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
65  if (showVersion)
66  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
67 
68  // Device
69  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
70  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
71  return 1;
72 
73  BurnConfig config(deviceSpec);
74 
75  // Input source
76  const string legalSources(CNTV2DemoCommon::GetInputSourceStrings(NTV2_IOKINDS_ALL, deviceSpec));
77  const string inputSourceStr (pInputSrcSpec ? CNTV2DemoCommon::ToLower(string(pInputSrcSpec)) : "");
78  if (inputSourceStr == "?" || inputSourceStr == "list")
79  {cout << legalSources << endl; return 0;}
80  if (!inputSourceStr.empty())
81  {
84  {cerr << "## ERROR: Input source '" << inputSourceStr << "' not one of:" << endl << legalSources << endl; return 1;}
85  } // if input source specified
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, 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 legalTCSources(CNTV2DemoCommon::GetTCIndexStrings(TC_INDEXES_ALL, deviceSpec));
101  const string tcSourceStr (pTcSource ? CNTV2DemoCommon::ToLower(pTcSource) : "");
102  if (tcSourceStr == "?" || tcSourceStr == "list")
103  {cout << legalTCSources << endl; return 0;}
104  if (!tcSourceStr.empty())
105  {
108  {cerr << "## ERROR: Timecode source '" << tcSourceStr << "' not one of these:" << endl << legalTCSources << endl; return 1;}
109  }
110 
111  // InputFrames
112  string framesSpec(pInFramesSpec ? pInFramesSpec : "");
113  static const string legalFrmSpec("{frameCount}[@{firstFrameNum}] or {firstFrameNum}-{lastFrameNum}");
114  if (!framesSpec.empty())
115  { const string parseResult(config.fInputFrames.setFromString(framesSpec));
116  if (!parseResult.empty())
117  {cerr << "## ERROR: Bad '--iframes' spec '" << framesSpec << "'" << endl << "## " << parseResult << endl; return 1;}
118  }
119  if (!config.fInputFrames.valid())
120  {cerr << "## ERROR: Bad '--iframes' spec '" << framesSpec << "'" << endl << "## Expected " << legalFrmSpec << endl; return 1;}
121 
122  // OutputFrames
123  framesSpec = pOutFramesSpec ? pOutFramesSpec : "";
124  if (!framesSpec.empty())
125  { const string parseResult(config.fOutputFrames.setFromString(framesSpec));
126  if (!parseResult.empty())
127  {cerr << "## ERROR: Bad '--oframes' spec '" << framesSpec << "'" << endl << "## " << parseResult << endl; return 1;}
128  }
129  if (!config.fOutputFrames.valid())
130  {cerr << "## ERROR: Bad '--oframes' spec '" << framesSpec << "'" << endl << "## Expected " << legalFrmSpec << endl; return 1;}
131 
132  if (noVideo && noAudio)
133  {cerr << "## ERROR: '--novideo' and '--noaudio' cannot both be specified" << endl; return 1;}
134  config.fDoMultiFormat = doMultiFormat ? true : false;
135  config.fSuppressAudio = noAudio ? true : false;
136  config.fSuppressVideo = noVideo ? true : false;
137  config.fWithAnc = noAnc ? false : true;
138 
139  // Instantiate the NTV2Burn object...
140  NTV2Burn burner (config);
141 
142  // Initialize the NTV2Burn instance...
143  AJAStatus status (burner.Init());
144  if (AJA_FAILURE(status))
145  {cerr << "## ERROR: Initialization failed, status=" << status << endl; return 4;}
146 
147  ::signal (SIGINT, SignalHandler);
148  #if defined (AJAMac)
149  ::signal (SIGHUP, SignalHandler);
150  ::signal (SIGQUIT, SignalHandler);
151  #endif
152 
153  // Start the burner's capture and playout threads...
154  burner.Run();
155 
156  // Loop until told to stop...
157  cout << " Capture Playout Capture Playout" << endl
158  << " Frames Frames Frames Buffer Buffer" << endl
159  << "Processed Dropped Dropped Level Level" << endl;
160  do
161  {
162  AUTOCIRCULATE_STATUS inputStatus, outputStatus;
163  burner.GetStatus (inputStatus, outputStatus);
164  cout << setw(9) << inputStatus.GetProcessedFrameCount()
165  << setw(9) << inputStatus.GetDroppedFrameCount()
166  << setw(9) << outputStatus.GetDroppedFrameCount()
167  << setw(9) << inputStatus.GetBufferLevel()
168  << setw(9) << outputStatus.GetBufferLevel()
169  << "\r" << flush;
170  AJATime::Sleep(2000);
171  } while (!gGlobalQuit); // loop until signaled
172 
173  cout << endl;
174  return 0;
175 
176 } // main
CNTV2DemoCommon::GetInputSourceFromString
static NTV2InputSource GetInputSourceFromString(const std::string &inStr)
Returns the NTV2InputSource that matches the given string.
Definition: ntv2democommon.cpp:713
NTV2Burn::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2burn.cpp:67
poptOption
Definition: options_popt.h:148
AUTOCIRCULATE_STATUS::GetProcessedFrameCount
ULWord GetProcessedFrameCount(void) const
Definition: ntv2publicinterface.h:7161
NTV2_IS_VALID_TIMECODE_INDEX
#define NTV2_IS_VALID_TIMECODE_INDEX(__x__)
Definition: ntv2enums.h:3898
BurnConfig::fDoMultiFormat
bool fDoMultiFormat
If true, enables device-sharing; otherwise takes exclusive control of the device.
Definition: ntv2democommon.h:388
BurnConfig::fSuppressAudio
bool fSuppressAudio
If true, suppress audio; otherwise include audio.
Definition: ntv2democommon.h:389
BurnConfig::fTimecodeSource
NTV2TCIndex fTimecodeSource
Timecode source to use.
Definition: ntv2democommon.h:387
AUTOCIRCULATE_STATUS::GetBufferLevel
ULWord GetBufferLevel(void) const
Definition: ntv2publicinterface.h:7166
main
int main(int argc, const char **argv)
Definition: main.cpp:30
BurnConfig::fSuppressVideo
bool fSuppressVideo
If true, suppress video; otherwise include video.
Definition: ntv2democommon.h:390
NTV2ACFrameRange::setFromString
std::string setFromString(const std::string &inStr)
Definition: ntv2utils.cpp:4155
CNTV2DemoCommon::GetTCIndexFromString
static NTV2TCIndex GetTCIndexFromString(const std::string &inStr)
Returns the NTV2TCIndex that matches the given string.
Definition: ntv2democommon.cpp:816
CNTV2DemoCommon::GetTCIndexStrings
static std::string GetTCIndexStrings(const NTV2TCIndexKinds inKinds=TC_INDEXES_ALL, const std::string inDeviceSpecifier=std::string(), const bool inIsInputOnly=true)
Definition: ntv2democommon.cpp:780
BurnConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:386
NTV2Burn::GetStatus
virtual void GetStatus(AUTOCIRCULATE_STATUS &outInputStatus, AUTOCIRCULATE_STATUS &outOutputStatus)
Provides status information about my input (capture) and output (playout) processes.
Definition: ntv2burn.cpp:760
BurnConfig::fOutputFrames
NTV2ACFrameRange fOutputFrames
Playout frame count or range.
Definition: ntv2democommon.h:385
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
CNTV2DemoCommon::IsValidDevice
static bool IsValidDevice(const std::string &inDeviceSpec)
Definition: ntv2democommon.cpp:433
AJAStatus
AJAStatus
Definition: types.h:365
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
CNTV2DemoCommon::ToLower
static std::string ToLower(const std::string &inStr)
Returns the given string after converting it to lower case.
Definition: ntv2democommon.cpp:937
AUTOCIRCULATE_STATUS
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
Definition: ntv2publicinterface.h:7105
CNTV2DemoCommon::GetPixelFormatFromString
static NTV2FrameBufferFormat GetPixelFormatFromString(const std::string &inStr)
Returns the NTV2FrameBufferFormat that matches the given string.
Definition: ntv2democommon.cpp:660
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:240
NTV2_IS_VALID_INPUT_SOURCE
#define NTV2_IS_VALID_INPUT_SOURCE(_inpSrc_)
Definition: ntv2enums.h:1243
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
BurnConfig::fWithAnc
bool fWithAnc
If true, capture & play anc data (LLBurn). Defaults to false.
Definition: ntv2democommon.h:392
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
SignalHandler
static void SignalHandler(int inSignal)
Definition: main.cpp:23
BurnConfig::fInputSource
NTV2InputSource fInputSource
The device input connector to use.
Definition: ntv2democommon.h:383
NTV2Burn
I capture frames from a video signal provided to an AJA device's video input. I burn timecode into th...
Definition: ntv2burn.h:30
false
#define false
Definition: ntv2devicefeatures.h:25
ntv2burn.h
Header file for the NTV2Burn demonstration class.
CNTV2DemoCommon::GetInputSourceStrings
static std::string GetInputSourceStrings(const NTV2IOKinds inKinds=NTV2_IOKINDS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:685
AUTOCIRCULATE_STATUS::GetDroppedFrameCount
ULWord GetDroppedFrameCount(void) const
Definition: ntv2publicinterface.h:7156
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
gGlobalQuit
static bool gGlobalQuit(false)
Set this "true" to exit gracefully.
NTV2_IOKINDS_ALL
@ NTV2_IOKINDS_ALL
Specifies any/all input/output kinds.
Definition: ntv2enums.h:1250
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:603
NTV2ACFrameRange::valid
bool valid(void) const
Definition: ntv2utils.h:977
NTV2Burn::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2burn.cpp:516
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:358
BurnConfig::fInputFrames
NTV2ACFrameRange fInputFrames
Ingest frame count or range.
Definition: ntv2democommon.h:384
BurnConfig
Configures an NTV2Burn or NTV2FieldBurn instance.
Definition: ntv2democommon.h:376
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:252