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 */
9 // Includes
10 #include "ntv2outputtestpattern.h"
11 #include "ajabase/common/common.h"
12 
13 
14 using namespace std;
15 
16 
17 int main (int argc, const char ** argv)
18 {
19  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
20  char * pPixelFormat (AJA_NULL); // Pixel format argument
21  char * pTestPattern (AJA_NULL); // Test pattern argument
22  char * pVancMode (AJA_NULL); // VANC mode argument
23  char * pVideoFormat (AJA_NULL); // Video format to use
24  int channelNumber (1); // Channel/FrameStore to use
25  int showVersion (0); // Show version?
27 
28  // Command line option descriptions:
29  const CNTV2DemoCommon::PoptOpts optionsTable [] =
30  {
31  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
32  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
33  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
34  {"pattern", 'p', POPT_ARG_STRING, &pTestPattern, 0, "test pattern to show", "0-15, name or '?' to list" },
35  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list"},
36  {"pixelFormat", 0, POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list"},
37  {"vanc", 0, POPT_ARG_STRING, &pVancMode, 0, "vanc mode", "off|none|0|on|tall|1|taller|tallest|2"},
40  };
41  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
42  if (!popt)
43  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
44  if (showVersion)
45  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
46 
47  // Device
48  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
49  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
50  return 1;
51 
52  TestPatConfig config(deviceSpec);
53 
54  // Channel
55  if ((channelNumber < 1) || (channelNumber > 8))
56  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
57  config.fOutputChannel = NTV2Channel(channelNumber - 1);
58 
59  // VideoFormat
60  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
61  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
63  if (videoFormatStr == "?" || videoFormatStr == "list")
64  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_NON_4KUHD, deviceSpec) << endl; return 0;}
65  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
66  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
68  return 2;
69  }
70 
71  // Pixel Format
72  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
73  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
74  if (pixelFormatStr == "?" || pixelFormatStr == "list")
75  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
76  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
77  {
78  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
80  return 2;
81  }
82 
83  // Pattern
84  string tpSpec(pTestPattern ? pTestPattern : "");
85  aja::lower(tpSpec);
86  if (tpSpec == "?" || tpSpec == "list")
87  {cout << CNTV2DemoCommon::GetTestPatternStrings() << endl; return 0;}
88  if (!tpSpec.empty())
89  {
91  if (config.fTestPatternName.empty())
92  {
93  cerr << "## ERROR: Invalid '--pattern' value '" << tpSpec << "' -- expected values:" << endl
95  return 2;
96  }
97  }
98 
99  // VANC Mode
100  string vancStr (pVancMode ? pVancMode : "");
101  aja::lower(vancStr);
102  if (vancStr == "?" || vancStr == "list")
103  {cout << CNTV2DemoCommon::GetVANCModeStrings() << endl; return 0;}
104  if (videoFormatStr.empty() && !vancStr.empty())
105  {cerr << "## ERROR: '--vanc' option also requires --videoFormat option" << endl; return 2;}
106  if (!vancStr.empty())
107  {
109  if (!NTV2_IS_VALID_VANCMODE(config.fVancMode))
110  { cerr << "## ERROR: Invalid '--vanc' value '" << vancStr << "' -- expected values: " << endl
112  return 2;
113  }
114  }
115 
116  // Create the object that will display the test pattern...
117  NTV2OutputTestPattern player(config);
118  AJAStatus status = player.Init();
119  if (AJA_FAILURE(status))
120  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
121 
122  // Write the test pattern to the device and make it visible on the output...
123  status = player.EmitPattern();
124  if (AJA_FAILURE(status))
125  {cout << "## ERROR: EmitPattern failed: " << ::AJAStatusToString(status) << endl; return 2;}
126 
127  // Pause and wait for user to press Return or Enter...
128  cout << "## NOTE: Press Enter or Return to exit..." << endl;
129  cin.get();
130 
131  return 0;
132 
133 } // main
CNTV2DemoCommon::GetVideoFormatStrings
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_NON_4KUHD, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:553
ntv2outputtestpattern.h
poptOption
Definition: options_popt.h:148
CNTV2DemoCommon::GetVANCModeFromString
static NTV2VANCMode GetVANCModeFromString(const std::string &inStr)
Definition: ntv2democommon.cpp:893
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific Frame Store. They're also commonly used to i...
Definition: ntv2enums.h:1305
TestPatConfig
Configures an NTV2OutputTestPattern instance.
Definition: ntv2outputtestpattern.h:18
NTV2_FORMAT_1080i_5994
@ NTV2_FORMAT_1080i_5994
Definition: ntv2enums.h:512
main
int main(int argc, const char **argv)
Definition: main.cpp:30
PlayerConfig::fVancMode
NTV2VANCMode fVancMode
VANC mode to use.
Definition: ntv2democommon.h:320
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
CNTV2DemoCommon::GetVideoFormatFromString
static NTV2VideoFormat GetVideoFormatFromString(const std::string &inStr, const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_NON_4KUHD)
Returns the NTV2VideoFormat that matches the given string.
Definition: ntv2democommon.cpp:642
NTV2OutputTestPattern::EmitPattern
AJAStatus EmitPattern(void)
Generates, transfers and displays the test pattern on the output.
Definition: ntv2outputtestpattern.cpp:230
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
CNTV2DemoCommon::GetTestPatternStrings
static std::string GetTestPatternStrings(void)
Definition: ntv2democommon.cpp:900
aja::lower
std::string & lower(std::string &str)
Definition: common.cpp:436
TestPatConfig::fTestPatternName
std::string fTestPatternName
Name of the test pattern to use.
Definition: ntv2outputtestpattern.h:21
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
PlayerConfig::fVideoFormat
NTV2VideoFormat fVideoFormat
The video format to use.
Definition: ntv2democommon.h:319
CNTV2DemoCommon::GetVANCModeStrings
static std::string GetVANCModeStrings(void)
Definition: ntv2democommon.cpp:862
NTV2_FBF_8BIT_YCBCR
@ NTV2_FBF_8BIT_YCBCR
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:211
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:801
PlayerConfig::fOutputChannel
NTV2Channel fOutputChannel
The device channel to use.
Definition: ntv2democommon.h:315
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
CNTV2DemoCommon::GetTestPatternNameFromString
static std::string GetTestPatternNameFromString(const std::string &inStr)
Definition: ntv2democommon.cpp:928
NTV2OutputTestPattern::Init
AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2outputtestpattern.cpp:58
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
NTV2_FORMAT_UNKNOWN
@ NTV2_FORMAT_UNKNOWN
Definition: ntv2enums.h:498
VIDEO_FORMATS_NON_4KUHD
@ VIDEO_FORMATS_NON_4KUHD
Definition: ntv2democommon.h:225
common.h
Private include file for all ajabase sources.
NTV2OutputTestPattern
I generate and transfer a test pattern into an AJA device's frame buffer for steady-state playout usi...
Definition: ntv2outputtestpattern.h:43
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:980
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:603
PlayerConfig::fPixelFormat
NTV2PixelFormat fPixelFormat
The pixel format to use.
Definition: ntv2democommon.h:318
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
NTV2_IS_VALID_VANCMODE
#define NTV2_IS_VALID_VANCMODE(__v__)
Definition: ntv2enums.h:3719
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56