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);
70 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
, uint16_t iPhysicalAddress
) :
71 m_bConnectionOpened(false),
72 m_bInitialised(false),
73 m_communication(NULL
),
74 m_controller(controller
),
76 m_iStandardLineTimeout(3),
77 m_iRetryLineTimeout(3),
78 m_iLastTransmission(0)
80 m_configuration
.Clear();
81 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_5_0
;
83 // client version < 1.5.0
84 m_configuration
.clientVersion
= (uint32_t)CEC_CLIENT_VERSION_PRE_1_5
;
85 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
);
86 m_configuration
.deviceTypes
= types
;
87 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
88 m_configuration
.baseDevice
= (cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
;
89 m_configuration
.iHDMIPort
= CEC_DEFAULT_HDMI_PORT
;
91 if (m_configuration
.deviceTypes
.IsEmpty())
92 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
93 m_logicalAddresses
.Clear();
97 void CCECProcessor::CreateBusDevices(void)
99 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
103 case CECDEVICE_AUDIOSYSTEM
:
104 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
106 case CECDEVICE_PLAYBACKDEVICE1
:
107 case CECDEVICE_PLAYBACKDEVICE2
:
108 case CECDEVICE_PLAYBACKDEVICE3
:
109 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
111 case CECDEVICE_RECORDINGDEVICE1
:
112 case CECDEVICE_RECORDINGDEVICE2
:
113 case CECDEVICE_RECORDINGDEVICE3
:
114 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
116 case CECDEVICE_TUNER1
:
117 case CECDEVICE_TUNER2
:
118 case CECDEVICE_TUNER3
:
119 case CECDEVICE_TUNER4
:
120 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
123 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
126 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
132 CCECProcessor::~CCECProcessor(void)
136 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
137 delete m_busDevices
[iPtr
];
140 void CCECProcessor::Close(void)
143 SetInitialised(false);
148 CLockObject
lock(m_mutex
);
149 bClose
= m_bConnectionOpened
;
150 m_bConnectionOpened
= false;
153 if (bClose
&& m_communication
)
155 m_communication
->Close();
156 delete m_communication
;
157 m_communication
= NULL
;
161 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
167 CLockObject
lock(m_mutex
);
168 if (m_bConnectionOpened
)
170 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
173 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
174 m_bConnectionOpened
= (m_communication
!= NULL
);
177 /* check for an already opened connection */
178 if (m_communication
->IsOpen())
180 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
184 uint64_t iNow
= GetTimeMs();
185 uint64_t iTarget
= iTimeoutMs
> 0 ? iNow
+ iTimeoutMs
: iNow
+ CEC_DEFAULT_TRANSMIT_WAIT
;
187 /* open a new connection */
188 unsigned iConnectTry(0);
189 while (iNow
< iTarget
&& (bReturn
= m_communication
->Open(this, iTimeoutMs
)) == false)
191 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
197 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
));
202 bool CCECProcessor::IsInitialised(void)
204 CLockObject
lock(m_mutex
);
205 return m_bInitialised
;
208 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
210 CLockObject
lock(m_mutex
);
211 m_bInitialised
= bSetTo
;
214 bool CCECProcessor::Initialise(void)
218 CLockObject
lock(m_mutex
);
219 if (!m_logicalAddresses
.IsEmpty())
220 m_logicalAddresses
.Clear();
222 if (!FindLogicalAddresses())
224 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
228 /* only set our OSD name for the primary device */
229 m_busDevices
[m_logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
231 /* make the primary device the active source if the option is set */
232 if (m_configuration
.bActivateSource
== 1)
233 m_busDevices
[m_logicalAddresses
.primary
]->m_bActiveSource
= true;
236 /* get the vendor id from the TV, so we are using the correct handler */
237 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
239 if (m_configuration
.iPhysicalAddress
!= 0)
241 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
242 m_busDevices
[m_logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
243 if ((bReturn
= m_busDevices
[m_logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
244 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
246 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
247 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
);
249 if (m_configuration
.bActivateSource
== 1)
250 m_busDevices
[m_logicalAddresses
.primary
]->ActivateSource();
252 SetInitialised(bReturn
);
254 CLibCEC::ConfigurationChanged(m_configuration
);
259 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
264 CLockObject
lock(m_mutex
);
265 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
268 /* create the processor thread */
271 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
276 if ((bReturn
= Initialise()) == false)
278 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
283 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
289 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
291 if (m_busDevices
[address
]->TryLogicalAddress())
293 m_logicalAddresses
.Set(address
);
300 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
302 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
303 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
304 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
305 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
308 bool CCECProcessor::FindLogicalAddressTuner(void)
310 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
311 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
312 TryLogicalAddress(CECDEVICE_TUNER2
) ||
313 TryLogicalAddress(CECDEVICE_TUNER3
) ||
314 TryLogicalAddress(CECDEVICE_TUNER4
);
317 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
319 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
320 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
321 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
322 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
325 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
327 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
328 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
331 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
333 bool bChanged(false);
335 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
337 CLockObject
lock(m_mutex
);
338 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
339 m_logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
341 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
343 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
346 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
349 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
351 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
353 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
359 FindLogicalAddresses();
361 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
362 if (previousDevice
&& newDevice
)
364 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
365 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
367 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
368 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
370 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
371 cec_menu_language lang
;
372 lang
.device
= previousDevice
->GetLogicalAddress();
373 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
374 lang
.language
[iPtr
] = '?';
375 lang
.language
[3] = 0;
376 previousDevice
->SetMenuLanguage(lang
);
378 newDevice
->SetMenuState(previousDevice
->GetMenuState());
379 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
381 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
382 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
384 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
385 previousDevice
->SetPhysicalAddress(0xFFFF);
387 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
388 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
390 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
391 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
393 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
394 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
396 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
397 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
399 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
400 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
408 bool CCECProcessor::FindLogicalAddresses(void)
411 m_logicalAddresses
.Clear();
413 if (m_configuration
.deviceTypes
.IsEmpty())
415 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
419 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
421 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
424 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
426 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
427 bReturn
&= FindLogicalAddressRecordingDevice();
428 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
429 bReturn
&= FindLogicalAddressTuner();
430 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
431 bReturn
&= FindLogicalAddressPlaybackDevice();
432 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
433 bReturn
&= FindLogicalAddressAudioSystem();
437 SetAckMask(m_logicalAddresses
.AckMask());
442 void CCECProcessor::ReplaceHandlers(void)
444 if (!IsInitialised())
446 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
447 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
450 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
452 ParseCommand(command
);
456 void *CCECProcessor::Process(void)
458 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
460 while (!IsStopped() && m_communication
->IsOpen())
466 m_controller
->CheckKeypressTimeout();
474 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
481 cec_logical_address addr
= m_logicalAddresses
.primary
;
483 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
485 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
487 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
489 addr
= (cec_logical_address
) iPtr
;
495 m_busDevices
[addr
]->SetActiveSource();
496 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
497 bReturn
= m_busDevices
[addr
]->ActivateSource();
502 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
506 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
509 device
->SetActiveSource();
516 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
518 CLockObject
lock(m_mutex
);
519 m_iStandardLineTimeout
= iTimeout
;
522 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
524 CLockObject
lock(m_mutex
);
525 m_iRetryLineTimeout
= iTimeout
;
528 bool CCECProcessor::SetActiveView(void)
530 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
531 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
534 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
538 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
541 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
543 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
550 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
554 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
557 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
559 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
566 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
571 CLockObject
lock(m_mutex
);
572 m_configuration
.baseDevice
= iBaseDevice
;
573 m_configuration
.iHDMIPort
= iPort
;
576 if (!IsRunning() && !bForce
)
579 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
581 uint16_t iPhysicalAddress(0);
582 if (iBaseDevice
> CECDEVICE_TV
)
584 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
587 if (iPhysicalAddress
< 0xffff)
589 if (iPhysicalAddress
== 0)
590 iPhysicalAddress
+= 0x1000 * iPort
;
591 else if (iPhysicalAddress
% 0x1000 == 0)
592 iPhysicalAddress
+= 0x100 * iPort
;
593 else if (iPhysicalAddress
% 0x100 == 0)
594 iPhysicalAddress
+= 0x10 * iPort
;
595 else if (iPhysicalAddress
% 0x10 == 0)
596 iPhysicalAddress
+= iPort
;
602 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
604 SetPhysicalAddress(iPhysicalAddress
);
609 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
611 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
613 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
619 bool CCECProcessor::TransmitInactiveSource(void)
624 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
625 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
629 void CCECProcessor::LogOutput(const cec_command
&data
)
632 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
634 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
636 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
637 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
638 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
641 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
643 CLockObject
lock(m_mutex
);
644 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
646 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
647 m_logicalAddresses
.primary
= iLogicalAddress
;
648 m_logicalAddresses
.Set(iLogicalAddress
);
649 return SetAckMask(m_logicalAddresses
.AckMask());
655 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
657 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
659 if (m_logicalAddresses
[iPtr
])
660 m_busDevices
[iPtr
]->SetMenuState(state
);
664 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
669 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
671 bool bSendActiveView(false);
673 cec_logical_addresses sendUpdatesTo
;
674 sendUpdatesTo
.Clear();
677 CLockObject
lock(m_mutex
);
678 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
679 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting physical address to '%4x'", iPhysicalAddress
);
681 if (!m_logicalAddresses
.IsEmpty())
683 bool bWasActiveSource(false);
684 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
685 if (m_logicalAddresses
[iPtr
])
687 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
688 m_busDevices
[iPtr
]->SetInactiveSource();
689 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
691 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
694 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
699 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
700 if (sendUpdatesTo
[iPtr
])
701 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
707 CLibCEC::ConfigurationChanged(m_configuration
);
712 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
714 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
717 CLockObject
lock(m_mutex
);
718 m_bMonitor
= bEnable
;
722 return SetAckMask(0);
724 return SetAckMask(m_logicalAddresses
.AckMask());
727 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
729 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
731 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
732 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
733 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
738 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
741 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
742 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
747 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
750 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
751 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
756 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
759 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
760 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
765 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
767 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
768 return m_busDevices
[m_logicalAddresses
.primary
];
770 CCECBusDevice
*device
= NULL
;
771 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
773 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
775 device
= m_busDevices
[iPtr
];
783 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
785 CCECBusDevice
*device
= NULL
;
787 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
789 if (m_busDevices
[iPtr
]->m_type
== type
&& m_logicalAddresses
[iPtr
])
791 device
= m_busDevices
[iPtr
];
799 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
801 CCECBusDevice
*device(NULL
);
802 cec_logical_address primary
= m_logicalAddresses
.primary
;
803 if (primary
!= CECDEVICE_UNKNOWN
)
804 device
= m_busDevices
[primary
];
808 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
810 return m_busDevices
[iAddress
]->GetCecVersion();
813 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
815 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
818 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
819 retVal
.device
= iAddress
;
824 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
826 if (m_busDevices
[iAddress
])
828 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
829 return (strcmp(language
->language
, "???") != 0);
834 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
836 if (m_busDevices
[iAddress
])
837 return m_busDevices
[iAddress
]->GetVendorId();
841 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
843 if (m_busDevices
[iAddress
])
844 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
848 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
850 if (m_busDevices
[iAddress
])
851 return m_busDevices
[iAddress
]->GetPowerStatus();
852 return CEC_POWER_STATUS_UNKNOWN
;
855 cec_logical_address
CCECProcessor::GetActiveSource(void)
857 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
859 if (m_busDevices
[iPtr
]->IsActiveSource())
860 return (cec_logical_address
)iPtr
;
863 return CECDEVICE_UNKNOWN
;
866 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
868 return m_busDevices
[iAddress
]->IsActiveSource();
871 bool CCECProcessor::Transmit(const cec_command
&data
)
873 if (m_logicalAddresses
[(uint8_t)data
.destination
])
875 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
879 uint8_t iMaxTries(0);
881 CLockObject
lock(m_mutex
);
885 m_iLastTransmission
= GetTimeMs();
886 if (!m_communication
|| !m_communication
->IsOpen())
888 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
891 iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
894 return m_communication
->Write(data
, iMaxTries
, m_iLineTimeout
, m_iRetryLineTimeout
)
895 == ADAPTER_MESSAGE_STATE_SENT_ACKED
;
898 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
900 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
904 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
905 command
.parameters
.PushBack((uint8_t)opcode
);
906 command
.parameters
.PushBack((uint8_t)reason
);
911 void CCECProcessor::ParseCommand(const cec_command
&command
)
914 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
915 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
916 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
917 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
919 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
920 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
923 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
925 cec_logical_addresses addresses
;
927 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
929 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
930 addresses
.Set((cec_logical_address
) iPtr
);
935 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
937 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
940 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
942 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
944 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
951 uint16_t CCECProcessor::GetPhysicalAddress(void) const
953 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
954 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
958 bool CCECProcessor::SetAckMask(uint16_t iMask
)
960 return m_communication
->SetAckMask(iMask
);
963 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
965 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
968 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
970 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
973 bool CCECProcessor::EnablePhysicalAddressDetection(void)
975 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
976 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
977 if (iPhysicalAddress
!= 0)
979 m_configuration
.bAutodetectAddress
= 1;
980 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
981 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
982 m_configuration
.iHDMIPort
= 0;
983 return SetPhysicalAddress(iPhysicalAddress
);
988 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
990 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
993 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
995 if (m_configuration
.powerOffDevices
[iPtr
])
996 bReturn
&= m_busDevices
[iPtr
]->Standby();
1001 return m_busDevices
[address
]->Standby();
1004 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
1006 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1009 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1011 if (m_configuration
.powerOffDevices
[iPtr
])
1012 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1017 return m_busDevices
[address
]->PowerOn();
1020 const char *CCECProcessor::ToString(const cec_device_type type
)
1024 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1025 return "audio system";
1026 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1027 return "playback device";
1028 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1029 return "recording device";
1030 case CEC_DEVICE_TYPE_RESERVED
:
1032 case CEC_DEVICE_TYPE_TUNER
:
1034 case CEC_DEVICE_TYPE_TV
:
1041 const char *CCECProcessor::ToString(const cec_menu_state state
)
1045 case CEC_MENU_STATE_ACTIVATED
:
1047 case CEC_MENU_STATE_DEACTIVATED
:
1048 return "deactivated";
1054 const char *CCECProcessor::ToString(const cec_version version
)
1058 case CEC_VERSION_1_2
:
1060 case CEC_VERSION_1_2A
:
1062 case CEC_VERSION_1_3
:
1064 case CEC_VERSION_1_3A
:
1066 case CEC_VERSION_1_4
:
1073 const char *CCECProcessor::ToString(const cec_power_status status
)
1077 case CEC_POWER_STATUS_ON
:
1079 case CEC_POWER_STATUS_STANDBY
:
1081 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1082 return "in transition from on to standby";
1083 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1084 return "in transition from standby to on";
1090 const char *CCECProcessor::ToString(const cec_logical_address address
)
1094 case CECDEVICE_AUDIOSYSTEM
:
1096 case CECDEVICE_BROADCAST
:
1098 case CECDEVICE_FREEUSE
:
1100 case CECDEVICE_PLAYBACKDEVICE1
:
1101 return "Playback 1";
1102 case CECDEVICE_PLAYBACKDEVICE2
:
1103 return "Playback 2";
1104 case CECDEVICE_PLAYBACKDEVICE3
:
1105 return "Playback 3";
1106 case CECDEVICE_RECORDINGDEVICE1
:
1107 return "Recorder 1";
1108 case CECDEVICE_RECORDINGDEVICE2
:
1109 return "Recorder 2";
1110 case CECDEVICE_RECORDINGDEVICE3
:
1111 return "Recorder 3";
1112 case CECDEVICE_RESERVED1
:
1113 return "Reserved 1";
1114 case CECDEVICE_RESERVED2
:
1115 return "Reserved 2";
1116 case CECDEVICE_TUNER1
:
1118 case CECDEVICE_TUNER2
:
1120 case CECDEVICE_TUNER3
:
1122 case CECDEVICE_TUNER4
:
1131 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1135 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1136 return "skip forward wind";
1137 case CEC_DECK_CONTROL_MODE_EJECT
:
1139 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1140 return "reverse rewind";
1141 case CEC_DECK_CONTROL_MODE_STOP
:
1148 const char *CCECProcessor::ToString(const cec_deck_info status
)
1152 case CEC_DECK_INFO_PLAY
:
1154 case CEC_DECK_INFO_RECORD
:
1156 case CEC_DECK_INFO_PLAY_REVERSE
:
1157 return "play reverse";
1158 case CEC_DECK_INFO_STILL
:
1160 case CEC_DECK_INFO_SLOW
:
1162 case CEC_DECK_INFO_SLOW_REVERSE
:
1163 return "slow reverse";
1164 case CEC_DECK_INFO_FAST_FORWARD
:
1165 return "fast forward";
1166 case CEC_DECK_INFO_FAST_REVERSE
:
1167 return "fast reverse";
1168 case CEC_DECK_INFO_NO_MEDIA
:
1170 case CEC_DECK_INFO_STOP
:
1172 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1173 return "info skip forward wind";
1174 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1175 return "info skip reverse rewind";
1176 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1177 return "info index search forward";
1178 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1179 return "info index search reverse";
1180 case CEC_DECK_INFO_OTHER_STATUS
:
1187 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1191 case CEC_OPCODE_ACTIVE_SOURCE
:
1192 return "active source";
1193 case CEC_OPCODE_IMAGE_VIEW_ON
:
1194 return "image view on";
1195 case CEC_OPCODE_TEXT_VIEW_ON
:
1196 return "text view on";
1197 case CEC_OPCODE_INACTIVE_SOURCE
:
1198 return "inactive source";
1199 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1200 return "request active source";
1201 case CEC_OPCODE_ROUTING_CHANGE
:
1202 return "routing change";
1203 case CEC_OPCODE_ROUTING_INFORMATION
:
1204 return "routing information";
1205 case CEC_OPCODE_SET_STREAM_PATH
:
1206 return "set stream path";
1207 case CEC_OPCODE_STANDBY
:
1209 case CEC_OPCODE_RECORD_OFF
:
1210 return "record off";
1211 case CEC_OPCODE_RECORD_ON
:
1213 case CEC_OPCODE_RECORD_STATUS
:
1214 return "record status";
1215 case CEC_OPCODE_RECORD_TV_SCREEN
:
1216 return "record tv screen";
1217 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1218 return "clear analogue timer";
1219 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1220 return "clear digital timer";
1221 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1222 return "clear external timer";
1223 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1224 return "set analogue timer";
1225 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1226 return "set digital timer";
1227 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1228 return "set external timer";
1229 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1230 return "set timer program title";
1231 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1232 return "timer cleared status";
1233 case CEC_OPCODE_TIMER_STATUS
:
1234 return "timer status";
1235 case CEC_OPCODE_CEC_VERSION
:
1236 return "cec version";
1237 case CEC_OPCODE_GET_CEC_VERSION
:
1238 return "get cec version";
1239 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1240 return "give physical address";
1241 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1242 return "get menu language";
1243 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1244 return "report physical address";
1245 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1246 return "set menu language";
1247 case CEC_OPCODE_DECK_CONTROL
:
1248 return "deck control";
1249 case CEC_OPCODE_DECK_STATUS
:
1250 return "deck status";
1251 case CEC_OPCODE_GIVE_DECK_STATUS
:
1252 return "give deck status";
1253 case CEC_OPCODE_PLAY
:
1255 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1256 return "give tuner status";
1257 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1258 return "select analogue service";
1259 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1260 return "set digital service";
1261 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1262 return "tuner device status";
1263 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1264 return "tuner step decrement";
1265 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1266 return "tuner step increment";
1267 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1268 return "device vendor id";
1269 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1270 return "give device vendor id";
1271 case CEC_OPCODE_VENDOR_COMMAND
:
1272 return "vendor command";
1273 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1274 return "vendor command with id";
1275 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1276 return "vendor remote button down";
1277 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1278 return "vendor remote button up";
1279 case CEC_OPCODE_SET_OSD_STRING
:
1280 return "set osd string";
1281 case CEC_OPCODE_GIVE_OSD_NAME
:
1282 return "give osd name";
1283 case CEC_OPCODE_SET_OSD_NAME
:
1284 return "set osd name";
1285 case CEC_OPCODE_MENU_REQUEST
:
1286 return "menu request";
1287 case CEC_OPCODE_MENU_STATUS
:
1288 return "menu status";
1289 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1290 return "user control pressed";
1291 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1292 return "user control release";
1293 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1294 return "give device power status";
1295 case CEC_OPCODE_REPORT_POWER_STATUS
:
1296 return "report power status";
1297 case CEC_OPCODE_FEATURE_ABORT
:
1298 return "feature abort";
1299 case CEC_OPCODE_ABORT
:
1301 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1302 return "give audio status";
1303 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1304 return "give audio mode status";
1305 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1306 return "report audio status";
1307 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1308 return "set system audio mode";
1309 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1310 return "system audio mode request";
1311 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1312 return "system audio mode status";
1313 case CEC_OPCODE_SET_AUDIO_RATE
:
1314 return "set audio rate";
1315 case CEC_OPCODE_NONE
:
1322 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1326 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1328 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1335 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1337 // TODO this is a mask
1341 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1345 case CEC_VENDOR_SAMSUNG
:
1349 case CEC_VENDOR_PANASONIC
:
1351 case CEC_VENDOR_PIONEER
:
1353 case CEC_VENDOR_ONKYO
:
1355 case CEC_VENDOR_YAMAHA
:
1357 case CEC_VENDOR_PHILIPS
:
1359 case CEC_VENDOR_SONY
:
1361 case CEC_VENDOR_TOSHIBA
:
1368 const char *CCECProcessor::ToString(const cec_client_version version
)
1372 case CEC_CLIENT_VERSION_PRE_1_5
:
1374 case CEC_CLIENT_VERSION_1_5_0
:
1381 const char *CCECProcessor::ToString(const cec_server_version version
)
1385 case CEC_SERVER_VERSION_PRE_1_5
:
1387 case CEC_SERVER_VERSION_1_5_0
:
1394 void *CCECBusScan::Process(void)
1396 CCECBusDevice
*device(NULL
);
1397 uint8_t iCounter(0);
1399 while (!IsStopped())
1401 if (++iCounter
< 10)
1406 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1408 device
= m_processor
->m_busDevices
[iPtr
];
1410 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1414 device
->GetVendorId();
1418 device
->GetPowerStatus(true);
1426 void CCECBusScan::WaitUntilIdle(void)
1431 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1432 while (iWaitTime
> 0)
1435 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1439 bool CCECProcessor::StartBootloader(void)
1441 return m_communication
->StartBootloader();
1444 bool CCECProcessor::PingAdapter(void)
1446 return m_communication
->PingAdapter();
1449 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1451 m_busDevices
[initiator
]->HandlePoll(destination
);
1454 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1456 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1459 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1461 // stream path changes are sent by the TV
1462 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1465 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1467 bool bReinit(false);
1468 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1469 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1470 m_configuration
.clientVersion
= configuration
->clientVersion
;
1472 // client version 1.5.0
1475 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1476 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1478 bool bPhysicalAddressChanged(false);
1480 // autodetect address
1481 bool bPhysicalAutodetected(false);
1482 if (IsRunning() && configuration
->bAutodetectAddress
== 1)
1484 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
1485 if (iPhysicalAddress
!= 0)
1488 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%4x'", __FUNCTION__
, iPhysicalAddress
);
1489 bPhysicalAddressChanged
= (m_configuration
.iPhysicalAddress
!= iPhysicalAddress
);
1490 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1491 m_configuration
.iHDMIPort
= 0;
1492 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1493 bPhysicalAutodetected
= true;
1498 if (!bPhysicalAutodetected
)
1500 if (configuration
->iPhysicalAddress
!= 0)
1501 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1503 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using physical address '%4x'", __FUNCTION__
, configuration
->iPhysicalAddress
);
1504 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1507 bool bHdmiPortChanged(false);
1508 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1511 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1513 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using base device '%x'", __FUNCTION__
, (int)configuration
->baseDevice
);
1514 m_configuration
.baseDevice
= configuration
->baseDevice
;
1517 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1519 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using HDMI port '%d'", __FUNCTION__
, configuration
->iHDMIPort
);
1520 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1525 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
1526 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1527 m_configuration
.iHDMIPort
= 0;
1530 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
;
1533 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1534 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1536 primary
->SetOSDName(m_configuration
.strDeviceName
);
1537 if (!bReinit
&& IsRunning())
1538 primary
->TransmitOSDName(CECDEVICE_TV
);
1541 // tv vendor id override
1542 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1544 m_configuration
.tvVendor
= configuration
->tvVendor
;
1545 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1549 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1551 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1552 if (!bReinit
&& IsRunning())
1557 m_configuration
.clientVersion
= configuration
->clientVersion
;
1558 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1559 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1560 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1561 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1562 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1564 // ensure that there is at least 1 device type set
1565 if (m_configuration
.deviceTypes
.IsEmpty())
1566 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1570 if (bDeviceTypeChanged
)
1571 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1572 else if (bPhysicalAddressChanged
)
1573 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1575 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1581 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1583 // client version 1.5.0
1584 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1585 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1586 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1587 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1588 configuration
->baseDevice
= m_configuration
.baseDevice
;
1589 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1590 configuration
->clientVersion
= m_configuration
.clientVersion
;
1591 configuration
->serverVersion
= m_configuration
.serverVersion
;
1592 configuration
->tvVendor
= m_configuration
.tvVendor
;
1594 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1595 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1596 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1597 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1598 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1599 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1600 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1605 bool CCECProcessor::CanPersistConfiguration(void)
1607 return m_communication
->GetFirmwareVersion() >= 2;
1610 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1612 return m_communication
->PersistConfiguration(configuration
);
1615 void CCECProcessor::RescanActiveDevices(void)
1617 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1618 m_busDevices
[iPtr
]->GetStatus(true);