2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CECProcessor.h"
35 #include "adapter/USBCECAdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
37 #include "devices/CECAudioSystem.h"
38 #include "devices/CECPlaybackDevice.h"
39 #include "devices/CECRecordingDevice.h"
40 #include "devices/CECTuner.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
44 #include "platform/util/timeutils.h"
48 using namespace PLATFORM
;
50 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const libcec_configuration
*configuration
) :
51 m_bInitialised(false),
52 m_communication(NULL
),
53 m_controller(controller
),
55 m_iStandardLineTimeout(3),
56 m_iRetryLineTimeout(3),
57 m_iLastTransmission(0)
59 m_logicalAddresses
.Clear();
61 m_configuration
.Clear();
63 SetConfiguration(configuration
);
65 if (m_configuration
.tvVendor
!= CEC_VENDOR_UNKNOWN
)
66 m_busDevices
[CECDEVICE_TV
]->ReplaceHandler(false);
69 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
, uint16_t iPhysicalAddress
) :
70 m_bInitialised(false),
71 m_communication(NULL
),
72 m_controller(controller
),
74 m_iStandardLineTimeout(3),
75 m_iRetryLineTimeout(3),
76 m_iLastTransmission(0)
78 m_configuration
.Clear();
80 // client version < 1.5.0
81 m_configuration
.clientVersion
= CEC_CLIENT_VERSION_PRE_1_5
;
82 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
);
83 m_configuration
.deviceTypes
= types
;
84 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
85 m_configuration
.baseDevice
= (cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
;
86 m_configuration
.iHDMIPort
= CEC_DEFAULT_HDMI_PORT
;
88 if (m_configuration
.deviceTypes
.IsEmpty())
89 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
90 m_logicalAddresses
.Clear();
94 void CCECProcessor::CreateBusDevices(void)
96 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
100 case CECDEVICE_AUDIOSYSTEM
:
101 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
103 case CECDEVICE_PLAYBACKDEVICE1
:
104 case CECDEVICE_PLAYBACKDEVICE2
:
105 case CECDEVICE_PLAYBACKDEVICE3
:
106 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
108 case CECDEVICE_RECORDINGDEVICE1
:
109 case CECDEVICE_RECORDINGDEVICE2
:
110 case CECDEVICE_RECORDINGDEVICE3
:
111 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
113 case CECDEVICE_TUNER1
:
114 case CECDEVICE_TUNER2
:
115 case CECDEVICE_TUNER3
:
116 case CECDEVICE_TUNER4
:
117 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
120 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
123 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
129 CCECProcessor::~CCECProcessor(void)
133 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
134 delete m_busDevices
[iPtr
];
137 void CCECProcessor::Close(void)
141 CLockObject
lock(m_mutex
);
144 m_communication
->Close();
145 delete m_communication
;
146 m_communication
= NULL
;
150 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
153 CLockObject
lock(m_mutex
);
156 CLibCEC::AddLog(CEC_LOG_WARNING
, "existing connection handler found, deleting it");
157 m_communication
->Close();
158 delete m_communication
;
161 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
163 /* check for an already opened connection */
164 if (m_communication
->IsOpen())
166 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
170 uint64_t iNow
= GetTimeMs();
171 uint64_t iTarget
= iTimeoutMs
> 0 ? iNow
+ iTimeoutMs
: iNow
+ CEC_DEFAULT_TRANSMIT_WAIT
;
173 /* open a new connection */
174 unsigned iConnectTry(0);
175 while (iNow
< iTarget
&& (bReturn
= m_communication
->Open(this, iTimeoutMs
)) == false)
177 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
183 CLibCEC::AddLog(CEC_LOG_NOTICE
, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication
->GetFirmwareVersion(), ToString(m_configuration
.clientVersion
));
188 bool CCECProcessor::IsInitialised(void)
190 CLockObject
lock(m_mutex
);
191 return m_bInitialised
;
194 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
196 CLockObject
lock(m_mutex
);
197 m_bInitialised
= bSetTo
;
200 bool CCECProcessor::Initialise(void)
204 CLockObject
lock(m_mutex
);
205 if (!m_logicalAddresses
.IsEmpty())
206 m_logicalAddresses
.Clear();
208 if (!FindLogicalAddresses())
210 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
214 /* only set our OSD name for the primary device */
215 m_busDevices
[m_logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
218 /* get the vendor id from the TV, so we are using the correct handler */
219 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
221 if (m_configuration
.iPhysicalAddress
!= 0)
223 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
224 m_busDevices
[m_logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
225 if ((bReturn
= m_busDevices
[m_logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
226 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
228 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
229 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set HDMI port %d on %s (%x)", m_configuration
.iHDMIPort
, ToString(m_configuration
.baseDevice
), (uint8_t)m_configuration
.baseDevice
);
231 SetInitialised(bReturn
);
232 CLibCEC::ConfigurationChanged(m_configuration
);
237 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
242 CLockObject
lock(m_mutex
);
243 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
246 /* create the processor thread */
249 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
254 if ((bReturn
= Initialise()) == false)
256 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
261 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
267 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
269 if (m_busDevices
[address
]->TryLogicalAddress())
271 m_logicalAddresses
.Set(address
);
278 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
280 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
281 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
282 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
283 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
286 bool CCECProcessor::FindLogicalAddressTuner(void)
288 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
289 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
290 TryLogicalAddress(CECDEVICE_TUNER2
) ||
291 TryLogicalAddress(CECDEVICE_TUNER3
) ||
292 TryLogicalAddress(CECDEVICE_TUNER4
);
295 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
297 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
298 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
299 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
300 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
303 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
305 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
306 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
309 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
311 bool bChanged(false);
313 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
315 CLockObject
lock(m_mutex
);
316 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
317 m_logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
319 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
321 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
324 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
327 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
329 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
331 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
337 FindLogicalAddresses();
339 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
340 if (previousDevice
&& newDevice
)
342 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
343 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
345 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
346 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
348 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
349 cec_menu_language lang
;
350 lang
.device
= previousDevice
->GetLogicalAddress();
351 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
352 lang
.language
[iPtr
] = '?';
353 lang
.language
[3] = 0;
354 previousDevice
->SetMenuLanguage(lang
);
356 newDevice
->SetMenuState(previousDevice
->GetMenuState());
357 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
359 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
360 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
362 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
363 previousDevice
->SetPhysicalAddress(0xFFFF);
365 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
366 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
368 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
369 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
371 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
372 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
374 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
375 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
377 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
378 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
386 bool CCECProcessor::FindLogicalAddresses(void)
389 m_logicalAddresses
.Clear();
391 if (m_configuration
.deviceTypes
.IsEmpty())
393 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
397 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
399 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
402 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
404 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
405 bReturn
&= FindLogicalAddressRecordingDevice();
406 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
407 bReturn
&= FindLogicalAddressTuner();
408 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
409 bReturn
&= FindLogicalAddressPlaybackDevice();
410 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
411 bReturn
&= FindLogicalAddressAudioSystem();
415 SetAckMask(m_logicalAddresses
.AckMask());
420 void CCECProcessor::ReplaceHandlers(void)
422 if (!IsInitialised())
424 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
425 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
428 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
430 m_commandBuffer
.Push(command
);
434 void *CCECProcessor::Process(void)
437 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
439 while (!IsStopped() && m_communication
->IsOpen())
444 if (m_commandBuffer
.Pop(command
))
445 ParseCommand(command
);
447 m_controller
->CheckKeypressTimeout();
455 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
462 cec_logical_address addr
= m_logicalAddresses
.primary
;
464 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
466 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
468 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
470 addr
= (cec_logical_address
) iPtr
;
476 m_busDevices
[addr
]->SetActiveSource();
477 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
478 bReturn
= m_busDevices
[addr
]->ActivateSource();
483 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
487 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
490 device
->SetActiveSource();
497 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
499 CLockObject
lock(m_mutex
);
500 m_iStandardLineTimeout
= iTimeout
;
503 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
505 CLockObject
lock(m_mutex
);
506 m_iRetryLineTimeout
= iTimeout
;
509 bool CCECProcessor::SetActiveView(void)
511 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
512 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
515 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
519 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
522 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
524 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
531 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
535 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
538 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
540 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
547 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
552 CLockObject
lock(m_mutex
);
553 m_configuration
.baseDevice
= iBaseDevice
;
554 m_configuration
.iHDMIPort
= iPort
;
555 m_configuration
.bAutodetectAddress
= false;
558 if (!IsRunning() && !bForce
)
561 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
563 uint16_t iPhysicalAddress(0);
564 if (iBaseDevice
> CECDEVICE_TV
)
566 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
569 if (iPhysicalAddress
< 0xffff)
571 if (iPhysicalAddress
== 0)
572 iPhysicalAddress
+= 0x1000 * iPort
;
573 else if (iPhysicalAddress
% 0x1000 == 0)
574 iPhysicalAddress
+= 0x100 * iPort
;
575 else if (iPhysicalAddress
% 0x100 == 0)
576 iPhysicalAddress
+= 0x10 * iPort
;
577 else if (iPhysicalAddress
% 0x10 == 0)
578 iPhysicalAddress
+= iPort
;
584 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
586 SetPhysicalAddress(iPhysicalAddress
);
591 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
593 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
595 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
601 bool CCECProcessor::TransmitInactiveSource(void)
606 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
607 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
611 void CCECProcessor::LogOutput(const cec_command
&data
)
614 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
616 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
618 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
619 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
620 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
623 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
625 CLockObject
lock(m_mutex
);
626 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
628 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
629 m_logicalAddresses
.primary
= iLogicalAddress
;
630 m_logicalAddresses
.Set(iLogicalAddress
);
631 return SetAckMask(m_logicalAddresses
.AckMask());
637 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
639 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
641 if (m_logicalAddresses
[iPtr
])
642 m_busDevices
[iPtr
]->SetMenuState(state
);
646 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
651 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
653 bool bSendActiveView(false);
655 cec_logical_addresses sendUpdatesTo
;
656 sendUpdatesTo
.Clear();
659 CLockObject
lock(m_mutex
);
660 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
661 if (m_configuration
.bAutodetectAddress
)
663 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
664 m_configuration
.iHDMIPort
= 0;
667 if (!m_logicalAddresses
.IsEmpty())
669 bool bWasActiveSource(false);
670 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
671 if (m_logicalAddresses
[iPtr
])
673 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
674 m_busDevices
[iPtr
]->SetInactiveSource();
675 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
677 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
680 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
685 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
686 if (sendUpdatesTo
[iPtr
])
687 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
693 CLibCEC::ConfigurationChanged(m_configuration
);
698 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
700 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
703 CLockObject
lock(m_mutex
);
704 m_bMonitor
= bEnable
;
708 return SetAckMask(0);
710 return SetAckMask(m_logicalAddresses
.AckMask());
713 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
715 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
717 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
718 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
719 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
724 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
727 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
728 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
733 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
736 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
737 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
742 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
745 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
746 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
751 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
753 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
754 return m_busDevices
[m_logicalAddresses
.primary
];
756 CCECBusDevice
*device
= NULL
;
757 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
759 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
761 device
= m_busDevices
[iPtr
];
769 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
771 CCECBusDevice
*device
= NULL
;
773 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
775 if (m_busDevices
[iPtr
]->m_type
== type
&& m_logicalAddresses
[iPtr
])
777 device
= m_busDevices
[iPtr
];
785 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
787 CCECBusDevice
*device(NULL
);
788 cec_logical_address primary
= m_logicalAddresses
.primary
;
789 if (primary
!= CECDEVICE_UNKNOWN
)
790 device
= m_busDevices
[primary
];
794 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
796 return m_busDevices
[iAddress
]->GetCecVersion();
799 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
801 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
804 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
805 retVal
.device
= iAddress
;
810 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
812 if (m_busDevices
[iAddress
])
814 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
815 return (strcmp(language
->language
, "???") != 0);
820 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
822 if (m_busDevices
[iAddress
])
823 return m_busDevices
[iAddress
]->GetVendorId();
827 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
829 if (m_busDevices
[iAddress
])
830 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
834 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
836 if (m_busDevices
[iAddress
])
837 return m_busDevices
[iAddress
]->GetPowerStatus();
838 return CEC_POWER_STATUS_UNKNOWN
;
841 cec_logical_address
CCECProcessor::GetActiveSource(void)
843 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
845 if (m_busDevices
[iPtr
]->IsActiveSource())
846 return (cec_logical_address
)iPtr
;
849 return CECDEVICE_UNKNOWN
;
852 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
854 return m_busDevices
[iAddress
]->IsActiveSource();
857 bool CCECProcessor::Transmit(const cec_command
&data
)
859 if (m_logicalAddresses
[(uint8_t)data
.destination
])
861 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
865 cec_adapter_message_state
retVal(ADAPTER_MESSAGE_STATE_UNKNOWN
);
867 CLockObject
lock(m_mutex
);
869 m_iLastTransmission
= GetTimeMs();
870 if (!m_communication
)
872 uint8_t iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
873 retVal
= m_communication
->Write(data
, iMaxTries
, m_iLineTimeout
, m_iRetryLineTimeout
);
876 /* set to "not present" on failed ack */
877 if (retVal
== ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED
&&
878 data
.destination
!= CECDEVICE_BROADCAST
)
879 m_busDevices
[data
.destination
]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
881 return retVal
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
884 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
886 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
890 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
891 command
.parameters
.PushBack((uint8_t)opcode
);
892 command
.parameters
.PushBack((uint8_t)reason
);
897 void CCECProcessor::ParseCommand(const cec_command
&command
)
900 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
901 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
902 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
903 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
905 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
906 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
909 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
911 cec_logical_addresses addresses
;
913 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
915 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
916 addresses
.Set((cec_logical_address
) iPtr
);
921 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
923 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
926 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
928 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
930 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
937 uint16_t CCECProcessor::GetPhysicalAddress(void) const
939 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
940 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
944 bool CCECProcessor::SetAckMask(uint16_t iMask
)
946 return m_communication
->SetAckMask(iMask
);
949 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
951 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
954 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
956 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
959 bool CCECProcessor::EnablePhysicalAddressDetection(void)
961 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
962 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
963 if (iPhysicalAddress
!= 0)
965 m_configuration
.bAutodetectAddress
= 1;
966 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
967 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
968 m_configuration
.iHDMIPort
= 0;
969 return SetPhysicalAddress(iPhysicalAddress
);
974 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
976 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
979 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
981 if (m_configuration
.powerOffDevices
[iPtr
])
982 bReturn
&= m_busDevices
[iPtr
]->Standby();
987 return m_busDevices
[address
]->Standby();
990 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
992 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
995 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
997 if (m_configuration
.powerOffDevices
[iPtr
])
998 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1003 return m_busDevices
[address
]->PowerOn();
1006 const char *CCECProcessor::ToString(const cec_device_type type
)
1010 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1011 return "audio system";
1012 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1013 return "playback device";
1014 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1015 return "recording device";
1016 case CEC_DEVICE_TYPE_RESERVED
:
1018 case CEC_DEVICE_TYPE_TUNER
:
1020 case CEC_DEVICE_TYPE_TV
:
1027 const char *CCECProcessor::ToString(const cec_menu_state state
)
1031 case CEC_MENU_STATE_ACTIVATED
:
1033 case CEC_MENU_STATE_DEACTIVATED
:
1034 return "deactivated";
1040 const char *CCECProcessor::ToString(const cec_version version
)
1044 case CEC_VERSION_1_2
:
1046 case CEC_VERSION_1_2A
:
1048 case CEC_VERSION_1_3
:
1050 case CEC_VERSION_1_3A
:
1052 case CEC_VERSION_1_4
:
1059 const char *CCECProcessor::ToString(const cec_power_status status
)
1063 case CEC_POWER_STATUS_ON
:
1065 case CEC_POWER_STATUS_STANDBY
:
1067 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1068 return "in transition from on to standby";
1069 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1070 return "in transition from standby to on";
1076 const char *CCECProcessor::ToString(const cec_logical_address address
)
1080 case CECDEVICE_AUDIOSYSTEM
:
1082 case CECDEVICE_BROADCAST
:
1084 case CECDEVICE_FREEUSE
:
1086 case CECDEVICE_PLAYBACKDEVICE1
:
1087 return "Playback 1";
1088 case CECDEVICE_PLAYBACKDEVICE2
:
1089 return "Playback 2";
1090 case CECDEVICE_PLAYBACKDEVICE3
:
1091 return "Playback 3";
1092 case CECDEVICE_RECORDINGDEVICE1
:
1093 return "Recorder 1";
1094 case CECDEVICE_RECORDINGDEVICE2
:
1095 return "Recorder 2";
1096 case CECDEVICE_RECORDINGDEVICE3
:
1097 return "Recorder 3";
1098 case CECDEVICE_RESERVED1
:
1099 return "Reserved 1";
1100 case CECDEVICE_RESERVED2
:
1101 return "Reserved 2";
1102 case CECDEVICE_TUNER1
:
1104 case CECDEVICE_TUNER2
:
1106 case CECDEVICE_TUNER3
:
1108 case CECDEVICE_TUNER4
:
1117 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1121 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1122 return "skip forward wind";
1123 case CEC_DECK_CONTROL_MODE_EJECT
:
1125 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1126 return "reverse rewind";
1127 case CEC_DECK_CONTROL_MODE_STOP
:
1134 const char *CCECProcessor::ToString(const cec_deck_info status
)
1138 case CEC_DECK_INFO_PLAY
:
1140 case CEC_DECK_INFO_RECORD
:
1142 case CEC_DECK_INFO_PLAY_REVERSE
:
1143 return "play reverse";
1144 case CEC_DECK_INFO_STILL
:
1146 case CEC_DECK_INFO_SLOW
:
1148 case CEC_DECK_INFO_SLOW_REVERSE
:
1149 return "slow reverse";
1150 case CEC_DECK_INFO_FAST_FORWARD
:
1151 return "fast forward";
1152 case CEC_DECK_INFO_FAST_REVERSE
:
1153 return "fast reverse";
1154 case CEC_DECK_INFO_NO_MEDIA
:
1156 case CEC_DECK_INFO_STOP
:
1158 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1159 return "info skip forward wind";
1160 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1161 return "info skip reverse rewind";
1162 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1163 return "info index search forward";
1164 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1165 return "info index search reverse";
1166 case CEC_DECK_INFO_OTHER_STATUS
:
1173 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1177 case CEC_OPCODE_ACTIVE_SOURCE
:
1178 return "active source";
1179 case CEC_OPCODE_IMAGE_VIEW_ON
:
1180 return "image view on";
1181 case CEC_OPCODE_TEXT_VIEW_ON
:
1182 return "text view on";
1183 case CEC_OPCODE_INACTIVE_SOURCE
:
1184 return "inactive source";
1185 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1186 return "request active source";
1187 case CEC_OPCODE_ROUTING_CHANGE
:
1188 return "routing change";
1189 case CEC_OPCODE_ROUTING_INFORMATION
:
1190 return "routing information";
1191 case CEC_OPCODE_SET_STREAM_PATH
:
1192 return "set stream path";
1193 case CEC_OPCODE_STANDBY
:
1195 case CEC_OPCODE_RECORD_OFF
:
1196 return "record off";
1197 case CEC_OPCODE_RECORD_ON
:
1199 case CEC_OPCODE_RECORD_STATUS
:
1200 return "record status";
1201 case CEC_OPCODE_RECORD_TV_SCREEN
:
1202 return "record tv screen";
1203 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1204 return "clear analogue timer";
1205 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1206 return "clear digital timer";
1207 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1208 return "clear external timer";
1209 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1210 return "set analogue timer";
1211 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1212 return "set digital timer";
1213 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1214 return "set external timer";
1215 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1216 return "set timer program title";
1217 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1218 return "timer cleared status";
1219 case CEC_OPCODE_TIMER_STATUS
:
1220 return "timer status";
1221 case CEC_OPCODE_CEC_VERSION
:
1222 return "cec version";
1223 case CEC_OPCODE_GET_CEC_VERSION
:
1224 return "get cec version";
1225 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1226 return "give physical address";
1227 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1228 return "get menu language";
1229 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1230 return "report physical address";
1231 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1232 return "set menu language";
1233 case CEC_OPCODE_DECK_CONTROL
:
1234 return "deck control";
1235 case CEC_OPCODE_DECK_STATUS
:
1236 return "deck status";
1237 case CEC_OPCODE_GIVE_DECK_STATUS
:
1238 return "give deck status";
1239 case CEC_OPCODE_PLAY
:
1241 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1242 return "give tuner status";
1243 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1244 return "select analogue service";
1245 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1246 return "set digital service";
1247 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1248 return "tuner device status";
1249 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1250 return "tuner step decrement";
1251 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1252 return "tuner step increment";
1253 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1254 return "device vendor id";
1255 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1256 return "give device vendor id";
1257 case CEC_OPCODE_VENDOR_COMMAND
:
1258 return "vendor command";
1259 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1260 return "vendor command with id";
1261 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1262 return "vendor remote button down";
1263 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1264 return "vendor remote button up";
1265 case CEC_OPCODE_SET_OSD_STRING
:
1266 return "set osd string";
1267 case CEC_OPCODE_GIVE_OSD_NAME
:
1268 return "give osd name";
1269 case CEC_OPCODE_SET_OSD_NAME
:
1270 return "set osd name";
1271 case CEC_OPCODE_MENU_REQUEST
:
1272 return "menu request";
1273 case CEC_OPCODE_MENU_STATUS
:
1274 return "menu status";
1275 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1276 return "user control pressed";
1277 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1278 return "user control release";
1279 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1280 return "give device power status";
1281 case CEC_OPCODE_REPORT_POWER_STATUS
:
1282 return "report power status";
1283 case CEC_OPCODE_FEATURE_ABORT
:
1284 return "feature abort";
1285 case CEC_OPCODE_ABORT
:
1287 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1288 return "give audio status";
1289 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1290 return "give audio mode status";
1291 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1292 return "report audio status";
1293 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1294 return "set system audio mode";
1295 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1296 return "system audio mode request";
1297 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1298 return "system audio mode status";
1299 case CEC_OPCODE_SET_AUDIO_RATE
:
1300 return "set audio rate";
1306 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1310 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1312 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1319 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1321 // TODO this is a mask
1325 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1329 case CEC_VENDOR_SAMSUNG
:
1333 case CEC_VENDOR_PANASONIC
:
1335 case CEC_VENDOR_PIONEER
:
1337 case CEC_VENDOR_ONKYO
:
1339 case CEC_VENDOR_YAMAHA
:
1341 case CEC_VENDOR_PHILIPS
:
1343 case CEC_VENDOR_SONY
:
1350 const char *CCECProcessor::ToString(const cec_client_version version
)
1354 case CEC_CLIENT_VERSION_PRE_1_5
:
1356 case CEC_CLIENT_VERSION_1_5_0
:
1363 void *CCECBusScan::Process(void)
1365 CCECBusDevice
*device(NULL
);
1366 uint8_t iCounter(0);
1368 while (!IsStopped())
1370 if (++iCounter
< 10)
1375 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1377 device
= m_processor
->m_busDevices
[iPtr
];
1379 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1383 device
->GetVendorId();
1387 device
->GetPowerStatus(true);
1395 void CCECBusScan::WaitUntilIdle(void)
1400 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1401 while (iWaitTime
> 0)
1404 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1408 bool CCECProcessor::StartBootloader(void)
1410 return m_communication
->StartBootloader();
1413 bool CCECProcessor::PingAdapter(void)
1415 return m_communication
->PingAdapter();
1418 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1420 m_busDevices
[initiator
]->HandlePoll(destination
);
1423 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1425 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1428 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1430 // stream path changes are sent by the TV
1431 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1434 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1436 bool bReinit(false);
1437 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1438 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1439 m_configuration
.clientVersion
= configuration
->clientVersion
;
1441 // client version 1.5.0
1444 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1445 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1447 // autodetect address
1448 uint16_t iPhysicalAddress
= IsRunning() && configuration
->bAutodetectAddress
? m_communication
->GetPhysicalAddress() : 0;
1449 bool bPhysicalAutodetected
= IsRunning() && configuration
->bAutodetectAddress
&& iPhysicalAddress
!= m_configuration
.iPhysicalAddress
&& iPhysicalAddress
!= 0;
1450 if (bPhysicalAutodetected
)
1452 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1453 m_configuration
.bAutodetectAddress
= true;
1457 m_configuration
.bAutodetectAddress
= false;
1461 bool bPhysicalAddressChanged(false);
1462 if (!bPhysicalAutodetected
)
1464 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1465 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1469 bool bHdmiPortChanged(false);
1470 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1472 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1473 m_configuration
.baseDevice
= configuration
->baseDevice
;
1477 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1481 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1483 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1484 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1488 m_configuration
.iHDMIPort
= 0;
1491 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
|| bPhysicalAutodetected
;
1494 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1495 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1497 primary
->SetOSDName(m_configuration
.strDeviceName
);
1498 if (!bReinit
&& IsRunning())
1499 primary
->TransmitOSDName(CECDEVICE_TV
);
1502 // tv vendor id override
1503 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1505 m_configuration
.tvVendor
= configuration
->tvVendor
;
1506 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1510 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1512 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1513 if (!bReinit
&& IsRunning())
1518 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1519 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1520 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1521 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1523 // ensure that there is at least 1 device type set
1524 if (m_configuration
.deviceTypes
.IsEmpty())
1525 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1529 if (bDeviceTypeChanged
)
1530 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1531 else if (bPhysicalAddressChanged
)
1532 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1534 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1540 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1542 // client version 1.5.0
1543 configuration
->clientVersion
= m_configuration
.clientVersion
;
1544 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1545 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1546 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1547 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1548 configuration
->baseDevice
= m_configuration
.baseDevice
;
1549 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1550 configuration
->tvVendor
= m_configuration
.tvVendor
;
1551 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1552 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1553 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1554 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1555 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1560 bool CCECProcessor::CanPersistConfiguration(void)
1562 return m_communication
->GetFirmwareVersion() >= 2;
1565 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1567 return m_communication
->PersistConfiguration(configuration
);