28 #include <unordered_map>
35 namespace subtecConnector
46 attribs.
winColor.rgb = GSW_CC_EMBEDDED_COLOR;
50 attribs.
fontSize = GSW_CC_FONT_SIZE_EMBEDDED;
52 std::memcpy(attribs.
fontStyle , GSW_CC_FONT_STYLE_EMBEDDED,
sizeof(GSW_CC_FONT_STYLE_EMBEDDED));
54 attribs.
fontItalic = GSW_CC_TEXT_STYLE_EMBEDDED_TEXT;
56 attribs.
borderType = GSW_CC_BORDER_TYPE_EMBEDDED;
58 attribs.
edgeType = GSW_CC_EDGE_TYPE_EMBEDDED;
59 attribs.
edgeColor.rgb = GSW_CC_EMBEDDED_COLOR;
65 CCDataController* CCDataController::Instance()
67 static CCDataController instance;
71 void CCDataController::closedCaptionDataCb (
int decoderIndex, VL_CC_DATA_TYPE eType,
unsigned char* ccData,
72 unsigned dataLength,
int sequenceNumber,
long long localPts)
74 channel.SendDataPacketWithPTS(localPts, ccData, dataLength);
77 void CCDataController::closedCaptionDecodeCb(
int decoderIndex,
int event)
79 logprintf(
"closedCaptionDecodeCb decoderIndex = %d, event = %d", decoderIndex, event);
82 void CCDataController::sendMute()
84 channel.SendMutePacket();
87 void CCDataController::sendUnmute()
89 channel.SendUnmutePacket();
92 void CCDataController::sendPause()
94 channel.SendPausePacket();
97 void CCDataController::sendResume()
99 channel.SendResumePacket();
102 void CCDataController::sendResetChannelPacket()
104 channel.SendResetChannelPacket();
107 CCDataController::CCDataController()
109 , currentAttributes{createDefaultAttributes()}
113 void CCDataController::ccSetDigitalChannel(
unsigned int channelId)
115 channel.SendActiveTypePacket(ClosedCaptionsActiveTypePacket::CEA::type_708, channelId);
118 void CCDataController::ccSetAnalogChannel(
unsigned int channelId)
120 channel.SendActiveTypePacket(ClosedCaptionsActiveTypePacket::CEA::type_608, channelId);
132 return static_cast<uint32_t
>(attrib.rgb);
136 return static_cast<uint32_t
>(attrib);
140 return static_cast<uint32_t
>(attrib);
142 uint32_t getValue(
const gsw_CcFontStyle& attrib)
145 static const std::unordered_map<std::string, uint32_t> valuesMap{
146 {GSW_CC_FONT_STYLE_DEFAULT, 0},
147 {GSW_CC_FONT_STYLE_MONOSPACED_SERIF, 1},
148 {GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF, 2},
149 {GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF, 3},
150 {GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF, 4},
151 {GSW_CC_FONT_STYLE_CASUAL, 5},
152 {GSW_CC_FONT_STYLE_CURSIVE, 6},
153 {GSW_CC_FONT_STYLE_SMALL_CAPITALS, 7},
156 const auto it = valuesMap.find(attrib);
157 if(it != valuesMap.end())
161 logprintf(
"Cannot match %s to attribute value", attrib);
168 return static_cast<uint32_t
>(attrib);
172 return static_cast<uint32_t
>(attrib);
176 return static_cast<uint32_t
>(attrib);
180 return static_cast<uint32_t
>(type);
187 case GSW_CC_ATTRIB_BACKGROUND_COLOR:
189 case GSW_CC_ATTRIB_FONT_COLOR:
191 case GSW_CC_ATTRIB_WIN_COLOR:
193 case GSW_CC_ATTRIB_BACKGROUND_OPACITY:
195 case GSW_CC_ATTRIB_FONT_OPACITY:
197 case GSW_CC_ATTRIB_WIN_OPACITY:
199 case GSW_CC_ATTRIB_FONT_SIZE:
201 case GSW_CC_ATTRIB_FONT_STYLE:
203 case GSW_CC_ATTRIB_FONT_ITALIC:
205 case GSW_CC_ATTRIB_FONT_UNDERLINE:
207 case GSW_CC_ATTRIB_BORDER_TYPE:
209 case GSW_CC_ATTRIB_BORDER_COLOR:
211 case GSW_CC_ATTRIB_EDGE_TYPE:
213 case GSW_CC_ATTRIB_EDGE_COLOR:
216 AAMPLOG_WARN(
"wrong attribute type used 0x%x",type);
226 case GSW_CC_ATTRIB_BACKGROUND_COLOR:
229 case GSW_CC_ATTRIB_FONT_COLOR:
232 case GSW_CC_ATTRIB_WIN_COLOR:
235 case GSW_CC_ATTRIB_BACKGROUND_OPACITY:
238 case GSW_CC_ATTRIB_FONT_OPACITY:
241 case GSW_CC_ATTRIB_WIN_OPACITY:
244 case GSW_CC_ATTRIB_FONT_SIZE:
247 case GSW_CC_ATTRIB_FONT_STYLE:
248 std::memcpy(currentAttributes->
fontStyle, attrib->
fontStyle, GSW_CC_MAX_FONT_NAME_LENGTH);
251 case GSW_CC_ATTRIB_FONT_ITALIC:
254 case GSW_CC_ATTRIB_FONT_UNDERLINE:
257 case GSW_CC_ATTRIB_BORDER_TYPE:
260 case GSW_CC_ATTRIB_BORDER_COLOR:
263 case GSW_CC_ATTRIB_EDGE_TYPE:
266 case GSW_CC_ATTRIB_EDGE_COLOR:
270 logprintf(
"%s: wrong attribute type used 0x%x",__func__, type);
279 using AttributesArray = std::array<uint32_t, 14> ;
281 static constexpr AttributesArray masks = {
282 GSW_CC_ATTRIB_FONT_COLOR,
283 GSW_CC_ATTRIB_BACKGROUND_COLOR,
284 GSW_CC_ATTRIB_FONT_OPACITY,
285 GSW_CC_ATTRIB_BACKGROUND_OPACITY,
286 GSW_CC_ATTRIB_FONT_STYLE,
287 GSW_CC_ATTRIB_FONT_SIZE,
288 GSW_CC_ATTRIB_FONT_ITALIC,
289 GSW_CC_ATTRIB_FONT_UNDERLINE,
290 GSW_CC_ATTRIB_BORDER_TYPE,
291 GSW_CC_ATTRIB_BORDER_COLOR,
292 GSW_CC_ATTRIB_WIN_COLOR,
293 GSW_CC_ATTRIB_WIN_OPACITY,
294 GSW_CC_ATTRIB_EDGE_TYPE,
295 GSW_CC_ATTRIB_EDGE_COLOR,
298 AttributesArray attributes{};
300 for(
int i = 0; i<attributes.size(); ++i)
302 if(type & (masks[i]))
304 setValue(¤tAttributes, attrib, masks[i]);
305 attributes[i] = getValue(attrib, masks[i]);
313 const auto ccTypeValue = getValue(ccType);
315 channel.SendCCSetAttributePacket(ccTypeValue, uint32_t{type}, attributes);
318 void closedCaptionDecodeCb(
void *context,
int decoderIndex,
int event)
320 CCDataController* p =
static_cast<CCDataController*
>(context);
321 p->closedCaptionDecodeCb(decoderIndex, event);
324 void closedCaptionDataCb (
void *context,
int decoderIndex, VL_CC_DATA_TYPE eType,
unsigned char* ccData,
325 unsigned dataLength,
int sequenceNumber,
long long localPts)
327 CCDataController* p =
static_cast<CCDataController*
>(context);
328 p->closedCaptionDataCb(decoderIndex, eType, ccData, dataLength, sequenceNumber, localPts);