AJA NTV2 SDK  18.1.0.2262
NTV2 SDK 18.1.0.2262
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 "ntv2utils.h"
17 #include "ntv2vpid.h"
18 #include "ajabase/common/types.h"
23 #include "ajabase/system/thread.h"
24 #include "ajabase/system/info.h"
26 #include "ajabase/system/process.h"
27 #include "ntv2captiondecoder608.h"
28 #include "ntv2captiondecoder708.h"
29 
30 
31 typedef enum _OutputMode
32 {
39 } OutputMode;
40 
41 #define IS_VALID_OutputMode(_x_) ((_x_) >= kOutputMode_CaptionStream && (_x_) < kOutputMode_INVALID)
42 
43 
44 typedef enum _CaptionDataSrc
45 {
46  kCaptionDataSrc_Default, // Best available
54 
55 #define IS_VALID_CaptionDataSrc(_x_) ((_x_) >= kCaptionDataSrc_Default && (_x_) < kCaptionDataSrc_INVALID)
56 
57 
61 typedef struct CCGrabberConfig : public CaptureConfig
62 {
63  public:
69  bool fUseVanc;
70 
74  inline explicit CCGrabberConfig (const std::string & inDeviceSpecifier = "0")
75  : CaptureConfig (inDeviceSpecifier),
81  fUseVanc (false)
82  {
83  fWithAnc = true;
84  fWithAudio = false;
85  }
86  unsigned GetNumSourceSpecs (void) const {return (NTV2_IS_VALID_CHANNEL(fInputChannel)?1:0)
88  AJALabelValuePairs Get (const bool inCompact = false) const;
89 
90  static std::string GetLegalOutputModes (void);
91  static std::string OutputModeToString (const OutputMode inMode);
92  static OutputMode StringToOutputMode (const std::string & inModeStr);
93  static std::string GetLegalCaptionDataSources (void);
94  static std::string CaptionDataSrcToString (const CaptionDataSrc inDataSrc);
95  static CaptionDataSrc StringToCaptionDataSrc (const std::string & inDataSrcStr);
97 
98 std::ostream & operator << (std::ostream & ioStrm, const CCGrabberConfig & inObj);
99 
100 
111 {
112  // Public Class Methods
113  public:
119  static std::string GetLine21ChannelNames (std::string inDelimiter = ", ");
120 
121 
122  // Public Instance Methods
123  public:
129  NTV2CCGrabber (const CCGrabberConfig & inConfigData);
130  virtual ~NTV2CCGrabber ();
131 
135  virtual AJAStatus Init (void);
136 
141  virtual AJAStatus Run (void);
142 
146  virtual void Quit (void);
147 
152  virtual void SetCaptionDisplayChannel (const NTV2Line21Channel inNewChannel);
153 
154 
158  virtual inline bool IsCaptureThreadRunning (void) const {return mCaptureThread.Active();}
159 
160 
164  virtual inline bool IsPlayThreadRunning (void) const {return mPlayoutThread.Active();}
165 
169  virtual AJAStatus StartPlayThread (void);
170 
175  virtual inline void ToggleHUD (void) {mHeadUpDisplayOn = !mHeadUpDisplayOn;}
176 
177  virtual void ToggleVANC (void);
178  virtual void SwitchOutput(void);
179  virtual void Switch608Source(void);
180  virtual void SwitchPixelFormat(void);
181 
182  // Protected Instance Methods
183  protected:
187  virtual AJAStatus SetupInputVideo (void);
188 
192  virtual AJAStatus SetupAudio (void);
193 
199  virtual bool RouteInputSignal (const NTV2VideoFormat inVideoFormat);
200 
205  virtual void SetOutputStandards (const NTV2VideoFormat inVideoFormat);
206 
210  virtual AJAStatus StartCaptureThread (void);
211 
215  virtual void CaptureFrames (void);
216 
222 
228  virtual AJAStatus SetupHostBuffers (const NTV2VideoFormat inVideoFormat);
229 
233  virtual void ReleaseHostBuffers (void);
234 
241  virtual void ExtractClosedCaptionData (const uint32_t inFrameCount, const NTV2VideoFormat inVideoFormat);
242 
243 
249  virtual AJAStatus SetupOutputVideo (const NTV2VideoFormat inVideoFormat);
250 
257  virtual void DoCCOutput (const uint32_t inFrameNum, const CaptionData & inCCData, const NTV2VideoFormat inVideoFormat);
258 
263  virtual bool RouteOutputSignal (const NTV2VideoFormat inVideoFormat);
264 
268  virtual void PlayFrames (void);
269 
270 
275  virtual void CaptioningChanged (const NTV2Caption608ChangeInfo & inChangeInfo);
276 
277 
278  // Protected Class Methods
279  protected:
287  static void CaptureThreadStatic (AJAThread * pThread, void * pContext);
288 
296  static void PlayThreadStatic (AJAThread * pThread, void * pContext);
297 
303  static void Caption608ChangedStatic (void * pInstance, const NTV2Caption608ChangeInfo & inChangeInfo);
304 
305 
306  // Instance Data
307  private:
308  CCGrabberConfig mConfig;
309  mutable AJAThread mCaptureThread;
310  CNTV2Card mDevice;
311  NTV2DeviceID mDeviceID;
312  NTV2TaskMode mSavedTaskMode;
313  NTV2AudioSystem mAudioSystem;
314  NTV2VANCMode mVancMode;
315  bool mGlobalQuit;
316  bool mSquares;
317  std::string mLastOutStr;
318  uint32_t mFirstOutFrame;
319  uint32_t mLastOutFrame;
320  ULWord mErrorTally;
321  ULWord mCaptionDataTally;
322  NTV2Line21Channel m608Channel;
323  NTV2Line21Mode m608Mode;
324  CNTV2CaptionDecoder608Ptr m608Decoder;
325  CNTV2CaptionDecoder708Ptr m708DecoderAnc;
326  CNTV2CaptionDecoder708Ptr m708DecoderVanc;
327  CNTV2VPID mVPIDInfoDS1;
328  CNTV2VPID mVPIDInfoDS2;
329  NTV2ChannelSet mInputFrameStores;
330  NTV2ChannelSet mActiveSDIInputs;
331  NTV2ChannelSet mActiveCSCs;
332  NTV2XptConnections mInputConnections;
333  NTV2FrameDataArray mHostBuffers;
334  FrameDataRingBuffer mCircularBuffer;
335  AUTOCIRCULATE_TRANSFER mInputXferInfo;
336 
337  // Instance data only used for caption burn-in:
338  bool mHeadUpDisplayOn;
339  NTV2Channel mOutputChannel;
340  NTV2FrameBufferFormat mPlayoutFBF;
341  mutable AJAThread mPlayoutThread;
342  NTV2ChannelSet mOutputFrameStores;
343  NTV2XptConnections mOutputConnections;
344 
345 }; // NTV2CCGrabber
346 
347 #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:3898
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:65
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:221
NTV2TaskMode
Describes the task mode state. See also: NTV2 Device Sharing.
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:69
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:68
CCGrabberConfig(const std::string &inDeviceSpecifier="0")
Constructs a default CCPlayer configuration.
Definition: ntv2ccgrabber.h:74
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:61
Declares the AJATimeCodeBurn class.
#define false
uint32_t ULWord
Definition: ajatypes.h:236
NTV2Channel
These enum values are mostly used to identify a specific widget_framestore. They&#39;re also commonly use...
Definition: ntv2enums.h:1359
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:86
_CaptionDataSrc
Definition: ntv2ccgrabber.h:44
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:3954
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:31
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:67
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:1373
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.
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:1286
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:3800
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:66
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:64
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)