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 "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 (!popt.otherArgs().empty())
47  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
48  if (showVersion)
49  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
50 
51  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
52  TestPatConfig config(deviceSpec);
53  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
54 
55  // Channel
56  if ((channelNumber < 1) || (channelNumber > 8))
57  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
58  config.fOutputChannel = NTV2Channel(channelNumber - 1);
59 
60  // VideoFormat
61  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
63  if (videoFormatStr == "?" || videoFormatStr == "list")
64  {cout << CNTV2DemoCommon::GetVideoFormatStrings(vfKinds, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
65  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
67  vfKinds,
68  deviceSpec);
69  if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
70  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
71  << CNTV2DemoCommon::GetVideoFormatStrings(vfKinds, deviceSpec) << endl;
72  return 2;
73  }
74 
75  // Pixel Format
76  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
77  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
78  if (pixelFormatStr == "?" || pixelFormatStr == "list")
79  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
80  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
81  {
82  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
84  return 2;
85  }
86 
87  // Pattern
88  string tpSpec(pTestPattern ? pTestPattern : "");
89  aja::lower(tpSpec);
90  if (tpSpec == "?" || tpSpec == "list")
91  {cout << CNTV2DemoCommon::GetTestPatternStrings() << endl; return 0;}
92  if (!tpSpec.empty())
93  {
95  if (config.fTestPatternName.empty())
96  {
97  cerr << "## ERROR: Invalid '--pattern' value '" << tpSpec << "' -- expected values:" << endl
99  return 2;
100  }
101  }
102 
103  // VANC Mode
104  string vancStr (pVancMode ? pVancMode : "");
105  aja::lower(vancStr);
106  if (vancStr == "?" || vancStr == "list")
107  {cout << CNTV2DemoCommon::GetVANCModeStrings() << endl; return 0;}
108  if (videoFormatStr.empty() && !vancStr.empty())
109  {cerr << "## ERROR: '--vanc' option also requires --videoFormat option" << endl; return 2;}
110  if (!vancStr.empty())
111  {
113  if (!NTV2_IS_VALID_VANCMODE(config.fVancMode))
114  { cerr << "## ERROR: Invalid '--vanc' value '" << vancStr << "' -- expected values: " << endl
116  return 2;
117  }
118  }
119 
120  { // Instantiate and initialize the NTV2OutputTestPattern object...
121  NTV2OutputTestPattern player(config);
122  AJAStatus status = player.Init();
123  if (AJA_FAILURE(status))
124  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
125 
126  // Write the test pattern to the device and make it visible on the output...
127  status = player.EmitPattern();
128  if (AJA_FAILURE(status))
129  {cout << "## ERROR: EmitPattern failed: " << ::AJAStatusToString(status) << endl; return 2;}
130 
131  // Pause and wait for user to press Return or Enter...
132  cout << "## NOTE: Press Enter or Return to exit..." << endl;
133  cin.get();
134  } // NTV2OutputTestPattern scope
135 
136  return 0;
137 
138 } // main
static std::string GetTestPatternNameFromString(const std::string &inStr)
int main(int argc, const char **argv)
Definition: main.cpp:30
AJAStatus Init(void)
Initializes me and prepares me to Run.
AJAStatus
Definition: types.h:380
NTV2VANCMode fVancMode
VANC mode to use.
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
Configures an NTV2OutputTestPattern instance.
std::string fTestPatternName
Name of the test pattern to use.
#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())
Definition: json.hpp:5362
static std::string GetTestPatternStrings(void)
#define POPT_ARG_INT
Definition: options_popt.h:58
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1359
#define POPT_AUTOHELP
Definition: options_popt.h:227
#define true
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
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
NTV2PixelFormat fPixelFormat
The pixel format to use.
virtual const std::string & errorStr(void) const
NTV2VideoFormat fVideoFormat
The video format to use.
static NTV2VANCMode GetVANCModeFromString(const std::string &inStr)
AJAStatus EmitPattern(void)
Generates, transfers and displays the test pattern on the output.
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
NTV2Channel fOutputChannel
The device channel to use.
#define POPT_TABLEEND
Definition: options_popt.h:222
I generate and transfer a test pattern into an AJA device&#39;s frame buffer for steady-state playout usi...
ULWord NTV2VideoFormatKinds
Private include file for all ajabase sources.
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:987
static std::string GetVANCModeStrings(void)
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
#define NTV2_IS_VALID_VANCMODE(__v__)
Definition: ntv2enums.h:3808
std::string & lower(std::string &str)
Definition: common.cpp:436
#define POPT_ARG_STRING
Definition: options_popt.h:57
#define POPT_ARG_NONE
Definition: options_popt.h:56
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.
See 8-Bit YCbCr Format.
Definition: ntv2enums.h:225