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