31 #include "AampUtils.h"
35 #if defined(AAMP_RDK_CC_ENABLED)
37 #elif defined(AAMP_SUBTEC_CC_ENABLED)
40 #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"
44 #define CHAR_CODE_1 49
45 #define CHAR_CODE_6 54
48 #if defined(AAMP_RDK_CC_ENABLED)
52 return ccGetCapability(attribType, ccType, values, size);
57 return ccGetAttributes(attrib, ccType);
62 return ccSetAttributes(attrib, type, ccType);
65 #elif defined(AAMP_SUBTEC_CC_ENABLED)
69 return subtecConnector::ccMgrAPI::ccGetCapability(attribType, ccType, values, size);
74 return subtecConnector::ccMgrAPI::ccGetAttributes(attrib, ccType);
79 return subtecConnector::ccMgrAPI::ccSetAttributes(attrib, type, ccType);
83 #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"
98 static bool flagForMalloc =
false;
99 static const int MAX_COLOR_BUFFER_LEN = ((GSW_MAX_CC_COLOR_NAME_LENGTH > 8 ? GSW_MAX_CC_COLOR_NAME_LENGTH : 8) + 1);
100 unsigned int ccSizeOfCaps = 0;
103 if (!input.empty() && colorOut)
107 flagForMalloc =
true;
108 for (
int i = 0; i < GSW_CC_COLOR_MAX; i++)
114 GetCapability(attributeIndex, ccType, (
void**) &ccColorCaps, &ccSizeOfCaps);
117 const char *inputStr = input.c_str();
118 for (
unsigned int i = 0; i < ccSizeOfCaps; i++)
121 if (0 == strncasecmp(ccColorCaps[i]->name, inputStr, GSW_MAX_CC_COLOR_NAME_LENGTH))
124 memcpy(colorOut, ccColorCaps[i],
sizeof (
gsw_CcColor));
131 AAMPLOG_ERR(
"Unsupported color type %s", inputStr);
136 AAMPLOG_ERR(
"Input is NULL!");
152 if (!input.empty() && textStyleOut)
154 const char *inputStr = input.c_str();
155 if (0 == strncasecmp(inputStr,
"false", strlen(
"false")))
157 *textStyleOut = GSW_CC_TEXT_STYLE_FALSE;
159 else if (0 == strncasecmp(inputStr,
"true", strlen(
"true")))
161 *textStyleOut = GSW_CC_TEXT_STYLE_TRUE;
163 else if (0 == strncasecmp(inputStr,
"auto", strlen(
"auto")))
165 *textStyleOut = GSW_CC_TEXT_STYLE_EMBEDDED_TEXT;
169 AAMPLOG_ERR(
"Unsupported text style %s", inputStr);
174 AAMPLOG_ERR(
"Input is NULL");
190 if (!input.empty() && edgeTypeOut)
192 const char *inputStr = input.c_str();
193 if (0 == strncasecmp(inputStr,
"none", strlen(
"none")))
195 *edgeTypeOut = GSW_CC_EDGE_TYPE_NONE;
197 else if (0 == strncasecmp(inputStr,
"raised", strlen(
"raised")))
199 *edgeTypeOut = GSW_CC_EDGE_TYPE_RAISED;
201 else if (0 == strncasecmp(inputStr,
"depressed", strlen(
"depressed")))
203 *edgeTypeOut = GSW_CC_EDGE_TYPE_DEPRESSED;
205 else if (0 == strncasecmp(inputStr,
"uniform", strlen(
"uniform")))
207 *edgeTypeOut = GSW_CC_EDGE_TYPE_UNIFORM;
209 else if ((0 == strncasecmp(inputStr,
"drop_shadow_left", strlen(
"drop_shadow_left"))) ||
210 (0 == strncasecmp(inputStr,
"Left drop shadow", strlen(
"Left drop shadow"))))
212 *edgeTypeOut = GSW_CC_EDGE_TYPE_SHADOW_LEFT;
214 else if ((0 == strncasecmp(inputStr,
"drop_shadow_right", strlen(
"drop_shadow_right"))) ||
215 (0 == strncasecmp(inputStr,
"Right drop shadow", strlen(
"Right drop shadow"))))
217 *edgeTypeOut = GSW_CC_EDGE_TYPE_SHADOW_RIGHT;
219 else if (0 == strncasecmp(inputStr,
"auto", strlen(
"auto")))
221 *edgeTypeOut = GSW_CC_EDGE_TYPE_EMBEDDED;
225 AAMPLOG_ERR(
"Unsupported edge type %s", inputStr);
230 AAMPLOG_ERR(
"Input is NULL");
243 static int getFontStyle(std::string input, gsw_CcFontStyle *fontStyleOut)
246 if (!input.empty() && fontStyleOut)
248 const char *inputStr = input.c_str();
249 if (0 == strncasecmp(inputStr,
"default", strlen(
"default")))
251 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_DEFAULT,
sizeof(GSW_CC_FONT_STYLE_DEFAULT));
253 else if ((0 == strncasecmp(inputStr,
"monospaced_serif", strlen(
"monospaced_serif"))) ||
254 (0 == strncasecmp(inputStr,
"Monospaced serif", strlen(
"Monospaced serif"))))
256 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_MONOSPACED_SERIF,
sizeof(GSW_CC_FONT_STYLE_MONOSPACED_SERIF));
258 else if ((0 == strncasecmp(inputStr,
"proportional_serif", strlen(
"proportional_serif"))) ||
259 (0 == strncasecmp(inputStr,
"Proportional serif", strlen(
"Proportional serif"))))
261 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF,
sizeof(GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF));
263 else if ((0 == strncasecmp(inputStr,
"monospaced_sanserif", strlen(
"monospaced_sanserif"))) ||
264 (0 == strncasecmp(inputStr,
"Monospaced sans serif", strlen(
"Monospaced sans serif"))))
266 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF,
sizeof(GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF));
268 else if ((0 == strncasecmp(inputStr,
"proportional_sanserif", strlen(
"proportional_sanserif"))) ||
269 (0 == strncasecmp(inputStr,
"Proportional sans serif", strlen(
"Proportional sans serif"))))
271 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF,
sizeof(GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF));
273 else if (0 == strncasecmp(inputStr,
"casual", strlen(
"casual")))
275 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_CASUAL,
sizeof(GSW_CC_FONT_STYLE_CASUAL));
277 else if (0 == strncasecmp(inputStr,
"cursive", strlen(
"cursive")))
279 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_CURSIVE,
sizeof(GSW_CC_FONT_STYLE_CURSIVE));
281 else if ((0 == strncasecmp(inputStr,
"smallcaps", strlen(
"smallcaps"))) ||
282 (0 == strncasecmp(inputStr,
"small capital", strlen(
"small capital"))))
284 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_SMALL_CAPITALS,
sizeof(GSW_CC_FONT_STYLE_SMALL_CAPITALS));
286 else if (0 == strncasecmp(inputStr,
"auto", strlen(
"auto")))
288 memcpy(fontStyleOut, GSW_CC_FONT_STYLE_EMBEDDED,
sizeof(GSW_CC_FONT_STYLE_EMBEDDED));
292 AAMPLOG_ERR(
"Unsupported font style type %s", inputStr);
297 AAMPLOG_ERR(
"Input is NULL");
313 if (!input.empty() && fontSizeOut)
315 const char *inputStr = input.c_str();
316 if (0 == strncasecmp(inputStr,
"small", strlen(
"small")))
318 *fontSizeOut = GSW_CC_FONT_SIZE_SMALL;
320 else if ((0 == strncasecmp(inputStr,
"standard", strlen(
"standard"))) ||
321 (0 == strncasecmp(inputStr,
"medium", strlen(
"medium"))))
323 *fontSizeOut = GSW_CC_FONT_SIZE_STANDARD;
325 else if (0 == strncasecmp(inputStr,
"large", strlen(
"large")))
327 *fontSizeOut = GSW_CC_FONT_SIZE_LARGE;
329 else if (0 == strncasecmp(inputStr,
"extra_large", strlen(
"extra_large")))
331 *fontSizeOut = GSW_CC_FONT_SIZE_EXTRALARGE;
333 else if (0 == strncasecmp(inputStr,
"auto", strlen(
"auto")))
335 *fontSizeOut = GSW_CC_FONT_SIZE_EMBEDDED;
339 AAMPLOG_ERR(
"Unsupported font size type %s", inputStr);
344 AAMPLOG_ERR(
"Input is NULL");
360 if (!input.empty() && opacityOut)
362 const char *inputStr = input.c_str();
363 if (0 == strncasecmp(inputStr,
"solid", strlen(
"solid")))
365 *opacityOut = GSW_CC_OPACITY_SOLID;
367 else if (0 == strncasecmp(inputStr,
"flash", strlen(
"flash")))
369 *opacityOut = GSW_CC_OPACITY_FLASHING;
371 else if (0 == strncasecmp(inputStr,
"translucent", strlen(
"translucent")))
373 *opacityOut = GSW_CC_OPACITY_TRANSLUCENT;
375 else if (0 == strncasecmp(inputStr,
"transparent", strlen(
"transparent")))
377 *opacityOut = GSW_CC_OPACITY_TRANSPARENT;
379 else if (0 == strncasecmp(inputStr,
"auto", strlen(
"auto")))
381 *opacityOut = GSW_CC_OPACITY_EMBEDDED;
385 AAMPLOG_ERR(
"Unsupported opacity type %s", inputStr);
390 AAMPLOG_ERR(
"Input is NULL");
404 AAMPLOG_WARN(
"AampCCManagerBase::");
432 if (!options.empty())
436 std::string optionValue;
442 GetAttributes (&attribute, GSW_CC_TYPE_DIGITAL);
444 short attribsMask = 0;
446 if (inputOptions.
get(
"fontStyle", optionValue))
449 attribsMask |=GSW_CC_ATTRIB_FONT_STYLE;
452 if (inputOptions.
get(
"textEdgeColor", optionValue))
454 getColor(GSW_CC_ATTRIB_EDGE_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.
edgeColor));
455 attribsMask |=GSW_CC_ATTRIB_EDGE_COLOR;
458 if (inputOptions.
get(
"textEdgeStyle", optionValue))
461 attribsMask |=GSW_CC_ATTRIB_EDGE_TYPE;
464 if (inputOptions.
get(
"textForegroundColor", optionValue))
466 getColor(GSW_CC_ATTRIB_FONT_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.
charFgColor));
467 attribsMask |=GSW_CC_ATTRIB_FONT_COLOR;
470 if (inputOptions.
get(
"textForegroundOpacity", optionValue))
473 attribsMask |=GSW_CC_ATTRIB_FONT_OPACITY;
476 if (inputOptions.
get(
"textBackgroundColor", optionValue))
478 getColor(GSW_CC_ATTRIB_BACKGROUND_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.
charBgColor));
479 attribsMask |=GSW_CC_ATTRIB_BACKGROUND_COLOR;
482 if (inputOptions.
get(
"textBackgroundOpacity", optionValue))
485 attribsMask |=GSW_CC_ATTRIB_BACKGROUND_OPACITY;
488 if (inputOptions.
get(
"penItalicized", optionValue))
491 attribsMask |=GSW_CC_ATTRIB_FONT_ITALIC;
494 if (inputOptions.
get(
"penSize", optionValue))
497 attribsMask |=GSW_CC_ATTRIB_FONT_SIZE;
500 if (inputOptions.
get(
"penUnderline", optionValue))
503 attribsMask |=GSW_CC_ATTRIB_FONT_UNDERLINE;
506 if (inputOptions.
get(
"windowBorderEdgeColor", optionValue))
508 getColor(GSW_CC_ATTRIB_BORDER_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.
borderColor));
509 attribsMask |=GSW_CC_ATTRIB_BORDER_COLOR;
512 if (inputOptions.
get(
"windowBorderEdgeStyle", optionValue))
515 attribsMask |=GSW_CC_ATTRIB_BORDER_TYPE;
518 if (inputOptions.
get(
"windowFillColor", optionValue))
520 getColor(GSW_CC_ATTRIB_WIN_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.
winColor));
521 attribsMask |=GSW_CC_ATTRIB_WIN_COLOR;
524 if (inputOptions.
get(
"windowFillOpacity", optionValue))
527 attribsMask |=GSW_CC_ATTRIB_WIN_OPACITY;
533 SetAttributes(&attribute, attribsMask, GSW_CC_TYPE_DIGITAL);
534 SetAttributes(&attribute, attribsMask, GSW_CC_TYPE_ANALOG);
538 AAMPLOG_WARN(
"AampCCManagerBase::received optionsJson but result attributeMask is 0");
545 AAMPLOG_WARN(
"AampCCManagerBase::CC rendering not enabled");
551 AAMPLOG_ERR(
"AampCCManagerBase: AampJsonParseException - %s", e.what());
561 AAMPLOG_WARN(
"AampCCManagerBase::mEnabled=%d",
mEnabled);
571 AAMPLOG_WARN(
"AampCCManagerBase:: mEnabled=%d",
mEnabled);
582 AAMPLOG_WARN(
"AampCCManagerBase:: NULL handle");
588 AAMPLOG_WARN(
"AampCCManagerBase::Initialize failure");
592 AAMPLOG_WARN(
"AampCCManagerBase:: Start CC with video dec handle: %p and mEnabled: %d", handle,
mEnabled);
611 AAMPLOG_WARN(
"AampCCManagerBase::trickplay status(%d)", on);
631 AAMPLOG_WARN(
"AampCCManagerBase:: lock status(%s)", (locked)?
"true":
"false");
655 unsigned int trackNum = 0;
656 CCFormat finalFormat = eCLOSEDCAPTION_FORMAT_DEFAULT;
661 if (!track.empty() && track[0] >= CHAR_CODE_1 && track[0] <= CHAR_CODE_6)
663 trackNum = (
unsigned int) std::stoul(track);
671 finalFormat = eCLOSEDCAPTION_FORMAT_608;
672 trackNum = ((int)track[2] - 48);
678 finalFormat = eCLOSEDCAPTION_FORMAT_608;
679 trackNum = ((int)track[3] - 48) + 4;
685 finalFormat = eCLOSEDCAPTION_FORMAT_608;
686 trackNum = ((int)track[4] - 48) + 4;
688 else if (track.size() > 7 &&
aamp_StartsWith(track.c_str(),
"SERVICE"))
692 finalFormat = eCLOSEDCAPTION_FORMAT_708;
693 trackNum = (
unsigned int) std::stoul(track.substr(7));
697 if (format != eCLOSEDCAPTION_FORMAT_DEFAULT && finalFormat != format)
699 if (format == eCLOSEDCAPTION_FORMAT_608)
702 finalFormat = eCLOSEDCAPTION_FORMAT_608;
708 AAMPLOG_WARN(
"AampCCManagerBase:: Force CC track format to 608 and trackNum to %d!", trackNum);
713 finalFormat = eCLOSEDCAPTION_FORMAT_708;
714 AAMPLOG_WARN(
"AampCCManagerBase::Force CC track format to 708!");
718 AAMPLOG_WARN(
"AampCCManagerBase::Set CC InstreamId '%s' format(%d) trackNum(%d)", track.c_str(), finalFormat, trackNum);
720 if (finalFormat == eCLOSEDCAPTION_FORMAT_708 && (trackNum > 0 && trackNum <= 63))
724 else if (finalFormat == eCLOSEDCAPTION_FORMAT_608 && (trackNum > 0 && trackNum <= 8))
731 AAMPLOG_WARN(
"AampCCManagerBase::Invalid track number or format, ignoring it!");
736 AAMPLOG_WARN(
"AampCCManagerBase::Failed to set trackNum(%d) and format(%d) with ret - %d", trackNum, finalFormat, ret);
746 AAMPLOG_WARN(
"AampCCManagerBase::mEnabled: %d, mTrickplayStarted: %d, mParentalCtrlLocked: %d, mCCHandle: %s",
759 AAMPLOG_WARN(
"AampCCManagerBase::mEnabled: %d, mTrickplayStarted: %d, mParentalCtrlLocked: %d, mCCHandle: %s",
784 #if defined(AAMP_SUBTEC_CC_ENABLED)
803 #if defined(AAMP_RDK_CC_ENABLED)
805 #elif defined(AAMP_SUBTEC_CC_ENABLED)
808 #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"