Commit | Line | Data |
---|---|---|
2abe74eb LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
2abe74eb LOK |
5 | * libCEC(R) is an original work, containing original code. |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
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/ | |
31 | */ | |
32 | ||
33 | #include "LibCEC.h" | |
34 | ||
7bb4ed43 | 35 | #include "adapter/USBCECAdapterDetection.h" |
08d80226 | 36 | #include "adapter/USBCECAdapterCommunication.h" |
2abe74eb | 37 | #include "CECProcessor.h" |
0f23c85c | 38 | #include "devices/CECBusDevice.h" |
ba65909d LOK |
39 | #include "platform/util/timeutils.h" |
40 | #include "platform/util/StdString.h" | |
2abe74eb LOK |
41 | |
42 | using namespace std; | |
43 | using namespace CEC; | |
f00ff009 | 44 | using namespace PLATFORM; |
2abe74eb | 45 | |
4f362964 | 46 | CLibCEC::CLibCEC(const char *strDeviceName, cec_device_type_list types, uint16_t iPhysicalAddress /* = 0 */) : |
f8513317 LOK |
47 | m_iStartTime(GetTimeMs()), |
48 | m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), | |
fa4798bd | 49 | m_buttontime(0), |
547b390d LOK |
50 | m_callbacks(NULL), |
51 | m_cbParam(NULL) | |
f8513317 | 52 | { |
7bdfd76c | 53 | m_cec = new CCECProcessor(this, strDeviceName, types, iPhysicalAddress); |
caca2d81 LOK |
54 | } |
55 | ||
3efda01a | 56 | CLibCEC::CLibCEC(libcec_configuration *configuration) : |
caca2d81 LOK |
57 | m_iStartTime(GetTimeMs()), |
58 | m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), | |
59 | m_buttontime(0), | |
60 | m_callbacks(configuration->callbacks), | |
61 | m_cbParam(configuration->callbackParam) | |
62 | { | |
b98fc43d | 63 | configuration->serverVersion = CEC_SERVER_VERSION_1_6_0; |
caca2d81 | 64 | m_cec = new CCECProcessor(this, configuration); |
f8513317 LOK |
65 | } |
66 | ||
2abe74eb LOK |
67 | CLibCEC::~CLibCEC(void) |
68 | { | |
69 | delete m_cec; | |
2abe74eb LOK |
70 | } |
71 | ||
25701fa6 | 72 | bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */) |
2abe74eb | 73 | { |
1113cb7d | 74 | if (m_cec->IsRunning()) |
2abe74eb LOK |
75 | { |
76 | AddLog(CEC_LOG_ERROR, "connection already open"); | |
77 | return false; | |
78 | } | |
79 | ||
1113cb7d | 80 | if (!m_cec->Start(strPort, 38400, iTimeoutMs)) |
2abe74eb LOK |
81 | { |
82 | AddLog(CEC_LOG_ERROR, "could not start CEC communications"); | |
83 | return false; | |
84 | } | |
85 | ||
86 | return true; | |
87 | } | |
88 | ||
89 | void CLibCEC::Close(void) | |
90 | { | |
25701fa6 | 91 | if (m_cec) |
eca71746 | 92 | m_cec->Close(); |
2abe74eb LOK |
93 | } |
94 | ||
547b390d | 95 | bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) |
fa4798bd | 96 | { |
f00ff009 | 97 | CLockObject lock(m_mutex); |
fa4798bd | 98 | if (m_cec) |
547b390d LOK |
99 | { |
100 | m_cbParam = cbParam; | |
fa4798bd | 101 | m_callbacks = callbacks; |
547b390d | 102 | } |
fa4798bd LOK |
103 | return false; |
104 | } | |
105 | ||
25701fa6 | 106 | int8_t CLibCEC::FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) |
2abe74eb LOK |
107 | { |
108 | CStdString strDebug; | |
109 | if (strDevicePath) | |
110 | strDebug.Format("trying to autodetect the com port for device path '%s'", strDevicePath); | |
111 | else | |
112 | strDebug.Format("trying to autodetect all CEC adapters"); | |
113 | AddLog(CEC_LOG_DEBUG, strDebug); | |
114 | ||
7bb4ed43 | 115 | return CUSBCECAdapterDetection::FindAdapters(deviceList, iBufSize, strDevicePath); |
2abe74eb LOK |
116 | } |
117 | ||
118 | bool CLibCEC::PingAdapter(void) | |
119 | { | |
1113cb7d | 120 | return m_cec ? m_cec->PingAdapter() : false; |
2abe74eb LOK |
121 | } |
122 | ||
123 | bool CLibCEC::StartBootloader(void) | |
124 | { | |
1113cb7d | 125 | return m_cec ? m_cec->StartBootloader() : false; |
2abe74eb LOK |
126 | } |
127 | ||
2abe74eb LOK |
128 | bool CLibCEC::GetNextLogMessage(cec_log_message *message) |
129 | { | |
25701fa6 | 130 | return (m_logBuffer.Pop(*message)); |
2abe74eb LOK |
131 | } |
132 | ||
133 | bool CLibCEC::GetNextKeypress(cec_keypress *key) | |
134 | { | |
135 | return m_keyBuffer.Pop(*key); | |
136 | } | |
137 | ||
138 | bool CLibCEC::GetNextCommand(cec_command *command) | |
139 | { | |
140 | return m_commandBuffer.Pop(*command); | |
141 | } | |
142 | ||
8d84e2c0 | 143 | bool CLibCEC::Transmit(const cec_command &data) |
2abe74eb | 144 | { |
8d84e2c0 | 145 | return m_cec ? m_cec->Transmit(data) : false; |
2abe74eb LOK |
146 | } |
147 | ||
148 | bool CLibCEC::SetLogicalAddress(cec_logical_address iLogicalAddress) | |
149 | { | |
150 | return m_cec ? m_cec->SetLogicalAddress(iLogicalAddress) : false; | |
151 | } | |
152 | ||
16b1e052 | 153 | bool CLibCEC::SetPhysicalAddress(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) |
2492216a LOK |
154 | { |
155 | return m_cec ? m_cec->SetPhysicalAddress(iPhysicalAddress) : false; | |
156 | } | |
157 | ||
d2f1c157 | 158 | bool CLibCEC::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort /* = CEC_DEFAULT_HDMI_PORT */) |
16b1e052 | 159 | { |
d2f1c157 | 160 | return m_cec ? m_cec->SetHDMIPort(iBaseDevice, iPort) : false; |
16b1e052 LOK |
161 | } |
162 | ||
2dbd78f8 LOK |
163 | bool CLibCEC::EnablePhysicalAddressDetection(void) |
164 | { | |
165 | return m_cec ? m_cec->EnablePhysicalAddressDetection() : false; | |
166 | } | |
167 | ||
2abe74eb LOK |
168 | bool CLibCEC::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV */) |
169 | { | |
ca27e6cf | 170 | return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->PowerOnDevices(address) : false; |
2abe74eb LOK |
171 | } |
172 | ||
173 | bool CLibCEC::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */) | |
174 | { | |
ca27e6cf | 175 | return m_cec && address >= CECDEVICE_TV && address <= CECDEVICE_BROADCAST ? m_cec->StandbyDevices(address) : false; |
2abe74eb LOK |
176 | } |
177 | ||
18203d17 LOK |
178 | bool CLibCEC::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */) |
179 | { | |
180 | return m_cec ? m_cec->SetActiveSource(type) : false; | |
181 | } | |
182 | ||
2abe74eb LOK |
183 | bool CLibCEC::SetActiveView(void) |
184 | { | |
185 | return m_cec ? m_cec->SetActiveView() : false; | |
186 | } | |
187 | ||
28fa6c97 | 188 | bool CLibCEC::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) |
a9232a79 | 189 | { |
28fa6c97 | 190 | return m_cec ? m_cec->SetDeckControlMode(mode, bSendUpdate) : false; |
a9232a79 LOK |
191 | } |
192 | ||
28fa6c97 | 193 | bool CLibCEC::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) |
a9232a79 | 194 | { |
28fa6c97 | 195 | return m_cec ? m_cec->SetDeckInfo(info, bSendUpdate) : false; |
a9232a79 LOK |
196 | } |
197 | ||
2abe74eb LOK |
198 | bool CLibCEC::SetInactiveView(void) |
199 | { | |
8fb8355c | 200 | return m_cec ? m_cec->TransmitInactiveSource() : false; |
2abe74eb LOK |
201 | } |
202 | ||
28fa6c97 LOK |
203 | bool CLibCEC::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) |
204 | { | |
205 | return m_cec ? m_cec->SetMenuState(state, bSendUpdate) : false; | |
206 | } | |
207 | ||
1969b140 LOK |
208 | bool CLibCEC::SetOSDString(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
209 | { | |
38bdb943 LOK |
210 | return m_cec && iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST ? |
211 | m_cec->m_busDevices[m_cec->GetLogicalAddress()]->TransmitOSDString(iLogicalAddress, duration, strMessage) : | |
212 | false; | |
1969b140 LOK |
213 | } |
214 | ||
8b7e5ff6 LOK |
215 | bool CLibCEC::SwitchMonitoring(bool bEnable) |
216 | { | |
217 | return m_cec ? m_cec->SwitchMonitoring(bEnable) : false; | |
218 | } | |
219 | ||
6a1c0009 LOK |
220 | cec_version CLibCEC::GetDeviceCecVersion(cec_logical_address iAddress) |
221 | { | |
222 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
223 | return m_cec->GetDeviceCecVersion(iAddress); | |
224 | return CEC_VERSION_UNKNOWN; | |
225 | } | |
226 | ||
a3269a0a LOK |
227 | bool CLibCEC::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
228 | { | |
229 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
230 | return m_cec->GetDeviceMenuLanguage(iAddress, language); | |
231 | return false; | |
232 | } | |
233 | ||
44c74256 LOK |
234 | uint64_t CLibCEC::GetDeviceVendorId(cec_logical_address iAddress) |
235 | { | |
236 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
237 | return m_cec->GetDeviceVendorId(iAddress); | |
238 | return 0; | |
239 | } | |
240 | ||
eab72c40 LOK |
241 | uint16_t CLibCEC::GetDevicePhysicalAddress(cec_logical_address iAddress) |
242 | { | |
243 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
244 | return m_cec->GetDevicePhysicalAddress(iAddress); | |
245 | return 0; | |
246 | } | |
247 | ||
b4b1b49b LOK |
248 | cec_logical_address CLibCEC::GetActiveSource(void) |
249 | { | |
250 | return m_cec ? m_cec->GetActiveSource() : CECDEVICE_UNKNOWN; | |
251 | } | |
252 | ||
253 | bool CLibCEC::IsActiveSource(cec_logical_address iAddress) | |
254 | { | |
255 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
256 | return m_cec->IsActiveSource(iAddress); | |
257 | return false; | |
258 | } | |
259 | ||
e55f3f70 LOK |
260 | cec_power_status CLibCEC::GetDevicePowerStatus(cec_logical_address iAddress) |
261 | { | |
262 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
263 | return m_cec->GetDevicePowerStatus(iAddress); | |
264 | return CEC_POWER_STATUS_UNKNOWN; | |
265 | } | |
44c74256 | 266 | |
57f45e6c LOK |
267 | bool CLibCEC::PollDevice(cec_logical_address iAddress) |
268 | { | |
269 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
270 | return m_cec->PollDevice(iAddress); | |
271 | return false; | |
272 | } | |
273 | ||
6d858ba4 LOK |
274 | cec_logical_addresses CLibCEC::GetActiveDevices(void) |
275 | { | |
276 | cec_logical_addresses addresses; | |
988de7b9 | 277 | addresses.Clear(); |
6d858ba4 LOK |
278 | if (m_cec) |
279 | addresses = m_cec->GetActiveDevices(); | |
280 | return addresses; | |
281 | } | |
282 | ||
283 | bool CLibCEC::IsActiveDevice(cec_logical_address iAddress) | |
284 | { | |
285 | if (m_cec && iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST) | |
37b0c572 | 286 | return m_cec->IsPresentDevice(iAddress); |
6d858ba4 LOK |
287 | return false; |
288 | } | |
289 | ||
290 | bool CLibCEC::IsActiveDeviceType(cec_device_type type) | |
291 | { | |
292 | if (m_cec && type >= CEC_DEVICE_TYPE_TV && type <= CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
37b0c572 | 293 | return m_cec->IsPresentDeviceType(type); |
6d858ba4 LOK |
294 | return false; |
295 | } | |
296 | ||
5c73f7f7 | 297 | uint8_t CLibCEC::VolumeUp(bool bSendRelease /* = true */) |
04e637f9 LOK |
298 | { |
299 | if (m_cec) | |
5c73f7f7 | 300 | return m_cec->VolumeUp(bSendRelease); |
04e637f9 LOK |
301 | return 0; |
302 | } | |
303 | ||
5c73f7f7 | 304 | uint8_t CLibCEC::VolumeDown(bool bSendRelease /* = true */) |
04e637f9 LOK |
305 | { |
306 | if (m_cec) | |
5c73f7f7 | 307 | return m_cec->VolumeDown(bSendRelease); |
04e637f9 LOK |
308 | return 0; |
309 | } | |
310 | ||
311 | ||
5c73f7f7 | 312 | uint8_t CLibCEC::MuteAudio(bool bSendRelease /* = true */) |
04e637f9 LOK |
313 | { |
314 | if (m_cec) | |
5c73f7f7 | 315 | return m_cec->MuteAudio(bSendRelease); |
04e637f9 LOK |
316 | return 0; |
317 | } | |
318 | ||
4bec9d79 | 319 | bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
a33794d8 LOK |
320 | { |
321 | if (m_cec) | |
4bec9d79 | 322 | return m_cec->TransmitKeypress(iDestination, key, bWait); |
a33794d8 LOK |
323 | return false; |
324 | } | |
325 | ||
4bec9d79 | 326 | bool CLibCEC::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = true */) |
a33794d8 LOK |
327 | { |
328 | if (m_cec) | |
4bec9d79 | 329 | return m_cec->TransmitKeyRelease(iDestination, bWait); |
a33794d8 LOK |
330 | return false; |
331 | } | |
332 | ||
f71a1df9 | 333 | cec_osd_name CLibCEC::GetDeviceOSDName(cec_logical_address iAddress) |
ed21be2a LOK |
334 | { |
335 | cec_osd_name retVal; | |
336 | retVal.device = iAddress; | |
337 | retVal.name[0] = 0; | |
338 | ||
339 | if (m_cec) | |
340 | retVal = m_cec->GetDeviceOSDName(iAddress); | |
341 | ||
342 | return retVal; | |
343 | } | |
344 | ||
32403cc3 | 345 | void CLibCEC::AddLog(const cec_log_level level, const char *strFormat, ...) |
2abe74eb | 346 | { |
5477a250 | 347 | CStdString strLog; |
fa4798bd | 348 | |
5477a250 LOK |
349 | va_list argList; |
350 | va_start(argList, strFormat); | |
351 | strLog.FormatV(strFormat, argList); | |
352 | va_end(argList); | |
353 | ||
354 | CLibCEC *instance = CLibCEC::GetInstance(); | |
a2198e5e LOK |
355 | if (!instance) |
356 | return; | |
5477a250 LOK |
357 | CLockObject lock(instance->m_mutex); |
358 | ||
359 | cec_log_message message; | |
360 | message.level = level; | |
361 | message.time = GetTimeMs() - instance->m_iStartTime; | |
362 | snprintf(message.message, sizeof(message.message), "%s", strLog.c_str()); | |
363 | ||
364 | if (instance->m_callbacks) | |
365 | instance->m_callbacks->CBCecLogMessage(instance->m_cbParam, message); | |
366 | else | |
367 | instance->m_logBuffer.Push(message); | |
2abe74eb LOK |
368 | } |
369 | ||
32403cc3 | 370 | void CLibCEC::AddKey(const cec_keypress &key) |
95ba7a09 | 371 | { |
02e7043e | 372 | CLibCEC *instance = CLibCEC::GetInstance(); |
a2198e5e LOK |
373 | if (!instance) |
374 | return; | |
02e7043e LOK |
375 | CLockObject lock(instance->m_mutex); |
376 | ||
377 | AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode); | |
378 | ||
379 | if (instance->m_callbacks) | |
380 | instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key); | |
fa4798bd | 381 | else |
02e7043e LOK |
382 | instance->m_keyBuffer.Push(key); |
383 | ||
384 | instance->m_iCurrentButton = key.duration > 0 ? CEC_USER_CONTROL_CODE_UNKNOWN : key.keycode; | |
385 | instance->m_buttontime = key.duration > 0 ? 0 : GetTimeMs(); | |
386 | } | |
387 | ||
32403cc3 LOK |
388 | void CLibCEC::ConfigurationChanged(const libcec_configuration &config) |
389 | { | |
390 | CLibCEC *instance = CLibCEC::GetInstance(); | |
391 | CLockObject lock(instance->m_mutex); | |
392 | ||
393 | if (instance->m_callbacks && | |
394 | config.clientVersion >= CEC_CLIENT_VERSION_1_5_0 && | |
468d786e LOK |
395 | instance->m_callbacks->CBCecConfigurationChanged != NULL && |
396 | instance->m_cec->IsInitialised()) | |
32403cc3 LOK |
397 | instance->m_callbacks->CBCecConfigurationChanged(instance->m_cbParam, config); |
398 | } | |
399 | ||
02e7043e LOK |
400 | void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode) |
401 | { | |
402 | /* push keypress to the keybuffer with 0 duration. | |
403 | push another press to the keybuffer with the duration set when the button is released */ | |
404 | cec_keypress key; | |
405 | key.duration = 0; | |
406 | key.keycode = iButtonCode; | |
407 | ||
408 | AddKey(key); | |
95ba7a09 LOK |
409 | } |
410 | ||
2abe74eb LOK |
411 | void CLibCEC::AddKey(void) |
412 | { | |
02e7043e | 413 | CLibCEC *instance = CLibCEC::GetInstance(); |
a2198e5e LOK |
414 | if (!instance) |
415 | return; | |
02e7043e LOK |
416 | CLockObject lock(instance->m_mutex); |
417 | ||
418 | if (instance->m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN) | |
2abe74eb LOK |
419 | { |
420 | cec_keypress key; | |
25701fa6 | 421 | |
02e7043e LOK |
422 | key.duration = (unsigned int) (GetTimeMs() - instance->m_buttontime); |
423 | key.keycode = instance->m_iCurrentButton; | |
424 | AddLog(CEC_LOG_DEBUG, "key released: %1x", key.keycode); | |
fa4798bd | 425 | |
02e7043e LOK |
426 | if (instance->m_callbacks) |
427 | instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key); | |
fa4798bd | 428 | else |
02e7043e LOK |
429 | instance->m_keyBuffer.Push(key); |
430 | instance->m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN; | |
2abe74eb | 431 | } |
02e7043e | 432 | instance->m_buttontime = 0; |
2abe74eb LOK |
433 | } |
434 | ||
e9de9629 | 435 | void CLibCEC::AddCommand(const cec_command &command) |
2abe74eb | 436 | { |
02e7043e | 437 | CLibCEC *instance = CLibCEC::GetInstance(); |
a2198e5e LOK |
438 | if (!instance) |
439 | return; | |
02e7043e LOK |
440 | CLockObject lock(instance->m_mutex); |
441 | ||
442 | AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", instance->m_cec->ToString(command.initiator), command.initiator, instance->m_cec->ToString(command.destination), command.destination, instance->m_cec->ToString(command.opcode), command.opcode); | |
443 | ||
444 | if (instance->m_callbacks) | |
445 | instance->m_callbacks->CBCecCommand(instance->m_cbParam, command); | |
446 | else if (!instance->m_commandBuffer.Push(command)) | |
2abe74eb | 447 | AddLog(CEC_LOG_WARNING, "command buffer is full"); |
2abe74eb LOK |
448 | } |
449 | ||
450 | void CLibCEC::CheckKeypressTimeout(void) | |
451 | { | |
452 | if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN && GetTimeMs() - m_buttontime > CEC_BUTTON_TIMEOUT) | |
453 | { | |
454 | AddKey(); | |
455 | m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN; | |
456 | } | |
457 | } | |
458 | ||
f42d3e0f LOK |
459 | bool CLibCEC::SetStreamPath(cec_logical_address iAddress) |
460 | { | |
461 | uint16_t iPhysicalAddress = GetDevicePhysicalAddress(iAddress); | |
462 | if (iPhysicalAddress != 0xFFFF) | |
463 | return SetStreamPath(iPhysicalAddress); | |
464 | return false; | |
465 | } | |
466 | ||
467 | bool CLibCEC::SetStreamPath(uint16_t iPhysicalAddress) | |
468 | { | |
469 | return m_cec->SetStreamPath(iPhysicalAddress); | |
470 | } | |
471 | ||
80b72250 LOK |
472 | cec_logical_addresses CLibCEC::GetLogicalAddresses(void) |
473 | { | |
474 | cec_logical_addresses addr = m_cec->GetLogicalAddresses(); | |
475 | return addr; | |
476 | } | |
477 | ||
5477a250 LOK |
478 | static CLibCEC *g_libCEC_instance(NULL); |
479 | CLibCEC *CLibCEC::GetInstance(void) | |
480 | { | |
481 | return g_libCEC_instance; | |
482 | } | |
483 | ||
484 | void CLibCEC::SetInstance(CLibCEC *instance) | |
485 | { | |
486 | if (g_libCEC_instance) | |
487 | delete g_libCEC_instance; | |
488 | g_libCEC_instance = instance; | |
489 | } | |
490 | ||
81b78e4a | 491 | void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t UNUSED(iPhysicalAddress) /* = 0 */) |
f8513317 | 492 | { |
5477a250 LOK |
493 | CLibCEC *lib = new CLibCEC(strDeviceName, types); |
494 | CLibCEC::SetInstance(lib); | |
495 | return static_cast< void* > (lib); | |
f8513317 LOK |
496 | } |
497 | ||
3efda01a | 498 | void * CECInitialise(libcec_configuration *configuration) |
caca2d81 LOK |
499 | { |
500 | CLibCEC *lib = new CLibCEC(configuration); | |
501 | CLibCEC::SetInstance(lib); | |
502 | return static_cast< void* > (lib); | |
503 | } | |
504 | ||
a2198e5e LOK |
505 | bool CECStartBootloader(void) |
506 | { | |
a2198e5e LOK |
507 | bool bReturn(false); |
508 | cec_adapter deviceList[1]; | |
509 | if (CUSBCECAdapterDetection::FindAdapters(deviceList, 1) > 0) | |
510 | { | |
08d80226 LOK |
511 | CUSBCECAdapterCommunication comm(NULL, deviceList[0].comm); |
512 | CTimeout timeout(10000); | |
08d80226 LOK |
513 | while (timeout.TimeLeft() > 0 && (bReturn = comm.Open(NULL, (timeout.TimeLeft() / CEC_CONNECT_TRIES)), true) == false) |
514 | { | |
515 | comm.Close(); | |
b76619e8 | 516 | CEvent::Sleep(500); |
08d80226 LOK |
517 | } |
518 | if (comm.IsOpen()) | |
519 | bReturn = comm.StartBootloader(); | |
a2198e5e | 520 | } |
08d80226 | 521 | |
a2198e5e LOK |
522 | return bReturn; |
523 | } | |
524 | ||
5477a250 | 525 | void CECDestroy(CEC::ICECAdapter *UNUSED(instance)) |
25701fa6 | 526 | { |
5477a250 | 527 | CLibCEC::SetInstance(NULL); |
25701fa6 | 528 | } |
03ae897d LOK |
529 | |
530 | const char *CLibCEC::ToString(const cec_menu_state state) | |
531 | { | |
532 | return m_cec->ToString(state); | |
533 | } | |
534 | ||
535 | const char *CLibCEC::ToString(const cec_version version) | |
536 | { | |
537 | return m_cec->ToString(version); | |
538 | } | |
539 | ||
540 | const char *CLibCEC::ToString(const cec_power_status status) | |
541 | { | |
542 | return m_cec->ToString(status); | |
543 | } | |
544 | ||
545 | const char *CLibCEC::ToString(const cec_logical_address address) | |
546 | { | |
547 | return m_cec->ToString(address); | |
548 | } | |
549 | ||
550 | const char *CLibCEC::ToString(const cec_deck_control_mode mode) | |
551 | { | |
552 | return m_cec->ToString(mode); | |
553 | } | |
554 | ||
555 | const char *CLibCEC::ToString(const cec_deck_info status) | |
556 | { | |
557 | return m_cec->ToString(status); | |
558 | } | |
559 | ||
560 | const char *CLibCEC::ToString(const cec_opcode opcode) | |
561 | { | |
562 | return m_cec->ToString(opcode); | |
563 | } | |
564 | ||
565 | const char *CLibCEC::ToString(const cec_system_audio_status mode) | |
566 | { | |
567 | return m_cec->ToString(mode); | |
568 | } | |
569 | ||
570 | const char *CLibCEC::ToString(const cec_audio_status status) | |
571 | { | |
572 | return m_cec->ToString(status); | |
573 | } | |
574 | ||
575 | const char *CLibCEC::ToString(const cec_vendor_id vendor) | |
576 | { | |
577 | return m_cec->ToString(vendor); | |
578 | } | |
caca2d81 LOK |
579 | |
580 | const char *CLibCEC::ToString(const cec_client_version version) | |
581 | { | |
582 | return m_cec->ToString(version); | |
583 | } | |
d40928b5 | 584 | |
3efda01a LOK |
585 | const char *CLibCEC::ToString(const cec_server_version version) |
586 | { | |
587 | return m_cec->ToString(version); | |
588 | } | |
589 | ||
d40928b5 LOK |
590 | bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration) |
591 | { | |
d465a51a | 592 | return m_cec->IsInitialised() && m_cec->GetCurrentConfiguration(configuration); |
224ea877 LOK |
593 | } |
594 | ||
30b4aac0 LOK |
595 | bool CLibCEC::SetConfiguration(const libcec_configuration *configuration) |
596 | { | |
597 | return m_cec->SetConfiguration(configuration); | |
598 | } | |
599 | ||
224ea877 LOK |
600 | bool CLibCEC::CanPersistConfiguration(void) |
601 | { | |
602 | return m_cec->CanPersistConfiguration(); | |
603 | } | |
604 | ||
605 | bool CLibCEC::PersistConfiguration(libcec_configuration *configuration) | |
606 | { | |
607 | return m_cec->PersistConfiguration(configuration); | |
608 | } | |
3efda01a LOK |
609 | |
610 | void CLibCEC::RescanActiveDevices(void) | |
611 | { | |
612 | return m_cec->RescanActiveDevices(); | |
613 | } | |
c9549d35 LOK |
614 | |
615 | bool CLibCEC::IsLibCECActiveSource(void) | |
616 | { | |
a2f4c09c LOK |
617 | bool bReturn(false); |
618 | if (m_cec) | |
619 | { | |
620 | cec_logical_address activeSource = m_cec->GetActiveSource(); | |
621 | if (activeSource != CECDEVICE_UNKNOWN) | |
622 | bReturn = m_cec->m_busDevices[activeSource]->GetStatus(false) == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC; | |
623 | } | |
624 | return bReturn; | |
c9549d35 | 625 | } |
9878069e LOK |
626 | |
627 | cec_device_type CLibCEC::GetType(cec_logical_address address) | |
628 | { | |
629 | switch (address) | |
630 | { | |
631 | case CECDEVICE_AUDIOSYSTEM: | |
632 | return CEC_DEVICE_TYPE_AUDIO_SYSTEM; | |
633 | case CECDEVICE_PLAYBACKDEVICE1: | |
634 | case CECDEVICE_PLAYBACKDEVICE2: | |
635 | case CECDEVICE_PLAYBACKDEVICE3: | |
636 | return CEC_DEVICE_TYPE_PLAYBACK_DEVICE; | |
637 | case CECDEVICE_RECORDINGDEVICE1: | |
638 | case CECDEVICE_RECORDINGDEVICE2: | |
639 | case CECDEVICE_RECORDINGDEVICE3: | |
640 | return CEC_DEVICE_TYPE_RECORDING_DEVICE; | |
641 | case CECDEVICE_TUNER1: | |
642 | case CECDEVICE_TUNER2: | |
643 | case CECDEVICE_TUNER3: | |
644 | case CECDEVICE_TUNER4: | |
645 | return CEC_DEVICE_TYPE_TUNER; | |
646 | case CECDEVICE_TV: | |
647 | return CEC_DEVICE_TYPE_TV; | |
648 | default: | |
649 | return CEC_DEVICE_TYPE_RESERVED; | |
650 | } | |
651 | } | |
209b7a5c LOK |
652 | |
653 | uint16_t CLibCEC::GetMaskForType(cec_logical_address address) | |
654 | { | |
655 | return GetMaskForType(GetType(address)); | |
656 | } | |
657 | ||
658 | uint16_t CLibCEC::GetMaskForType(cec_device_type type) | |
659 | { | |
660 | switch (type) | |
661 | { | |
662 | case CEC_DEVICE_TYPE_AUDIO_SYSTEM: | |
663 | { | |
664 | cec_logical_addresses addr; | |
665 | addr.Clear(); | |
666 | addr.Set(CECDEVICE_AUDIOSYSTEM); | |
667 | return addr.AckMask(); | |
668 | } | |
669 | case CEC_DEVICE_TYPE_PLAYBACK_DEVICE: | |
670 | { | |
671 | cec_logical_addresses addr; | |
672 | addr.Clear(); | |
673 | addr.Set(CECDEVICE_PLAYBACKDEVICE1); | |
674 | addr.Set(CECDEVICE_PLAYBACKDEVICE2); | |
675 | addr.Set(CECDEVICE_PLAYBACKDEVICE3); | |
676 | return addr.AckMask(); | |
677 | } | |
678 | case CEC_DEVICE_TYPE_RECORDING_DEVICE: | |
679 | { | |
680 | cec_logical_addresses addr; | |
681 | addr.Clear(); | |
682 | addr.Set(CECDEVICE_RECORDINGDEVICE1); | |
683 | addr.Set(CECDEVICE_RECORDINGDEVICE2); | |
684 | addr.Set(CECDEVICE_RECORDINGDEVICE3); | |
685 | return addr.AckMask(); | |
686 | } | |
687 | case CEC_DEVICE_TYPE_TUNER: | |
688 | { | |
689 | cec_logical_addresses addr; | |
690 | addr.Clear(); | |
691 | addr.Set(CECDEVICE_TUNER1); | |
692 | addr.Set(CECDEVICE_TUNER2); | |
693 | addr.Set(CECDEVICE_TUNER3); | |
694 | addr.Set(CECDEVICE_TUNER4); | |
695 | return addr.AckMask(); | |
696 | } | |
697 | case CEC_DEVICE_TYPE_TV: | |
698 | { | |
699 | cec_logical_addresses addr; | |
700 | addr.Clear(); | |
701 | addr.Set(CECDEVICE_TV); | |
702 | return addr.AckMask(); | |
703 | } | |
704 | default: | |
705 | return 0; | |
706 | } | |
707 | } | |
f80cd208 LOK |
708 | |
709 | bool CLibCEC::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = 10000 */) | |
710 | { | |
711 | if (m_cec->IsRunning()) | |
712 | return false; | |
713 | ||
714 | return m_cec->GetDeviceInformation(strPort, config, iTimeoutMs); | |
715 | } |