diff --git a/mythtv/configure b/mythtv/configure
index 7ab8aa7..7d5e39d 100755
a
|
b
|
using namespace std; |
5178 | 5178 | using namespace CEC; |
5179 | 5179 | #include <libcec/cecloader.h> |
5180 | 5180 | int main(void) { |
| 5181 | if (CEC_LIB_VERSION_MAJOR == 2) |
| 5182 | return 1; |
5181 | 5183 | if (CEC_LIB_VERSION_MAJOR < 1 || (CEC_LIB_VERSION_MAJOR == 1 && |
5182 | 5184 | CEC_LIB_VERSION_MINOR < 5)) |
5183 | 5185 | return 0; |
5184 | | return (long) LibCecInit; |
| 5186 | return 1; |
5185 | 5187 | } |
5186 | 5188 | EOF |
5187 | 5189 | fi |
diff --git a/mythtv/libs/libmythui/cecadapter.cpp b/mythtv/libs/libmythui/cecadapter.cpp
index edad8f6..5987d5d 100644
a
|
b
|
|
14 | 14 | #include "cecadapter.h" |
15 | 15 | #include <vector> |
16 | 16 | |
17 | | #define MIN_LIBCEC_VERSION 1 |
| 17 | #ifdef CEC_CLIENT_VERSION_CURRENT // 2.0.3 and up |
| 18 | #define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_CURRENT; |
| 19 | #else |
| 20 | #ifdef LIBCEC_VERSION_CURRENT // 1.6.2 and up |
| 21 | #define CEC_CONFIG_VERSION LIBCEC_VERSION_CURRENT; |
| 22 | #else |
| 23 | #define CEC_CONFIG_VERSION 0; |
| 24 | #endif |
| 25 | #endif |
| 26 | |
18 | 27 | #define MAX_CEC_DEVICES 10 |
19 | 28 | #define LOC QString("CECAdapter: ") |
| 29 | #define OSDNAME "MythTv" |
| 30 | |
| 31 | // TODO remove if we have a ui. |
| 32 | // hard code logical and physical address |
| 33 | #define CEC_DEFAULT_DEVICE_TYPE CEC_DEVICE_TYPE_RECORDING_DEVICE |
| 34 | #undef CEC_DEFAULT_HDMI_PORT |
| 35 | #define CEC_DEFAULT_HDMI_PORT 2 |
| 36 | #undef CEC_DEFAULT_BASE_DEVICE |
| 37 | #define CEC_DEFAULT_BASE_DEVICE CECDEVICE_AUDIOSYSTEM |
| 38 | #define CEC_DEFAULT_PHYSICALADDRESS (quint16)0x2200 |
20 | 39 | |
21 | 40 | #include <libcec/cec.h> |
22 | 41 | #include <iostream> |
… |
… |
using namespace std; |
25 | 44 | #include <libcec/cecloader.h> |
26 | 45 | |
27 | 46 | QMutex* CECAdapter::gLock = new QMutex(QMutex::Recursive); |
| 47 | bool resetSafe = false; |
28 | 48 | |
29 | 49 | class CECAdapterPriv |
30 | 50 | { |
31 | 51 | public: |
32 | 52 | CECAdapterPriv() |
33 | | : adapter(NULL), defaultDevice("auto"), defaultHDMIPort(1), |
34 | | defaultDeviceID(CECDEVICE_PLAYBACKDEVICE1), timer(NULL), valid(false), |
| 53 | : adapter(NULL), defaultDevice("auto"), defaultHDMIPort(CEC_DEFAULT_HDMI_PORT), |
| 54 | defaultDeviceID(CEC_DEFAULT_DEVICE_TYPE), timer(NULL), valid(false), |
35 | 55 | powerOffTV(false), powerOffTVAllowed(false), powerOffTVOnExit(false), |
36 | 56 | powerOnTV(false), powerOnTVAllowed(false), powerOnTVOnStart(false), |
37 | 57 | switchInput(false), switchInputAllowed(true) |
38 | 58 | { |
| 59 | callbacks.Clear(); |
| 60 | callbacks.CBCecLogMessage = LogMessages; |
| 61 | callbacks.CBCecKeyPress = HandleKeyPresses; |
| 62 | callbacks.CBCecCommand = HandleCommands; |
| 63 | callbacks.CBCecConfigurationChanged = HandleConfigurationChanged; |
| 64 | callbacks.CBCecAlert = HandleAlerts; |
| 65 | callbacks.CBCecMenuStateChanged = HandleMenuStateChanged; |
| 66 | callbacks.CBCecSourceActivated = HandleSourceActivated; |
39 | 67 | } |
40 | 68 | |
41 | 69 | static QString addressToString(enum cec_logical_address addr, bool source) |
… |
… |
class CECAdapterPriv |
69 | 97 | static QStringList GetDeviceList(void) |
70 | 98 | { |
71 | 99 | QStringList results; |
72 | | cec_device_type_list list; |
73 | | list.Clear(); |
74 | | list.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
75 | | ICECAdapter *adapter = LibCecInit("MythTV", list); |
| 100 | libcec_configuration configuration; |
| 101 | configuration.Clear(); |
| 102 | ICECAdapter *adapter = LibCecInitialise(&configuration); |
76 | 103 | if (!adapter) |
77 | 104 | return results; |
78 | 105 | cec_adapter *devices = new cec_adapter[MAX_CEC_DEVICES]; |
79 | 106 | uint8_t num_devices = adapter->FindAdapters(devices, MAX_CEC_DEVICES, NULL); |
| 107 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("GetDeviceList() found %1 devices(s).") |
| 108 | .arg(num_devices)); |
80 | 109 | if (num_devices < 1) |
81 | 110 | return results; |
82 | 111 | for (uint8_t i = 0; i < num_devices; i++) |
… |
… |
class CECAdapterPriv |
89 | 118 | { |
90 | 119 | // get settings |
91 | 120 | // N.B. these do not currently work as there is no UI |
| 121 | |
| 122 | // There is no way current CEC adapters can find their physical address |
| 123 | // on their own. The are only connected to the CEC pin of the HDMI connector. |
| 124 | // To construct a valid physical address libCEC needs: |
| 125 | // - the HDMI port (number) Myth is connected to |
| 126 | // - the HDMI device (TV, Receiver) Myth is connected to (the logical address) |
| 127 | |
| 128 | //The CEC adapter we want to connect to |
92 | 129 | defaultDevice = gCoreContext->GetSetting(LIBCEC_DEVICE, "auto").trimmed(); |
| 130 | // The number of the HDMI port Myth is connected to |
93 | 131 | QString hdmi_port = gCoreContext->GetSetting(LIBCEC_PORT, "auto"); |
| 132 | // The logical address of the HDMI device Myth is connected to |
| 133 | QString base_dev = gCoreContext->GetSetting(LIBCEC_BASE, "auto"); |
| 134 | // Device type we want Myth to use |
94 | 135 | QString device_id = gCoreContext->GetSetting(LIBCEC_DEVICEID, "auto"); |
95 | 136 | powerOffTVAllowed = (bool)gCoreContext->GetNumSetting(POWEROFFTV_ALLOWED, 1); |
96 | 137 | powerOffTVOnExit = (bool)gCoreContext->GetNumSetting(POWEROFFTV_ONEXIT, 1); |
97 | 138 | powerOnTVAllowed = (bool)gCoreContext->GetNumSetting(POWERONTV_ALLOWED, 1); |
98 | 139 | powerOnTVOnStart = (bool)gCoreContext->GetNumSetting(POWERONTV_ONSTART, 1); |
99 | 140 | |
100 | | defaultHDMIPort = 1; |
101 | 141 | if ("auto" != hdmi_port) |
102 | 142 | { |
103 | 143 | defaultHDMIPort = hdmi_port.toInt(); |
104 | | if (defaultHDMIPort < 1 || defaultHDMIPort > 3) |
105 | | defaultHDMIPort = 1; |
| 144 | if (defaultHDMIPort < CEC_MIN_HDMI_PORTNUMBER || defaultHDMIPort > CEC_MAX_HDMI_PORTNUMBER) |
| 145 | defaultHDMIPort = CEC_DEFAULT_HDMI_PORT; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | defaultHDMIPort = CEC_DEFAULT_HDMI_PORT; |
106 | 150 | } |
107 | | defaultHDMIPort = defaultHDMIPort << 12; |
108 | 151 | |
109 | | defaultDeviceID = CECDEVICE_PLAYBACKDEVICE1; |
110 | 152 | if ("auto" != device_id) |
111 | 153 | { |
112 | 154 | int id = device_id.toInt(); |
113 | | if (id < 1 || id > 3) |
114 | | id = 1; |
115 | | defaultDeviceID = (id == 1) ? CECDEVICE_PLAYBACKDEVICE1 : |
116 | | ((id == 2) ? CECDEVICE_PLAYBACKDEVICE2 : |
117 | | CECDEVICE_PLAYBACKDEVICE3); |
| 155 | switch (id) |
| 156 | { |
| 157 | case CEC_DEVICE_TYPE_TV: |
| 158 | case CEC_DEVICE_TYPE_RECORDING_DEVICE: |
| 159 | case CEC_DEVICE_TYPE_RESERVED: |
| 160 | case CEC_DEVICE_TYPE_TUNER: |
| 161 | case CEC_DEVICE_TYPE_PLAYBACK_DEVICE: |
| 162 | case CEC_DEVICE_TYPE_AUDIO_SYSTEM: |
| 163 | defaultDeviceID = (cec_device_type)id; |
| 164 | break; |
| 165 | default: |
| 166 | defaultDeviceID = CEC_DEFAULT_DEVICE_TYPE; |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | defaultDeviceID = CEC_DEFAULT_DEVICE_TYPE; |
118 | 173 | } |
119 | 174 | |
| 175 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("base_dev= %1.") |
| 176 | .arg(base_dev)); |
| 177 | if ("auto" != base_dev) |
| 178 | { |
| 179 | base_device = (cec_logical_address)base_dev.toInt(); |
| 180 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("base_device= %1.") |
| 181 | .arg(base_device)); |
| 182 | switch (base_device) |
| 183 | { |
| 184 | case CECDEVICE_TV: |
| 185 | case CECDEVICE_RECORDINGDEVICE1: |
| 186 | case CECDEVICE_RECORDINGDEVICE2: |
| 187 | case CECDEVICE_TUNER1: |
| 188 | case CECDEVICE_PLAYBACKDEVICE1: |
| 189 | case CECDEVICE_AUDIOSYSTEM: |
| 190 | case CECDEVICE_TUNER2: |
| 191 | case CECDEVICE_TUNER3: |
| 192 | case CECDEVICE_PLAYBACKDEVICE2: |
| 193 | case CECDEVICE_RECORDINGDEVICE3: |
| 194 | case CECDEVICE_TUNER4: |
| 195 | case CECDEVICE_PLAYBACKDEVICE3: |
| 196 | case CECDEVICE_FREEUSE: |
| 197 | break; |
| 198 | case CECDEVICE_UNKNOWN: |
| 199 | case CECDEVICE_RESERVED1: |
| 200 | case CECDEVICE_RESERVED2: |
| 201 | case CECDEVICE_BROADCAST: |
| 202 | default: |
| 203 | base_device = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | base_device = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE; |
| 210 | } |
| 211 | |
120 | 212 | // create adapter interface |
121 | | cec_device_type_list list; |
122 | | list.Clear(); |
123 | | list.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
124 | | adapter = LibCecInit("MythTV", list); |
| 213 | libcec_configuration configuration; |
| 214 | configuration.Clear(); |
| 215 | configuration.clientVersion = LIBCEC_VERSION_CURRENT; |
| 216 | snprintf(configuration.strDeviceName, 13, "MythTV"); |
| 217 | configuration.deviceTypes.Add(defaultDeviceID); |
| 218 | configuration.iPhysicalAddress = CEC_DEFAULT_PHYSICALADDRESS; |
| 219 | configuration.iHDMIPort = defaultHDMIPort; |
| 220 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("using HDMI port %1.") |
| 221 | .arg(defaultHDMIPort)); |
| 222 | configuration.baseDevice = base_device; |
| 223 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("using base device %1.") |
| 224 | .arg(configuration.baseDevice)); |
| 225 | configuration.callbacks = &callbacks; |
| 226 | ICECAdapter *adapter = LibCecInitialise(&configuration); |
125 | 227 | |
126 | 228 | if (!adapter) |
127 | 229 | { |
… |
… |
class CECAdapterPriv |
129 | 231 | return false; |
130 | 232 | } |
131 | 233 | |
132 | | if (adapter->GetMinLibVersion() > MIN_LIBCEC_VERSION) |
| 234 | if ((configuration.serverVersion >> 12) > CEC_MIN_LIB_VERSION) |
133 | 235 | { |
134 | 236 | LOG(VB_GENERAL, LOG_ERR, LOC + |
135 | 237 | QString("The installed libCEC supports version %1 and above. " |
136 | 238 | "This version of MythTV only supports version %2.") |
137 | | .arg(adapter->GetMinLibVersion()).arg(MIN_LIBCEC_VERSION)); |
| 239 | .arg(configuration.serverVersion).arg(CEC_MIN_LIB_VERSION)); |
138 | 240 | return false; |
139 | 241 | } |
140 | 242 | |
… |
… |
class CECAdapterPriv |
185 | 287 | // get the vendor ID (for non-standard implementations) |
186 | 288 | adapter->GetDeviceVendorId(CECDEVICE_TV); |
187 | 289 | |
188 | | // set the physical address |
189 | | adapter->SetPhysicalAddress(defaultHDMIPort); |
190 | | |
191 | | // set the logical address |
192 | | adapter->SetLogicalAddress(defaultDeviceID); |
193 | | |
194 | 290 | // switch input (if configured) |
195 | 291 | switchInput = true; |
196 | 292 | HandleActions(); |
… |
… |
class CECAdapterPriv |
210 | 306 | |
211 | 307 | // delete adapter |
212 | 308 | adapter->Close(); |
213 | | LogMessages(); |
214 | 309 | UnloadLibCec(adapter); |
215 | 310 | |
216 | 311 | LOG(VB_GENERAL, LOG_INFO, LOC + "Closing down CEC."); |
… |
… |
class CECAdapterPriv |
219 | 314 | adapter = NULL; |
220 | 315 | } |
221 | 316 | |
222 | | void LogMessages(void) |
| 317 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 318 | static int LogMessages(void *, const cec_log_message &message) |
| 319 | #else |
| 320 | static int LogMessages(void *, const cec_log_message message) |
| 321 | #endif |
223 | 322 | { |
224 | | if (!adapter || !valid) |
225 | | return; |
226 | | |
227 | | cec_log_message message; |
228 | | while (adapter->GetNextLogMessage(&message)) |
229 | | { |
230 | 323 | QString msg(message.message); |
231 | 324 | int lvl = LOG_UNKNOWN; |
232 | 325 | switch (message.level) |
… |
… |
class CECAdapterPriv |
237 | 330 | case CEC_LOG_DEBUG: lvl = LOG_DEBUG; break; |
238 | 331 | } |
239 | 332 | LOG(VB_GENERAL, lvl, LOC + QString("%1").arg(msg)); |
240 | | } |
| 333 | return 0; |
241 | 334 | } |
242 | 335 | |
243 | | void HandleCommands(void) |
| 336 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 337 | static int HandleCommands(void * /*cbParam*/, const cec_command &command) |
| 338 | #else |
| 339 | static int HandleCommands(void * /*cbParam*/, const cec_command command) |
| 340 | #endif |
244 | 341 | { |
245 | | if (!adapter || !valid) |
246 | | return; |
247 | | |
248 | | LogMessages(); |
249 | | |
250 | | cec_command command; |
251 | | while (adapter->GetNextCommand(&command)) |
252 | | { |
253 | 342 | LOG(VB_GENERAL, LOG_DEBUG, LOC + |
254 | 343 | QString("Command %1 from '%2' (%3) - destination '%4' (%5)") |
255 | 344 | .arg(command.opcode) |
… |
… |
class CECAdapterPriv |
260 | 349 | |
261 | 350 | switch (command.opcode) |
262 | 351 | { |
263 | | // TODO |
| 352 | // TODO handle CEC commands. |
264 | 353 | default: |
265 | 354 | break; |
266 | 355 | } |
267 | | } |
| 356 | return 0; |
| 357 | } |
268 | 358 | |
269 | | LogMessages(); |
| 359 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 360 | static int HandleConfigurationChanged(void * /*cbParam*/, const libcec_configuration &config) |
| 361 | #else |
| 362 | static int HandleConfigurationChanged(void * /*cbParam*/, const libcec_configuration config) |
| 363 | #endif |
| 364 | { |
| 365 | LOG(VB_GENERAL, LOG_INFO, LOC + "Adapter configuration changed."); |
| 366 | return 1; |
270 | 367 | } |
271 | 368 | |
272 | | void HandleKeyPresses(void) |
| 369 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 370 | static int HandleAlerts(void * /*cbParam*/, const libcec_alert type, const libcec_parameter & /*param*/) |
| 371 | #else |
| 372 | static int HandleAlerts(void * /*cbParam*/, const libcec_alert type, const libcec_parameter /*param*/) |
| 373 | #endif |
273 | 374 | { |
274 | | if (!adapter || !valid) |
275 | | return; |
| 375 | switch (type) // TODO Handle alerts. |
| 376 | { |
| 377 | case CEC_ALERT_CONNECTION_LOST: |
| 378 | LOG(VB_GENERAL, LOG_ERR, LOC + "Connection lost - TODO: need to handle this!"); |
| 379 | break; |
| 380 | default: |
| 381 | LOG(VB_GENERAL, LOG_ERR, LOC + "Received unknown alert."); |
| 382 | break; |
| 383 | } |
| 384 | return 0; |
| 385 | } |
276 | 386 | |
277 | | cec_keypress key; |
278 | | if (!adapter->GetNextKeypress(&key)) |
279 | | return; |
| 387 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 388 | static int HandleMenuStateChanged(void * /*cbParam*/, const cec_menu_state &state) |
| 389 | #else |
| 390 | static int HandleMenuStateChanged(void * /*cbParam*/, const cec_menu_state state) |
| 391 | #endif |
| 392 | { |
| 393 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("CEC menu state %1") |
| 394 | .arg(state == CEC_MENU_STATE_ACTIVATED ? "Activated" : "Deactivated")); |
| 395 | return 1; |
| 396 | } |
280 | 397 | |
| 398 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 399 | static void HandleSourceActivated(void * /*cbParam*/, const cec_logical_address &address, const &uint8_t activated) |
| 400 | #else |
| 401 | static void HandleSourceActivated(void * /*cbParam*/, const cec_logical_address address, const uint8_t activated) |
| 402 | #endif |
| 403 | { |
| 404 | LOG(VB_GENERAL, LOG_INFO, LOC + QString("Source %1 %2") |
| 405 | .arg(address).arg(activated ? "Activated" : "Deactivated")); |
| 406 | |
| 407 | if (activated && resetSafe) |
| 408 | GetMythUI()->ResetScreensaver(); |
| 409 | else |
| 410 | resetSafe = true; |
| 411 | } |
| 412 | |
| 413 | #if CEC_LIB_VERSION_MAJOR < 2 |
| 414 | static int HandleKeyPresses(void * /*cbParam*/, const cec_keypress &key) |
| 415 | #else |
| 416 | static int HandleKeyPresses(void * /*cbParam*/, const cec_keypress key) |
| 417 | #endif |
| 418 | { |
281 | 419 | // Ignore key down events and wait for the key 'up' |
282 | 420 | if (key.duration < 1) |
283 | | return; |
| 421 | return 0; |
284 | 422 | |
285 | 423 | QString code; |
286 | 424 | int action = 0; |
… |
… |
class CECAdapterPriv |
595 | 733 | .arg(code).arg(0 == action ? "(Not actioned)" : "")); |
596 | 734 | |
597 | 735 | if (0 == action) |
598 | | return; |
| 736 | return 0; |
599 | 737 | |
600 | 738 | GetMythUI()->ResetScreensaver(); |
601 | 739 | QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, action, Qt::NoModifier); |
602 | 740 | qApp->postEvent(GetMythMainWindow(), (QEvent*)ke); |
603 | | |
604 | | LogMessages(); |
| 741 | return 0; |
605 | 742 | } |
606 | 743 | |
607 | 744 | void HandleActions(void) |
… |
… |
class CECAdapterPriv |
629 | 766 | // HDMI input |
630 | 767 | if (switchInput && switchInputAllowed) |
631 | 768 | { |
632 | | if (adapter->SetActiveView()) |
| 769 | if (adapter->SetActiveSource()) |
633 | 770 | LOG(VB_GENERAL, LOG_INFO, LOC + "Asked TV to switch to this input."); |
634 | 771 | else |
635 | 772 | LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to switch to this input."); |
… |
… |
class CECAdapterPriv |
638 | 775 | powerOffTV = false; |
639 | 776 | powerOnTV = false; |
640 | 777 | switchInput = false; |
641 | | |
642 | | LogMessages(); |
643 | 778 | } |
644 | 779 | |
645 | 780 | ICECAdapter *adapter; |
| 781 | ICECCallbacks callbacks; |
646 | 782 | QString defaultDevice; |
647 | 783 | int defaultHDMIPort; |
648 | | cec_logical_address defaultDeviceID; |
| 784 | cec_device_type defaultDeviceID; |
| 785 | cec_logical_address base_device; |
649 | 786 | QTimer *timer; |
650 | 787 | bool valid; |
651 | 788 | bool powerOffTV; |
… |
… |
void CECAdapter::Action(const QString &action) |
728 | 865 | void CECAdapter::Process(void) |
729 | 866 | { |
730 | 867 | gLock->lock(); |
731 | | m_priv->HandleCommands(); |
732 | | m_priv->HandleKeyPresses(); |
733 | 868 | m_priv->HandleActions(); |
734 | 869 | gLock->unlock(); |
735 | 870 | } |
diff --git a/mythtv/libs/libmythui/cecadapter.h b/mythtv/libs/libmythui/cecadapter.h
index e9cf6d6..bb5eba8 100644
a
|
b
|
|
7 | 7 | #define LIBCEC_ENABLED QString("libCECEnabled") |
8 | 8 | #define LIBCEC_DEVICE QString("libCECDevice") |
9 | 9 | #define LIBCEC_PORT QString("libCECPort") |
| 10 | #define LIBCEC_BASE QString("libCECBase") |
10 | 11 | #define LIBCEC_DEVICEID QString("libCECDeviceID") |
11 | 12 | #define POWEROFFTV_ALLOWED QString("PowerOffTVAllowed") |
12 | 13 | #define POWEROFFTV_ONEXIT QString("PowerOffTVOnExit") |