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 "ntv2streamplayer.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 * pFramesSpec (AJA_NULL); // AutoCirculate frames spec
33  char * pAncFilePath (AJA_NULL); // Anc data filepath to play
34  char * pVideoFormat (AJA_NULL); // Video format to use
35  int channelNumber (1); // Channel/FrameStore to use
36  int doMultiFormat (0); // MultiFormat mode?
37  int showVersion (0); // Show version?
39 
40  // Command line option descriptions:
41  const CNTV2DemoCommon::PoptOpts optionsTable [] =
42  {
43  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
44  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
45  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
46  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
47  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
48  {"frames", 0, POPT_ARG_STRING, &pFramesSpec, 0, "frames to Stream", "num[@min] or min-max" },
49  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list" },
52  };
53  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
54  if (!popt)
55  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
56  if (!popt.otherArgs().empty())
57  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
58  if (showVersion)
59  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
60 
61  // Device
62  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
63  PlayerConfig config(deviceSpec);
64 
65  // Channel
66  if ((channelNumber < 1) || (channelNumber > 8))
67  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
68  config.fOutputChannel = NTV2Channel(channelNumber - 1);
69 
70  // VideoFormat
71  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
72  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
74  if (videoFormatStr == "?" || videoFormatStr == "list")
75  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
76  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
77  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
79  return 2;
80  }
81 
82  // Pixel Format
83  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
84  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
85  if (pixelFormatStr == "?" || pixelFormatStr == "list")
86  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
87  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
88  {
89  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
91  return 2;
92  }
93 
94  // AutoCirculate Frames
95  static const string legalFramesSpec ("{frameCount}[@{firstFrameNum}] or {firstFrameNum}-{lastFrameNum}");
96  const string framesSpec (pFramesSpec ? pFramesSpec : "");
97  if (!framesSpec.empty())
98  {
99  const string parseResult(config.fFrames.setFromString(framesSpec));
100  if (!parseResult.empty())
101  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## " << parseResult << endl; return 1;}
102  }
103  if (!config.fFrames.valid())
104  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## Expected " << legalFramesSpec << endl; return 1;}
105 
106  // Anc Playback
107  string ancFilePath (pAncFilePath ? pAncFilePath : "");
108  ancFilePath = aja::strip(ancFilePath);
109 
110  config.fAncDataFilePath = ancFilePath;
112  config.fSuppressAudio = true;
113  config.fSuppressVideo = false;
114  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
115  config.fTransmitLTC = false;
116 
117  { // Instantiate and initialize the NTV2StreamPlayer object...
118  NTV2StreamPlayer player(config);
119  AJAStatus status = player.Init();
120  if (AJA_FAILURE(status))
121  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
122 
123  ::signal (SIGINT, SignalHandler);
124  #if defined(AJAMac)
125  ::signal (SIGHUP, SignalHandler);
126  ::signal (SIGQUIT, SignalHandler);
127  #endif
128 
129  // Run it...
130  player.Run();
131 
132  cout << " Active Repeat Queue" << endl
133  << " Count Count Depth" << endl;
134  do
135  { // Poll its status until stopped...
136  NTV2StreamChannel strStatus;
137  player.GetStreamStatus(strStatus);
138  cout << setw(9) << strStatus.mActiveCount
139  << setw(9) << strStatus.mRepeatCount
140  << setw(9) << strStatus.GetQueueDepth() << "\r" << flush;
141  AJATime::Sleep(2000);
142  } while (player.IsRunning() && !gGlobalQuit); // loop til done
143  cout << endl;
144  } // NTV2StreamPlayer scope
145  return 0;
146 
147 } // main
virtual bool IsRunning(void) const
int main(int argc, const char **argv)
Definition: main.cpp:30
bool fSuppressAudio
If true, suppress audio; otherwise generate & xfer audio tone.
ULWord64 mActiveCount
Number of active transfers.
I play out SD or HD test pattern (with timecode) to an output of an AJA device with or without audio ...
AJAStatus
Definition: types.h:380
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
NTV2OutputDestination NTV2ChannelToOutputDestination(const NTV2Channel inChannel, const NTV2IOKinds inKinds=NTV2_IOKINDS_SDI)
Converts the given NTV2Channel value into its ordinary equivalent NTV2OutputDestination.
Definition: ntv2utils.cpp:5170
#define AJA_FAILURE(_status_)
Definition: types.h:373
virtual AJAStatus Run(void)
Runs me.
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())
std::string setFromString(const std::string &inStr)
Definition: ntv2utils.cpp:4256
Definition: json.hpp:5362
#define POPT_ARG_INT
Definition: options_popt.h:58
void SignalHandler(int inSignal)
Definition: main.cpp:26
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
bool fTransmitLTC
If true, embed LTC; otherwise embed VITC.
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
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
NTV2PixelFormat fPixelFormat
The pixel format to use.
virtual const std::string & errorStr(void) const
static bool gGlobalQuit((0))
NTV2VideoFormat fVideoFormat
The video format to use.
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
NTV2OutputDest fOutputDest
The desired output connector to use.
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
ULWord64 mRepeatCount
Number of repeated transfers.
std::string & strip(std::string &str, const std::string &ws)
Definition: common.cpp:461
virtual void GetStreamStatus(NTV2StreamChannel &outStatus)
Provides status information about my output (playout) process.
NTV2Channel fOutputChannel
The device channel to use.
#define POPT_TABLEEND
Definition: options_popt.h:222
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:987
Configures an NTV2Player instance.
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
bool valid(void) const
Definition: ntv2utils.h:987
#define POPT_ARG_STRING
Definition: options_popt.h:57
#define POPT_ARG_NONE
Definition: options_popt.h:56
ULWord GetQueueDepth(void)
Gets the queue depth.
bool fSuppressVideo
If true, suppress video; otherwise generate & xfer test patterns.
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
std::string fAncDataFilePath
Optional path to Anc binary data file to playout.