AJA NTV2 SDK  18.0.0.2717
NTV2 SDK 18.0.0.2717
main.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
10 // Includes
11 #include "ajatypes.h"
13 #include "ajabase/system/process.h"
14 #include "ntv2card.h"
15 #include "ntv2devicescanner.h"
16 #include "ntv2democommon.h"
17 
18 using namespace std;
19 
20 
21 // Globals
22 const uint32_t kAppSignature (NTV2_FOURCC('H','d','r','s'));
23 
24 
31 int main (int argc, const char ** argv)
32 {
33  char * pDeviceSpec (AJA_NULL); // Which device to use
34  int eotf (0); // EOTF to enable 0,1,2,3
35  int constLuminance (0); // Constant luminanace?
36  int dolbyVision (0); // Enable dolby vision bit?
37  int verbose (0); // Verbose mode?
38  int noHDR (0); // Disable hdr?
39  int showVersion (0); // Show version and exit?
41 
42  // Command line option descriptions:
43  const CNTV2DemoCommon::PoptOpts optionsTable [] =
44  {
45  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model"},
46  {"eotf", 'e', POPT_ARG_INT, &eotf, 0, "0=TradGammaSDR 1=TradGammaHDR 2=ST2084 3=HLG", "EOTF to use"},
47  {"luminance", 'l', POPT_ARG_NONE, &constLuminance, 0, "constant luminance?", AJA_NULL },
48  {"dolbyvision", 0, POPT_ARG_NONE, &dolbyVision, 0, "enable DolbyVision bit?", AJA_NULL },
49  {"nohdr", 0, POPT_ARG_NONE, &noHDR, 0, "disable HDMI HDR output?", AJA_NULL },
50  {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "verbose output?", AJA_NULL },
51  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
54  };
55  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
56  if (!popt)
57  {cerr << "## ERROR: " << popt.errorStr() << endl; return 1;}
58  if (showVersion)
59  {cout << "NTV2HDRSetup, NTV2 SDK " << ::NTV2Version() << endl; return 0;}
60 
61  if ((eotf < 0) || (eotf > 3))
62  {cerr << "## ERROR: Bad EOTF value '" << DEC(eotf) << "' -- expected 0, 1, 2 or 3" << endl; return 2;}
63 
64  // Open the device...
65  CNTV2Card device;
66  if (!CNTV2DeviceScanner::GetFirstDeviceFromArgument (pDeviceSpec ? pDeviceSpec : "0", device))
67  {cerr << "## ERROR: Device '" << pDeviceSpec << "' not found" << endl; return 3;}
68 
69  if (!device.IsDeviceReady(false))
70  {cerr << "## ERROR: Device '" << pDeviceSpec << "' not ready" << endl; return 4;}
71 
72  if (!device.features().CanDoHDMIHDROut())
73  {cerr << "## ERROR: Device '" << pDeviceSpec << "' does not support HDMI HDR" << endl; return 5;}
74 
75  // Acquire the device...
76  ULWord appSignature (0);
77  int32_t appPID (0);
78  NTV2TaskMode savedTaskMode(NTV2_TASK_MODE_INVALID);
79  device.GetTaskMode(savedTaskMode); // Save the current device state
80  device.GetStreamingApplication(appSignature, appPID); // Who currently "owns" the device?
82  {
83  cerr << "## ERROR: Unable to acquire device because another app (pid " << appPID << ") owns it" << endl;
84  return 6; // Device reserved by other app
85  }
86  device.SetTaskMode(NTV2_OEM_TASKS); // Set the OEM service level
87 
88  if (verbose)
89  {
90  static const string sEOTFs[] = {"Traditional Gamma SDR", "Traditional Gamma HDR", "ST-2084", "HLG", ""};
91  cout << "## NOTE: Options specified:" << endl
92  << "\tEOTF: " << DEC(eotf) << " (" << sEOTFs[eotf] << ")" << endl
93  << "\tLuminance: " << (constLuminance ? "Constant" : "Non-Constant") << endl
94  << "\tDolbyVision: " << (dolbyVision ? "Enabled" : "Disabled") << endl;
95  if (noHDR)
96  cout << "## WARNING: --nohdr option will disable HDMI HDR output" << endl;
97  }
98 
99  // Load up the digital primitives with some reasonable values...
100  HDRRegValues regValues;
101  regValues.setBT2020().electroOpticalTransferFunction = uint8_t(eotf);
102  device.SetHDRData(regValues);
103 
104  // Setup HDR values based on passed args...
105  device.SetHDMIHDRConstantLuminance(bool(constLuminance));
106  device.SetHDMIHDRElectroOpticalTransferFunction(uint8_t(eotf)); // This call is redundant (was set in SetHDRData above)
107 
108  // Enabling this will allow dolby vision containing frames to properly display out of HDMI
109  device.EnableHDMIHDRDolbyVision(bool(dolbyVision));
110 
111  // The master switch for HDMI HDR output
112  device.EnableHDMIHDR(noHDR ? false : true);
113 
114  // Loop until a key is pressed, that way user can inspect the changes with watcher
116 
117  device.SetTaskMode(savedTaskMode); // Restore prior tasks mode
118  device.ReleaseStreamForApplication (kAppSignature, int32_t(AJAProcess::GetPid())); // Release the device
119 
120  return 0; // Success!
121 
122 } // main
NTV2TaskMode
NTV2TaskMode
Describes the task mode state. See also: Sharing AJA Devices With Other Applications.
Definition: ntv2publicinterface.h:4462
NTV2_FOURCC
#define NTV2_FOURCC(_a_, _b_, _c_, _d_)
Definition: ntv2publicinterface.h:5623
poptOption
Definition: options_popt.h:148
CNTV2DeviceScanner::GetFirstDeviceFromArgument
static bool GetFirstDeviceFromArgument(const std::string &inArgument, CNTV2Card &outDevice)
Rescans the host, and returns an open CNTV2Card instance for the AJA device that matches a command li...
Definition: ntv2devicescanner.cpp:338
appPID
int32_t appPID(0)
CNTV2Card::SetHDMIHDRConstantLuminance
virtual bool SetHDMIHDRConstantLuminance(const bool inEnableConstantLuminance, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Enables or disables BT.2020 Y'cC'bcC'rc versus BT.2020 Y'C'bC'r or R'G'B'.
Definition: ntv2hdmi.cpp:968
CNTV2MacDriverInterface::ReleaseStreamForApplication
virtual bool ReleaseStreamForApplication(ULWord inApplicationType, int32_t inProcessID)
Releases exclusive use of the AJA device for the given process, permitting other processes to acquire...
Definition: ntv2macdriverinterface.cpp:540
main
int main(int argc, const char **argv)
Definition: main.cpp:30
kAppSignature
const uint32_t kAppSignature(((((uint32_t)( 'H'))<< 24)|(((uint32_t)( 'd'))<< 16)|(((uint32_t)( 'r'))<< 8)|(((uint32_t)( 's'))<< 0)))
CNTV2Card::SetTaskMode
virtual bool SetTaskMode(const NTV2TaskMode inMode)
Sets the device's task mode.
Definition: ntv2register.cpp:179
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
CNTV2Card::GetTaskMode
virtual bool GetTaskMode(NTV2TaskMode &outMode)
Retrieves the device's current task mode.
Definition: ntv2register.cpp:184
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
CNTV2Card::features
virtual class DeviceCapabilities & features(void)
Definition: ntv2card.h:148
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
process.h
Declares the AJAProcess class.
ULWord
uint32_t ULWord
Definition: ajatypes.h:276
ntv2devicescanner.h
Declares the CNTV2DeviceScanner class.
CNTV2MacDriverInterface::GetStreamingApplication
virtual bool GetStreamingApplication(ULWord &outAppType, int32_t &outProcessID)
Answers with the four-CC type and process ID of the application that currently "owns" the AJA device ...
Definition: ntv2macdriverinterface.cpp:675
ntv2card.h
Declares the CNTV2Card class.
AJAProcess::GetPid
static uint64_t GetPid()
Definition: process.cpp:35
options_popt.h
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:849
CNTV2DemoCommon::Popt::errorStr
virtual const std::string & errorStr(void) const
Definition: ntv2democommon.h:857
NTV2Version
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
CNTV2Card
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
CNTV2DemoCommon::WaitForEnterKeyPress
static void WaitForEnterKeyPress(void)
Prompts the user (via stdout) to press the Return or Enter key, then waits for it to happen.
Definition: ntv2democommon.cpp:1050
CNTV2DriverInterface::IsDeviceReady
virtual bool IsDeviceReady(const bool inCheckValid=(0))
Definition: ntv2driverinterface.cpp:1348
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:220
CNTV2Card::SetHDMIHDRElectroOpticalTransferFunction
virtual bool SetHDMIHDRElectroOpticalTransferFunction(const uint8_t inEOTFByte, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Definition: ntv2hdmi.cpp:992
CNTV2Card::SetHDRData
virtual bool SetHDRData(const HDRFloatValues &inFloatValues, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Definition: ntv2hdmi.cpp:1089
DEC
#define DEC(__x__)
Definition: ntv2publicinterface.h:5769
CNTV2Card::EnableHDMIHDR
virtual bool EnableHDMIHDR(const bool inEnableHDMIHDR, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Enables or disables HDMI HDR.
Definition: ntv2hdmi.cpp:1036
ntv2democommon.h
This file contains some structures, constants, classes and functions that are used in some of the dem...
std
Definition: json.hpp:5362
appSignature
ULWord appSignature(0)
POPT_TABLEEND
#define POPT_TABLEEND
Definition: options_popt.h:215
CNTV2MacDriverInterface::AcquireStreamForApplication
virtual bool AcquireStreamForApplication(ULWord inApplicationType, int32_t inProcessID)
Reserves exclusive use of the AJA device for a given process, preventing other processes on the host ...
Definition: ntv2macdriverinterface.cpp:505
HDRRegValues::setBT2020
HDRRegValues & setBT2020(void)
Definition: ntv2publicinterface.h:10241
HDRRegValues
defined(NTV2_DEPRECATE_17_6)
Definition: ntv2publicinterface.h:10215
CNTV2Card::EnableHDMIHDRDolbyVision
virtual bool EnableHDMIHDRDolbyVision(const bool inEnable, const NTV2Channel inWhichHDMIOut=NTV2_CHANNEL1)
Enables or disables HDMI HDR Dolby Vision.
Definition: ntv2hdmi.cpp:1063
POPT_ARG_STRING
#define POPT_ARG_STRING
Definition: options_popt.h:57
POPT_ARG_NONE
#define POPT_ARG_NONE
Definition: options_popt.h:56
HDRRegValues::electroOpticalTransferFunction
uint8_t electroOpticalTransferFunction
Definition: ntv2publicinterface.h:10229
NTV2_TASK_MODE_INVALID
@ NTV2_TASK_MODE_INVALID
Definition: ntv2publicinterface.h:4467
NTV2_OEM_TASKS
@ NTV2_OEM_TASKS
2: OEM (recommended): device configured by client application(s) with some driver involvement.
Definition: ntv2publicinterface.h:4466