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
= configuration
->serverVersion
;
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_5_2
;
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
++)
135 delete m_busDevices
[iPtr
];
138 void CCECProcessor::Close(void)
141 SetInitialised(false);
146 CLockObject
lock(m_mutex
);
147 bClose
= m_bConnectionOpened
;
148 m_bConnectionOpened
= false;
151 if (bClose
&& m_communication
)
153 m_communication
->PersistConfiguration(&m_configuration
);
154 m_communication
->Close();
155 delete m_communication
;
156 m_communication
= NULL
;
160 bool CCECProcessor::OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
)
166 CLockObject
lock(m_mutex
);
167 if (m_bConnectionOpened
)
169 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
172 m_communication
= new CUSBCECAdapterCommunication(this, strPort
, iBaudRate
);
173 m_bConnectionOpened
= (m_communication
!= NULL
);
176 /* check for an already opened connection */
177 if (m_communication
->IsOpen())
179 CLibCEC::AddLog(CEC_LOG_ERROR
, "connection already opened");
183 CTimeout
timeout(iTimeoutMs
> 0 ? iTimeoutMs
: CEC_DEFAULT_TRANSMIT_WAIT
);
185 /* open a new connection */
186 unsigned iConnectTry(0);
187 while (timeout
.TimeLeft() > 0 && (bReturn
= m_communication
->Open(this, (timeout
.TimeLeft() / CEC_CONNECT_TRIES
))) == false)
189 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
190 m_communication
->Close();
195 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
));
197 if (m_configuration
.bGetSettingsFromROM
== 1)
198 m_communication
->GetConfiguration(&m_configuration
);
203 bool CCECProcessor::IsInitialised(void)
205 CLockObject
lock(m_mutex
);
206 return m_bInitialised
;
209 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
211 CLockObject
lock(m_mutex
);
212 m_bInitialised
= bSetTo
;
215 bool CCECProcessor::Initialise(void)
219 CLockObject
lock(m_mutex
);
220 if (!m_configuration
.logicalAddresses
.IsEmpty())
221 m_configuration
.logicalAddresses
.Clear();
223 if (!FindLogicalAddresses())
225 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
229 /* only set our OSD name for the primary device */
230 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
232 /* make the primary device the active source if the option is set */
233 if (m_configuration
.bActivateSource
== 1)
234 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_bActiveSource
= true;
237 /* get the vendor id from the TV, so we are using the correct handler */
238 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
240 if (m_configuration
.iPhysicalAddress
!= 0)
242 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
243 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
244 if ((bReturn
= m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
245 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
247 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
248 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
);
250 if (m_configuration
.bActivateSource
== 1)
251 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->ActivateSource();
253 SetInitialised(bReturn
);
255 CLibCEC::ConfigurationChanged(m_configuration
);
260 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
265 CLockObject
lock(m_mutex
);
266 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
269 /* create the processor thread */
272 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
277 if ((bReturn
= Initialise()) == false)
279 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
284 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
290 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
292 if (m_busDevices
[address
]->TryLogicalAddress())
294 m_configuration
.logicalAddresses
.Set(address
);
301 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
303 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
304 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
305 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
306 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
309 bool CCECProcessor::FindLogicalAddressTuner(void)
311 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
312 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
313 TryLogicalAddress(CECDEVICE_TUNER2
) ||
314 TryLogicalAddress(CECDEVICE_TUNER3
) ||
315 TryLogicalAddress(CECDEVICE_TUNER4
);
318 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
320 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
321 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
322 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
323 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
326 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
328 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
329 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
332 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
334 bool bChanged(false);
336 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
338 CLockObject
lock(m_mutex
);
339 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
340 m_configuration
.logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
342 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
344 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
347 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
350 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
352 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
354 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
360 FindLogicalAddresses();
362 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
363 if (previousDevice
&& newDevice
)
365 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
366 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
368 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
369 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
371 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
372 cec_menu_language lang
;
373 lang
.device
= previousDevice
->GetLogicalAddress();
374 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
375 lang
.language
[iPtr
] = '?';
376 lang
.language
[3] = 0;
377 previousDevice
->SetMenuLanguage(lang
);
379 newDevice
->SetMenuState(previousDevice
->GetMenuState());
380 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
382 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
383 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
385 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
386 previousDevice
->SetPhysicalAddress(0xFFFF);
388 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
389 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
391 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
392 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
394 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
395 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
397 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
398 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
400 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
401 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
409 bool CCECProcessor::FindLogicalAddresses(void)
412 m_configuration
.logicalAddresses
.Clear();
414 if (m_configuration
.deviceTypes
.IsEmpty())
416 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
420 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
422 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
425 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
427 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
428 bReturn
&= FindLogicalAddressRecordingDevice();
429 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
430 bReturn
&= FindLogicalAddressTuner();
431 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
432 bReturn
&= FindLogicalAddressPlaybackDevice();
433 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
434 bReturn
&= FindLogicalAddressAudioSystem();
438 SetAckMask(m_configuration
.logicalAddresses
.AckMask());
443 void CCECProcessor::ReplaceHandlers(void)
445 if (!IsInitialised())
447 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
448 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
451 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
453 ParseCommand(command
);
457 void *CCECProcessor::Process(void)
459 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
461 while (!IsStopped() && m_communication
->IsOpen())
467 m_controller
->CheckKeypressTimeout();
475 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
482 cec_logical_address addr
= m_configuration
.logicalAddresses
.primary
;
484 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
486 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
488 if (m_configuration
.logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
490 addr
= (cec_logical_address
) iPtr
;
496 m_busDevices
[addr
]->SetActiveSource();
497 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
498 bReturn
= m_busDevices
[addr
]->ActivateSource();
503 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
507 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
510 device
->SetActiveSource();
517 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
519 CLockObject
lock(m_mutex
);
520 m_iStandardLineTimeout
= iTimeout
;
523 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
525 CLockObject
lock(m_mutex
);
526 m_iRetryLineTimeout
= iTimeout
;
529 bool CCECProcessor::SetActiveView(void)
531 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
532 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
535 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
539 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
542 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
544 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
551 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
555 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
558 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
560 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
567 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
572 CLockObject
lock(m_mutex
);
573 m_configuration
.baseDevice
= iBaseDevice
;
574 m_configuration
.iHDMIPort
= iPort
;
577 if (!IsRunning() && !bForce
)
580 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
582 uint16_t iPhysicalAddress(0);
583 if (iBaseDevice
> CECDEVICE_TV
)
585 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
588 if (iPhysicalAddress
< 0xffff)
590 if (iPhysicalAddress
== 0)
591 iPhysicalAddress
+= 0x1000 * iPort
;
592 else if (iPhysicalAddress
% 0x1000 == 0)
593 iPhysicalAddress
+= 0x100 * iPort
;
594 else if (iPhysicalAddress
% 0x100 == 0)
595 iPhysicalAddress
+= 0x10 * iPort
;
596 else if (iPhysicalAddress
% 0x10 == 0)
597 iPhysicalAddress
+= iPort
;
603 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
605 SetPhysicalAddress(iPhysicalAddress
);
610 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
612 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
614 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
620 bool CCECProcessor::TransmitInactiveSource(void)
625 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
626 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitInactiveSource();
630 void CCECProcessor::LogOutput(const cec_command
&data
)
633 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
635 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
637 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
638 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
639 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
642 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
644 CLockObject
lock(m_mutex
);
645 if (m_configuration
.logicalAddresses
.primary
!= iLogicalAddress
)
647 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
648 m_configuration
.logicalAddresses
.primary
= iLogicalAddress
;
649 m_configuration
.logicalAddresses
.Set(iLogicalAddress
);
650 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
656 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
658 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
660 if (m_configuration
.logicalAddresses
[iPtr
])
661 m_busDevices
[iPtr
]->SetMenuState(state
);
665 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
670 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
672 bool bSendActiveView(false);
674 cec_logical_addresses sendUpdatesTo
;
675 sendUpdatesTo
.Clear();
678 CLockObject
lock(m_mutex
);
679 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
680 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting physical address to '%4x'", iPhysicalAddress
);
682 if (!m_configuration
.logicalAddresses
.IsEmpty())
684 bool bWasActiveSource(false);
685 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
686 if (m_configuration
.logicalAddresses
[iPtr
])
688 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
689 m_busDevices
[iPtr
]->SetInactiveSource();
690 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
692 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
695 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
700 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
701 if (sendUpdatesTo
[iPtr
])
702 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
708 CLibCEC::ConfigurationChanged(m_configuration
);
713 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
715 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
718 CLockObject
lock(m_mutex
);
719 m_bMonitor
= bEnable
;
723 return SetAckMask(0);
725 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
728 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
730 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
732 return m_configuration
.logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
733 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
734 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPoll(iAddress
);
739 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
742 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
743 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
748 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
751 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
752 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
757 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
760 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
761 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
766 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
768 if (m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
769 return m_busDevices
[m_configuration
.logicalAddresses
.primary
];
771 CCECBusDevice
*device
= NULL
;
772 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
774 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
776 device
= m_busDevices
[iPtr
];
784 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
786 CCECBusDevice
*device
= NULL
;
788 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
790 if (m_busDevices
[iPtr
]->m_type
== type
&& m_configuration
.logicalAddresses
[iPtr
])
792 device
= m_busDevices
[iPtr
];
800 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
802 CCECBusDevice
*device(NULL
);
803 cec_logical_address primary
= m_configuration
.logicalAddresses
.primary
;
804 if (primary
!= CECDEVICE_UNKNOWN
)
805 device
= m_busDevices
[primary
];
809 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
811 return m_busDevices
[iAddress
]->GetCecVersion();
814 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
816 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
819 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
820 retVal
.device
= iAddress
;
825 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
827 if (m_busDevices
[iAddress
])
829 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
830 return (strcmp(language
->language
, "???") != 0);
835 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
837 if (m_busDevices
[iAddress
])
838 return m_busDevices
[iAddress
]->GetVendorId();
842 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
844 if (m_busDevices
[iAddress
])
845 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
849 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
851 if (m_busDevices
[iAddress
])
852 return m_busDevices
[iAddress
]->GetPowerStatus();
853 return CEC_POWER_STATUS_UNKNOWN
;
856 cec_logical_address
CCECProcessor::GetActiveSource(void)
858 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
860 if (m_busDevices
[iPtr
]->IsActiveSource())
861 return (cec_logical_address
)iPtr
;
864 return CECDEVICE_UNKNOWN
;
867 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
869 return m_busDevices
[iAddress
]->IsActiveSource();
872 bool CCECProcessor::Transmit(const cec_command
&data
)
874 if (m_configuration
.logicalAddresses
[(uint8_t)data
.destination
])
876 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
880 uint8_t iMaxTries(0);
882 CLockObject
lock(m_mutex
);
886 m_iLastTransmission
= GetTimeMs();
887 if (!m_communication
|| !m_communication
->IsOpen())
889 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
892 iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
895 return m_communication
->Write(data
, iMaxTries
, m_iStandardLineTimeout
, m_iRetryLineTimeout
)
896 == ADAPTER_MESSAGE_STATE_SENT_ACKED
;
899 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
901 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
905 cec_command::Format(command
, m_configuration
.logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
906 command
.parameters
.PushBack((uint8_t)opcode
);
907 command
.parameters
.PushBack((uint8_t)reason
);
912 void CCECProcessor::ParseCommand(const cec_command
&command
)
915 dataStr
.Format(">> %1x%1x", command
.initiator
, command
.destination
);
916 if (command
.opcode_set
== 1)
917 dataStr
.AppendFormat(":%02x", command
.opcode
);
918 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
919 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
920 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
922 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
923 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
926 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
928 cec_logical_addresses addresses
;
930 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
932 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
933 addresses
.Set((cec_logical_address
) iPtr
);
938 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
940 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
943 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
945 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
947 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
954 uint16_t CCECProcessor::GetPhysicalAddress(void) const
956 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
957 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false);
961 bool CCECProcessor::SetAckMask(uint16_t iMask
)
963 return m_communication
->SetAckMask(iMask
);
966 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
968 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
971 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
973 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
976 bool CCECProcessor::EnablePhysicalAddressDetection(void)
978 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
979 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
980 if (iPhysicalAddress
!= 0)
982 m_configuration
.bAutodetectAddress
= 1;
983 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
984 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
985 m_configuration
.iHDMIPort
= 0;
986 return SetPhysicalAddress(iPhysicalAddress
);
991 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
993 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
996 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
998 if (m_configuration
.powerOffDevices
[iPtr
])
999 bReturn
&= m_busDevices
[iPtr
]->Standby();
1004 return m_busDevices
[address
]->Standby();
1007 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
1009 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1012 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1014 if (m_configuration
.powerOffDevices
[iPtr
])
1015 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1020 return m_busDevices
[address
]->PowerOn();
1023 const char *CCECProcessor::ToString(const cec_device_type type
)
1027 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1028 return "audio system";
1029 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1030 return "playback device";
1031 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1032 return "recording device";
1033 case CEC_DEVICE_TYPE_RESERVED
:
1035 case CEC_DEVICE_TYPE_TUNER
:
1037 case CEC_DEVICE_TYPE_TV
:
1044 const char *CCECProcessor::ToString(const cec_menu_state state
)
1048 case CEC_MENU_STATE_ACTIVATED
:
1050 case CEC_MENU_STATE_DEACTIVATED
:
1051 return "deactivated";
1057 const char *CCECProcessor::ToString(const cec_version version
)
1061 case CEC_VERSION_1_2
:
1063 case CEC_VERSION_1_2A
:
1065 case CEC_VERSION_1_3
:
1067 case CEC_VERSION_1_3A
:
1069 case CEC_VERSION_1_4
:
1076 const char *CCECProcessor::ToString(const cec_power_status status
)
1080 case CEC_POWER_STATUS_ON
:
1082 case CEC_POWER_STATUS_STANDBY
:
1084 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1085 return "in transition from on to standby";
1086 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1087 return "in transition from standby to on";
1093 const char *CCECProcessor::ToString(const cec_logical_address address
)
1097 case CECDEVICE_AUDIOSYSTEM
:
1099 case CECDEVICE_BROADCAST
:
1101 case CECDEVICE_FREEUSE
:
1103 case CECDEVICE_PLAYBACKDEVICE1
:
1104 return "Playback 1";
1105 case CECDEVICE_PLAYBACKDEVICE2
:
1106 return "Playback 2";
1107 case CECDEVICE_PLAYBACKDEVICE3
:
1108 return "Playback 3";
1109 case CECDEVICE_RECORDINGDEVICE1
:
1110 return "Recorder 1";
1111 case CECDEVICE_RECORDINGDEVICE2
:
1112 return "Recorder 2";
1113 case CECDEVICE_RECORDINGDEVICE3
:
1114 return "Recorder 3";
1115 case CECDEVICE_RESERVED1
:
1116 return "Reserved 1";
1117 case CECDEVICE_RESERVED2
:
1118 return "Reserved 2";
1119 case CECDEVICE_TUNER1
:
1121 case CECDEVICE_TUNER2
:
1123 case CECDEVICE_TUNER3
:
1125 case CECDEVICE_TUNER4
:
1134 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1138 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1139 return "skip forward wind";
1140 case CEC_DECK_CONTROL_MODE_EJECT
:
1142 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1143 return "reverse rewind";
1144 case CEC_DECK_CONTROL_MODE_STOP
:
1151 const char *CCECProcessor::ToString(const cec_deck_info status
)
1155 case CEC_DECK_INFO_PLAY
:
1157 case CEC_DECK_INFO_RECORD
:
1159 case CEC_DECK_INFO_PLAY_REVERSE
:
1160 return "play reverse";
1161 case CEC_DECK_INFO_STILL
:
1163 case CEC_DECK_INFO_SLOW
:
1165 case CEC_DECK_INFO_SLOW_REVERSE
:
1166 return "slow reverse";
1167 case CEC_DECK_INFO_FAST_FORWARD
:
1168 return "fast forward";
1169 case CEC_DECK_INFO_FAST_REVERSE
:
1170 return "fast reverse";
1171 case CEC_DECK_INFO_NO_MEDIA
:
1173 case CEC_DECK_INFO_STOP
:
1175 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1176 return "info skip forward wind";
1177 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1178 return "info skip reverse rewind";
1179 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1180 return "info index search forward";
1181 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1182 return "info index search reverse";
1183 case CEC_DECK_INFO_OTHER_STATUS
:
1190 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1194 case CEC_OPCODE_ACTIVE_SOURCE
:
1195 return "active source";
1196 case CEC_OPCODE_IMAGE_VIEW_ON
:
1197 return "image view on";
1198 case CEC_OPCODE_TEXT_VIEW_ON
:
1199 return "text view on";
1200 case CEC_OPCODE_INACTIVE_SOURCE
:
1201 return "inactive source";
1202 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1203 return "request active source";
1204 case CEC_OPCODE_ROUTING_CHANGE
:
1205 return "routing change";
1206 case CEC_OPCODE_ROUTING_INFORMATION
:
1207 return "routing information";
1208 case CEC_OPCODE_SET_STREAM_PATH
:
1209 return "set stream path";
1210 case CEC_OPCODE_STANDBY
:
1212 case CEC_OPCODE_RECORD_OFF
:
1213 return "record off";
1214 case CEC_OPCODE_RECORD_ON
:
1216 case CEC_OPCODE_RECORD_STATUS
:
1217 return "record status";
1218 case CEC_OPCODE_RECORD_TV_SCREEN
:
1219 return "record tv screen";
1220 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1221 return "clear analogue timer";
1222 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1223 return "clear digital timer";
1224 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1225 return "clear external timer";
1226 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1227 return "set analogue timer";
1228 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1229 return "set digital timer";
1230 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1231 return "set external timer";
1232 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1233 return "set timer program title";
1234 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1235 return "timer cleared status";
1236 case CEC_OPCODE_TIMER_STATUS
:
1237 return "timer status";
1238 case CEC_OPCODE_CEC_VERSION
:
1239 return "cec version";
1240 case CEC_OPCODE_GET_CEC_VERSION
:
1241 return "get cec version";
1242 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1243 return "give physical address";
1244 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1245 return "get menu language";
1246 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1247 return "report physical address";
1248 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1249 return "set menu language";
1250 case CEC_OPCODE_DECK_CONTROL
:
1251 return "deck control";
1252 case CEC_OPCODE_DECK_STATUS
:
1253 return "deck status";
1254 case CEC_OPCODE_GIVE_DECK_STATUS
:
1255 return "give deck status";
1256 case CEC_OPCODE_PLAY
:
1258 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1259 return "give tuner status";
1260 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1261 return "select analogue service";
1262 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1263 return "set digital service";
1264 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1265 return "tuner device status";
1266 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1267 return "tuner step decrement";
1268 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1269 return "tuner step increment";
1270 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1271 return "device vendor id";
1272 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1273 return "give device vendor id";
1274 case CEC_OPCODE_VENDOR_COMMAND
:
1275 return "vendor command";
1276 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1277 return "vendor command with id";
1278 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1279 return "vendor remote button down";
1280 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1281 return "vendor remote button up";
1282 case CEC_OPCODE_SET_OSD_STRING
:
1283 return "set osd string";
1284 case CEC_OPCODE_GIVE_OSD_NAME
:
1285 return "give osd name";
1286 case CEC_OPCODE_SET_OSD_NAME
:
1287 return "set osd name";
1288 case CEC_OPCODE_MENU_REQUEST
:
1289 return "menu request";
1290 case CEC_OPCODE_MENU_STATUS
:
1291 return "menu status";
1292 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1293 return "user control pressed";
1294 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1295 return "user control release";
1296 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1297 return "give device power status";
1298 case CEC_OPCODE_REPORT_POWER_STATUS
:
1299 return "report power status";
1300 case CEC_OPCODE_FEATURE_ABORT
:
1301 return "feature abort";
1302 case CEC_OPCODE_ABORT
:
1304 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1305 return "give audio status";
1306 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1307 return "give audio mode status";
1308 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1309 return "report audio status";
1310 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1311 return "set system audio mode";
1312 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1313 return "system audio mode request";
1314 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1315 return "system audio mode status";
1316 case CEC_OPCODE_SET_AUDIO_RATE
:
1317 return "set audio rate";
1318 case CEC_OPCODE_NONE
:
1325 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1329 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1331 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1338 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1340 // TODO this is a mask
1344 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1348 case CEC_VENDOR_SAMSUNG
:
1352 case CEC_VENDOR_PANASONIC
:
1354 case CEC_VENDOR_PIONEER
:
1356 case CEC_VENDOR_ONKYO
:
1358 case CEC_VENDOR_YAMAHA
:
1360 case CEC_VENDOR_PHILIPS
:
1362 case CEC_VENDOR_SONY
:
1364 case CEC_VENDOR_TOSHIBA
:
1371 const char *CCECProcessor::ToString(const cec_client_version version
)
1375 case CEC_CLIENT_VERSION_PRE_1_5
:
1377 case CEC_CLIENT_VERSION_1_5_0
:
1379 case CEC_CLIENT_VERSION_1_5_1
:
1381 case CEC_CLIENT_VERSION_1_5_2
:
1388 const char *CCECProcessor::ToString(const cec_server_version version
)
1392 case CEC_SERVER_VERSION_PRE_1_5
:
1394 case CEC_SERVER_VERSION_1_5_0
:
1396 case CEC_SERVER_VERSION_1_5_1
:
1398 case CEC_SERVER_VERSION_1_5_2
:
1405 void *CCECBusScan::Process(void)
1407 CCECBusDevice
*device(NULL
);
1408 uint8_t iCounter(0);
1410 while (!IsStopped())
1412 if (++iCounter
< 10)
1417 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1419 device
= m_processor
->m_busDevices
[iPtr
];
1421 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1425 device
->GetVendorId();
1429 device
->GetPowerStatus(true);
1437 void CCECBusScan::WaitUntilIdle(void)
1442 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1443 while (iWaitTime
> 0)
1446 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1450 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
1452 if (!m_communication
&& strPort
)
1454 bool bReturn(false);
1455 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
1456 CTimeout
timeout(10000);
1458 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(NULL
, (timeout
.TimeLeft() / CEC_CONNECT_TRIES
)), true) == false)
1460 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
1466 bReturn
= comm
->StartBootloader();
1473 return m_communication
->StartBootloader();
1477 bool CCECProcessor::PingAdapter(void)
1479 return m_communication
->PingAdapter();
1482 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1484 m_busDevices
[destination
]->HandlePoll(initiator
);
1487 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1489 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1492 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1494 // stream path changes are sent by the TV
1495 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1498 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1500 bool bReinit(false);
1501 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1502 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1503 m_configuration
.clientVersion
= configuration
->clientVersion
;
1505 // client version 1.5.0
1508 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1509 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1511 bool bPhysicalAddressChanged(false);
1513 // autodetect address
1514 bool bPhysicalAutodetected(false);
1515 if (IsRunning() && configuration
->bAutodetectAddress
== 1)
1517 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
1518 if (iPhysicalAddress
!= 0)
1521 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%4x'", __FUNCTION__
, iPhysicalAddress
);
1522 bPhysicalAddressChanged
= (m_configuration
.iPhysicalAddress
!= iPhysicalAddress
);
1523 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1524 m_configuration
.iHDMIPort
= 0;
1525 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1526 bPhysicalAutodetected
= true;
1531 if (!bPhysicalAutodetected
)
1533 if (configuration
->iPhysicalAddress
!= 0)
1534 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1536 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using physical address '%4x'", __FUNCTION__
, configuration
->iPhysicalAddress
);
1537 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1540 bool bHdmiPortChanged(false);
1541 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1544 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1546 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using base device '%x'", __FUNCTION__
, (int)configuration
->baseDevice
);
1547 m_configuration
.baseDevice
= configuration
->baseDevice
;
1550 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1552 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using HDMI port '%d'", __FUNCTION__
, configuration
->iHDMIPort
);
1553 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1558 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
1559 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1560 m_configuration
.iHDMIPort
= 0;
1563 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
;
1566 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1567 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1569 primary
->SetOSDName(m_configuration
.strDeviceName
);
1570 if (!bReinit
&& IsRunning())
1571 primary
->TransmitOSDName(CECDEVICE_TV
);
1574 // tv vendor id override
1575 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1577 m_configuration
.tvVendor
= configuration
->tvVendor
;
1578 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1582 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1584 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1585 if (!bReinit
&& IsRunning())
1590 m_configuration
.clientVersion
= configuration
->clientVersion
;
1591 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1592 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1593 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1594 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1595 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1597 // client version 1.5.1
1598 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1599 m_configuration
.bSendInactiveSource
= configuration
->bSendInactiveSource
;
1601 // ensure that there is at least 1 device type set
1602 if (m_configuration
.deviceTypes
.IsEmpty())
1603 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1607 if (bDeviceTypeChanged
)
1608 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1609 else if (bPhysicalAddressChanged
)
1610 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1612 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1614 else if (m_configuration
.bActivateSource
== 1 && IsRunning() && !IsActiveSource(m_configuration
.logicalAddresses
.primary
))
1616 // activate the source if we're not already the active source
1617 SetActiveSource(m_configuration
.deviceTypes
.types
[0]);
1623 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1625 // client version 1.5.0
1626 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1627 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1628 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1629 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1630 configuration
->baseDevice
= m_configuration
.baseDevice
;
1631 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1632 configuration
->clientVersion
= m_configuration
.clientVersion
;
1633 configuration
->serverVersion
= m_configuration
.serverVersion
;
1634 configuration
->tvVendor
= m_configuration
.tvVendor
;
1636 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1637 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1638 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1639 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1640 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1641 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1642 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1644 // client version 1.5.1
1645 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1646 configuration
->bSendInactiveSource
= m_configuration
.bSendInactiveSource
;
1648 // client version 1.5.3
1649 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_3
)
1650 configuration
->logicalAddresses
= m_configuration
.logicalAddresses
;
1655 bool CCECProcessor::CanPersistConfiguration(void)
1657 return m_communication
->GetFirmwareVersion() >= 2;
1660 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1662 return m_communication
->PersistConfiguration(configuration
);
1665 void CCECProcessor::RescanActiveDevices(void)
1667 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1668 m_busDevices
[iPtr
]->GetStatus(true);