RDK Documentation (Open Sourced RDK Components)
AampCCManager.cpp
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file AampCCManager.cpp
22  *
23  * @brief Base class for ClosedCaption integration layer
24  *
25  */
26 
27 #include "priv_aamp.h" // Included for AAMPLOG
28 //TODO: Fix cyclic dependency btw GlobalConfig and AampLogManager
29 
30 #include "AampJsonObject.h" // For JSON parsing
31 #include "AampUtils.h" // For aamp_StartsWith
32 
34 
35 #if defined(AAMP_RDK_CC_ENABLED)
37 #elif defined(AAMP_SUBTEC_CC_ENABLED)
39 #else
40 #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"
41 #endif
42 
43 
44 #define CHAR_CODE_1 49
45 #define CHAR_CODE_6 54
46 
47 
48 #if defined(AAMP_RDK_CC_ENABLED)
49 
50 static mrcc_Error GetCapability(gsw_CcAttribType attribType, gsw_CcType ccType, void **values, unsigned int *size)
51 {
52  return ccGetCapability(attribType, ccType, values, size);
53 }
54 
55 mrcc_Error GetAttributes(gsw_CcAttributes * attrib, gsw_CcType ccType)
56 {
57  return ccGetAttributes(attrib, ccType);
58 }
59 
60 mrcc_Error SetAttributes(gsw_CcAttributes * attrib, short type, gsw_CcType ccType)
61 {
62  return ccSetAttributes(attrib, type, ccType);
63 }
64 
65 #elif defined(AAMP_SUBTEC_CC_ENABLED)
66 
67 static mrcc_Error GetCapability(gsw_CcAttribType attribType, gsw_CcType ccType, void **values, unsigned int *size)
68 {
69  return subtecConnector::ccMgrAPI::ccGetCapability(attribType, ccType, values, size);
70 }
71 
72 mrcc_Error GetAttributes(gsw_CcAttributes * attrib, gsw_CcType ccType)
73 {
74  return subtecConnector::ccMgrAPI::ccGetAttributes(attrib, ccType);
75 }
76 
77 mrcc_Error SetAttributes(gsw_CcAttributes * attrib, short type, gsw_CcType ccType)
78 {
79  return subtecConnector::ccMgrAPI::ccSetAttributes(attrib, type, ccType);
80 }
81 
82 #else
83  #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"
84 #endif
85 
86 /**
87  * @brief Get color option from input string
88  *
89  * @param[in] attributeIndex - CC attribute
90  * @param[in] ccType - CC type
91  * @param[in] input - input color style
92  * @param[out] colorOut - color option for the input value
93  * @return int - 0 for success, -1 for failure
94  */
95 static int getColor(gsw_CcAttribType attributeIndex, gsw_CcType ccType, std::string input, gsw_CcColor *colorOut)
96 {
97  static gsw_CcColor* ccColorCaps[GSW_CC_COLOR_MAX];
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;
101  AAMPLOG_TRACE("input: %s", input.c_str());
102 
103  if (!input.empty() && colorOut)
104  {
105  if (!flagForMalloc)
106  {
107  flagForMalloc = true;
108  for (int i = 0; i < GSW_CC_COLOR_MAX; i++)
109  {
110  ccColorCaps[i] = (gsw_CcColor*) malloc(sizeof(gsw_CcColor));
111  memset(ccColorCaps[i], 0, sizeof(gsw_CcColor));
112  }
113  }
114  GetCapability(attributeIndex, ccType, (void**) &ccColorCaps, &ccSizeOfCaps);
115 
116  bool found = false;
117  const char *inputStr = input.c_str();
118  for (unsigned int i = 0; i < ccSizeOfCaps; i++)
119  {
120  AAMPLOG_TRACE("color caps: %s", ccColorCaps[i]->name);
121  if (0 == strncasecmp(ccColorCaps[i]->name, inputStr, GSW_MAX_CC_COLOR_NAME_LENGTH))
122  {
123  AAMPLOG_TRACE("found match %s", ccColorCaps[i]->name);
124  memcpy(colorOut, ccColorCaps[i], sizeof (gsw_CcColor));
125  found = true;
126  break;
127  }
128  }
129  if(!found)
130  {
131  AAMPLOG_ERR("Unsupported color type %s", inputStr);
132  }
133  }
134  else
135  {
136  AAMPLOG_ERR("Input is NULL!");
137  return -1;
138  }
139  return 0;
140 }
141 
142 /**
143  * @brief Get text style value from input string
144  *
145  * @param[in] input - input text style value
146  * @param[out] fontSizeOut - text style option for the input value
147  * @return int - 0 for success, -1 for failure
148  */
149 static int getTextStyle(std::string input, gsw_CcTextStyle *textStyleOut)
150 {
151  AAMPLOG_TRACE("input: %s", input.c_str());
152  if (!input.empty() && textStyleOut)
153  {
154  const char *inputStr = input.c_str();
155  if (0 == strncasecmp(inputStr, "false", strlen("false")))
156  {
157  *textStyleOut = GSW_CC_TEXT_STYLE_FALSE;
158  }
159  else if (0 == strncasecmp(inputStr, "true", strlen("true")))
160  {
161  *textStyleOut = GSW_CC_TEXT_STYLE_TRUE;
162  }
163  else if (0 == strncasecmp(inputStr, "auto", strlen("auto")))
164  {
165  *textStyleOut = GSW_CC_TEXT_STYLE_EMBEDDED_TEXT;
166  }
167  else
168  {
169  AAMPLOG_ERR("Unsupported text style %s", inputStr);
170  }
171  }
172  else
173  {
174  AAMPLOG_ERR("Input is NULL");
175  return -1;
176  }
177  return 0;
178 }
179 
180 /**
181  * @brief Get edge type value from input string
182  *
183  * @param[in] input - input edge type value
184  * @param[out] fontSizeOut - edge type option for the input value
185  * @return int - 0 for success, -1 for failure
186  */
187 static int getEdgeType(std::string input, gsw_CcEdgeType *edgeTypeOut)
188 {
189  AAMPLOG_TRACE("input: %s", input.c_str());
190  if (!input.empty() && edgeTypeOut)
191  {
192  const char *inputStr = input.c_str();
193  if (0 == strncasecmp(inputStr, "none", strlen("none")))
194  {
195  *edgeTypeOut = GSW_CC_EDGE_TYPE_NONE;
196  }
197  else if (0 == strncasecmp(inputStr, "raised", strlen("raised")))
198  {
199  *edgeTypeOut = GSW_CC_EDGE_TYPE_RAISED;
200  }
201  else if (0 == strncasecmp(inputStr, "depressed", strlen("depressed")))
202  {
203  *edgeTypeOut = GSW_CC_EDGE_TYPE_DEPRESSED;
204  }
205  else if (0 == strncasecmp(inputStr, "uniform", strlen("uniform")))
206  {
207  *edgeTypeOut = GSW_CC_EDGE_TYPE_UNIFORM;
208  }
209  else if ((0 == strncasecmp(inputStr, "drop_shadow_left", strlen("drop_shadow_left"))) ||
210  (0 == strncasecmp(inputStr, "Left drop shadow", strlen("Left drop shadow"))))
211  {
212  *edgeTypeOut = GSW_CC_EDGE_TYPE_SHADOW_LEFT;
213  }
214  else if ((0 == strncasecmp(inputStr, "drop_shadow_right", strlen("drop_shadow_right"))) ||
215  (0 == strncasecmp(inputStr, "Right drop shadow", strlen("Right drop shadow"))))
216  {
217  *edgeTypeOut = GSW_CC_EDGE_TYPE_SHADOW_RIGHT;
218  }
219  else if (0 == strncasecmp(inputStr, "auto", strlen("auto")))
220  {
221  *edgeTypeOut = GSW_CC_EDGE_TYPE_EMBEDDED;
222  }
223  else
224  {
225  AAMPLOG_ERR("Unsupported edge type %s", inputStr);
226  }
227  }
228  else
229  {
230  AAMPLOG_ERR("Input is NULL");
231  return -1;
232  }
233  return 0;
234 }
235 
236 /**
237  * @brief Get font style value from input string
238  *
239  * @param[in] input - input font style value
240  * @param[out] fontSizeOut - font style option for the input value
241  * @return int - 0 for success, -1 for failure
242  */
243 static int getFontStyle(std::string input, gsw_CcFontStyle *fontStyleOut)
244 {
245  AAMPLOG_TRACE("input: %s", input.c_str());
246  if (!input.empty() && fontStyleOut)
247  {
248  const char *inputStr = input.c_str();
249  if (0 == strncasecmp(inputStr, "default", strlen("default")))
250  {
251  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_DEFAULT, sizeof(GSW_CC_FONT_STYLE_DEFAULT));
252  }
253  else if ((0 == strncasecmp(inputStr, "monospaced_serif", strlen("monospaced_serif"))) ||
254  (0 == strncasecmp(inputStr, "Monospaced serif", strlen("Monospaced serif"))))
255  {
256  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_MONOSPACED_SERIF, sizeof(GSW_CC_FONT_STYLE_MONOSPACED_SERIF));
257  }
258  else if ((0 == strncasecmp(inputStr, "proportional_serif", strlen("proportional_serif"))) ||
259  (0 == strncasecmp(inputStr, "Proportional serif", strlen("Proportional serif"))))
260  {
261  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF, sizeof(GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF));
262  }
263  else if ((0 == strncasecmp(inputStr, "monospaced_sanserif", strlen("monospaced_sanserif"))) ||
264  (0 == strncasecmp(inputStr, "Monospaced sans serif", strlen("Monospaced sans serif"))))
265  {
266  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF, sizeof(GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF));
267  }
268  else if ((0 == strncasecmp(inputStr, "proportional_sanserif", strlen("proportional_sanserif"))) ||
269  (0 == strncasecmp(inputStr, "Proportional sans serif", strlen("Proportional sans serif"))))
270  {
271  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF, sizeof(GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF));
272  }
273  else if (0 == strncasecmp(inputStr, "casual", strlen("casual")))
274  {
275  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_CASUAL, sizeof(GSW_CC_FONT_STYLE_CASUAL));
276  }
277  else if (0 == strncasecmp(inputStr, "cursive", strlen("cursive")))
278  {
279  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_CURSIVE, sizeof(GSW_CC_FONT_STYLE_CURSIVE));
280  }
281  else if ((0 == strncasecmp(inputStr, "smallcaps", strlen("smallcaps"))) ||
282  (0 == strncasecmp(inputStr, "small capital", strlen("small capital"))))
283  {
284  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_SMALL_CAPITALS, sizeof(GSW_CC_FONT_STYLE_SMALL_CAPITALS));
285  }
286  else if (0 == strncasecmp(inputStr, "auto", strlen("auto")))
287  {
288  memcpy(fontStyleOut, GSW_CC_FONT_STYLE_EMBEDDED, sizeof(GSW_CC_FONT_STYLE_EMBEDDED));
289  }
290  else
291  {
292  AAMPLOG_ERR("Unsupported font style type %s", inputStr);
293  }
294  }
295  else
296  {
297  AAMPLOG_ERR("Input is NULL");
298  return -1;
299  }
300  return 0;
301 }
302 
303 /**
304  * @brief Get font size value from input string
305  *
306  * @param[in] input - input font size value
307  * @param[out] fontSizeOut - font size option for the input value
308  * @return int - 0 for success, -1 for failure
309  */
310 static int getFontSize(std::string input, gsw_CcFontSize *fontSizeOut)
311 {
312  AAMPLOG_TRACE("input: %s", input.c_str());
313  if (!input.empty() && fontSizeOut)
314  {
315  const char *inputStr = input.c_str();
316  if (0 == strncasecmp(inputStr, "small", strlen("small")))
317  {
318  *fontSizeOut = GSW_CC_FONT_SIZE_SMALL;
319  }
320  else if ((0 == strncasecmp(inputStr, "standard", strlen("standard"))) ||
321  (0 == strncasecmp(inputStr, "medium", strlen("medium"))))
322  {
323  *fontSizeOut = GSW_CC_FONT_SIZE_STANDARD;
324  }
325  else if (0 == strncasecmp(inputStr, "large", strlen("large")))
326  {
327  *fontSizeOut = GSW_CC_FONT_SIZE_LARGE;
328  }
329  else if (0 == strncasecmp(inputStr, "extra_large", strlen("extra_large")))
330  {
331  *fontSizeOut = GSW_CC_FONT_SIZE_EXTRALARGE;
332  }
333  else if (0 == strncasecmp(inputStr, "auto", strlen("auto")))
334  {
335  *fontSizeOut = GSW_CC_FONT_SIZE_EMBEDDED;
336  }
337  else
338  {
339  AAMPLOG_ERR("Unsupported font size type %s", inputStr);
340  }
341  }
342  else
343  {
344  AAMPLOG_ERR("Input is NULL");
345  return -1;
346  }
347  return 0;
348 }
349 
350 /**
351  * @brief Get opacity value from input string
352  *
353  * @param[in] input - input opacity style
354  * @param[out] opacityOut - opacity option for the input value
355  * @return int - 0 for success, -1 for failure
356  */
357 static int getOpacity(std::string input, gsw_CcOpacity *opacityOut)
358 {
359  AAMPLOG_TRACE("input: %s", input.c_str());
360  if (!input.empty() && opacityOut)
361  {
362  const char *inputStr = input.c_str();
363  if (0 == strncasecmp(inputStr, "solid", strlen("solid")))
364  {
365  *opacityOut = GSW_CC_OPACITY_SOLID;
366  }
367  else if (0 == strncasecmp(inputStr, "flash", strlen("flash")))
368  {
369  *opacityOut = GSW_CC_OPACITY_FLASHING;
370  }
371  else if (0 == strncasecmp(inputStr, "translucent", strlen("translucent")))
372  {
373  *opacityOut = GSW_CC_OPACITY_TRANSLUCENT;
374  }
375  else if (0 == strncasecmp(inputStr, "transparent", strlen("transparent")))
376  {
377  *opacityOut = GSW_CC_OPACITY_TRANSPARENT;
378  }
379  else if (0 == strncasecmp(inputStr, "auto", strlen("auto")))
380  {
381  *opacityOut = GSW_CC_OPACITY_EMBEDDED;
382  }
383  else
384  {
385  AAMPLOG_ERR("Unsupported opacity type %s", inputStr);
386  }
387  }
388  else
389  {
390  AAMPLOG_ERR("Input is NULL");
391  return -1;
392  }
393  return 0;
394 }
395 
396 
397 /**
398  * @brief Set CC styles for rendering
399  */
400 int AampCCManagerBase::SetStyle(const std::string &options)
401 try
402 {
404  AAMPLOG_WARN("AampCCManagerBase::");
405 
406  int ret = -1;
407  /*
408  * Values received from JS PP:
409  *
410  * export interface IPlayerCCStyle {
411  * fontStyle?: string;
412  * textEdgeColor?: string;
413  * textEdgeStyle?: string;
414  * textForegroundColor?: string;
415  * textForegroundOpacity?: string;
416  * textBackgroundColor?: string;
417  * textBackgroundOpacity?: string;
418  * penItalicized?: string;
419  * penSize?: string;
420  * penUnderline?: string;
421  * windowBorderEdgeColor?: string;
422  * windowBorderEdgeStyle?: string;
423  * windowFillColor?: string;
424  * windowFillOpacity?: string;
425  * bottomInset?: string;
426  * }
427  * FYI - bottomInset unsupported in RDK CC module
428  */
429 
430  if(mEnabled)
431  {
432  if (!options.empty())
433  {
434  AampJsonObject inputOptions(options);
435 
436  std::string optionValue;
437  ret = 0;
438  mOptions = options;
439 
440  gsw_CcAttributes attribute;
441  /** Get the current attributes */
442  GetAttributes (&attribute, GSW_CC_TYPE_DIGITAL);
443 
444  short attribsMask = 0;
445 
446  if (inputOptions.get("fontStyle", optionValue))
447  {
448  getFontStyle(optionValue, &(attribute.fontStyle));
449  attribsMask |=GSW_CC_ATTRIB_FONT_STYLE;
450  }
451 
452  if (inputOptions.get("textEdgeColor", optionValue))
453  {
454  getColor(GSW_CC_ATTRIB_EDGE_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.edgeColor));
455  attribsMask |=GSW_CC_ATTRIB_EDGE_COLOR;
456  }
457 
458  if (inputOptions.get("textEdgeStyle", optionValue))
459  {
460  getEdgeType(optionValue, &(attribute.edgeType));
461  attribsMask |=GSW_CC_ATTRIB_EDGE_TYPE;
462  }
463 
464  if (inputOptions.get("textForegroundColor", optionValue))
465  {
466  getColor(GSW_CC_ATTRIB_FONT_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.charFgColor));
467  attribsMask |=GSW_CC_ATTRIB_FONT_COLOR;
468  }
469 
470  if (inputOptions.get("textForegroundOpacity", optionValue))
471  {
472  getOpacity(optionValue, &(attribute.charFgOpacity));
473  attribsMask |=GSW_CC_ATTRIB_FONT_OPACITY;
474  }
475 
476  if (inputOptions.get("textBackgroundColor", optionValue))
477  {
478  getColor(GSW_CC_ATTRIB_BACKGROUND_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.charBgColor));
479  attribsMask |=GSW_CC_ATTRIB_BACKGROUND_COLOR;
480  }
481 
482  if (inputOptions.get("textBackgroundOpacity", optionValue))
483  {
484  getOpacity(optionValue, &(attribute.charBgOpacity));
485  attribsMask |=GSW_CC_ATTRIB_BACKGROUND_OPACITY;
486  }
487 
488  if (inputOptions.get("penItalicized", optionValue))
489  {
490  getTextStyle(optionValue, &(attribute.fontItalic));
491  attribsMask |=GSW_CC_ATTRIB_FONT_ITALIC;
492  }
493 
494  if (inputOptions.get("penSize", optionValue))
495  {
496  getFontSize(optionValue, &(attribute.fontSize));
497  attribsMask |=GSW_CC_ATTRIB_FONT_SIZE;
498  }
499 
500  if (inputOptions.get("penUnderline", optionValue))
501  {
502  getTextStyle(optionValue, &(attribute.fontUnderline));
503  attribsMask |=GSW_CC_ATTRIB_FONT_UNDERLINE;
504  }
505 
506  if (inputOptions.get("windowBorderEdgeColor", optionValue))
507  {
508  getColor(GSW_CC_ATTRIB_BORDER_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.borderColor));
509  attribsMask |=GSW_CC_ATTRIB_BORDER_COLOR;
510  }
511 
512  if (inputOptions.get("windowBorderEdgeStyle", optionValue))
513  {
514  getEdgeType(optionValue, (gsw_CcEdgeType*) &(attribute.borderType));
515  attribsMask |=GSW_CC_ATTRIB_BORDER_TYPE;
516  }
517 
518  if (inputOptions.get("windowFillColor", optionValue))
519  {
520  getColor(GSW_CC_ATTRIB_WIN_COLOR, GSW_CC_TYPE_DIGITAL, optionValue, &(attribute.winColor));
521  attribsMask |=GSW_CC_ATTRIB_WIN_COLOR;
522  }
523 
524  if (inputOptions.get("windowFillOpacity", optionValue))
525  {
526  getOpacity(optionValue, &(attribute.winOpacity));
527  attribsMask |=GSW_CC_ATTRIB_WIN_OPACITY;
528  }
529 
530  if(attribsMask != 0)
531  {
532 
533  SetAttributes(&attribute, attribsMask, GSW_CC_TYPE_DIGITAL);
534  SetAttributes(&attribute, attribsMask, GSW_CC_TYPE_ANALOG);
535  }
536  else
537  {
538  AAMPLOG_WARN("AampCCManagerBase::received optionsJson but result attributeMask is 0");
539  }
540 
541  }
542  }
543  else
544  {
545  AAMPLOG_WARN("AampCCManagerBase::CC rendering not enabled");
546  }
547  return ret;
548 }
549 catch(const AampJsonParseException& e)
550 {
551  AAMPLOG_ERR("AampCCManagerBase: AampJsonParseException - %s", e.what());
552  return -1;
553 }
554 
555 /**
556  * @brief To stop CC rendering
557  */
559 {
561  AAMPLOG_WARN("AampCCManagerBase::mEnabled=%d",mEnabled);
562  StopRendering();
563 }
564 
565 /**
566  * @brief To start CC rendering
567  */
569 {
571  AAMPLOG_WARN("AampCCManagerBase:: mEnabled=%d", mEnabled);
572  StartRendering();
573 }
574 
575 /**
576  * @brief Initialize CC resource.
577  */
578 int AampCCManagerBase::Init(void *handle)
579 {
580  if (handle == NULL)
581  {
582  AAMPLOG_WARN("AampCCManagerBase:: NULL handle");
583  return -1;
584  }
585 
586  if (Initialize(handle) != 0)
587  {
588  AAMPLOG_WARN("AampCCManagerBase::Initialize failure");
589  return -1;
590  }
591 
592  AAMPLOG_WARN("AampCCManagerBase:: Start CC with video dec handle: %p and mEnabled: %d", handle, mEnabled);
593 
594  if (mEnabled)
595  {
596  Start();
597  }
598  else
599  {
600  Stop();
601  }
602 
603  return 0;
604 }
605 
606 /**
607  * @brief To enable/disable CC when trickplay starts/ends
608  */
610 {
611  AAMPLOG_WARN("AampCCManagerBase::trickplay status(%d)", on);
612  if (on)
613  {
614  // When trickplay starts, stop CC rendering
615  Stop();
616  }
617  else if (mEnabled)
618  {
619  // When trickplay ends and CC rendering enabled by app
620  Start();
621  }
622  mTrickplayStarted = on;
623 }
624 
625 /**
626  * @brief To enable/disable CC when parental control locked/unlocked
627  */
629 {
631  AAMPLOG_WARN("AampCCManagerBase:: lock status(%s)", (locked)?"true":"false");
632  if (locked)
633  {
634  // When parental control locked, stop CC rendering
635  Stop();
636  }
637  else
638  {
639  if (mEnabled)
640  {
641  // When parental control unlocked, start CC rendering if already enabled by app
642  Start();
643  }
644  }
645  mParentalCtrlLocked = locked;
646 }
647 
648 /**
649  * @brief Set CC track
650  */
651 int AampCCManagerBase::SetTrack(const std::string &track, const CCFormat format)
652 {
654  int ret = -1;
655  unsigned int trackNum = 0;
656  CCFormat finalFormat = eCLOSEDCAPTION_FORMAT_DEFAULT;
657  mTrack = track;
658 
659  // Check if track is CCx or SERVICEx or track number
660  // Could be from 1 -> 63
661  if (!track.empty() && track[0] >= CHAR_CODE_1 && track[0] <= CHAR_CODE_6)
662  {
663  trackNum = (unsigned int) std::stoul(track);
664  // This is slightly confusing as we don't know if its 608/708
665  // more info might be available in format argument
666  }
667  else if (track.size() > 2 && aamp_StartsWith(track.c_str(), "CC"))
668  {
669  // Value between 1 - 4
670  // Set as analog channel
671  finalFormat = eCLOSEDCAPTION_FORMAT_608;
672  trackNum = ((int)track[2] - 48);
673  }
674  else if (track.size() > 3 && aamp_StartsWith(track.c_str(), "TXT"))
675  {
676  // Value between 5 - 8
677  // Set as analog channel
678  finalFormat = eCLOSEDCAPTION_FORMAT_608;
679  trackNum = ((int)track[3] - 48) + 4;
680  }
681  else if (track.size() > 4 && aamp_StartsWith(track.c_str(), "TEXT"))
682  {
683  // Value between 5 - 8
684  // Set as analog channel
685  finalFormat = eCLOSEDCAPTION_FORMAT_608;
686  trackNum = ((int)track[4] - 48) + 4;
687  }
688  else if (track.size() > 7 && aamp_StartsWith(track.c_str(), "SERVICE"))
689  {
690  // Value between 1 - 63
691  // Set as digital channel
692  finalFormat = eCLOSEDCAPTION_FORMAT_708;
693  trackNum = (unsigned int) std::stoul(track.substr(7));
694  }
695 
696  // Format argument overrides whatever we infer from track
697  if (format != eCLOSEDCAPTION_FORMAT_DEFAULT && finalFormat != format)
698  {
699  if (format == eCLOSEDCAPTION_FORMAT_608)
700  {
701  //Force to 608
702  finalFormat = eCLOSEDCAPTION_FORMAT_608;
703  if (trackNum > 8)
704  {
705  //Hope this will not happen in realtime
706  trackNum = 0;
707  }
708  AAMPLOG_WARN("AampCCManagerBase:: Force CC track format to 608 and trackNum to %d!", trackNum);
709  }
710  else
711  {
712  //Force to 708
713  finalFormat = eCLOSEDCAPTION_FORMAT_708;
714  AAMPLOG_WARN("AampCCManagerBase::Force CC track format to 708!");
715  }
716  }
717 
718  AAMPLOG_WARN("AampCCManagerBase::Set CC InstreamId '%s' format(%d) trackNum(%d)", track.c_str(), finalFormat, trackNum);
719 
720  if (finalFormat == eCLOSEDCAPTION_FORMAT_708 && (trackNum > 0 && trackNum <= 63))
721  {
722  ret = SetDigitalChannel(trackNum);
723  }
724  else if (finalFormat == eCLOSEDCAPTION_FORMAT_608 && (trackNum > 0 && trackNum <= 8))
725  {
726  int analogChannel = GSW_CC_ANALOG_SERVICE_CC1 + (trackNum - 1);
727  ret = SetAnalogChannel(analogChannel);
728  }
729  else
730  {
731  AAMPLOG_WARN("AampCCManagerBase::Invalid track number or format, ignoring it!");
732  }
733 
734  if(0 != ret)
735  {
736  AAMPLOG_WARN("AampCCManagerBase::Failed to set trackNum(%d) and format(%d) with ret - %d", trackNum, finalFormat, ret);
737  }
738  return ret;
739 }
740 
741 /**
742  * @brief To restore cc state after new tune
743  */
745 {
746  AAMPLOG_WARN("AampCCManagerBase::mEnabled: %d, mTrickplayStarted: %d, mParentalCtrlLocked: %d, mCCHandle: %s",
747  mEnabled, mTrickplayStarted, mParentalCtrlLocked, (CheckCCHandle()) ? "set" : "not set");
748 
749  SetTrack(GetTrack());
750 }
751 
752 /**
753  * @brief Enable/disable CC rendering
754  */
756 {
757  int ret = 0;
758  mEnabled = enable;
759  AAMPLOG_WARN("AampCCManagerBase::mEnabled: %d, mTrickplayStarted: %d, mParentalCtrlLocked: %d, mCCHandle: %s",
760  mEnabled, mTrickplayStarted, mParentalCtrlLocked, (CheckCCHandle()) ? "set" : "not set");
762  {
763  // Setting CC rendering to true before media_closeCaptionStart is not honoured
764  // by CC module. CC rendering status is saved in mEnabled and Start/Stop is
765  // called when the required operations are completed
766  if (mEnabled)
767  {
768  Start();
769  }
770  else
771  {
772  Stop();
773  }
774  }
775  return ret;
776 }
777 
778 /**
779  * @brief To check whether Out of Band Closed caption/subtitle rendering supported or not.
780  */
782 {
783  bool bRet = false;
784 #if defined(AAMP_SUBTEC_CC_ENABLED)
785  bRet = true; // Subtec takes care of rendering CC hence return true
786 #endif
787  AAMPLOG_TRACE("Subtec CC Mode Support: %d", bRet);
788  return bRet;
789 }
790 
791 /**
792  * @brief Singleton instance
793  */
795 
796 /**
797  * @brief Get the singleton instance
798  */
800 {
801  if (mInstance == NULL)
802  {
803 #if defined(AAMP_RDK_CC_ENABLED)
804  mInstance = new AampRDKCCManager();
805 #elif defined(AAMP_SUBTEC_CC_ENABLED)
807 #else
808  #error "AAMP_RDK_CC_ENABLED and AAMP_SUBTEC_CC_ENABLED undefined"
809 #endif
810  }
811  return mInstance;
812 }
813 
814 /**
815  * @brief Destroy instance
816  */
818 {
819  if (mInstance)
820  {
821  delete mInstance;
822  mInstance = NULL;
823  }
824 }
gsw_CcAttribType
gsw_CcAttribType
type of attributes
Definition: SubtecConnector.h:198
gsw_CcAttributes::charFgColor
gsw_CcColor charFgColor
Definition: SubtecConnector.h:178
gsw_CcAttributes::charBgColor
gsw_CcColor charBgColor
Definition: SubtecConnector.h:177
AampCCManagerBase::StopRendering
virtual void StopRendering()=0
To stop CC rendering.
AampCCManagerBase::SetTrack
int SetTrack(const std::string &track, const CCFormat format=eCLOSEDCAPTION_FORMAT_DEFAULT)
Set CC track.
Definition: AampCCManager.cpp:651
AampJsonParseException
Handles the exception for JSON parser.
Definition: AampJsonObject.h:252
AampCCManagerBase::Initialize
virtual int Initialize(void *handle)
Impl specific initialization code called once in Init() function.
Definition: AampCCManager.h:208
gsw_CcTextStyle
gsw_CcTextStyle
Closed captioning text styles.
Definition: SubtecConnector.h:134
AampJsonObject::get
bool get(const std::string &name, std::vector< std::string > &values)
Get a string value.
Definition: AampJsonObject.cpp:291
AampCCManagerBase::mTrickplayStarted
bool mTrickplayStarted
Definition: AampCCManager.h:250
AampCCManagerBase::SetParentalControlStatus
void SetParentalControlStatus(bool locked)
To enable/disable CC when parental control locked/unlocked.
Definition: AampCCManager.cpp:628
AampCCManagerBase::Init
int Init(void *handle)
Initialize CC resource.
Definition: AampCCManager.cpp:578
AampCCManagerBase::GetTrack
const std::string & GetTrack()
Get current CC track.
Definition: AampCCManager.h:94
AampCCManagerBase::SetAnalogChannel
virtual int SetAnalogChannel(unsigned int id)=0
set analog channel with specified id
gsw_CcAttributes::fontSize
gsw_CcFontSize fontSize
Definition: SubtecConnector.h:183
AampCCManagerBase::mParentalCtrlLocked
bool mParentalCtrlLocked
Definition: AampCCManager.h:251
AampCCManagerBase::SetStatus
int SetStatus(bool enable)
Enable/disable CC rendering.
Definition: AampCCManager.cpp:755
getColor
static int getColor(gsw_CcAttribType attributeIndex, gsw_CcType ccType, std::string input, gsw_CcColor *colorOut)
Get color option from input string.
Definition: AampCCManager.cpp:95
AampCCManagerBase::EnsureInitialized
virtual void EnsureInitialized()
Impl specific initialization code called before each public interface call.
Definition: AampCCManager.h:189
GSW_CC_ANALOG_SERVICE_CC1
@ GSW_CC_ANALOG_SERVICE_CC1
Definition: SubtecConnector.h:277
AampCCManagerBase::SetDigitalChannel
virtual int SetDigitalChannel(unsigned int id)=0
set digital channel with specified id
gsw_CcEdgeType
gsw_CcEdgeType
Font Edge type.
Definition: SubtecConnector.h:161
gsw_CcAttributes::winOpacity
gsw_CcOpacity winOpacity
Definition: SubtecConnector.h:182
gsw_CcAttributes
Definition: SubtecConnector.h:176
getEdgeType
static int getEdgeType(std::string input, gsw_CcEdgeType *edgeTypeOut)
Get edge type value from input string.
Definition: AampCCManager.cpp:187
aamp_StartsWith
bool aamp_StartsWith(const char *inputStr, const char *prefix)
Check if string start with a prefix.
Definition: AampUtils.cpp:284
AampCCManagerBase::Start
void Start()
To start CC rendering.
Definition: AampCCManager.cpp:568
gsw_CcAttributes::charBgOpacity
gsw_CcOpacity charBgOpacity
Definition: SubtecConnector.h:180
AampCCManagerBase::StartRendering
virtual void StartRendering()=0
To start CC rendering.
getFontStyle
static int getFontStyle(std::string input, gsw_CcFontStyle *fontStyleOut)
Get font style value from input string.
Definition: AampCCManager.cpp:243
AampCCManager::DestroyInstance
static void DestroyInstance()
Destroy instance.
Definition: AampCCManager.cpp:817
AampCCManagerBase::SetStyle
int SetStyle(const std::string &options)
Set CC styles for rendering.
Definition: AampCCManager.cpp:400
gsw_CcFontSize
gsw_CcFontSize
Closed caption Fontsize.
Definition: SubtecConnector.h:79
gsw_CcAttributes::fontUnderline
gsw_CcTextStyle fontUnderline
Definition: SubtecConnector.h:186
gsw_CcAttributes::fontItalic
gsw_CcTextStyle fontItalic
Definition: SubtecConnector.h:185
getOpacity
static int getOpacity(std::string input, gsw_CcOpacity *opacityOut)
Get opacity value from input string.
Definition: AampCCManager.cpp:357
AampCCManagerBase::IsOOBCCRenderingSupported
bool IsOOBCCRenderingSupported()
To check whether Out of Band Closed caption/Subtile rendering supported or not.
Definition: AampCCManager.cpp:781
AampJsonObject.h
File to handle Json format.
AampCCManagerBase::mTrack
std::string mTrack
Definition: AampCCManager.h:247
gsw_CcAttributes::winColor
gsw_CcColor winColor
Definition: SubtecConnector.h:179
gsw_CcOpacity
gsw_CcOpacity
Closed Captioning Opacity.
Definition: SubtecConnector.h:66
AampCCManagerBase
Handles closed caption operations.
Definition: AampCCManager.h:51
AampCCManagerBase::mEnabled
bool mEnabled
Definition: AampCCManager.h:249
gsw_CcAttributes::edgeType
gsw_CcEdgeType edgeType
Definition: SubtecConnector.h:189
gsw_CcAttributes::edgeColor
gsw_CcColor edgeColor
Definition: SubtecConnector.h:190
gsw_CcAttributes::borderType
gsw_CcBorderType borderType
Definition: SubtecConnector.h:187
CCFormat
CCFormat
Different CC formats.
Definition: AampCCManager.h:39
AampCCManagerBase::EnsureRendererCommsInitialized
virtual void EnsureRendererCommsInitialized()
Impl specific initialization code for Communication with renderer.
Definition: AampCCManager.h:201
priv_aamp.h
Private functions and types used internally by AAMP.
AampRDKCCManager.h
Integration layer of RDK ClosedCaption in AAMP.
AampSubtecCCManager
Handling Subtec CC operation.
Definition: AampSubtecCCManager.h:43
AampSubtecCCManager.h
Integration layer of Subtec ClosedCaption in AAMP.
AAMPLOG_TRACE
#define AAMPLOG_TRACE(FORMAT,...)
AAMP logging defines, this can be enabled through setLogLevel() as per the need.
Definition: AampLogManager.h:83
getFontSize
static int getFontSize(std::string input, gsw_CcFontSize *fontSizeOut)
Get font size value from input string.
Definition: AampCCManager.cpp:310
gsw_CcAttributes::charFgOpacity
gsw_CcOpacity charFgOpacity
Definition: SubtecConnector.h:181
gsw_CcType
gsw_CcType
Closed Captioning type.
Definition: SubtecConnector.h:55
AampCCManagerBase::SetTrickplayStatus
void SetTrickplayStatus(bool enable)
To enable/disable CC when trickplay starts/ends.
Definition: AampCCManager.cpp:609
AampCCManager::GetInstance
static AampCCManagerBase * GetInstance()
Get the singleton instance.
Definition: AampCCManager.cpp:799
AampCCManager::mInstance
static AampCCManagerBase * mInstance
Singleton instance.
Definition: AampCCManager.h:278
AampCCManagerBase::RestoreCC
void RestoreCC()
To restore cc state after new tune.
Definition: AampCCManager.cpp:744
AampCCManagerBase::Stop
void Stop()
To stop CC rendering.
Definition: AampCCManager.cpp:558
gsw_CcAttributes::borderColor
gsw_CcColor borderColor
Definition: SubtecConnector.h:188
AampRDKCCManager
Handling CC operations.
Definition: AampRDKCCManager.h:39
AampCCManager.h
Integration layer of ClosedCaption in AAMP.
AampCCManagerBase::mOptions
std::string mOptions
Definition: AampCCManager.h:246
gsw_CcAttributes::fontStyle
gsw_CcFontStyle fontStyle
Definition: SubtecConnector.h:184
getTextStyle
static int getTextStyle(std::string input, gsw_CcTextStyle *textStyleOut)
Get text style value from input string.
Definition: AampCCManager.cpp:149
AampJsonObject
Utility class to construct a JSON string.
Definition: AampJsonObject.h:37
gsw_CcColor
Structure to hold color information for CC.
Definition: SubtecConnector.h:43
AampCCManagerBase::CheckCCHandle
virtual bool CheckCCHandle() const
validate mCCHandle
Definition: AampCCManager.h:229