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
));
200 bool CCECProcessor::IsInitialised(void)
202 CLockObject
lock(m_mutex
);
203 return m_bInitialised
;
206 void CCECProcessor::SetInitialised(bool bSetTo
/* = true */)
208 CLockObject
lock(m_mutex
);
209 m_bInitialised
= bSetTo
;
212 bool CCECProcessor::Initialise(void)
216 CLockObject
lock(m_mutex
);
217 if (!m_configuration
.logicalAddresses
.IsEmpty())
218 m_configuration
.logicalAddresses
.Clear();
220 if (!FindLogicalAddresses())
222 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
226 /* only set our OSD name for the primary device */
227 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_strDeviceName
= m_configuration
.strDeviceName
;
229 /* make the primary device the active source if the option is set */
230 if (m_configuration
.bActivateSource
== 1)
231 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_bActiveSource
= true;
234 /* get the vendor id from the TV, so we are using the correct handler */
235 m_busDevices
[CECDEVICE_TV
]->GetVendorId();
237 if (m_configuration
.iPhysicalAddress
!= 0)
239 CLibCEC::AddLog(CEC_LOG_NOTICE
, "setting the physical address to %4x", m_configuration
.iPhysicalAddress
);
240 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->m_iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
241 if ((bReturn
= m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPhysicalAddress()) == false)
242 CLibCEC::AddLog(CEC_LOG_ERROR
, "unable to set the physical address to %4x", m_configuration
.iPhysicalAddress
);
244 else if (m_configuration
.iPhysicalAddress
== 0 && (bReturn
= SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
, true)) == false)
245 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
);
247 if (m_configuration
.bActivateSource
== 1)
248 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->ActivateSource();
250 SetInitialised(bReturn
);
252 CLibCEC::ConfigurationChanged(m_configuration
);
257 bool CCECProcessor::Start(const char *strPort
, uint16_t iBaudRate
/* = 38400 */, uint32_t iTimeoutMs
/* = 10000 */)
262 CLockObject
lock(m_mutex
);
263 if (!OpenConnection(strPort
, iBaudRate
, iTimeoutMs
))
266 /* create the processor thread */
269 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
274 if ((bReturn
= Initialise()) == false)
276 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
281 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
287 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
289 if (m_busDevices
[address
]->TryLogicalAddress())
291 m_configuration
.logicalAddresses
.Set(address
);
298 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
300 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
301 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
302 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
303 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
306 bool CCECProcessor::FindLogicalAddressTuner(void)
308 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
309 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
310 TryLogicalAddress(CECDEVICE_TUNER2
) ||
311 TryLogicalAddress(CECDEVICE_TUNER3
) ||
312 TryLogicalAddress(CECDEVICE_TUNER4
);
315 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
317 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
318 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
319 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
320 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
323 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
325 CLibCEC::AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
326 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
329 bool CCECProcessor::ChangeDeviceType(cec_device_type from
, cec_device_type to
)
331 bool bChanged(false);
333 CLibCEC::AddLog(CEC_LOG_NOTICE
, "changing device type '%s' into '%s'", ToString(from
), ToString(to
));
335 CLockObject
lock(m_mutex
);
336 CCECBusDevice
*previousDevice
= GetDeviceByType(from
);
337 m_configuration
.logicalAddresses
.primary
= CECDEVICE_UNKNOWN
;
339 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
341 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
344 if (m_configuration
.deviceTypes
.types
[iPtr
] == from
)
347 m_configuration
.deviceTypes
.types
[iPtr
] = to
;
349 else if (m_configuration
.deviceTypes
.types
[iPtr
] == to
&& bChanged
)
351 m_configuration
.deviceTypes
.types
[iPtr
] = CEC_DEVICE_TYPE_RESERVED
;
357 FindLogicalAddresses();
359 CCECBusDevice
*newDevice
= GetDeviceByType(to
);
360 if (previousDevice
&& newDevice
)
362 newDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
);
363 previousDevice
->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT
);
365 newDevice
->SetCecVersion(previousDevice
->GetCecVersion(false));
366 previousDevice
->SetCecVersion(CEC_VERSION_UNKNOWN
);
368 newDevice
->SetMenuLanguage(previousDevice
->GetMenuLanguage(false));
369 cec_menu_language lang
;
370 lang
.device
= previousDevice
->GetLogicalAddress();
371 for (unsigned int iPtr
= 0; iPtr
< 4; iPtr
++)
372 lang
.language
[iPtr
] = '?';
373 lang
.language
[3] = 0;
374 previousDevice
->SetMenuLanguage(lang
);
376 newDevice
->SetMenuState(previousDevice
->GetMenuState());
377 previousDevice
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
379 newDevice
->SetOSDName(previousDevice
->GetOSDName(false));
380 previousDevice
->SetOSDName(ToString(previousDevice
->GetLogicalAddress()));
382 newDevice
->SetPhysicalAddress(previousDevice
->GetPhysicalAddress(false));
383 previousDevice
->SetPhysicalAddress(0xFFFF);
385 newDevice
->SetPowerStatus(previousDevice
->GetPowerStatus(false));
386 previousDevice
->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN
);
388 newDevice
->SetVendorId(previousDevice
->GetVendorId(false));
389 previousDevice
->SetVendorId(CEC_VENDOR_UNKNOWN
);
391 if ((from
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| from
== CEC_DEVICE_TYPE_RECORDING_DEVICE
) &&
392 (to
== CEC_DEVICE_TYPE_PLAYBACK_DEVICE
|| to
== CEC_DEVICE_TYPE_RECORDING_DEVICE
))
394 ((CCECPlaybackDevice
*) newDevice
)->SetDeckControlMode(((CCECPlaybackDevice
*) previousDevice
)->GetDeckControlMode());
395 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP
);
397 ((CCECPlaybackDevice
*) newDevice
)->SetDeckStatus(((CCECPlaybackDevice
*) previousDevice
)->GetDeckStatus());
398 ((CCECPlaybackDevice
*) previousDevice
)->SetDeckStatus(CEC_DECK_INFO_STOP
);
406 bool CCECProcessor::FindLogicalAddresses(void)
409 m_configuration
.logicalAddresses
.Clear();
411 if (m_configuration
.deviceTypes
.IsEmpty())
413 CLibCEC::AddLog(CEC_LOG_ERROR
, "no device types set");
417 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
419 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
422 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - device %d: type %d", __FUNCTION__
, iPtr
, m_configuration
.deviceTypes
.types
[iPtr
]);
424 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
425 bReturn
&= FindLogicalAddressRecordingDevice();
426 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
427 bReturn
&= FindLogicalAddressTuner();
428 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
429 bReturn
&= FindLogicalAddressPlaybackDevice();
430 if (m_configuration
.deviceTypes
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
431 bReturn
&= FindLogicalAddressAudioSystem();
435 SetAckMask(m_configuration
.logicalAddresses
.AckMask());
440 void CCECProcessor::ReplaceHandlers(void)
442 if (!IsInitialised())
444 for (uint8_t iPtr
= 0; iPtr
<= CECDEVICE_PLAYBACKDEVICE3
; iPtr
++)
445 m_busDevices
[iPtr
]->ReplaceHandler(m_bInitialised
);
448 bool CCECProcessor::OnCommandReceived(const cec_command
&command
)
450 ParseCommand(command
);
454 void *CCECProcessor::Process(void)
456 CLibCEC::AddLog(CEC_LOG_DEBUG
, "processor thread started");
458 while (!IsStopped() && m_communication
->IsOpen())
464 m_controller
->CheckKeypressTimeout();
472 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
479 cec_logical_address addr
= m_configuration
.logicalAddresses
.primary
;
481 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
483 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
485 if (m_configuration
.logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
487 addr
= (cec_logical_address
) iPtr
;
493 m_busDevices
[addr
]->SetActiveSource();
494 if (m_busDevices
[addr
]->GetPhysicalAddress(false) != 0xFFFF)
495 bReturn
= m_busDevices
[addr
]->ActivateSource();
500 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath
)
504 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
507 device
->SetActiveSource();
514 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout
)
516 CLockObject
lock(m_mutex
);
517 m_iStandardLineTimeout
= iTimeout
;
520 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout
)
522 CLockObject
lock(m_mutex
);
523 m_iRetryLineTimeout
= iTimeout
;
526 bool CCECProcessor::SetActiveView(void)
528 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
529 return SetActiveSource(m_configuration
.deviceTypes
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_configuration
.deviceTypes
[0]);
532 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
536 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
539 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
541 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
548 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
552 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
555 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
557 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
564 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
569 CLockObject
lock(m_mutex
);
570 m_configuration
.baseDevice
= iBaseDevice
;
571 m_configuration
.iHDMIPort
= iPort
;
574 if (!IsRunning() && !bForce
)
577 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
579 uint16_t iPhysicalAddress(0);
580 if (iBaseDevice
> CECDEVICE_TV
)
582 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
585 if (iPhysicalAddress
< 0xffff)
587 if (iPhysicalAddress
== 0)
588 iPhysicalAddress
+= 0x1000 * iPort
;
589 else if (iPhysicalAddress
% 0x1000 == 0)
590 iPhysicalAddress
+= 0x100 * iPort
;
591 else if (iPhysicalAddress
% 0x100 == 0)
592 iPhysicalAddress
+= 0x10 * iPort
;
593 else if (iPhysicalAddress
% 0x10 == 0)
594 iPhysicalAddress
+= iPort
;
600 CLibCEC::AddLog(CEC_LOG_ERROR
, "failed to set the physical address");
602 SetPhysicalAddress(iPhysicalAddress
);
607 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress
)
609 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
611 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
617 bool CCECProcessor::TransmitInactiveSource(void)
622 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
623 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitInactiveSource();
627 void CCECProcessor::LogOutput(const cec_command
&data
)
630 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
632 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
634 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
635 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
636 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
639 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
641 CLockObject
lock(m_mutex
);
642 if (m_configuration
.logicalAddresses
.primary
!= iLogicalAddress
)
644 CLibCEC::AddLog(CEC_LOG_NOTICE
, "<< setting primary logical address to %1x", iLogicalAddress
);
645 m_configuration
.logicalAddresses
.primary
= iLogicalAddress
;
646 m_configuration
.logicalAddresses
.Set(iLogicalAddress
);
647 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
653 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
655 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
657 if (m_configuration
.logicalAddresses
[iPtr
])
658 m_busDevices
[iPtr
]->SetMenuState(state
);
662 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
667 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
, bool bSendUpdate
/* = true */)
669 bool bSendActiveView(false);
671 cec_logical_addresses sendUpdatesTo
;
672 sendUpdatesTo
.Clear();
675 CLockObject
lock(m_mutex
);
676 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
677 CLibCEC::AddLog(CEC_LOG_DEBUG
, "setting physical address to '%4x'", iPhysicalAddress
);
679 if (!m_configuration
.logicalAddresses
.IsEmpty())
681 bool bWasActiveSource(false);
682 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
683 if (m_configuration
.logicalAddresses
[iPtr
])
685 bWasActiveSource
|= m_busDevices
[iPtr
]->IsActiveSource();
686 m_busDevices
[iPtr
]->SetInactiveSource();
687 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
689 sendUpdatesTo
.Set((cec_logical_address
)iPtr
);
692 bSendActiveView
= bWasActiveSource
&& bSendUpdate
;
697 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
698 if (sendUpdatesTo
[iPtr
])
699 m_busDevices
[iPtr
]->TransmitPhysicalAddress();
705 CLibCEC::ConfigurationChanged(m_configuration
);
710 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
712 CLibCEC::AddLog(CEC_LOG_NOTICE
, "== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
715 CLockObject
lock(m_mutex
);
716 m_bMonitor
= bEnable
;
720 return SetAckMask(0);
722 return SetAckMask(m_configuration
.logicalAddresses
.AckMask());
725 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
727 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
729 return m_configuration
.logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
730 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
731 m_busDevices
[m_configuration
.logicalAddresses
.primary
]->TransmitPoll(iAddress
);
736 uint8_t CCECProcessor::VolumeUp(bool bSendRelease
/* = true */)
739 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
740 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bSendRelease
);
745 uint8_t CCECProcessor::VolumeDown(bool bSendRelease
/* = true */)
748 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
749 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bSendRelease
);
754 uint8_t CCECProcessor::MuteAudio(bool bSendRelease
/* = true */)
757 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM
))
758 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bSendRelease
);
763 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
765 if (m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
766 return m_busDevices
[m_configuration
.logicalAddresses
.primary
];
768 CCECBusDevice
*device
= NULL
;
769 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
771 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
773 device
= m_busDevices
[iPtr
];
781 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
783 CCECBusDevice
*device
= NULL
;
785 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
787 if (m_busDevices
[iPtr
]->m_type
== type
&& m_configuration
.logicalAddresses
[iPtr
])
789 device
= m_busDevices
[iPtr
];
797 CCECBusDevice
*CCECProcessor::GetPrimaryDevice(void) const
799 CCECBusDevice
*device(NULL
);
800 cec_logical_address primary
= m_configuration
.logicalAddresses
.primary
;
801 if (primary
!= CECDEVICE_UNKNOWN
)
802 device
= m_busDevices
[primary
];
806 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
808 return m_busDevices
[iAddress
]->GetCecVersion();
811 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
813 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
816 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
817 retVal
.device
= iAddress
;
822 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
824 if (m_busDevices
[iAddress
])
826 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
827 return (strcmp(language
->language
, "???") != 0);
832 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
834 if (m_busDevices
[iAddress
])
835 return m_busDevices
[iAddress
]->GetVendorId();
839 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress
)
841 if (m_busDevices
[iAddress
])
842 return m_busDevices
[iAddress
]->GetPhysicalAddress(false);
846 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
848 if (m_busDevices
[iAddress
])
849 return m_busDevices
[iAddress
]->GetPowerStatus();
850 return CEC_POWER_STATUS_UNKNOWN
;
853 cec_logical_address
CCECProcessor::GetActiveSource(void)
855 for (uint8_t iPtr
= 0; iPtr
<= 11; iPtr
++)
857 if (m_busDevices
[iPtr
]->IsActiveSource())
858 return (cec_logical_address
)iPtr
;
861 return CECDEVICE_UNKNOWN
;
864 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress
)
866 return m_busDevices
[iAddress
]->IsActiveSource();
869 bool CCECProcessor::Transmit(const cec_command
&data
)
871 if (m_configuration
.logicalAddresses
[(uint8_t)data
.destination
])
873 CLibCEC::AddLog(CEC_LOG_WARNING
, "not sending data to myself!");
877 uint8_t iMaxTries(0);
879 CLockObject
lock(m_mutex
);
883 m_iLastTransmission
= GetTimeMs();
884 if (!m_communication
|| !m_communication
->IsOpen())
886 CLibCEC::AddLog(CEC_LOG_ERROR
, "cannot transmit command: connection closed");
889 iMaxTries
= m_busDevices
[data
.initiator
]->GetHandler()->GetTransmitRetries() + 1;
892 return m_communication
->Write(data
, iMaxTries
, m_iLineTimeout
, m_iRetryLineTimeout
)
893 == ADAPTER_MESSAGE_STATE_SENT_ACKED
;
896 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
898 CLibCEC::AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
902 cec_command::Format(command
, m_configuration
.logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
903 command
.parameters
.PushBack((uint8_t)opcode
);
904 command
.parameters
.PushBack((uint8_t)reason
);
909 void CCECProcessor::ParseCommand(const cec_command
&command
)
912 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
913 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
914 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
915 CLibCEC::AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
917 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
918 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
921 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
923 cec_logical_addresses addresses
;
925 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
927 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
928 addresses
.Set((cec_logical_address
) iPtr
);
933 bool CCECProcessor::IsPresentDevice(cec_logical_address address
)
935 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
938 bool CCECProcessor::IsPresentDeviceType(cec_device_type type
)
940 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
942 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
949 uint16_t CCECProcessor::GetPhysicalAddress(void) const
951 if (!m_configuration
.logicalAddresses
.IsEmpty() && m_busDevices
[m_configuration
.logicalAddresses
.primary
])
952 return m_busDevices
[m_configuration
.logicalAddresses
.primary
]->GetPhysicalAddress(false);
956 bool CCECProcessor::SetAckMask(uint16_t iMask
)
958 return m_communication
->SetAckMask(iMask
);
961 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
963 return m_busDevices
[iDestination
]->TransmitKeypress(key
, bWait
);
966 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination
, bool bWait
/* = true */)
968 return m_busDevices
[iDestination
]->TransmitKeyRelease(bWait
);
971 bool CCECProcessor::EnablePhysicalAddressDetection(void)
973 CLibCEC::AddLog(CEC_LOG_WARNING
, "deprecated method %s called", __FUNCTION__
);
974 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
975 if (iPhysicalAddress
!= 0)
977 m_configuration
.bAutodetectAddress
= 1;
978 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
979 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
980 m_configuration
.iHDMIPort
= 0;
981 return SetPhysicalAddress(iPhysicalAddress
);
986 bool CCECProcessor::StandbyDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
988 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
991 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
993 if (m_configuration
.powerOffDevices
[iPtr
])
994 bReturn
&= m_busDevices
[iPtr
]->Standby();
999 return m_busDevices
[address
]->Standby();
1002 bool CCECProcessor::PowerOnDevices(cec_logical_address address
/* = CECDEVICE_BROADCAST */)
1004 if (address
== CECDEVICE_BROADCAST
&& m_configuration
.clientVersion
>= CEC_CLIENT_VERSION_1_5_0
)
1007 for (uint8_t iPtr
= 0; iPtr
<= 0xF; iPtr
++)
1009 if (m_configuration
.powerOffDevices
[iPtr
])
1010 bReturn
&= m_busDevices
[iPtr
]->PowerOn();
1015 return m_busDevices
[address
]->PowerOn();
1018 const char *CCECProcessor::ToString(const cec_device_type type
)
1022 case CEC_DEVICE_TYPE_AUDIO_SYSTEM
:
1023 return "audio system";
1024 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE
:
1025 return "playback device";
1026 case CEC_DEVICE_TYPE_RECORDING_DEVICE
:
1027 return "recording device";
1028 case CEC_DEVICE_TYPE_RESERVED
:
1030 case CEC_DEVICE_TYPE_TUNER
:
1032 case CEC_DEVICE_TYPE_TV
:
1039 const char *CCECProcessor::ToString(const cec_menu_state state
)
1043 case CEC_MENU_STATE_ACTIVATED
:
1045 case CEC_MENU_STATE_DEACTIVATED
:
1046 return "deactivated";
1052 const char *CCECProcessor::ToString(const cec_version version
)
1056 case CEC_VERSION_1_2
:
1058 case CEC_VERSION_1_2A
:
1060 case CEC_VERSION_1_3
:
1062 case CEC_VERSION_1_3A
:
1064 case CEC_VERSION_1_4
:
1071 const char *CCECProcessor::ToString(const cec_power_status status
)
1075 case CEC_POWER_STATUS_ON
:
1077 case CEC_POWER_STATUS_STANDBY
:
1079 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
1080 return "in transition from on to standby";
1081 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
1082 return "in transition from standby to on";
1088 const char *CCECProcessor::ToString(const cec_logical_address address
)
1092 case CECDEVICE_AUDIOSYSTEM
:
1094 case CECDEVICE_BROADCAST
:
1096 case CECDEVICE_FREEUSE
:
1098 case CECDEVICE_PLAYBACKDEVICE1
:
1099 return "Playback 1";
1100 case CECDEVICE_PLAYBACKDEVICE2
:
1101 return "Playback 2";
1102 case CECDEVICE_PLAYBACKDEVICE3
:
1103 return "Playback 3";
1104 case CECDEVICE_RECORDINGDEVICE1
:
1105 return "Recorder 1";
1106 case CECDEVICE_RECORDINGDEVICE2
:
1107 return "Recorder 2";
1108 case CECDEVICE_RECORDINGDEVICE3
:
1109 return "Recorder 3";
1110 case CECDEVICE_RESERVED1
:
1111 return "Reserved 1";
1112 case CECDEVICE_RESERVED2
:
1113 return "Reserved 2";
1114 case CECDEVICE_TUNER1
:
1116 case CECDEVICE_TUNER2
:
1118 case CECDEVICE_TUNER3
:
1120 case CECDEVICE_TUNER4
:
1129 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
1133 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
1134 return "skip forward wind";
1135 case CEC_DECK_CONTROL_MODE_EJECT
:
1137 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
1138 return "reverse rewind";
1139 case CEC_DECK_CONTROL_MODE_STOP
:
1146 const char *CCECProcessor::ToString(const cec_deck_info status
)
1150 case CEC_DECK_INFO_PLAY
:
1152 case CEC_DECK_INFO_RECORD
:
1154 case CEC_DECK_INFO_PLAY_REVERSE
:
1155 return "play reverse";
1156 case CEC_DECK_INFO_STILL
:
1158 case CEC_DECK_INFO_SLOW
:
1160 case CEC_DECK_INFO_SLOW_REVERSE
:
1161 return "slow reverse";
1162 case CEC_DECK_INFO_FAST_FORWARD
:
1163 return "fast forward";
1164 case CEC_DECK_INFO_FAST_REVERSE
:
1165 return "fast reverse";
1166 case CEC_DECK_INFO_NO_MEDIA
:
1168 case CEC_DECK_INFO_STOP
:
1170 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
1171 return "info skip forward wind";
1172 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
1173 return "info skip reverse rewind";
1174 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
1175 return "info index search forward";
1176 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
1177 return "info index search reverse";
1178 case CEC_DECK_INFO_OTHER_STATUS
:
1185 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1189 case CEC_OPCODE_ACTIVE_SOURCE
:
1190 return "active source";
1191 case CEC_OPCODE_IMAGE_VIEW_ON
:
1192 return "image view on";
1193 case CEC_OPCODE_TEXT_VIEW_ON
:
1194 return "text view on";
1195 case CEC_OPCODE_INACTIVE_SOURCE
:
1196 return "inactive source";
1197 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1198 return "request active source";
1199 case CEC_OPCODE_ROUTING_CHANGE
:
1200 return "routing change";
1201 case CEC_OPCODE_ROUTING_INFORMATION
:
1202 return "routing information";
1203 case CEC_OPCODE_SET_STREAM_PATH
:
1204 return "set stream path";
1205 case CEC_OPCODE_STANDBY
:
1207 case CEC_OPCODE_RECORD_OFF
:
1208 return "record off";
1209 case CEC_OPCODE_RECORD_ON
:
1211 case CEC_OPCODE_RECORD_STATUS
:
1212 return "record status";
1213 case CEC_OPCODE_RECORD_TV_SCREEN
:
1214 return "record tv screen";
1215 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1216 return "clear analogue timer";
1217 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1218 return "clear digital timer";
1219 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1220 return "clear external timer";
1221 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1222 return "set analogue timer";
1223 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1224 return "set digital timer";
1225 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1226 return "set external timer";
1227 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1228 return "set timer program title";
1229 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1230 return "timer cleared status";
1231 case CEC_OPCODE_TIMER_STATUS
:
1232 return "timer status";
1233 case CEC_OPCODE_CEC_VERSION
:
1234 return "cec version";
1235 case CEC_OPCODE_GET_CEC_VERSION
:
1236 return "get cec version";
1237 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1238 return "give physical address";
1239 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1240 return "get menu language";
1241 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1242 return "report physical address";
1243 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1244 return "set menu language";
1245 case CEC_OPCODE_DECK_CONTROL
:
1246 return "deck control";
1247 case CEC_OPCODE_DECK_STATUS
:
1248 return "deck status";
1249 case CEC_OPCODE_GIVE_DECK_STATUS
:
1250 return "give deck status";
1251 case CEC_OPCODE_PLAY
:
1253 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1254 return "give tuner status";
1255 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1256 return "select analogue service";
1257 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1258 return "set digital service";
1259 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1260 return "tuner device status";
1261 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1262 return "tuner step decrement";
1263 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1264 return "tuner step increment";
1265 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1266 return "device vendor id";
1267 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1268 return "give device vendor id";
1269 case CEC_OPCODE_VENDOR_COMMAND
:
1270 return "vendor command";
1271 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1272 return "vendor command with id";
1273 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1274 return "vendor remote button down";
1275 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1276 return "vendor remote button up";
1277 case CEC_OPCODE_SET_OSD_STRING
:
1278 return "set osd string";
1279 case CEC_OPCODE_GIVE_OSD_NAME
:
1280 return "give osd name";
1281 case CEC_OPCODE_SET_OSD_NAME
:
1282 return "set osd name";
1283 case CEC_OPCODE_MENU_REQUEST
:
1284 return "menu request";
1285 case CEC_OPCODE_MENU_STATUS
:
1286 return "menu status";
1287 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1288 return "user control pressed";
1289 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1290 return "user control release";
1291 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1292 return "give device power status";
1293 case CEC_OPCODE_REPORT_POWER_STATUS
:
1294 return "report power status";
1295 case CEC_OPCODE_FEATURE_ABORT
:
1296 return "feature abort";
1297 case CEC_OPCODE_ABORT
:
1299 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1300 return "give audio status";
1301 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1302 return "give audio mode status";
1303 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1304 return "report audio status";
1305 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1306 return "set system audio mode";
1307 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1308 return "system audio mode request";
1309 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1310 return "system audio mode status";
1311 case CEC_OPCODE_SET_AUDIO_RATE
:
1312 return "set audio rate";
1313 case CEC_OPCODE_NONE
:
1320 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1324 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1326 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1333 const char *CCECProcessor::ToString(const cec_audio_status
UNUSED(status
))
1335 // TODO this is a mask
1339 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1343 case CEC_VENDOR_SAMSUNG
:
1347 case CEC_VENDOR_PANASONIC
:
1349 case CEC_VENDOR_PIONEER
:
1351 case CEC_VENDOR_ONKYO
:
1353 case CEC_VENDOR_YAMAHA
:
1355 case CEC_VENDOR_PHILIPS
:
1357 case CEC_VENDOR_SONY
:
1359 case CEC_VENDOR_TOSHIBA
:
1366 const char *CCECProcessor::ToString(const cec_client_version version
)
1370 case CEC_CLIENT_VERSION_PRE_1_5
:
1372 case CEC_CLIENT_VERSION_1_5_0
:
1374 case CEC_CLIENT_VERSION_1_5_1
:
1376 case CEC_CLIENT_VERSION_1_5_2
:
1383 const char *CCECProcessor::ToString(const cec_server_version version
)
1387 case CEC_SERVER_VERSION_PRE_1_5
:
1389 case CEC_SERVER_VERSION_1_5_0
:
1391 case CEC_SERVER_VERSION_1_5_1
:
1393 case CEC_SERVER_VERSION_1_5_2
:
1400 void *CCECBusScan::Process(void)
1402 CCECBusDevice
*device(NULL
);
1403 uint8_t iCounter(0);
1405 while (!IsStopped())
1407 if (++iCounter
< 10)
1412 for (unsigned int iPtr
= 0; iPtr
<= 11 && !IsStopped(); iPtr
++)
1414 device
= m_processor
->m_busDevices
[iPtr
];
1416 if (device
&& device
->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT
)
1420 device
->GetVendorId();
1424 device
->GetPowerStatus(true);
1432 void CCECBusScan::WaitUntilIdle(void)
1437 int32_t iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1438 while (iWaitTime
> 0)
1441 iWaitTime
= 3000 - (int32_t)(GetTimeMs() - m_processor
->GetLastTransmission());
1445 bool CCECProcessor::StartBootloader(const char *strPort
/* = NULL */)
1447 if (!m_communication
&& strPort
)
1449 bool bReturn(false);
1450 IAdapterCommunication
*comm
= new CUSBCECAdapterCommunication(this, strPort
);
1451 CTimeout
timeout(10000);
1453 while (timeout
.TimeLeft() > 0 && (bReturn
= comm
->Open(NULL
, (timeout
.TimeLeft() / CEC_CONNECT_TRIES
)), true) == false)
1455 CLibCEC::AddLog(CEC_LOG_ERROR
, "could not open a connection (try %d)", ++iConnectTry
);
1461 bReturn
= comm
->StartBootloader();
1468 return m_communication
->StartBootloader();
1472 bool CCECProcessor::PingAdapter(void)
1474 return m_communication
->PingAdapter();
1477 void CCECProcessor::HandlePoll(cec_logical_address initiator
, cec_logical_address destination
)
1479 m_busDevices
[initiator
]->HandlePoll(destination
);
1482 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator
)
1484 return !m_busDevices
[initiator
]->HandleReceiveFailed();
1487 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress
)
1489 // stream path changes are sent by the TV
1490 return m_busDevices
[CECDEVICE_TV
]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress
);
1493 bool CCECProcessor::SetConfiguration(const libcec_configuration
*configuration
)
1495 bool bReinit(false);
1496 CCECBusDevice
*primary
= IsRunning() ? GetPrimaryDevice() : NULL
;
1497 cec_device_type oldPrimaryType
= primary
? primary
->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE
;
1498 m_configuration
.clientVersion
= configuration
->clientVersion
;
1500 // client version 1.5.0
1503 bool bDeviceTypeChanged
= IsRunning () && m_configuration
.deviceTypes
!= configuration
->deviceTypes
;
1504 m_configuration
.deviceTypes
= configuration
->deviceTypes
;
1506 bool bPhysicalAddressChanged(false);
1508 // autodetect address
1509 bool bPhysicalAutodetected(false);
1510 if (IsRunning() && configuration
->bAutodetectAddress
== 1)
1512 uint16_t iPhysicalAddress
= m_communication
->GetPhysicalAddress();
1513 if (iPhysicalAddress
!= 0)
1516 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - autodetected physical address '%4x'", __FUNCTION__
, iPhysicalAddress
);
1517 bPhysicalAddressChanged
= (m_configuration
.iPhysicalAddress
!= iPhysicalAddress
);
1518 m_configuration
.iPhysicalAddress
= iPhysicalAddress
;
1519 m_configuration
.iHDMIPort
= 0;
1520 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1521 bPhysicalAutodetected
= true;
1526 if (!bPhysicalAutodetected
)
1528 if (configuration
->iPhysicalAddress
!= 0)
1529 bPhysicalAddressChanged
= IsRunning() && m_configuration
.iPhysicalAddress
!= configuration
->iPhysicalAddress
;
1531 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using physical address '%4x'", __FUNCTION__
, configuration
->iPhysicalAddress
);
1532 m_configuration
.iPhysicalAddress
= configuration
->iPhysicalAddress
;
1535 bool bHdmiPortChanged(false);
1536 if (!bPhysicalAutodetected
&& !bPhysicalAddressChanged
)
1539 bHdmiPortChanged
= IsRunning() && m_configuration
.baseDevice
!= configuration
->baseDevice
;
1541 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using base device '%x'", __FUNCTION__
, (int)configuration
->baseDevice
);
1542 m_configuration
.baseDevice
= configuration
->baseDevice
;
1545 bHdmiPortChanged
|= IsRunning() && m_configuration
.iHDMIPort
!= configuration
->iHDMIPort
;
1547 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - using HDMI port '%d'", __FUNCTION__
, configuration
->iHDMIPort
);
1548 m_configuration
.iHDMIPort
= configuration
->iHDMIPort
;
1553 CLibCEC::AddLog(CEC_LOG_DEBUG
, "%s - resetting HDMI port and base device to defaults", __FUNCTION__
);
1554 m_configuration
.baseDevice
= CECDEVICE_UNKNOWN
;
1555 m_configuration
.iHDMIPort
= 0;
1558 bReinit
= bPhysicalAddressChanged
|| bHdmiPortChanged
|| bDeviceTypeChanged
;
1561 snprintf(m_configuration
.strDeviceName
, 13, "%s", configuration
->strDeviceName
);
1562 if (primary
&& !primary
->GetOSDName().Equals(m_configuration
.strDeviceName
))
1564 primary
->SetOSDName(m_configuration
.strDeviceName
);
1565 if (!bReinit
&& IsRunning())
1566 primary
->TransmitOSDName(CECDEVICE_TV
);
1569 // tv vendor id override
1570 if (m_configuration
.tvVendor
!= configuration
->tvVendor
)
1572 m_configuration
.tvVendor
= configuration
->tvVendor
;
1573 m_busDevices
[CECDEVICE_TV
]->SetVendorId((uint64_t)m_configuration
.tvVendor
);
1577 if (m_configuration
.wakeDevices
!= configuration
->wakeDevices
)
1579 m_configuration
.wakeDevices
= configuration
->wakeDevices
;
1580 if (!bReinit
&& IsRunning())
1585 m_configuration
.clientVersion
= configuration
->clientVersion
;
1586 m_configuration
.bActivateSource
= configuration
->bActivateSource
;
1587 m_configuration
.bGetSettingsFromROM
= configuration
->bGetSettingsFromROM
;
1588 m_configuration
.powerOffDevices
= configuration
->powerOffDevices
;
1589 m_configuration
.bPowerOffScreensaver
= configuration
->bPowerOffScreensaver
;
1590 m_configuration
.bPowerOffOnStandby
= configuration
->bPowerOffOnStandby
;
1592 // client version 1.5.1
1593 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1594 m_configuration
.bSendInactiveSource
= configuration
->bSendInactiveSource
;
1596 // ensure that there is at least 1 device type set
1597 if (m_configuration
.deviceTypes
.IsEmpty())
1598 m_configuration
.deviceTypes
.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE
);
1602 if (bDeviceTypeChanged
)
1603 return ChangeDeviceType(oldPrimaryType
, m_configuration
.deviceTypes
[0]);
1604 else if (bPhysicalAddressChanged
)
1605 return SetPhysicalAddress(m_configuration
.iPhysicalAddress
);
1607 return SetHDMIPort(m_configuration
.baseDevice
, m_configuration
.iHDMIPort
);
1609 else if (m_configuration
.bActivateSource
== 1 && IsRunning() && !IsActiveSource(m_configuration
.logicalAddresses
.primary
))
1611 // activate the source if we're not already the active source
1612 SetActiveSource(m_configuration
.deviceTypes
.types
[0]);
1618 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration
*configuration
)
1620 // client version 1.5.0
1621 snprintf(configuration
->strDeviceName
, 13, "%s", m_configuration
.strDeviceName
);
1622 configuration
->deviceTypes
= m_configuration
.deviceTypes
;
1623 configuration
->bAutodetectAddress
= m_configuration
.bAutodetectAddress
;
1624 configuration
->iPhysicalAddress
= m_configuration
.iPhysicalAddress
;
1625 configuration
->baseDevice
= m_configuration
.baseDevice
;
1626 configuration
->iHDMIPort
= m_configuration
.iHDMIPort
;
1627 configuration
->clientVersion
= m_configuration
.clientVersion
;
1628 configuration
->serverVersion
= m_configuration
.serverVersion
;
1629 configuration
->tvVendor
= m_configuration
.tvVendor
;
1631 configuration
->bGetSettingsFromROM
= m_configuration
.bGetSettingsFromROM
;
1632 configuration
->bUseTVMenuLanguage
= m_configuration
.bUseTVMenuLanguage
;
1633 configuration
->bActivateSource
= m_configuration
.bActivateSource
;
1634 configuration
->wakeDevices
= m_configuration
.wakeDevices
;
1635 configuration
->powerOffDevices
= m_configuration
.powerOffDevices
;
1636 configuration
->bPowerOffScreensaver
= m_configuration
.bPowerOffScreensaver
;
1637 configuration
->bPowerOffOnStandby
= m_configuration
.bPowerOffOnStandby
;
1639 // client version 1.5.1
1640 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_1
)
1641 configuration
->bSendInactiveSource
= m_configuration
.bSendInactiveSource
;
1643 // client version 1.5.3
1644 if (configuration
->clientVersion
>= CEC_CLIENT_VERSION_1_5_3
)
1645 configuration
->logicalAddresses
= m_configuration
.logicalAddresses
;
1650 bool CCECProcessor::CanPersistConfiguration(void)
1652 return m_communication
->GetFirmwareVersion() >= 2;
1655 bool CCECProcessor::PersistConfiguration(libcec_configuration
*configuration
)
1657 return m_communication
->PersistConfiguration(configuration
);
1660 void CCECProcessor::RescanActiveDevices(void)
1662 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
1663 m_busDevices
[iPtr
]->GetStatus(true);