2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
34 #include "CECCommandHandler.h"
36 #include "lib/devices/CECBusDevice.h"
37 #include "lib/devices/CECAudioSystem.h"
38 #include "lib/devices/CECPlaybackDevice.h"
39 #include "lib/CECClient.h"
40 #include "lib/CECProcessor.h"
41 #include "lib/LibCEC.h"
42 #include "lib/CECTypeUtils.h"
43 #include "lib/platform/util/util.h"
47 using namespace PLATFORM
;
49 #define LIB_CEC m_busDevice->GetProcessor()->GetLib()
50 #define ToString(p) CCECTypeUtils::ToString(p)
51 #define REQUEST_POWER_STATUS_TIMEOUT 5000
53 CCECCommandHandler::CCECCommandHandler(CCECBusDevice
*busDevice
,
54 int32_t iTransmitTimeout
/* = CEC_DEFAULT_TRANSMIT_TIMEOUT */,
55 int32_t iTransmitWait
/* = CEC_DEFAULT_TRANSMIT_WAIT */,
56 int8_t iTransmitRetries
/* = CEC_DEFAULT_TRANSMIT_RETRIES */,
57 int64_t iActiveSourcePending
/* = 0 */) :
58 m_busDevice(busDevice
),
59 m_processor(m_busDevice
->GetProcessor()),
60 m_iTransmitTimeout(iTransmitTimeout
),
61 m_iTransmitWait(iTransmitWait
),
62 m_iTransmitRetries(iTransmitRetries
),
63 m_bHandlerInited(false),
64 m_bOPTSendDeckStatusUpdateOnActiveSource(false),
65 m_vendorId(CEC_VENDOR_UNKNOWN
),
66 m_iActiveSourcePending(iActiveSourcePending
),
67 m_iPowerStatusRequested(0)
71 bool CCECCommandHandler::HandleCommand(const cec_command
&command
)
73 if (command
.opcode_set
== 0)
74 return HandlePoll(command
);
76 int iHandled(CEC_ABORT_REASON_UNRECOGNIZED_OPCODE
);
78 LIB_CEC
->AddCommand(command
);
80 switch(command
.opcode
)
82 case CEC_OPCODE_REPORT_POWER_STATUS
:
83 iHandled
= HandleReportPowerStatus(command
);
85 case CEC_OPCODE_CEC_VERSION
:
86 iHandled
= HandleDeviceCecVersion(command
);
88 case CEC_OPCODE_SET_MENU_LANGUAGE
:
89 iHandled
= HandleSetMenuLanguage(command
);
91 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
92 iHandled
= HandleGivePhysicalAddress(command
);
94 case CEC_OPCODE_GET_MENU_LANGUAGE
:
95 iHandled
= HandleGiveMenuLanguage(command
);
97 case CEC_OPCODE_GIVE_OSD_NAME
:
98 iHandled
= HandleGiveOSDName(command
);
100 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
101 iHandled
= HandleGiveDeviceVendorId(command
);
103 case CEC_OPCODE_DEVICE_VENDOR_ID
:
104 iHandled
= HandleDeviceVendorId(command
);
106 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
107 iHandled
= HandleDeviceVendorCommandWithId(command
);
109 case CEC_OPCODE_GIVE_DECK_STATUS
:
110 iHandled
= HandleGiveDeckStatus(command
);
112 case CEC_OPCODE_DECK_CONTROL
:
113 iHandled
= HandleDeckControl(command
);
115 case CEC_OPCODE_MENU_REQUEST
:
116 iHandled
= HandleMenuRequest(command
);
118 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
119 iHandled
= HandleGiveDevicePowerStatus(command
);
121 case CEC_OPCODE_GET_CEC_VERSION
:
122 iHandled
= HandleGetCecVersion(command
);
124 case CEC_OPCODE_USER_CONTROL_PRESSED
:
125 iHandled
= HandleUserControlPressed(command
);
127 case CEC_OPCODE_USER_CONTROL_RELEASE
:
128 iHandled
= HandleUserControlRelease(command
);
130 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
131 iHandled
= HandleGiveAudioStatus(command
);
133 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
134 iHandled
= HandleGiveSystemAudioModeStatus(command
);
136 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
137 iHandled
= HandleSystemAudioModeRequest(command
);
139 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
140 iHandled
= HandleReportAudioStatus(command
);
142 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
143 iHandled
= HandleSystemAudioModeStatus(command
);
145 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
146 iHandled
= HandleSetSystemAudioMode(command
);
148 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
149 iHandled
= HandleRequestActiveSource(command
);
151 case CEC_OPCODE_SET_STREAM_PATH
:
152 iHandled
= HandleSetStreamPath(command
);
154 case CEC_OPCODE_ROUTING_CHANGE
:
155 iHandled
= HandleRoutingChange(command
);
157 case CEC_OPCODE_ROUTING_INFORMATION
:
158 iHandled
= HandleRoutingInformation(command
);
160 case CEC_OPCODE_STANDBY
:
161 iHandled
= HandleStandby(command
);
163 case CEC_OPCODE_ACTIVE_SOURCE
:
164 iHandled
= HandleActiveSource(command
);
166 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
167 iHandled
= HandleReportPhysicalAddress(command
);
169 case CEC_OPCODE_SET_OSD_NAME
:
170 iHandled
= HandleSetOSDName(command
);
172 case CEC_OPCODE_IMAGE_VIEW_ON
:
173 iHandled
= HandleImageViewOn(command
);
175 case CEC_OPCODE_TEXT_VIEW_ON
:
176 iHandled
= HandleTextViewOn(command
);
178 case CEC_OPCODE_FEATURE_ABORT
:
179 iHandled
= HandleFeatureAbort(command
);
181 case CEC_OPCODE_VENDOR_COMMAND
:
182 iHandled
= HandleVendorCommand(command
);
184 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
185 iHandled
= HandleVendorRemoteButtonDown(command
);
187 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
188 iHandled
= HandleVendorRemoteButtonUp(command
);
190 case CEC_OPCODE_PLAY
:
191 // libCEC (currently) doesn't need to do anything with this, since player applications handle it
192 // but it should not respond with a feature abort
193 iHandled
= COMMAND_HANDLED
;
199 if (iHandled
== COMMAND_HANDLED
)
200 m_busDevice
->SignalOpcode((command
.opcode
== CEC_OPCODE_FEATURE_ABORT
&& command
.parameters
.size
> 0) ? (cec_opcode
)command
.parameters
[0] : command
.opcode
);
202 UnhandledCommand(command
, (cec_abort_reason
)iHandled
);
204 return iHandled
== COMMAND_HANDLED
;
207 int CCECCommandHandler::HandleActiveSource(const cec_command
&command
)
209 if (command
.parameters
.size
== 2)
211 uint16_t iAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
212 CCECBusDevice
*device
= m_processor
->GetDeviceByPhysicalAddress(iAddress
);
215 device
->MarkAsActiveSource();
216 return COMMAND_HANDLED
;
220 return CEC_ABORT_REASON_INVALID_OPERAND
;
223 int CCECCommandHandler::HandleDeckControl(const cec_command
&command
)
225 CCECPlaybackDevice
*device
= CCECBusDevice::AsPlaybackDevice(GetDevice(command
.destination
));
226 if (device
&& command
.parameters
.size
> 0)
228 device
->SetDeckControlMode((cec_deck_control_mode
) command
.parameters
[0]);
229 return COMMAND_HANDLED
;
232 return CEC_ABORT_REASON_INVALID_OPERAND
;
235 int CCECCommandHandler::HandleDeviceCecVersion(const cec_command
&command
)
237 if (command
.parameters
.size
== 1)
239 CCECBusDevice
*device
= GetDevice(command
.initiator
);
241 device
->SetCecVersion((cec_version
) command
.parameters
[0]);
243 return COMMAND_HANDLED
;
246 return CEC_ABORT_REASON_INVALID_OPERAND
;
249 int CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command
& UNUSED(command
))
251 return CEC_ABORT_REASON_INVALID_OPERAND
;
254 int CCECCommandHandler::HandleDeviceVendorId(const cec_command
&command
)
256 SetVendorId(command
);
257 return COMMAND_HANDLED
;
260 int CCECCommandHandler::HandleFeatureAbort(const cec_command
&command
)
262 if (command
.parameters
.size
== 2 &&
263 (command
.parameters
[1] == CEC_ABORT_REASON_UNRECOGNIZED_OPCODE
||
264 command
.parameters
[1] == CEC_ABORT_REASON_REFUSED
))
265 m_processor
->GetDevice(command
.initiator
)->SetUnsupportedFeature((cec_opcode
)command
.parameters
[0]);
266 return COMMAND_HANDLED
;
269 int CCECCommandHandler::HandleGetCecVersion(const cec_command
&command
)
271 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
273 CCECBusDevice
*device
= GetDevice(command
.destination
);
274 if (device
&& device
->TransmitCECVersion(command
.initiator
, true))
275 return COMMAND_HANDLED
;
276 return CEC_ABORT_REASON_INVALID_OPERAND
;
279 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
282 int CCECCommandHandler::HandleGiveAudioStatus(const cec_command
&command
)
284 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
286 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.destination
));
287 if (device
&& device
->TransmitAudioStatus(command
.initiator
, true))
288 return COMMAND_HANDLED
;
289 return CEC_ABORT_REASON_INVALID_OPERAND
;
292 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
295 int CCECCommandHandler::HandleGiveDeckStatus(const cec_command
&command
)
297 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
299 CCECPlaybackDevice
*device
= CCECBusDevice::AsPlaybackDevice(GetDevice(command
.destination
));
300 if (device
&& device
->TransmitDeckStatus(command
.initiator
, true))
301 return COMMAND_HANDLED
;
302 return CEC_ABORT_REASON_INVALID_OPERAND
;
305 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
308 int CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command
&command
)
310 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
312 CCECBusDevice
*device
= GetDevice(command
.destination
);
313 if (device
&& device
->TransmitPowerState(command
.initiator
, true))
314 return COMMAND_HANDLED
;
315 return CEC_ABORT_REASON_INVALID_OPERAND
;
318 return CEC_ABORT_REASON_INVALID_OPERAND
;
321 int CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command
&command
)
323 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
325 CCECBusDevice
*device
= GetDevice(command
.destination
);
326 if (device
&& device
->TransmitVendorID(command
.initiator
, true, true))
327 return COMMAND_HANDLED
;
330 return CEC_ABORT_REASON_INVALID_OPERAND
;
333 int CCECCommandHandler::HandleGiveOSDName(const cec_command
&command
)
335 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
337 CCECBusDevice
*device
= GetDevice(command
.destination
);
338 if (device
&& device
->TransmitOSDName(command
.initiator
, true))
339 return COMMAND_HANDLED
;
342 return CEC_ABORT_REASON_INVALID_OPERAND
;
345 int CCECCommandHandler::HandleGivePhysicalAddress(const cec_command
&command
)
347 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
349 CCECBusDevice
*device
= GetDevice(command
.destination
);
350 if (device
&& device
->TransmitPhysicalAddress(true))
351 return COMMAND_HANDLED
;
352 return CEC_ABORT_REASON_INVALID_OPERAND
;
355 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
358 int CCECCommandHandler::HandleGiveMenuLanguage(const cec_command
&command
)
360 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
362 CCECBusDevice
*device
= GetDevice(command
.destination
);
363 if (device
&& device
->TransmitSetMenuLanguage(command
.initiator
, true))
364 return COMMAND_HANDLED
;
365 return CEC_ABORT_REASON_INVALID_OPERAND
;
368 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
371 int CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command
&command
)
373 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
375 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.destination
));
376 if (device
&& device
->TransmitSystemAudioModeStatus(command
.initiator
, true))
377 return COMMAND_HANDLED
;
378 return CEC_ABORT_REASON_INVALID_OPERAND
;
381 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
384 int CCECCommandHandler::HandleImageViewOn(const cec_command
&command
)
386 CCECBusDevice
*device
= GetDevice(command
.destination
);
387 if (device
&& (device
->GetCurrentStatus() == CEC_DEVICE_STATUS_PRESENT
||
388 device
->GetCurrentStatus() == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
))
390 if (device
->GetCurrentPowerStatus() == CEC_POWER_STATUS_STANDBY
||
391 device
->GetCurrentPowerStatus() == CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
)
392 device
->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
);
394 return COMMAND_HANDLED
;
397 int CCECCommandHandler::HandleMenuRequest(const cec_command
&command
)
399 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
401 CCECBusDevice
*device
= GetDevice(command
.destination
);
404 CCECClient
*client
= device
->GetClient();
407 if (command
.parameters
[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE
)
409 if (client
->MenuStateChanged(CEC_MENU_STATE_ACTIVATED
) == 1)
410 device
->SetMenuState(CEC_MENU_STATE_ACTIVATED
);
412 else if (command
.parameters
[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE
)
414 if (client
->MenuStateChanged(CEC_MENU_STATE_DEACTIVATED
) == 1)
415 device
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
418 if (device
->TransmitMenuState(command
.initiator
, true))
419 return COMMAND_HANDLED
;
421 return CEC_ABORT_REASON_INVALID_OPERAND
;
424 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
427 bool CCECCommandHandler::HandlePoll(const cec_command
&command
)
429 m_busDevice
->HandlePoll(command
.destination
);
433 int CCECCommandHandler::HandleReportAudioStatus(const cec_command
&command
)
435 if (command
.parameters
.size
== 1)
437 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.initiator
));
440 device
->SetAudioStatus(command
.parameters
[0]);
441 return COMMAND_HANDLED
;
444 return CEC_ABORT_REASON_INVALID_OPERAND
;
447 int CCECCommandHandler::HandleReportPhysicalAddress(const cec_command
&command
)
449 if (command
.parameters
.size
== 3)
451 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
452 SetPhysicalAddress(command
.initiator
, iNewAddress
);
453 return COMMAND_HANDLED
;
455 return CEC_ABORT_REASON_INVALID_OPERAND
;
458 int CCECCommandHandler::HandleReportPowerStatus(const cec_command
&command
)
460 if (command
.parameters
.size
== 1)
462 CCECBusDevice
*device
= GetDevice(command
.initiator
);
465 device
->SetPowerStatus((cec_power_status
) command
.parameters
[0]);
466 return COMMAND_HANDLED
;
469 return CEC_ABORT_REASON_INVALID_OPERAND
;
472 int CCECCommandHandler::HandleRequestActiveSource(const cec_command
&command
)
474 if (m_processor
->CECInitialised())
476 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, ">> %i requests active source", (uint8_t) command
.initiator
);
477 m_processor
->GetDevice(command
.initiator
)->SetPowerStatus(CEC_POWER_STATUS_ON
);
479 vector
<CCECBusDevice
*> devices
;
480 for (size_t iDevicePtr
= 0; iDevicePtr
< GetMyDevices(devices
); iDevicePtr
++)
481 devices
[iDevicePtr
]->TransmitActiveSource(true);
484 return COMMAND_HANDLED
;
487 int CCECCommandHandler::HandleRoutingChange(const cec_command
&command
)
489 if (command
.parameters
.size
== 4)
491 CCECBusDevice
*device
= GetDevice(command
.initiator
);
494 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[2] << 8) | ((uint16_t)command
.parameters
[3]);
495 device
->SetActiveRoute(iNewAddress
);
496 return COMMAND_HANDLED
;
500 return CEC_ABORT_REASON_INVALID_OPERAND
;
503 int CCECCommandHandler::HandleRoutingInformation(const cec_command
&command
)
505 if (command
.parameters
.size
== 2)
507 CCECBusDevice
*device
= GetDevice(command
.initiator
);
510 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
511 device
->SetActiveRoute(iNewAddress
);
512 return COMMAND_HANDLED
;
516 return CEC_ABORT_REASON_INVALID_OPERAND
;
519 int CCECCommandHandler::HandleSetMenuLanguage(const cec_command
&command
)
521 if (command
.parameters
.size
== 3)
523 CCECBusDevice
*device
= GetDevice(command
.initiator
);
526 cec_menu_language language
;
527 language
.device
= command
.initiator
;
528 for (uint8_t iPtr
= 0; iPtr
< 4; iPtr
++)
529 language
.language
[iPtr
] = command
.parameters
[iPtr
];
530 language
.language
[3] = 0;
531 device
->SetMenuLanguage(language
);
532 return COMMAND_HANDLED
;
536 return CEC_ABORT_REASON_INVALID_OPERAND
;
539 int CCECCommandHandler::HandleSetOSDName(const cec_command
&command
)
541 if (command
.parameters
.size
> 0)
543 CCECBusDevice
*device
= GetDevice(command
.initiator
);
547 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
548 buf
[iPtr
] = (char)command
.parameters
[iPtr
];
549 buf
[command
.parameters
.size
] = 0;
551 CStdString
strName(buf
);
552 device
->SetOSDName(strName
);
554 return COMMAND_HANDLED
;
558 return CEC_ABORT_REASON_INVALID_OPERAND
;
561 int CCECCommandHandler::HandleSetStreamPath(const cec_command
&command
)
563 if (!m_processor
->CECInitialised())
564 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
566 if (command
.parameters
.size
>= 2)
568 uint16_t iStreamAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
569 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, ">> %s (%x) sets stream path to physical address %04x", ToString(command
.initiator
), command
.initiator
, iStreamAddress
);
571 /* one of the device handled by libCEC has been made active */
572 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamAddress
);
573 if (device
&& device
->IsHandledByLibCEC())
575 device
->ActivateSource();
576 return COMMAND_HANDLED
;
580 return CEC_ABORT_REASON_INVALID_OPERAND
;
583 int CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command
&command
)
585 if (m_processor
->CECInitialised() && m_processor
->IsHandledByLibCEC(command
.destination
))
587 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.destination
));
590 if (command
.parameters
.size
>= 2)
592 device
->SetPowerStatus(CEC_POWER_STATUS_ON
);
593 device
->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON
);
594 uint16_t iNewAddress
= ((uint16_t)command
.parameters
[0] << 8) | ((uint16_t)command
.parameters
[1]);
595 CCECBusDevice
*newActiveDevice
= GetDeviceByPhysicalAddress(iNewAddress
);
597 newActiveDevice
->MarkAsActiveSource();
598 if (device
->TransmitSetSystemAudioMode(command
.initiator
, true))
599 return COMMAND_HANDLED
;
603 device
->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF
);
604 if (device
->TransmitSetSystemAudioMode(command
.initiator
, true))
605 return COMMAND_HANDLED
;
610 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
613 int CCECCommandHandler::HandleStandby(const cec_command
&command
)
615 CCECBusDevice
*device
= GetDevice(command
.initiator
);
617 device
->SetPowerStatus(CEC_POWER_STATUS_STANDBY
);
619 return COMMAND_HANDLED
;
622 int CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command
&command
)
624 if (command
.parameters
.size
== 1)
626 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.initiator
));
629 device
->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
630 return COMMAND_HANDLED
;
634 return CEC_ABORT_REASON_INVALID_OPERAND
;
637 int CCECCommandHandler::HandleSetSystemAudioMode(const cec_command
&command
)
639 if (command
.parameters
.size
== 1)
641 CCECAudioSystem
*device
= CCECBusDevice::AsAudioSystem(GetDevice(command
.initiator
));
644 device
->SetSystemAudioModeStatus((cec_system_audio_status
)command
.parameters
[0]);
645 return COMMAND_HANDLED
;
649 return CEC_ABORT_REASON_INVALID_OPERAND
;
652 int CCECCommandHandler::HandleTextViewOn(const cec_command
&command
)
654 m_processor
->GetDevice(command
.initiator
)->MarkAsActiveSource();
655 return COMMAND_HANDLED
;
658 int CCECCommandHandler::HandleUserControlPressed(const cec_command
&command
)
660 if (!m_processor
->CECInitialised() ||
661 !m_processor
->IsHandledByLibCEC(command
.destination
))
662 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
664 if (command
.parameters
.size
== 0)
665 return CEC_ABORT_REASON_INVALID_OPERAND
;
667 CCECBusDevice
*device
= GetDevice(command
.destination
);
669 return CEC_ABORT_REASON_INVALID_OPERAND
;
671 CCECClient
*client
= device
->GetClient();
673 client
->SetCurrentButton((cec_user_control_code
) command
.parameters
[0]);
675 if (command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER
||
676 command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION
)
680 // CEC_USER_CONTROL_CODE_POWER operates as a toggle
681 // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not
682 if (command
.parameters
[0] == CEC_USER_CONTROL_CODE_POWER
)
684 cec_power_status status
= device
->GetCurrentPowerStatus();
685 bPowerOn
= !(status
== CEC_POWER_STATUS_ON
|| status
== CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
);
690 device
->ActivateSource();
694 device
->MarkAsInactiveSource();
695 device
->TransmitInactiveSource();
696 device
->SetMenuState(CEC_MENU_STATE_DEACTIVATED
);
700 return COMMAND_HANDLED
;
703 int CCECCommandHandler::HandleUserControlRelease(const cec_command
&command
)
705 if (!m_processor
->CECInitialised() ||
706 !m_processor
->IsHandledByLibCEC(command
.destination
))
707 return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND
;
709 CCECClient
*client
= m_processor
->GetClient(command
.destination
);
713 return COMMAND_HANDLED
;
716 int CCECCommandHandler::HandleVendorCommand(const cec_command
& UNUSED(command
))
718 return CEC_ABORT_REASON_INVALID_OPERAND
;
721 int CCECCommandHandler::HandleVendorRemoteButtonDown(const cec_command
& command
)
723 if (command
.parameters
.size
== 0)
724 return CEC_ABORT_REASON_INVALID_OPERAND
;
726 LIB_CEC
->AddLog(CEC_LOG_NOTICE
, "unhandled vendor remote button received with keycode %x", command
.parameters
[0]);
727 return COMMAND_HANDLED
;
730 void CCECCommandHandler::UnhandledCommand(const cec_command
&command
, const cec_abort_reason reason
)
732 if (m_processor
->IsHandledByLibCEC(command
.destination
))
734 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "sending abort with opcode %02x and reason '%s' to %s", command
.opcode
, ToString(reason
), ToString(command
.initiator
));
735 m_processor
->TransmitAbort(command
.destination
, command
.initiator
, command
.opcode
, reason
);
739 size_t CCECCommandHandler::GetMyDevices(vector
<CCECBusDevice
*> &devices
) const
743 cec_logical_addresses addresses
= m_processor
->GetLogicalAddresses();
744 for (uint8_t iPtr
= CECDEVICE_TV
; iPtr
< CECDEVICE_BROADCAST
; iPtr
++)
748 devices
.push_back(GetDevice((cec_logical_address
) iPtr
));
756 CCECBusDevice
*CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress
) const
758 return m_processor
->GetDevice(iLogicalAddress
);
761 CCECBusDevice
*CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
) const
763 return m_processor
->GetDeviceByPhysicalAddress(iPhysicalAddress
);
766 bool CCECCommandHandler::SetVendorId(const cec_command
&command
)
768 bool bChanged(false);
769 if (command
.parameters
.size
< 3)
771 LIB_CEC
->AddLog(CEC_LOG_WARNING
, "invalid vendor ID received");
775 uint64_t iVendorId
= ((uint64_t)command
.parameters
[0] << 16) +
776 ((uint64_t)command
.parameters
[1] << 8) +
777 (uint64_t)command
.parameters
[2];
779 CCECBusDevice
*device
= GetDevice((cec_logical_address
) command
.initiator
);
781 bChanged
= device
->SetVendorId(iVendorId
);
785 void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress
, uint16_t iNewAddress
)
787 if (!m_processor
->IsHandledByLibCEC(iAddress
))
789 CCECBusDevice
*otherDevice
= m_processor
->GetDeviceByPhysicalAddress(iNewAddress
);
790 CCECClient
*client
= otherDevice
? otherDevice
->GetClient() : NULL
;
792 CCECBusDevice
*device
= m_processor
->GetDevice(iAddress
);
794 device
->SetPhysicalAddress(iNewAddress
);
797 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "device with logical address %X not found", iAddress
);
800 /* another device reported the same physical address as ours */
802 client
->ResetPhysicalAddress();
806 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
);
810 bool CCECCommandHandler::PowerOn(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
812 if (iDestination
== CECDEVICE_TV
)
813 return TransmitImageViewOn(iInitiator
, iDestination
);
815 return TransmitKeypress(iInitiator
, iDestination
, CEC_USER_CONTROL_CODE_POWER
) &&
816 TransmitKeyRelease(iInitiator
, iDestination
);
819 bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
822 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_IMAGE_VIEW_ON
);
824 if (Transmit(command
, false, false))
826 CCECBusDevice
* dest
= m_processor
->GetDevice(iDestination
);
827 if (dest
&& dest
->GetCurrentPowerStatus() != CEC_POWER_STATUS_ON
)
828 dest
->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
);
834 bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator
, const cec_logical_address iDestination
)
837 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_STANDBY
);
839 return Transmit(command
, false, false);
842 bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator
, bool bWaitForResponse
/* = true */)
845 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_REQUEST_ACTIVE_SOURCE
);
847 return Transmit(command
, !bWaitForResponse
, false);
850 bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
853 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_CEC_VERSION
);
855 return Transmit(command
, !bWaitForResponse
, false);
858 bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
861 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GET_MENU_LANGUAGE
);
863 return Transmit(command
, !bWaitForResponse
, false);
866 bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
869 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_OSD_NAME
);
871 return Transmit(command
, !bWaitForResponse
, false);
874 bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
877 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
);
879 return Transmit(command
, !bWaitForResponse
, false);
882 bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
884 if (iDestination
== CECDEVICE_TV
)
886 int64_t now(GetTimeMs());
887 if (now
- m_iPowerStatusRequested
< REQUEST_POWER_STATUS_TIMEOUT
)
889 m_iPowerStatusRequested
= now
;
892 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "<< requesting power status of '%s' (%X)", m_busDevice
->GetLogicalAddressName(), iDestination
);
895 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
);
897 return Transmit(command
, !bWaitForResponse
, false);
900 bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWaitForResponse
/* = true */)
903 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
);
905 return Transmit(command
, !bWaitForResponse
, false);
908 bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
, bool bIsReply
)
911 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_ACTIVE_SOURCE
);
912 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
913 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
915 return Transmit(command
, false, bIsReply
);
918 bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_version cecVersion
, bool bIsReply
)
921 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_CEC_VERSION
);
922 command
.parameters
.PushBack((uint8_t)cecVersion
);
924 return Transmit(command
, false, bIsReply
);
927 bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
)
930 cec_command::Format(command
, iInitiator
, CECDEVICE_TV
, CEC_OPCODE_INACTIVE_SOURCE
);
931 command
.parameters
.PushBack((iPhysicalAddress
>> 8) & 0xFF);
932 command
.parameters
.PushBack(iPhysicalAddress
& 0xFF);
934 return Transmit(command
, false, false);
937 bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_menu_state menuState
, bool bIsReply
)
940 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_MENU_STATUS
);
941 command
.parameters
.PushBack((uint8_t)menuState
);
943 return Transmit(command
, false, bIsReply
);
946 bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, std::string strDeviceName
, bool bIsReply
)
949 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_NAME
);
950 for (size_t iPtr
= 0; iPtr
< strDeviceName
.length(); iPtr
++)
951 command
.parameters
.PushBack(strDeviceName
.at(iPtr
));
953 return Transmit(command
, false, bIsReply
);
956 bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_display_control duration
, const char *strMessage
, bool bIsReply
)
959 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_OSD_STRING
);
960 command
.parameters
.PushBack((uint8_t)duration
);
962 size_t iLen
= strlen(strMessage
);
963 if (iLen
> 13) iLen
= 13;
965 for (size_t iPtr
= 0; iPtr
< iLen
; iPtr
++)
966 command
.parameters
.PushBack(strMessage
[iPtr
]);
968 return Transmit(command
, false, bIsReply
);
971 bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator
, uint16_t iPhysicalAddress
, cec_device_type type
, bool bIsReply
)
974 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
);
975 command
.parameters
.PushBack((uint8_t) ((iPhysicalAddress
>> 8) & 0xFF));
976 command
.parameters
.PushBack((uint8_t) (iPhysicalAddress
& 0xFF));
977 command
.parameters
.PushBack((uint8_t) (type
));
979 return Transmit(command
, false, bIsReply
);
982 bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator
, const char lang
[3], bool bIsReply
)
985 command
.Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_SET_MENU_LANGUAGE
);
986 command
.parameters
.PushBack((uint8_t) lang
[0]);
987 command
.parameters
.PushBack((uint8_t) lang
[1]);
988 command
.parameters
.PushBack((uint8_t) lang
[2]);
990 return Transmit(command
, false, bIsReply
);
993 bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bIsReply
)
996 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_NONE
);
998 return Transmit(command
, false, bIsReply
);
1001 bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_power_status state
, bool bIsReply
)
1003 cec_command command
;
1004 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_POWER_STATUS
);
1005 command
.parameters
.PushBack((uint8_t) state
);
1007 return Transmit(command
, false, bIsReply
);
1010 bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator
, uint64_t iVendorId
, bool bIsReply
)
1012 cec_command command
;
1013 cec_command::Format(command
, iInitiator
, CECDEVICE_BROADCAST
, CEC_OPCODE_DEVICE_VENDOR_ID
);
1015 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 16) & 0xFF));
1016 command
.parameters
.PushBack((uint8_t) (((uint64_t)iVendorId
>> 8) & 0xFF));
1017 command
.parameters
.PushBack((uint8_t) ((uint64_t)iVendorId
& 0xFF));
1019 return Transmit(command
, false, bIsReply
);
1022 bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, uint8_t state
, bool bIsReply
)
1024 cec_command command
;
1025 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_REPORT_AUDIO_STATUS
);
1026 command
.parameters
.PushBack(state
);
1028 return Transmit(command
, false, bIsReply
);
1031 bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
, bool bIsReply
)
1033 cec_command command
;
1034 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
);
1035 command
.parameters
.PushBack((uint8_t)state
);
1037 return Transmit(command
, false, bIsReply
);
1040 bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath
, bool bIsReply
)
1042 if (m_busDevice
->GetLogicalAddress() != CECDEVICE_TV
)
1044 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "only the TV is allowed to send CEC_OPCODE_SET_STREAM_PATH");
1047 cec_command command
;
1048 cec_command::Format(command
, m_busDevice
->GetLogicalAddress(), CECDEVICE_BROADCAST
, CEC_OPCODE_SET_STREAM_PATH
);
1049 command
.parameters
.PushBack((uint8_t) ((iStreamPath
>> 8) & 0xFF));
1050 command
.parameters
.PushBack((uint8_t) (iStreamPath
& 0xFF));
1052 return Transmit(command
, false, bIsReply
);
1055 bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_system_audio_status state
, bool bIsReply
)
1057 cec_command command
;
1058 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
);
1059 command
.parameters
.PushBack((uint8_t)state
);
1061 return Transmit(command
, false, bIsReply
);
1064 bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_deck_info state
, bool bIsReply
)
1066 cec_command command
;
1067 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_DECK_STATUS
);
1068 command
.PushBack((uint8_t)state
);
1070 return Transmit(command
, false, bIsReply
);
1073 bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = true */)
1075 cec_command command
;
1076 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_PRESSED
);
1077 command
.parameters
.PushBack((uint8_t)key
);
1079 return Transmit(command
, !bWait
, false);
1082 bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator
, const cec_logical_address iDestination
, bool bWait
/* = true */)
1084 cec_command command
;
1085 cec_command::Format(command
, iInitiator
, iDestination
, CEC_OPCODE_USER_CONTROL_RELEASE
);
1087 return Transmit(command
, !bWait
, false);
1090 bool CCECCommandHandler::Transmit(cec_command
&command
, bool bSuppressWait
, bool bIsReply
)
1092 bool bReturn(false);
1093 cec_opcode
expectedResponse(cec_command::GetResponseOpcode(command
.opcode
));
1094 bool bExpectResponse(expectedResponse
!= CEC_OPCODE_NONE
&& !bSuppressWait
);
1095 command
.transmit_timeout
= m_iTransmitTimeout
;
1097 if (command
.initiator
== CECDEVICE_UNKNOWN
)
1099 LIB_CEC
->AddLog(CEC_LOG_ERROR
, "not transmitting a command without a valid initiator");
1103 // check whether the destination is not marked as not present or handled by libCEC
1104 if (command
.destination
!= CECDEVICE_BROADCAST
&& command
.opcode_set
)
1106 CCECBusDevice
* destinationDevice
= m_processor
->GetDevice(command
.destination
);
1107 cec_bus_device_status status
= destinationDevice
? destinationDevice
->GetStatus() : CEC_DEVICE_STATUS_NOT_PRESENT
;
1108 if (status
== CEC_DEVICE_STATUS_NOT_PRESENT
)
1110 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "not sending command '%s': destination device '%s' marked as not present", ToString(command
.opcode
),ToString(command
.destination
));
1113 else if (status
== CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC
)
1115 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "not sending command '%s': destination device '%s' marked as handled by libCEC", ToString(command
.opcode
),ToString(command
.destination
));
1121 uint8_t iTries(0), iMaxTries(!command
.opcode_set
? 1 : m_iTransmitRetries
+ 1);
1122 while (!bReturn
&& ++iTries
<= iMaxTries
&& !m_busDevice
->IsUnsupportedFeature(command
.opcode
))
1124 if ((bReturn
= m_processor
->Transmit(command
, bIsReply
)) == true)
1126 #ifdef CEC_DEBUGGING
1127 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "command transmitted");
1129 if (bExpectResponse
)
1131 bReturn
= m_busDevice
->WaitForOpcode(expectedResponse
);
1132 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, bReturn
? "expected response received (%X: %s)" : "expected response not received (%X: %s)", (int)expectedResponse
, ToString(expectedResponse
));
1141 bool CCECCommandHandler::ActivateSource(bool bTransmitDelayedCommandsOnly
/* = false */)
1143 if (m_busDevice
->IsActiveSource() &&
1144 m_busDevice
->IsHandledByLibCEC())
1147 CLockObject
lock(m_mutex
);
1148 // check if we need to send a delayed source switch
1149 if (bTransmitDelayedCommandsOnly
)
1151 if (m_iActiveSourcePending
== 0 || GetTimeMs() < m_iActiveSourcePending
)
1154 #ifdef CEC_DEBUGGING
1155 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "transmitting delayed activate source command");
1160 // update the power state and menu state
1161 if (!bTransmitDelayedCommandsOnly
)
1163 m_busDevice
->SetPowerStatus(CEC_POWER_STATUS_ON
);
1164 m_busDevice
->SetMenuState(CEC_MENU_STATE_ACTIVATED
);
1167 // vendor specific hook
1168 VendorPreActivateSourceHook();
1171 CCECBusDevice
* tv
= m_processor
->GetDevice(CECDEVICE_TV
);
1172 bool bTvPresent
= (tv
&& tv
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
);
1173 bool bActiveSourceFailed(false);
1176 if (tv
->GetCurrentPowerStatus() != CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
)
1177 bActiveSourceFailed
= !m_busDevice
->TransmitImageViewOn();
1180 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "TV not present, not sending 'image view on'");
1182 // check if we're allowed to switch sources
1183 bool bSourceSwitchAllowed
= SourceSwitchAllowed();
1184 if (!bSourceSwitchAllowed
)
1185 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "source switch is currently not allowed by command handler");
1187 // switch sources (if allowed)
1188 if (!bActiveSourceFailed
&& bSourceSwitchAllowed
)
1190 bActiveSourceFailed
= !m_busDevice
->TransmitActiveSource(false);
1191 if (bTvPresent
&& !bActiveSourceFailed
)
1192 bActiveSourceFailed
= !m_busDevice
->TransmitMenuState(CECDEVICE_TV
, false);
1194 // update the deck status for playback devices
1195 if (bTvPresent
&& !bActiveSourceFailed
)
1197 CCECPlaybackDevice
*playbackDevice
= m_busDevice
->AsPlaybackDevice();
1198 if (playbackDevice
&& SendDeckStatusUpdateOnActiveSource())
1199 bActiveSourceFailed
= !playbackDevice
->TransmitDeckStatus(CECDEVICE_TV
, false);
1204 if (bActiveSourceFailed
|| !bSourceSwitchAllowed
)
1206 LIB_CEC
->AddLog(CEC_LOG_DEBUG
, "failed to make '%s' the active source. will retry later", m_busDevice
->GetLogicalAddressName());
1207 int64_t now(GetTimeMs());
1208 CLockObject
lock(m_mutex
);
1209 if (m_iActiveSourcePending
== 0 || m_iActiveSourcePending
< now
)
1210 m_iActiveSourcePending
= now
+ (int64_t)CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS
;
1215 CLockObject
lock(m_mutex
);
1216 // clear previous pending active source command
1217 m_iActiveSourcePending
= 0;
1220 // mark the handler as initialised
1221 CLockObject
lock(m_mutex
);
1222 m_bHandlerInited
= true;
1227 void CCECCommandHandler::ScheduleActivateSource(uint64_t iDelay
)
1229 CLockObject
lock(m_mutex
);
1230 m_iActiveSourcePending
= GetTimeMs() + iDelay
;