renamed libPlatform -> platform. stuck everything from libCEC in the CEC namespace...
[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
2abe74eb 43CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int 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
92 if (bParseFrame)
93 ParseCurrentFrame();
abbca718 94
2abe74eb 95 m_controller->CheckKeypressTimeout();
abbca718
LOK
96 CCondition::Sleep(50);
97 }
98
2abe74eb 99 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread terminated");
60fa4578 100 return NULL;
abbca718
LOK
101}
102
2abe74eb 103bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */)
abbca718 104{
60fa4578 105 if (!IsRunning())
f99bc831
LOK
106 return false;
107
abbca718
LOK
108 CStdString strLog;
109 strLog.Format("powering on devices with logical address %d", (int8_t)address);
2abe74eb 110 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
111 cec_frame frame;
112 frame.push_back(GetSourceDestination(address));
113 frame.push_back(CEC_OPCODE_TEXT_VIEW_ON);
114 return Transmit(frame);
115}
116
2abe74eb 117bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
abbca718 118{
60fa4578 119 if (!IsRunning())
f99bc831
LOK
120 return false;
121
abbca718
LOK
122 CStdString strLog;
123 strLog.Format("putting all devices with logical address %d in standby mode", (int8_t)address);
2abe74eb 124 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
125 cec_frame frame;
126 frame.push_back(GetSourceDestination(address));
127 frame.push_back(CEC_OPCODE_STANDBY);
128 return Transmit(frame);
129}
130
2abe74eb 131bool CCECProcessor::SetActiveView(void)
abbca718 132{
60fa4578 133 if (!IsRunning())
f99bc831
LOK
134 return false;
135
2abe74eb 136 m_controller->AddLog(CEC_LOG_DEBUG, "setting active view");
abbca718
LOK
137 cec_frame frame;
138 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
139 frame.push_back(CEC_OPCODE_ACTIVE_SOURCE);
140 frame.push_back((m_physicaladdress >> 8) & 0xFF);
141 frame.push_back(m_physicaladdress & 0xFF);
142 return Transmit(frame);
143}
144
2abe74eb 145bool CCECProcessor::SetInactiveView(void)
abbca718 146{
60fa4578 147 if (!IsRunning())
f99bc831
LOK
148 return false;
149
2abe74eb 150 m_controller->AddLog(CEC_LOG_DEBUG, "setting inactive view");
abbca718
LOK
151 cec_frame frame;
152 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
153 frame.push_back(CEC_OPCODE_INACTIVE_SOURCE);
154 frame.push_back((m_physicaladdress >> 8) & 0xFF);
155 frame.push_back(m_physicaladdress & 0xFF);
156 return Transmit(frame);
157}
158
2abe74eb 159bool CCECProcessor::Transmit(const cec_frame &data, bool bWaitForAck /* = true */)
abbca718 160{
2abe74eb
LOK
161 CStdString txStr = "transmit ";
162 for (unsigned int i = 0; i < data.size(); i++)
163 txStr.AppendFormat(" %02x", data[i]);
164 m_controller->AddLog(CEC_LOG_DEBUG, txStr.c_str());
165
166 if (data.empty())
167 {
168 m_controller->AddLog(CEC_LOG_WARNING, "transmit buffer is empty");
169 return false;
170 }
171
172 cec_frame output;
173
174 //set ack polarity to high when transmitting to the broadcast address
175 //set ack polarity low when transmitting to any other address
176 output.push_back(MSGSTART);
177 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT_ACK_POLARITY);
178
179 if ((data[0] & 0xF) == 0xF)
180 CAdapterCommunication::PushEscaped(output, CEC_TRUE);
181 else
182 CAdapterCommunication::PushEscaped(output, CEC_FALSE);
183
184 output.push_back(MSGEND);
185
186 for (unsigned int i = 0; i < data.size(); i++)
187 {
188 output.push_back(MSGSTART);
189
190 if (i == data.size() - 1)
191 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT_EOM);
192 else
193 CAdapterCommunication::PushEscaped(output, MSGCODE_TRANSMIT);
194
195 CAdapterCommunication::PushEscaped(output, data[i]);
196
197 output.push_back(MSGEND);
198 }
199
200 return TransmitFormatted(output, bWaitForAck);
abbca718
LOK
201}
202
2abe74eb 203bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
abbca718 204{
2abe74eb
LOK
205 CStdString strLog;
206 strLog.Format("setting logical address to %d", iLogicalAddress);
207 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
208
209 m_iLogicalAddress = iLogicalAddress;
210 return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress);
abbca718 211}
825ddb96 212
2abe74eb 213bool CCECProcessor::TransmitFormatted(const cec_frame &data, bool bWaitForAck /* = true */)
825ddb96 214{
2abe74eb
LOK
215 CLockObject lock(&m_mutex);
216 if (!m_communication || !m_communication->Write(data))
217 return false;
218
219 if (bWaitForAck && !WaitForAck())
220 {
221 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ACK");
222 return false;
223 }
224
225 return true;
825ddb96 226}
abbca718 227
2abe74eb 228void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
abbca718 229{
2abe74eb 230 m_controller->AddLog(CEC_LOG_DEBUG, "transmitting abort message");
abbca718
LOK
231 cec_frame frame;
232 frame.push_back(GetSourceDestination(address));
233 frame.push_back(CEC_OPCODE_FEATURE_ABORT);
234 frame.push_back(opcode);
235 frame.push_back(reason);
236 Transmit(frame);
237}
238
2abe74eb 239void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_TV */)
abbca718
LOK
240{
241 cec_frame frame;
2abe74eb 242 m_controller->AddLog(CEC_LOG_NOTICE, "reporting CEC version as 1.3a");
abbca718
LOK
243 frame.push_back(GetSourceDestination(address));
244 frame.push_back(CEC_OPCODE_CEC_VERSION);
245 frame.push_back(CEC_VERSION_1_3A);
246 Transmit(frame);
247}
248
2abe74eb 249void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_TV */, bool bOn /* = true */)
abbca718
LOK
250{
251 cec_frame frame;
252 if (bOn)
2abe74eb 253 m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"On\" power status");
abbca718 254 else
2abe74eb 255 m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"Off\" power status");
abbca718
LOK
256
257 frame.push_back(GetSourceDestination(address));
258 frame.push_back(CEC_OPCODE_REPORT_POWER_STATUS);
259 frame.push_back(bOn ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY);
260 Transmit(frame);
261}
262
2abe74eb 263void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_TV */, bool bActive /* = true */)
abbca718
LOK
264{
265 cec_frame frame;
266 if (bActive)
2abe74eb 267 m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as active");
abbca718 268 else
2abe74eb 269 m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as inactive");
abbca718
LOK
270
271 frame.push_back(GetSourceDestination(address));
272 frame.push_back(CEC_OPCODE_MENU_STATUS);
273 frame.push_back(bActive ? CEC_MENU_STATE_ACTIVATED : CEC_MENU_STATE_DEACTIVATED);
274 Transmit(frame);
275}
276
2abe74eb 277void CCECProcessor::ReportVendorID(cec_logical_address address /* = CECDEVICE_TV */)
abbca718 278{
2abe74eb 279 m_controller->AddLog(CEC_LOG_NOTICE, "vendor ID requested, feature abort");
abbca718
LOK
280 TransmitAbort(address, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
281}
282
2abe74eb 283void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV */)
abbca718
LOK
284{
285 cec_frame frame;
286 const char *osdname = m_strDeviceName.c_str();
287 CStdString strLog;
288 strLog.Format("reporting OSD name as %s", osdname);
2abe74eb 289 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
abbca718
LOK
290 frame.push_back(GetSourceDestination(address));
291 frame.push_back(CEC_OPCODE_SET_OSD_NAME);
292
293 for (unsigned int i = 0; i < strlen(osdname); i++)
294 frame.push_back(osdname[i]);
295
296 Transmit(frame);
297}
298
2abe74eb 299void CCECProcessor::ReportPhysicalAddress(void)
abbca718
LOK
300{
301 cec_frame frame;
302 CStdString strLog;
303 strLog.Format("reporting physical address as %04x", m_physicaladdress);
2abe74eb 304 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
abbca718
LOK
305 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
306 frame.push_back(CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
307 frame.push_back((m_physicaladdress >> 8) & 0xFF);
308 frame.push_back(m_physicaladdress & 0xFF);
309 frame.push_back(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
310 Transmit(frame);
311}
312
2abe74eb 313void CCECProcessor::BroadcastActiveSource(void)
abbca718
LOK
314{
315 cec_frame frame;
2abe74eb 316 m_controller->AddLog(CEC_LOG_NOTICE, "broadcasting active source");
abbca718
LOK
317 frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST));
318 frame.push_back(CEC_OPCODE_ACTIVE_SOURCE);
319 frame.push_back((m_physicaladdress >> 8) & 0xFF);
320 frame.push_back(m_physicaladdress & 0xFF);
321 Transmit(frame);
322}
323
2abe74eb 324uint8_t CCECProcessor::GetSourceDestination(cec_logical_address destination /* = CECDEVICE_BROADCAST */) const
abbca718 325{
2abe74eb 326 return ((uint8_t)m_iLogicalAddress << 4) + (uint8_t)destination;
abbca718
LOK
327}
328
2abe74eb 329bool CCECProcessor::WaitForAck(int iTimeout /* = 1000 */)
abbca718
LOK
330{
331 bool bGotAck(false);
332 bool bError(false);
333
334 int64_t iNow = GetTimeMs();
390b42d6 335 int64_t iTargetTime = iNow + (int64_t) iTimeout;
abbca718
LOK
336
337 while (!bGotAck && !bError && (iTimeout <= 0 || iNow < iTargetTime))
338 {
abbca718 339 cec_frame msg;
a8f0bd18 340 while (!bGotAck && !bError && m_communication->Read(msg, iTimeout))
abbca718
LOK
341 {
342 uint8_t iCode = msg[0] & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK);
343
344 switch (iCode)
345 {
346 case MSGCODE_COMMAND_ACCEPTED:
2abe74eb 347 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_COMMAND_ACCEPTED");
abbca718
LOK
348 break;
349 case MSGCODE_TRANSMIT_SUCCEEDED:
2abe74eb 350 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_TRANSMIT_SUCCEEDED");
abbca718
LOK
351 // TODO
352 bGotAck = true;
353 break;
354 case MSGCODE_RECEIVE_FAILED:
2abe74eb 355 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_RECEIVE_FAILED");
abbca718
LOK
356 bError = true;
357 break;
358 case MSGCODE_COMMAND_REJECTED:
2abe74eb 359 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_COMMAND_REJECTED");
abbca718
LOK
360 bError = true;
361 break;
362 case MSGCODE_TRANSMIT_FAILED_LINE:
2abe74eb 363 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_LINE");
abbca718
LOK
364 bError = true;
365 break;
366 case MSGCODE_TRANSMIT_FAILED_ACK:
2abe74eb 367 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_ACK");
abbca718
LOK
368 bError = true;
369 break;
370 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA:
2abe74eb 371 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA");
abbca718
LOK
372 bError = true;
373 break;
374 case MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE:
2abe74eb 375 m_controller->AddLog(CEC_LOG_WARNING, "MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE");
abbca718
LOK
376 bError = true;
377 break;
378 default:
379 m_frameBuffer.Push(msg);
380 bGotAck = (msg[0] & MSGCODE_FRAME_ACK) != 0;
381 break;
382 }
383 iNow = GetTimeMs();
384 }
385 }
386
387 return bGotAck && !bError;
388}
389
2abe74eb 390bool CCECProcessor::ParseMessage(cec_frame &msg)
abbca718 391{
60fa4578
LOK
392 bool bReturn(false);
393
abbca718 394 if (msg.empty())
60fa4578 395 return bReturn;
abbca718
LOK
396
397 CStdString logStr;
398 uint8_t iCode = msg[0] & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK);
399 bool bEom = (msg[0] & MSGCODE_FRAME_EOM) != 0;
400 bool bAck = (msg[0] & MSGCODE_FRAME_ACK) != 0;
401
402 switch(iCode)
403 {
404 case MSGCODE_NOTHING:
2abe74eb 405 m_controller->AddLog(CEC_LOG_DEBUG, "MSGCODE_NOTHING");
abbca718
LOK
406 break;
407 case MSGCODE_TIMEOUT_ERROR:
408 case MSGCODE_HIGH_ERROR:
409 case MSGCODE_LOW_ERROR:
410 {
411 if (iCode == MSGCODE_TIMEOUT_ERROR)
412 logStr = "MSGCODE_TIMEOUT";
413 else if (iCode == MSGCODE_HIGH_ERROR)
414 logStr = "MSGCODE_HIGH_ERROR";
415 else
416 logStr = "MSGCODE_LOW_ERROR";
417
418 int iLine = (msg.size() >= 3) ? (msg[1] << 8) | (msg[2]) : 0;
419 uint32_t iTime = (msg.size() >= 7) ? (msg[3] << 24) | (msg[4] << 16) | (msg[5] << 8) | (msg[6]) : 0;
420 logStr.AppendFormat(" line:%i", iLine);
421 logStr.AppendFormat(" time:%u", iTime);
2abe74eb 422 m_controller->AddLog(CEC_LOG_WARNING, logStr.c_str());
abbca718
LOK
423 }
424 break;
425 case MSGCODE_FRAME_START:
426 {
427 logStr = "MSGCODE_FRAME_START";
428 m_currentframe.clear();
429 if (msg.size() >= 2)
430 {
431 int iInitiator = msg[1] >> 4;
432 int iDestination = msg[1] & 0xF;
433 logStr.AppendFormat(" initiator:%u destination:%u ack:%s %s", iInitiator, iDestination, bAck ? "high" : "low", bEom ? "eom" : "");
434
435 m_currentframe.push_back(msg[1]);
436 }
2abe74eb 437 m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str());
abbca718
LOK
438 }
439 break;
440 case MSGCODE_FRAME_DATA:
441 {
442 logStr = "MSGCODE_FRAME_DATA";
443 if (msg.size() >= 2)
444 {
445 uint8_t iData = msg[1];
446 logStr.AppendFormat(" %02x", iData);
447 m_currentframe.push_back(iData);
448 }
2abe74eb 449 m_controller->AddLog(CEC_LOG_DEBUG, logStr.c_str());
abbca718
LOK
450 }
451 if (bEom)
60fa4578 452 bReturn = true;
abbca718
LOK
453 break;
454 default:
455 break;
456 }
60fa4578
LOK
457
458 return bReturn;
abbca718
LOK
459}
460
2abe74eb 461void CCECProcessor::ParseCurrentFrame(void)
abbca718
LOK
462{
463 uint8_t initiator = m_currentframe[0] >> 4;
464 uint8_t destination = m_currentframe[0] & 0xF;
465
466 CStdString dataStr;
467 dataStr.Format("received frame: initiator: %u destination: %u", initiator, destination);
468
469 if (m_currentframe.size() > 1)
470 {
471 dataStr += " data:";
472 for (unsigned int i = 1; i < m_currentframe.size(); i++)
473 dataStr.AppendFormat(" %02x", m_currentframe[i]);
474 }
2abe74eb 475 m_controller->AddLog(CEC_LOG_DEBUG, dataStr.c_str());
abbca718
LOK
476
477 if (m_currentframe.size() <= 1)
478 return;
479
480 vector<uint8_t> tx;
825ddb96 481 cec_opcode opCode = (cec_opcode) m_currentframe[1];
abbca718
LOK
482 if (destination == (uint16_t) m_iLogicalAddress)
483 {
484 switch(opCode)
485 {
486 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
487 ReportPhysicalAddress();
488 SetActiveView();
489 break;
490 case CEC_OPCODE_GIVE_OSD_NAME:
491 ReportOSDName((cec_logical_address)initiator);
492 break;
493 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
494 ReportVendorID((cec_logical_address)initiator);
495 break;
496 case CEC_OPCODE_MENU_REQUEST:
497 ReportMenuState((cec_logical_address)initiator);
498 break;
499 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
500 ReportPowerState((cec_logical_address)initiator);
501 break;
502 case CEC_OPCODE_GET_CEC_VERSION:
503 ReportCECVersion((cec_logical_address)initiator);
504 break;
505 case CEC_OPCODE_USER_CONTROL_PRESSED:
506 if (m_currentframe.size() > 2)
507 {
2abe74eb 508 m_controller->AddKey();
abbca718
LOK
509
510 if (m_currentframe[2] <= CEC_USER_CONTROL_CODE_MAX)
2abe74eb 511 m_controller->SetCurrentButton((cec_user_control_code) m_currentframe[2]);
abbca718
LOK
512 }
513 break;
514 case CEC_OPCODE_USER_CONTROL_RELEASE:
2abe74eb 515 m_controller->AddKey();
abbca718
LOK
516 break;
517 default:
825ddb96
LOK
518 cec_frame params = m_currentframe;
519 params.erase(params.begin(), params.begin() + 2);
2abe74eb 520 m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
abbca718
LOK
521 break;
522 }
523 }
524 else if (destination == (uint8_t) CECDEVICE_BROADCAST)
525 {
526 if (opCode == CEC_OPCODE_REQUEST_ACTIVE_SOURCE)
527 {
528 BroadcastActiveSource();
529 }
530 else if (opCode == CEC_OPCODE_SET_STREAM_PATH)
531 {
532 if (m_currentframe.size() >= 4)
533 {
534 int streamaddr = ((int)m_currentframe[2] << 8) | ((int)m_currentframe[3]);
535 CStdString strLog;
536 strLog.Format("%i requests stream path from physical address %04x", initiator, streamaddr);
2abe74eb 537 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
538 if (streamaddr == m_physicaladdress)
539 BroadcastActiveSource();
540 }
541 }
c49c485b
LOK
542 else
543 {
544 cec_frame params = m_currentframe;
545 params.erase(params.begin(), params.begin() + 2);
2abe74eb 546 m_controller->AddCommand((cec_logical_address) initiator, (cec_logical_address) destination, opCode, &params);
c49c485b 547 }
abbca718
LOK
548 }
549 else
550 {
551 CStdString strLog;
552 strLog.Format("ignoring frame: destination: %u != %u", destination, (uint16_t)m_iLogicalAddress);
2abe74eb 553 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
abbca718
LOK
554 }
555}