Commit | Line | Data |
---|---|---|
e9de9629 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. |
e9de9629 LOK |
5 | * libCEC(R) is an original work, containing original code. |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
33 | #include "CECCommandHandler.h" | |
eafa9d46 | 34 | #include "../devices/CECBusDevice.h" |
a1f8fb1b | 35 | #include "../devices/CECAudioSystem.h" |
28089abc | 36 | #include "../devices/CECPlaybackDevice.h" |
004b8382 | 37 | #include "../CECClient.h" |
387b6f6f | 38 | #include "../CECProcessor.h" |
5477a250 | 39 | #include "../LibCEC.h" |
0d800fe5 | 40 | #include "../CECTypeUtils.h" |
c9d15485 | 41 | #include "../platform/util/util.h" |
e9de9629 LOK |
42 | |
43 | using namespace CEC; | |
8747dd4f | 44 | using namespace std; |
f00ff009 | 45 | using namespace PLATFORM; |
e9de9629 | 46 | |
004b8382 | 47 | #define LIB_CEC m_busDevice->GetProcessor()->GetLib() |
0d800fe5 | 48 | #define ToString(p) CCECTypeUtils::ToString(p) |
004b8382 | 49 | |
8fa35473 LOK |
50 | CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : |
51 | m_busDevice(busDevice), | |
52 | m_processor(m_busDevice->GetProcessor()), | |
ae693aaa LOK |
53 | m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT), |
54 | m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT), | |
89a726fa | 55 | m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES), |
b64db02e | 56 | m_bHandlerInited(false), |
d79b67d8 | 57 | m_bOPTSendDeckStatusUpdateOnActiveSource(false), |
960f33c6 | 58 | m_vendorId(CEC_VENDOR_UNKNOWN), |
b0015449 LOK |
59 | m_waitForResponse(new CWaitForResponse), |
60 | m_bActiveSourcePending(false) | |
e9de9629 | 61 | { |
8fa35473 LOK |
62 | } |
63 | ||
64 | CCECCommandHandler::~CCECCommandHandler(void) | |
65 | { | |
c9d15485 | 66 | DELETE_AND_NULL(m_waitForResponse); |
e9de9629 LOK |
67 | } |
68 | ||
69 | bool CCECCommandHandler::HandleCommand(const cec_command &command) | |
70 | { | |
d297cbd4 LOK |
71 | if (command.opcode_set == 0) |
72 | return HandlePoll(command); | |
73 | ||
3e61b350 | 74 | bool bHandled(true); |
e9de9629 | 75 | |
004b8382 LOK |
76 | CCECClient *client = m_busDevice->GetClient(); |
77 | if (client) | |
78 | client->AddCommand(command); | |
855a3a98 | 79 | |
6b72afcd | 80 | switch(command.opcode) |
e9de9629 | 81 | { |
6b72afcd LOK |
82 | case CEC_OPCODE_REPORT_POWER_STATUS: |
83 | HandleReportPowerStatus(command); | |
84 | break; | |
85 | case CEC_OPCODE_CEC_VERSION: | |
86 | HandleDeviceCecVersion(command); | |
87 | break; | |
88 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
89 | HandleSetMenuLanguage(command); | |
90 | break; | |
91 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
004b8382 | 92 | if (m_processor->CECInitialised()) |
3e61b350 | 93 | HandleGivePhysicalAddress(command); |
6b72afcd | 94 | break; |
fbdea54c | 95 | case CEC_OPCODE_GET_MENU_LANGUAGE: |
004b8382 | 96 | if (m_processor->CECInitialised()) |
fbdea54c MK |
97 | HandleGiveMenuLanguage(command); |
98 | break; | |
6b72afcd | 99 | case CEC_OPCODE_GIVE_OSD_NAME: |
004b8382 | 100 | if (m_processor->CECInitialised()) |
3e61b350 | 101 | HandleGiveOSDName(command); |
6b72afcd LOK |
102 | break; |
103 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
004b8382 | 104 | if (m_processor->CECInitialised()) |
3e61b350 | 105 | HandleGiveDeviceVendorId(command); |
6b72afcd LOK |
106 | break; |
107 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
3e61b350 | 108 | HandleDeviceVendorId(command); |
6b72afcd LOK |
109 | break; |
110 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
111 | HandleDeviceVendorCommandWithId(command); | |
112 | break; | |
113 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
004b8382 | 114 | if (m_processor->CECInitialised()) |
3e61b350 | 115 | HandleGiveDeckStatus(command); |
6b72afcd LOK |
116 | break; |
117 | case CEC_OPCODE_DECK_CONTROL: | |
118 | HandleDeckControl(command); | |
119 | break; | |
120 | case CEC_OPCODE_MENU_REQUEST: | |
004b8382 | 121 | if (m_processor->CECInitialised()) |
3e61b350 | 122 | HandleMenuRequest(command); |
6b72afcd LOK |
123 | break; |
124 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
004b8382 | 125 | if (m_processor->CECInitialised()) |
3e61b350 | 126 | HandleGiveDevicePowerStatus(command); |
6b72afcd LOK |
127 | break; |
128 | case CEC_OPCODE_GET_CEC_VERSION: | |
004b8382 | 129 | if (m_processor->CECInitialised()) |
3e61b350 | 130 | HandleGetCecVersion(command); |
6b72afcd LOK |
131 | break; |
132 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
004b8382 | 133 | if (m_processor->CECInitialised()) |
3e61b350 | 134 | HandleUserControlPressed(command); |
6b72afcd LOK |
135 | break; |
136 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
004b8382 | 137 | if (m_processor->CECInitialised()) |
3e61b350 | 138 | HandleUserControlRelease(command); |
6b72afcd LOK |
139 | break; |
140 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
004b8382 | 141 | if (m_processor->CECInitialised()) |
3e61b350 | 142 | HandleGiveAudioStatus(command); |
6b72afcd LOK |
143 | break; |
144 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
004b8382 | 145 | if (m_processor->CECInitialised()) |
3e61b350 | 146 | HandleGiveSystemAudioModeStatus(command); |
6b72afcd LOK |
147 | break; |
148 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
004b8382 | 149 | if (m_processor->CECInitialised()) |
3e61b350 | 150 | HandleSystemAudioModeRequest(command); |
aa517a0d LOK |
151 | break; |
152 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
855a3a98 | 153 | HandleReportAudioStatus(command); |
aa517a0d LOK |
154 | break; |
155 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
855a3a98 | 156 | HandleSystemAudioModeStatus(command); |
aa517a0d LOK |
157 | break; |
158 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
855a3a98 | 159 | HandleSetSystemAudioMode(command); |
6b72afcd LOK |
160 | break; |
161 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
004b8382 | 162 | if (m_processor->CECInitialised()) |
3e61b350 | 163 | HandleRequestActiveSource(command); |
6b72afcd LOK |
164 | break; |
165 | case CEC_OPCODE_SET_STREAM_PATH: | |
166 | HandleSetStreamPath(command); | |
167 | break; | |
168 | case CEC_OPCODE_ROUTING_CHANGE: | |
169 | HandleRoutingChange(command); | |
170 | break; | |
907bd60f LOK |
171 | case CEC_OPCODE_ROUTING_INFORMATION: |
172 | HandleRoutingInformation(command); | |
173 | break; | |
6b72afcd | 174 | case CEC_OPCODE_STANDBY: |
004b8382 | 175 | if (m_processor->CECInitialised()) |
3e61b350 | 176 | HandleStandby(command); |
6b72afcd LOK |
177 | break; |
178 | case CEC_OPCODE_ACTIVE_SOURCE: | |
179 | HandleActiveSource(command); | |
180 | break; | |
907bd60f LOK |
181 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: |
182 | HandleReportPhysicalAddress(command); | |
183 | break; | |
15d1a84c LOK |
184 | case CEC_OPCODE_SET_OSD_NAME: |
185 | HandleSetOSDName(command); | |
186 | break; | |
1a6669b8 LOK |
187 | case CEC_OPCODE_IMAGE_VIEW_ON: |
188 | HandleImageViewOn(command); | |
189 | break; | |
190 | case CEC_OPCODE_TEXT_VIEW_ON: | |
191 | HandleTextViewOn(command); | |
192 | break; | |
4d738fe3 LOK |
193 | case CEC_OPCODE_FEATURE_ABORT: |
194 | HandleFeatureAbort(command); | |
195 | break; | |
468a1414 LOK |
196 | case CEC_OPCODE_VENDOR_COMMAND: |
197 | HandleVendorCommand(command); | |
198 | break; | |
34fe491f LOK |
199 | case CEC_OPCODE_PLAY: |
200 | // libCEC (currently) doesn't need to do anything with this, since player applications handle it | |
201 | // but it should not respond with a feature abort | |
202 | break; | |
6b72afcd | 203 | default: |
e9de9629 | 204 | bHandled = false; |
6b72afcd | 205 | break; |
e9de9629 LOK |
206 | } |
207 | ||
3e61b350 | 208 | if (bHandled) |
24dd566c | 209 | m_waitForResponse->Received((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode); |
004b8382 LOK |
210 | else |
211 | UnhandledCommand(command); | |
8fa35473 | 212 | |
e9de9629 LOK |
213 | return bHandled; |
214 | } | |
215 | ||
be5b0e24 LOK |
216 | bool CCECCommandHandler::HandleActiveSource(const cec_command &command) |
217 | { | |
218 | if (command.parameters.size == 2) | |
219 | { | |
220 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
004b8382 LOK |
221 | CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iAddress); |
222 | if (device) | |
223 | device->MarkAsActiveSource(); | |
be5b0e24 LOK |
224 | } |
225 | ||
226 | return true; | |
227 | } | |
228 | ||
a9232a79 LOK |
229 | bool CCECCommandHandler::HandleDeckControl(const cec_command &command) |
230 | { | |
aa40e0e2 LOK |
231 | CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); |
232 | if (device && command.parameters.size > 0) | |
a9232a79 | 233 | { |
aa40e0e2 | 234 | device->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); |
a9232a79 LOK |
235 | return true; |
236 | } | |
237 | ||
238 | return false; | |
239 | } | |
240 | ||
6a1c0009 LOK |
241 | bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) |
242 | { | |
243 | if (command.parameters.size == 1) | |
244 | { | |
245 | CCECBusDevice *device = GetDevice(command.initiator); | |
246 | if (device) | |
247 | device->SetCecVersion((cec_version) command.parameters[0]); | |
248 | } | |
249 | ||
250 | return true; | |
251 | } | |
252 | ||
e9de9629 LOK |
253 | bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) |
254 | { | |
0b8c7eab | 255 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
1d2cc194 | 256 | m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); |
6b72afcd | 257 | |
6a1c0009 | 258 | return true; |
e9de9629 LOK |
259 | } |
260 | ||
261 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
262 | { | |
8fa35473 | 263 | return SetVendorId(command); |
e9de9629 LOK |
264 | } |
265 | ||
4d738fe3 LOK |
266 | bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) |
267 | { | |
69a1a673 LOK |
268 | if (command.parameters.size == 2 && |
269 | (command.parameters[1] == CEC_ABORT_REASON_UNRECOGNIZED_OPCODE || | |
270 | command.parameters[1] == CEC_ABORT_REASON_REFUSED)) | |
004b8382 | 271 | m_processor->GetDevice(command.initiator)->SetUnsupportedFeature((cec_opcode)command.parameters[0]); |
7de6ad36 | 272 | return true; |
4d738fe3 LOK |
273 | } |
274 | ||
e9de9629 LOK |
275 | bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) |
276 | { | |
0b8c7eab | 277 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
278 | { |
279 | CCECBusDevice *device = GetDevice(command.destination); | |
280 | if (device) | |
281 | return device->TransmitCECVersion(command.initiator); | |
282 | } | |
0f23c85c LOK |
283 | |
284 | return false; | |
e9de9629 LOK |
285 | } |
286 | ||
a1f8fb1b LOK |
287 | bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) |
288 | { | |
0b8c7eab | 289 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd | 290 | { |
aa40e0e2 LOK |
291 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
292 | if (device) | |
293 | return device->TransmitAudioStatus(command.initiator); | |
6b72afcd | 294 | } |
a1f8fb1b LOK |
295 | |
296 | return false; | |
297 | } | |
298 | ||
e9de9629 LOK |
299 | bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
300 | { | |
0b8c7eab | 301 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd | 302 | { |
aa40e0e2 LOK |
303 | CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); |
304 | if (device) | |
305 | return device->TransmitDeckStatus(command.initiator); | |
6b72afcd | 306 | } |
0f23c85c LOK |
307 | |
308 | return false; | |
e9de9629 LOK |
309 | } |
310 | ||
311 | bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) | |
312 | { | |
0b8c7eab | 313 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
314 | { |
315 | CCECBusDevice *device = GetDevice(command.destination); | |
316 | if (device) | |
317 | return device->TransmitPowerState(command.initiator); | |
318 | } | |
0f23c85c LOK |
319 | |
320 | return false; | |
e9de9629 LOK |
321 | } |
322 | ||
323 | bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) | |
324 | { | |
0b8c7eab | 325 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
326 | { |
327 | CCECBusDevice *device = GetDevice(command.destination); | |
328 | if (device) | |
329 | return device->TransmitVendorID(command.initiator); | |
330 | } | |
0f23c85c LOK |
331 | |
332 | return false; | |
e9de9629 LOK |
333 | } |
334 | ||
335 | bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) | |
336 | { | |
0b8c7eab | 337 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
338 | { |
339 | CCECBusDevice *device = GetDevice(command.destination); | |
340 | if (device) | |
341 | return device->TransmitOSDName(command.initiator); | |
342 | } | |
0f23c85c LOK |
343 | |
344 | return false; | |
e9de9629 LOK |
345 | } |
346 | ||
347 | bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
348 | { | |
0b8c7eab | 349 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
350 | { |
351 | CCECBusDevice *device = GetDevice(command.destination); | |
352 | if (device) | |
7656096e | 353 | return device->TransmitPhysicalAddress(); |
6b72afcd | 354 | } |
09c10b66 LOK |
355 | |
356 | return false; | |
e9de9629 LOK |
357 | } |
358 | ||
fbdea54c MK |
359 | bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) |
360 | { | |
0b8c7eab | 361 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
fbdea54c MK |
362 | { |
363 | CCECBusDevice *device = GetDevice(command.destination); | |
364 | if (device) | |
365 | return device->TransmitSetMenuLanguage(command.initiator); | |
366 | } | |
367 | ||
368 | return false; | |
369 | } | |
370 | ||
1a6669b8 LOK |
371 | bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) |
372 | { | |
0b8c7eab | 373 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
1a6669b8 | 374 | { |
aa40e0e2 LOK |
375 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
376 | if (device) | |
377 | return device->TransmitSystemAudioModeStatus(command.initiator); | |
1a6669b8 LOK |
378 | } |
379 | ||
380 | return false; | |
381 | } | |
382 | ||
383 | bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) | |
384 | { | |
004b8382 | 385 | m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); |
1a6669b8 LOK |
386 | return true; |
387 | } | |
388 | ||
e9de9629 LOK |
389 | bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) |
390 | { | |
0b8c7eab | 391 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
0f23c85c | 392 | { |
e1804a4e LOK |
393 | CCECBusDevice *device = GetDevice(command.destination); |
394 | if (device) | |
6b72afcd | 395 | { |
004b8382 LOK |
396 | CCECClient *client = device->GetClient(); |
397 | if (client) | |
e1804a4e | 398 | { |
004b8382 LOK |
399 | if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE) |
400 | { | |
401 | if (client->MenuStateChanged(CEC_MENU_STATE_ACTIVATED) == 1) | |
402 | device->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
403 | } | |
404 | else if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE) | |
405 | { | |
406 | if (client->MenuStateChanged(CEC_MENU_STATE_DEACTIVATED) == 1) | |
407 | device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
408 | } | |
e1804a4e LOK |
409 | } |
410 | return device->TransmitMenuState(command.initiator); | |
6b72afcd | 411 | } |
15d1a84c LOK |
412 | } |
413 | ||
414 | return false; | |
415 | } | |
416 | ||
d297cbd4 LOK |
417 | bool CCECCommandHandler::HandlePoll(const cec_command &command) |
418 | { | |
a75e3a5a | 419 | m_busDevice->HandlePoll(command.destination); |
d297cbd4 LOK |
420 | return true; |
421 | } | |
422 | ||
15d1a84c LOK |
423 | bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) |
424 | { | |
425 | if (command.parameters.size == 1) | |
426 | { | |
aa40e0e2 LOK |
427 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
428 | if (device) | |
6b72afcd | 429 | { |
aa40e0e2 | 430 | device->SetAudioStatus(command.parameters[0]); |
15d1a84c | 431 | return true; |
6b72afcd | 432 | } |
0f23c85c LOK |
433 | } |
434 | return false; | |
e9de9629 LOK |
435 | } |
436 | ||
907bd60f LOK |
437 | bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) |
438 | { | |
0bfce006 | 439 | if (command.parameters.size == 3) |
907bd60f LOK |
440 | { |
441 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
16b1e052 | 442 | SetPhysicalAddress(command.initiator, iNewAddress); |
907bd60f LOK |
443 | } |
444 | return true; | |
445 | } | |
446 | ||
e55f3f70 LOK |
447 | bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) |
448 | { | |
449 | if (command.parameters.size == 1) | |
450 | { | |
451 | CCECBusDevice *device = GetDevice(command.initiator); | |
452 | if (device) | |
453 | device->SetPowerStatus((cec_power_status) command.parameters[0]); | |
454 | } | |
455 | return true; | |
456 | } | |
457 | ||
e9de9629 LOK |
458 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) |
459 | { | |
0b8c7eab | 460 | if (m_processor->CECInitialised()) |
5f316715 | 461 | { |
004b8382 LOK |
462 | LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator); |
463 | m_processor->GetDevice(command.initiator)->SetPowerStatus(CEC_POWER_STATUS_ON); | |
8747dd4f | 464 | |
5f316715 | 465 | vector<CCECBusDevice *> devices; |
f00ff009 | 466 | for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) |
5f316715 | 467 | devices[iDevicePtr]->TransmitActiveSource(); |
c4098482 | 468 | |
5f316715 LOK |
469 | return true; |
470 | } | |
471 | return false; | |
e9de9629 LOK |
472 | } |
473 | ||
474 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
475 | { | |
476 | if (command.parameters.size == 4) | |
477 | { | |
478 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
479 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
e9de9629 | 480 | |
0f23c85c LOK |
481 | CCECBusDevice *device = GetDevice(command.initiator); |
482 | if (device) | |
9dc04b07 | 483 | device->SetStreamPath(iNewAddress, iOldAddress); |
e9de9629 LOK |
484 | } |
485 | return true; | |
486 | } | |
487 | ||
907bd60f LOK |
488 | bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) |
489 | { | |
490 | if (command.parameters.size == 2) | |
491 | { | |
492 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
004b8382 LOK |
493 | CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); |
494 | if (device) | |
495 | device->MarkAsActiveSource(); | |
907bd60f | 496 | } |
15d1a84c LOK |
497 | |
498 | return false; | |
907bd60f LOK |
499 | } |
500 | ||
a3269a0a LOK |
501 | bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) |
502 | { | |
503 | if (command.parameters.size == 3) | |
504 | { | |
505 | CCECBusDevice *device = GetDevice(command.initiator); | |
506 | if (device) | |
507 | { | |
508 | cec_menu_language language; | |
509 | language.device = command.initiator; | |
56701628 | 510 | for (uint8_t iPtr = 0; iPtr < 4; iPtr++) |
a3269a0a LOK |
511 | language.language[iPtr] = command.parameters[iPtr]; |
512 | language.language[3] = 0; | |
513 | device->SetMenuLanguage(language); | |
15d1a84c LOK |
514 | return true; |
515 | } | |
516 | } | |
517 | return false; | |
518 | } | |
519 | ||
520 | bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) | |
521 | { | |
522 | if (command.parameters.size > 0) | |
523 | { | |
524 | CCECBusDevice *device = GetDevice(command.initiator); | |
525 | if (device) | |
526 | { | |
527 | char buf[1024]; | |
528 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
529 | buf[iPtr] = (char)command.parameters[iPtr]; | |
530 | buf[command.parameters.size] = 0; | |
531 | ||
532 | CStdString strName(buf); | |
533 | device->SetOSDName(strName); | |
6b72afcd | 534 | |
15d1a84c | 535 | return true; |
a3269a0a LOK |
536 | } |
537 | } | |
15d1a84c | 538 | return false; |
a3269a0a LOK |
539 | } |
540 | ||
e9de9629 LOK |
541 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) |
542 | { | |
0b8c7eab | 543 | if (m_processor->CECInitialised() && command.parameters.size >= 2) |
e9de9629 | 544 | { |
b6c7bc94 | 545 | uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
004b8382 | 546 | LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); |
72689600 LOK |
547 | |
548 | /* one of the device handled by libCEC has been made active */ | |
549 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); | |
004b8382 LOK |
550 | if (device && device->IsHandledByLibCEC()) |
551 | device->ActivateSource(); | |
e9de9629 | 552 | } |
15d1a84c | 553 | return false; |
e9de9629 LOK |
554 | } |
555 | ||
aa517a0d | 556 | bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) |
e5e86c76 | 557 | { |
0b8c7eab | 558 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
e5e86c76 | 559 | { |
aa40e0e2 LOK |
560 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
561 | if (device) | |
aa517a0d LOK |
562 | { |
563 | if (command.parameters.size >= 2) | |
564 | { | |
565 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
aa40e0e2 | 566 | device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); |
aa517a0d LOK |
567 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
568 | CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); | |
569 | if (newActiveDevice) | |
004b8382 | 570 | newActiveDevice->MarkAsActiveSource(); |
aa40e0e2 | 571 | return device->TransmitSetSystemAudioMode(command.initiator); |
aa517a0d LOK |
572 | } |
573 | else | |
574 | { | |
aa40e0e2 LOK |
575 | device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); |
576 | return device->TransmitSetSystemAudioMode(command.initiator); | |
aa517a0d LOK |
577 | } |
578 | } | |
e5e86c76 | 579 | } |
6b72afcd | 580 | return false; |
e5e86c76 LOK |
581 | } |
582 | ||
4d6b4433 LOK |
583 | bool CCECCommandHandler::HandleStandby(const cec_command &command) |
584 | { | |
585 | CCECBusDevice *device = GetDevice(command.initiator); | |
586 | if (device) | |
587 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
6b72afcd | 588 | |
4d6b4433 LOK |
589 | return true; |
590 | } | |
591 | ||
aa517a0d | 592 | bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) |
868dc71f | 593 | { |
aa517a0d | 594 | if (command.parameters.size == 1) |
868dc71f | 595 | { |
aa40e0e2 LOK |
596 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
597 | if (device) | |
aa517a0d | 598 | { |
aa40e0e2 | 599 | device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); |
aa517a0d LOK |
600 | return true; |
601 | } | |
602 | } | |
603 | ||
604 | return false; | |
605 | } | |
606 | ||
607 | bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) | |
608 | { | |
609 | if (command.parameters.size == 1) | |
610 | { | |
aa40e0e2 LOK |
611 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
612 | if (device) | |
aa517a0d | 613 | { |
aa40e0e2 | 614 | device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); |
aa517a0d LOK |
615 | return true; |
616 | } | |
868dc71f LOK |
617 | } |
618 | ||
619 | return false; | |
620 | } | |
621 | ||
1a6669b8 | 622 | bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) |
cf0ecd85 | 623 | { |
004b8382 | 624 | m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); |
1a6669b8 | 625 | return true; |
cf0ecd85 LOK |
626 | } |
627 | ||
e9de9629 LOK |
628 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) |
629 | { | |
0b8c7eab | 630 | if (m_processor->CECInitialised() && |
004b8382 | 631 | m_processor->IsHandledByLibCEC(command.destination) && |
e33e0d75 | 632 | command.parameters.size > 0) |
e9de9629 | 633 | { |
004b8382 LOK |
634 | CCECBusDevice *device = GetDevice(command.destination); |
635 | if (!device) | |
636 | return true; | |
637 | ||
638 | CCECClient *client = device->GetClient(); | |
639 | if (client) | |
640 | client->AddKey(); | |
641 | ||
e9de9629 | 642 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) |
004b8382 | 643 | client->SetCurrentButton((cec_user_control_code) command.parameters[0]); |
e33e0d75 MK |
644 | |
645 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || | |
646 | command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) | |
e9de9629 | 647 | { |
e33e0d75 | 648 | bool bPowerOn(true); |
e33e0d75 MK |
649 | if (!device) |
650 | return true; | |
651 | ||
652 | // CEC_USER_CONTROL_CODE_POWER operates as a toggle | |
653 | // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not | |
654 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER) | |
68391d4f | 655 | { |
004b8382 | 656 | cec_power_status status = device->GetCurrentPowerStatus(); |
e33e0d75 MK |
657 | bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
658 | } | |
659 | ||
660 | if (bPowerOn) | |
661 | { | |
004b8382 | 662 | device->ActivateSource(); |
68391d4f | 663 | } |
d1ab114f LOK |
664 | else |
665 | { | |
004b8382 | 666 | device->MarkAsInactiveSource(); |
e33e0d75 MK |
667 | device->TransmitInactiveSource(); |
668 | device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
d1ab114f | 669 | } |
e9de9629 | 670 | } |
e33e0d75 MK |
671 | |
672 | return true; | |
e9de9629 | 673 | } |
15d1a84c | 674 | return false; |
e9de9629 LOK |
675 | } |
676 | ||
677 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
678 | { | |
004b8382 LOK |
679 | CCECClient *client = m_processor->GetClient(command.destination); |
680 | if (client) | |
681 | client->AddKey(); | |
e9de9629 LOK |
682 | return true; |
683 | } | |
684 | ||
36cc67e0 | 685 | bool CCECCommandHandler::HandleVendorCommand(const cec_command &command) |
1de6617c | 686 | { |
36cc67e0 LOK |
687 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
688 | m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); | |
1de6617c LOK |
689 | return true; |
690 | } | |
691 | ||
e9de9629 LOK |
692 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) |
693 | { | |
004b8382 LOK |
694 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); |
695 | ||
0b8c7eab | 696 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
004b8382 | 697 | m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); |
0f23c85c LOK |
698 | } |
699 | ||
6f14b512 | 700 | size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const |
8747dd4f | 701 | { |
6f14b512 | 702 | size_t iReturn(0); |
8747dd4f | 703 | |
fcf10e27 | 704 | cec_logical_addresses addresses = m_processor->GetLogicalAddresses(); |
d2d1660c | 705 | for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++) |
8747dd4f LOK |
706 | { |
707 | if (addresses[iPtr]) | |
708 | { | |
709 | devices.push_back(GetDevice((cec_logical_address) iPtr)); | |
710 | ++iReturn; | |
711 | } | |
712 | } | |
713 | ||
714 | return iReturn; | |
715 | } | |
716 | ||
0f23c85c LOK |
717 | CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const |
718 | { | |
004b8382 | 719 | return m_processor->GetDevice(iLogicalAddress); |
e9de9629 | 720 | } |
6685ae07 LOK |
721 | |
722 | CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const | |
723 | { | |
fcf10e27 | 724 | return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress); |
6685ae07 | 725 | } |
181b3475 | 726 | |
8fa35473 | 727 | bool CCECCommandHandler::SetVendorId(const cec_command &command) |
181b3475 | 728 | { |
8fa35473 | 729 | bool bChanged(false); |
181b3475 LOK |
730 | if (command.parameters.size < 3) |
731 | { | |
004b8382 | 732 | LIB_CEC->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); |
8fa35473 | 733 | return bChanged; |
181b3475 LOK |
734 | } |
735 | ||
bae71306 LOK |
736 | uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) + |
737 | ((uint64_t)command.parameters[1] << 8) + | |
181b3475 LOK |
738 | (uint64_t)command.parameters[2]; |
739 | ||
740 | CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); | |
741 | if (device) | |
8fa35473 LOK |
742 | bChanged = device->SetVendorId(iVendorId); |
743 | return bChanged; | |
181b3475 | 744 | } |
5e822b09 | 745 | |
16b1e052 LOK |
746 | void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress) |
747 | { | |
004b8382 | 748 | if (!m_processor->IsHandledByLibCEC(iAddress)) |
16b1e052 | 749 | { |
c0152c09 LOK |
750 | CCECBusDevice *otherDevice = m_processor->GetDeviceByPhysicalAddress(iNewAddress); |
751 | CCECClient *client = otherDevice ? otherDevice->GetClient() : NULL; | |
004b8382 | 752 | |
c0152c09 LOK |
753 | CCECBusDevice *device = m_processor->GetDevice(iAddress); |
754 | if (device) | |
755 | device->SetPhysicalAddress(iNewAddress); | |
756 | else | |
16b1e052 | 757 | { |
c0152c09 | 758 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "device with logical address %X not found", iAddress); |
16b1e052 | 759 | } |
c0152c09 LOK |
760 | |
761 | /* another device reported the same physical address as ours */ | |
762 | if (client) | |
763 | client->ResetPhysicalAddress(); | |
764 | } | |
765 | else | |
766 | { | |
767 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "ignore physical address report for device %s (%X) because it's marked as handled by libCEC", ToString(iAddress), iAddress); | |
16b1e052 LOK |
768 | } |
769 | } | |
855a3a98 | 770 | |
f4698390 LOK |
771 | bool CCECCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
772 | { | |
773 | if (iDestination == CECDEVICE_TV) | |
774 | return TransmitImageViewOn(iInitiator, iDestination); | |
775 | ||
776 | return TransmitKeypress(iInitiator, iDestination, CEC_USER_CONTROL_CODE_POWER) && | |
777 | TransmitKeyRelease(iInitiator, iDestination); | |
778 | } | |
779 | ||
b64db02e | 780 | bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
8fa35473 LOK |
781 | { |
782 | cec_command command; | |
ae693aaa | 783 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON); |
8fa35473 | 784 | |
4fde2fd0 | 785 | return Transmit(command); |
8fa35473 LOK |
786 | } |
787 | ||
788 | bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
789 | { | |
790 | cec_command command; | |
ae693aaa | 791 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY); |
8fa35473 | 792 | |
4fde2fd0 | 793 | return Transmit(command); |
8fa35473 LOK |
794 | } |
795 | ||
5734016c LOK |
796 | bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */) |
797 | { | |
798 | cec_command command; | |
799 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE); | |
800 | ||
801 | return Transmit(command, !bWaitForResponse); | |
802 | } | |
803 | ||
a75e3a5a | 804 | bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
805 | { |
806 | cec_command command; | |
ae693aaa | 807 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION); |
8fa35473 | 808 | |
4fde2fd0 | 809 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
810 | } |
811 | ||
a75e3a5a | 812 | bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
813 | { |
814 | cec_command command; | |
ae693aaa | 815 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE); |
8fa35473 | 816 | |
4fde2fd0 | 817 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
818 | } |
819 | ||
a75e3a5a | 820 | bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
821 | { |
822 | cec_command command; | |
ae693aaa | 823 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME); |
8fa35473 | 824 | |
4fde2fd0 | 825 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
826 | } |
827 | ||
a75e3a5a | 828 | bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
829 | { |
830 | cec_command command; | |
ae693aaa | 831 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS); |
8fa35473 | 832 | |
4fde2fd0 | 833 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
834 | } |
835 | ||
a75e3a5a | 836 | bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
837 | { |
838 | cec_command command; | |
ae693aaa | 839 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS); |
8fa35473 | 840 | |
4fde2fd0 | 841 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
842 | } |
843 | ||
a75e3a5a | 844 | bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
845 | { |
846 | cec_command command; | |
ae693aaa | 847 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
8fa35473 | 848 | |
4fde2fd0 | 849 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
850 | } |
851 | ||
852 | bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
853 | { | |
854 | cec_command command; | |
ae693aaa | 855 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); |
8fa35473 LOK |
856 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
857 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
858 | ||
4fde2fd0 | 859 | return Transmit(command); |
8fa35473 LOK |
860 | } |
861 | ||
862 | bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion) | |
863 | { | |
864 | cec_command command; | |
ae693aaa | 865 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION); |
8fa35473 LOK |
866 | command.parameters.PushBack((uint8_t)cecVersion); |
867 | ||
4fde2fd0 | 868 | return Transmit(command); |
8fa35473 LOK |
869 | } |
870 | ||
871 | bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
872 | { | |
873 | cec_command command; | |
ae693aaa | 874 | cec_command::Format(command, iInitiator, CECDEVICE_TV, CEC_OPCODE_INACTIVE_SOURCE); |
8fa35473 LOK |
875 | command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF); |
876 | command.parameters.PushBack(iPhysicalAddress & 0xFF); | |
877 | ||
4fde2fd0 | 878 | return Transmit(command); |
8fa35473 LOK |
879 | } |
880 | ||
881 | bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState) | |
882 | { | |
883 | cec_command command; | |
ae693aaa | 884 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS); |
8fa35473 LOK |
885 | command.parameters.PushBack((uint8_t)menuState); |
886 | ||
4fde2fd0 | 887 | return Transmit(command); |
8fa35473 LOK |
888 | } |
889 | ||
890 | bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, CStdString strDeviceName) | |
891 | { | |
892 | cec_command command; | |
ae693aaa | 893 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME); |
6f14b512 | 894 | for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++) |
8fa35473 LOK |
895 | command.parameters.PushBack(strDeviceName.at(iPtr)); |
896 | ||
4fde2fd0 | 897 | return Transmit(command); |
8fa35473 LOK |
898 | } |
899 | ||
900 | bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage) | |
901 | { | |
902 | cec_command command; | |
ae693aaa | 903 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING); |
8fa35473 LOK |
904 | command.parameters.PushBack((uint8_t)duration); |
905 | ||
6f14b512 | 906 | size_t iLen = strlen(strMessage); |
8fa35473 LOK |
907 | if (iLen > 13) iLen = 13; |
908 | ||
6f14b512 | 909 | for (size_t iPtr = 0; iPtr < iLen; iPtr++) |
8fa35473 LOK |
910 | command.parameters.PushBack(strMessage[iPtr]); |
911 | ||
4fde2fd0 | 912 | return Transmit(command); |
8fa35473 LOK |
913 | } |
914 | ||
915 | bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type) | |
916 | { | |
917 | cec_command command; | |
ae693aaa | 918 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); |
8fa35473 LOK |
919 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
920 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
921 | command.parameters.PushBack((uint8_t) (type)); | |
922 | ||
4fde2fd0 | 923 | return Transmit(command); |
fbdea54c MK |
924 | } |
925 | ||
926 | bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator, const char lang[3]) | |
927 | { | |
928 | cec_command command; | |
929 | command.Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_SET_MENU_LANGUAGE); | |
930 | command.parameters.PushBack((uint8_t) lang[0]); | |
931 | command.parameters.PushBack((uint8_t) lang[1]); | |
932 | command.parameters.PushBack((uint8_t) lang[2]); | |
933 | ||
4fde2fd0 | 934 | return Transmit(command); |
8fa35473 LOK |
935 | } |
936 | ||
937 | bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
938 | { | |
939 | cec_command command; | |
ae693aaa | 940 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE); |
8fa35473 | 941 | |
4fde2fd0 | 942 | return Transmit(command); |
8fa35473 LOK |
943 | } |
944 | ||
945 | bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state) | |
946 | { | |
947 | cec_command command; | |
ae693aaa | 948 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS); |
8fa35473 LOK |
949 | command.parameters.PushBack((uint8_t) state); |
950 | ||
4fde2fd0 | 951 | return Transmit(command); |
8fa35473 LOK |
952 | } |
953 | ||
954 | bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, uint64_t iVendorId) | |
955 | { | |
956 | cec_command command; | |
ae693aaa | 957 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID); |
8fa35473 LOK |
958 | |
959 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 16) & 0xFF)); | |
960 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF)); | |
961 | command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF)); | |
962 | ||
4fde2fd0 | 963 | return Transmit(command); |
8fa35473 LOK |
964 | } |
965 | ||
966 | bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state) | |
967 | { | |
968 | cec_command command; | |
ae693aaa | 969 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS); |
8fa35473 LOK |
970 | command.parameters.PushBack(state); |
971 | ||
4fde2fd0 | 972 | return Transmit(command); |
8fa35473 LOK |
973 | } |
974 | ||
975 | bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) | |
976 | { | |
977 | cec_command command; | |
ae693aaa | 978 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE); |
8fa35473 LOK |
979 | command.parameters.PushBack((uint8_t)state); |
980 | ||
4fde2fd0 | 981 | return Transmit(command); |
8fa35473 LOK |
982 | } |
983 | ||
f42d3e0f LOK |
984 | bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath) |
985 | { | |
986 | cec_command command; | |
987 | cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH); | |
988 | command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF)); | |
989 | command.parameters.PushBack((uint8_t) (iStreamPath & 0xFF)); | |
990 | ||
4fde2fd0 | 991 | return Transmit(command); |
f42d3e0f LOK |
992 | } |
993 | ||
8fa35473 LOK |
994 | bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) |
995 | { | |
996 | cec_command command; | |
ae693aaa | 997 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS); |
8fa35473 LOK |
998 | command.parameters.PushBack((uint8_t)state); |
999 | ||
4fde2fd0 | 1000 | return Transmit(command); |
8fa35473 LOK |
1001 | } |
1002 | ||
1003 | bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state) | |
1004 | { | |
1005 | cec_command command; | |
ae693aaa | 1006 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS); |
8fa35473 LOK |
1007 | command.PushBack((uint8_t)state); |
1008 | ||
4fde2fd0 | 1009 | return Transmit(command); |
8fa35473 LOK |
1010 | } |
1011 | ||
4bec9d79 | 1012 | bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
8fa35473 LOK |
1013 | { |
1014 | cec_command command; | |
ae693aaa | 1015 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED); |
8fa35473 LOK |
1016 | command.parameters.PushBack((uint8_t)key); |
1017 | ||
4fde2fd0 | 1018 | return Transmit(command, !bWait); |
8fa35473 LOK |
1019 | } |
1020 | ||
4bec9d79 | 1021 | bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */) |
8fa35473 LOK |
1022 | { |
1023 | cec_command command; | |
ae693aaa | 1024 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE); |
8fa35473 | 1025 | |
4fde2fd0 | 1026 | return Transmit(command, !bWait); |
8fa35473 LOK |
1027 | } |
1028 | ||
4fde2fd0 | 1029 | bool CCECCommandHandler::Transmit(cec_command &command, bool bSuppressWait /* = false */) |
8fa35473 | 1030 | { |
b64db02e | 1031 | bool bReturn(false); |
4fde2fd0 LOK |
1032 | cec_opcode expectedResponse(cec_command::GetResponseOpcode(command.opcode)); |
1033 | bool bExpectResponse(expectedResponse != CEC_OPCODE_NONE && !bSuppressWait); | |
ae693aaa | 1034 | command.transmit_timeout = m_iTransmitTimeout; |
ae693aaa | 1035 | |
7e4558f1 LOK |
1036 | if (command.initiator == CECDEVICE_UNKNOWN) |
1037 | { | |
004b8382 | 1038 | LIB_CEC->AddLog(CEC_LOG_ERROR, "not transmitting a command without a valid initiator"); |
7e4558f1 LOK |
1039 | return bReturn; |
1040 | } | |
1041 | ||
ae693aaa | 1042 | { |
6c0ccaa5 | 1043 | uint8_t iTries(0), iMaxTries(!command.opcode_set ? 1 : m_iTransmitRetries + 1); |
ec15344c | 1044 | while (!bReturn && ++iTries <= iMaxTries && !m_busDevice->IsUnsupportedFeature(command.opcode)) |
b64db02e | 1045 | { |
99666519 | 1046 | if ((bReturn = m_processor->Transmit(command)) == true) |
19cbfa8f | 1047 | { |
004b8382 | 1048 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "command transmitted"); |
4478bc79 | 1049 | if (bExpectResponse) |
24dd566c LOK |
1050 | { |
1051 | bReturn = m_waitForResponse->Wait(expectedResponse); | |
004b8382 | 1052 | LIB_CEC->AddLog(CEC_LOG_DEBUG, bReturn ? "expected response received (%X: %s)" : "expected response not received (%X: %s)", (int)expectedResponse, ToString(expectedResponse)); |
24dd566c | 1053 | } |
19cbfa8f | 1054 | } |
b64db02e | 1055 | } |
ae693aaa | 1056 | } |
8fa35473 | 1057 | |
b64db02e | 1058 | return bReturn; |
8fa35473 | 1059 | } |
83be0701 | 1060 | |
3e61b350 | 1061 | bool CCECCommandHandler::ActivateSource(void) |
83be0701 | 1062 | { |
c4287bcd | 1063 | if (m_busDevice->IsActiveSource() && |
004b8382 | 1064 | m_busDevice->IsHandledByLibCEC()) |
c4287bcd | 1065 | { |
b0015449 LOK |
1066 | { |
1067 | CLockObject lock(m_mutex); | |
1068 | m_bActiveSourcePending = false; | |
1069 | } | |
1070 | ||
c4287bcd LOK |
1071 | m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON); |
1072 | m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
1073 | ||
dbad810a LOK |
1074 | bool bActiveSourceFailed = !m_busDevice->TransmitImageViewOn() || |
1075 | !m_busDevice->TransmitActiveSource() || | |
1076 | !m_busDevice->TransmitMenuState(CECDEVICE_TV); | |
1077 | ||
1078 | if (!bActiveSourceFailed) | |
b0015449 | 1079 | { |
dbad810a LOK |
1080 | CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice(); |
1081 | if (playbackDevice && SendDeckStatusUpdateOnActiveSource()) | |
1082 | bActiveSourceFailed = !playbackDevice->TransmitDeckStatus(CECDEVICE_TV); | |
1083 | } | |
1084 | ||
1085 | if (bActiveSourceFailed) | |
1086 | { | |
1087 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "failed to make '%s' the active source. will retry later", m_busDevice->GetLogicalAddressName()); | |
b0015449 LOK |
1088 | CLockObject lock(m_mutex); |
1089 | m_bActiveSourcePending = true; | |
1090 | return false; | |
1091 | } | |
aa40e0e2 | 1092 | |
c4287bcd | 1093 | m_bHandlerInited = true; |
83be0701 | 1094 | } |
7dc58c9f | 1095 | return true; |
83be0701 | 1096 | } |
b499cf16 LOK |
1097 | |
1098 | void CCECCommandHandler::SignalOpcode(cec_opcode opcode) | |
1099 | { | |
1100 | m_waitForResponse->Received(opcode); | |
1101 | } | |
b0015449 LOK |
1102 | |
1103 | bool CCECCommandHandler::ActiveSourcePending(void) | |
1104 | { | |
1105 | CLockObject lock(m_mutex); | |
1106 | return m_bActiveSourcePending; | |
1107 | } |