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 "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?
38  int hdrType (0); // Transmit HDR anc?
39  int noAudio (0); // Disable audio tone?
40  int noVideo (0); // Disable video?
41  int xmitLTC (0); // Use LTC? (Defaults to VITC)
43 
44  // Command line option descriptions:
45  const CNTV2DemoCommon::PoptOpts optionsTable [] =
46  {
47  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
48  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
49  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8" },
50  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
51  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
52  {"frames", 0, POPT_ARG_STRING, &pFramesSpec, 0, "frames to AutoCirculate", "num[@min] or min-max" },
53  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list" },
54  {"hdrType", 't', POPT_ARG_INT, &hdrType, 0, "HDR pkt to send", "0=none 1=SDR 2=HDR10 3=HLG"},
55  {"anc", 'a', POPT_ARG_STRING, &pAncFilePath, 0, "play prerecorded anc", "path/to/binary/data/file" },
56  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio tone", AJA_NULL },
57  {"novideo", 0, POPT_ARG_NONE, &noVideo, 0, "disable video tone", AJA_NULL },
58  {"ltc", 'l', POPT_ARG_NONE, &xmitLTC, 0, "xmit LTC instead of VITC", AJA_NULL },
61  };
62  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
63  if (!popt)
64  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
65  if (showVersion)
66  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
67 
68  // Device
69  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
70  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
71  return 1;
72 
73  PlayerConfig config(deviceSpec);
74 
75  // Channel
76  if ((channelNumber < 1) || (channelNumber > 8))
77  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 1 thru 8" << endl; return 1;}
78  config.fOutputChannel = NTV2Channel(channelNumber - 1);
79 
80  // VideoFormat
81  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
82  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
84  if (videoFormatStr == "?" || videoFormatStr == "list")
85  {cout << CNTV2DemoCommon::GetVideoFormatStrings(VIDEO_FORMATS_NON_4KUHD, deviceSpec) << endl; return 0;}
86  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
87  { cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
89  return 2;
90  }
91 
92  // Pixel Format
93  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
94  config.fPixelFormat = pixelFormatStr.empty() ? NTV2_FBF_8BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString(pixelFormatStr);
95  if (pixelFormatStr == "?" || pixelFormatStr == "list")
96  {cout << CNTV2DemoCommon::GetPixelFormatStrings(PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
97  else if (!pixelFormatStr.empty() && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT(config.fPixelFormat))
98  {
99  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
101  return 2;
102  }
103 
104  // AutoCirculate Frames
105  static const string legalFramesSpec ("{frameCount}[@{firstFrameNum}] or {firstFrameNum}-{lastFrameNum}");
106  const string framesSpec (pFramesSpec ? pFramesSpec : "");
107  if (!framesSpec.empty())
108  {
109  const string parseResult(config.fFrames.setFromString(framesSpec));
110  if (!parseResult.empty())
111  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## " << parseResult << endl; return 1;}
112  }
113  if (!config.fFrames.valid())
114  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## Expected " << legalFramesSpec << endl; return 1;}
115 
116  if (noVideo && noAudio)
117  {cerr << "## ERROR: conflicting options '--novideo' and '--noaudio'" << endl; return 1;}
118 
119  // Anc Playback & HDRType
120  string ancFilePath (pAncFilePath ? pAncFilePath : "");
121  ancFilePath = aja::strip(ancFilePath);
122  config.fTransmitHDRType = hdrType == 1 ? AJAAncDataType_HDR_SDR
123  : (hdrType == 2 ? AJAAncDataType_HDR_HDR10
124  : (hdrType == 3 ? AJAAncDataType_HDR_HLG
126  if (config.fTransmitHDRType != AJAAncDataType_Unknown && !ancFilePath.empty())
127  {cerr << "## ERROR: conflicting options '--hdrType' and '--anc'" << endl; return 2;}
128 
129  config.fAncDataFilePath = ancFilePath;
131  config.fSuppressAudio = noAudio ? true : false;
132  config.fSuppressVideo = noVideo ? true : false;
133  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
134  config.fTransmitLTC = xmitLTC ? true : false;
135 
136  // Instantiate and initialize the NTV2StreamPlayer object...
137  NTV2StreamPlayer player(config);
138  AJAStatus status = player.Init();
139  if (AJA_FAILURE(status))
140  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
141 
142  ::signal (SIGINT, SignalHandler);
143  #if defined(AJAMac)
144  ::signal (SIGHUP, SignalHandler);
145  ::signal (SIGQUIT, SignalHandler);
146  #endif
147 
148  // Run it...
149  player.Run();
150 
151  cout << " Frames Frames Buffer" << endl
152  << " Played Dropped Level" << endl;
153  do
154  { // Poll its status until stopped...
155  NTV2StreamChannel strStatus;
156  player.GetStreamStatus(strStatus);
157  cout << setw(9) << strStatus.mActiveCount
158  << setw(9) << strStatus.mRepeatCount
159  << setw(9) << strStatus.GetQueueDepth() << "\r" << flush;
160  AJATime::Sleep(2000);
161  } while (player.IsRunning() && !gGlobalQuit); // loop til done
162 
163  cout << endl;
164  return 0;
165 
166 } // main
CNTV2DemoCommon::GetVideoFormatStrings
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_NON_4KUHD, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:553
NTV2StreamChannel
Definition: ntv2publicinterface.h:8701
poptOption
Definition: options_popt.h:148
AJAAncDataType_Unknown
@ AJAAncDataType_Unknown
Includes data that is valid, but we don't recognize.
Definition: ancillarydata.h:46
aja::strip
std::string & strip(std::string &str, const std::string &ws)
Definition: common.cpp:461
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
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
NTV2StreamChannel::GetQueueDepth
ULWord GetQueueDepth(void)
Gets the queue depth.
Definition: ntv2publicinterface.h:8733
NTV2_FORMAT_1080i_5994
@ NTV2_FORMAT_1080i_5994
Definition: ntv2enums.h:512
NTV2StreamPlayer::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2streamplayer.cpp:109
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
NTV2StreamPlayer
I play out SD or HD test pattern (with timecode) to an output of an AJA device with or without audio ...
Definition: ntv2streamplayer.h:24
NTV2ACFrameRange::setFromString
std::string setFromString(const std::string &inStr)
Definition: ntv2utils.cpp:4155
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
PlayerConfig::fTransmitHDRType
AJAAncDataType fTransmitHDRType
Specifies the HDR anc data packet to transmit, if any.
Definition: ntv2democommon.h:321
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
NTV2ChannelToOutputDestination
NTV2OutputDestination NTV2ChannelToOutputDestination(const NTV2Channel inChannel)
Converts the given NTV2Channel value into its ordinary equivalent NTV2OutputDestination.
Definition: ntv2utils.cpp:5225
PlayerConfig::fFrames
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
Definition: ntv2democommon.h:317
AJATime::Sleep
static void Sleep(const int32_t inMilliseconds)
Suspends execution of the current thread for a given number of milliseconds.
Definition: systemtime.cpp:284
PlayerConfig::fSuppressAudio
bool fSuppressAudio
If true, suppress audio; otherwise generate audio tone.
Definition: ntv2democommon.h:324
CNTV2DemoCommon::GetPixelFormatFromString
static NTV2FrameBufferFormat GetPixelFormatFromString(const std::string &inStr)
Returns the NTV2FrameBufferFormat that matches the given string.
Definition: ntv2democommon.cpp:660
PlayerConfig::fSuppressVideo
bool fSuppressVideo
If true, suppress video; otherwise generate test patterns.
Definition: ntv2democommon.h:325
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:240
PlayerConfig::fVideoFormat
NTV2VideoFormat fVideoFormat
The video format to use.
Definition: ntv2democommon.h:319
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
PlayerConfig::fAncDataFilePath
std::string fAncDataFilePath
Optional path to Anc binary data file to playout.
Definition: ntv2democommon.h:314
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
AJAAncDataType_HDR_SDR
@ AJAAncDataType_HDR_SDR
Definition: ancillarydata.h:57
NTV2StreamPlayer::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2streamplayer.cpp:462
NTV2_FORMAT_UNKNOWN
@ NTV2_FORMAT_UNKNOWN
Definition: ntv2enums.h:498
PlayerConfig::fTransmitLTC
bool fTransmitLTC
If true, embed LTC; otherwise embed VITC.
Definition: ntv2democommon.h:326
VIDEO_FORMATS_NON_4KUHD
@ VIDEO_FORMATS_NON_4KUHD
Definition: ntv2democommon.h:225
PlayerConfig::fOutputDest
NTV2OutputDest fOutputDest
The desired output connector to use.
Definition: ntv2democommon.h:316
gGlobalQuit
static bool gGlobalQuit(false)
ntv2streamplayer.h
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:980
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
NTV2StreamChannel::mActiveCount
ULWord64 mActiveCount
Number of buffers active.
Definition: ntv2publicinterface.h:8713
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:603
AJAAncDataType_HDR_HLG
@ AJAAncDataType_HDR_HLG
Definition: ancillarydata.h:59
NTV2ACFrameRange::valid
bool valid(void) const
Definition: ntv2utils.h:977
PlayerConfig
Configures an NTV2Player instance.
Definition: ntv2democommon.h:310
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
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
NTV2StreamChannel::mRepeatCount
ULWord64 mRepeatCount
Number of buffer repeats.
Definition: ntv2publicinterface.h:8714
NTV2StreamPlayer::GetStreamStatus
virtual void GetStreamStatus(NTV2StreamChannel &outStatus)
Provides status information about my output (playout) process.
Definition: ntv2streamplayer.cpp:667
AJAAncDataType_HDR_HDR10
@ AJAAncDataType_HDR_HDR10
Definition: ancillarydata.h:58