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)
61 m_configuration
.Clear();
62 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_6_0
;
63 SetConfiguration(configuration
);
65 if (m_configuration
.tvVendor
!= CEC_VENDOR_UNKNOWN
)
66 m_busDevices
[CECDEVICE_TV
]->ReplaceHandler(false);
69 CCECProcessor::CCECProcessor(CLibCEC
*controller
, const char *strDeviceName
, const cec_device_type_list
&types
, uint16_t iPhysicalAddress
) :
70 m_bConnectionOpened(false),
71 m_bInitialised(false),
72 m_communication(NULL
),
73 m_controller(controller
),
75 m_iStandardLineTimeout(3),
76 m_iRetryLineTimeout(3),
77 m_iLastTransmission(0)
79 m_configuration
.Clear();
80 m_configuration
.serverVersion
= CEC_SERVER_VERSION_1_6_0
;
82 // client version < 1.5.0
83 m_configuration
.clientVersion
= (uint32_t)CEC_CLIENT_VERSION_PRE_1_5
;
84 snprintf(m_configuration
.strDeviceName
, 13, "%s", strDeviceName
);
85 m_configuration
.deviceTypes
= types
;
86 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
87 m_configuration
.baseDevice
= (cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
;
88 m_configuration
.iHDMIPort
= CEC_DEFAULT_HDMI_PORT
;
90 if (m_configuration
.deviceTypes
.IsEmpty())
91 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
95 void CCECProcessor::CreateBusDevices(void)
97 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
101 case CECDEVICE_AUDIOSYSTEM
:
102 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
104 case CECDEVICE_PLAYBACKDEVICE1
:
105 case CECDEVICE_PLAYBACKDEVICE2
:
106 case CECDEVICE_PLAYBACKDEVICE3
:
107 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
109 case CECDEVICE_RECORDINGDEVICE1
:
110 case CECDEVICE_RECORDINGDEVICE2
:
111 case CECDEVICE_RECORDINGDEVICE3
:
112 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
114 case CECDEVICE_TUNER1
:
115 case CECDEVICE_TUNER2
:
116 case CECDEVICE_TUNER3
:
117 case CECDEVICE_TUNER4
:
118 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
121 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
124 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
130 CCECProcessor::~CCECProcessor(void)
134 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
136 delete m_busDevices
[iPtr
];
137 m_busDevices
[iPtr
] = NULL
;
141 void CCECProcessor::Close(void)
144 SetInitialised(false);
149 CLockObject
lock(m_mutex
);
150 bClose
= m_bConnectionOpened
;
151 m_bConnectionOpened
= false;
154 if (bClose
&& m_communication
)
156 m_communication
->PersistConfiguration(&m_configuration
);
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
, bool bStartListening
/* = true */)
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 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
188 /* open a new connection */
189 unsigned iConnectTry(0);
190 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open((timeout
.TimeLeft() / CEC_CONNECT_TRIES
), false, bStartListening
)) == false)
192 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
193 m_communication
->Close();
199 m_configuration
.iFirmwareVersion
= m_communication
->GetFirmwareVersion();
200 CLibCEC::AddLog(CEC_LOG_NOTICE
, "connected to the CEC adapter. firmware version = %d, client version = %s", m_configuration
.iFirmwareVersion
, ToString((cec_client_version
)m_configuration
.clientVersion
));
203 if (m_configuration
.bGetSettingsFromROM
== 1)
204 m_communication
->GetConfiguration(&m_configuration
);
209 bool CCECProcessor::IsInitialised(void)
211 CLockObject
lock(m_mutex
);
212 return m_bInitialised
;
215 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
217 CLockObject
lock(m_mutex
);
218 m_bInitialised
= bSetTo
;
221 bool CCECProcessor::Initialise(void)
225 CLockObject
lock(m_mutex
);
226 if (!m_configuration
.logicalAddresses
.IsEmpty())
227 m_configuration
.logicalAddresses
.Clear();
229 if (!FindLogicalAddresses())
231 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
235 /* only set our OSD name for the primary device */
236 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
238 /* make the primary device the active source if the option is set */
239 if (m_configuration
.bActivateSource
== 1)
240 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_bActiveSource
= true;
243 /* get the vendor id from the TV, so we are using the correct handler */
244 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
246 if (m_configuration
.iPhysicalAddress
!= 0)
248 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
249 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
250 if ((bReturn
= m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
251 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
253 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
254 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
);
256 if (bReturn
&& m_configuration
.bActivateSource
== 1)
257 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->ActivateSource();
259 SetInitialised(bReturn
);
261 CLibCEC::ConfigurationChanged(m_configuration
);
266 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
271 CLockObject
lock(m_mutex
);
272 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
275 /* create the processor thread */
278 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
283 if ((bReturn
= Initialise()) == false)
285 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
290 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
296 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
298 if (m_busDevices
[address
]->TryLogicalAddress())
300 m_configuration
.logicalAddresses
.Set(address
);
307 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
309 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
310 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
311 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
312 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
315 bool CCECProcessor::FindLogicalAddressTuner(void)
317 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
318 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
319 TryLogicalAddress(CECDEVICE_TUNER2
) ||
320 TryLogicalAddress(CECDEVICE_TUNER3
) ||
321 TryLogicalAddress(CECDEVICE_TUNER4
);
324 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
326 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
327 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
328 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
329 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
332 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
334 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
335 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
338 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
340 bool bChanged(false);
342 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
344 CLockObject
lock(m_mutex
);
345 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
346 m_configuration
.logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
348 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
350 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
353 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
356 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
358 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
360 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
366 FindLogicalAddresses();
368 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
369 if (previousDevice
&& newDevice
)
371 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
372 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
374 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
375 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
377 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
378 cec_menu_language lang
;
379 lang
.device
= previousDevice
->GetLogicalAddress();
380 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
381 lang
.language
[iPtr
] = '?';
382 lang
.language
[3] = 0;
383 previousDevice
->SetMenuLanguage(lang
);
385 newDevice
->SetMenuState(previousDevice
->GetMenuState());
386 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
388 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
389 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
391 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
392 previousDevice
->SetPhysicalAddress(0xFFFF);
394 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
395 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
397 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
398 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
400 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
401 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
403 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
404 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
406 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
407 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
415 bool CCECProcessor::FindLogicalAddresses(void)
418 m_configuration
.logicalAddresses
.Clear();
420 if (m_configuration
.deviceTypes
.IsEmpty())
422 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
426 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
428 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
431 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
433 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
434 bReturn
&= FindLogicalAddressRecordingDevice();
435 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
436 bReturn
&= FindLogicalAddressTuner();
437 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
438 bReturn
&= FindLogicalAddressPlaybackDevice();
439 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
440 bReturn
&= FindLogicalAddressAudioSystem();
444 SetAckMask(m_configuration
.logicalAddresses
.AckMask());
449 void CCECProcessor::ReplaceHandlers(void)
451 if (!IsInitialised())
453 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
454 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
457 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
459 return m_inBuffer
.Push(command
);
462 void *CCECProcessor::Process(void)
464 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
469 while (!IsStopped() && m_communication
->IsOpen())
471 if (m_inBuffer
.Pop(command
, 500))
472 ParseCommand(command
);
478 m_controller
->CheckKeypressTimeout();
485 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
492 cec_logical_address addr
= m_configuration
.logicalAddresses
.primary
;
494 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
496 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
498 if (m_configuration
.logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
500 addr
= (cec_logical_address
) iPtr
;
506 m_busDevices
[addr
]->SetActiveSource();
507 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
508 bReturn
= m_busDevices
[addr
]->ActivateSource();
513 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
517 // suppress polls when searching for a device
518 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
, false, true);
521 device
->SetActiveSource();
528 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
530 CLockObject
lock(m_mutex
);
531 m_iStandardLineTimeout
= iTimeout
;
534 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
536 CLockObject
lock(m_mutex
);
537 m_iRetryLineTimeout
= iTimeout
;
540 bool CCECProcessor::SetActiveView(void)
542 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
543 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
546 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
550 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
553 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
555 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
562 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
566 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
569 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
571 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
578 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
582 // limit the HDMI port range to 1-15
589 CLockObject
lock(m_mutex
);
590 m_configuration
.baseDevice
= iBaseDevice
;
591 m_configuration
.iHDMIPort
= iPort
;
594 if (!IsRunning() && !bForce
)
597 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
599 uint16_t iPhysicalAddress(0);
600 if (iBaseDevice
> CECDEVICE_TV
)
602 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
605 if (iPhysicalAddress
< 0xffff)
607 if (iPhysicalAddress
== 0)
608 iPhysicalAddress
+= 0x1000 * iPort
;
609 else if (iPhysicalAddress
% 0x1000 == 0)
610 iPhysicalAddress
+= 0x100 * iPort
;
611 else if (iPhysicalAddress
% 0x100 == 0)
612 iPhysicalAddress
+= 0x10 * iPort
;
613 else if (iPhysicalAddress
% 0x10 == 0)
614 iPhysicalAddress
+= iPort
;
620 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
622 SetPhysicalAddress(iPhysicalAddress
);
627 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
629 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
631 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
637 bool CCECProcessor::TransmitInactiveSource(void)
642 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
643 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitInactiveSource();
647 void CCECProcessor::LogOutput(const cec_command
&data
)
650 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
652 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
654 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
655 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
656 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
659 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
661 CLockObject
lock(m_mutex
);
662 if (m_configuration
.logicalAddresses
.primary
!= iLogicalAddress
)
664 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
665 m_configuration
.logicalAddresses
.primary
= iLogicalAddress
;
666 m_configuration
.logicalAddresses
.Set(iLogicalAddress
);
667 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
673 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
675 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
677 if (m_configuration
.logicalAddresses
[iPtr
])
678 m_busDevices
[iPtr
]->SetMenuState(state
);
682 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
687 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
689 bool bSendActiveView(false);
691 cec_logical_addresses sendUpdatesTo
;
692 sendUpdatesTo
.Clear();
695 CLockObject
lock(m_mutex
);
696 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
697 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting physical address to '%4x'", iPhysicalAddress
);
699 if (!m_configuration
.logicalAddresses
.IsEmpty())
701 bool bWasActiveSource(false);
702 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
703 if (m_configuration
.logicalAddresses
[iPtr
])
705 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
706 m_busDevices
[iPtr
]->SetInactiveSource();
707 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
709 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
712 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
717 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
718 if (sendUpdatesTo
[iPtr
])
719 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
725 CLibCEC::ConfigurationChanged(m_configuration
);
730 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
732 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
735 CLockObject
lock(m_mutex
);
736 m_bMonitor
= bEnable
;
740 return SetAckMask(0);
742 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
745 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
747 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
749 return m_configuration
.logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
750 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
751 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPoll(iAddress
);
756 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
759 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
760 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
765 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
768 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
769 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
774 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
777 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
778 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
783 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */, bool bSuppressPoll
/* = false */) const
785 if (m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
786 return m_busDevices
[m_configuration
.logicalAddresses
.primary
];
788 CCECBusDevice
*device
= NULL
;
789 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
791 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
, bSuppressPoll
) == iPhysicalAddress
)
793 device
= m_busDevices
[iPtr
];
801 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
803 CCECBusDevice
*device
= NULL
;
805 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
807 if (m_busDevices
[iPtr
]->m_type
== type
&& m_configuration
.logicalAddresses
[iPtr
])
809 device
= m_busDevices
[iPtr
];
817 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
819 CCECBusDevice
*device(NULL
);
820 cec_logical_address primary
= m_configuration
.logicalAddresses
.primary
;
821 if (primary
!= CECDEVICE_UNKNOWN
)
822 device
= m_busDevices
[primary
];
826 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
828 return m_busDevices
[iAddress
]->GetCecVersion();
831 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
833 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
836 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
837 retVal
.device
= iAddress
;
842 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
844 if (m_busDevices
[iAddress
])
846 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
847 return (strcmp(language
->language
, "???") != 0);
852 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
854 if (m_busDevices
[iAddress
])
855 return m_busDevices
[iAddress
]->GetVendorId();
859 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
861 if (m_busDevices
[iAddress
])
862 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
866 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
868 if (m_busDevices
[iAddress
])
869 return m_busDevices
[iAddress
]->GetPowerStatus();
870 return CEC_POWER_STATUS_UNKNOWN
;
873 cec_logical_address
CCECProcessor::GetActiveSource(void)
875 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
877 if (m_busDevices
[iPtr
]->IsActiveSource())
878 return (cec_logical_address
)iPtr
;
881 return CECDEVICE_UNKNOWN
;
884 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
886 return m_busDevices
[iAddress
]->IsActiveSource();
889 bool CCECProcessor::Transmit(const cec_command
&data
)
891 if (m_configuration
.logicalAddresses
[(uint8_t)data
.destination
])
893 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
897 uint8_t iMaxTries(0);
899 CLockObject
lock(m_mutex
);
903 m_iLastTransmission
= GetTimeMs();
904 if (!m_communication
|| !m_communication
->IsOpen())
906 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
909 iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
912 return m_communication
->Write(data
, iMaxTries
, m_iStandardLineTimeout
, m_iRetryLineTimeout
)
913 == ADAPTER_MESSAGE_STATE_SENT_ACKED
;
916 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
918 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
922 cec_command::Format(command
, m_configuration
.logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
923 command
.parameters
.PushBack((uint8_t)opcode
);
924 command
.parameters
.PushBack((uint8_t)reason
);
929 void CCECProcessor::ParseCommand(const cec_command
&command
)
932 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
933 if (command
.opcode_set
== 1)
934 dataStr
.AppendFormat(":%02x", command
.opcode
);
935 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
936 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
937 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
939 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
940 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
943 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
945 cec_logical_addresses addresses
;
947 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
949 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
950 addresses
.Set((cec_logical_address
) iPtr
);
955 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
957 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
960 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
962 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
964 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
971 uint16_t CCECProcessor::GetPhysicalAddress(void) const
973 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
974 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false);
978 bool CCECProcessor::SetAckMask(uint16_t iMask
)
980 return m_communication
->SetAckMask(iMask
);
983 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
985 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
988 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
990 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
993 bool CCECProcessor::EnablePhysicalAddressDetection(void)
995 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
996 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
997 if (iPhysicalAddress
!= 0)
999 m_configuration
.bAutodetectAddress
= 1;
1000 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1001 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1002 m_configuration
.iHDMIPort
= 0;
1003 return SetPhysicalAddress(iPhysicalAddress
);
1008 bool CCECProcessor::StandbyDevices(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
]->Standby();
1021 return m_busDevices
[address
]->Standby();
1024 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
1026 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1029 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1031 if (m_configuration
.powerOffDevices
[iPtr
])
1032 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1037 return m_busDevices
[address
]->PowerOn();
1040 const char *CCECProcessor::ToString(const cec_device_type type
)
1044 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1045 return "audio system";
1046 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1047 return "playback device";
1048 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1049 return "recording device";
1050 case CEC_DEVICE_TYPE_RESERVED
:
1052 case CEC_DEVICE_TYPE_TUNER
:
1054 case CEC_DEVICE_TYPE_TV
:
1061 const char *CCECProcessor::ToString(const cec_menu_state state
)
1065 case CEC_MENU_STATE_ACTIVATED
:
1067 case CEC_MENU_STATE_DEACTIVATED
:
1068 return "deactivated";
1074 const char *CCECProcessor::ToString(const cec_version version
)
1078 case CEC_VERSION_1_2
:
1080 case CEC_VERSION_1_2A
:
1082 case CEC_VERSION_1_3
:
1084 case CEC_VERSION_1_3A
:
1086 case CEC_VERSION_1_4
:
1093 const char *CCECProcessor::ToString(const cec_power_status status
)
1097 case CEC_POWER_STATUS_ON
:
1099 case CEC_POWER_STATUS_STANDBY
:
1101 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1102 return "in transition from on to standby";
1103 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1104 return "in transition from standby to on";
1110 const char *CCECProcessor::ToString(const cec_logical_address address
)
1114 case CECDEVICE_AUDIOSYSTEM
:
1116 case CECDEVICE_BROADCAST
:
1118 case CECDEVICE_FREEUSE
:
1120 case CECDEVICE_PLAYBACKDEVICE1
:
1121 return "Playback 1";
1122 case CECDEVICE_PLAYBACKDEVICE2
:
1123 return "Playback 2";
1124 case CECDEVICE_PLAYBACKDEVICE3
:
1125 return "Playback 3";
1126 case CECDEVICE_RECORDINGDEVICE1
:
1127 return "Recorder 1";
1128 case CECDEVICE_RECORDINGDEVICE2
:
1129 return "Recorder 2";
1130 case CECDEVICE_RECORDINGDEVICE3
:
1131 return "Recorder 3";
1132 case CECDEVICE_RESERVED1
:
1133 return "Reserved 1";
1134 case CECDEVICE_RESERVED2
:
1135 return "Reserved 2";
1136 case CECDEVICE_TUNER1
:
1138 case CECDEVICE_TUNER2
:
1140 case CECDEVICE_TUNER3
:
1142 case CECDEVICE_TUNER4
:
1151 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1155 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1156 return "skip forward wind";
1157 case CEC_DECK_CONTROL_MODE_EJECT
:
1159 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1160 return "reverse rewind";
1161 case CEC_DECK_CONTROL_MODE_STOP
:
1168 const char *CCECProcessor::ToString(const cec_deck_info status
)
1172 case CEC_DECK_INFO_PLAY
:
1174 case CEC_DECK_INFO_RECORD
:
1176 case CEC_DECK_INFO_PLAY_REVERSE
:
1177 return "play reverse";
1178 case CEC_DECK_INFO_STILL
:
1180 case CEC_DECK_INFO_SLOW
:
1182 case CEC_DECK_INFO_SLOW_REVERSE
:
1183 return "slow reverse";
1184 case CEC_DECK_INFO_FAST_FORWARD
:
1185 return "fast forward";
1186 case CEC_DECK_INFO_FAST_REVERSE
:
1187 return "fast reverse";
1188 case CEC_DECK_INFO_NO_MEDIA
:
1190 case CEC_DECK_INFO_STOP
:
1192 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1193 return "info skip forward wind";
1194 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1195 return "info skip reverse rewind";
1196 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1197 return "info index search forward";
1198 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1199 return "info index search reverse";
1200 case CEC_DECK_INFO_OTHER_STATUS
:
1207 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1211 case CEC_OPCODE_ACTIVE_SOURCE
:
1212 return "active source";
1213 case CEC_OPCODE_IMAGE_VIEW_ON
:
1214 return "image view on";
1215 case CEC_OPCODE_TEXT_VIEW_ON
:
1216 return "text view on";
1217 case CEC_OPCODE_INACTIVE_SOURCE
:
1218 return "inactive source";
1219 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1220 return "request active source";
1221 case CEC_OPCODE_ROUTING_CHANGE
:
1222 return "routing change";
1223 case CEC_OPCODE_ROUTING_INFORMATION
:
1224 return "routing information";
1225 case CEC_OPCODE_SET_STREAM_PATH
:
1226 return "set stream path";
1227 case CEC_OPCODE_STANDBY
:
1229 case CEC_OPCODE_RECORD_OFF
:
1230 return "record off";
1231 case CEC_OPCODE_RECORD_ON
:
1233 case CEC_OPCODE_RECORD_STATUS
:
1234 return "record status";
1235 case CEC_OPCODE_RECORD_TV_SCREEN
:
1236 return "record tv screen";
1237 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1238 return "clear analogue timer";
1239 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1240 return "clear digital timer";
1241 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1242 return "clear external timer";
1243 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1244 return "set analogue timer";
1245 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1246 return "set digital timer";
1247 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1248 return "set external timer";
1249 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1250 return "set timer program title";
1251 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1252 return "timer cleared status";
1253 case CEC_OPCODE_TIMER_STATUS
:
1254 return "timer status";
1255 case CEC_OPCODE_CEC_VERSION
:
1256 return "cec version";
1257 case CEC_OPCODE_GET_CEC_VERSION
:
1258 return "get cec version";
1259 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1260 return "give physical address";
1261 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1262 return "get menu language";
1263 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1264 return "report physical address";
1265 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1266 return "set menu language";
1267 case CEC_OPCODE_DECK_CONTROL
:
1268 return "deck control";
1269 case CEC_OPCODE_DECK_STATUS
:
1270 return "deck status";
1271 case CEC_OPCODE_GIVE_DECK_STATUS
:
1272 return "give deck status";
1273 case CEC_OPCODE_PLAY
:
1275 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1276 return "give tuner status";
1277 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1278 return "select analogue service";
1279 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1280 return "set digital service";
1281 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1282 return "tuner device status";
1283 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1284 return "tuner step decrement";
1285 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1286 return "tuner step increment";
1287 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1288 return "device vendor id";
1289 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1290 return "give device vendor id";
1291 case CEC_OPCODE_VENDOR_COMMAND
:
1292 return "vendor command";
1293 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1294 return "vendor command with id";
1295 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1296 return "vendor remote button down";
1297 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1298 return "vendor remote button up";
1299 case CEC_OPCODE_SET_OSD_STRING
:
1300 return "set osd string";
1301 case CEC_OPCODE_GIVE_OSD_NAME
:
1302 return "give osd name";
1303 case CEC_OPCODE_SET_OSD_NAME
:
1304 return "set osd name";
1305 case CEC_OPCODE_MENU_REQUEST
:
1306 return "menu request";
1307 case CEC_OPCODE_MENU_STATUS
:
1308 return "menu status";
1309 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1310 return "user control pressed";
1311 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1312 return "user control release";
1313 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1314 return "give device power status";
1315 case CEC_OPCODE_REPORT_POWER_STATUS
:
1316 return "report power status";
1317 case CEC_OPCODE_FEATURE_ABORT
:
1318 return "feature abort";
1319 case CEC_OPCODE_ABORT
:
1321 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1322 return "give audio status";
1323 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1324 return "give audio mode status";
1325 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1326 return "report audio status";
1327 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1328 return "set system audio mode";
1329 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1330 return "system audio mode request";
1331 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1332 return "system audio mode status";
1333 case CEC_OPCODE_SET_AUDIO_RATE
:
1334 return "set audio rate";
1335 case CEC_OPCODE_NONE
:
1342 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1346 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1348 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1355 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1357 // TODO this is a mask
1361 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1365 case CEC_VENDOR_SAMSUNG
:
1369 case CEC_VENDOR_PANASONIC
:
1371 case CEC_VENDOR_PIONEER
:
1373 case CEC_VENDOR_ONKYO
:
1375 case CEC_VENDOR_YAMAHA
:
1377 case CEC_VENDOR_PHILIPS
:
1379 case CEC_VENDOR_SONY
:
1381 case CEC_VENDOR_TOSHIBA
:
1388 const char *CCECProcessor::ToString(const cec_client_version version
)
1392 case CEC_CLIENT_VERSION_PRE_1_5
:
1394 case CEC_CLIENT_VERSION_1_5_0
:
1396 case CEC_CLIENT_VERSION_1_5_1
:
1398 case CEC_CLIENT_VERSION_1_5_2
:
1400 case CEC_CLIENT_VERSION_1_5_3
:
1402 case CEC_CLIENT_VERSION_1_6_0
:
1409 const char *CCECProcessor::ToString(const cec_server_version version
)
1413 case CEC_SERVER_VERSION_PRE_1_5
:
1415 case CEC_SERVER_VERSION_1_5_0
:
1417 case CEC_SERVER_VERSION_1_5_1
:
1419 case CEC_SERVER_VERSION_1_5_2
:
1421 case CEC_SERVER_VERSION_1_5_3
:
1423 case CEC_SERVER_VERSION_1_6_0
:
1430 void *CCECBusScan::Process(void)
1432 CCECBusDevice
*device(NULL
);
1433 uint8_t iCounter(0);
1435 while (!IsStopped())
1437 if (++iCounter
< 10)
1442 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1444 device
= m_processor
->m_busDevices
[iPtr
];
1446 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1450 device
->GetVendorId();
1454 device
->GetPowerStatus(true);
1462 void CCECBusScan::WaitUntilIdle(void)
1467 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1468 while (iWaitTime
> 0)
1471 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1475 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
1477 if (!m_communication
&& strPort
)
1479 bool bReturn(false);
1480 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
1481 CTimeout
timeout(10000);
1483 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(NULL
, (timeout
.TimeLeft() / CEC_CONNECT_TRIES
)), true) == false)
1485 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
1491 bReturn
= comm
->StartBootloader();
1498 return m_communication
->StartBootloader();
1502 bool CCECProcessor::PingAdapter(void)
1504 return m_communication
->PingAdapter();
1507 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1509 if (destination
< CECDEVICE_BROADCAST
)
1510 m_busDevices
[destination
]->HandlePollFrom(initiator
);
1513 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1515 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1518 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1520 // stream path changes are sent by the TV
1521 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1524 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1526 bool bReinit(false);
1527 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1528 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1529 m_configuration
.clientVersion
= configuration
->clientVersion
;
1531 // client version 1.5.0
1534 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1535 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1537 bool bPhysicalAddressChanged(false);
1539 // autodetect address
1540 bool bPhysicalAutodetected(false);
1541 if (IsRunning() && configuration
->bAutodetectAddress
== 1)
1543 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
1544 if (iPhysicalAddress
!= 0)
1547 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%4x'", __FUNCTION__
, iPhysicalAddress
);
1548 bPhysicalAddressChanged
= (m_configuration
.iPhysicalAddress
!= iPhysicalAddress
);
1549 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1550 m_configuration
.iHDMIPort
= 0;
1551 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1552 bPhysicalAutodetected
= true;
1557 if (!bPhysicalAutodetected
)
1559 if (configuration
->iPhysicalAddress
!= 0)
1560 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1561 if (bPhysicalAddressChanged
)
1564 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using physical address '%4x'", __FUNCTION__
, configuration
->iPhysicalAddress
);
1565 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1569 bool bHdmiPortChanged(false);
1570 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1573 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1575 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using base device '%x'", __FUNCTION__
, (int)configuration
->baseDevice
);
1576 m_configuration
.baseDevice
= configuration
->baseDevice
;
1579 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1581 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using HDMI port '%d'", __FUNCTION__
, configuration
->iHDMIPort
);
1582 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1587 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
1588 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1589 m_configuration
.iHDMIPort
= 0;
1592 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
;
1595 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1596 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1598 primary
->SetOSDName(m_configuration
.strDeviceName
);
1599 if (!bReinit
&& IsRunning())
1600 primary
->TransmitOSDName(CECDEVICE_TV
);
1603 // tv vendor id override
1604 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1606 m_configuration
.tvVendor
= configuration
->tvVendor
;
1607 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1611 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1613 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1614 if (!bReinit
&& IsRunning())
1619 m_configuration
.clientVersion
= configuration
->clientVersion
;
1620 m_configuration
.bUseTVMenuLanguage
= configuration
->bUseTVMenuLanguage
;
1621 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1622 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1623 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1624 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1625 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1627 // client version 1.5.1
1628 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1629 m_configuration
.bSendInactiveSource
= configuration
->bSendInactiveSource
;
1631 // client version 1.6.0
1632 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_6_0
)
1634 m_configuration
.bPowerOffDevicesOnStandby
= configuration
->bPowerOffDevicesOnStandby
;
1635 m_configuration
.bShutdownOnStandby
= configuration
->bShutdownOnStandby
;
1638 // ensure that there is at least 1 device type set
1639 if (m_configuration
.deviceTypes
.IsEmpty())
1640 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1644 if (bDeviceTypeChanged
)
1645 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1646 else if (bPhysicalAddressChanged
)
1647 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1649 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1651 else if (m_configuration
.bActivateSource
== 1 && IsRunning() && !IsActiveSource(m_configuration
.logicalAddresses
.primary
))
1653 // activate the source if we're not already the active source
1654 SetActiveSource(m_configuration
.deviceTypes
.types
[0]);
1660 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1662 // client version 1.5.0
1663 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1664 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1665 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1666 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1667 configuration
->baseDevice
= m_configuration
.baseDevice
;
1668 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1669 configuration
->clientVersion
= m_configuration
.clientVersion
;
1670 configuration
->serverVersion
= m_configuration
.serverVersion
;
1671 configuration
->tvVendor
= m_configuration
.tvVendor
;
1673 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1674 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1675 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1676 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1677 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1678 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1679 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1681 // client version 1.5.1
1682 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1683 configuration
->bSendInactiveSource
= m_configuration
.bSendInactiveSource
;
1685 // client version 1.5.3
1686 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_3
)
1687 configuration
->logicalAddresses
= m_configuration
.logicalAddresses
;
1689 // client version 1.6.0
1690 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_6_0
)
1692 configuration
->iFirmwareVersion
= m_configuration
.iFirmwareVersion
;
1693 configuration
->bPowerOffDevicesOnStandby
= m_configuration
.bPowerOffDevicesOnStandby
;
1694 configuration
->bShutdownOnStandby
= m_configuration
.bShutdownOnStandby
;
1700 bool CCECProcessor::CanPersistConfiguration(void)
1702 return m_communication
->GetFirmwareVersion() >= 2;
1705 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1707 return m_communication
->PersistConfiguration(configuration
);
1710 void CCECProcessor::RescanActiveDevices(void)
1712 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1713 m_busDevices
[iPtr
]->GetStatus(true);
1716 bool CCECProcessor::GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
/* = 10000 */)
1718 if (!OpenConnection(strPort
, 38400, iTimeoutMs
, false))
1721 config
->iFirmwareVersion
= m_communication
->GetFirmwareVersion();
1722 config
->iPhysicalAddress
= m_communication
->GetPhysicalAddress();
1724 delete m_communication
;
1725 m_communication
= NULL
;