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_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();
62 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_5_0
;
63 SetConfiguration(configuration
);
65 if (m_configuration
.tvVendor
!= CEC_VENDOR_UNKNOWN
)
66 m_busDevices
[CECDEVICE_TV
]->ReplaceHandler(false);
68 GetCurrentConfiguration(configuration
);
71 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
, uint16_t iPhysicalAddress
) :
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);
146 CLockObject
lock(m_mutex
);
149 m_communication
->Close();
150 delete m_communication
;
151 m_communication
= NULL
;
155 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
158 CLockObject
lock(m_mutex
);
161 CLibCEC::AddLog(CEC_LOG_WARNING
, "existing connection handler found, deleting it");
162 m_communication
->Close();
163 delete m_communication
;
166 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
168 /* check for an already opened connection */
169 if (m_communication
->IsOpen())
171 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
175 uint64_t iNow
= GetTimeMs();
176 uint64_t iTarget
= iTimeoutMs
> 0 ? iNow
+ iTimeoutMs
: iNow
+ CEC_DEFAULT_TRANSMIT_WAIT
;
178 /* open a new connection */
179 unsigned iConnectTry(0);
180 while (iNow
< iTarget
&& (bReturn
= m_communication
->Open(this, iTimeoutMs
)) == false)
182 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
188 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
));
193 bool CCECProcessor::IsInitialised(void)
195 CLockObject
lock(m_mutex
);
196 return m_bInitialised
;
199 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
201 CLockObject
lock(m_mutex
);
202 m_bInitialised
= bSetTo
;
205 bool CCECProcessor::Initialise(void)
209 CLockObject
lock(m_mutex
);
210 if (!m_logicalAddresses
.IsEmpty())
211 m_logicalAddresses
.Clear();
213 if (!FindLogicalAddresses())
215 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
219 /* only set our OSD name for the primary device */
220 m_busDevices
[m_logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
223 /* get the vendor id from the TV, so we are using the correct handler */
224 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
226 if (m_configuration
.iPhysicalAddress
!= 0)
228 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
229 m_busDevices
[m_logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
230 if ((bReturn
= m_busDevices
[m_logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
231 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
233 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
234 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
);
236 SetInitialised(bReturn
);
237 CLibCEC::ConfigurationChanged(m_configuration
);
242 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
247 CLockObject
lock(m_mutex
);
248 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
251 /* create the processor thread */
254 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
259 if ((bReturn
= Initialise()) == false)
261 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
266 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
272 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
274 if (m_busDevices
[address
]->TryLogicalAddress())
276 m_logicalAddresses
.Set(address
);
283 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
285 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
286 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
287 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
288 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
291 bool CCECProcessor::FindLogicalAddressTuner(void)
293 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
294 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
295 TryLogicalAddress(CECDEVICE_TUNER2
) ||
296 TryLogicalAddress(CECDEVICE_TUNER3
) ||
297 TryLogicalAddress(CECDEVICE_TUNER4
);
300 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
302 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
303 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
304 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
305 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
308 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
310 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
311 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
314 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
316 bool bChanged(false);
318 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
320 CLockObject
lock(m_mutex
);
321 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
322 m_logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
324 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
326 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
329 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
332 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
334 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
336 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
342 FindLogicalAddresses();
344 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
345 if (previousDevice
&& newDevice
)
347 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
348 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
350 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
351 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
353 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
354 cec_menu_language lang
;
355 lang
.device
= previousDevice
->GetLogicalAddress();
356 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
357 lang
.language
[iPtr
] = '?';
358 lang
.language
[3] = 0;
359 previousDevice
->SetMenuLanguage(lang
);
361 newDevice
->SetMenuState(previousDevice
->GetMenuState());
362 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
364 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
365 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
367 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
368 previousDevice
->SetPhysicalAddress(0xFFFF);
370 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
371 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
373 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
374 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
376 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
377 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
379 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
380 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
382 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
383 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
391 bool CCECProcessor::FindLogicalAddresses(void)
394 m_logicalAddresses
.Clear();
396 if (m_configuration
.deviceTypes
.IsEmpty())
398 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
402 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
404 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
407 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
409 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
410 bReturn
&= FindLogicalAddressRecordingDevice();
411 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
412 bReturn
&= FindLogicalAddressTuner();
413 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
414 bReturn
&= FindLogicalAddressPlaybackDevice();
415 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
416 bReturn
&= FindLogicalAddressAudioSystem();
420 SetAckMask(m_logicalAddresses
.AckMask());
425 void CCECProcessor::ReplaceHandlers(void)
427 if (!IsInitialised())
429 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
430 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
433 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
435 ParseCommand(command
);
439 void *CCECProcessor::Process(void)
441 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
443 while (!IsStopped() && m_communication
->IsOpen())
449 m_controller
->CheckKeypressTimeout();
457 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
464 cec_logical_address addr
= m_logicalAddresses
.primary
;
466 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
468 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
470 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
472 addr
= (cec_logical_address
) iPtr
;
478 m_busDevices
[addr
]->SetActiveSource();
479 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
480 bReturn
= m_busDevices
[addr
]->ActivateSource();
485 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
489 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
492 device
->SetActiveSource();
499 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
501 CLockObject
lock(m_mutex
);
502 m_iStandardLineTimeout
= iTimeout
;
505 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
507 CLockObject
lock(m_mutex
);
508 m_iRetryLineTimeout
= iTimeout
;
511 bool CCECProcessor::SetActiveView(void)
513 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
514 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
517 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
521 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
524 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
526 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
533 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
537 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
540 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
542 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
549 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
554 CLockObject
lock(m_mutex
);
555 m_configuration
.baseDevice
= iBaseDevice
;
556 m_configuration
.iHDMIPort
= iPort
;
557 m_configuration
.bAutodetectAddress
= false;
560 if (!IsRunning() && !bForce
)
563 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
565 uint16_t iPhysicalAddress(0);
566 if (iBaseDevice
> CECDEVICE_TV
)
568 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
571 if (iPhysicalAddress
< 0xffff)
573 if (iPhysicalAddress
== 0)
574 iPhysicalAddress
+= 0x1000 * iPort
;
575 else if (iPhysicalAddress
% 0x1000 == 0)
576 iPhysicalAddress
+= 0x100 * iPort
;
577 else if (iPhysicalAddress
% 0x100 == 0)
578 iPhysicalAddress
+= 0x10 * iPort
;
579 else if (iPhysicalAddress
% 0x10 == 0)
580 iPhysicalAddress
+= iPort
;
586 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
588 SetPhysicalAddress(iPhysicalAddress
);
593 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
595 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
597 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
603 bool CCECProcessor::TransmitInactiveSource(void)
608 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
609 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
613 void CCECProcessor::LogOutput(const cec_command
&data
)
616 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
618 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
620 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
621 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
622 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
625 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
627 CLockObject
lock(m_mutex
);
628 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
630 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
631 m_logicalAddresses
.primary
= iLogicalAddress
;
632 m_logicalAddresses
.Set(iLogicalAddress
);
633 return SetAckMask(m_logicalAddresses
.AckMask());
639 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
641 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
643 if (m_logicalAddresses
[iPtr
])
644 m_busDevices
[iPtr
]->SetMenuState(state
);
648 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
653 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
655 bool bSendActiveView(false);
657 cec_logical_addresses sendUpdatesTo
;
658 sendUpdatesTo
.Clear();
661 CLockObject
lock(m_mutex
);
662 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
663 if (m_configuration
.bAutodetectAddress
)
665 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
666 m_configuration
.iHDMIPort
= 0;
669 if (!m_logicalAddresses
.IsEmpty())
671 bool bWasActiveSource(false);
672 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
673 if (m_logicalAddresses
[iPtr
])
675 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
676 m_busDevices
[iPtr
]->SetInactiveSource();
677 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
679 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
682 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
687 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
688 if (sendUpdatesTo
[iPtr
])
689 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
695 CLibCEC::ConfigurationChanged(m_configuration
);
700 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
702 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
705 CLockObject
lock(m_mutex
);
706 m_bMonitor
= bEnable
;
710 return SetAckMask(0);
712 return SetAckMask(m_logicalAddresses
.AckMask());
715 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
717 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
719 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
720 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
721 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
726 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
729 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
730 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
735 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
738 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
739 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
744 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
747 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
748 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
753 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
755 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
756 return m_busDevices
[m_logicalAddresses
.primary
];
758 CCECBusDevice
*device
= NULL
;
759 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
761 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
763 device
= m_busDevices
[iPtr
];
771 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
773 CCECBusDevice
*device
= NULL
;
775 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
777 if (m_busDevices
[iPtr
]->m_type
== type
&& m_logicalAddresses
[iPtr
])
779 device
= m_busDevices
[iPtr
];
787 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
789 CCECBusDevice
*device(NULL
);
790 cec_logical_address primary
= m_logicalAddresses
.primary
;
791 if (primary
!= CECDEVICE_UNKNOWN
)
792 device
= m_busDevices
[primary
];
796 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
798 return m_busDevices
[iAddress
]->GetCecVersion();
801 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
803 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
806 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
807 retVal
.device
= iAddress
;
812 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
814 if (m_busDevices
[iAddress
])
816 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
817 return (strcmp(language
->language
, "???") != 0);
822 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
824 if (m_busDevices
[iAddress
])
825 return m_busDevices
[iAddress
]->GetVendorId();
829 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
831 if (m_busDevices
[iAddress
])
832 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
836 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
838 if (m_busDevices
[iAddress
])
839 return m_busDevices
[iAddress
]->GetPowerStatus();
840 return CEC_POWER_STATUS_UNKNOWN
;
843 cec_logical_address
CCECProcessor::GetActiveSource(void)
845 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
847 if (m_busDevices
[iPtr
]->IsActiveSource())
848 return (cec_logical_address
)iPtr
;
851 return CECDEVICE_UNKNOWN
;
854 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
856 return m_busDevices
[iAddress
]->IsActiveSource();
859 bool CCECProcessor::Transmit(const cec_command
&data
)
861 if (m_logicalAddresses
[(uint8_t)data
.destination
])
863 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
867 cec_adapter_message_state
retVal(ADAPTER_MESSAGE_STATE_UNKNOWN
);
869 CLockObject
lock(m_mutex
);
871 m_iLastTransmission
= GetTimeMs();
872 if (!m_communication
|| !m_communication
->IsOpen())
874 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
877 uint8_t iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
878 retVal
= m_communication
->Write(data
, iMaxTries
, m_iLineTimeout
, m_iRetryLineTimeout
);
881 /* set to "not present" on failed ack */
882 if (retVal
== ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED
&&
883 data
.destination
!= CECDEVICE_BROADCAST
)
884 m_busDevices
[data
.destination
]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
886 return retVal
== ADAPTER_MESSAGE_STATE_SENT_ACKED
;
889 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
891 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
895 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
896 command
.parameters
.PushBack((uint8_t)opcode
);
897 command
.parameters
.PushBack((uint8_t)reason
);
902 void CCECProcessor::ParseCommand(const cec_command
&command
)
905 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
906 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
907 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
908 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
910 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
911 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
914 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
916 cec_logical_addresses addresses
;
918 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
920 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
921 addresses
.Set((cec_logical_address
) iPtr
);
926 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
928 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
931 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
933 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
935 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
942 uint16_t CCECProcessor::GetPhysicalAddress(void) const
944 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
945 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
949 bool CCECProcessor::SetAckMask(uint16_t iMask
)
951 return m_communication
->SetAckMask(iMask
);
954 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
956 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
959 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
961 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
964 bool CCECProcessor::EnablePhysicalAddressDetection(void)
966 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
967 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
968 if (iPhysicalAddress
!= 0)
970 m_configuration
.bAutodetectAddress
= 1;
971 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
972 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
973 m_configuration
.iHDMIPort
= 0;
974 return SetPhysicalAddress(iPhysicalAddress
);
979 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
981 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
984 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
986 if (m_configuration
.powerOffDevices
[iPtr
])
987 bReturn
&= m_busDevices
[iPtr
]->Standby();
992 return m_busDevices
[address
]->Standby();
995 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
997 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1000 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1002 if (m_configuration
.powerOffDevices
[iPtr
])
1003 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1008 return m_busDevices
[address
]->PowerOn();
1011 const char *CCECProcessor::ToString(const cec_device_type type
)
1015 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1016 return "audio system";
1017 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1018 return "playback device";
1019 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1020 return "recording device";
1021 case CEC_DEVICE_TYPE_RESERVED
:
1023 case CEC_DEVICE_TYPE_TUNER
:
1025 case CEC_DEVICE_TYPE_TV
:
1032 const char *CCECProcessor::ToString(const cec_menu_state state
)
1036 case CEC_MENU_STATE_ACTIVATED
:
1038 case CEC_MENU_STATE_DEACTIVATED
:
1039 return "deactivated";
1045 const char *CCECProcessor::ToString(const cec_version version
)
1049 case CEC_VERSION_1_2
:
1051 case CEC_VERSION_1_2A
:
1053 case CEC_VERSION_1_3
:
1055 case CEC_VERSION_1_3A
:
1057 case CEC_VERSION_1_4
:
1064 const char *CCECProcessor::ToString(const cec_power_status status
)
1068 case CEC_POWER_STATUS_ON
:
1070 case CEC_POWER_STATUS_STANDBY
:
1072 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1073 return "in transition from on to standby";
1074 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1075 return "in transition from standby to on";
1081 const char *CCECProcessor::ToString(const cec_logical_address address
)
1085 case CECDEVICE_AUDIOSYSTEM
:
1087 case CECDEVICE_BROADCAST
:
1089 case CECDEVICE_FREEUSE
:
1091 case CECDEVICE_PLAYBACKDEVICE1
:
1092 return "Playback 1";
1093 case CECDEVICE_PLAYBACKDEVICE2
:
1094 return "Playback 2";
1095 case CECDEVICE_PLAYBACKDEVICE3
:
1096 return "Playback 3";
1097 case CECDEVICE_RECORDINGDEVICE1
:
1098 return "Recorder 1";
1099 case CECDEVICE_RECORDINGDEVICE2
:
1100 return "Recorder 2";
1101 case CECDEVICE_RECORDINGDEVICE3
:
1102 return "Recorder 3";
1103 case CECDEVICE_RESERVED1
:
1104 return "Reserved 1";
1105 case CECDEVICE_RESERVED2
:
1106 return "Reserved 2";
1107 case CECDEVICE_TUNER1
:
1109 case CECDEVICE_TUNER2
:
1111 case CECDEVICE_TUNER3
:
1113 case CECDEVICE_TUNER4
:
1122 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1126 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1127 return "skip forward wind";
1128 case CEC_DECK_CONTROL_MODE_EJECT
:
1130 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1131 return "reverse rewind";
1132 case CEC_DECK_CONTROL_MODE_STOP
:
1139 const char *CCECProcessor::ToString(const cec_deck_info status
)
1143 case CEC_DECK_INFO_PLAY
:
1145 case CEC_DECK_INFO_RECORD
:
1147 case CEC_DECK_INFO_PLAY_REVERSE
:
1148 return "play reverse";
1149 case CEC_DECK_INFO_STILL
:
1151 case CEC_DECK_INFO_SLOW
:
1153 case CEC_DECK_INFO_SLOW_REVERSE
:
1154 return "slow reverse";
1155 case CEC_DECK_INFO_FAST_FORWARD
:
1156 return "fast forward";
1157 case CEC_DECK_INFO_FAST_REVERSE
:
1158 return "fast reverse";
1159 case CEC_DECK_INFO_NO_MEDIA
:
1161 case CEC_DECK_INFO_STOP
:
1163 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1164 return "info skip forward wind";
1165 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1166 return "info skip reverse rewind";
1167 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1168 return "info index search forward";
1169 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1170 return "info index search reverse";
1171 case CEC_DECK_INFO_OTHER_STATUS
:
1178 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1182 case CEC_OPCODE_ACTIVE_SOURCE
:
1183 return "active source";
1184 case CEC_OPCODE_IMAGE_VIEW_ON
:
1185 return "image view on";
1186 case CEC_OPCODE_TEXT_VIEW_ON
:
1187 return "text view on";
1188 case CEC_OPCODE_INACTIVE_SOURCE
:
1189 return "inactive source";
1190 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1191 return "request active source";
1192 case CEC_OPCODE_ROUTING_CHANGE
:
1193 return "routing change";
1194 case CEC_OPCODE_ROUTING_INFORMATION
:
1195 return "routing information";
1196 case CEC_OPCODE_SET_STREAM_PATH
:
1197 return "set stream path";
1198 case CEC_OPCODE_STANDBY
:
1200 case CEC_OPCODE_RECORD_OFF
:
1201 return "record off";
1202 case CEC_OPCODE_RECORD_ON
:
1204 case CEC_OPCODE_RECORD_STATUS
:
1205 return "record status";
1206 case CEC_OPCODE_RECORD_TV_SCREEN
:
1207 return "record tv screen";
1208 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1209 return "clear analogue timer";
1210 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1211 return "clear digital timer";
1212 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1213 return "clear external timer";
1214 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1215 return "set analogue timer";
1216 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1217 return "set digital timer";
1218 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1219 return "set external timer";
1220 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1221 return "set timer program title";
1222 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1223 return "timer cleared status";
1224 case CEC_OPCODE_TIMER_STATUS
:
1225 return "timer status";
1226 case CEC_OPCODE_CEC_VERSION
:
1227 return "cec version";
1228 case CEC_OPCODE_GET_CEC_VERSION
:
1229 return "get cec version";
1230 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1231 return "give physical address";
1232 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1233 return "get menu language";
1234 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1235 return "report physical address";
1236 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1237 return "set menu language";
1238 case CEC_OPCODE_DECK_CONTROL
:
1239 return "deck control";
1240 case CEC_OPCODE_DECK_STATUS
:
1241 return "deck status";
1242 case CEC_OPCODE_GIVE_DECK_STATUS
:
1243 return "give deck status";
1244 case CEC_OPCODE_PLAY
:
1246 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1247 return "give tuner status";
1248 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1249 return "select analogue service";
1250 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1251 return "set digital service";
1252 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1253 return "tuner device status";
1254 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1255 return "tuner step decrement";
1256 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1257 return "tuner step increment";
1258 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1259 return "device vendor id";
1260 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1261 return "give device vendor id";
1262 case CEC_OPCODE_VENDOR_COMMAND
:
1263 return "vendor command";
1264 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1265 return "vendor command with id";
1266 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1267 return "vendor remote button down";
1268 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1269 return "vendor remote button up";
1270 case CEC_OPCODE_SET_OSD_STRING
:
1271 return "set osd string";
1272 case CEC_OPCODE_GIVE_OSD_NAME
:
1273 return "give osd name";
1274 case CEC_OPCODE_SET_OSD_NAME
:
1275 return "set osd name";
1276 case CEC_OPCODE_MENU_REQUEST
:
1277 return "menu request";
1278 case CEC_OPCODE_MENU_STATUS
:
1279 return "menu status";
1280 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1281 return "user control pressed";
1282 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1283 return "user control release";
1284 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1285 return "give device power status";
1286 case CEC_OPCODE_REPORT_POWER_STATUS
:
1287 return "report power status";
1288 case CEC_OPCODE_FEATURE_ABORT
:
1289 return "feature abort";
1290 case CEC_OPCODE_ABORT
:
1292 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1293 return "give audio status";
1294 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1295 return "give audio mode status";
1296 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1297 return "report audio status";
1298 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1299 return "set system audio mode";
1300 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1301 return "system audio mode request";
1302 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1303 return "system audio mode status";
1304 case CEC_OPCODE_SET_AUDIO_RATE
:
1305 return "set audio rate";
1311 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1315 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1317 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1324 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1326 // TODO this is a mask
1330 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1334 case CEC_VENDOR_SAMSUNG
:
1338 case CEC_VENDOR_PANASONIC
:
1340 case CEC_VENDOR_PIONEER
:
1342 case CEC_VENDOR_ONKYO
:
1344 case CEC_VENDOR_YAMAHA
:
1346 case CEC_VENDOR_PHILIPS
:
1348 case CEC_VENDOR_SONY
:
1355 const char *CCECProcessor::ToString(const cec_client_version version
)
1359 case CEC_CLIENT_VERSION_PRE_1_5
:
1361 case CEC_CLIENT_VERSION_1_5_0
:
1368 const char *CCECProcessor::ToString(const cec_server_version version
)
1372 case CEC_SERVER_VERSION_PRE_1_5
:
1374 case CEC_SERVER_VERSION_1_5_0
:
1381 void *CCECBusScan::Process(void)
1383 CCECBusDevice
*device(NULL
);
1384 uint8_t iCounter(0);
1386 while (!IsStopped())
1388 if (++iCounter
< 10)
1393 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1395 device
= m_processor
->m_busDevices
[iPtr
];
1397 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1401 device
->GetVendorId();
1405 device
->GetPowerStatus(true);
1413 void CCECBusScan::WaitUntilIdle(void)
1418 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1419 while (iWaitTime
> 0)
1422 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1426 bool CCECProcessor::StartBootloader(void)
1428 return m_communication
->StartBootloader();
1431 bool CCECProcessor::PingAdapter(void)
1433 return m_communication
->PingAdapter();
1436 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1438 m_busDevices
[initiator
]->HandlePoll(destination
);
1441 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1443 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1446 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1448 // stream path changes are sent by the TV
1449 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1452 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1454 bool bReinit(false);
1455 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1456 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1457 m_configuration
.clientVersion
= configuration
->clientVersion
;
1459 // client version 1.5.0
1462 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1463 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1465 // autodetect address
1466 uint16_t iPhysicalAddress
= IsRunning() && configuration
->bAutodetectAddress
? m_communication
->GetPhysicalAddress() : 0;
1467 bool bPhysicalAutodetected
= IsRunning() && configuration
->bAutodetectAddress
&& iPhysicalAddress
!= m_configuration
.iPhysicalAddress
&& iPhysicalAddress
!= 0;
1468 if (bPhysicalAutodetected
)
1470 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1471 m_configuration
.bAutodetectAddress
= true;
1475 m_configuration
.bAutodetectAddress
= false;
1479 bool bPhysicalAddressChanged(false);
1480 if (!bPhysicalAutodetected
)
1482 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1483 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1487 bool bHdmiPortChanged(false);
1488 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1490 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1491 m_configuration
.baseDevice
= configuration
->baseDevice
;
1495 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1499 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1501 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1502 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1506 m_configuration
.iHDMIPort
= 0;
1509 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
|| bPhysicalAutodetected
;
1512 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1513 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1515 primary
->SetOSDName(m_configuration
.strDeviceName
);
1516 if (!bReinit
&& IsRunning())
1517 primary
->TransmitOSDName(CECDEVICE_TV
);
1520 // tv vendor id override
1521 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1523 m_configuration
.tvVendor
= configuration
->tvVendor
;
1524 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1528 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1530 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1531 if (!bReinit
&& IsRunning())
1536 m_configuration
.clientVersion
= configuration
->clientVersion
;
1537 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1538 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1539 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1540 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1541 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1543 // ensure that there is at least 1 device type set
1544 if (m_configuration
.deviceTypes
.IsEmpty())
1545 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1549 if (bDeviceTypeChanged
)
1550 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1551 else if (bPhysicalAddressChanged
)
1552 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1554 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1560 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1562 // client version 1.5.0
1563 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1564 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1565 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1566 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1567 configuration
->baseDevice
= m_configuration
.baseDevice
;
1568 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1569 configuration
->clientVersion
= m_configuration
.clientVersion
;
1570 configuration
->serverVersion
= m_configuration
.serverVersion
;
1571 configuration
->tvVendor
= m_configuration
.tvVendor
;
1573 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1574 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1575 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1576 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1577 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1578 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1579 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1584 bool CCECProcessor::CanPersistConfiguration(void)
1586 return m_communication
->GetFirmwareVersion() >= 2;
1589 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1591 return m_communication
->PersistConfiguration(configuration
);
1594 void CCECProcessor::RescanActiveDevices(void)
1596 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1597 m_busDevices
[iPtr
]->GetStatus(true);