Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
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 | ||
2abe74eb | 33 | #include "CECProcessor.h" |
abbca718 | 34 | |
2abe74eb | 35 | #include "AdapterCommunication.h" |
eafa9d46 | 36 | #include "devices/CECBusDevice.h" |
51b2a094 LOK |
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" | |
62f5527d | 42 | #include "implementations/CECCommandHandler.h" |
2abe74eb | 43 | #include "LibCEC.h" |
abbca718 | 44 | #include "util/StdString.h" |
b9187cc6 | 45 | #include "platform/timeutils.h" |
abbca718 LOK |
46 | |
47 | using namespace CEC; | |
48 | using namespace std; | |
49 | ||
2b4d8297 | 50 | CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : |
f8513317 | 51 | m_bStarted(false), |
16b1e052 | 52 | m_iHDMIPort(CEC_DEFAULT_HDMI_PORT), |
d2f1c157 | 53 | m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE), |
855a3a98 | 54 | m_lastInitiator(CECDEVICE_UNKNOWN), |
2abe74eb LOK |
55 | m_strDeviceName(strDeviceName), |
56 | m_communication(serComm), | |
8b7e5ff6 | 57 | m_controller(controller), |
7c63a480 LOK |
58 | m_bMonitor(false), |
59 | m_busScan(NULL) | |
abbca718 | 60 | { |
ab1469a0 LOK |
61 | m_logicalAddresses.Clear(); |
62 | m_logicalAddresses.Set(iLogicalAddress); | |
20b8870a | 63 | m_types.clear(); |
7871d66e | 64 | for (int iPtr = 0; iPtr <= 16; iPtr++) |
09c10b66 | 65 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0); |
abbca718 LOK |
66 | } |
67 | ||
f8513317 LOK |
68 | CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, const cec_device_type_list &types) : |
69 | m_bStarted(false), | |
16b1e052 | 70 | m_iHDMIPort(CEC_DEFAULT_HDMI_PORT), |
d2f1c157 | 71 | m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE), |
f8513317 LOK |
72 | m_strDeviceName(strDeviceName), |
73 | m_types(types), | |
74 | m_communication(serComm), | |
75 | m_controller(controller), | |
76 | m_bMonitor(false) | |
77 | { | |
ab1469a0 | 78 | m_logicalAddresses.Clear(); |
f8513317 | 79 | for (int iPtr = 0; iPtr < 16; iPtr++) |
51b2a094 LOK |
80 | { |
81 | switch(iPtr) | |
82 | { | |
83 | case CECDEVICE_AUDIOSYSTEM: | |
5d5a2dc2 | 84 | m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
85 | break; |
86 | case CECDEVICE_PLAYBACKDEVICE1: | |
87 | case CECDEVICE_PLAYBACKDEVICE2: | |
88 | case CECDEVICE_PLAYBACKDEVICE3: | |
5d5a2dc2 | 89 | m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
90 | break; |
91 | case CECDEVICE_RECORDINGDEVICE1: | |
92 | case CECDEVICE_RECORDINGDEVICE2: | |
93 | case CECDEVICE_RECORDINGDEVICE3: | |
5d5a2dc2 | 94 | m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
95 | break; |
96 | case CECDEVICE_TUNER1: | |
97 | case CECDEVICE_TUNER2: | |
98 | case CECDEVICE_TUNER3: | |
99 | case CECDEVICE_TUNER4: | |
5d5a2dc2 | 100 | m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
101 | break; |
102 | case CECDEVICE_TV: | |
103 | m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0); | |
104 | break; | |
105 | default: | |
5d5a2dc2 | 106 | m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF); |
51b2a094 LOK |
107 | break; |
108 | } | |
109 | } | |
f8513317 LOK |
110 | } |
111 | ||
2abe74eb | 112 | CCECProcessor::~CCECProcessor(void) |
abbca718 | 113 | { |
7c63a480 LOK |
114 | if (m_busScan) |
115 | { | |
116 | m_busScan->StopThread(); | |
117 | delete m_busScan; | |
118 | } | |
119 | ||
8b0ee2cc | 120 | m_startCondition.Broadcast(); |
2abe74eb | 121 | StopThread(); |
7c63a480 | 122 | |
2abe74eb LOK |
123 | m_communication = NULL; |
124 | m_controller = NULL; | |
d1998c7b LOK |
125 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
126 | delete m_busDevices[iPtr]; | |
abbca718 LOK |
127 | } |
128 | ||
2abe74eb | 129 | bool CCECProcessor::Start(void) |
abbca718 | 130 | { |
8b0ee2cc | 131 | CLockObject lock(&m_mutex); |
2abe74eb | 132 | if (!m_communication || !m_communication->IsOpen()) |
13fd6a66 LOK |
133 | { |
134 | m_controller->AddLog(CEC_LOG_ERROR, "connection is closed"); | |
a8f0bd18 | 135 | return false; |
13fd6a66 | 136 | } |
abbca718 | 137 | |
60fa4578 | 138 | if (CreateThread()) |
8b0ee2cc | 139 | { |
f8513317 | 140 | if (!m_startCondition.Wait(&m_mutex) || !m_bStarted) |
8b0ee2cc LOK |
141 | { |
142 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); | |
143 | return false; | |
144 | } | |
9fd73dd4 LOK |
145 | |
146 | lock.Leave(); | |
147 | if (SetAckMask(m_logicalAddresses.AckMask()) && | |
d2f1c157 | 148 | SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true)) |
9fd73dd4 | 149 | { |
7c63a480 LOK |
150 | m_busScan = new CCECBusScan(this); |
151 | m_busScan->CreateThread(true); | |
9fd73dd4 LOK |
152 | return true; |
153 | } | |
8b0ee2cc | 154 | } |
a8f0bd18 | 155 | else |
2abe74eb | 156 | m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); |
abbca718 | 157 | |
a8f0bd18 | 158 | return false; |
abbca718 LOK |
159 | } |
160 | ||
b58d9277 | 161 | bool CCECProcessor::TryLogicalAddress(cec_logical_address address) |
f8513317 | 162 | { |
93fff5c1 | 163 | if (m_busDevices[address]->TryLogicalAddress()) |
f8513317 | 164 | { |
8747dd4f | 165 | /* only set our OSD name and active source for the primary device */ |
ab1469a0 | 166 | if (m_logicalAddresses.IsEmpty()) |
8747dd4f | 167 | { |
787a3cb8 | 168 | m_busDevices[address]->m_strDeviceName = m_strDeviceName; |
8747dd4f LOK |
169 | m_busDevices[address]->m_bActiveSource = true; |
170 | } | |
ab1469a0 | 171 | m_logicalAddresses.Set(address); |
f8513317 LOK |
172 | return true; |
173 | } | |
174 | ||
f8513317 LOK |
175 | return false; |
176 | } | |
177 | ||
b58d9277 | 178 | bool CCECProcessor::FindLogicalAddressRecordingDevice(void) |
f8513317 LOK |
179 | { |
180 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'"); | |
b58d9277 LOK |
181 | return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) || |
182 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) || | |
183 | TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3); | |
f8513317 LOK |
184 | } |
185 | ||
b58d9277 | 186 | bool CCECProcessor::FindLogicalAddressTuner(void) |
f8513317 LOK |
187 | { |
188 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'"); | |
b58d9277 LOK |
189 | return TryLogicalAddress(CECDEVICE_TUNER1) || |
190 | TryLogicalAddress(CECDEVICE_TUNER2) || | |
191 | TryLogicalAddress(CECDEVICE_TUNER3) || | |
192 | TryLogicalAddress(CECDEVICE_TUNER4); | |
f8513317 LOK |
193 | } |
194 | ||
b58d9277 | 195 | bool CCECProcessor::FindLogicalAddressPlaybackDevice(void) |
f8513317 LOK |
196 | { |
197 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'"); | |
b58d9277 LOK |
198 | return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) || |
199 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) || | |
200 | TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3); | |
f8513317 LOK |
201 | } |
202 | ||
b58d9277 | 203 | bool CCECProcessor::FindLogicalAddressAudioSystem(void) |
f8513317 LOK |
204 | { |
205 | AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'"); | |
b58d9277 | 206 | return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM); |
f8513317 LOK |
207 | } |
208 | ||
209 | bool CCECProcessor::FindLogicalAddresses(void) | |
210 | { | |
211 | bool bReturn(true); | |
ab1469a0 | 212 | m_logicalAddresses.Clear(); |
f8513317 LOK |
213 | CStdString strLog; |
214 | ||
215 | for (unsigned int iPtr = 0; iPtr < 5; iPtr++) | |
216 | { | |
217 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED) | |
218 | continue; | |
219 | ||
220 | strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]); | |
221 | AddLog(CEC_LOG_DEBUG, strLog); | |
222 | ||
223 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE) | |
b58d9277 | 224 | bReturn &= FindLogicalAddressRecordingDevice(); |
f8513317 | 225 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER) |
b58d9277 | 226 | bReturn &= FindLogicalAddressTuner(); |
f8513317 | 227 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE) |
b58d9277 | 228 | bReturn &= FindLogicalAddressPlaybackDevice(); |
f8513317 | 229 | if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM) |
b58d9277 | 230 | bReturn &= FindLogicalAddressAudioSystem(); |
f8513317 LOK |
231 | } |
232 | ||
233 | return bReturn; | |
234 | } | |
235 | ||
855a3a98 LOK |
236 | bool CCECProcessor::SetLineTimeout(uint8_t iTimeout) |
237 | { | |
238 | bool bReturn(false); | |
239 | CCECAdapterMessage *output = new CCECAdapterMessage; | |
240 | ||
241 | output->push_back(MSGSTART); | |
242 | output->push_escaped(MSGCODE_TRANSMIT_IDLETIME); | |
243 | output->push_escaped(iTimeout); | |
244 | output->push_back(MSGEND); | |
245 | ||
246 | if ((bReturn = Transmit(output)) == false) | |
247 | m_controller->AddLog(CEC_LOG_ERROR, "could not set the idletime"); | |
248 | delete output; | |
249 | return bReturn; | |
250 | } | |
251 | ||
2abe74eb | 252 | void *CCECProcessor::Process(void) |
f99bc831 | 253 | { |
8747dd4f | 254 | bool bParseFrame(false); |
e0407d3d LOK |
255 | cec_command command; |
256 | CCECAdapterMessage msg; | |
257 | ||
9fd73dd4 | 258 | if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses()) |
8b0ee2cc | 259 | { |
9fd73dd4 LOK |
260 | CLockObject lock(&m_mutex); |
261 | m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses"); | |
262 | m_startCondition.Signal(); | |
263 | return NULL; | |
264 | } | |
265 | else | |
266 | { | |
267 | CLockObject lock(&m_mutex); | |
268 | m_bStarted = true; | |
269 | m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); | |
270 | m_startCondition.Signal(); | |
8b0ee2cc | 271 | } |
abbca718 | 272 | |
13fd6a66 | 273 | while (!IsStopped()) |
abbca718 | 274 | { |
ab1469a0 | 275 | command.Clear(); |
76321de4 LOK |
276 | msg.clear(); |
277 | ||
60fa4578 LOK |
278 | { |
279 | CLockObject lock(&m_mutex); | |
8747dd4f LOK |
280 | if (m_commandBuffer.Pop(command)) |
281 | { | |
282 | bParseFrame = true; | |
283 | } | |
284 | else if (m_communication->IsOpen() && m_communication->Read(msg, 50)) | |
b5f34cf9 | 285 | { |
f2198ab5 | 286 | if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true) |
8747dd4f | 287 | command = m_currentframe; |
b5f34cf9 | 288 | } |
60fa4578 LOK |
289 | } |
290 | ||
13fd6a66 | 291 | if (bParseFrame) |
9dee1670 | 292 | ParseCommand(command); |
8747dd4f | 293 | bParseFrame = false; |
abbca718 | 294 | |
b5f34cf9 LOK |
295 | Sleep(5); |
296 | ||
13fd6a66 | 297 | m_controller->CheckKeypressTimeout(); |
abbca718 LOK |
298 | } |
299 | ||
60fa4578 | 300 | return NULL; |
abbca718 LOK |
301 | } |
302 | ||
18203d17 | 303 | bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */) |
abbca718 | 304 | { |
8ac9c610 LOK |
305 | bool bReturn(false); |
306 | ||
60fa4578 | 307 | if (!IsRunning()) |
8ac9c610 | 308 | return bReturn; |
f99bc831 | 309 | |
18203d17 | 310 | cec_logical_address addr = m_logicalAddresses.primary; |
04437dcf | 311 | |
18203d17 LOK |
312 | if (type != CEC_DEVICE_TYPE_RESERVED) |
313 | { | |
f2198ab5 | 314 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
18203d17 LOK |
315 | { |
316 | if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type) | |
317 | { | |
318 | addr = (cec_logical_address) iPtr; | |
319 | break; | |
320 | } | |
321 | } | |
322 | } | |
323 | ||
16b1e052 | 324 | return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress(false)) && |
4a870dc8 | 325 | m_busDevices[addr]->TransmitActiveSource(); |
18203d17 LOK |
326 | } |
327 | ||
1a6669b8 LOK |
328 | bool CCECProcessor::SetActiveSource(cec_logical_address iAddress) |
329 | { | |
16b1e052 | 330 | return SetStreamPath(m_busDevices[iAddress]->GetPhysicalAddress(false)); |
1a6669b8 LOK |
331 | } |
332 | ||
18203d17 LOK |
333 | bool CCECProcessor::SetActiveView(void) |
334 | { | |
4a870dc8 | 335 | return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]); |
8ac9c610 LOK |
336 | } |
337 | ||
28fa6c97 | 338 | bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */) |
a9232a79 LOK |
339 | { |
340 | bool bReturn(false); | |
341 | ||
342 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
343 | if (device) | |
344 | { | |
345 | ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode); | |
28fa6c97 LOK |
346 | if (bSendUpdate) |
347 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
348 | bReturn = true; |
349 | } | |
350 | ||
351 | return bReturn; | |
352 | } | |
353 | ||
28fa6c97 | 354 | bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */) |
a9232a79 LOK |
355 | { |
356 | bool bReturn(false); | |
357 | ||
358 | CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); | |
359 | if (device) | |
360 | { | |
361 | ((CCECPlaybackDevice *) device)->SetDeckStatus(info); | |
28fa6c97 LOK |
362 | if (bSendUpdate) |
363 | ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV); | |
a9232a79 LOK |
364 | bReturn = true; |
365 | } | |
366 | ||
367 | return bReturn; | |
368 | } | |
369 | ||
d2f1c157 | 370 | bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */) |
16b1e052 LOK |
371 | { |
372 | bool bReturn(false); | |
373 | ||
374 | CStdString strLog; | |
d2f1c157 | 375 | strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice); |
16b1e052 LOK |
376 | AddLog(CEC_LOG_DEBUG, strLog); |
377 | ||
d2f1c157 | 378 | m_iBaseDevice = iBaseDevice; |
16b1e052 | 379 | m_iHDMIPort = iPort; |
9fd73dd4 | 380 | if (!m_bStarted && !bForce) |
16b1e052 LOK |
381 | return true; |
382 | ||
383 | uint16_t iPhysicalAddress(0); | |
d2f1c157 LOK |
384 | iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress(); |
385 | uint16_t iPos = 0; | |
386 | if (iPhysicalAddress == 0) | |
387 | iPos = 0x1000; | |
388 | else if (iPhysicalAddress % 0x1000 == 0) | |
389 | iPos = 0x100; | |
390 | else if (iPhysicalAddress % 0x100 == 0) | |
391 | iPos = 0x10; | |
392 | else if (iPhysicalAddress % 0x10 == 0) | |
393 | iPos = 0x1; | |
394 | ||
395 | while(!bReturn && iPos > 0) | |
16b1e052 | 396 | { |
d2f1c157 | 397 | iPhysicalAddress += (uint16_t)(iPort * iPos); |
16b1e052 LOK |
398 | strLog.Format("checking physical address %4x", iPhysicalAddress); |
399 | AddLog(CEC_LOG_DEBUG, strLog); | |
400 | if (CheckPhysicalAddress(iPhysicalAddress)) | |
401 | { | |
402 | strLog.Format("physical address %4x is in use", iPhysicalAddress); | |
403 | AddLog(CEC_LOG_DEBUG, strLog); | |
d2f1c157 | 404 | iPos = (iPos == 1) ? 0 : iPos / 0x10; |
16b1e052 LOK |
405 | } |
406 | else | |
407 | { | |
408 | SetPhysicalAddress(iPhysicalAddress); | |
409 | bReturn = true; | |
410 | } | |
411 | } | |
412 | ||
413 | return bReturn; | |
414 | } | |
415 | ||
416 | bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress) | |
417 | { | |
9fd73dd4 | 418 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
16b1e052 LOK |
419 | { |
420 | if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress) | |
421 | return true; | |
422 | } | |
423 | return false; | |
424 | } | |
425 | ||
8ac9c610 LOK |
426 | bool CCECProcessor::SetStreamPath(uint16_t iStreamPath) |
427 | { | |
04437dcf LOK |
428 | bool bReturn(false); |
429 | ||
8ac9c610 LOK |
430 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath); |
431 | if (device) | |
432 | { | |
7856411b | 433 | device->SetActiveDevice(); |
91bea174 | 434 | bReturn = true; |
8ac9c610 LOK |
435 | } |
436 | ||
04437dcf | 437 | return bReturn; |
abbca718 LOK |
438 | } |
439 | ||
ab27363d | 440 | bool CCECProcessor::TransmitInactiveSource(void) |
abbca718 | 441 | { |
60fa4578 | 442 | if (!IsRunning()) |
f99bc831 LOK |
443 | return false; |
444 | ||
ab1469a0 | 445 | if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) |
ab27363d | 446 | return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource(); |
cc60ab1c | 447 | return false; |
abbca718 LOK |
448 | } |
449 | ||
9dee1670 | 450 | void CCECProcessor::LogOutput(const cec_command &data) |
abbca718 | 451 | { |
1d3ca3de | 452 | CStdString strTx; |
57f45e6c LOK |
453 | strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination); |
454 | if (data.opcode_set) | |
455 | strTx.AppendFormat(":%02x", (uint8_t)data.opcode); | |
9dee1670 | 456 | |
06a1f7ce | 457 | for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++) |
1d3ca3de LOK |
458 | strTx.AppendFormat(":%02x", data.parameters[iPtr]); |
459 | m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str()); | |
9dee1670 | 460 | } |
2abe74eb | 461 | |
06bfd4d7 | 462 | bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress) |
abbca718 | 463 | { |
f8513317 | 464 | if (m_logicalAddresses.primary != iLogicalAddress) |
06775107 LOK |
465 | { |
466 | CStdString strLog; | |
f8513317 | 467 | strLog.Format("<< setting primary logical address to %1x", iLogicalAddress); |
06775107 | 468 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); |
f8513317 | 469 | m_logicalAddresses.primary = iLogicalAddress; |
ab1469a0 LOK |
470 | m_logicalAddresses.Set(iLogicalAddress); |
471 | return SetAckMask(m_logicalAddresses.AckMask()); | |
06775107 | 472 | } |
2abe74eb | 473 | |
06bfd4d7 | 474 | return true; |
abbca718 | 475 | } |
825ddb96 | 476 | |
28fa6c97 LOK |
477 | bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */) |
478 | { | |
479 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) | |
480 | { | |
481 | if (m_logicalAddresses[iPtr]) | |
482 | m_busDevices[iPtr]->SetMenuState(state); | |
483 | } | |
484 | ||
485 | if (bSendUpdate) | |
486 | m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV); | |
487 | ||
488 | return true; | |
489 | } | |
490 | ||
2492216a LOK |
491 | bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress) |
492 | { | |
16b1e052 | 493 | if (!m_logicalAddresses.IsEmpty()) |
cc60ab1c | 494 | { |
16b1e052 LOK |
495 | for (uint8_t iPtr = 0; iPtr < 15; iPtr++) |
496 | if (m_logicalAddresses[iPtr]) | |
497 | m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress); | |
8ac9c610 | 498 | return SetActiveView(); |
cc60ab1c LOK |
499 | } |
500 | return false; | |
1969b140 LOK |
501 | } |
502 | ||
8b7e5ff6 LOK |
503 | bool CCECProcessor::SwitchMonitoring(bool bEnable) |
504 | { | |
505 | CStdString strLog; | |
506 | strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling"); | |
507 | m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); | |
508 | ||
855a3a98 LOK |
509 | { |
510 | CLockObject lock(&m_mutex); | |
511 | m_bMonitor = bEnable; | |
512 | ||
513 | if (bEnable) | |
514 | { | |
515 | if (!m_busScan) | |
516 | { | |
517 | m_busScan = new CCECBusScan(this); | |
518 | m_busScan->CreateThread(true); | |
519 | } | |
520 | } | |
521 | else | |
522 | { | |
523 | if (m_busScan) | |
524 | { | |
525 | m_busScan->StopThread(); | |
526 | delete m_busScan; | |
527 | m_busScan = NULL; | |
528 | } | |
529 | } | |
530 | } | |
531 | ||
8b7e5ff6 | 532 | if (bEnable) |
06bfd4d7 | 533 | return SetAckMask(0); |
8b7e5ff6 | 534 | else |
ab1469a0 | 535 | return SetAckMask(m_logicalAddresses.AckMask()); |
8b7e5ff6 LOK |
536 | } |
537 | ||
57f45e6c LOK |
538 | bool CCECProcessor::PollDevice(cec_logical_address iAddress) |
539 | { | |
540 | if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress]) | |
95a73fa7 LOK |
541 | { |
542 | return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ? | |
543 | m_busDevices[iAddress]->TransmitPoll(iAddress) : | |
544 | m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress); | |
545 | } | |
57f45e6c LOK |
546 | return false; |
547 | } | |
548 | ||
9f332fe2 | 549 | uint8_t CCECProcessor::VolumeUp(bool bWait /* = true */) |
04e637f9 LOK |
550 | { |
551 | uint8_t status = 0; | |
552 | if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) | |
9f332fe2 | 553 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bWait); |
04e637f9 LOK |
554 | |
555 | return status; | |
556 | } | |
557 | ||
9f332fe2 | 558 | uint8_t CCECProcessor::VolumeDown(bool bWait /* = true */) |
04e637f9 LOK |
559 | { |
560 | uint8_t status = 0; | |
561 | if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) | |
9f332fe2 | 562 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bWait); |
04e637f9 LOK |
563 | |
564 | return status; | |
565 | } | |
566 | ||
9f332fe2 | 567 | uint8_t CCECProcessor::MuteAudio(bool bWait /* = true */) |
04e637f9 LOK |
568 | { |
569 | uint8_t status = 0; | |
570 | if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) | |
9f332fe2 | 571 | status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bWait); |
04e637f9 LOK |
572 | |
573 | return status; | |
574 | } | |
575 | ||
16b1e052 | 576 | CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const |
8ac9c610 | 577 | { |
16b1e052 | 578 | if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) |
b58d9277 | 579 | return m_busDevices[m_logicalAddresses.primary]; |
8ac9c610 | 580 | |
b58d9277 | 581 | CCECBusDevice *device = NULL; |
8ac9c610 LOK |
582 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) |
583 | { | |
16b1e052 | 584 | if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress) |
8ac9c610 LOK |
585 | { |
586 | device = m_busDevices[iPtr]; | |
587 | break; | |
588 | } | |
589 | } | |
590 | ||
591 | return device; | |
592 | } | |
593 | ||
a9232a79 LOK |
594 | CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const |
595 | { | |
596 | CCECBusDevice *device = NULL; | |
597 | ||
598 | for (unsigned int iPtr = 0; iPtr < 16; iPtr++) | |
599 | { | |
600 | if (m_busDevices[iPtr]->m_type == type) | |
601 | { | |
602 | device = m_busDevices[iPtr]; | |
603 | break; | |
604 | } | |
605 | } | |
606 | ||
607 | return device; | |
608 | } | |
609 | ||
6a1c0009 LOK |
610 | cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress) |
611 | { | |
612 | return m_busDevices[iAddress]->GetCecVersion(); | |
613 | } | |
614 | ||
ed21be2a LOK |
615 | cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress) |
616 | { | |
617 | CStdString strOSDName = m_busDevices[iAddress]->GetOSDName(); | |
618 | cec_osd_name retVal; | |
619 | ||
620 | snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str()); | |
621 | retVal.device = iAddress; | |
622 | ||
623 | return retVal; | |
624 | } | |
625 | ||
a3269a0a LOK |
626 | bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language) |
627 | { | |
cc60ab1c LOK |
628 | if (m_busDevices[iAddress]) |
629 | { | |
630 | *language = m_busDevices[iAddress]->GetMenuLanguage(); | |
5744fbba | 631 | return (strcmp(language->language, "???") != 0); |
cc60ab1c LOK |
632 | } |
633 | return false; | |
a3269a0a LOK |
634 | } |
635 | ||
44c74256 LOK |
636 | uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress) |
637 | { | |
cc60ab1c LOK |
638 | if (m_busDevices[iAddress]) |
639 | return m_busDevices[iAddress]->GetVendorId(); | |
640 | return false; | |
44c74256 LOK |
641 | } |
642 | ||
e55f3f70 LOK |
643 | cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress) |
644 | { | |
cc60ab1c LOK |
645 | if (m_busDevices[iAddress]) |
646 | return m_busDevices[iAddress]->GetPowerStatus(); | |
647 | return CEC_POWER_STATUS_UNKNOWN; | |
e55f3f70 LOK |
648 | } |
649 | ||
8d84e2c0 | 650 | bool CCECProcessor::Transmit(const cec_command &data) |
825ddb96 | 651 | { |
28352a04 | 652 | bool bReturn(false); |
13929cff LOK |
653 | LogOutput(data); |
654 | ||
28352a04 LOK |
655 | CCECAdapterMessage *output = new CCECAdapterMessage(data); |
656 | bReturn = Transmit(output); | |
657 | delete output; | |
658 | ||
659 | return bReturn; | |
06bfd4d7 | 660 | } |
13929cff | 661 | |
28352a04 | 662 | bool CCECProcessor::Transmit(CCECAdapterMessage *output) |
06bfd4d7 LOK |
663 | { |
664 | bool bReturn(false); | |
2abe74eb | 665 | CLockObject lock(&m_mutex); |
eb35e4ca LOK |
666 | { |
667 | CLockObject msgLock(&output->mutex); | |
668 | if (!m_communication || !m_communication->Write(output)) | |
669 | return bReturn; | |
670 | else | |
0e31a62c | 671 | { |
3a0ca6e1 | 672 | output->condition.Wait(&output->mutex); |
0e31a62c LOK |
673 | if (output->state != ADAPTER_MESSAGE_STATE_SENT) |
674 | { | |
675 | m_controller->AddLog(CEC_LOG_ERROR, "command was not sent"); | |
676 | return bReturn; | |
677 | } | |
678 | } | |
2abe74eb | 679 | |
06bfd4d7 | 680 | if (output->transmit_timeout > 0) |
cd505625 | 681 | { |
06bfd4d7 | 682 | if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false) |
0d8f286e | 683 | m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack"); |
cd505625 LOK |
684 | } |
685 | else | |
cd505625 | 686 | bReturn = true; |
2abe74eb LOK |
687 | } |
688 | ||
7ea0d558 | 689 | return bReturn; |
825ddb96 | 690 | } |
abbca718 | 691 | |
22b4e74a | 692 | void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */) |
abbca718 | 693 | { |
9dee1670 LOK |
694 | m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message"); |
695 | ||
06a1f7ce | 696 | cec_command command; |
f8513317 | 697 | // TODO |
ab1469a0 LOK |
698 | cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT); |
699 | command.parameters.PushBack((uint8_t)opcode); | |
700 | command.parameters.PushBack((uint8_t)reason); | |
9dee1670 LOK |
701 | |
702 | Transmit(command); | |
abbca718 LOK |
703 | } |
704 | ||
1f0e9e0f | 705 | bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */) |
abbca718 | 706 | { |
1f0e9e0f LOK |
707 | bool bError(false); |
708 | bool bTransmitSucceeded(false); | |
7ea0d558 | 709 | uint8_t iPacketsLeft(iLength / 4); |
abbca718 LOK |
710 | |
711 | int64_t iNow = GetTimeMs(); | |
25701fa6 | 712 | int64_t iTargetTime = iNow + (uint64_t) iTimeout; |
abbca718 | 713 | |
1f0e9e0f | 714 | while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime)) |
abbca718 | 715 | { |
220537f2 | 716 | CCECAdapterMessage msg; |
25701fa6 | 717 | |
06a1f7ce | 718 | if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000)) |
abbca718 | 719 | { |
abbca718 | 720 | iNow = GetTimeMs(); |
5d38b0b6 LOK |
721 | continue; |
722 | } | |
723 | ||
855a3a98 LOK |
724 | if (msg.message() == MSGCODE_FRAME_START && msg.ack()) |
725 | { | |
726 | m_busDevices[msg.initiator()]->GetHandler()->HandlePoll(msg.initiator(), msg.destination()); | |
727 | m_lastInitiator = msg.initiator(); | |
728 | iNow = GetTimeMs(); | |
729 | continue; | |
730 | } | |
731 | ||
732 | bError = msg.is_error(); | |
733 | if (msg.message() == MSGCODE_RECEIVE_FAILED && | |
734 | m_lastInitiator != CECDEVICE_UNKNOWN && | |
735 | !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed()) | |
736 | { | |
737 | iNow = GetTimeMs(); | |
738 | continue; | |
739 | } | |
740 | ||
edab6137 | 741 | if ((bError = msg.is_error()) == false) |
7ea0d558 | 742 | { |
0544ff56 LOK |
743 | m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); |
744 | ||
edab6137 LOK |
745 | switch(msg.message()) |
746 | { | |
747 | case MSGCODE_COMMAND_ACCEPTED: | |
748 | if (iPacketsLeft > 0) | |
749 | iPacketsLeft--; | |
750 | break; | |
751 | case MSGCODE_TRANSMIT_SUCCEEDED: | |
752 | bTransmitSucceeded = (iPacketsLeft == 0); | |
753 | bError = !bTransmitSucceeded; | |
754 | break; | |
755 | default: | |
8747dd4f LOK |
756 | if (ParseMessage(msg)) |
757 | m_commandBuffer.Push(m_currentframe); | |
edab6137 | 758 | } |
7ea0d558 | 759 | |
edab6137 LOK |
760 | iNow = GetTimeMs(); |
761 | } | |
abbca718 LOK |
762 | } |
763 | ||
1f0e9e0f | 764 | return bTransmitSucceeded && !bError; |
abbca718 LOK |
765 | } |
766 | ||
0e7b6c54 | 767 | bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg) |
abbca718 | 768 | { |
855a3a98 LOK |
769 | bool bEom(false); |
770 | bool bIsError(msg.is_error()); | |
60fa4578 | 771 | |
0e7b6c54 | 772 | if (msg.empty()) |
7ea0d558 | 773 | return bEom; |
abbca718 | 774 | |
0e7b6c54 | 775 | switch(msg.message()) |
abbca718 | 776 | { |
abbca718 LOK |
777 | case MSGCODE_FRAME_START: |
778 | { | |
ab1469a0 | 779 | m_currentframe.Clear(); |
0e7b6c54 | 780 | if (msg.size() >= 2) |
abbca718 | 781 | { |
0e7b6c54 LOK |
782 | m_currentframe.initiator = msg.initiator(); |
783 | m_currentframe.destination = msg.destination(); | |
784 | m_currentframe.ack = msg.ack(); | |
785 | m_currentframe.eom = msg.eom(); | |
abbca718 | 786 | } |
855a3a98 LOK |
787 | if (m_currentframe.ack == true) |
788 | { | |
789 | m_lastInitiator = m_currentframe.initiator; | |
790 | m_busDevices[m_lastInitiator]->GetHandler()->HandlePoll(m_currentframe.initiator, m_currentframe.destination); | |
791 | } | |
792 | } | |
793 | break; | |
794 | case MSGCODE_RECEIVE_FAILED: | |
795 | { | |
796 | if (m_lastInitiator != CECDEVICE_UNKNOWN) | |
797 | bIsError = m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed(); | |
abbca718 LOK |
798 | } |
799 | break; | |
800 | case MSGCODE_FRAME_DATA: | |
801 | { | |
0e7b6c54 | 802 | if (msg.size() >= 2) |
78e8010a | 803 | { |
ab1469a0 | 804 | m_currentframe.PushBack(msg[1]); |
0e7b6c54 | 805 | m_currentframe.eom = msg.eom(); |
abbca718 | 806 | } |
0e7b6c54 | 807 | bEom = msg.eom(); |
abbca718 | 808 | } |
78e8010a | 809 | break; |
abbca718 LOK |
810 | default: |
811 | break; | |
812 | } | |
7ea0d558 | 813 | |
855a3a98 | 814 | m_controller->AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString()); |
7ea0d558 | 815 | return bEom; |
abbca718 LOK |
816 | } |
817 | ||
e9de9629 | 818 | void CCECProcessor::ParseCommand(cec_command &command) |
abbca718 | 819 | { |
e9de9629 | 820 | CStdString dataStr; |
1d3ca3de | 821 | dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode); |
e9de9629 LOK |
822 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) |
823 | dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]); | |
1d3ca3de | 824 | m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str()); |
dc113aca | 825 | |
7871d66e | 826 | if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST) |
e9de9629 | 827 | m_busDevices[(uint8_t)command.initiator]->HandleCommand(command); |
dc113aca LOK |
828 | } |
829 | ||
6d858ba4 LOK |
830 | cec_logical_addresses CCECProcessor::GetActiveDevices(void) |
831 | { | |
832 | cec_logical_addresses addresses; | |
988de7b9 | 833 | addresses.Clear(); |
6d858ba4 LOK |
834 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
835 | { | |
836 | if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
837 | addresses.Set((cec_logical_address) iPtr); | |
838 | } | |
839 | return addresses; | |
840 | } | |
841 | ||
842 | bool CCECProcessor::IsActiveDevice(cec_logical_address address) | |
843 | { | |
844 | return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT; | |
845 | } | |
846 | ||
847 | bool CCECProcessor::IsActiveDeviceType(cec_device_type type) | |
848 | { | |
6d858ba4 | 849 | for (unsigned int iPtr = 0; iPtr < 15; iPtr++) |
2813bd07 LOK |
850 | { |
851 | if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
6d858ba4 | 852 | return true; |
2813bd07 LOK |
853 | } |
854 | ||
6d858ba4 LOK |
855 | return false; |
856 | } | |
857 | ||
0f23c85c LOK |
858 | uint16_t CCECProcessor::GetPhysicalAddress(void) const |
859 | { | |
ab1469a0 | 860 | if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary]) |
16b1e052 | 861 | return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false); |
cc60ab1c | 862 | return false; |
0f23c85c LOK |
863 | } |
864 | ||
e9de9629 | 865 | void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode) |
dc113aca | 866 | { |
e9de9629 | 867 | m_controller->SetCurrentButton(iButtonCode); |
dc113aca LOK |
868 | } |
869 | ||
e9de9629 | 870 | void CCECProcessor::AddCommand(const cec_command &command) |
dc113aca | 871 | { |
0544ff56 | 872 | m_controller->AddCommand(command); |
dc113aca LOK |
873 | } |
874 | ||
95ba7a09 LOK |
875 | void CCECProcessor::AddKey(cec_keypress &key) |
876 | { | |
877 | m_controller->AddKey(key); | |
878 | } | |
879 | ||
e9de9629 | 880 | void CCECProcessor::AddKey(void) |
dc113aca | 881 | { |
e9de9629 | 882 | m_controller->AddKey(); |
abbca718 | 883 | } |
acec5f48 | 884 | |
e9de9629 | 885 | void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage) |
acec5f48 | 886 | { |
e9de9629 | 887 | m_controller->AddLog(level, strMessage); |
acec5f48 | 888 | } |
06bfd4d7 LOK |
889 | |
890 | bool CCECProcessor::SetAckMask(uint16_t iMask) | |
891 | { | |
28352a04 | 892 | bool bReturn(false); |
06bfd4d7 LOK |
893 | CStdString strLog; |
894 | strLog.Format("setting ackmask to %2x", iMask); | |
895 | m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
896 | ||
28352a04 | 897 | CCECAdapterMessage *output = new CCECAdapterMessage; |
06bfd4d7 LOK |
898 | |
899 | output->push_back(MSGSTART); | |
900 | output->push_escaped(MSGCODE_SET_ACK_MASK); | |
901 | output->push_escaped(iMask >> 8); | |
902 | output->push_escaped((uint8_t)iMask); | |
903 | output->push_back(MSGEND); | |
904 | ||
28352a04 | 905 | if ((bReturn = Transmit(output)) == false) |
06bfd4d7 | 906 | m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask"); |
06bfd4d7 | 907 | |
28352a04 LOK |
908 | delete output; |
909 | ||
910 | return bReturn; | |
06bfd4d7 | 911 | } |
a33794d8 LOK |
912 | |
913 | bool CCECProcessor::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = false */) | |
914 | { | |
915 | return m_busDevices[iDestination]->SendKeypress(key, bWait); | |
916 | } | |
917 | ||
918 | bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination, bool bWait /* = false */) | |
919 | { | |
920 | return m_busDevices[iDestination]->SendKeyRelease(bWait); | |
921 | } | |
7c63a480 | 922 | |
03ae897d LOK |
923 | const char *CCECProcessor::ToString(const cec_menu_state state) |
924 | { | |
925 | switch (state) | |
926 | { | |
927 | case CEC_MENU_STATE_ACTIVATED: | |
928 | return "activated"; | |
929 | case CEC_MENU_STATE_DEACTIVATED: | |
930 | return "deactivated"; | |
931 | default: | |
932 | return "unknown"; | |
933 | } | |
934 | } | |
935 | ||
936 | const char *CCECProcessor::ToString(const cec_version version) | |
937 | { | |
938 | switch (version) | |
939 | { | |
940 | case CEC_VERSION_1_2: | |
941 | return "1.2"; | |
942 | case CEC_VERSION_1_2A: | |
943 | return "1.2a"; | |
944 | case CEC_VERSION_1_3: | |
945 | return "1.3"; | |
946 | case CEC_VERSION_1_3A: | |
947 | return "1.3a"; | |
948 | case CEC_VERSION_1_4: | |
949 | return "1.4"; | |
950 | default: | |
951 | return "unknown"; | |
952 | } | |
953 | } | |
954 | ||
955 | const char *CCECProcessor::ToString(const cec_power_status status) | |
956 | { | |
957 | switch (status) | |
958 | { | |
959 | case CEC_POWER_STATUS_ON: | |
960 | return "on"; | |
961 | case CEC_POWER_STATUS_STANDBY: | |
962 | return "standby"; | |
963 | case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: | |
964 | return "in transition from on to standby"; | |
965 | case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: | |
966 | return "in transition from standby to on"; | |
967 | default: | |
968 | return "unknown"; | |
969 | } | |
970 | } | |
971 | ||
972 | const char *CCECProcessor::ToString(const cec_logical_address address) | |
973 | { | |
974 | switch(address) | |
975 | { | |
976 | case CECDEVICE_AUDIOSYSTEM: | |
977 | return "Audio"; | |
978 | case CECDEVICE_BROADCAST: | |
979 | return "Broadcast"; | |
980 | case CECDEVICE_FREEUSE: | |
981 | return "Free use"; | |
982 | case CECDEVICE_PLAYBACKDEVICE1: | |
983 | return "Playback 1"; | |
984 | case CECDEVICE_PLAYBACKDEVICE2: | |
985 | return "Playback 2"; | |
986 | case CECDEVICE_PLAYBACKDEVICE3: | |
987 | return "Playback 3"; | |
988 | case CECDEVICE_RECORDINGDEVICE1: | |
989 | return "Recorder 1"; | |
990 | case CECDEVICE_RECORDINGDEVICE2: | |
991 | return "Recorder 2"; | |
992 | case CECDEVICE_RECORDINGDEVICE3: | |
993 | return "Recorder 3"; | |
994 | case CECDEVICE_RESERVED1: | |
995 | return "Reserved 1"; | |
996 | case CECDEVICE_RESERVED2: | |
997 | return "Reserved 2"; | |
998 | case CECDEVICE_TUNER1: | |
999 | return "Tuner 1"; | |
1000 | case CECDEVICE_TUNER2: | |
1001 | return "Tuner 2"; | |
1002 | case CECDEVICE_TUNER3: | |
1003 | return "Tuner 3"; | |
1004 | case CECDEVICE_TUNER4: | |
1005 | return "Tuner 4"; | |
1006 | case CECDEVICE_TV: | |
1007 | return "TV"; | |
1008 | default: | |
1009 | return "unknown"; | |
1010 | } | |
1011 | } | |
1012 | ||
1013 | const char *CCECProcessor::ToString(const cec_deck_control_mode mode) | |
1014 | { | |
1015 | switch (mode) | |
1016 | { | |
1017 | case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND: | |
1018 | return "skip forward wind"; | |
1019 | case CEC_DECK_CONTROL_MODE_EJECT: | |
1020 | return "eject"; | |
1021 | case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND: | |
1022 | return "reverse rewind"; | |
1023 | case CEC_DECK_CONTROL_MODE_STOP: | |
1024 | return "stop"; | |
1025 | default: | |
1026 | return "unknown"; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | const char *CCECProcessor::ToString(const cec_deck_info status) | |
1031 | { | |
1032 | switch (status) | |
1033 | { | |
1034 | case CEC_DECK_INFO_PLAY: | |
1035 | return "play"; | |
1036 | case CEC_DECK_INFO_RECORD: | |
1037 | return "record"; | |
1038 | case CEC_DECK_INFO_PLAY_REVERSE: | |
1039 | return "play reverse"; | |
1040 | case CEC_DECK_INFO_STILL: | |
1041 | return "still"; | |
1042 | case CEC_DECK_INFO_SLOW: | |
1043 | return "slow"; | |
1044 | case CEC_DECK_INFO_SLOW_REVERSE: | |
1045 | return "slow reverse"; | |
1046 | case CEC_DECK_INFO_FAST_FORWARD: | |
1047 | return "fast forward"; | |
1048 | case CEC_DECK_INFO_FAST_REVERSE: | |
1049 | return "fast reverse"; | |
1050 | case CEC_DECK_INFO_NO_MEDIA: | |
1051 | return "no media"; | |
1052 | case CEC_DECK_INFO_STOP: | |
1053 | return "stop"; | |
1054 | case CEC_DECK_INFO_SKIP_FORWARD_WIND: | |
1055 | return "info skip forward wind"; | |
1056 | case CEC_DECK_INFO_SKIP_REVERSE_REWIND: | |
1057 | return "info skip reverse rewind"; | |
1058 | case CEC_DECK_INFO_INDEX_SEARCH_FORWARD: | |
1059 | return "info index search forward"; | |
1060 | case CEC_DECK_INFO_INDEX_SEARCH_REVERSE: | |
1061 | return "info index search reverse"; | |
1062 | case CEC_DECK_INFO_OTHER_STATUS: | |
1063 | return "other"; | |
1064 | default: | |
1065 | return "unknown"; | |
1066 | } | |
1067 | } | |
1068 | ||
1069 | const char *CCECProcessor::ToString(const cec_opcode opcode) | |
1070 | { | |
1071 | switch (opcode) | |
1072 | { | |
1073 | case CEC_OPCODE_ACTIVE_SOURCE: | |
1074 | return "active source"; | |
1075 | case CEC_OPCODE_IMAGE_VIEW_ON: | |
1076 | return "image view on"; | |
1077 | case CEC_OPCODE_TEXT_VIEW_ON: | |
1078 | return "text view on"; | |
1079 | case CEC_OPCODE_INACTIVE_SOURCE: | |
1080 | return "inactive source"; | |
1081 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
1082 | return "request active source"; | |
1083 | case CEC_OPCODE_ROUTING_CHANGE: | |
1084 | return "routing change"; | |
1085 | case CEC_OPCODE_ROUTING_INFORMATION: | |
1086 | return "routing information"; | |
1087 | case CEC_OPCODE_SET_STREAM_PATH: | |
1088 | return "set stream path"; | |
1089 | case CEC_OPCODE_STANDBY: | |
1090 | return "standby"; | |
1091 | case CEC_OPCODE_RECORD_OFF: | |
1092 | return "record off"; | |
1093 | case CEC_OPCODE_RECORD_ON: | |
1094 | return "record on"; | |
1095 | case CEC_OPCODE_RECORD_STATUS: | |
1096 | return "record status"; | |
1097 | case CEC_OPCODE_RECORD_TV_SCREEN: | |
1098 | return "record tv screen"; | |
1099 | case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: | |
1100 | return "clear analogue timer"; | |
1101 | case CEC_OPCODE_CLEAR_DIGITAL_TIMER: | |
1102 | return "clear digital timer"; | |
1103 | case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: | |
1104 | return "clear external timer"; | |
1105 | case CEC_OPCODE_SET_ANALOGUE_TIMER: | |
1106 | return "set analogue timer"; | |
1107 | case CEC_OPCODE_SET_DIGITAL_TIMER: | |
1108 | return "set digital timer"; | |
1109 | case CEC_OPCODE_SET_EXTERNAL_TIMER: | |
1110 | return "set external timer"; | |
1111 | case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: | |
1112 | return "set timer program title"; | |
1113 | case CEC_OPCODE_TIMER_CLEARED_STATUS: | |
1114 | return "timer cleared status"; | |
1115 | case CEC_OPCODE_TIMER_STATUS: | |
1116 | return "timer status"; | |
1117 | case CEC_OPCODE_CEC_VERSION: | |
1118 | return "cec version"; | |
1119 | case CEC_OPCODE_GET_CEC_VERSION: | |
1120 | return "get cec version"; | |
1121 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
1122 | return "give physical address"; | |
1123 | case CEC_OPCODE_GET_MENU_LANGUAGE: | |
1124 | return "get menu language"; | |
1125 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: | |
1126 | return "report physical address"; | |
1127 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
1128 | return "set menu language"; | |
1129 | case CEC_OPCODE_DECK_CONTROL: | |
1130 | return "deck control"; | |
1131 | case CEC_OPCODE_DECK_STATUS: | |
1132 | return "deck status"; | |
1133 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
1134 | return "give deck status"; | |
1135 | case CEC_OPCODE_PLAY: | |
1136 | return "play"; | |
1137 | case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: | |
1138 | return "give tuner status"; | |
1139 | case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: | |
1140 | return "select analogue service"; | |
1141 | case CEC_OPCODE_SELECT_DIGITAL_SERVICE: | |
1142 | return "set digital service"; | |
1143 | case CEC_OPCODE_TUNER_DEVICE_STATUS: | |
1144 | return "tuner device status"; | |
1145 | case CEC_OPCODE_TUNER_STEP_DECREMENT: | |
1146 | return "tuner step decrement"; | |
1147 | case CEC_OPCODE_TUNER_STEP_INCREMENT: | |
1148 | return "tuner step increment"; | |
1149 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
1150 | return "device vendor id"; | |
1151 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
1152 | return "give device vendor id"; | |
1153 | case CEC_OPCODE_VENDOR_COMMAND: | |
1154 | return "vendor command"; | |
1155 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
1156 | return "vendor command with id"; | |
1157 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: | |
1158 | return "vendor remote button down"; | |
1159 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: | |
1160 | return "vendor remote button up"; | |
1161 | case CEC_OPCODE_SET_OSD_STRING: | |
1162 | return "set osd string"; | |
1163 | case CEC_OPCODE_GIVE_OSD_NAME: | |
1164 | return "give osd name"; | |
1165 | case CEC_OPCODE_SET_OSD_NAME: | |
1166 | return "set osd name"; | |
1167 | case CEC_OPCODE_MENU_REQUEST: | |
1168 | return "menu request"; | |
1169 | case CEC_OPCODE_MENU_STATUS: | |
1170 | return "menu status"; | |
1171 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
1172 | return "user control pressed"; | |
1173 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
1174 | return "user control release"; | |
1175 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
1176 | return "give device power status"; | |
1177 | case CEC_OPCODE_REPORT_POWER_STATUS: | |
1178 | return "report power status"; | |
1179 | case CEC_OPCODE_FEATURE_ABORT: | |
1180 | return "feature abort"; | |
1181 | case CEC_OPCODE_ABORT: | |
1182 | return "abort"; | |
1183 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
1184 | return "give audio status"; | |
1185 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
1186 | return "give audio mode status"; | |
1187 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
1188 | return "report audio status"; | |
1189 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
1190 | return "set system audio mode"; | |
1191 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
1192 | return "system audio mode request"; | |
1193 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
1194 | return "system audio mode status"; | |
1195 | case CEC_OPCODE_SET_AUDIO_RATE: | |
1196 | return "set audio rate"; | |
1197 | default: | |
1198 | return "UNKNOWN"; | |
1199 | } | |
1200 | } | |
1201 | ||
1202 | const char *CCECProcessor::ToString(const cec_system_audio_status mode) | |
1203 | { | |
1204 | switch(mode) | |
1205 | { | |
1206 | case CEC_SYSTEM_AUDIO_STATUS_ON: | |
1207 | return "on"; | |
1208 | case CEC_SYSTEM_AUDIO_STATUS_OFF: | |
1209 | return "off"; | |
1210 | default: | |
1211 | return "unknown"; | |
1212 | } | |
1213 | } | |
1214 | ||
1215 | const char *CCECProcessor::ToString(const cec_audio_status status) | |
1216 | { | |
1217 | // TODO this is a mask | |
1218 | return "TODO"; | |
1219 | } | |
1220 | ||
1221 | const char *CCECProcessor::ToString(const cec_vendor_id vendor) | |
1222 | { | |
1223 | switch (vendor) | |
1224 | { | |
1225 | case CEC_VENDOR_SAMSUNG: | |
1226 | return "Samsung"; | |
1227 | case CEC_VENDOR_LG: | |
1228 | return "LG"; | |
1229 | case CEC_VENDOR_PANASONIC: | |
1230 | return "Panasonic"; | |
1231 | case CEC_VENDOR_PIONEER: | |
1232 | return "Pioneer"; | |
1233 | case CEC_VENDOR_ONKYO: | |
1234 | return "Onkyo"; | |
1235 | case CEC_VENDOR_YAMAHA: | |
1236 | return "Yamaha"; | |
ec0deac1 LOK |
1237 | case CEC_VENDOR_PHILIPS: |
1238 | return "Philips"; | |
03ae897d LOK |
1239 | default: |
1240 | return "Unknown"; | |
1241 | } | |
1242 | } | |
1243 | ||
7c63a480 LOK |
1244 | void *CCECBusScan::Process(void) |
1245 | { | |
1246 | CCECBusDevice *device(NULL); | |
5e5637c6 | 1247 | while (!IsStopped()) |
7c63a480 | 1248 | { |
5e5637c6 | 1249 | for (unsigned int iPtr = 0; iPtr < 15 && !IsStopped(); iPtr++) |
7c63a480 | 1250 | { |
5e5637c6 LOK |
1251 | device = m_processor->m_busDevices[iPtr]; |
1252 | if (device && device->GetStatus() == CEC_DEVICE_STATUS_PRESENT) | |
1253 | { | |
1254 | if (!IsStopped()) | |
0b775bf2 | 1255 | device->GetPhysicalAddress(false); |
5e5637c6 | 1256 | Sleep(5); |
7c63a480 | 1257 | |
5e5637c6 LOK |
1258 | if (!IsStopped()) |
1259 | device->GetCecVersion(); | |
1260 | Sleep(5); | |
7c63a480 | 1261 | |
5e5637c6 LOK |
1262 | if (!IsStopped()) |
1263 | device->GetVendorId(); | |
1264 | Sleep(5); | |
1265 | } | |
7c63a480 | 1266 | } |
34d46707 | 1267 | Sleep(5000); |
7c63a480 LOK |
1268 | } |
1269 | return NULL; | |
1270 | } |