forked from rdkcentral/rdkservices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHdmiCecSink.h
491 lines (442 loc) · 17.8 KB
/
HdmiCecSink.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2019 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#pragma once
#include <stdint.h>
#include "ccec/FrameListener.hpp"
#include "ccec/Connection.hpp"
#include "libIBus.h"
#include "ccec/Assert.hpp"
#include "ccec/Messages.hpp"
#include "ccec/MessageDecoder.hpp"
#include "ccec/MessageProcessor.hpp"
#undef Assert // this define from Connection.hpp conflicts with WPEFramework
#include "Module.h"
#include "utils.h"
#include "AbstractPlugin.h"
#include <thread>
#include <mutex>
namespace WPEFramework {
namespace Plugin {
class HdmiCecSinkFrameListener : public FrameListener
{
public:
HdmiCecSinkFrameListener(MessageProcessor &processor) : processor(processor) {}
void notify(const CECFrame &in) const;
~HdmiCecSinkFrameListener() {}
private:
MessageProcessor &processor;
};
class HdmiCecSinkProcessor : public MessageProcessor
{
public:
HdmiCecSinkProcessor(Connection &conn) : conn(conn) {}
void process (const ActiveSource &msg, const Header &header);
void process (const InActiveSource &msg, const Header &header);
void process (const ImageViewOn &msg, const Header &header);
void process (const TextViewOn &msg, const Header &header);
void process (const RequestActiveSource &msg, const Header &header);
void process (const Standby &msg, const Header &header);
void process (const GetCECVersion &msg, const Header &header);
void process (const CECVersion &msg, const Header &header);
void process (const SetMenuLanguage &msg, const Header &header);
void process (const GiveOSDName &msg, const Header &header);
void process (const GivePhysicalAddress &msg, const Header &header);
void process (const GiveDeviceVendorID &msg, const Header &header);
void process (const SetOSDString &msg, const Header &header);
void process (const SetOSDName &msg, const Header &header);
void process (const RoutingChange &msg, const Header &header);
void process (const RoutingInformation &msg, const Header &header);
void process (const SetStreamPath &msg, const Header &header);
void process (const GetMenuLanguage &msg, const Header &header);
void process (const ReportPhysicalAddress &msg, const Header &header);
void process (const DeviceVendorID &msg, const Header &header);
void process (const GiveDevicePowerStatus &msg, const Header &header);
void process (const ReportPowerStatus &msg, const Header &header);
void process (const FeatureAbort &msg, const Header &header);
void process (const Abort &msg, const Header &header);
void process (const Polling &msg, const Header &header);
private:
Connection conn;
void printHeader(const Header &header)
{
printf("Header : From : %s \n", header.from.toString().c_str());
printf("Header : to : %s \n", header.to.toString().c_str());
}
};
class CECDeviceParams {
public:
enum {
REQUEST_NONE = 0,
REQUEST_PHISICAL_ADDRESS = 1,
REQUEST_CEC_VERSION,
REQUEST_DEVICE_VENDOR_ID,
REQUEST_POWER_STATUS,
REQUEST_OSD_NAME,
};
enum {
REQUEST_DONE = 0,
REQUEST_NOT_DONE,
REQUEST_TIME_ELAPSED,
};
DeviceType m_deviceType;
LogicalAddress m_logicalAddress;
PhysicalAddress m_physicalAddr;
Version m_cecVersion;
VendorID m_vendorID;
OSDName m_osdName;
PowerStatus m_powerStatus;
bool m_isDevicePresent;
bool m_isDeviceDisconnected;
Language m_currentLanguage;
bool m_isActiveSource;
bool m_isDeviceTypeUpdated;
bool m_isPAUpdated;
bool m_isVersionUpdated;
bool m_isOSDNameUpdated;
bool m_isVendorIDUpdated;
bool m_isPowerStatusUpdated;
int m_isRequested;
int m_isRequestRetry;
std::chrono::system_clock::time_point m_requestTime;
std::vector<FeatureAbort> m_featureAborts;
std::chrono::system_clock::time_point m_lastPowerUpdateTime;
CECDeviceParams()
: m_deviceType(0), m_logicalAddress(0),m_physicalAddr(0,0,0,0),m_cecVersion(0),m_vendorID(0,0,0),m_osdName("NA"),m_powerStatus(0),m_currentLanguage("NA")
{
m_isDevicePresent = false;
m_isActiveSource = false;
m_isPAUpdated = false;
m_isVersionUpdated = false;
m_isOSDNameUpdated = false;
m_isVendorIDUpdated = false;
m_isPowerStatusUpdated = false;
m_isDeviceDisconnected = false;
m_isDeviceTypeUpdated = false;
m_isRequestRetry = 0;
}
void clear( )
{
m_deviceType = 0;
m_logicalAddress = 0;
m_physicalAddr = PhysicalAddress(0,0,0,0);
m_cecVersion = 0;
m_vendorID = VendorID(0,0,0);
m_osdName = "NA";
m_powerStatus = 0;
m_currentLanguage = "NA";
m_isDevicePresent = false;
m_isActiveSource = false;
m_isPAUpdated = false;
m_isVersionUpdated = false;
m_isOSDNameUpdated = false;
m_isVendorIDUpdated = false;
m_isPowerStatusUpdated = false;
m_isDeviceDisconnected = false;
m_isDeviceTypeUpdated = false;
}
void printVariable()
{
LOGWARN("Device LogicalAddress %s", m_logicalAddress.toString().c_str());
LOGWARN("Device Type %s", m_deviceType.toString().c_str());
LOGWARN("Device Present %d", m_isDevicePresent);
LOGWARN("Active Source %d", m_isActiveSource);
LOGWARN("PA Updated %d", m_isPAUpdated);
LOGWARN("Version Updated %d", m_isVersionUpdated);
LOGWARN("OSDName Updated %d", m_isOSDNameUpdated);
LOGWARN("PowerStatus Updated %d", m_isPowerStatusUpdated);
LOGWARN("VendorID Updated %d", m_isPowerStatusUpdated);
LOGWARN("CEC Version : %s", m_cecVersion.toString().c_str());
LOGWARN("Vendor ID : %s", m_vendorID.toString().c_str());
LOGWARN("PhisicalAddress : %s", m_physicalAddr.toString().c_str());
LOGWARN("OSDName : %s", m_osdName.toString().c_str());
LOGWARN("Power Status : %s", m_powerStatus.toString().c_str());
LOGWARN("Language : %s", m_currentLanguage.toString().c_str());
}
bool isAllUpdated() {
if( !m_isPAUpdated
|| !m_isVersionUpdated
|| !m_isOSDNameUpdated
|| !m_isVendorIDUpdated
|| !m_isPowerStatusUpdated
|| !m_isDeviceTypeUpdated ){
return false;
}
return true;
}
void update( const DeviceType &deviceType ) {
m_deviceType = deviceType;
m_isDeviceTypeUpdated = true;
}
void update( const PhysicalAddress &physical_addr ) {
m_physicalAddr = physical_addr;
m_isPAUpdated = true;
}
void update ( const VendorID &vendorId) {
m_vendorID = vendorId;
m_isVendorIDUpdated = true;
}
void update ( const Version &version ) {
m_cecVersion = version;
m_isVersionUpdated = true;
}
void update ( const OSDName &osdName ) {
m_osdName = osdName;
m_isOSDNameUpdated = true;
}
void update ( const PowerStatus &status ) {
m_powerStatus = status;
m_isPowerStatusUpdated = true;
m_lastPowerUpdateTime = std::chrono::system_clock::now();
}
};
class DeviceNode {
public:
uint8_t m_childsLogicalAddr[LogicalAddress::UNREGISTERED];
DeviceNode() {
int i;
for (i; i < LogicalAddress::UNREGISTERED; i++ )
{
m_childsLogicalAddr[i] = LogicalAddress::UNREGISTERED;
}
}
} ;
class HdmiPortMap {
public:
uint8_t m_portID;
bool m_isConnected;
LogicalAddress m_logicalAddr;
PhysicalAddress m_physicalAddr;
DeviceNode m_deviceChain[3];
HdmiPortMap(uint8_t portID) : m_portID(portID), m_physicalAddr(portID+1,0,0,0),m_logicalAddr(LogicalAddress::UNREGISTERED)
{
m_isConnected = false;
}
void update(bool isConnected)
{
m_isConnected = isConnected;
}
void update( const LogicalAddress &addr )
{
m_logicalAddr = addr;
}
void addChild( const LogicalAddress &logical_addr, const PhysicalAddress &physical_addr )
{
LOGINFO(" logicalAddr = %d, phisicalAddr = %s", m_logicalAddr.toInt(), physical_addr.toString().c_str());
if ( m_logicalAddr.toInt() != LogicalAddress::UNREGISTERED &&
m_logicalAddr.toInt() != logical_addr.toInt() )
{
LOGINFO(" update own logicalAddr = %d, new devcie logicalAddress", m_logicalAddr.toInt(), logical_addr.toInt() );
/* check matching with this port's physical address */
if( physical_addr.getByteValue(0) == m_physicalAddr.getByteValue(0) &&
physical_addr.getByteValue(1) != 0 )
{
if ( physical_addr.getByteValue(3) != 0 )
{
m_deviceChain[2].m_childsLogicalAddr[physical_addr.getByteValue(3) - 1] = logical_addr.toInt();
}
else if ( physical_addr.getByteValue(2) != 0 )
{
m_deviceChain[1].m_childsLogicalAddr[physical_addr.getByteValue(2) - 1] = logical_addr.toInt();
}
else if ( physical_addr.getByteValue(1) != 0 )
{
m_deviceChain[0].m_childsLogicalAddr[physical_addr.getByteValue(1) - 1] = logical_addr.toInt();
}
}
}
else if ( physical_addr == m_physicalAddr )
{
update(logical_addr);
LOGINFO(" update own logicalAddr = %d", m_logicalAddr.toInt());
}
}
void removeChild( PhysicalAddress &physical_addr )
{
if ( m_logicalAddr.toInt() != LogicalAddress::UNREGISTERED )
{
/* check matching with this port's physical address */
if( physical_addr.getByteValue(0) == m_physicalAddr.getByteValue(0) &&
physical_addr.getByteValue(1) != 0 )
{
if ( physical_addr.getByteValue(3) != 0 )
{
m_deviceChain[2].m_childsLogicalAddr[physical_addr.getByteValue(3) - 1] = LogicalAddress::UNREGISTERED;
}
else if ( physical_addr.getByteValue(2) != 0 )
{
m_deviceChain[1].m_childsLogicalAddr[physical_addr.getByteValue(2) - 1] = LogicalAddress::UNREGISTERED;
}
else if ( physical_addr.getByteValue(1) != 0 )
{
m_deviceChain[0].m_childsLogicalAddr[physical_addr.getByteValue(1) - 1] = LogicalAddress::UNREGISTERED;
}
}
}
}
void getRoute( PhysicalAddress &physical_addr, std::vector<uint8_t> & route )
{
LOGINFO(" logicalAddr = %d, phsical = %s", m_logicalAddr.toInt(), physical_addr.toString().c_str());
if ( m_logicalAddr.toInt() != LogicalAddress::UNREGISTERED )
{
LOGINFO(" search for logicalAddr = %d", m_logicalAddr.toInt());
/* check matching with this port's physical address */
if( physical_addr.getByteValue(0) == m_physicalAddr.getByteValue(0) &&
physical_addr.getByteValue(1) != 0 )
{
if ( physical_addr.getByteValue(3) != 0 )
{
route.push_back(m_deviceChain[2].m_childsLogicalAddr[physical_addr.getByteValue(3) - 1]);
}
if ( physical_addr.getByteValue(2) != 0 )
{
route.push_back(m_deviceChain[1].m_childsLogicalAddr[physical_addr.getByteValue(2) - 1]);
}
if ( physical_addr.getByteValue(1) != 0 )
{
route.push_back(m_deviceChain[0].m_childsLogicalAddr[physical_addr.getByteValue(1) - 1]);
}
route.push_back(m_logicalAddr.toInt());
}
else
{
route.push_back(m_logicalAddr.toInt());
LOGINFO("logicalAddr = %d, physical = %s", m_logicalAddr.toInt(), m_physicalAddr.toString().c_str());
}
}
}
};
// This is a server for a JSONRPC communication channel.
// For a plugin to be capable to handle JSONRPC, inherit from PluginHost::JSONRPC.
// By inheriting from this class, the plugin realizes the interface PluginHost::IDispatcher.
// This realization of this interface implements, by default, the following methods on this plugin
// - exists
// - register
// - unregister
// Any other methood to be handled by this plugin can be added can be added by using the
// templated methods Register on the PluginHost::JSONRPC class.
// As the registration/unregistration of notifications is realized by the class PluginHost::JSONRPC,
// this class exposes a public method called, Notify(), using this methods, all subscribed clients
// will receive a JSONRPC message as a notification, in case this method is called.
class HdmiCecSink : public AbstractPlugin {
enum {
POLL_THREAD_STATE_NONE,
POLL_THREAD_STATE_IDLE,
POLL_THREAD_STATE_POLL,
POLL_THREAD_STATE_PING,
POLL_THREAD_STATE_INFO,
POLL_THREAD_STATE_WAIT,
POLL_THREAD_STATE_CLEAN,
POLL_THREAD_STATE_UPDATE,
POLL_THREAD_STATE_EXIT,
};
public:
HdmiCecSink();
virtual ~HdmiCecSink();
static HdmiCecSink* _instance;
CECDeviceParams deviceList[16];
std::vector<HdmiPortMap> hdmiInputs;
int m_currentActiveSource;
void updateInActiveSource(const int logical_address, const InActiveSource &source );
void updateActiveSource(const int logical_address, const ActiveSource &source );
void updateTextViewOn(const int logicalAddress);
void updateImageViewOn(const int logicalAddress);
void updateDeviceChain(const LogicalAddress &logicalAddress, const PhysicalAddress &phy_addr);
void getActiveRoute(const LogicalAddress &logicalAddress, std::vector<uint8_t> &route);
void removeDevice(const int logicalAddress);
void addDevice(const int logicalAddress);
void printDeviceList();
void setStreamPath( const PhysicalAddress &physical_addr);
void setRoutingChange(const std::string &from, const std::string &to);
void setCurrentLanguage(const Language &lang);
void sendMenuLanguage();
void setActiveSource(bool isResponse);
void requestActiveSource();
int m_numberOfDevices; /* Number of connected devices othethan own device */
private:
// We do not allow this plugin to be copied !!
HdmiCecSink(const HdmiCecSink&) = delete;
HdmiCecSink& operator=(const HdmiCecSink&) = delete;
//Begin methods
uint32_t setEnabledWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getEnabledWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setOSDNameWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getOSDNameWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setVendorIdWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getVendorIdWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t printDeviceListWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setActivePathWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setRoutingChangeWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getDeviceListWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getActiveSourceWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setActiveSourceWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t getActiveRouteWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t requestActiveSourceWrapper(const JsonObject& parameters, JsonObject& response);
uint32_t setMenuLanguageWrapper(const JsonObject& parameters, JsonObject& response);
//End methods
std::string logicalAddressDeviceType;
bool cecSettingEnabled;
bool cecOTPSettingEnabled;
bool cecEnableStatus;
bool m_isHdmiInConnected;
int m_numofHdmiInput;
uint8_t m_deviceType;
int m_logicalAddressAllocated;
std::thread m_pollThread;
uint32_t m_pollThreadState;
uint32_t m_pollNextState;
uint32_t m_sleepTime;
std::mutex m_pollMutex;
Connection *smConnection;
std::vector<uint8_t> m_connectedDevices;
HdmiCecSinkProcessor *msgProcessor;
HdmiCecSinkFrameListener *msgFrameListener;
const void InitializeIARM();
void DeinitializeIARM();
void allocateLogicalAddress(int deviceType);
void allocateLAforTV();
void pingDevices(std::vector<int> &connected , std::vector<int> &disconnected);
void CheckHdmiInState();
void request(const int logicalAddress);
int requestType(const int logicalAddress);
int requestStatus(const int logicalAddress);
void requestPowerStatus(const int logicalAddress);
static void threadRun();
void cecMonitoringThread();
static void cecMgrEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
static void dsHdmiEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
static void pwrMgrModeChangeEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
void onCECDaemonInit();
void cecStatusUpdated(void *evtStatus);
void onHdmiHotPlug(int connectStatus);
void onPowerStateON();
bool loadSettings();
void persistSettings(bool enableStatus);
void persistOTPSettings(bool enableStatus);
void persistOSDName(const char *name);
void persistVendorId(unsigned int vendorID);
void setEnabled(bool enabled);
bool getEnabled();
void CECEnable(void);
void CECDisable(void);
void getPhysicalAddress();
void getLogicalAddress();
void cecAddressesChanged(int changeStatus);
};
} // namespace Plugin
} // namespace WPEFramework