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 "ntv2utils.h"
10 #include "ajatypes.h"
11 #include "ntv2m31publicinterface.h"
14 #include "ntv2encodehevcvif.h"
15 #include <signal.h>
16 #include <iostream>
17 #include <iomanip>
18 
19 using namespace std;
20 
21 
22 // Globals
27 
31 
35 };
36 
42 };
43 
44 static const size_t gNumCodecPresets (sizeof(kCodecPreset)/sizeof(M31VideoPreset));
45 static const size_t gNumCodecFormats (sizeof(kCodecFormat)/sizeof(NTV2FrameBufferFormat));
46 static const int kNoSelection (1000000000);
47 static bool gGlobalQuit (false); // Set this "true" to exit gracefully
48 
49 
50 static void SignalHandler (int inSignal)
51 { (void) inSignal;
52  gGlobalQuit = true;
53 }
54 
55 static int printPresets (void)
56 {
57  cout << "M31 Presets" << endl;
58  for (size_t ndx(0); ndx < gNumCodecPresets; ndx++)
59  { const string presetStr (::NTV2M31VideoPresetToString (kCodecPreset[ndx], true));
60  if (!presetStr.empty())
61  cout << ndx << ": " << presetStr << endl;
62  }
63  return 0;
64 }
65 
66 static int printFormats (void)
67 {
68  cout << "M31 Formats" << endl;
69  for (size_t ndx(0); ndx < gNumCodecFormats; ndx++)
70  { const string pixFormatStr (::NTV2FrameBufferFormatToString(kCodecFormat[ndx], true));
71  if (!pixFormatStr.empty())
72  cout << ndx << ": " << pixFormatStr << endl;
73  }
74  return 0;
75 }
76 
77 
78 int main (int argc, const char ** argv)
79 {
80  M31VideoPreset m31Preset (M31_NUMVIDEOPRESETS); // Codec preset
81  NTV2FrameBufferFormat pixelFormat (NTV2_FBF_NUMFRAMEBUFFERFORMATS); // Codec frame format
82  char * pWhatToList (AJA_NULL); // Value of --list argument
83  char * pDeviceSpec (AJA_NULL); // Device specifier string, if any
84  int codecFormat (kNoSelection); // Codec format index
85  int codecPreset (kNoSelection); // Codec preset index
86  int infoData (0); // Picture and encoded information
87  int maxFrames (kNoSelection); // Maximum number of catpured frames
88  int audioChannels (0); // Number of audio channels
89  poptContext optionsContext; // Context for parsing command line arguments
90 
92 
93  // Command line option descriptions:
94  const struct poptOption userOptionsTable [] =
95  {
96  {"audio", 'a', POPT_ARG_INT, &audioChannels, 0, "number of audio channels", "1-16"},
97  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model"},
98  {"format", 'f', POPT_ARG_INT, &codecFormat, 0, "format to use", "use '-lf' for list"},
99  {"preset", 'p', POPT_ARG_INT, &codecPreset, 0, "codec preset to use", "use '-lp' for list"},
100  {"list", 'l', POPT_ARG_STRING, &pWhatToList, 0, "list options", "p or f (presets or formats)"},
101  {"info", 'i', POPT_ARG_NONE, &infoData, 0, "write encoded info file", ""},
102  {"maxframes", 'x', POPT_ARG_INT |
103  POPT_ARGFLAG_OPTIONAL, &maxFrames, 0, "limit output file frames", ""},
106  };
107 
108  // Read command line arguments...
109  optionsContext = ::poptGetContext (AJA_NULL, argc, argv, userOptionsTable, 0);
110  ::poptGetNextOpt(optionsContext);
111  optionsContext = ::poptFreeContext(optionsContext);
112 
113  if (pWhatToList && string(pWhatToList) == "p")
114  return printPresets();
115  else if (pWhatToList && string(pWhatToList) == "f")
116  return printFormats();
117  else if (pWhatToList)
118  {cerr << "## ERROR: Invalid argument to --list option, expected 'p' or 'f'" << endl; return 2;}
119 
120  if ((codecFormat != kNoSelection) && (codecFormat >= int(gNumCodecFormats)))
121  {cerr << "## ERROR: Invalid M31 format " << codecFormat << " -- expected 0 thru " << (gNumCodecFormats) << endl; return 2;}
122 
123  if (codecFormat < int(gNumCodecFormats))
124  pixelFormat = kCodecFormat[codecFormat];
125 
126  if ((codecPreset != kNoSelection) && (codecPreset >= int(gNumCodecPresets)))
127  {cerr << "## ERROR: Invalid M31 preset " << codecPreset << " -- expected 0 thru " << (gNumCodecPresets) << endl; return 2;}
128 
129  if (codecPreset < int(gNumCodecPresets))
130  m31Preset = kCodecPreset[codecPreset];
131 
132  ::signal (SIGINT, SignalHandler);
133  #if defined(AJAMac)
134  ::signal (SIGHUP, SignalHandler);
135  ::signal (SIGQUIT, SignalHandler);
136  #endif
137 
138  // Instantiate the NTV2EncodeHEVCVif object, using the specified AJA device
139  const bool infoMode (infoData ? true : false); // Picture and encoded information mode
140  const uint32_t hevcMaxFrames (maxFrames >= kNoSelection ? 0xffffffff : uint32_t(maxFrames));
141  NTV2EncodeHEVCVif hevcVifEncoder (pDeviceSpec ? string (pDeviceSpec) : "0",
142  m31Preset, pixelFormat, UWord(audioChannels),
143  infoMode, hevcMaxFrames);
144 
145  // Initialize the NTV2EncodeHEVCVif instance
146  if (AJA_FAILURE(hevcVifEncoder.Init()))
147  {cerr << "## ERROR: Initialization failed" << endl; return 1;}
148 
149  // Get the current codec preset
150  m31Preset = hevcVifEncoder.GetCodecPreset();
151 
152  cout << endl
153  << "Capture: " << ::NTV2M31VideoPresetToString (m31Preset, false) << endl
154  << endl;
155 
156  // Run the capturer...
157  hevcVifEncoder.Run();
158 
159  cout << " Capture Capture" << endl
160  << " Frames Frames Buffer" << endl
161  << "Processed Dropped Level" << endl;
162 
163  // Loop til told to stop...
164  do
165  {
166  AVHevcStatus info;
167  hevcVifEncoder.GetStatus(&info);
168  cout << setw(9) << info.framesProcessed
169  << setw(9) << info.framesDropped
170  << setw(9) << info.bufferLevel
171  << "\r" << flush;
172  AJATime::Sleep(1000);
173  } while (!gGlobalQuit);
174  cout << endl;
175 
176  // Quit the capturer
177  hevcVifEncoder.Quit();
178 
179  return 0;
180 
181 } // main
NTV2EncodeHEVCVif::GetCodecPreset
virtual M31VideoPreset GetCodecPreset(void)
Get the codec preset.
Definition: ntv2encodehevcvif.cpp:354
NTV2_FBF_NUMFRAMEBUFFERFORMATS
@ NTV2_FBF_NUMFRAMEBUFFERFORMATS
Definition: ntv2enums.h:244
NTV2_FBF_10BIT_YCBCR_420PL2
@ NTV2_FBF_10BIT_YCBCR_420PL2
10-Bit 4:2:0 2-Plane YCbCr
Definition: ntv2enums.h:239
M31_VIF_3840X2160_422_10_50p
@ M31_VIF_3840X2160_422_10_50p
Definition: ntv2m31enums.h:174
poptOption
Definition: options_popt.h:148
M31_VIF_3840X2160_420_10_50p
@ M31_VIF_3840X2160_420_10_50p
Definition: ntv2m31enums.h:169
gNumCodecFormats
static const size_t gNumCodecFormats(sizeof(kCodecFormat)/sizeof(NTV2FrameBufferFormat))
systemtime.h
Declares the AJATime class.
SignalHandler
void SignalHandler(int inSignal)
Definition: main.cpp:26
M31_VIF_3840X2160_422_10_5994p
@ M31_VIF_3840X2160_422_10_5994p
Definition: ntv2m31enums.h:175
NTV2FrameBufferFormat
NTV2FrameBufferFormat
Identifies a particular video frame buffer format. See Device Frame Buffer Formats for details.
Definition: ntv2enums.h:207
M31_VIF_3840X2160_420_8_50p
@ M31_VIF_3840X2160_420_8_50p
Definition: ntv2m31enums.h:166
main
int main(int argc, const char **argv)
Definition: main.cpp:30
M31_VIF_3840X2160_420_10_5994p
@ M31_VIF_3840X2160_420_10_5994p
Definition: ntv2m31enums.h:170
AVHevcStatus::framesDropped
ULWord framesDropped
Definition: ntv2demohevccommon.h:51
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
M31_VIF_3840X2160_420_8_5994p
@ M31_VIF_3840X2160_420_8_5994p
Definition: ntv2m31enums.h:167
gNumCodecPresets
static const size_t gNumCodecPresets(sizeof(kCodecPreset)/sizeof(M31VideoPreset))
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...
printFormats
static int printFormats(void)
Definition: main.cpp:66
M31_NUMVIDEOPRESETS
@ M31_NUMVIDEOPRESETS
Definition: ntv2m31enums.h:178
NTV2_FBF_8BIT_YCBCR_420PL2
@ NTV2_FBF_8BIT_YCBCR_420PL2
8-Bit 4:2:0 2-Plane YCbCr
Definition: ntv2enums.h:241
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
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
M31_VIF_3840X2160_420_10_60p
@ M31_VIF_3840X2160_420_10_60p
Definition: ntv2m31enums.h:171
NTV2M31VideoPresetToString
std::string NTV2M31VideoPresetToString(const M31VideoPreset inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:6982
AVHevcStatus::bufferLevel
ULWord bufferLevel
Definition: ntv2demohevccommon.h:52
ntv2m31publicinterface.h
Declares structs used for the Corvid HEVC.
UWord
uint16_t UWord
Definition: ajatypes.h:244
options_popt.h
ntv2utils.h
Declares numerous NTV2 utility functions.
poptFreeContext
poptContext poptFreeContext(poptContext con)
Definition: options_popt.cpp:3539
M31_VIF_3840X2160_422_10_60p
@ M31_VIF_3840X2160_422_10_60p
Definition: ntv2m31enums.h:176
kCodecPreset
const M31VideoPreset kCodecPreset[]
Definition: main.cpp:23
gGlobalQuit
static bool gGlobalQuit((0))
NTV2_FBF_10BIT_YCBCR_422PL2
@ NTV2_FBF_10BIT_YCBCR_422PL2
10-Bit 4:2:2 2-Plane YCbCr
Definition: ntv2enums.h:240
M31VideoPreset
M31VideoPreset
Definition: ntv2m31enums.h:12
POPT_ARGFLAG_OPTIONAL
#define POPT_ARGFLAG_OPTIONAL
Definition: options_popt.h:88
printPresets
static int printPresets(void)
Definition: main.cpp:55
NTV2EncodeHEVCVif::Run
virtual AJAStatus Run(void)
Runs me.
Definition: ntv2encodehevcvif.cpp:614
NTV2EncodeHEVCVif
Instances of me capture frames in real time from a video signal provided to an input of an AJA device...
Definition: ntv2encodehevcvif.h:38
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
kNoSelection
const int kNoSelection(1000000000)
NTV2EncodeHEVCVif::Init
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Definition: ntv2encodehevcvif.cpp:224
NTV2EncodeHEVCVif::Quit
virtual void Quit(void)
Gracefully stops me from running.
Definition: ntv2encodehevcvif.cpp:160
poptGetContext
poptContext poptGetContext(const char *name, int argc, const char **argv, const struct poptOption *options, unsigned int flags)
Definition: options_popt.cpp:2264
poptGetNextOpt
int poptGetNextOpt(poptContext con)
Definition: options_popt.cpp:3236
NTV2FrameBufferFormatToString
std::string NTV2FrameBufferFormatToString(const NTV2FrameBufferFormat inValue, const bool inForRetailDisplay=false)
Definition: ntv2utils.cpp:6940
kCodecFormat
const NTV2FrameBufferFormat kCodecFormat[]
Definition: main.cpp:99
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
AVHevcStatus
Definition: ntv2demohevccommon.h:48
NTV2EncodeHEVCVif::GetStatus
virtual void GetStatus(AVHevcStatus *outInputStatus)
Provides status information about my input (capture) process.
Definition: ntv2encodehevcvif.cpp:1003
NTV2_FBF_8BIT_YCBCR_422PL2
@ NTV2_FBF_8BIT_YCBCR_422PL2
8-Bit 4:2:2 2-Plane YCbCr
Definition: ntv2enums.h:242
AJA_FAILURE
#define AJA_FAILURE(_status_)
Definition: types.h:358
AVHevcStatus::framesProcessed
ULWord framesProcessed
Definition: ntv2demohevccommon.h:50
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
ntv2encodehevcvif.h
Declares the NTV2EncodeHEVCVif class.
M31_VIF_3840X2160_420_8_60p
@ M31_VIF_3840X2160_420_8_60p
Definition: ntv2m31enums.h:168