changelog updated for release v0.4.3
[deb_libcec.git] / src / lib / CECProcessor.cpp
CommitLineData
abbca718
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
2abe74eb 33#include "CECProcessor.h"
abbca718 34
2abe74eb
LOK
35#include "AdapterCommunication.h"
36#include "LibCEC.h"
abbca718 37#include "util/StdString.h"
b9187cc6 38#include "platform/timeutils.h"
abbca718
LOK
39
40using namespace CEC;
41using namespace std;
42
2b4d8297 43CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
df7339c6
LOK
44 m_physicaladdress(iPhysicalAddress),
45 m_iLogicalAddress(iLogicalAddress),
2abe74eb
LOK
46 m_strDeviceName(strDeviceName),
47 m_communication(serComm),
48 m_controller(controller)
abbca718 49{
abbca718
LOK
50}
51
2abe74eb 52CCECProcessor::~CCECProcessor(void)
abbca718 53{
2abe74eb
LOK
54 StopThread();
55 m_communication = NULL;
56 m_controller = NULL;
abbca718
LOK
57}
58
2abe74eb 59bool CCECProcessor::Start(void)
abbca718 60{
2abe74eb 61 if (!m_communication || !m_communication->IsOpen())
a8f0bd18 62 return false;
abbca718 63
a8f0bd18 64 if (!SetLogicalAddress(m_iLogicalAddress))
abbca718 65 {
2abe74eb 66 m_controller->AddLog(CEC_LOG_ERROR, "could not set the logical address");
a8f0bd18 67 return false;
abbca718
LOK
68 }
69
60fa4578 70 if (CreateThread())
a8f0bd18 71 return true;
a8f0bd18 72 else
2abe74eb 73 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
abbca718 74
a8f0bd18 75 return false;
abbca718
LOK
76}
77
2abe74eb 78void *CCECProcessor::Process(void)
f99bc831 79{
2abe74eb 80 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
abbca718 81
60fa4578 82 while (!m_bStop)
abbca718 83 {
60fa4578
LOK
84 bool bParseFrame(false);
85 {
86 CLockObject lock(&m_mutex);
87 cec_frame msg;
88 if (!m_bStop && m_communication->IsOpen() && m_communication->Read(msg, CEC_BUTTON_TIMEOUT))
89 bParseFrame = ParseMessage(msg);
90 }
91
f7e6ba70 92 if (!m_bStop && bParseFrame)
60fa4578 93 ParseCurrentFrame();
abbca718 94
f7e6ba70
LOK
95 if (!m_bStop)
96 {
97 m_controller->CheckKeypressTimeout();
12027dbe 98 Sleep(50);
f7e6ba70 99 }
abbca718
LOK
100 }
101
60fa4578 102 return NULL;
abbca718
LOK
103}
104
2abe74eb 105bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
abbca718 106{
60fa4578 107 if (!IsRunning())
f99bc831
LOK
108 return false;
109
abbca718
LOK
110 CStdString strLog;
111 strLog.Format("powering on devices with logical address %d", (int8_t)address);
2abe74eb 112 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
113 cec_frame frame;
114 frame.push_back(GetSourceDestination(address));
8bca69de 115 frame.push_back((uint8_t) CEC_OPCODE_TEXT_VIEW_ON);
abbca718
LOK
116 return Transmit(frame);
117}
118
2abe74eb 119bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
abbca718 120{
60fa4578 121 if (!IsRunning())
f99bc831
LOK
122 return false;
123
abbca718
LOK
124 CStdString strLog;
125 strLog.Format("putting all devices with logical address %d in standby mode", (int8_t)address);
2abe74eb 126 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
127 cec_frame frame;
128 frame.push_back(GetSourceDestination(address));
8bca69de 129 frame.push_back((uint8_t) CEC_OPCODE_STANDBY);
abbca718
LOK
130 return Transmit(frame);
131}
132
2abe74eb 133bool CCECProcessor::SetActiveView(void)
abbca718 134{
60fa4578 135 if (!IsRunning())
f99bc831
LOK
136 return false;
137
2abe74eb 138 m_controller->AddLog(CEC_LOG_DEBUG, "setting active view");
abbca718
LOK
139 cec_frame frame;
140 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
8bca69de 141 frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE);
abbca718
LOK
142 frame.push_back((m_physicaladdress >> 8) & 0xFF);
143 frame.push_back(m_physicaladdress & 0xFF);
144 return Transmit(frame);
145}
146
2abe74eb 147bool CCECProcessor::SetInactiveView(void)
abbca718 148{
60fa4578 149 if (!IsRunning())
f99bc831
LOK
150 return false;
151
2abe74eb 152 m_controller->AddLog(CEC_LOG_DEBUG, "setting inactive view");
abbca718
LOK
153 cec_frame frame;
154 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
8bca69de 155 frame.push_back((uint8_t) CEC_OPCODE_INACTIVE_SOURCE);
abbca718
LOK
156 frame.push_back((m_physicaladdress >> 8) & 0xFF);
157 frame.push_back(m_physicaladdress & 0xFF);
158 return Transmit(frame);
159}
160
2abe74eb 161bool CCECProcessor::Transmit(const cec_frame &data, bool bWaitForAck /* = true */)
abbca718 162{
2abe74eb
LOK
163 CStdString txStr = "transmit ";
164 for (unsigned int i = 0; i < data.size(); i++)
165 txStr.AppendFormat(" %02x", data[i]);
166 m_controller->AddLog(CEC_LOG_DEBUG, txStr.c_str());
167
168 if (data.empty())
169 {
170 m_controller->AddLog(CEC_LOG_WARNING, "transmit buffer is empty");
171 return false;
172 }
173
174 cec_frame output;
175
176 //set ack polarity to high when transmitting to the broadcast address
177 //set ack polarity low when transmitting to any other address
178 output.push_back(MSGSTART);
179 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT_ACK_POLARITY);
180
181 if ((data[0] & 0xF) == 0xF)
182 CAdapterCommunication::PushEscaped(output, CEC_TRUE);
183 else
184 CAdapterCommunication::PushEscaped(output, CEC_FALSE);
185
186 output.push_back(MSGEND);
187
188 for (unsigned int i = 0; i < data.size(); i++)
189 {
190 output.push_back(MSGSTART);
191
192 if (i == data.size() - 1)
193 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT_EOM);
194 else
195 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT);
196
197 CAdapterCommunication::PushEscaped(output, data[i]);
198
199 output.push_back(MSGEND);
200 }
201
202 return TransmitFormatted(output, bWaitForAck);
abbca718
LOK
203}
204
2abe74eb 205bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
abbca718 206{
2abe74eb
LOK
207 CStdString strLog;
208 strLog.Format("setting logical address to %d", iLogicalAddress);
209 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
210
211 m_iLogicalAddress = iLogicalAddress;
212 return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
abbca718 213}
825ddb96 214
2abe74eb 215bool CCECProcessor::TransmitFormatted(const cec_frame &data, bool bWaitForAck /* = true */)
825ddb96 216{
2abe74eb
LOK
217 CLockObject lock(&m_mutex);
218 if (!m_communication || !m_communication->Write(data))
219 return false;
220
221 if (bWaitForAck && !WaitForAck())
222 {
223 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ACK");
224 return false;
225 }
226
227 return true;
825ddb96 228}
abbca718 229
2abe74eb 230void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
abbca718 231{
2abe74eb 232 m_controller->AddLog(CEC_LOG_DEBUG, "transmitting abort message");
abbca718
LOK
233 cec_frame frame;
234 frame.push_back(GetSourceDestination(address));
8bca69de
LOK
235 frame.push_back((uint8_t) CEC_OPCODE_FEATURE_ABORT);
236 frame.push_back((uint8_t) opcode);
237 frame.push_back((uint8_t) reason);
abbca718
LOK
238 Transmit(frame);
239}
240
2abe74eb 241void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_TV */)
abbca718
LOK
242{
243 cec_frame frame;
2abe74eb 244 m_controller->AddLog(CEC_LOG_NOTICE, "reporting CEC version as 1.3a");
abbca718 245 frame.push_back(GetSourceDestination(address));
8bca69de 246 frame.push_back((uint8_t) CEC_OPCODE_CEC_VERSION);
abbca718
LOK
247 frame.push_back(CEC_VERSION_1_3A);
248 Transmit(frame);
249}
250
2abe74eb 251void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_TV */, bool bOn /* = true */)
abbca718
LOK
252{
253 cec_frame frame;
254 if (bOn)
2abe74eb 255 m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"On\" power status");
abbca718 256 else
2abe74eb 257 m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"Off\" power status");
abbca718
LOK
258
259 frame.push_back(GetSourceDestination(address));
8bca69de
LOK
260 frame.push_back((uint8_t) CEC_OPCODE_REPORT_POWER_STATUS);
261 frame.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY);
abbca718
LOK
262 Transmit(frame);
263}
264
2abe74eb 265void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_TV */, bool bActive /* = true */)
abbca718
LOK
266{
267 cec_frame frame;
268 if (bActive)
2abe74eb 269 m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as active");
abbca718 270 else
2abe74eb 271 m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as inactive");
abbca718
LOK
272
273 frame.push_back(GetSourceDestination(address));
8bca69de
LOK
274 frame.push_back((uint8_t) CEC_OPCODE_MENU_STATUS);
275 frame.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED);
abbca718
LOK
276 Transmit(frame);
277}
278
2abe74eb 279void CCECProcessor::ReportVendorID(cec_logical_address address /* = CECDEVICE_TV */)
abbca718 280{
2abe74eb 281 m_controller->AddLog(CEC_LOG_NOTICE, "vendor ID requested, feature abort");
abbca718
LOK
282 TransmitAbort(address, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
283}
284
2abe74eb 285void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV */)
abbca718
LOK
286{
287 cec_frame frame;
288 const char *osdname = m_strDeviceName.c_str();
289 CStdString strLog;
290 strLog.Format("reporting OSD name as %s", osdname);
2abe74eb 291 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
abbca718 292 frame.push_back(GetSourceDestination(address));
8bca69de 293 frame.push_back((uint8_t) CEC_OPCODE_SET_OSD_NAME);
abbca718
LOK
294
295 for (unsigned int i = 0; i < strlen(osdname); i++)
296 frame.push_back(osdname[i]);
297
298 Transmit(frame);
299}
300
2abe74eb 301void CCECProcessor::ReportPhysicalAddress(void)
abbca718
LOK
302{
303 cec_frame frame;
304 CStdString strLog;
305 strLog.Format("reporting physical address as %04x", m_physicaladdress);
2abe74eb 306 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
abbca718 307 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
8bca69de 308 frame.push_back((uint8_t) CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
abbca718
LOK
309 frame.push_back((m_physicaladdress >> 8) & 0xFF);
310 frame.push_back(m_physicaladdress & 0xFF);
311 frame.push_back(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
312 Transmit(frame);
313}
314
2abe74eb 315void CCECProcessor::BroadcastActiveSource(void)
abbca718
LOK
316{
317 cec_frame frame;
2abe74eb 318 m_controller->AddLog(CEC_LOG_NOTICE, "broadcasting active source");
abbca718 319 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
8bca69de 320 frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE);
abbca718
LOK
321 frame.push_back((m_physicaladdress >> 8) & 0xFF);
322 frame.push_back(m_physicaladdress & 0xFF);
323 Transmit(frame);
324}
325
2abe74eb 326uint8_t CCECProcessor::GetSourceDestination(cec_logical_address destination /* = CECDEVICE_BROADCAST */) const
abbca718 327{
2abe74eb 328 return ((uint8_t)m_iLogicalAddress << 4) + (uint8_t)destination;
abbca718
LOK
329}
330
2abe74eb 331bool CCECProcessor::WaitForAck(int iTimeout /* = 1000 */)
abbca718
LOK
332{
333 bool bGotAck(false);
334 bool bError(false);
335
336 int64_t iNow = GetTimeMs();
390b42d6 337 int64_t iTargetTime = iNow + (int64_t) iTimeout;
abbca718
LOK
338
339 while (!bGotAck && !bError && (iTimeout <= 0 || iNow < iTargetTime))
340 {
abbca718 341 cec_frame msg;
a8f0bd18 342 while (!bGotAck && !bError && m_communication->Read(msg, iTimeout))
abbca718
LOK
343 {
344 uint8_t iCode = msg[0] & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK);
345
346 switch (iCode)
347 {
348 case MSGCODE_COMMAND_ACCEPTED:
2abe74eb 349 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED");
abbca718
LOK
350 break;
351 case MSGCODE_TRANSMIT_SUCCEEDED:
2abe74eb 352 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED");
abbca718
LOK
353 // TODO
354 bGotAck = true;
355 break;
356 case MSGCODE_RECEIVE_FAILED:
2abe74eb 357 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED");
abbca718
LOK
358 bError = true;
359 break;
360 case MSGCODE_COMMAND_REJECTED:
2abe74eb 361 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED");
abbca718
LOK
362 bError = true;
363 break;
364 case MSGCODE_TRANSMIT_FAILED_LINE:
2abe74eb 365 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE");
abbca718
LOK
366 bError = true;
367 break;
368 case MSGCODE_TRANSMIT_FAILED_ACK:
2abe74eb 369 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK");
abbca718
LOK
370 bError = true;
371 break;
372 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
2abe74eb 373 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA");
abbca718
LOK
374 bError = true;
375 break;
376 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
2abe74eb 377 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE");
abbca718
LOK
378 bError = true;
379 break;
380 default:
381 m_frameBuffer.Push(msg);
382 bGotAck = (msg[0] & MSGCODE_FRAME_ACK) != 0;
383 break;
384 }
385 iNow = GetTimeMs();
386 }
387 }
388
389 return bGotAck && !bError;
390}
391
2abe74eb 392bool CCECProcessor::ParseMessage(cec_frame &msg)
abbca718 393{
60fa4578
LOK
394 bool bReturn(false);
395
abbca718 396 if (msg.empty())
60fa4578 397 return bReturn;
abbca718
LOK
398
399 CStdString logStr;
400 uint8_t iCode = msg[0] & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK);
401 bool bEom = (msg[0] & MSGCODE_FRAME_EOM) != 0;
402 bool bAck = (msg[0] & MSGCODE_FRAME_ACK) != 0;
403
404 switch(iCode)
405 {
406 case MSGCODE_NOTHING:
2abe74eb 407 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING");
abbca718
LOK
408 break;
409 case MSGCODE_TIMEOUT_ERROR:
410 case MSGCODE_HIGH_ERROR:
411 case MSGCODE_LOW_ERROR:
412 {
413 if (iCode == MSGCODE_TIMEOUT_ERROR)
414 logStr = "MSGCODE_TIMEOUT";
415 else if (iCode == MSGCODE_HIGH_ERROR)
416 logStr = "MSGCODE_HIGH_ERROR";
417 else
418 logStr = "MSGCODE_LOW_ERROR";
419
420 int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0;
421 uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0;
422 logStr.AppendFormat(" line:%i", iLine);
423 logStr.AppendFormat(" time:%u", iTime);
2abe74eb 424 m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str());
abbca718
LOK
425 }
426 break;
427 case MSGCODE_FRAME_START:
428 {
429 logStr = "MSGCODE_FRAME_START";
430 m_currentframe.clear();
431 if (msg.size() >= 2)
432 {
433 int iInitiator = msg[1] >> 4;
434 int iDestination = msg[1] & 0xF;
435 logStr.AppendFormat(" initiator:%u destination:%u ack:%s %s", iInitiator, iDestination, bAck ? "high" : "low", bEom ? "eom" : "");
436
437 m_currentframe.push_back(msg[1]);
438 }
2abe74eb 439 m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str());
abbca718
LOK
440 }
441 break;
442 case MSGCODE_FRAME_DATA:
443 {
444 logStr = "MSGCODE_FRAME_DATA";
445 if (msg.size() >= 2)
446 {
447 uint8_t iData = msg[1];
448 logStr.AppendFormat(" %02x", iData);
449 m_currentframe.push_back(iData);
450 }
2abe74eb 451 m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str());
abbca718
LOK
452 }
453 if (bEom)
60fa4578 454 bReturn = true;
abbca718
LOK
455 break;
456 default:
457 break;
458 }
60fa4578
LOK
459
460 return bReturn;
abbca718
LOK
461}
462
2abe74eb 463void CCECProcessor::ParseCurrentFrame(void)
abbca718
LOK
464{
465 uint8_t initiator = m_currentframe[0] >> 4;
466 uint8_t destination = m_currentframe[0] & 0xF;
467
468 CStdString dataStr;
469 dataStr.Format("received frame: initiator: %u destination: %u", initiator, destination);
470
471 if (m_currentframe.size() > 1)
472 {
473 dataStr += " data:";
474 for (unsigned int i = 1; i < m_currentframe.size(); i++)
475 dataStr.AppendFormat(" %02x", m_currentframe[i]);
476 }
2abe74eb 477 m_controller->AddLog(CEC_LOG_DEBUG, dataStr.c_str());
abbca718
LOK
478
479 if (m_currentframe.size() <= 1)
480 return;
481
482 vector<uint8_t> tx;
825ddb96 483 cec_opcode opCode = (cec_opcode) m_currentframe[1];
abbca718
LOK
484 if (destination == (uint16_t) m_iLogicalAddress)
485 {
486 switch(opCode)
487 {
488 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
489 ReportPhysicalAddress();
490 SetActiveView();
491 break;
492 case CEC_OPCODE_GIVE_OSD_NAME:
493 ReportOSDName((cec_logical_address)initiator);
494 break;
495 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
496 ReportVendorID((cec_logical_address)initiator);
497 break;
498 case CEC_OPCODE_MENU_REQUEST:
499 ReportMenuState((cec_logical_address)initiator);
500 break;
501 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
502 ReportPowerState((cec_logical_address)initiator);
503 break;
504 case CEC_OPCODE_GET_CEC_VERSION:
505 ReportCECVersion((cec_logical_address)initiator);
506 break;
507 case CEC_OPCODE_USER_CONTROL_PRESSED:
508 if (m_currentframe.size() > 2)
509 {
2abe74eb 510 m_controller->AddKey();
abbca718
LOK
511
512 if (m_currentframe[2] <= CEC_USER_CONTROL_CODE_MAX)
2abe74eb 513 m_controller->SetCurrentButton((cec_user_control_code) m_currentframe[2]);
abbca718
LOK
514 }
515 break;
516 case CEC_OPCODE_USER_CONTROL_RELEASE:
2abe74eb 517 m_controller->AddKey();
abbca718
LOK
518 break;
519 default:
825ddb96
LOK
520 cec_frame params = m_currentframe;
521 params.erase(params.begin(), params.begin() + 2);
2abe74eb 522 m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
abbca718
LOK
523 break;
524 }
525 }
526 else if (destination == (uint8_t) CECDEVICE_BROADCAST)
527 {
528 if (opCode == CEC_OPCODE_REQUEST_ACTIVE_SOURCE)
529 {
530 BroadcastActiveSource();
531 }
532 else if (opCode == CEC_OPCODE_SET_STREAM_PATH)
533 {
534 if (m_currentframe.size() >= 4)
535 {
536 int streamaddr = ((int)m_currentframe[2] << 8) | ((int)m_currentframe[3]);
537 CStdString strLog;
538 strLog.Format("%i requests stream path from physical address %04x", initiator, streamaddr);
2abe74eb 539 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
540 if (streamaddr == m_physicaladdress)
541 BroadcastActiveSource();
542 }
543 }
c49c485b
LOK
544 else
545 {
546 cec_frame params = m_currentframe;
547 params.erase(params.begin(), params.begin() + 2);
2abe74eb 548 m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
c49c485b 549 }
abbca718
LOK
550 }
551 else
552 {
553 CStdString strLog;
554 strLog.Format("ignoring frame: destination: %u != %u", destination, (uint16_t)m_iLogicalAddress);
2abe74eb 555 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
556 }
557}