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 "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
67  deviceSpec);
68  if (videoFormatStr == "?" || videoFormatStr == "list")
69  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_SDHD, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
70  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
71  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
73  return 2;
74  }
75 
76  // Pixel Format
77  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
78  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
79  if (pixelFormatStr == "?" || pixelFormatStr == "list")
80  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
81  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
82  {
83  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
85  return 2;
86  }
87 
88  // Pattern
89  string tpSpec(pTestPattern ? pTestPattern : "");
90  aja::lower(tpSpec);
91  if (tpSpec == "?" || tpSpec == "list")
92  {cout << CNTV2DemoCommon::GetTestPatternStrings() << endl; return 0;}
93  if (!tpSpec.empty())
94  {
96  if (config.fTestPatternName.empty())
97  {
98  cerr << "## ERROR: Invalid '--pattern' value '" << tpSpec << "' -- expected values:" << endl
100  return 2;
101  }
102  }
103 
104  // VANC Mode
105  string vancStr (pVancMode ? pVancMode : "");
106  aja::lower(vancStr);
107  if (vancStr == "?" || vancStr == "list")
108  {cout << CNTV2DemoCommon::GetVANCModeStrings() << endl; return 0;}
109  if (videoFormatStr.empty() && !vancStr.empty())
110  {cerr << "## ERROR: '--vanc' option also requires --videoFormat option" << endl; return 2;}
111  if (!vancStr.empty())
112  {
114  if (!NTV2_IS_VALID_VANCMODE(config.fVancMode))
115  { cerr << "## ERROR: Invalid '--vanc' value '" << vancStr << "' -- expected values: " << endl
117  return 2;
118  }
119  }
120 
121  // Create the object that will display the test pattern...
122  NTV2OutputTestPattern player(config);
123  AJAStatus status = player.Init();
124  if (AJA_FAILURE(status))
125  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
126 
127  // Write the test pattern to the device and make it visible on the output...
128  status = player.EmitPattern();
129  if (AJA_FAILURE(status))
130  {cout << "## ERROR: EmitPattern failed: " << ::AJAStatusToString(status) << endl; return 2;}
131 
132  // Pause and wait for user to press Return or Enter...
133  cout << "## NOTE: Press Enter or Return to exit..." << endl;
134  cin.get();
135 
136  return 0;
137 
138 } // 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
ntv2outputtestpattern.h
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
CNTV2DemoCommon::GetVANCModeFromString
static NTV2VANCMode GetVANCModeFromString(const std::string &inStr)
Definition: ntv2democommon.cpp:989
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1334
TestPatConfig
Configures an NTV2OutputTestPattern instance.
Definition: ntv2outputtestpattern.h:18
NTV2_FORMAT_1080i_5994
@ NTV2_FORMAT_1080i_5994
Definition: ntv2enums.h:535
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
PlayerConfig::fVancMode
NTV2VANCMode fVancMode
VANC mode to use.
Definition: ntv2democommon.h:329
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
VIDEO_FORMATS_4KUHD
@ VIDEO_FORMATS_4KUHD
Definition: ntv2democommon.h:226
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:455
AJAStatus
AJAStatus
Definition: types.h:378
CNTV2DemoCommon::GetTestPatternStrings
static std::string GetTestPatternStrings(void)
Definition: ntv2democommon.cpp:996
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::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDevSpec=std::string())
Definition: ntv2democommon.cpp:605
PlayerConfig::fVideoFormat
NTV2VideoFormat fVideoFormat
The video format to use.
Definition: ntv2democommon.h:328
CNTV2DemoCommon::GetVANCModeStrings
static std::string GetVANCModeStrings(void)
Definition: ntv2democommon.cpp:958
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
CNTV2DemoCommon::GetTestPatternNameFromString
static std::string GetTestPatternNameFromString(const std::string &inStr)
Definition: ntv2democommon.cpp:1024
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:199
NTV2_FORMAT_UNKNOWN
@ NTV2_FORMAT_UNKNOWN
Definition: ntv2enums.h:521
VIDEO_FORMATS_SDHD
@ VIDEO_FORMATS_SDHD
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
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
NTV2_IS_VALID_VANCMODE
#define NTV2_IS_VALID_VANCMODE(__v__)
Definition: ntv2enums.h:3758
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