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 */
10 // Includes
11 #include "ajatypes.h"
13 #include "ajabase/common/types.h"
14 #include "ajabase/system/process.h"
16 #include "ntv2card.h"
17 #include "ntv2devicefeatures.h"
18 #include "ntv2devicescanner.h"
19 #include "ntv2utils.h"
20 
21 #include "ntv2democommon.h"
22 #include <signal.h>
23 #include <iostream>
24 #include <iomanip>
25 
26 using namespace std;
27 
28 
29 // Globals
30 const uint32_t kAppSignature (NTV2_FOURCC('H','d','r','s'));
31 
32 
39 int main (int argc, const char ** argv)
40 {
41  char * pDeviceSpec (AJA_NULL); // Which device to use
42  int eotf (0); // EOTF to enable 0,1,2,3
43  int constLuminance (0); // Constant luminanace?
44  int dolbyVision (0); // Enable dolby vision bit?
45  int verbose (0); // Verbose mode?
46  int noHDR (0); // Disable hdr?
47  int showVersion (0); // Show version and exit?
49 
50  // Command line option descriptions:
51  const CNTV2DemoCommon::PoptOpts optionsTable [] =
52  {
53  {"device", 'd', POPT_ARG_STRING, &pDeviceSpec, 0, "device to use", "index#, serial#, or model"},
54  {"eotf", 'e', POPT_ARG_INT, &eotf, 0, "0=TradGammaSDR 1=TradGammaHDR 2=ST2084 3=HLG", "EOTF to use"},
55  {"luminance", 'l', POPT_ARG_NONE, &constLuminance, 0, "constant luminance?", AJA_NULL },
56  {"dolbyvision", 0, POPT_ARG_NONE, &dolbyVision, 0, "enable DolbyVision bit?", AJA_NULL },
57  {"nohdr", 0, POPT_ARG_NONE, &noHDR, 0, "disable HDMI HDR output?", AJA_NULL },
58  {"verbose", 'v', POPT_ARG_NONE, &verbose, 0, "verbose output?", AJA_NULL },
59  {"version", 0, POPT_ARG_NONE, &showVersion, 0, "show version & exit", AJA_NULL },
62  };
63  CNTV2DemoCommon::Popt popt(argc, argv, optionsTable);
64  if (!popt)
65  {cerr << "## ERROR: " << popt.errorStr() << endl; return 1;}
66  if (showVersion)
67  {cout << "NTV2HDRSetup, NTV2 SDK " << ::NTV2Version() << endl; return 0;}
68 
69  if ((eotf < 0) || (eotf > 3))
70  {cerr << "## ERROR: Bad EOTF value '" << DEC(eotf) << "' -- expected 0, 1, 2 or 3" << endl; return 2;}
71 
72  // Open the device...
73  CNTV2Card device;
74  if (!CNTV2DeviceScanner::GetFirstDeviceFromArgument (pDeviceSpec ? pDeviceSpec : "0", device))
75  {cerr << "## ERROR: Device '" << pDeviceSpec << "' not found" << endl; return 3;}
76 
77  if (!device.IsDeviceReady(false))
78  {cerr << "## ERROR: Device '" << pDeviceSpec << "' not ready" << endl; return 4;}
79 
81  {cerr << "## ERROR: Device '" << pDeviceSpec << "' does not support HDMI HDR" << endl; return 5;}
82 
83  // Acquire the device...
84  ULWord appSignature (0);
85  int32_t appPID (0);
87  device.GetEveryFrameServices(savedTaskMode); // Save the current device state
88  device.GetStreamingApplication(appSignature, appPID); // Who currently "owns" the device?
90  {
91  cerr << "## ERROR: Unable to acquire device because another app (pid " << appPID << ") owns it" << endl;
92  return 6; // Device reserved by other app
93  }
94  device.SetEveryFrameServices(NTV2_OEM_TASKS); // Set the OEM service level
95 
96  if (verbose)
97  {
98  static const string sEOTFs[] = {"Traditional Gamma SDR", "Traditional Gamma HDR", "ST-2084", "HLG", ""};
99  cout << "## NOTE: Options specified:" << endl
100  << "\tEOTF: " << DEC(eotf) << " (" << sEOTFs[eotf] << ")" << endl
101  << "\tLuminance: " << (constLuminance ? "Constant" : "Non-Constant") << endl
102  << "\tDolbyVision: " << (dolbyVision ? "Enabled" : "Disabled") << endl;
103  if (noHDR)
104  cout << "## WARNING: --nohdr option will disable HDMI HDR output" << endl;
105  }
106 
107  // Load up the digital primitives with some reasonable values...
108  HDRRegValues registerValues;
109  ::setHDRDefaultsForBT2020(registerValues);
110  registerValues.electroOpticalTransferFunction = uint8_t(eotf);
111  device.SetHDRData(registerValues);
112 
113  // Setup HDR values based on passed args...
114  device.SetHDMIHDRConstantLuminance(bool(constLuminance));
115  device.SetHDMIHDRElectroOpticalTransferFunction(uint8_t(eotf));
116 
117  // Enabling this will allow dolby vision containing frames to properly display out of HDMI
118  device.EnableHDMIHDRDolbyVision(bool(dolbyVision));
119 
120  // The master switch for HDMI HDR output
121  device.EnableHDMIHDR(noHDR ? false : true);
122 
123  // Loop until a key is pressed, that way user can inspect the changes with watcher
125 
126  device.SetEveryFrameServices(savedTaskMode); // Restore prior tasks mode
127  device.ReleaseStreamForApplication (kAppSignature, int32_t(AJAProcess::GetPid())); // Release the device
128 
129  return 0; // Success!
130 
131 } // main
setHDRDefaultsForBT2020
void setHDRDefaultsForBT2020(HDRRegValues &outRegisterValues)
Definition: ntv2utils.cpp:7874
CNTV2Card::EnableHDMIHDR
virtual bool EnableHDMIHDR(const bool inEnableHDMIHDR)
Enables or disables HDMI HDR.
Definition: ntv2hdmi.cpp:923
NTV2_FOURCC
#define NTV2_FOURCC(_a_, _b_, _c_, _d_)
Definition: ntv2publicinterface.h:5413
poptOption
Definition: options_popt.h:148
ntv2devicefeatures.h
Declares device capability functions.
types.h
Declares common types used in the ajabase library.
systemtime.h
Declares the AJATime class.
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:327
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:832
CNTV2Card::SetHDMIHDRConstantLuminance
virtual bool SetHDMIHDRConstantLuminance(const bool inEnableConstantLuminance)
Enables or disables BT.2020 Y'cC'bcC'rc versus BT.2020 Y'C'bC'r or R'G'B'.
Definition: ntv2hdmi.cpp:860
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)))
POPT_ARG_INT
#define POPT_ARG_INT
Definition: options_popt.h:58
ajatypes.h
Declares the most fundamental data types used by NTV2. Since Windows NT was the first principal devel...
POPT_AUTOHELP
#define POPT_AUTOHELP
Definition: options_popt.h:220
process.h
Declares the AJAProcess class.
ULWord
uint32_t ULWord
Definition: ajatypes.h:246
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:944
ntv2card.h
Declares the CNTV2Card class.
AJAProcess::GetPid
static uint64_t GetPid()
Definition: process.cpp:35
CNTV2Card::SetHDMIHDRElectroOpticalTransferFunction
virtual bool SetHDMIHDRElectroOpticalTransferFunction(const uint8_t inEOTFByte)
Definition: ntv2hdmi.cpp:883
options_popt.h
CNTV2DemoCommon::Popt
Definition: ntv2democommon.h:801
ntv2utils.h
Declares numerous NTV2 utility functions.
CNTV2DemoCommon::Popt::errorStr
virtual const std::string & errorStr(void) const
Definition: ntv2democommon.h:809
NTV2Version
std::string NTV2Version(const bool inDetailed=false)
Definition: ntv2version.cpp:41
CNTV2Card::EnableHDMIHDRDolbyVision
virtual bool EnableHDMIHDRDolbyVision(const bool inEnable)
Enables or disables HDMI HDR Dolby Vision.
Definition: ntv2hdmi.cpp:942
CNTV2Card
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:262
NTV2_TASK_MODE_INVALID
@ NTV2_TASK_MODE_INVALID
Definition: ntv2publicinterface.h:4262
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:992
CNTV2DriverInterface::IsDeviceReady
virtual bool IsDeviceReady(const bool inCheckValid=(0))
Definition: ntv2driverinterface.cpp:1228
CNTV2Card::SetEveryFrameServices
virtual bool SetEveryFrameServices(const NTV2EveryFrameTaskMode inMode)
Sets the device's task mode.
Definition: ntv2register.cpp:179
AJADebug::Open
static AJAStatus Open(bool incrementRefCount=false)
Definition: debug.cpp:44
AJA_NULL
#define AJA_NULL
Definition: ajatypes.h:190
DEC
#define DEC(__x__)
Definition: ntv2publicinterface.h:5579
ntv2democommon.h
This file contains some structures, constants, classes and functions that are used in some of the dem...
NTV2DeviceCanDoHDMIHDROut
bool NTV2DeviceCanDoHDMIHDROut(const NTV2DeviceID inDeviceID)
Definition: ntv2devicefeatures.hpp:2896
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:808
NTV2EveryFrameTaskMode
NTV2EveryFrameTaskMode
Describes the task mode state. See also: Sharing AJA Devices With Other Applications.
Definition: ntv2publicinterface.h:4257
CNTV2DriverInterface::GetDeviceID
virtual NTV2DeviceID GetDeviceID(void)
Definition: ntv2driverinterface.cpp:371
CNTV2Card::GetEveryFrameServices
virtual bool GetEveryFrameServices(NTV2EveryFrameTaskMode &outMode)
Retrieves the device's current "retail service" task mode.
Definition: ntv2register.cpp:184
CNTV2Card::SetHDRData
virtual bool SetHDRData(const HDRFloatValues &inFloatValues)
Definition: ntv2hdmi.cpp:961
HDRRegValues
Definition: ntv2publicinterface.h:9832
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:9845
NTV2_OEM_TASKS
@ NTV2_OEM_TASKS
2: OEM: Device is configured by controlling application(s), with minimal driver involvement.
Definition: ntv2publicinterface.h:4261