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 "ntv2fieldburn.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 * pPixelFormat (AJA_NULL); // Pixel format spec
35  int doMultiFormat (0); // MultiFormat mode?
36  int showVersion (0); // Show version?
37  int noAudio (0); // Disable audio?
38  int noFieldMode (0); // Disable AutoCirculate Field Mode?
40 
41  // Command line option descriptions:
42  const struct poptOption optionsTable [] =
43  {
44  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
45  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
46  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
47  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
48  {"input", 'i', POPT_ARG_STRING, &pInputSrcSpec, 0, "SDI input to use", "1-8, ?=list" },
49  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio?", AJA_NULL },
50  {"nofield", 0, POPT_ARG_NONE, &noFieldMode, 0, "disables field mode", AJA_NULL },
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  // Input source
68  const string legalSources(CNTV2DemoCommon::GetInputSourceStrings(NTV2_IOKINDS_ALL, deviceSpec));
69  const string inputSourceStr (pInputSrcSpec ? CNTV2DemoCommon::ToLower(string(pInputSrcSpec)) : "");
70  if (inputSourceStr == "?" || inputSourceStr == "list")
71  {cout << legalSources << endl; return 0;}
72  if (!inputSourceStr.empty())
73  {
76  {cerr << "## ERROR: Input source '" << inputSourceStr << "' not one of:" << endl << legalSources << endl; return 1;}
77  } // if input source specified
78 
79  // Pixel Format
80  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
81  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
82  if (pixelFormatStr == "?" || pixelFormatStr == "list")
83  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
84  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
85  {
86  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
88  return 2;
89  }
90 
91  config.fDoMultiFormat = doMultiFormat ? true : false;
92  config.fSuppressAudio = noAudio ? true : false;
93  config.fIsFieldMode = noFieldMode ? false : true;
95 
96  // Instantiate the NTV2FieldBurn object...
97  NTV2FieldBurn burner (config);
98 
99  ::signal (SIGINT, SignalHandler);
100  #if defined (AJAMac)
101  ::signal (SIGHUP, SignalHandler);
102  ::signal (SIGQUIT, SignalHandler);
103  #endif
104  const string hdg1 (" Capture Playout Capture Playout"),
105  hdg2a(" Fields Fields Fields Buffer Buffer"),
106  hdg2b(" Frames Frames Frames Buffer Buffer"),
107  hdg3 ("Processed Dropped Dropped Level Level"),
108  hdg2 (noFieldMode ? hdg2b : hdg2a);
109 
110  // Initialize the NTV2FieldBurn instance...
111  AJAStatus status (burner.Init());
112  if (AJA_FAILURE (status))
113  {cerr << "## ERROR: Initialization failed, status=" << status << endl; return 4;}
114 
115  // Start the burner's capture and playout threads...
116  burner.Run();
117 
118  // Loop until told to stop...
119  cout << hdg1 << endl << hdg2 << endl << hdg3 << endl;
120  do
121  {
122  ULWord totalFrames(0), inputDrops(0), outputDrops(0), inputBufferLevel(0), outputBufferLevel(0);
123  burner.GetStatus (totalFrames, inputDrops, outputDrops, inputBufferLevel, outputBufferLevel);
124  cout << setw(9) << totalFrames << setw(9) << inputDrops << setw(9) << outputDrops
125  << setw(9) << inputBufferLevel << setw(9) << outputBufferLevel << "\r" << flush;
126  AJATime::Sleep(2000);
127  } while (!gGlobalQuit); // loop until signaled
128 
129  cout << endl;
130  return 0;
131 
132 } // main
NTV2InputSourceToChannel
NTV2Channel NTV2InputSourceToChannel(const NTV2InputSource inInputSource)
Converts a given NTV2InputSource to its equivalent NTV2Channel value.
Definition: ntv2utils.cpp:5105
CNTV2DemoCommon::GetInputSourceFromString
static NTV2InputSource GetInputSourceFromString(const std::string &inStr)
Returns the NTV2InputSource that matches the given string.
Definition: ntv2democommon.cpp:713
poptOption
Definition: options_popt.h:148
BurnConfig::fIsFieldMode
bool fIsFieldMode
True if Field Mode, otherwise Frame Mode.
Definition: ntv2democommon.h:391
NTV2FieldBurn::GetStatus
virtual void GetStatus(ULWord &outNumProcessed, ULWord &outCaptureDrops, ULWord &outPlayoutDrops, ULWord &outCaptureLevel, ULWord &outPlayoutLevel)
Provides status information about my input (capture) and output (playout) processes.
Definition: ntv2fieldburn.cpp:765
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
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
main
int main(int argc, const char **argv)
Definition: main.cpp:30
BurnConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:386
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
ULWord
uint32_t ULWord
Definition: ajatypes.h:246
CNTV2DemoCommon::ToLower
static std::string ToLower(const std::string &inStr)
Returns the given string after converting it to lower case.
Definition: ntv2democommon.cpp:937
NTV2FieldBurn::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2fieldburn.cpp:66
CNTV2DemoCommon::GetPixelFormatFromString
static NTV2FrameBufferFormat GetPixelFormatFromString(const std::string &inStr)
Returns the NTV2FrameBufferFormat that matches the given string.
Definition: ntv2democommon.cpp:660
NTV2ChannelToTimecodeIndex
NTV2TCIndex NTV2ChannelToTimecodeIndex(const NTV2Channel inChannel, const bool inEmbeddedLTC=false, const bool inIsF2=false)
Converts the given NTV2Channel value into the equivalent NTV2TCIndex value.
Definition: ntv2utils.cpp:5020
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
NTV2FieldBurn
I capture individual fields from an interlaced video signal provided to an SDI input....
Definition: ntv2fieldburn.h:32
gGlobalQuit
static bool gGlobalQuit(false)
Set this "true" to exit gracefully.
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
BurnConfig::fInputSource
NTV2InputSource fInputSource
The device input connector to use.
Definition: ntv2democommon.h:383
false
#define false
Definition: ntv2devicefeatures.h:25
CNTV2DemoCommon::GetInputSourceStrings
static std::string GetInputSourceStrings(const NTV2IOKinds inKinds=NTV2_IOKINDS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:685
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
ntv2fieldburn.h
Header file for the NTV2FieldBurn demonstration class.
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
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
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
NTV2FieldBurn::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2fieldburn.cpp:446