AJA NTV2 SDK  17.1.1.1245
NTV2 SDK 17.1.1.1245
ancillarydata_cea608.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MIT */
8 #include "ancillarydata_cea608.h"
9 #include <ios>
10 #include <iomanip>
11 
12 using namespace std;
13 
14 
16 {
17  Init();
18 }
19 
20 
22 {
23  Init();
24 
25  *this = clone;
26 }
27 
28 
30 {
31  Init();
32 
33  if (pClone != NULL_PTR)
34  *this = *pClone;
35 }
36 
37 
39 {
40  Init();
41 }
42 
43 
45 {
46 }
47 
48 
49 void
51 {
52  m_char1 = 0x80; // CEA-608 "Null" character (with parity)
53  m_char2 = 0x80;
54 }
55 
56 
58 {
59  if (this != &rhs) // ignore self-assignment
60  {
61  AJAAncillaryData::operator= (rhs); // copy the base class stuff
62 
63  // copy the local stuff
64  m_char1 = rhs.m_char1;
65  m_char2 = rhs.m_char2;
66  }
67  return *this;
68 }
69 
70 
72 {
74  Init();
75 }
76 
77 
78 //------------------------------
79 // Get/Set 8-bit bytes: we assume the caller has already dealt with the parity
80 
81 AJAStatus AJAAncillaryData_Cea608::SetCEA608Bytes (const uint8_t byte1, const uint8_t byte2)
82 {
83  m_char1 = byte1;
84  m_char2 = byte2;
85  return AJA_STATUS_SUCCESS;
86 }
87 
88 
89 AJAStatus AJAAncillaryData_Cea608::GetCEA608Bytes (uint8_t & byte1, uint8_t & byte2, bool & bRcvdData) const
90 {
91  byte1 = m_char1;
92  byte2 = m_char2;
93  bRcvdData = m_rcvDataValid;
94  return AJA_STATUS_SUCCESS;
95 }
96 
97 
98 //------------------------------
99 // Get/Set 7-bit characters: automatically add/delete odd parity to bit 7
100 
102 {
103  m_char1 = AddOddParity (char1);
104  m_char2 = AddOddParity (char2);
105  return AJA_STATUS_SUCCESS;
106 }
107 
108 
109 uint8_t AJAAncillaryData_Cea608::AddOddParity (const uint8_t inChar)
110 {
111  // add odd parity to bit 7
112  uint8_t onesCount = 0;
113  uint8_t shiftChar = inChar;
114 
115  // count the number of 1's in the ls 7 bits
116  for (uint8_t i = 0; i < 7; i++)
117  {
118  if ((shiftChar & 0x01) != 0)
119  onesCount++;
120 
121  shiftChar = shiftChar >> 1;
122  }
123 
124  // set bit 7 to make the total number of 1's odd
125  if ((onesCount % 2) == 1) // we already have an odd number of 1's: set bit 7 = 0
126  return (inChar & 0x7F);
127  else // we have an even number of 1's: set bit 7 = 1 to make the total odd
128  return (inChar | 0x80);
129 }
130 
131 
132 AJAStatus AJAAncillaryData_Cea608::GetCEA608Characters (uint8_t & char1, uint8_t & char2, bool & bRcvdData) const
133 {
134  char1 = m_char1 & 0x7F; // strip parity bit before returning
135  char2 = m_char2 & 0x7F;
136  bRcvdData = m_rcvDataValid;
137  return AJA_STATUS_SUCCESS;
138 }
139 
140 
142 {
143  (void) pInAncData;
144  // Since the AJAAncillaryData_Cea608 object has no "concrete" transport of its own,
145  // this has to be done by its subclasses.
146  return AJAAncDataType_Unknown;
147 }
148 
149 ostream & AJAAncillaryData_Cea608::Print (ostream & oss, const bool bShowDetail) const
150 {
151  AJAAncillaryData::Print (oss, bShowDetail);
152  const uint8_t char1 (m_char1 & 0x7F); // strip parity and see if we can print it a an ASCII character
153  const uint8_t char2 (m_char2 & 0x7F);
154 
155  oss << endl
156  << "CEA608";
157  if (IsRaw() && GetDataLocation().GetLineNumber()) // If analog/raw and valid line number
158  oss << (GetDataLocation().GetLineNumber() > 264 ? " F2" : " F1");
159  oss << " Caption Byte1=" << xHEX0N(uint16_t(m_char1),2);
160  if (char1 >= 0x20 && char1 < 0x7F)
161  oss << " ('" << char1 << "')";
162  oss << " Byte2=" << xHEX0N(uint16_t(m_char2),2);
163  if (char2 >= 0x20 && char2 < 0x7F)
164  oss << " ('" << char2 << "')";
165  return oss;
166 }
AJAAncillaryData_Cea608::SetCEA608Bytes
virtual AJAStatus SetCEA608Bytes(const uint8_t inByte1, const uint8_t inByte2)
Set the CEA608 payload bytes.
Definition: ancillarydata_cea608.cpp:81
NULL_PTR
#define NULL_PTR
Definition: types.h:325
AJAAncillaryData_Cea608::Print
virtual std::ostream & Print(std::ostream &inOutStream, const bool inDetailed=false) const
Streams a human-readable representation of me to the given output stream.
Definition: ancillarydata_cea608.cpp:149
AJAAncillaryData_Cea608::GetCEA608Bytes
virtual AJAStatus GetCEA608Bytes(uint8_t &outByte1, uint8_t &outByte2, bool &outIsValid) const
Answers with the CEA608 payload bytes.
Definition: ancillarydata_cea608.cpp:89
AJAAncDataType_Unknown
@ AJAAncDataType_Unknown
Includes data that is valid, but we don't recognize.
Definition: ancillarydata.h:46
AJA_STATUS_SUCCESS
@ AJA_STATUS_SUCCESS
Definition: types.h:381
AJAAncillaryData_Cea608::Clear
virtual void Clear(void)
Frees my allocated memory, if any, and resets my members to their default values.
Definition: ancillarydata_cea608.cpp:71
AJAAncDataType
AJAAncDataType
Identifies the ancillary data types that are known to this module.
Definition: ancillarydata.h:44
nlohmann::json_abiNLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON_v3_11_NLOHMANN_JSON_VERSION_PATCH::detail::void
j template void())
Definition: json.hpp:4893
AJAStatus
AJAStatus
Definition: types.h:378
AJAAncillaryData_Cea608::RecognizeThisAncillaryData
static AJAAncDataType RecognizeThisAncillaryData(const AJAAncillaryData *pInAncData)
Definition: ancillarydata_cea608.cpp:141
AJAAncillaryData::Print
virtual std::ostream & Print(std::ostream &inOutStream, const bool inDetailed=false) const
Streams a human-readable representation of me to the given output stream.
Definition: ancillarydata.cpp:1409
AJAAncillaryData_Cea608
This is the base class for handling CEA-608 caption data packets.
Definition: ancillarydata_cea608.h:18
AJAAncillaryData_Cea608::AJAAncillaryData_Cea608
AJAAncillaryData_Cea608()
My default constructor.
Definition: ancillarydata_cea608.cpp:15
AJAAncillaryData
I am the principal class that stores a single SMPTE-291 SDI ancillary data packet OR the digitized co...
Definition: ancillarydata.h:552
ancillarydata_cea608.h
Declares the AJAAncillaryData_Cea608 class.
AJAAncillaryData_Cea608::AddOddParity
static uint8_t AddOddParity(const uint8_t inValue)
Set/Clear bit 7 of a byte to make odd parity.
Definition: ancillarydata_cea608.cpp:109
AJAAncillaryData_Cea608::Init
void Init(void)
Definition: ancillarydata_cea608.cpp:50
AJAAncillaryData::m_rcvDataValid
bool m_rcvDataValid
This is set true (or not) by ParsePayloadData()
Definition: ancillarydata.h:1158
AJAAncillaryData_Cea608::GetCEA608Characters
virtual AJAStatus GetCEA608Characters(uint8_t &outChar1, uint8_t &outChar2, bool &outIsValid) const
Answers with the CEA608 payload characters.
Definition: ancillarydata_cea608.cpp:132
AJAAncillaryData::Clear
virtual void Clear(void)
Frees my allocated memory, if any, and resets my members to their default values.
Definition: ancillarydata.cpp:159
AJAAncillaryData_Cea608::~AJAAncillaryData_Cea608
virtual ~AJAAncillaryData_Cea608()
My destructor.
Definition: ancillarydata_cea608.cpp:44
AJAAncillaryData::operator=
AJAAncillaryData & operator=(const AJAAncillaryData &inRHS)
Definition: ancillarydata.cpp:1576
std
Definition: json.hpp:5362
AJAAncillaryData_Cea608::SetCEA608Characters
virtual AJAStatus SetCEA608Characters(const uint8_t inChar1, const uint8_t inChar2)
Sets the CEA608 payload characters. Uses the least significant 7 bits of the input values and adds od...
Definition: ancillarydata_cea608.cpp:101
IsRaw
bool IsRaw(const NTV2FrameBufferFormat format)
Definition: ntv2utils.cpp:5478
AJAAncillaryData_Cea608::m_char1
uint8_t m_char1
Definition: ancillarydata_cea608.h:118
AJAAncillaryData_Cea608::m_char2
uint8_t m_char2
Definition: ancillarydata_cea608.h:119
xHEX0N
#define xHEX0N(__x__, __n__)
Definition: ntv2publicinterface.h:5604
AJAAncillaryData_Cea608::operator=
AJAAncillaryData_Cea608 & operator=(const AJAAncillaryData_Cea608 &inRHS)
Assignment operator – replaces my contents with the right-hand-side value.
Definition: ancillarydata_cea608.cpp:57