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 */
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 },
57 
60  };
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  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
69  if (!CNTV2DemoCommon::IsValidDevice(deviceSpec))
70  return 1;
71 
72  DolbyPlayerConfig config(deviceSpec);
73 
74  // Channel
75  if ((channelNumber < 2) || (channelNumber > 4))
76  {cerr << "## ERROR: Invalid channel number " << channelNumber << " -- expected 2 thru 4" << endl; return 1;}
77  config.fOutputChannel = NTV2Channel(channelNumber - 1);
78 
79  // VideoFormat
80  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
81  config.fVideoFormat = videoFormatStr.empty() ? NTV2_FORMAT_1080i_5994
83  if (videoFormatStr == "?" || videoFormatStr == "list")
84  {cout << CNTV2DemoCommon::GetVideoFormatStrings (VIDEO_FORMATS_SDHD | VIDEO_FORMATS_4KUHD, pDeviceSpec ? deviceSpec : "") << endl; return 0;}
85  else if (!videoFormatStr.empty() && config.fVideoFormat == NTV2_FORMAT_UNKNOWN)
86  {
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_10BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString (pixelFormatStr));
95  if (pixelFormatStr == "?" || pixelFormatStr == "list")
96  {cout << CNTV2DemoCommon::GetPixelFormatStrings (PIXEL_FORMATS_ALL, pDeviceSpec ? 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  if (noAudio && doRamp)
120  {cerr << "## ERROR: conflicting options '--noaudio' and '--ramp'" << endl; return 1;}
121 
122  if (noAudio && pDolbyFile)
123  {cerr << "## ERROR: conflicting options '--noaudio' and '--dolby'" << endl; return 1;}
124 
125  if (doRamp && pDolbyFile)
126  {cerr << "## ERROR: conflicting options '--ramp' and '--dolby'" << endl; return 1;}
127 
128  //remaining options for this demo
129  config.fSuppressAudio = noAudio ? true : false;
130  config.fSuppressVideo = noVideo ? true : false;
131  config.fDoMultiFormat = doMultiFormat ? true : false; // Multiformat mode?
132  config.fDoRamp = doRamp ? true : false; // inDoRamp
133  config.fDoHDMIOutput = true;
134  config.fDolbyFilePath = pDolbyFile ? pDolbyFile : "";
135 
136  NTV2DolbyPlayer player (config);
137  status = player.Init();
138  if (AJA_FAILURE(status))
139  {cout << "## ERROR: Initialization failed: " << ::AJAStatusToString(status) << endl; return 1;}
140 
141  ::signal (SIGINT, SignalHandler);
142  #if defined (AJAMac)
143  ::signal (SIGHUP, SignalHandler);
144  ::signal (SIGQUIT, SignalHandler);
145  #endif
146 
147  // Run the player...
148  player.Run();
149 
150  cout << " Playout Playout Frames" << endl
151  << " Frames Buffer Dropped" << endl;
152  do
153  { // Poll its status until stopped...
154  AUTOCIRCULATE_STATUS outputStatus;
155  player.GetACStatus(outputStatus);
156  cout << setw(9) << outputStatus.GetProcessedFrameCount()
157  << setw(9) << outputStatus.GetDroppedFrameCount()
158  << setw(9) << outputStatus.GetBufferLevel() << "\r" << flush;
159  AJATime::Sleep(2000);
160  } while (player.IsRunning() && !gGlobalQuit); // loop til done
161 
162  cout << endl;
163  return 0;
164 
165 } // 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
PlayerConfig::fDoHDMIOutput
bool fDoHDMIOutput
If true, enable HDMI output; otherwise, disable HDMI output.
Definition: ntv2democommon.h:337
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
DolbyPlayerConfig::fDolbyFilePath
std::string fDolbyFilePath
Optional path to Dolby audio source file.
Definition: ntv2dolbyplayer.h:29
NTV2Channel
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They're also commonly use...
Definition: ntv2enums.h:1334
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
NTV2_FORMAT_1080i_5994
@ NTV2_FORMAT_1080i_5994
Definition: ntv2enums.h:535
AUTOCIRCULATE_STATUS::GetProcessedFrameCount
ULWord GetProcessedFrameCount(void) const
Definition: ntv2publicinterface.h:7249
AUTOCIRCULATE_STATUS::GetBufferLevel
ULWord GetBufferLevel(void) const
Definition: ntv2publicinterface.h:7254
main
int main(int argc, const char **argv)
Definition: main.cpp:30
NTV2DolbyPlayer::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2dolbyplayer.cpp:421
PlayerConfig::fDoMultiFormat
bool fDoMultiFormat
If true, enable device-sharing; otherwise take exclusive control of device.
Definition: ntv2democommon.h:332
ntv2dolbyplayer.h
Header file for NTV2DolbyPlayer demonstration class.
NTV2ACFrameRange::setFromString
std::string setFromString(const std::string &inStr)
Definition: ntv2utils.cpp:4155
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::void
j template void())
Definition: json.hpp:4893
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
VIDEO_FORMATS_4KUHD
@ VIDEO_FORMATS_4KUHD
Definition: ntv2democommon.h:226
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
NTV2DolbyPlayer
I am similar to NTV2Player, but I demonstrate how to play/output 8 channels of audio tone (or ramp da...
Definition: ntv2dolbyplayer.h:52
PlayerConfig::fFrames
NTV2ACFrameRange fFrames
AutoCirculate frame count or range.
Definition: ntv2democommon.h:326
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
AUTOCIRCULATE_STATUS
This is returned from the CNTV2Card::AutoCirculateGetStatus function.
Definition: ntv2publicinterface.h:7193
PlayerConfig::fSuppressAudio
bool fSuppressAudio
If true, suppress audio; otherwise generate & xfer audio tone.
Definition: ntv2democommon.h:333
PlayerConfig::fSuppressVideo
bool fSuppressVideo
If true, suppress video; otherwise generate & xfer test patterns.
Definition: ntv2democommon.h:334
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::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
DolbyPlayerConfig
Configures an NTV2DolbyPlayer instance.
Definition: ntv2dolbyplayer.h:25
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
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
NTV2_FBF_10BIT_YCBCR
@ NTV2_FBF_10BIT_YCBCR
See 10-Bit YCbCr Format.
Definition: ntv2enums.h:213
gGlobalQuit
static bool gGlobalQuit((0))
std
Definition: json.hpp:5362
AJAStatusToString
std::string AJAStatusToString(const AJAStatus inStatus, const bool inDetailed)
Definition: debug.cpp:981
AUTOCIRCULATE_STATUS::GetDroppedFrameCount
ULWord GetDroppedFrameCount(void) const
Definition: ntv2publicinterface.h:7244
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
true
#define true
Definition: ntv2devicefeatures.h:26
NTV2ACFrameRange::valid
bool valid(void) const
Definition: ntv2utils.h:985
NTV2DolbyPlayer::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2dolbyplayer.cpp:134
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
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
NTV2DolbyPlayer::GetACStatus
virtual void GetACStatus(AUTOCIRCULATE_STATUS &outStatus)
Provides status information about my output (playout) process.
Definition: ntv2dolbyplayer.cpp:633
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:252
DolbyPlayerConfig::fDoRamp
bool fDoRamp
If true, use audio ramp pattern instead of tone.
Definition: ntv2dolbyplayer.h:28