AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
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 doMultiFormat (0); // MultiFormat mode?
26  int showVersion (0); // Show version?
28 
29  // Command line option descriptions:
30  const CNTV2DemoCommon::PoptOpts optionsTable [] =
31  {
32  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
33  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
34  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
35  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
36  {"pattern", 'p', POPT_ARG_STRING, &pTestPattern, 0, "test pattern to show", "0-15, name or '?' to list" },
37  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list"},
38  {"pixelFormat", 0, POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list"},
39  {"vanc", 0, POPT_ARG_STRING, &pVancMode, 0, "vanc mode", "off|none|0|on|tall|1|taller|tallest|2"},
42  };
43  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
44  if (!popt)
45  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
46  if (showVersion)
47  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
48 
49  // Device
50  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
51  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
52  return 1;
53 
54  TestPatConfig config(deviceSpec);
55  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
56 
57  // Channel
58  if ((channelNumber < 1) || (channelNumber > 8))
59  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
60  config.fOutputChannel = NTV2Channel(channelNumber - 1);
61 
62  // VideoFormat
63  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
64  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
66  if (videoFormatStr == "?" || videoFormatStr == "list")
67  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_NON_4KUHD, deviceSpec) << endl; return 0;}
68  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
69  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
71  return 2;
72  }
73 
74  // Pixel Format
75  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
76  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
77  if (pixelFormatStr == "?" || pixelFormatStr == "list")
78  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
79  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
80  {
81  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
83  return 2;
84  }
85 
86  // Pattern
87  string tpSpec(pTestPattern ? pTestPattern : "");
88  aja::lower(tpSpec);
89  if (tpSpec == "?" || tpSpec == "list")
90  {cout << CNTV2DemoCommon::GetTestPatternStrings() << endl; return 0;}
91  if (!tpSpec.empty())
92  {
94  if (config.fTestPatternName.empty())
95  {
96  cerr << "## ERROR: Invalid '--pattern' value '" << tpSpec << "' -- expected values:" << endl
98  return 2;
99  }
100  }
101 
102  // VANC Mode
103  string vancStr (pVancMode ? pVancMode : "");
104  aja::lower(vancStr);
105  if (vancStr == "?" || vancStr == "list")
106  {cout << CNTV2DemoCommon::GetVANCModeStrings() << endl; return 0;}
107  if (videoFormatStr.empty() && !vancStr.empty())
108  {cerr << "## ERROR: '--vanc' option also requires --videoFormat option" << endl; return 2;}
109  if (!vancStr.empty())
110  {
112  if (!NTV2_IS_VALID_VANCMODE(config.fVancMode))
113  { cerr << "## ERROR: Invalid '--vanc' value '" << vancStr << "' -- expected values: " << endl
115  return 2;
116  }
117  }
118 
119  // Create the object that will display the test pattern...
120  NTV2OutputTestPattern player(config);
121  AJAStatus status = player.Init();
122  if (AJA_FAILURE(status))
123  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
124 
125  // Write the test pattern to the device and make it visible on the output...
126  status = player.EmitPattern();
127  if (AJA_FAILURE(status))
128  {cout << "## ERROR: EmitPattern failed: " << ::AJAStatusToString(status) << endl; return 2;}
129 
130  // Pause and wait for user to press Return or Enter...
131  cout << "## NOTE: Press Enter or Return to exit..." << endl;
132  cin.get();
133 
134  return 0;
135 
136 } // main
CNTV2DemoCommon::GetVideoFormatStrings
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_NON_4KUHD, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:550
ntv2outputtestpattern.h
poptOption
Definition: options_popt.h:148
CNTV2DemoCommon::GetVANCModeFromString
static NTV2VANCMode GetVANCModeFromString(const std::string &inStr)
Definition: ntv2democommon.cpp:882
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
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::fDoMultiFormat
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
Definition: ntv2democommon.h:323
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:635
NTV2OutputTestPattern::EmitPattern
AJAStatus EmitPattern(void)
Generates, transfers and displays the test pattern on the output.
Definition: ntv2outputtestpattern.cpp:235
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
CNTV2DemoCommon::IsValidDevice
static bool IsValidDevice(const std::string &inDeviceSpec)
Definition: ntv2democommon.cpp:430
AJAStatus
AJAStatus
Definition: types.h:378
CNTV2DemoCommon::GetTestPatternStrings
static std::string GetTestPatternStrings(void)
Definition: ntv2democommon.cpp:889
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:653
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:851
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:917
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:197
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
std
Definition: json.hpp:5362
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:981
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
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:600
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:371
NTV2_IS_VALID_VANCMODE
#define NTV2_IS_VALID_VANCMODE(__v__)
Definition: ntv2enums.h:3724
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56