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
, libcec_configuration
*configuration
) :
51 m_bConnectionOpened(false),
52 m_bInitialised(false),
53 m_communication(NULL
),
54 m_controller(controller
),
56 m_iStandardLineTimeout(3),
57 m_iRetryLineTimeout(3),
58 m_iLastTransmission(0)
60 m_logicalAddresses
.Clear();
62 m_configuration
.Clear();
63 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_5_0
;
64 SetConfiguration(configuration
);
66 if (m_configuration
.tvVendor
!= CEC_VENDOR_UNKNOWN
)
67 m_busDevices
[CECDEVICE_TV
]->ReplaceHandler(false);
69 GetCurrentConfiguration(configuration
);
72 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
, uint16_t iPhysicalAddress
) :
73 m_bConnectionOpened(false),
74 m_bInitialised(false),
75 m_communication(NULL
),
76 m_controller(controller
),
78 m_iStandardLineTimeout(3),
79 m_iRetryLineTimeout(3),
80 m_iLastTransmission(0)
82 m_configuration
.Clear();
83 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_5_0
;
85 // client version < 1.5.0
86 m_configuration
.clientVersion
= (uint32_t)CEC_CLIENT_VERSION_PRE_1_5
;
87 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
);
88 m_configuration
.deviceTypes
= types
;
89 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
90 m_configuration
.baseDevice
= (cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
;
91 m_configuration
.iHDMIPort
= CEC_DEFAULT_HDMI_PORT
;
93 if (m_configuration
.deviceTypes
.IsEmpty())
94 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
95 m_logicalAddresses
.Clear();
99 void CCECProcessor::CreateBusDevices(void)
101 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
105 case CECDEVICE_AUDIOSYSTEM
:
106 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
108 case CECDEVICE_PLAYBACKDEVICE1
:
109 case CECDEVICE_PLAYBACKDEVICE2
:
110 case CECDEVICE_PLAYBACKDEVICE3
:
111 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
113 case CECDEVICE_RECORDINGDEVICE1
:
114 case CECDEVICE_RECORDINGDEVICE2
:
115 case CECDEVICE_RECORDINGDEVICE3
:
116 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
118 case CECDEVICE_TUNER1
:
119 case CECDEVICE_TUNER2
:
120 case CECDEVICE_TUNER3
:
121 case CECDEVICE_TUNER4
:
122 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
125 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
128 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
134 CCECProcessor::~CCECProcessor(void)
138 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
139 delete m_busDevices
[iPtr
];
142 void CCECProcessor::Close(void)
145 SetInitialised(false);
150 CLockObject
lock(m_mutex
);
151 bClose
= m_bConnectionOpened
;
152 m_bConnectionOpened
= false;
155 if (bClose
&& m_communication
)
157 m_communication
->Close();
158 delete m_communication
;
159 m_communication
= NULL
;
163 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
169 CLockObject
lock(m_mutex
);
170 if (m_bConnectionOpened
)
172 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
175 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
176 m_bConnectionOpened
= (m_communication
!= NULL
);
179 /* check for an already opened connection */
180 if (m_communication
->IsOpen())
182 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
186 uint64_t iNow
= GetTimeMs();
187 uint64_t iTarget
= iTimeoutMs
> 0 ? iNow
+ iTimeoutMs
: iNow
+ CEC_DEFAULT_TRANSMIT_WAIT
;
189 /* open a new connection */
190 unsigned iConnectTry(0);
191 while (iNow
< iTarget
&& (bReturn
= m_communication
->Open(this, iTimeoutMs
)) == false)
193 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
199 CLibCEC::AddLog(CEC_LOG_NOTICE
, "connected to the CEC adapter. firmware version = %d, client version = %s", m_communication
->GetFirmwareVersion(), ToString((cec_client_version
)m_configuration
.clientVersion
));
204 bool CCECProcessor::IsInitialised(void)
206 CLockObject
lock(m_mutex
);
207 return m_bInitialised
;
210 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
212 CLockObject
lock(m_mutex
);
213 m_bInitialised
= bSetTo
;
216 bool CCECProcessor::Initialise(void)
220 CLockObject
lock(m_mutex
);
221 if (!m_logicalAddresses
.IsEmpty())
222 m_logicalAddresses
.Clear();
224 if (!FindLogicalAddresses())
226 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
230 /* only set our OSD name for the primary device */
231 m_busDevices
[m_logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
233 /* make the primary device the active source if the option is set */
234 if (m_configuration
.bActivateSource
== 1)
235 m_busDevices
[m_logicalAddresses
.primary
]->m_bActiveSource
= true;
238 /* get the vendor id from the TV, so we are using the correct handler */
239 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
241 if (m_configuration
.iPhysicalAddress
!= 0)
243 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
244 m_busDevices
[m_logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
245 if ((bReturn
= m_busDevices
[m_logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
246 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
248 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
249 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
);
251 if (m_configuration
.bActivateSource
== 1)
252 m_busDevices
[m_logicalAddresses
.primary
]->ActivateSource();
254 SetInitialised(bReturn
);
255 CLibCEC::ConfigurationChanged(m_configuration
);
260 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
265 CLockObject
lock(m_mutex
);
266 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
269 /* create the processor thread */
272 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
277 if ((bReturn
= Initialise()) == false)
279 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
284 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
290 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
292 if (m_busDevices
[address
]->TryLogicalAddress())
294 m_logicalAddresses
.Set(address
);
301 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
303 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
304 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
305 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
306 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
309 bool CCECProcessor::FindLogicalAddressTuner(void)
311 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
312 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
313 TryLogicalAddress(CECDEVICE_TUNER2
) ||
314 TryLogicalAddress(CECDEVICE_TUNER3
) ||
315 TryLogicalAddress(CECDEVICE_TUNER4
);
318 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
320 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
321 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
322 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
323 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
326 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
328 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
329 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
332 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
334 bool bChanged(false);
336 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
338 CLockObject
lock(m_mutex
);
339 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
340 m_logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
342 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
344 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
347 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
350 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
352 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
354 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
360 FindLogicalAddresses();
362 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
363 if (previousDevice
&& newDevice
)
365 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
366 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
368 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
369 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
371 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
372 cec_menu_language lang
;
373 lang
.device
= previousDevice
->GetLogicalAddress();
374 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
375 lang
.language
[iPtr
] = '?';
376 lang
.language
[3] = 0;
377 previousDevice
->SetMenuLanguage(lang
);
379 newDevice
->SetMenuState(previousDevice
->GetMenuState());
380 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
382 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
383 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
385 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
386 previousDevice
->SetPhysicalAddress(0xFFFF);
388 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
389 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
391 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
392 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
394 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
395 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
397 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
398 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
400 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
401 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
409 bool CCECProcessor::FindLogicalAddresses(void)
412 m_logicalAddresses
.Clear();
414 if (m_configuration
.deviceTypes
.IsEmpty())
416 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
420 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
422 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
425 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
427 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
428 bReturn
&= FindLogicalAddressRecordingDevice();
429 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
430 bReturn
&= FindLogicalAddressTuner();
431 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
432 bReturn
&= FindLogicalAddressPlaybackDevice();
433 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
434 bReturn
&= FindLogicalAddressAudioSystem();
438 SetAckMask(m_logicalAddresses
.AckMask());
443 void CCECProcessor::ReplaceHandlers(void)
445 if (!IsInitialised())
447 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
448 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
451 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
453 ParseCommand(command
);
457 void *CCECProcessor::Process(void)
459 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
461 while (!IsStopped() && m_communication
->IsOpen())
467 m_controller
->CheckKeypressTimeout();
475 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
482 cec_logical_address addr
= m_logicalAddresses
.primary
;
484 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
486 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
488 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
490 addr
= (cec_logical_address
) iPtr
;
496 m_busDevices
[addr
]->SetActiveSource();
497 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
498 bReturn
= m_busDevices
[addr
]->ActivateSource();
503 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
507 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
510 device
->SetActiveSource();
517 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
519 CLockObject
lock(m_mutex
);
520 m_iStandardLineTimeout
= iTimeout
;
523 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
525 CLockObject
lock(m_mutex
);
526 m_iRetryLineTimeout
= iTimeout
;
529 bool CCECProcessor::SetActiveView(void)
531 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
532 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
535 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
539 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
542 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
544 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
551 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
555 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
558 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
560 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
567 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
572 CLockObject
lock(m_mutex
);
573 m_configuration
.baseDevice
= iBaseDevice
;
574 m_configuration
.iHDMIPort
= iPort
;
575 m_configuration
.bAutodetectAddress
= false;
578 if (!IsRunning() && !bForce
)
581 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
583 uint16_t iPhysicalAddress(0);
584 if (iBaseDevice
> CECDEVICE_TV
)
586 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
589 if (iPhysicalAddress
< 0xffff)
591 if (iPhysicalAddress
== 0)
592 iPhysicalAddress
+= 0x1000 * iPort
;
593 else if (iPhysicalAddress
% 0x1000 == 0)
594 iPhysicalAddress
+= 0x100 * iPort
;
595 else if (iPhysicalAddress
% 0x100 == 0)
596 iPhysicalAddress
+= 0x10 * iPort
;
597 else if (iPhysicalAddress
% 0x10 == 0)
598 iPhysicalAddress
+= iPort
;
604 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
606 SetPhysicalAddress(iPhysicalAddress
);
611 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
613 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
615 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
621 bool CCECProcessor::TransmitInactiveSource(void)
626 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
627 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
631 void CCECProcessor::LogOutput(const cec_command
&data
)
634 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
636 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
638 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
639 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
640 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
643 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
645 CLockObject
lock(m_mutex
);
646 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
648 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
649 m_logicalAddresses
.primary
= iLogicalAddress
;
650 m_logicalAddresses
.Set(iLogicalAddress
);
651 return SetAckMask(m_logicalAddresses
.AckMask());
657 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
659 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
661 if (m_logicalAddresses
[iPtr
])
662 m_busDevices
[iPtr
]->SetMenuState(state
);
666 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
671 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
673 bool bSendActiveView(false);
675 cec_logical_addresses sendUpdatesTo
;
676 sendUpdatesTo
.Clear();
679 CLockObject
lock(m_mutex
);
680 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
681 if (m_configuration
.bAutodetectAddress
)
683 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
684 m_configuration
.iHDMIPort
= 0;
687 if (!m_logicalAddresses
.IsEmpty())
689 bool bWasActiveSource(false);
690 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
691 if (m_logicalAddresses
[iPtr
])
693 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
694 m_busDevices
[iPtr
]->SetInactiveSource();
695 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
697 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
700 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
705 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
706 if (sendUpdatesTo
[iPtr
])
707 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
713 CLibCEC::ConfigurationChanged(m_configuration
);
718 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
720 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
723 CLockObject
lock(m_mutex
);
724 m_bMonitor
= bEnable
;
728 return SetAckMask(0);
730 return SetAckMask(m_logicalAddresses
.AckMask());
733 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
735 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
737 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
738 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
739 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
744 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
747 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
748 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
753 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
756 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
757 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
762 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
765 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
766 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
771 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
773 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
774 return m_busDevices
[m_logicalAddresses
.primary
];
776 CCECBusDevice
*device
= NULL
;
777 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
779 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
781 device
= m_busDevices
[iPtr
];
789 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
791 CCECBusDevice
*device
= NULL
;
793 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
795 if (m_busDevices
[iPtr
]->m_type
== type
&& m_logicalAddresses
[iPtr
])
797 device
= m_busDevices
[iPtr
];
805 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
807 CCECBusDevice
*device(NULL
);
808 cec_logical_address primary
= m_logicalAddresses
.primary
;
809 if (primary
!= CECDEVICE_UNKNOWN
)
810 device
= m_busDevices
[primary
];
814 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
816 return m_busDevices
[iAddress
]->GetCecVersion();
819 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
821 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
824 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
825 retVal
.device
= iAddress
;
830 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
832 if (m_busDevices
[iAddress
])
834 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
835 return (strcmp(language
->language
, "???") != 0);
840 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
842 if (m_busDevices
[iAddress
])
843 return m_busDevices
[iAddress
]->GetVendorId();
847 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
849 if (m_busDevices
[iAddress
])
850 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
854 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
856 if (m_busDevices
[iAddress
])
857 return m_busDevices
[iAddress
]->GetPowerStatus();
858 return CEC_POWER_STATUS_UNKNOWN
;
861 cec_logical_address
CCECProcessor::GetActiveSource(void)
863 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
865 if (m_busDevices
[iPtr
]->IsActiveSource())
866 return (cec_logical_address
)iPtr
;
869 return CECDEVICE_UNKNOWN
;
872 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
874 return m_busDevices
[iAddress
]->IsActiveSource();
877 bool CCECProcessor::Transmit(const cec_command
&data
)
879 if (m_logicalAddresses
[(uint8_t)data
.destination
])
881 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
885 uint8_t iMaxTries(0);
887 CLockObject
lock(m_mutex
);
889 m_iLastTransmission
= GetTimeMs();
890 if (!m_communication
|| !m_communication
->IsOpen())
892 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
895 iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
898 return m_communication
->Write(data
, iMaxTries
, m_iLineTimeout
, m_iRetryLineTimeout
)
899 == ADAPTER_MESSAGE_STATE_SENT_ACKED
;
902 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
904 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
908 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
909 command
.parameters
.PushBack((uint8_t)opcode
);
910 command
.parameters
.PushBack((uint8_t)reason
);
915 void CCECProcessor::ParseCommand(const cec_command
&command
)
918 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
919 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
920 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
921 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
923 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
924 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
927 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
929 cec_logical_addresses addresses
;
931 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
933 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
934 addresses
.Set((cec_logical_address
) iPtr
);
939 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
941 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
944 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
946 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
948 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
955 uint16_t CCECProcessor::GetPhysicalAddress(void) const
957 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
958 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
962 bool CCECProcessor::SetAckMask(uint16_t iMask
)
964 return m_communication
->SetAckMask(iMask
);
967 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
969 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
972 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
974 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
977 bool CCECProcessor::EnablePhysicalAddressDetection(void)
979 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
980 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
981 if (iPhysicalAddress
!= 0)
983 m_configuration
.bAutodetectAddress
= 1;
984 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
985 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
986 m_configuration
.iHDMIPort
= 0;
987 return SetPhysicalAddress(iPhysicalAddress
);
992 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
994 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
997 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
999 if (m_configuration
.powerOffDevices
[iPtr
])
1000 bReturn
&= m_busDevices
[iPtr
]->Standby();
1005 return m_busDevices
[address
]->Standby();
1008 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
1010 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1013 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1015 if (m_configuration
.powerOffDevices
[iPtr
])
1016 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1021 return m_busDevices
[address
]->PowerOn();
1024 const char *CCECProcessor::ToString(const cec_device_type type
)
1028 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1029 return "audio system";
1030 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1031 return "playback device";
1032 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1033 return "recording device";
1034 case CEC_DEVICE_TYPE_RESERVED
:
1036 case CEC_DEVICE_TYPE_TUNER
:
1038 case CEC_DEVICE_TYPE_TV
:
1045 const char *CCECProcessor::ToString(const cec_menu_state state
)
1049 case CEC_MENU_STATE_ACTIVATED
:
1051 case CEC_MENU_STATE_DEACTIVATED
:
1052 return "deactivated";
1058 const char *CCECProcessor::ToString(const cec_version version
)
1062 case CEC_VERSION_1_2
:
1064 case CEC_VERSION_1_2A
:
1066 case CEC_VERSION_1_3
:
1068 case CEC_VERSION_1_3A
:
1070 case CEC_VERSION_1_4
:
1077 const char *CCECProcessor::ToString(const cec_power_status status
)
1081 case CEC_POWER_STATUS_ON
:
1083 case CEC_POWER_STATUS_STANDBY
:
1085 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1086 return "in transition from on to standby";
1087 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1088 return "in transition from standby to on";
1094 const char *CCECProcessor::ToString(const cec_logical_address address
)
1098 case CECDEVICE_AUDIOSYSTEM
:
1100 case CECDEVICE_BROADCAST
:
1102 case CECDEVICE_FREEUSE
:
1104 case CECDEVICE_PLAYBACKDEVICE1
:
1105 return "Playback 1";
1106 case CECDEVICE_PLAYBACKDEVICE2
:
1107 return "Playback 2";
1108 case CECDEVICE_PLAYBACKDEVICE3
:
1109 return "Playback 3";
1110 case CECDEVICE_RECORDINGDEVICE1
:
1111 return "Recorder 1";
1112 case CECDEVICE_RECORDINGDEVICE2
:
1113 return "Recorder 2";
1114 case CECDEVICE_RECORDINGDEVICE3
:
1115 return "Recorder 3";
1116 case CECDEVICE_RESERVED1
:
1117 return "Reserved 1";
1118 case CECDEVICE_RESERVED2
:
1119 return "Reserved 2";
1120 case CECDEVICE_TUNER1
:
1122 case CECDEVICE_TUNER2
:
1124 case CECDEVICE_TUNER3
:
1126 case CECDEVICE_TUNER4
:
1135 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1139 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1140 return "skip forward wind";
1141 case CEC_DECK_CONTROL_MODE_EJECT
:
1143 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1144 return "reverse rewind";
1145 case CEC_DECK_CONTROL_MODE_STOP
:
1152 const char *CCECProcessor::ToString(const cec_deck_info status
)
1156 case CEC_DECK_INFO_PLAY
:
1158 case CEC_DECK_INFO_RECORD
:
1160 case CEC_DECK_INFO_PLAY_REVERSE
:
1161 return "play reverse";
1162 case CEC_DECK_INFO_STILL
:
1164 case CEC_DECK_INFO_SLOW
:
1166 case CEC_DECK_INFO_SLOW_REVERSE
:
1167 return "slow reverse";
1168 case CEC_DECK_INFO_FAST_FORWARD
:
1169 return "fast forward";
1170 case CEC_DECK_INFO_FAST_REVERSE
:
1171 return "fast reverse";
1172 case CEC_DECK_INFO_NO_MEDIA
:
1174 case CEC_DECK_INFO_STOP
:
1176 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1177 return "info skip forward wind";
1178 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1179 return "info skip reverse rewind";
1180 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1181 return "info index search forward";
1182 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1183 return "info index search reverse";
1184 case CEC_DECK_INFO_OTHER_STATUS
:
1191 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1195 case CEC_OPCODE_ACTIVE_SOURCE
:
1196 return "active source";
1197 case CEC_OPCODE_IMAGE_VIEW_ON
:
1198 return "image view on";
1199 case CEC_OPCODE_TEXT_VIEW_ON
:
1200 return "text view on";
1201 case CEC_OPCODE_INACTIVE_SOURCE
:
1202 return "inactive source";
1203 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1204 return "request active source";
1205 case CEC_OPCODE_ROUTING_CHANGE
:
1206 return "routing change";
1207 case CEC_OPCODE_ROUTING_INFORMATION
:
1208 return "routing information";
1209 case CEC_OPCODE_SET_STREAM_PATH
:
1210 return "set stream path";
1211 case CEC_OPCODE_STANDBY
:
1213 case CEC_OPCODE_RECORD_OFF
:
1214 return "record off";
1215 case CEC_OPCODE_RECORD_ON
:
1217 case CEC_OPCODE_RECORD_STATUS
:
1218 return "record status";
1219 case CEC_OPCODE_RECORD_TV_SCREEN
:
1220 return "record tv screen";
1221 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1222 return "clear analogue timer";
1223 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1224 return "clear digital timer";
1225 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1226 return "clear external timer";
1227 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1228 return "set analogue timer";
1229 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1230 return "set digital timer";
1231 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1232 return "set external timer";
1233 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1234 return "set timer program title";
1235 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1236 return "timer cleared status";
1237 case CEC_OPCODE_TIMER_STATUS
:
1238 return "timer status";
1239 case CEC_OPCODE_CEC_VERSION
:
1240 return "cec version";
1241 case CEC_OPCODE_GET_CEC_VERSION
:
1242 return "get cec version";
1243 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1244 return "give physical address";
1245 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1246 return "get menu language";
1247 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1248 return "report physical address";
1249 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1250 return "set menu language";
1251 case CEC_OPCODE_DECK_CONTROL
:
1252 return "deck control";
1253 case CEC_OPCODE_DECK_STATUS
:
1254 return "deck status";
1255 case CEC_OPCODE_GIVE_DECK_STATUS
:
1256 return "give deck status";
1257 case CEC_OPCODE_PLAY
:
1259 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1260 return "give tuner status";
1261 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1262 return "select analogue service";
1263 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1264 return "set digital service";
1265 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1266 return "tuner device status";
1267 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1268 return "tuner step decrement";
1269 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1270 return "tuner step increment";
1271 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1272 return "device vendor id";
1273 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1274 return "give device vendor id";
1275 case CEC_OPCODE_VENDOR_COMMAND
:
1276 return "vendor command";
1277 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1278 return "vendor command with id";
1279 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1280 return "vendor remote button down";
1281 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1282 return "vendor remote button up";
1283 case CEC_OPCODE_SET_OSD_STRING
:
1284 return "set osd string";
1285 case CEC_OPCODE_GIVE_OSD_NAME
:
1286 return "give osd name";
1287 case CEC_OPCODE_SET_OSD_NAME
:
1288 return "set osd name";
1289 case CEC_OPCODE_MENU_REQUEST
:
1290 return "menu request";
1291 case CEC_OPCODE_MENU_STATUS
:
1292 return "menu status";
1293 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1294 return "user control pressed";
1295 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1296 return "user control release";
1297 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1298 return "give device power status";
1299 case CEC_OPCODE_REPORT_POWER_STATUS
:
1300 return "report power status";
1301 case CEC_OPCODE_FEATURE_ABORT
:
1302 return "feature abort";
1303 case CEC_OPCODE_ABORT
:
1305 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1306 return "give audio status";
1307 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1308 return "give audio mode status";
1309 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1310 return "report audio status";
1311 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1312 return "set system audio mode";
1313 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1314 return "system audio mode request";
1315 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1316 return "system audio mode status";
1317 case CEC_OPCODE_SET_AUDIO_RATE
:
1318 return "set audio rate";
1319 case CEC_OPCODE_NONE
:
1326 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1330 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1332 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1339 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1341 // TODO this is a mask
1345 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1349 case CEC_VENDOR_SAMSUNG
:
1353 case CEC_VENDOR_PANASONIC
:
1355 case CEC_VENDOR_PIONEER
:
1357 case CEC_VENDOR_ONKYO
:
1359 case CEC_VENDOR_YAMAHA
:
1361 case CEC_VENDOR_PHILIPS
:
1363 case CEC_VENDOR_SONY
:
1370 const char *CCECProcessor::ToString(const cec_client_version version
)
1374 case CEC_CLIENT_VERSION_PRE_1_5
:
1376 case CEC_CLIENT_VERSION_1_5_0
:
1383 const char *CCECProcessor::ToString(const cec_server_version version
)
1387 case CEC_SERVER_VERSION_PRE_1_5
:
1389 case CEC_SERVER_VERSION_1_5_0
:
1396 void *CCECBusScan::Process(void)
1398 CCECBusDevice
*device(NULL
);
1399 uint8_t iCounter(0);
1401 while (!IsStopped())
1403 if (++iCounter
< 10)
1408 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1410 device
= m_processor
->m_busDevices
[iPtr
];
1412 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1416 device
->GetVendorId();
1420 device
->GetPowerStatus(true);
1428 void CCECBusScan::WaitUntilIdle(void)
1433 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1434 while (iWaitTime
> 0)
1437 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1441 bool CCECProcessor::StartBootloader(void)
1443 return m_communication
->StartBootloader();
1446 bool CCECProcessor::PingAdapter(void)
1448 return m_communication
->PingAdapter();
1451 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1453 m_busDevices
[initiator
]->HandlePoll(destination
);
1456 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1458 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1461 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1463 // stream path changes are sent by the TV
1464 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1467 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1469 bool bReinit(false);
1470 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1471 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1472 m_configuration
.clientVersion
= configuration
->clientVersion
;
1474 // client version 1.5.0
1477 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1478 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1480 // autodetect address
1481 uint16_t iPhysicalAddress
= IsRunning() && configuration
->bAutodetectAddress
? m_communication
->GetPhysicalAddress() : 0;
1482 bool bPhysicalAutodetected
= IsRunning() && configuration
->bAutodetectAddress
&& iPhysicalAddress
!= m_configuration
.iPhysicalAddress
&& iPhysicalAddress
!= 0;
1483 if (bPhysicalAutodetected
)
1485 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1486 m_configuration
.bAutodetectAddress
= true;
1490 m_configuration
.bAutodetectAddress
= false;
1494 bool bPhysicalAddressChanged(false);
1495 if (!bPhysicalAutodetected
)
1497 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1498 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1502 bool bHdmiPortChanged(false);
1503 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1505 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1506 m_configuration
.baseDevice
= configuration
->baseDevice
;
1510 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1514 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1516 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1517 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1521 m_configuration
.iHDMIPort
= 0;
1524 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
|| bPhysicalAutodetected
;
1527 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1528 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1530 primary
->SetOSDName(m_configuration
.strDeviceName
);
1531 if (!bReinit
&& IsRunning())
1532 primary
->TransmitOSDName(CECDEVICE_TV
);
1535 // tv vendor id override
1536 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1538 m_configuration
.tvVendor
= configuration
->tvVendor
;
1539 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1543 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1545 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1546 if (!bReinit
&& IsRunning())
1551 m_configuration
.clientVersion
= configuration
->clientVersion
;
1552 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1553 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1554 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1555 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1556 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1558 // ensure that there is at least 1 device type set
1559 if (m_configuration
.deviceTypes
.IsEmpty())
1560 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1564 if (bDeviceTypeChanged
)
1565 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1566 else if (bPhysicalAddressChanged
)
1567 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1569 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1575 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1577 // client version 1.5.0
1578 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1579 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1580 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1581 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1582 configuration
->baseDevice
= m_configuration
.baseDevice
;
1583 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1584 configuration
->clientVersion
= m_configuration
.clientVersion
;
1585 configuration
->serverVersion
= m_configuration
.serverVersion
;
1586 configuration
->tvVendor
= m_configuration
.tvVendor
;
1588 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1589 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1590 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1591 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1592 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1593 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1594 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1599 bool CCECProcessor::CanPersistConfiguration(void)
1601 return m_communication
->GetFirmwareVersion() >= 2;
1604 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1606 return m_communication
->PersistConfiguration(configuration
);
1609 void CCECProcessor::RescanActiveDevices(void)
1611 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1612 m_busDevices
[iPtr
]->GetStatus(true);