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 */
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 (showVersion)
62  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
63 
64  // Device
65  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
66  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
67  return 1;
68 
69  PlayerConfig config(deviceSpec);
70 
71  // Channel
72  if ((channelNumber < 1) || (channelNumber > 8))
73  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
74  config.fOutputChannel = NTV2Channel(channelNumber - 1);
75 
76  // VideoFormat
77  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
78  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_4x3840x2160p_2398
80  if (videoFormatStr == "?" || videoFormatStr == "list")
81  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_8KUHD2, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
82  else if (!videoFormatStr.empty() && !NTV2_IS_8K_VIDEO_FORMAT(config.fVideoFormat))
83  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
85  return 2;
86  }
87 
88  // Pixel Format
89  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
90  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
91  if (pixelFormatStr == "?" || pixelFormatStr == "list")
92  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
93  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
94  {
95  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
97  return 2;
98  }
99 
100  // Anc Playback
101  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
102  config.fDoHDMIOutput = useHDMIOut ? true : false;
103  config.fDoTsiRouting = doSquares ? false : true;
104  config.fDoRGBOnWire = doRGBOnWire ? true : false;
105  config.fNumAudioLinks = UWord(numAudioLinks);
106 
107  // Instantiate and initialize the NTV2Player8K object...
108  NTV2Player8K player(config);
109  AJAStatus status = player.Init();
110  if (AJA_FAILURE(status))
111  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
112 
113  ::signal (SIGINT, SignalHandler);
114  #if defined(AJAMac)
115  ::signal (SIGHUP, SignalHandler);
116  ::signal (SIGQUIT, SignalHandler);
117  #endif
118 
119  // Run it...
120  player.Run();
121 
122  cout << " Frames Frames Buffer" << endl
123  << " Played Dropped Level" << endl;
124  do
125  { // Poll its status until stopped...
126  AUTOCIRCULATE_STATUS outputStatus;
127  player.GetACStatus(outputStatus);
128  cout << setw(9) << outputStatus.GetProcessedFrameCount()
129  << setw(9) << outputStatus.GetDroppedFrameCount()
130  << setw(9) << outputStatus.GetBufferLevel() << "\r" << flush;
131  AJATime::Sleep(2000);
132  } while (player.IsRunning() && !gGlobalQuit); // loop til done
133 
134  cout << endl;
135  return 0;
136 
137 } // main
CNTV2DemoCommon::GetVideoFormatFromString
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.
Definition: ntv2democommon.cpp:553
VIDEO_FORMATS_8KUHD2
@ VIDEO_FORMATS_8KUHD2
Definition: ntv2democommon.h:227
PlayerConfig::fDoHDMIOutput
bool fDoHDMIOutput
If true, enable HDMI output; otherwise, disable HDMI output.
Definition: ntv2democommon.h:337
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
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1334
ntv2player8k.h
Header file for NTV2Player8K demonstration class.
gGlobalQuit
static bool gGlobalQuit((0))
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
AUTOCIRCULATE_STATUS::GetProcessedFrameCount
ULWord GetProcessedFrameCount(void) const
Definition: ntv2publicinterface.h:7249
AUTOCIRCULATE_STATUS::GetBufferLevel
ULWord GetBufferLevel(void) const
Definition: ntv2publicinterface.h:7254
main
int main(int argc, const char **argv)
Definition: main.cpp:30
PlayerConfig::fDoMultiFormat
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
Definition: ntv2democommon.h:332
NTV2_IS_8K_VIDEO_FORMAT
#define NTV2_IS_8K_VIDEO_FORMAT(__f__)
Definition: ntv2enums.h:875
NTV2_FORMAT_4x3840x2160p_2398
@ NTV2_FORMAT_4x3840x2160p_2398
Definition: ntv2enums.h:678
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
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
VIDEO_FORMATS_4KUHD
@ VIDEO_FORMATS_4KUHD
Definition: ntv2democommon.h:226
PlayerConfig::fDoTsiRouting
bool fDoTsiRouting
If true, enable TSI routing; otherwise route for square division (4K/8K)
Definition: ntv2democommon.h:338
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
NTV2Player8K
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
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
AUTOCIRCULATE_STATUS
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
Definition: ntv2publicinterface.h:7193
PlayerConfig::fNumAudioLinks
UWord fNumAudioLinks
The number of audio systems to control for multi-link audio (4K/8K)
Definition: ntv2democommon.h:331
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:605
UWord
uint16_t UWord
Definition: ajatypes.h:253
PlayerConfig::fVideoFormat
NTV2VideoFormat fVideoFormat
The video format to use.
Definition: ntv2democommon.h:328
NTV2_FBF_8BIT_YCBCR
@ NTV2_FBF_8BIT_YCBCR
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:214
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:848
PlayerConfig::fOutputChannel
NTV2Channel fOutputChannel
The device channel to use.
Definition: ntv2democommon.h:324
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
CNTV2DemoCommon::GetVideoFormatStrings
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_SDHD, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:523
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:199
NTV2Player8K::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2player8k.cpp:600
PlayerConfig::fDoRGBOnWire
bool fDoRGBOnWire
If true, produce RGB on the wire; otherwise output YUV.
Definition: ntv2democommon.h:339
false
#define false
Definition: ntv2devicefeatures.h:25
std
Definition: json.hpp:5362
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:981
AUTOCIRCULATE_STATUS::GetDroppedFrameCount
ULWord GetDroppedFrameCount(void) const
Definition: ntv2publicinterface.h:7244
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
NTV2Player8K::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2player8k.cpp:107
NTV2Player8K::GetACStatus
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outStatus)
Provides status information about my output (playout) process.
Definition: ntv2player8k.cpp:868
PlayerConfig
Configures an NTV2Player instance.
Definition: ntv2democommon.h:319
PlayerConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:327
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
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:252