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 */
9 // Includes
10 #include "ntv2player8k.h"
11 #include <signal.h>
12 
13 
14 using namespace std;
15 
16 
17 // Globals
18 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
19 
20 
21 static void SignalHandler (int inSignal)
22 {
23  (void) inSignal;
24  gGlobalQuit = true;
25 }
26 
27 
28 int main (int argc, const char ** argv)
29 {
30  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
31  char * pPixelFormat (AJA_NULL); // Pixel format argument
32  char * pVideoFormat (AJA_NULL); // Video format to use
33  int channelNumber (1); // Channel/FrameStore to use
34  int doMultiFormat (0); // MultiFormat mode?
35  int showVersion (0); // Show version?
36  int numAudioLinks (1); // Number of audio systems for multi-link audio
37  int useHDMIOut (0); // Enable HDMI output?
38  int doRGBOnWire (0); // Route the output to put RGB on the wire
39  int doSquares (0); // Don't route output thru Tsi Muxes
41 
42  // Command line option descriptions:
43  const CNTV2DemoCommon::PoptOpts optionsTable [] =
44  {
45  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
46  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
47  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
48  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
49  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
50  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list" },
51  {"audioLinks", 'a', POPT_ARG_INT, &numAudioLinks, 0, "# audio systems to link", "1-4 0=silence" },
52  {"hdmi", 'h', POPT_ARG_NONE, &useHDMIOut, 0, "enable HDMI output?", AJA_NULL },
53  {"rgb", 'r', POPT_ARG_NONE, &doRGBOnWire, 0, "RGB on SDI?", AJA_NULL },
54  {"squares", 's', POPT_ARG_NONE, &doSquares, 0, "use square routing?", AJA_NULL },
57  };
58  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
59  if (!popt)
60  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
61  if (!popt.otherArgs().empty())
62  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
63  if (showVersion)
64  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
65 
66  // Device
67  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
68  PlayerConfig config(deviceSpec);
69 
70  // Channel
71  if ((channelNumber < 1) || (channelNumber > 8))
72  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
73  config.fOutputChannel = NTV2Channel(channelNumber - 1);
74 
75  // VideoFormat
76  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
77  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_4x3840x2160p_2398
79  if (videoFormatStr == "?" || videoFormatStr == "list")
80  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_8KUHD2, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
81  else if (!videoFormatStr.empty() && !NTV2_IS_8K_VIDEO_FORMAT(config.fVideoFormat))
82  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
84  return 2;
85  }
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  // Anc Playback
100  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
101  config.fDoHDMIOutput = useHDMIOut ? true : false;
102  config.fDoTsiRouting = doSquares ? false : true;
103  config.fDoRGBOnWire = doRGBOnWire ? true : false;
104  config.fNumAudioLinks = UWord(numAudioLinks);
105 
106  { // Instantiate and initialize the NTV2Player object...
107  NTV2Player8K player(config);
108  AJAStatus status = player.Init();
109  if (AJA_FAILURE(status))
110  return 1;
111 
112  ::signal (SIGINT, SignalHandler);
113  #if defined(AJAMac)
114  ::signal (SIGHUP, SignalHandler);
115  ::signal (SIGQUIT, SignalHandler);
116  #endif
117 
118  // Run it...
119  player.Run();
120 
121  cout << " Frames Frames Buffer" << endl
122  << " Played Dropped Level" << endl;
123  do
124  { // Poll its status until stopped...
125  AUTOCIRCULATE_STATUS outputStatus;
126  player.GetACStatus(outputStatus);
127  cout << setw(9) << outputStatus.GetProcessedFrameCount()
128  << setw(9) << outputStatus.GetDroppedFrameCount()
129  << setw(9) << outputStatus.GetBufferLevel() << "\r" << flush;
130  AJATime::Sleep(2000);
131  } while (player.IsRunning() && !gGlobalQuit); // loop til done
132  cout << endl;
133  } // NTV2Player8K scope
134  return 0;
135 
136 } // main
int main(int argc, const char **argv)
Definition: main.cpp:30
virtual bool IsRunning(void) const
Definition: ntv2player8k.h:47
AJAStatus
Definition: types.h:380
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
ULWord GetBufferLevel(void) const
#define AJA_FAILURE(_status_)
Definition: types.h:373
static NTV2VideoFormat GetVideoFormatFromString(const std::string &inStr, const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_SDHD, const std::string &inDevSpec=std::string())
Returns the NTV2VideoFormat that matches the given string.
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
#define NTV2_IS_8K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:895
Definition: json.hpp:5362
#define POPT_ARG_INT
Definition: options_popt.h:58
void SignalHandler(int inSignal)
Definition: main.cpp:26
#define false
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1359
ULWord GetProcessedFrameCount(void) const
#define POPT_AUTOHELP
Definition: options_popt.h:227
#define true
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
UWord fNumAudioLinks
The number of audio systems to control for multi-link audio (4K/8K)
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_SDHD, const std::string inDevSpec=std::string())
#define AJA_NULL
Definition: ajatypes.h:180
virtual const NTV2StringList & otherArgs(void) const
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
NTV2PixelFormat fPixelFormat
The pixel format to use.
virtual const std::string & errorStr(void) const
NTV2VideoFormat fVideoFormat
The video format to use.
ULWord GetDroppedFrameCount(void) const
bool fDoRGBOnWire
If true, produce RGB on the wire; otherwise output YUV.
static bool gGlobalQuit((0))
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
bool fDoTsiRouting
If true, enable TSI routing; otherwise route for square division (4K/8K)
NTV2Channel fOutputChannel
The device channel to use.
I am an object that can play out an 8K or UHD2 test pattern (with timecode) to 4 x 12G SDI outputs of...
Definition: ntv2player8k.h:24
#define POPT_TABLEEND
Definition: options_popt.h:222
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
uint16_t UWord
Definition: ajatypes.h:234
virtual AJAStatus Run(void)
Runs me.
Configures an NTV2Player instance.
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
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outStatus)
Provides status information about my output (playout) process.
Header file for NTV2Player8K demonstration class.
#define POPT_ARG_STRING
Definition: options_popt.h:57
#define POPT_ARG_NONE
Definition: options_popt.h:56
bool fDoHDMIOutput
If true, enable HDMI output; otherwise, disable HDMI output.
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.
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:225