RDK Documentation (Open Sourced RDK Components)
SubtecConnector.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 SubtecConnector.cpp
22  *
23  * @brief Impl of libsubtec_connector
24  *
25  */
26 
29 
30 #include "ccDataReader.h"
31 
32 
33 #include <iomanip>
34 #include <sstream>
35 #include <mutex>
36 
37 #include <cstdio>
38 #include <cstdarg>
39 
40 #include "AampLogManager.h"
41 
42 
43 namespace subtecConnector
44 {
45  mrcc_Error initHal()
46  {
47  const auto registerResult = vlhal_cc_Register(0, CCDataController::Instance(), closedCaptionDataCb, closedCaptionDecodeCb);
48  logprintf("vlhal_cc_Register return value = %d\n", registerResult);
49 
50  if(registerResult != 0)
51  return CC_VL_OS_API_RESULT_FAILED;
52 
53  const auto startResult = media_closeCaptionStart(nullptr);
54  logprintf("media_closeCaptionStart return value = %d\n", registerResult);
55 
56  if(startResult != 0)
57  return CC_VL_OS_API_RESULT_FAILED;
58 
59  return CC_VL_OS_API_RESULT_SUCCESS;
60  }
61 
62  mrcc_Error initPacketSender()
63  {
64  const auto packetSenderStartResult = ClosedCaptionsChannel::InitComms();
65  logprintf("CCDataController::Instance()->InitComms() return value = %d\n", (int)packetSenderStartResult);
66 
67  if(!packetSenderStartResult)
68  return CC_VL_OS_API_RESULT_FAILED;
69 
70  return CC_VL_OS_API_RESULT_SUCCESS;
71  }
72  void resetChannel()
73  {
74  CCDataController::Instance()->sendResetChannelPacket();
75  }
76 
77  void close()
78  {
79  media_closeCaptionStop();
80  }
81 
82 
83 namespace ccMgrAPI
84 {
85 
86  typedef int mrcc_Error;
87 
88  mrcc_Error ccShow(void)
89  {
90  CCDataController::Instance()->sendUnmute();
91  return {};
92  }
93 
94  mrcc_Error ccHide(void)
95  {
96  CCDataController::Instance()->sendMute();
97  return {};
98  }
99 
100  mrcc_Error ccSetAttributes(gsw_CcAttributes * attrib, short type, gsw_CcType ccType)
101  {
102  CCDataController::Instance()->sendCCSetAttribute(attrib, type, ccType);
103  return {};
104  }
105 
106  mrcc_Error ccSetDigitalChannel(unsigned int channel)
107  {
108  CCDataController::Instance()->ccSetDigitalChannel(channel);
109  return {};
110  }
111 
112  mrcc_Error ccSetAnalogChannel(unsigned int channel)
113  {
114  CCDataController::Instance()->ccSetAnalogChannel(channel);
115  return {};
116  }
117 
118  mrcc_Error ccGetAttributes(gsw_CcAttributes * attrib, gsw_CcType ccType)
119  {
120  CCDataController::Instance()->ccGetAttributes(attrib, ccType);
121  return {};
122  }
123 
124  mrcc_Error ccGetCapability(gsw_CcAttribType attribType, gsw_CcType ccType, void **values, unsigned int *size)
125  {
126 
127  if(!values || !size)
128  {
129  return CC_VL_OS_API_RESULT_FAILED;
130  }
131 
132  *size = 0; //default case
133  int i = 0;
134 
135 
136  switch(attribType)
137  {
138  case GSW_CC_ATTRIB_FONT_COLOR :
139  case GSW_CC_ATTRIB_BACKGROUND_COLOR:
140  case GSW_CC_ATTRIB_BORDER_COLOR:
141  case GSW_CC_ATTRIB_WIN_COLOR:
142  case GSW_CC_ATTRIB_EDGE_COLOR:
143  {
144  *size = sizeof(CCSupportedColors_strings)/sizeof(char *);
145  const char** pValuesNames = CCSupportedColors_strings;
146 
147  *size = sizeof(CCSupportedColors)/sizeof( unsigned long);
148  const unsigned long * pValues = CCSupportedColors;
149  // Copy our colors into the given capability array
150 
151  for(i = 0; i < *size; i++)
152  {
153  ((gsw_CcColor*)values[i])->rgb = pValues[i];
154  strncpy(((gsw_CcColor*)values[i])->name, pValuesNames[i],
155  GSW_MAX_CC_COLOR_NAME_LENGTH);
156  }
157  break;
158  }
159  default:
160  logprintf("ccGetCapability invoked with not supported attribType = 0x%x\n", (int)attribType);
161  return CC_VL_OS_API_RESULT_FAILED;
162  }
163 
164  return CC_VL_OS_API_RESULT_SUCCESS;
165  }
166 
167 
168 } // ccMgrAPI
169 } // subtecConnector
AampLogManager.h
Log managed for Aamp.
gsw_CcAttribType
gsw_CcAttribType
type of attributes
Definition: SubtecConnector.h:198
logprintf
void logprintf(const char *format,...)
Print logs to console / log fil.
Definition: aamplogging.cpp:432
gsw_CcAttributes
Definition: SubtecConnector.h:176
CCDataController.h
Impl of subtec communication layer.
SubtecConnector.h
Interface header for libsubtec_connector.
gsw_CcType
gsw_CcType
Closed Captioning type.
Definition: SubtecConnector.h:55
gsw_CcColor
Structure to hold color information for CC.
Definition: SubtecConnector.h:43