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 */
8 // Includes
9 #include "ajatypes.h"
10 #include "ntv2utils.h"
12 #include "ntv2dolbyplayer.h"
13 #include <signal.h>
14 #include <iostream>
15 #include <iomanip>
17 #include "ajabase/system/file_io.h"
18 
19 using namespace std;
20 
21 
22 // Globals
23 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
24 
25 static void SignalHandler (int inSignal)
26 {
27  (void) inSignal;
28  gGlobalQuit = true;
29 }
30 
31 
32 int main (int argc, const char ** argv)
33 {
34  char * pVideoFormat (AJA_NULL); // Video format argument
35  char * pPixelFormat (AJA_NULL); // Pixel format argument
36  char * pDeviceSpec (AJA_NULL); // Device argument
37  char * pDolbyName (AJA_NULL); // Dolby audio file name
38  uint32_t channelNumber (2); // Number of the channel to use
39  int noAudio (0); // Disable audio tone?
40  int doMultiChannel (0); // Enable multi-format?
41  int doRamp (0); // Enable audio ramp
42  poptContext optionsContext; // Context for parsing command line arguments
43  AJAStatus status;
44 
46 
47  // Command line option descriptions:
48  const struct poptOption userOptionsTable [] =
49  {
50  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model" },
51  {"dolbyFile", 'f', POPT_ARG_STRING, &pDolbyName, 0, "dolby audio to play", "file name" },
52  {"videoFormat", 'v', POPT_ARG_STRING, &pVideoFormat, 0, "video format to produce", "'?' or 'list' to list"},
53  {"pixelFormat", 'p', POPT_ARG_STRING, &pPixelFormat, 0, "pixel format to use", "'?' or 'list' to list"},
54  {"channel", 'c', POPT_ARG_INT, &channelNumber, 0, "channel to use", "1-8"},
55  {"multiChannel",'m', POPT_ARG_NONE, &doMultiChannel,0, "use multi-channel/format", AJA_NULL},
56  {"ramp", 'r', POPT_ARG_NONE, &doRamp, 0, "audio ramp", AJA_NULL},
57  {"noaudio", 't', POPT_ARG_NONE, &noAudio, 0, "disable audio tone", AJA_NULL},
60  };
61 
62  // Read command line arguments...
63  optionsContext = ::poptGetContext (AJA_NULL, argc, argv, userOptionsTable, 0);
64  ::poptGetNextOpt (optionsContext);
65  optionsContext = ::poptFreeContext (optionsContext);
66 
67  const string deviceSpec (pDeviceSpec ? pDeviceSpec : "0");
68  const string videoFormatStr (pVideoFormat ? pVideoFormat : "");
69  NTV2VideoFormat videoFormat (videoFormatStr.empty () ? NTV2_FORMAT_1080i_5994 : CNTV2DemoCommon::GetVideoFormatFromString (videoFormatStr));
70  if (videoFormat == NTV2_FORMAT_UNKNOWN)
71  videoFormat = CNTV2DemoCommon::GetVideoFormatFromString (videoFormatStr, VIDEO_FORMATS_4KUHD);
72  if (videoFormatStr == "?" || videoFormatStr == "list")
74  << CNTV2DemoCommon::GetVideoFormatStrings (VIDEO_FORMATS_4KUHD, deviceSpec) << endl; return 0;}
75  else if (!videoFormatStr.empty () && videoFormat == NTV2_FORMAT_UNKNOWN)
76  {
77  cerr << "## ERROR: Invalid '--videoFormat' value '" << videoFormatStr << "' -- expected values:" << endl
80  return 2;
81  }
82 
83  const string pixelFormatStr (pPixelFormat ? pPixelFormat : "");
84  const NTV2FrameBufferFormat pixelFormat (pixelFormatStr.empty () ? NTV2_FBF_10BIT_YCBCR : CNTV2DemoCommon::GetPixelFormatFromString (pixelFormatStr));
85  if (pixelFormatStr == "?" || pixelFormatStr == "list")
86  {cout << CNTV2DemoCommon::GetPixelFormatStrings (PIXEL_FORMATS_ALL, deviceSpec) << endl; return 0;}
87  else if (!pixelFormatStr.empty () && !NTV2_IS_VALID_FRAME_BUFFER_FORMAT (pixelFormat))
88  {
89  cerr << "## ERROR: Invalid '--pixelFormat' value '" << pixelFormatStr << "' -- expected values:" << endl
91  return 2;
92  }
93 
94  if (channelNumber < 2 || channelNumber > 4)
95  {cerr << "## ERROR: Invalid channel number '" << channelNumber << "' -- expected 2 thru 4" << endl; return 2;}
96 
97  AJAFileIO fileIO;
98  AJAFileIO* pDolbyFile = NULL;
99  const string fileStr (pDolbyName ? pDolbyName : "");
100  if (!fileStr.empty ())
101  {
102  status = fileIO.Open(pDolbyName, eAJAReadOnly, 0);
103  if (status == AJA_STATUS_SUCCESS)
104  pDolbyFile = &fileIO;
105  }
106 
107  const NTV2Channel channel (::GetNTV2ChannelForIndex (channelNumber - 1));
108 
109  NTV2DolbyPlayer player (deviceSpec, // inDeviceSpecifier
110  (noAudio ? false : true), // inWithAudio
111  channel, // inChannel
112  pixelFormat, // inPixelFormat
113  videoFormat, // inVideoFormat
114  doMultiChannel ? true : false, // inDoMultiFormat
115  doRamp ? true : false, // inDoRamp
116  pDolbyFile); // inDolbyFile
117 
118  ::signal (SIGINT, SignalHandler);
119  #if defined (AJAMac)
120  ::signal (SIGHUP, SignalHandler);
121  ::signal (SIGQUIT, SignalHandler);
122  #endif
123 
124  // Initialize the player...
125  if (AJA_FAILURE(player.Init()))
126  {cerr << "## ERROR: Initialization failed" << endl; return 3;}
127 
128  // Run the player...
129  player.Run ();
130 
131  cout << " Playout Playout Frames" << endl
132  << " Frames Buffer Dropped" << endl;
133  do
134  {
135  ULWord framesProcessed, framesDropped, bufferLevel;
136 
137  // Poll the player's status...
138  player.GetACStatus (framesProcessed, framesDropped, bufferLevel);
139  cout << setw (9) << framesProcessed << setw (9) << bufferLevel << setw (9) << framesDropped << "\r" << flush;
140  AJATime::Sleep (2000);
141  } while (player.IsRunning () && !gGlobalQuit); // loop til done
142 
143  // Ask the player to stop
144  player.Quit();
145 
146  cout << endl;
147  return 0;
148 
149 } // main
CNTV2DemoCommon::GetVideoFormatStrings
static std::string GetVideoFormatStrings(const NTV2VideoFormatKinds inKinds=VIDEO_FORMATS_NON_4KUHD, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:553
GetNTV2ChannelForIndex
NTV2Channel GetNTV2ChannelForIndex(const ULWord inIndex0)
Definition: ntv2utils.cpp:4755
NTV2DolbyPlayer::IsRunning
virtual bool IsRunning(void) const
Definition: ntv2dolbyplayer.h:76
poptOption
Definition: options_popt.h:148
NULL
#define NULL
Definition: ntv2caption608types.h:19
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
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:368
systemtime.h
Declares the AJATime class.
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
NTV2_FORMAT_1080i_5994
@ NTV2_FORMAT_1080i_5994
Definition: ntv2enums.h:512
NTV2FrameBufferFormat
NTV2FrameBufferFormat
Identifies a particular video frame buffer format. See Device Frame Buffer Formats for details.
Definition: ntv2enums.h:207
eAJAReadOnly
@ eAJAReadOnly
Definition: file_io.h:31
main
int main(int argc, const char **argv)
Definition: main.cpp:30
NTV2DolbyPlayer::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2dolbyplayer.cpp:363
ntv2dolbyplayer.h
Header file for NTV2DolbyPlayer demonstration class.
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
poptContext_s
Definition: options_popt.cpp:289
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
AJAFileIO::Open
AJAStatus Open(const std::string &fileName, const int flags, const int properties)
Definition: file_io.cpp:201
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
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
AJAStatus
AJAStatus
Definition: types.h:365
NTV2DolbyPlayer
I am an object that can play out a test pattern (with timecode) to an output of an AJA device with or...
Definition: ntv2dolbyplayer.h:30
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
ULWord
uint32_t ULWord
Definition: ajatypes.h:246
CNTV2DemoCommon::GetPixelFormatFromString
static NTV2FrameBufferFormat GetPixelFormatFromString(const std::string &inStr)
Returns the NTV2FrameBufferFormat that matches the given string.
Definition: ntv2democommon.cpp:660
PIXEL_FORMATS_ALL
@ PIXEL_FORMATS_ALL
Definition: ntv2democommon.h:240
options_popt.h
ntv2utils.h
Declares numerous NTV2 utility functions.
poptFreeContext
poptContext poptFreeContext(poptContext con)
Definition: options_popt.cpp:3539
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
NTV2_FORMAT_UNKNOWN
@ NTV2_FORMAT_UNKNOWN
Definition: ntv2enums.h:498
file_io.h
Declares the AJAFileIO class.
poptGetContext
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Definition: options_popt.cpp:2264
NTV2_FBF_10BIT_YCBCR
@ NTV2_FBF_10BIT_YCBCR
See 10-Bit YCbCr Format.
Definition: ntv2enums.h:210
VIDEO_FORMATS_NON_4KUHD
@ VIDEO_FORMATS_NON_4KUHD
Definition: ntv2democommon.h:225
NTV2DolbyPlayer::Quit
virtual void Quit(void)
Gracefully stops me from running.
Definition: ntv2dolbyplayer.cpp:155
poptGetNextOpt
int poptGetNextOpt(poptContext con)
Definition: options_popt.cpp:3236
gGlobalQuit
static bool gGlobalQuit(false)
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
NTV2VideoFormat
enum _NTV2VideoFormat NTV2VideoFormat
Identifies a particular video format.
AJAFileIO
Definition: file_io.h:64
CNTV2DemoCommon::GetPixelFormatStrings
static std::string GetPixelFormatStrings(const NTV2PixelFormatKinds inKinds=PIXEL_FORMATS_ALL, const std::string inDeviceSpecifier=std::string())
Definition: ntv2democommon.cpp:603
VIDEO_FORMATS_4KUHD
@ VIDEO_FORMATS_4KUHD
Definition: ntv2democommon.h:226
NTV2DolbyPlayer::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2dolbyplayer.cpp:174
NTV2DolbyPlayer::GetACStatus
virtual void GetACStatus(ULWord &outGoodFrames, ULWord &outDroppedFrames, ULWord &outBufferLevel)
Provides status information about my output (playout) process.
Definition: ntv2dolbyplayer.cpp:600
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