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 */
8 // Includes
9 #include "ntv2dolbyplayer.h"
10 #include <signal.h>
11 
12 
13 using namespace std;
14 
15 
16 // Globals
17 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
18 
19 static void SignalHandler (int inSignal)
20 {
21  (void) inSignal;
22  gGlobalQuit = true;
23 }
24 
25 
26 int main (int argc, const char ** argv)
27 {
28  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
29  char * pPixelFormat (AJA_NULL); // Pixel format argument
30  char * pFramesSpec (AJA_NULL); // AutoCirculate frames spec
31  char * pDolbyFile (AJA_NULL); // Optional path to Dolby audio file
32  char * pVideoFormat (AJA_NULL); // Video format to use
33  int channelNumber (2); // Channel/FrameStore to use
34  int doMultiFormat (0); // MultiFormat mode?
35  int showVersion (0); // Show version?
36  int noAudio (0); // Disable audio tone?
37  int noVideo (0); // Disable video?
38  int doRamp (0); // Enable audio ramp
39  AJAStatus status;
40 
42 
43  // Command line option descriptions:
44  const struct poptOption optionsTable [] =
45  {
46  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
47  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
48  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "2-4" },
49  {"multiFormat", 'm', POPT_ARG_NONE, &doMultiFormat, 0, "use multi-format/channel", AJA_NULL },
50  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list" },
51  {"frames", 0, POPT_ARG_STRING, &pFramesSpec, 0, "frames to AutoCirculate", "num[@min] or min-max" },
52  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list" },
53  {"dolby", 0, POPT_ARG_STRING, &pDolbyFile, 0, "dolby audio to play", "path to binary file" },
54  {"ramp", 'r', POPT_ARG_NONE, &doRamp, 0, "audio data ramp", AJA_NULL },
55  {"noaudio", 0, POPT_ARG_NONE, &noAudio, 0, "disable audio", AJA_NULL },
56  {"novideo", 0, POPT_ARG_NONE, &noVideo, 0, "disable video", AJA_NULL },
59  };
60 
61  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
62  if (!popt)
63  {cerr << "## ERROR: " << popt.errorStr() << endl; return 2;}
64  if (!popt.otherArgs().empty())
65  {cerr << "## WARNING: ignored argument(s): '" << aja::join(popt.otherArgs(), "', '") << "'" << endl; return 2;}
66  if (showVersion)
67  {cout << argv[0] << ", NTV2 SDK " << ::NTV2Version() << endl; return 0;}
68 
69  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
70  DolbyPlayerConfig config(deviceSpec);
71 
72  // Channel
73  if ((channelNumber < 2) || (channelNumber > 4))
74  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 2 thru 4" << endl; return 1;}
75  config.fOutputChannel = NTV2Channel(channelNumber - 1);
76 
77  // VideoFormat
78  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
79  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
81  if (videoFormatStr == "?" || videoFormatStr == "list")
82  {cout << CNTV2DemoCommon::GetVideoFormatStrings (VIDEO_FORMATS_SDHD | VIDEO_FORMATS_4KUHD, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
83  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
84  {
85  cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
87  return 2;
88  }
89 
90  // Pixel Format
91  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
92  config.fPixelFormat = (pixelFormatStr.empty () ? NTV2_FBF_10BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString (pixelFormatStr));
93  if (pixelFormatStr == "?" || pixelFormatStr == "list")
94  {cout << CNTV2DemoCommon::GetPixelFormatStrings (PIXEL_FORMATS_ALL, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
95  else if (!pixelFormatStr.empty () && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT (config.fPixelFormat))
96  {
97  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
99  return 2;
100  }
101 
102  // AutoCirculate Frames
103  static const string legalFramesSpec ("{frameCount}[@{firstFrameNum}] or {firstFrameNum}-{lastFrameNum}");
104  const string framesSpec (pFramesSpec ? pFramesSpec : "");
105  if (!framesSpec.empty())
106  {
107  const string parseResult(config.fFrames.setFromString(framesSpec));
108  if (!parseResult.empty())
109  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## " << parseResult << endl; return 1;}
110  }
111  if (!config.fFrames.valid())
112  {cerr << "## ERROR: Bad 'frames' spec '" << framesSpec << "'\n## Expected " << legalFramesSpec << endl; return 1;}
113 
114  if (noVideo && noAudio)
115  {cerr << "## ERROR: conflicting options '--novideo' and '--noaudio'" << endl; return 1;}
116 
117  if (noAudio && doRamp)
118  {cerr << "## ERROR: conflicting options '--noaudio' and '--ramp'" << endl; return 1;}
119 
120  if (noAudio && pDolbyFile)
121  {cerr << "## ERROR: conflicting options '--noaudio' and '--dolby'" << endl; return 1;}
122 
123  if (doRamp && pDolbyFile)
124  {cerr << "## ERROR: conflicting options '--ramp' and '--dolby'" << endl; return 1;}
125 
126  //Remaining options for this demo
127  config.fSuppressAudio = noAudio ? true : false;
128  config.fSuppressVideo = noVideo ? true : false;
129  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
130  config.fDoRamp = doRamp ? true : false; // inDoRamp
131  config.fDoHDMIOutput = true;
132  config.fDolbyFilePath = pDolbyFile ? pDolbyFile : "";
133 
134  { // Instantiate and initialize the NTV2DolbyPlayer object...
135  NTV2DolbyPlayer player (config);
136  status = player.Init();
137  if (AJA_FAILURE(status))
138  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
139 
140  ::signal (SIGINT, SignalHandler);
141  #if defined (AJAMac)
142  ::signal (SIGHUP, SignalHandler);
143  ::signal (SIGQUIT, SignalHandler);
144  #endif
145 
146  // Run the player...
147  player.Run();
148 
149  cout << " Playout Playout Frames" << endl
150  << " Frames Buffer Dropped" << endl;
151  do
152  { // Poll its status until stopped...
153  AUTOCIRCULATE_STATUS outputStatus;
154  player.GetACStatus(outputStatus);
155  cout << setw(9) << outputStatus.GetProcessedFrameCount()
156  << setw(9) << outputStatus.GetDroppedFrameCount()
157  << setw(9) << outputStatus.GetBufferLevel() << "\r" << flush;
158  AJATime::Sleep(2000);
159  } while (player.IsRunning() && !gGlobalQuit); // loop til done
160  cout << endl;
161  } // NTV2DolbyPlayer scope
162  return 0;
163 
164 } // main
int main(int argc, const char **argv)
Definition: main.cpp:30
bool fSuppressAudio
If true, suppress audio; otherwise generate & xfer audio tone.
virtual AJAStatus Run(void)
Runs me.
AJAStatus
Definition: types.h:380
See 10-Bit YCbCr Format.
Definition: ntv2enums.h:224
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
ULWord GetBufferLevel(void) const
#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())
I am similar to NTV2Player, but I demonstrate how to play/output 8 channels of audio tone (or ramp da...
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
ULWord GetProcessedFrameCount(void) const
#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
static bool gGlobalQuit((0))
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.
Configures an NTV2DolbyPlayer instance.
virtual const std::string & errorStr(void) const
NTV2VideoFormat fVideoFormat
The video format to use.
ULWord GetDroppedFrameCount(void) const
std::string fDolbyFilePath
Optional path to Dolby audio source file.
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
bool fDoRamp
If true, use audio ramp pattern instead of tone.
Header file for NTV2DolbyPlayer demonstration class.
NTV2Channel fOutputChannel
The device channel to use.
#define POPT_TABLEEND
Definition: options_popt.h:222
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
virtual bool IsRunning(void) const
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outStatus)
Provides status information about my output (playout) process.
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:987
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
bool fDoHDMIOutput
If true, enable HDMI output; otherwise, disable HDMI output.
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.