AJA NTV2 SDK  18.0.0.2122
NTV2 SDK 18.0.0.2122
ntv2ccgrabber.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
9 #ifndef _NTV2CCGRABBER_H
10 #define _NTV2CCGRABBER_H
11 
12 #include "ntv2enums.h"
13 #include "ntv2devicefeatures.h"
14 #include "ntv2devicescanner.h"
15 #include "ntv2democommon.h"
16 #include "ntv2task.h"
17 #include "ntv2utils.h"
18 #include "ntv2vpid.h"
19 #include "ajabase/common/types.h"
24 #include "ajabase/system/thread.h"
25 #include "ajabase/system/info.h"
27 #include "ajabase/system/process.h"
28 #include "ntv2captiondecoder608.h"
29 #include "ntv2captiondecoder708.h"
30 
31 
32 typedef enum _OutputMode
33 {
40 } OutputMode;
41 
42 #define IS_VALID_OutputMode(_x_) ((_x_) >= kOutputMode_CaptionStream && (_x_) < kOutputMode_INVALID)
43 
44 
45 typedef enum _CaptionDataSrc
46 {
47  kCaptionDataSrc_Default, // Best available
55 
56 #define IS_VALID_CaptionDataSrc(_x_) ((_x_) >= kCaptionDataSrc_Default && (_x_) < kCaptionDataSrc_INVALID)
57 
58 
62 typedef struct CCGrabberConfig : public CaptureConfig
63 {
64  public:
70  bool fUseVanc;
71 
75  inline explicit CCGrabberConfig (const std::string & inDeviceSpecifier = "0")
76  : CaptureConfig (inDeviceSpecifier),
82  fUseVanc (false)
83  {
84  fWithAnc = true;
85  fWithAudio = false;
86  }
87  unsigned GetNumSourceSpecs (void) const {return (NTV2_IS_VALID_CHANNEL(fInputChannel)?1:0)
89  AJALabelValuePairs Get (const bool inCompact = false) const;
90 
91  static std::string GetLegalOutputModes (void);
92  static std::string OutputModeToString (const OutputMode inMode);
93  static OutputMode StringToOutputMode (const std::string & inModeStr);
94  static std::string GetLegalCaptionDataSources (void);
95  static std::string CaptionDataSrcToString (const CaptionDataSrc inDataSrc);
96  static CaptionDataSrc StringToCaptionDataSrc (const std::string & inDataSrcStr);
98 
99 std::ostream & operator << (std::ostream & ioStrm, const CCGrabberConfig & inObj);
100 
101 
112 {
113  // Public Class Methods
114  public:
120  static std::string GetLine21ChannelNames (std::string inDelimiter = ", ");
121 
122 
123  // Public Instance Methods
124  public:
130  NTV2CCGrabber (const CCGrabberConfig & inConfigData);
131  virtual ~NTV2CCGrabber ();
132 
136  virtual AJAStatus Init (void);
137 
142  virtual AJAStatus Run (void);
143 
147  virtual void Quit (void);
148 
153  virtual void SetCaptionDisplayChannel (const NTV2Line21Channel inNewChannel);
154 
155 
159  virtual inline bool IsCaptureThreadRunning (void) const {return mCaptureThread.Active();}
160 
161 
165  virtual inline bool IsPlayThreadRunning (void) const {return mPlayoutThread.Active();}
166 
170  virtual AJAStatus StartPlayThread (void);
171 
176  virtual inline void ToggleHUD (void) {mHeadUpDisplayOn = !mHeadUpDisplayOn;}
177 
178  virtual void ToggleVANC (void);
179  virtual void SwitchOutput(void);
180  virtual void Switch608Source(void);
181  virtual void SwitchPixelFormat(void);
182 
183  // Protected Instance Methods
184  protected:
188  virtual AJAStatus SetupInputVideo (void);
189 
193  virtual AJAStatus SetupAudio (void);
194 
200  virtual bool RouteInputSignal (const NTV2VideoFormat inVideoFormat);
201 
206  virtual void SetOutputStandards (const NTV2VideoFormat inVideoFormat);
207 
211  virtual AJAStatus StartCaptureThread (void);
212 
216  virtual void CaptureFrames (void);
217 
223 
229  virtual AJAStatus SetupHostBuffers (const NTV2VideoFormat inVideoFormat);
230 
234  virtual void ReleaseHostBuffers (void);
235 
242  virtual void ExtractClosedCaptionData (const uint32_t inFrameCount, const NTV2VideoFormat inVideoFormat);
243 
244 
250  virtual AJAStatus SetupOutputVideo (const NTV2VideoFormat inVideoFormat);
251 
258  virtual void DoCCOutput (const uint32_t inFrameNum, const CaptionData & inCCData, const NTV2VideoFormat inVideoFormat);
259 
264  virtual bool RouteOutputSignal (const NTV2VideoFormat inVideoFormat);
265 
269  virtual void PlayFrames (void);
270 
271 
276  virtual void CaptioningChanged (const NTV2Caption608ChangeInfo & inChangeInfo);
277 
278 
279  // Protected Class Methods
280  protected:
288  static void CaptureThreadStatic (AJAThread * pThread, void * pContext);
289 
297  static void PlayThreadStatic (AJAThread * pThread, void * pContext);
298 
304  static void Caption608ChangedStatic (void * pInstance, const NTV2Caption608ChangeInfo & inChangeInfo);
305 
306 
307  // Instance Data
308  private:
309  CCGrabberConfig mConfig;
310  mutable AJAThread mCaptureThread;
311  CNTV2Card mDevice;
312  NTV2DeviceID mDeviceID;
313  NTV2TaskMode mSavedTaskMode;
314  NTV2AudioSystem mAudioSystem;
315  NTV2VANCMode mVancMode;
316  bool mGlobalQuit;
317  bool mSquares;
318  std::string mLastOutStr;
319  uint32_t mFirstOutFrame;
320  uint32_t mLastOutFrame;
321  ULWord mErrorTally;
322  ULWord mCaptionDataTally;
323  NTV2Line21Channel m608Channel;
324  NTV2Line21Mode m608Mode;
325  CNTV2CaptionDecoder608Ptr m608Decoder;
326  CNTV2CaptionDecoder708Ptr m708DecoderAnc;
327  CNTV2CaptionDecoder708Ptr m708DecoderVanc;
328  CNTV2VPID mVPIDInfoDS1;
329  CNTV2VPID mVPIDInfoDS2;
330  NTV2ChannelSet mInputFrameStores;
331  NTV2ChannelSet mActiveSDIInputs;
332  NTV2ChannelSet mActiveCSCs;
333  NTV2XptConnections mInputConnections;
334  NTV2FrameDataArray mHostBuffers;
335  FrameDataRingBuffer mCircularBuffer;
336  AUTOCIRCULATE_TRANSFER mInputXferInfo;
337 
338  // Instance data only used for caption burn-in:
339  bool mHeadUpDisplayOn;
340  NTV2Channel mOutputChannel;
341  NTV2FrameBufferFormat mPlayoutFBF;
342  mutable AJAThread mPlayoutThread;
343  NTV2ChannelSet mOutputFrameStores;
344  NTV2XptConnections mOutputConnections;
345 
346 }; // NTV2CCGrabber
347 
348 #endif // _NTV2CCGRABBER_H
virtual ~NTV2CCGrabber()
virtual bool IsPlayThreadRunning(void) const
Returns true if my play thread is currently running.
virtual void SetCaptionDisplayChannel(const NTV2Line21Channel inNewChannel)
Changes the caption channel I&#39;m displaying.
NTV2AudioSystem
Used to identify an Audio System on an NTV2 device. See Audio System Operation for more information...
Definition: ntv2enums.h:3895
Declares common types used in the ajabase library.
virtual bool RouteOutputSignal(const NTV2VideoFormat inVideoFormat)
This class is used to respond to dynamic events that occur during CEA-608 caption decoding...
CaptionDataSrc fCaptionSrc
Caption data source (Line21? 608 VANC? 608 Anc? etc)
Definition: ntv2ccgrabber.h:66
I interrogate and control an AJA video/audio capture/playout device.
Definition: ntv2card.h:28
NTV2FrameBufferFormat
Identifies a particular video frame buffer pixel format. See Device Frame Buffer Formats for details...
Definition: ntv2enums.h:219
NTV2TaskMode
Describes the task mode state. See also: Sharing AJA Devices With Other Applications.
AJAStatus
Definition: types.h:380
Declares the CNTV2VPID class. See SMPTE 352 standard for details.
enum _NTV2VideoFormat NTV2VideoFormat
Identifies a particular video format.
bool fUseVanc
If true, use Vanc, even if the device supports Anc insertion.
Definition: ntv2ccgrabber.h:70
static void Caption608ChangedStatic(void *pInstance, const NTV2Caption608ChangeInfo &inChangeInfo)
This static function gets called whenever 608 captioning changes.
virtual NTV2VideoFormat WaitForStableInputSignal(void)
Wait for a stable input signal, and return it.
std::vector< AJALabelValuePair > AJALabelValuePairs
An ordered sequence of label/value pairs.
Definition: info.h:71
Declares the AJATime class.
bool fWithAnc
If true, also capture Anc.
bool fBurnCaptions
If true, burn-in captions on 2nd channel.
Definition: ntv2ccgrabber.h:69
CCGrabberConfig(const std::string &inDeviceSpecifier="0")
Constructs a default CCPlayer configuration.
Definition: ntv2ccgrabber.h:75
static void CaptureThreadStatic(AJAThread *pThread, void *pContext)
This is the capture thread&#39;s static callback function that gets called when the capture thread runs...
I can decode captions from frames captured from an AJA device in real time. I can optionally play the...
virtual bool IsCaptureThreadRunning(void) const
Returns true if my capture thread is currently running.
virtual AJAStatus Run(void)
Runs me.
This class is used to configure an NTV2CCGrabber instance.
Definition: ntv2ccgrabber.h:62
Declares the AJATimeCodeBurn class.
#define false
uint32_t ULWord
Definition: ajatypes.h:223
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1357
virtual void ToggleVANC(void)
Toggles the use of VANC. (Debug, experimental)
virtual void PlayFrames(void)
Repeatedly updates captions (until global quit flag set).
unsigned GetNumSourceSpecs(void) const
Definition: ntv2ccgrabber.h:87
_CaptionDataSrc
Definition: ntv2ccgrabber.h:45
bool fWithAudio
If true, also capture Audio.
static void PlayThreadStatic(AJAThread *pThread, void *pContext)
This is the playout thread&#39;s static callback function that gets called when the playout thread runs...
NTV2Channel fInputChannel
The device channel to use.
virtual bool Active()
Definition: thread.cpp:116
NTV2TCIndex
These enum values are indexes into the capture/playout AutoCirculate timecode arrays.
Definition: ntv2enums.h:3951
std::ostream & operator<<(std::ostream &ioStrm, const CCGrabberConfig &inObj)
virtual AJAStatus SetupInputVideo(void)
Sets up everything I need for capturing video.
_OutputMode
Definition: ntv2ccgrabber.h:32
virtual AJAStatus SetupAudio(void)
Sets up audio for capture (and playout, if burning captions).
NTV2DeviceID
Identifies a specific AJA NTV2 device model number. The NTV2DeviceID is actually the PROM part number...
Definition: ntv2enums.h:20
Enumerations for controlling NTV2 devices.
This class is used to configure an NTV2Capture instance.
Declares the AJAThread class.
virtual AJAStatus Init(void)
Initializes me and prepares me to Run.
Declares the CNTV2CaptionDecoder708 class.
NTV2CCGrabber(const CCGrabberConfig &inConfigData)
Constructs me using the given configuration settings.
virtual void Switch608Source(void)
Switches/rotates –608src.
NTV2Line21Channel fCaptionChannel
Caption channel to monitor (defaults to CC1)
Definition: ntv2ccgrabber.h:68
Caption channel 1, the primary caption channel.
virtual void SwitchPixelFormat(void)
Switches/rotates –pixelFormat.
virtual AJAStatus SetupOutputVideo(const NTV2VideoFormat inVideoFormat)
Sets up everything I need for capturing video.
virtual void ReleaseHostBuffers(void)
Releases my circular buffers.
static std::string OutputModeToString(const OutputMode inMode)
Declares the CNTV2DeviceScanner class.
enum _CaptionDataSrc CaptionDataSrc
#define NTV2_IS_VALID_CHANNEL(__x__)
Definition: ntv2enums.h:1371
virtual void CaptureFrames(void)
Repeatedly captures frames using AutoCirculate (until global quit flag set).
Declares the AJAProcess class.
virtual AJAStatus StartCaptureThread(void)
Starts my capture thread.
Declares the CNTV2Task class (deprecated).
std::vector< NTV2FrameData > NTV2FrameDataArray
A vector of NTV2FrameData elements.
virtual void SetOutputStandards(const NTV2VideoFormat inVideoFormat)
Sets the device output standard based on the given video format.
Declaration of AJACircularBuffer template class.
This object specifies the information that will be transferred to or from the AJA device in the CNTV2...
virtual AJAStatus SetupHostBuffers(const NTV2VideoFormat inVideoFormat)
Sets up my circular buffers.
Declares the AJATimeCode class.
NTV2InputSource fInputSource
The device input connector to use.
virtual void DoCCOutput(const uint32_t inFrameNum, const CaptionData &inCCData, const NTV2VideoFormat inVideoFormat)
Outputs CC data.
virtual AJAStatus StartPlayThread(void)
Starts my playout thread.
std::set< NTV2Channel > NTV2ChannelSet
A set of distinct NTV2Channel values.
#define NTV2_IS_VALID_INPUT_SOURCE(_inpSrc_)
Definition: ntv2enums.h:1284
virtual void SwitchOutput(void)
Switches/rotates –output mode.
Declares numerous NTV2 utility functions.
virtual bool RouteInputSignal(const NTV2VideoFormat inVideoFormat)
Declares the AJASystemInfo class.
This structure encapsulates all possible CEA-608 caption data bytes that may be associated with a giv...
NTV2VANCMode
These enum values identify the available VANC modes.
Definition: ntv2enums.h:3797
static CaptionDataSrc StringToCaptionDataSrc(const std::string &inDataSrcStr)
static OutputMode StringToOutputMode(const std::string &inModeStr)
A convenience class that simplifies encoding or decoding the 4-byte VPID payload that can be read or ...
Definition: ntv2vpid.h:23
enum _OutputMode OutputMode
static std::string GetLegalCaptionDataSources(void)
This file contains some structures, constants, classes and functions that are used in some of the dem...
virtual void Quit(void)
Gracefully stops me from running.
virtual void ExtractClosedCaptionData(const uint32_t inFrameCount, const NTV2VideoFormat inVideoFormat)
Extracts closed-caption data, if present, and emits it on a character-by-character basis to the stand...
NTV2TCIndex fTimecodeSource
Timecode source to use (if any)
Definition: ntv2ccgrabber.h:67
virtual void ToggleHUD(void)
Toggles the Head-Up-Display.
AJALabelValuePairs Get(const bool inCompact=(0)) const
NTV2Line21Mode
The CEA-608 modes: pop-on, roll-up (2, 3 and 4-line), and paint-on.
std::map< NTV2InputXptID, NTV2OutputXptID > NTV2XptConnections
OutputMode fOutputMode
Desired output (captionStream, Screen etc)
Definition: ntv2ccgrabber.h:65
static std::string GetLegalOutputModes(void)
Declares the CNTV2CaptionDecoder608 class.
NTV2Line21Channel
The CEA-608 caption channels: CC1 thru CC4, TX1 thru TX4, plus XDS.
Declares the enumeration constants used in the ajabase library.
virtual void CaptioningChanged(const NTV2Caption608ChangeInfo &inChangeInfo)
This function gets called whenever caption changes occur.
I am a circular frame buffer that simplifies implementing a type-safe producer/consumer model for pro...
static std::string GetLine21ChannelNames(std::string inDelimiter=", ")
Returns a string containing a concatenation of human-readable names of every available NTV2Line21Chan...
Declares device capability functions.
CCGrabberConfig CCGrabberConfig
This class is used to configure an NTV2CCGrabber instance.
static std::string CaptionDataSrcToString(const CaptionDataSrc inDataSrc)