RDK Documentation (Open Sourced RDK Components)
closedcaptions.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt 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 #include "closedcaptions.h"
20 #include <stdio.h>
21 #include "ccDataReader.h"
22 #include "cc_util.h"
23 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
24 #define private public
25 #endif
26 #include "vlGfxScreen.h"
27 #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
28 #undef private
29 #endif
30 #if USE_SYSRES_MLT
31 #include "rpl_new.h"
32 #endif
33 #include <unistd.h>
34 #include "logger.h"
35 
36 #if 0
37 static void cc_msg_callback(CC_MSG_type_t decoderMsg)
38 {
39  if (CC_MSG_RENDER_START == decoderMsg)
40  {
41  LOG_WARNING("CC IS BEING DISPLAYED");
42  }
43  return;
44 }
45 #endif
46 
47 bool ClosedCaptions::m_wasLoadedOnce = false;
48 
49 #if 0
50 void ClosedCaptions::shutdown()
51 {
52  struct MyvlGfxScreen: public vlGfxScreen
53  {
54  static void shutdown()
55  {
56  IDirectFB* dfb = get_dfb();
57  if(dfb)
58  dfb->Release(dfb);
59  }
60  };
61 
62  if(m_wasLoadedOnce)
63  {
64  m_wasLoadedOnce = false;
65  MyvlGfxScreen::shutdown();
66  }
67 }
68 #endif
69 
70 ClosedCaptions::ClosedCaptions()
71 {
72  m_CCVisibilityStatus = 0;
73  m_isCCRendering = false;//CID:82758: Initialization
74  m_isCCEnabled = false;
75  m_isCCReaderStarted = true;
76  m_isParentalBlocked = true;
77  m_isCCStopedAtTrickMode = false;
78  m_viddecHandle = NULL;
79 }
80 
81 
82 ClosedCaptions::~ClosedCaptions()
83 {
84 }
85 
86 
87 bool ClosedCaptions::setEnabled(bool bNewState)
88 {
89  bool ret = true;
90  LOG_INFO("setEnabled enabled=%d", (int)bNewState);
91 
92  if(bNewState == m_isCCEnabled)
93  {
94  /* Trying to set the same state as previous */
95  return ret;
96  }
97 
98  m_isCCEnabled = bNewState;
99 
100  /* Decoder handle will be Set to a value only when it is playing mDVR content */
101  if (m_viddecHandle)
102  {
103  if ((m_isCCEnabled) && (!m_isParentalBlocked) && (!m_isCCStopedAtTrickMode))
104  {
105  ret = ccStart();
106  if (m_ccOptions.size() > 0)
107  {
108  //setAttribute(m_ccOptions);
109  }
110  }
111  else
112  {
113  ret = ccStop();
114  }
115  }
116  if(0 == access("/tmp/force_cc_enable_disable_failure", F_OK))
117  {
118  LOG_WARNING("Forcing setEnabled Failure.");
119  ret = false;
120  }
121  return ret;
122 }
123 
124 
125 void ClosedCaptions::setVisible(bool is_visible)
126 {
127  LOG_INFO("Entered %s \n", __FUNCTION__);
128  if(is_visible)
129  {
130  ccShow();
131 // Platform::Screen::showCCPlane(true);
132  }
133  else
134  {
135  ccHide();
136 // Platform::Screen::showCCPlane(false);
137  }
138 }
139 
140 
141 bool ClosedCaptions::start(void* pViddecHandle)
142 {
143  LOG_INFO("start: viddecHandle=%p", pViddecHandle);
144  //CCREADER_RegisterForLog(cclogcallback); //enable this only if you platform has corresponding modification in closed caption component.
145  if (NULL != pViddecHandle)
146  {
147  if (!m_isCCRendering)
148  {
149  ccInit();
150  int status = media_closeCaptionStart (pViddecHandle);
151  if (status < 0)
152  {
153  LOG_ERROR("start media_closeCaptionStart failed %d", status);
154  return false;
155  }
156  m_isCCReaderStarted = true;
157 
158  m_viddecHandle = pViddecHandle;
159 
160  m_wasLoadedOnce = true;
161 
162 
163  if ((m_isCCEnabled) && (!m_isParentalBlocked) && (!m_isCCStopedAtTrickMode))
164  {
165 #if 0
166  /** For testing, set the attributres locally and see whether it reflects or not */
167  QVariantHash options;
168 
169  options["textForegroundColor"] = "BLUE";
170  options["textItalicized"] = "false";
171  options["windowBorderEdgeStyle"] = "NONE";
172  options["textEdgeColor"] = "RED";
173  options["textEdgeStyle"] = "Uniform";
174  options["windowBorderEdgeColor"] = "BLACK";
175  options["textBackgroundOpacity"] = "SOLID";
176  options["textUnderline"] = "false";
177  options["windowFillColor"] = "white";
178  options["textSize"] = "Medium";
179  options["textBackgroundColor"] = "Green";
180  options["fontStyle"] = "DEFAULT";
181  options["textForegroundOpacity"] = "SOLID";
182  options["windowFillOpacity"] = "TRANSPARENT";
183 
184  setAttribute (options);
185 #endif
186  ccStart();
187  if (m_ccOptions.size() > 0)
188  {
189 // setAttribute(m_ccOptions);
190  }
191 
192  LOG_INFO("ClosedCaptions::start - Started CC data fetching");
193  }
194  else
195  {
196  ccStop();
197  LOG_INFO("ClosedCaptions::start - CC is not enabled");
198  }
199  }
200  else
201  {
202  LOG_INFO("ClosedCaptions::start - Already started");
203  return false;
204  }
205  }
206 #ifdef USE_CLOSED_CAPTIONING_CHIPSET_I
207  else if ((pViddecHandle == NULL) && (m_viddecHandle != NULL))
208  {
209  // special intel use case to stop decoder when viddec goes to zero
210  int status = media_closeCaptionStop();
211  if (status < 0)
212  {
213  LOG_ERROR("ClosedCaptions::start media_closeCaptionStop failed %d", status);
214  }
215  else
216  {
217  LOG_INFO("stop succeeded");
218  }
219  m_viddecHandle = NULL;
220  }
221 #endif
222  else
223  {
224  LOG_ERROR("ClosedCaptions::start - Invalid video decoder handle passed");
225  return false;
226  }
227  return true;
228 }
229 
230 bool ClosedCaptions::stop()
231 {
232  LOG_INFO("stop");
233 
234  if (ccStop())
235  {
236  if (m_viddecHandle)
237  {
238  int status = media_closeCaptionStop();
239  if (status < 0)
240  {
241  LOG_ERROR("ClosedCaptions::stop media_closeCaptionStop failed %d", status);
242  return false;
243  }
244  else
245  {
246  LOG_INFO("ClosedCaptions::stop succeeded");
247  }
248 
249  m_viddecHandle = NULL;
250  }
251  }
252  /* Reset the flags */
253  m_isParentalBlocked = false;
254  m_isCCStopedAtTrickMode = false;
255  m_isCCReaderStarted = false;
256  return true;
257 }
258 
259 
260 bool ClosedCaptions::ccStart()
261 {
262  if (m_isCCReaderStarted && !m_isCCRendering)
263  {
264  int ret = ccSetCCState(CCStatus_ON, 1);
265  m_isCCRendering = true;
266  LOG_WARNING("ClosedCaptions::ccStart started");
267  if(0 == access("/tmp/force_cc_enable_disable_failure", F_OK))
268  {
269  LOG_WARNING("Forcing ccStart failure");
270  return false;
271  }
272  if(0 != ret)
273  {
274  return false;
275  }
276  else
277  {
278  return true;
279  }
280  }
281  return false;
282 }
283 
284 bool ClosedCaptions::ccStop()
285 {
286  if (m_isCCRendering)
287  {
288  ccSetCCState(CCStatus_OFF, 1);
289  m_isCCRendering = false;
290  LOG_INFO("ClosedCaptions::ccStart stopped");
291  }
292  return true;
293 }
294 
295 void ClosedCaptions::ccInit (void)
296 {
297  static bool bInitStatus = false;
298 
299  if (!bInitStatus)
300  {
301  vlGfxInit(0);
302  int status = vlMpeosCCManagerInit();
303  if (0 != status)
304  {
305  LOG_ERROR("ClosedCaptions::ccInit vlMpeosCCManagerInit failed %d", status);
306  return;
307  }
308 
309  bInitStatus = true;
310  LOG_INFO("ClosedCaptions::ccInit succeeded");
311  /*Need to check the CC visibility status to check for Events generated before CC Initialization*/
312  if (0 != m_CCVisibilityStatus)
313  {
314  setVisible(false);
315  }
316  //ccRegisterMsgCallback(cc_msg_callback);
317  }
318  else
319  {
320  LOG_INFO("ClosedCaptions::ccInit - Already inited.. nothing to be done");
321  }
322 
323  return;
324 }
325 
326 std::string ClosedCaptions::getAvailableTracks()
327 {
328  LOG_INFO("getAvailableTracks");
329  //TODO - replace with real API because some stream might have no CC tracks or different CC tracks
330  return "1,2,3,4,5,6";
331 }
332 
333 #if 0
334 void ClosedCaptions::setEvent(bool status, moduleEvents eventType)
335 {
336  LOG_INFO("Entered %s \n", __FUNCTION__);
337 
338  if (true == status)
339  {
340  m_CCVisibilityStatus |= eventType;
341  }
342  else
343  {
344  if (m_CCVisibilityStatus & eventType)
345  {
346  m_CCVisibilityStatus ^= eventType;
347  }
348  }
349  if (0 == m_CCVisibilityStatus)
350  {
351  setVisible(true);
352  }
353  else
354  {
355  setVisible(false);
356  }
357 
358 }
359 
360 QVariantList ClosedCaptions::getSupportedOptions()
361 {
362  LOG_INFO("getSupportedOptions");
363  //from Parker-Comcast-SP-Tru2way-VSP-W01-110715 doc
364  //note: textEdgeColor/textEdgeStyle are not in Parker-Comcast-SP-Tru2way-VSP-W01-110715 doc but support by api
365  //note: added fontSize because I'm not sure if its suppose to be textSize or fontSize - TODO - determine which one to use
366  QVariantList list;
367  list << "textSize"
368  << "fontStyle"
369  << "textForegroundColor"
370  << "textForegroundOpacity"
371  << "textBackgroundColor"
372  << "textBackgroundOpacity"
373  << "textItalicized"
374  << "textUnderline"
375  << "windowFillColor"
376  << "windowFillOpacity"
377  << "windowBorderEdgeColor"
378  << "windowBorderEdgeStyle"
379  << "textEdgeColor"
380  << "textEdgeStyle"
381  << "fontSize";
382  return list;
383 }
384 
385 QVariantList ClosedCaptions::getServiceDetails()
386 {
387  QVariantList availableCCServices;
388  QVariantHash ccServiceDetails;
389 
390  LOG_INFO("getServiceDetails");
391  dumpCaptionDescriptor();
392 
393  //TODO - needs to add mutex protection for m_cationServices
394  int size = m_cationServices.length();
395  closedCaptionsService serviceData;
396 
397  for(int i = 0; i < size;i++)
398  {
399  serviceData = m_cationServices.at(i);
400 
401  ccServiceDetails.insert("ccType",serviceData.ccType);
402  ccServiceDetails.insert("track",serviceData.track);
403  ccServiceDetails.insert("language",serviceData.language);
404  ccServiceDetails.insert("hasEasyReader",serviceData.hasEasyReader);
405  ccServiceDetails.insert("isWideAspectRatio",serviceData.isWideAspectRatio);
406  availableCCServices.append(ccServiceDetails);
407  }
408  return availableCCServices;
409 }
410 
411 bool ClosedCaptions::setTrack(const QString& track)
412 {
413  int iTrack = track.toInt();
415  LOG_WARNING("setTrack track=%s index=%d", track.toAscii().constData(), iTrack);
416 
417  /*In case of invalid track value set the track to primary channel*/
418  if(iTrack < 1 || iTrack > 6)
419  {
420  iTrack = 1;
421  }
422  int status = ccSetDigitalChannel((unsigned int)iTrack);
423  if(0 != status)
424  {
425  LOG_ERROR("setTrack ccSetDigitalChannel failed %d", status);
426  return false;
427  }
428  switch (iTrack)
429  {
430  case 1:
431  analogChannel = GSW_CC_ANALOG_SERVICE_CC1;
432  break;
433  case 2:
434  analogChannel = GSW_CC_ANALOG_SERVICE_CC2;
435  break;
436  case 3:
437  analogChannel = GSW_CC_ANALOG_SERVICE_CC3;
438  break;
439  case 4:
440  analogChannel = GSW_CC_ANALOG_SERVICE_CC4;
441  break;
442  default:
443  analogChannel = GSW_CC_ANALOG_SERVICE_NONE;
444  break;
445  }
446  status = ccSetAnalogChannel(analogChannel);
447  if(0 != status)
448  {
449  LOG_ERROR("setTrack ccSetAnalogChannel failed %d", status);
450  return false;
451  }
452  else
453  {
454  if(0 == access("/tmp/force_cc_set_track_failure", F_OK))
455  {
456  LOG_WARNING("Forcing CC setTrack failure");
457  return false;
458  }
459  return true;
460  }
461 }
462 
463 int ClosedCaptions::getColor (gsw_CcAttribType attributeIndex, gsw_CcType ccType, QString inputStr, gsw_CcColor *pGetColor)
464 {
465  static gsw_CcColor* pCCcolorCaps[GSW_CC_COLOR_MAX];
466  static bool bFlagForMalloc = false;
467  unsigned int ccSizeOfCabs = 0;
468  QByteArray inputBytes = inputStr.toAscii();
469  const char* pColorTextIn = inputBytes.constData();
470  LOG_INFO("%s: %s", __FUNCTION__, pColorTextIn ? pColorTextIn : "NULL");
471  static const int MAX_COLOR_BUFFER_LEN = ((GSW_MAX_CC_COLOR_NAME_LENGTH > 8 ? GSW_MAX_CC_COLOR_NAME_LENGTH : 8) + 1);
472  char pColorText[MAX_COLOR_BUFFER_LEN];
473 
474  if ((pColorTextIn) && (pGetColor))
475  {
476 
477  if (!bFlagForMalloc)
478  {
479  bFlagForMalloc = true;
480  for (int iLoop = 0; iLoop < GSW_CC_COLOR_MAX; iLoop++)
481  {
482  pCCcolorCaps[iLoop] = (gsw_CcColor*) malloc(sizeof(gsw_CcColor));
483  memset (pCCcolorCaps[iLoop], 0, sizeof(gsw_CcColor));
484  }
485  }
486 
487  //if HEX format, convert to color
488  if (0 == strncasecmp ("0x000000", pColorTextIn, MAX_COLOR_BUFFER_LEN))
489  strncpy(pColorText,"BLACK", sizeof(pColorText)); /* RDKSEC-585 unsafe function replaced*/
490  else
491  if (0 == strncasecmp ("0xFFFFFF", pColorTextIn, MAX_COLOR_BUFFER_LEN))
492  strncpy(pColorText,"WHITE", sizeof(pColorText));
493  else
494  if (0 == strncasecmp ("0xFF0000", pColorTextIn, MAX_COLOR_BUFFER_LEN))
495  strncpy(pColorText,"RED", sizeof(pColorText));
496  else
497  if (0 == strncasecmp ("0x00FF00", pColorTextIn, MAX_COLOR_BUFFER_LEN))
498  strncpy(pColorText,"GREEN", sizeof(pColorText));
499  else
500  if (0 == strncasecmp ("0x0000FF", pColorTextIn, MAX_COLOR_BUFFER_LEN))
501  strncpy(pColorText,"BLUE", sizeof(pColorText));
502  else
503  if (0 == strncasecmp ("0xFFFF00", pColorTextIn, MAX_COLOR_BUFFER_LEN))
504  strncpy(pColorText,"YELLOW", sizeof(pColorText));
505  else
506  if (0 == strncasecmp ("0xFF00FF", pColorTextIn, MAX_COLOR_BUFFER_LEN))
507  strncpy(pColorText,"MAGENTA", sizeof(pColorText));
508  else
509  if (0 == strncasecmp ("0x00FFFF", pColorTextIn, MAX_COLOR_BUFFER_LEN))
510  strncpy(pColorText,"CYAN", sizeof(pColorText));
511  else
512  if (0 == strncasecmp ("0xFF000000", pColorTextIn, MAX_COLOR_BUFFER_LEN))
513  strncpy(pColorText,"AUTO", sizeof(pColorText));
514  else
515  strncpy(pColorText, pColorTextIn, MAX_COLOR_BUFFER_LEN);//could be a string color or could just be wrong
516 
517  ccGetCapability(attributeIndex, ccType, (void**) &pCCcolorCaps, &ccSizeOfCabs);
518  bool found = false;
519  for (unsigned int i = 0; i < ccSizeOfCabs; i++)
520  {
521  //LOG_INFO("%s color caps: %s", __FUNCTION__, pCCcolorCaps[i]->name);
522  if (0 == strncasecmp (pCCcolorCaps[i]->name, pColorText, GSW_MAX_CC_COLOR_NAME_LENGTH))
523  {
524  LOG_INFO("%s found match %s", __FUNCTION__, pCCcolorCaps[i]->name);
525  memcpy (pGetColor, pCCcolorCaps[i], sizeof (gsw_CcColor));
526  found = true;
527  break;
528  }
529  }
530  if(!found)
531  LOG_WARNING("%s: Unsupported Color type %s", __FUNCTION__, pColorText);
532  }
533  else
534  {
535  LOG_WARNING("%s: Null input", __FUNCTION__);
536  return -1;
537  }
538  return 0;
539 }
540 
541 int ClosedCaptions::getOpacity (QString inputStr, gsw_CcOpacity *pGetOpacity)
542 {
543  QByteArray inputBytes = inputStr.toAscii();
544  const char* pGivenOpacity = inputBytes.constData();
545  LOG_INFO("%s: %s", __FUNCTION__, pGivenOpacity ? pGivenOpacity : "NULL");
546  if ((pGivenOpacity) && (pGetOpacity))
547  {
548  if (0 == strncasecmp (pGivenOpacity, "solid", strlen ("solid")))
549  *pGetOpacity = GSW_CC_OPACITY_SOLID;
550  else if (0 == strncasecmp (pGivenOpacity, "flash", strlen ("flash")))
551  *pGetOpacity = GSW_CC_OPACITY_FLASHING;
552  else if (0 == strncasecmp (pGivenOpacity, "translucent", strlen ("translucent")))
553  *pGetOpacity = GSW_CC_OPACITY_TRANSLUCENT;
554  else if (0 == strncasecmp (pGivenOpacity, "transparent", strlen ("transparent")))
555  *pGetOpacity = GSW_CC_OPACITY_TRANSPARENT;
556  else if (0 == strncasecmp (pGivenOpacity, "auto", strlen ("auto")))
557  *pGetOpacity = GSW_CC_OPACITY_EMBEDDED;
558  else
559  {
560  LOG_WARNING("%s: Unsupported Opacity type %s", __FUNCTION__, pGivenOpacity);
561  }
562  }
563  else
564  {
565  LOG_WARNING("%s: Null input", __FUNCTION__);
566  return -1;
567  }
568  return 0;
569 }
570 
571 int ClosedCaptions::getFontSize (QString inputStr, gsw_CcFontSize *pGetFontSize)
572 {
573  QByteArray inputBytes = inputStr.toAscii();
574  const char* pGivenFontSize = inputBytes.constData();
575  LOG_INFO("%s: %s", __FUNCTION__, pGivenFontSize ? pGivenFontSize : "NULL");
576  if ((pGivenFontSize) && (pGetFontSize))
577  {
578  if (0 == strncasecmp (pGivenFontSize, "small", strlen ("small")))
579  *pGetFontSize = GSW_CC_FONT_SIZE_SMALL;
580  else if ((0 == strncasecmp (pGivenFontSize, "standard", strlen ("standard"))) || (0 == strncasecmp (pGivenFontSize, "medium", strlen ("medium"))))
581  *pGetFontSize = GSW_CC_FONT_SIZE_STANDARD;
582  else if (0 == strncasecmp (pGivenFontSize, "large", strlen ("large")))
583  *pGetFontSize = GSW_CC_FONT_SIZE_LARGE;
584  else if (0 == strncasecmp (pGivenFontSize, "auto", strlen ("auto")))
585  *pGetFontSize = GSW_CC_FONT_SIZE_EMBEDDED;
586  else
587  {
588  LOG_WARNING("%s: Unsupported Font Size type %s", __FUNCTION__, pGivenFontSize);
589  }
590  }
591  else
592  {
593  LOG_WARNING("%s: Null input", __FUNCTION__);
594  return -1;
595  }
596  return 0;
597 }
598 
599 int ClosedCaptions::getFontStyle (QString inputStr, gsw_CcFontStyle *pGetFontStyle)
600 {
601  QByteArray inputBytes = inputStr.toAscii();
602  const char* pGivenFontStyle = inputBytes.constData();
603  LOG_INFO("%s: %s", __FUNCTION__, pGivenFontStyle ? pGivenFontStyle : "NULL");
604  if ((pGivenFontStyle) && (pGetFontStyle))
605  {
606  if (0 == strncasecmp (pGivenFontStyle, "default", strlen ("default")))
607  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_DEFAULT, sizeof(gsw_CcFontStyle));
608  else if ((0 == strncasecmp (pGivenFontStyle, "monospaced_serif", strlen ("monospaced_serif"))) || (0 == strncasecmp (pGivenFontStyle, "Monospaced serif", strlen ("Monospaced serif"))))
609  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_MONOSPACED_SERIF, sizeof(gsw_CcFontStyle));
610  else if ((0 == strncasecmp (pGivenFontStyle, "proportional_serif", strlen ("proportional_serif"))) || (0 == strncasecmp (pGivenFontStyle, "Proportional serif", strlen ("Proportional serif"))))
611  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_PROPORTIONAL_SERIF, sizeof(gsw_CcFontStyle));
612  else if ((0 == strncasecmp (pGivenFontStyle, "monospaced_sanserif", strlen ("monospaced_sanserif"))) || (0 == strncasecmp (pGivenFontStyle, "Monospaced sans serif", strlen ("Monospaced sans serif"))))
613  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_MONOSPACED_SANSSERIF, sizeof(gsw_CcFontStyle));
614  else if ((0 == strncasecmp (pGivenFontStyle, "proportional_sanserif", strlen ("proportional_sanserif"))) || (0 == strncasecmp (pGivenFontStyle, "Proportional sans serif", strlen ("Proportional sans serif"))))
615  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_PROPORTIONAL_SANSSERIF, sizeof(gsw_CcFontStyle));
616  else if (0 == strncasecmp (pGivenFontStyle, "casual", strlen ("casual")))
617  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_CASUAL, sizeof(gsw_CcFontStyle));
618  else if (0 == strncasecmp (pGivenFontStyle, "cursive", strlen ("cursive")))
619  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_CURSIVE, sizeof(gsw_CcFontStyle));
620  else if ((0 == strncasecmp (pGivenFontStyle, "smallcaps", strlen ("smallcaps"))) || (0 == strncasecmp (pGivenFontStyle, "small capital", strlen ("small capital"))))
621  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_SMALL_CAPITALS, sizeof(gsw_CcFontStyle));
622  else if (0 == strncasecmp (pGivenFontStyle, "auto", strlen ("auto")))
623  memcpy (pGetFontStyle, GSW_CC_FONT_STYLE_EMBEDDED, sizeof(gsw_CcFontStyle));
624  else
625  LOG_WARNING("%s: Unsupported Font style type %s", __FUNCTION__, pGivenFontStyle);
626  }
627  else
628  {
629  LOG_WARNING("%s: Null input", __FUNCTION__);
630  return -1;
631  }
632  return 0;
633 }
634 
635 int ClosedCaptions::getEdgeType (QString inputStr, gsw_CcEdgeType *pGetEdgeType)
636 {
637  QByteArray inputBytes = inputStr.toAscii();
638  const char* pGivenEdgeType = inputBytes.constData();
639  LOG_INFO("%s: %s", __FUNCTION__, pGivenEdgeType ? pGivenEdgeType : "NULL");
640  if ((pGivenEdgeType) && (pGetEdgeType))
641  {
642  if (0 == strncasecmp (pGivenEdgeType, "none", strlen ("none")))
643  *pGetEdgeType = GSW_CC_EDGE_TYPE_NONE;
644  else if (0 == strncasecmp (pGivenEdgeType, "raised", strlen ("raised")))
645  *pGetEdgeType = GSW_CC_EDGE_TYPE_RAISED;
646  else if (0 == strncasecmp (pGivenEdgeType, "depressed", strlen ("depressed")))
647  *pGetEdgeType = GSW_CC_EDGE_TYPE_DEPRESSED;
648  else if (0 == strncasecmp (pGivenEdgeType, "uniform", strlen ("uniform")))
649  *pGetEdgeType = GSW_CC_EDGE_TYPE_UNIFORM;
650  else if ((0 == strncasecmp (pGivenEdgeType, "drop_shadow_left", strlen ("drop_shadow_left"))) || (0 == strncasecmp (pGivenEdgeType, "Left drop shadow", strlen ("Left drop shadow"))))
651  *pGetEdgeType = GSW_CC_EDGE_TYPE_SHADOW_LEFT;
652  else if ((0 == strncasecmp (pGivenEdgeType, "drop_shadow_right", strlen ("drop_shadow_right"))) || (0 == strncasecmp (pGivenEdgeType, "Right drop shadow", strlen ("Right drop shadow"))))
653  *pGetEdgeType = GSW_CC_EDGE_TYPE_SHADOW_RIGHT;
654  else if (0 == strncasecmp (pGivenEdgeType, "auto", strlen ("auto")))
655  *pGetEdgeType = GSW_CC_EDGE_TYPE_EMBEDDED;
656  else
657  LOG_WARNING("%s: Unsupported Edge type %s", __FUNCTION__, pGivenEdgeType);
658  }
659  else
660  {
661  LOG_WARNING("%s: Null input", __FUNCTION__);
662  return -1;
663  }
664  return 0;
665 }
666 
667 int ClosedCaptions::getTextStyle (QString inputStr, gsw_CcTextStyle *pGetTextStyle)
668 {
669  QByteArray inputBytes = inputStr.toAscii();
670  const char* pGivenTextStyle = inputBytes.constData();
671  LOG_INFO("%s: %s", __FUNCTION__, pGivenTextStyle ? pGivenTextStyle : "NULL");
672  if ((pGivenTextStyle) && (pGetTextStyle))
673  {
674  if (0 == strncasecmp (pGivenTextStyle, "false", strlen ("false")))
675  *pGetTextStyle = GSW_CC_TEXT_STYLE_FALSE;
676  else if (0 == strncasecmp (pGivenTextStyle, "true", strlen ("true")))
677  *pGetTextStyle = GSW_CC_TEXT_STYLE_TRUE;
678  else if (0 == strncasecmp (pGivenTextStyle, "auto", strlen ("auto")))
679  *pGetTextStyle = GSW_CC_TEXT_STYLE_EMBEDDED_TEXT;
680  else
681  {
682  LOG_WARNING("%s: Unsupported Text style %s", __FUNCTION__, pGivenTextStyle);
683  }
684  }
685  else
686  {
687  LOG_WARNING("%s: Null input", __FUNCTION__);
688  return -1;
689  }
690  return 0;
691 }
692 
693 void ClosedCaptions::setAttribute(QVariantHash options)
694 {
695  LOG_WARNING("setAttribute");
696 
697  if (m_ccOptions != options)
698  {
699  m_ccOptions = options;
700  }
701 
702  gsw_CcAttributes attribute;
703 
704  /** Get the current attributes */
705  ccGetAttributes (&attribute, GSW_CC_TYPE_DIGITAL);
706 
707  /* Font FG Color */
708  {
709  /* Get the color */
710  getColor (GSW_CC_ATTRIB_FONT_COLOR, GSW_CC_TYPE_DIGITAL, options["textForegroundColor"].toString(), &(attribute.charFgColor));
711 
712  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_COLOR, GSW_CC_TYPE_DIGITAL);
713  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_COLOR, GSW_CC_TYPE_ANALOG);
714  }
715 
716  /* Font BG Color */
717  {
718  /* Get the color */
719  getColor (GSW_CC_ATTRIB_BACKGROUND_COLOR, GSW_CC_TYPE_DIGITAL, options["textBackgroundColor"].toString(), &(attribute.charBgColor));
720 
721  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BACKGROUND_COLOR, GSW_CC_TYPE_DIGITAL);
722  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BACKGROUND_COLOR, GSW_CC_TYPE_ANALOG);
723  }
724 
725  /* Window border color */
726  {
727  /* Get the color */
728  getColor (GSW_CC_ATTRIB_BORDER_COLOR, GSW_CC_TYPE_DIGITAL, options["windowBorderEdgeColor"].toString(), &(attribute.borderColor));
729 
730  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BORDER_COLOR, GSW_CC_TYPE_DIGITAL);
731  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BORDER_COLOR, GSW_CC_TYPE_ANALOG);
732  }
733 
734  /* Window COLOR */
735  {
736  /* Get the color */
737  getColor (GSW_CC_ATTRIB_WIN_COLOR, GSW_CC_TYPE_DIGITAL, options["windowFillColor"].toString(), &(attribute.winColor));
738 
739  ccSetAttributes(&attribute, GSW_CC_ATTRIB_WIN_COLOR, GSW_CC_TYPE_DIGITAL);
740  ccSetAttributes(&attribute, GSW_CC_ATTRIB_WIN_COLOR, GSW_CC_TYPE_ANALOG);
741  }
742 
743  /* Test Edge color */
744  {
745  /* Get the color */
746  getColor (GSW_CC_ATTRIB_EDGE_COLOR, GSW_CC_TYPE_DIGITAL, options["textEdgeColor"].toString(), &(attribute.edgeColor));
747 
748  ccSetAttributes(&attribute, GSW_CC_ATTRIB_EDGE_COLOR, GSW_CC_TYPE_DIGITAL);
749  ccSetAttributes(&attribute, GSW_CC_ATTRIB_EDGE_COLOR, GSW_CC_TYPE_ANALOG);
750  }
751 
752  /* FONT FG OPACITY */
753  {
754  getOpacity (options["textForegroundOpacity"].toString(), &(attribute.charFgOpacity));
755  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_OPACITY, GSW_CC_TYPE_DIGITAL);
756  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_OPACITY, GSW_CC_TYPE_ANALOG);
757  }
758 
759  /* Font BACKGROUND OPACITY */
760  {
761  getOpacity (options["textBackgroundOpacity"].toString(), &(attribute.charBgOpacity));
762  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BACKGROUND_OPACITY, GSW_CC_TYPE_DIGITAL);
763  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BACKGROUND_OPACITY, GSW_CC_TYPE_ANALOG);
764  }
765 
766  /* Window OPACITY */
767  {
768  getOpacity (options["windowFillOpacity"].toString(), &(attribute.winOpacity));
769  ccSetAttributes(&attribute, GSW_CC_ATTRIB_WIN_OPACITY, GSW_CC_TYPE_DIGITAL);
770  ccSetAttributes(&attribute, GSW_CC_ATTRIB_WIN_OPACITY, GSW_CC_TYPE_ANALOG);
771  }
772 
773  /* Text EDGE TYPE */
774  {
775  getEdgeType (options["textEdgeStyle"].toString(), &(attribute.edgeType));
776  ccSetAttributes(&attribute, GSW_CC_ATTRIB_EDGE_TYPE, GSW_CC_TYPE_DIGITAL);
777  ccSetAttributes(&attribute, GSW_CC_ATTRIB_EDGE_TYPE, GSW_CC_TYPE_ANALOG);
778  }
779 
780  /* Window border TYPE */
781  {
782  getEdgeType (options["windowBorderEdgeStyle"].toString(), (gsw_CcEdgeType*) &(attribute.borderType));
783  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BORDER_TYPE, GSW_CC_TYPE_DIGITAL);
784  ccSetAttributes(&attribute, GSW_CC_ATTRIB_BORDER_TYPE, GSW_CC_TYPE_ANALOG);
785  }
786 
787  /* FONT STYLE */
788  {
789  getFontStyle (options["fontStyle"].toString(), &(attribute.fontStyle));
790  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_STYLE, GSW_CC_TYPE_DIGITAL);
791  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_STYLE, GSW_CC_TYPE_ANALOG);
792  }
793 
794  /* FONT SIZE */
795  {
796  getFontSize (options["textSize"].toString(), &(attribute.fontSize));
797  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_SIZE, GSW_CC_TYPE_DIGITAL);
798  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_SIZE, GSW_CC_TYPE_ANALOG);
799  }
800 
801  /* UnHandled part of settings */
802  {
803 // LOG_INFO("textItalicized = %s", options["textItalicized"].toString().toAscii().constData());
804 // LOG_INFO("textUnderline= %s", options["textUnderline"].toString().toAscii().constData());
805  }
806 
807  /* FONT ITALIC */
808  {
809  getTextStyle(options["textItalicized"].toString(), &(attribute.fontItalic));
810  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_ITALIC, GSW_CC_TYPE_DIGITAL);
811  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_ITALIC, GSW_CC_TYPE_ANALOG);
812  }
813 
814  /* FONT UNDERLINE */
815  {
816  getTextStyle(options["textUnderline"].toString(), &(attribute.fontUnderline));
817  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_UNDERLINE, GSW_CC_TYPE_DIGITAL);
818  ccSetAttributes(&attribute, GSW_CC_ATTRIB_FONT_UNDERLINE, GSW_CC_TYPE_ANALOG);
819  }
820 
821  return;
822 }
823 
824 
825 
826 bool ClosedCaptions::ccEASStarted()
827 {
828  LOG_INFO("ClosedCaptions::ccEASStarted - Entered");
829  ccOnEasStart();
830  return true;
831 }
832 
833 bool ClosedCaptions::ccEASStopped()
834 {
835  LOG_INFO("ClosedCaptions::ccEASStopped - Entered");
836  ccOnEasStop();
837  return true;
838 }
839 
840 
841 /**
842  * @fn bool ClosedCaptions::ccParentalLockStart()
843  * @brief This function disables the closed caption and stop rendering cc if the service is a parental lock.
844  *
845  * @return Returns the status of cc stop process.
846  */
847 bool ClosedCaptions::ccParentalLockStart()
848 {
849  LOG_INFO("ClosedCaptions::ccParentalLockStart - Entered");
850  m_isParentalBlocked = true;
851  return ccStop();
852 }
853 
854 bool ClosedCaptions::ccParentalLockStop()
855 {
856  LOG_INFO("ClosedCaptions::ccParentalLockStop - Entered");
857  if ((m_isCCEnabled) && (m_isParentalBlocked) && (!m_isCCStopedAtTrickMode))
858  {
859  ccStart();
860  if (m_ccOptions.size() > 0)
861  {
862  setAttribute(m_ccOptions);
863  }
864  }
865  m_isParentalBlocked = false;
866  return true;
867 }
868 
869 bool ClosedCaptions::stopCCatTrickMode ()
870 {
871  LOG_INFO("ClosedCaptions::stopCCatTrickMode - Entered");
872  m_isCCStopedAtTrickMode = true;
873  return ccStop();
874 }
875 
876 bool ClosedCaptions::startCCatNormalMode ()
877 {
878  LOG_INFO("ClosedCaptions::startCCatNormalMode - Entered");
879  m_isCCStopedAtTrickMode = false;
880  if ((m_isCCEnabled) && (!m_isParentalBlocked) && (!m_isCCStopedAtTrickMode))
881  {
882  return ccStart();
883  }
884  return true;
885 }
886 
887 void ClosedCaptions::ccGfxPreResolution(unsigned id)
888 {
889  LOG_INFO("ClosedCaptions::ccGfxPreResolution - Entered");
890  vlGfxPreResolution(id);
891  return;
892 }
893 
894 
895 void ClosedCaptions::ccGfxSetResolution(unsigned id, int width, int height)
896 {
897  LOG_INFO("ClosedCaptions::ccGfxSetResolution - Entered");
898  vlGfxSetResolution(id, width, height);
899  return;
900 }
901 
902 
903 void ClosedCaptions::ccGfxPostResolution(int id, int width, int height)
904 {
905  LOG_INFO("ClosedCaptions::ccGfxPostResolution - Entered");
906  vlGfxPostResolution(id, width, height);
907  return;
908 }
909 
910 #endif
911 
gsw_CcAttribType
gsw_CcAttribType
type of attributes
Definition: SubtecConnector.h:198
gsw_CcAttributes::charFgColor
gsw_CcColor charFgColor
Definition: SubtecConnector.h:178
GSW_CC_ANALOG_SERVICE_CC3
@ GSW_CC_ANALOG_SERVICE_CC3
Definition: SubtecConnector.h:279
gsw_CcAttributes::charBgColor
gsw_CcColor charBgColor
Definition: SubtecConnector.h:177
gsw_CcTextStyle
gsw_CcTextStyle
Closed captioning text styles.
Definition: SubtecConnector.h:134
gsw_CcAnalogServices
gsw_CcAnalogServices
Definition: SubtecConnector.h:275
GSW_CC_ANALOG_SERVICE_CC4
@ GSW_CC_ANALOG_SERVICE_CC4
Definition: SubtecConnector.h:280
gsw_CcAttributes::fontSize
gsw_CcFontSize fontSize
Definition: SubtecConnector.h:183
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
GSW_CC_ANALOG_SERVICE_CC1
@ GSW_CC_ANALOG_SERVICE_CC1
Definition: SubtecConnector.h:277
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
gsw_CcAttributes::charBgOpacity
gsw_CcOpacity charBgOpacity
Definition: SubtecConnector.h:180
CCStatus_OFF
@ CCStatus_OFF
Definition: SubtecConnector.h:366
getFontStyle
static int getFontStyle(std::string input, gsw_CcFontStyle *fontStyleOut)
Get font style value from input string.
Definition: AampCCManager.cpp:243
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
gsw_CcAttributes::winColor
gsw_CcColor winColor
Definition: SubtecConnector.h:179
gsw_CcOpacity
gsw_CcOpacity
Closed Captioning Opacity.
Definition: SubtecConnector.h:66
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
CCStatus_ON
@ CCStatus_ON
Definition: SubtecConnector.h:368
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
GSW_CC_ANALOG_SERVICE_CC2
@ GSW_CC_ANALOG_SERVICE_CC2
Definition: SubtecConnector.h:278
LOG_INFO
#define LOG_INFO(AAMP_JS_OBJECT, FORMAT,...)
Definition: jsutils.h:39
gsw_CcAttributes::borderColor
gsw_CcColor borderColor
Definition: SubtecConnector.h:188
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
gsw_CcColor
Structure to hold color information for CC.
Definition: SubtecConnector.h:43