2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 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/
33 #include "CECProcessor.h"
35 #include "AdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
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"
42 #include "implementations/CECCommandHandler.h"
44 #include "util/StdString.h"
45 #include "platform/timeutils.h"
50 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, cec_logical_address iLogicalAddress
/* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
52 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
53 m_iBaseDevice((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
),
54 m_strDeviceName(strDeviceName
),
55 m_communication(serComm
),
56 m_controller(controller
),
60 m_logicalAddresses
.Clear();
61 m_logicalAddresses
.Set(iLogicalAddress
);
63 for (int iPtr
= 0; iPtr
<= 16; iPtr
++)
64 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, iPtr
== iLogicalAddress
? iPhysicalAddress
: 0);
67 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, const cec_device_type_list
&types
) :
69 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
70 m_iBaseDevice((cec_logical_address
)CEC_DEFAULT_BASE_DEVICE
),
71 m_strDeviceName(strDeviceName
),
73 m_communication(serComm
),
74 m_controller(controller
),
77 m_logicalAddresses
.Clear();
78 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
82 case CECDEVICE_AUDIOSYSTEM
:
83 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
85 case CECDEVICE_PLAYBACKDEVICE1
:
86 case CECDEVICE_PLAYBACKDEVICE2
:
87 case CECDEVICE_PLAYBACKDEVICE3
:
88 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
90 case CECDEVICE_RECORDINGDEVICE1
:
91 case CECDEVICE_RECORDINGDEVICE2
:
92 case CECDEVICE_RECORDINGDEVICE3
:
93 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
95 case CECDEVICE_TUNER1
:
96 case CECDEVICE_TUNER2
:
97 case CECDEVICE_TUNER3
:
98 case CECDEVICE_TUNER4
:
99 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
102 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
105 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
111 CCECProcessor::~CCECProcessor(void)
115 m_busScan
->StopThread();
119 m_startCondition
.Broadcast();
122 m_communication
= NULL
;
124 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
125 delete m_busDevices
[iPtr
];
128 bool CCECProcessor::Start(void)
130 CLockObject
lock(&m_mutex
);
131 if (!m_communication
|| !m_communication
->IsOpen())
133 m_controller
->AddLog(CEC_LOG_ERROR
, "connection is closed");
139 if (!m_startCondition
.Wait(&m_mutex
) || !m_bStarted
)
141 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
146 if (SetAckMask(m_logicalAddresses
.AckMask()) &&
147 SetHDMIPort(m_iBaseDevice
, m_iHDMIPort
, true))
149 m_busScan
= new CCECBusScan(this);
150 m_busScan
->CreateThread(true);
155 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
160 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
162 if (m_busDevices
[address
]->TryLogicalAddress())
164 /* only set our OSD name and active source for the primary device */
165 if (m_logicalAddresses
.IsEmpty())
167 m_busDevices
[address
]->m_strDeviceName
= m_strDeviceName
;
168 m_busDevices
[address
]->m_bActiveSource
= true;
170 m_logicalAddresses
.Set(address
);
177 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
179 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
180 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
181 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
182 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
185 bool CCECProcessor::FindLogicalAddressTuner(void)
187 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
188 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
189 TryLogicalAddress(CECDEVICE_TUNER2
) ||
190 TryLogicalAddress(CECDEVICE_TUNER3
) ||
191 TryLogicalAddress(CECDEVICE_TUNER4
);
194 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
196 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
197 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
198 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
199 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
202 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
204 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
205 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
208 bool CCECProcessor::FindLogicalAddresses(void)
211 m_logicalAddresses
.Clear();
214 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
216 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
219 strLog
.Format("%s - device %d: type %d", __FUNCTION__
, iPtr
, m_types
.types
[iPtr
]);
220 AddLog(CEC_LOG_DEBUG
, strLog
);
222 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
223 bReturn
&= FindLogicalAddressRecordingDevice();
224 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
225 bReturn
&= FindLogicalAddressTuner();
226 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
227 bReturn
&= FindLogicalAddressPlaybackDevice();
228 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
229 bReturn
&= FindLogicalAddressAudioSystem();
235 void *CCECProcessor::Process(void)
237 bool bParseFrame(false);
239 CCECAdapterMessage msg
;
241 if (m_logicalAddresses
.IsEmpty() && !FindLogicalAddresses())
243 CLockObject
lock(&m_mutex
);
244 m_controller
->AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
245 m_startCondition
.Signal();
250 CLockObject
lock(&m_mutex
);
252 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
253 m_startCondition
.Signal();
262 CLockObject
lock(&m_mutex
);
263 if (m_commandBuffer
.Pop(command
))
267 else if (m_communication
->IsOpen() && m_communication
->Read(msg
, 50))
269 m_controller
->AddLog(msg
.is_error() ? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
270 if ((bParseFrame
= (ParseMessage(msg
) && !IsStopped())) == true)
271 command
= m_currentframe
;
276 ParseCommand(command
);
281 m_controller
->CheckKeypressTimeout();
287 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
294 cec_logical_address addr
= m_logicalAddresses
.primary
;
296 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
298 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
300 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
302 addr
= (cec_logical_address
) iPtr
;
308 return SetStreamPath(m_busDevices
[addr
]->GetPhysicalAddress(false)) &&
309 m_busDevices
[addr
]->TransmitActiveSource();
312 bool CCECProcessor::SetActiveSource(cec_logical_address iAddress
)
314 return SetStreamPath(m_busDevices
[iAddress
]->GetPhysicalAddress(false));
317 bool CCECProcessor::SetActiveView(void)
319 return SetActiveSource(m_types
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_types
[0]);
322 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
326 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
329 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
331 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
338 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
342 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
345 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
347 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
354 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice
, uint8_t iPort
, bool bForce
/* = false */)
359 strLog
.Format("setting HDMI port to %d on device %s (%d)", iPort
, ToString(iBaseDevice
), (int)iBaseDevice
);
360 AddLog(CEC_LOG_DEBUG
, strLog
);
362 m_iBaseDevice
= iBaseDevice
;
364 if (!m_bStarted
&& !bForce
)
367 uint16_t iPhysicalAddress(0);
368 iPhysicalAddress
= m_busDevices
[iBaseDevice
]->GetPhysicalAddress();
370 if (iPhysicalAddress
== 0)
372 else if (iPhysicalAddress
% 0x1000 == 0)
374 else if (iPhysicalAddress
% 0x100 == 0)
376 else if (iPhysicalAddress
% 0x10 == 0)
379 while(!bReturn
&& iPos
> 0)
381 iPhysicalAddress
+= (uint16_t)(iPort
* iPos
);
382 strLog
.Format("checking physical address %4x", iPhysicalAddress
);
383 AddLog(CEC_LOG_DEBUG
, strLog
);
384 if (CheckPhysicalAddress(iPhysicalAddress
))
386 strLog
.Format("physical address %4x is in use", iPhysicalAddress
);
387 AddLog(CEC_LOG_DEBUG
, strLog
);
388 iPos
= (iPos
== 1) ? 0 : iPos
/ 0x10;
392 SetPhysicalAddress(iPhysicalAddress
);
400 bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress
)
402 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
404 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
410 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath
)
414 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
417 device
->SetActiveDevice();
424 bool CCECProcessor::TransmitInactiveSource(void)
429 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
430 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
434 void CCECProcessor::LogOutput(const cec_command
&data
)
437 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
439 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
441 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
442 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
443 m_controller
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
446 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
448 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
451 strLog
.Format("<< setting primary logical address to %1x", iLogicalAddress
);
452 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
453 m_logicalAddresses
.primary
= iLogicalAddress
;
454 m_logicalAddresses
.Set(iLogicalAddress
);
455 return SetAckMask(m_logicalAddresses
.AckMask());
461 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
463 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
465 if (m_logicalAddresses
[iPtr
])
466 m_busDevices
[iPtr
]->SetMenuState(state
);
470 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
475 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
)
477 if (!m_logicalAddresses
.IsEmpty())
479 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
480 if (m_logicalAddresses
[iPtr
])
481 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
482 return SetActiveView();
487 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
490 strLog
.Format("== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
491 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
493 m_bMonitor
= bEnable
;
495 return SetAckMask(0);
497 return SetAckMask(m_logicalAddresses
.AckMask());
500 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
502 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
504 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
505 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
506 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
511 uint8_t CCECProcessor::VolumeUp(bool bWait
/* = true */)
514 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
515 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bWait
);
520 uint8_t CCECProcessor::VolumeDown(bool bWait
/* = true */)
523 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
524 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bWait
);
529 uint8_t CCECProcessor::MuteAudio(bool bWait
/* = true */)
532 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
533 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bWait
);
538 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
540 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
541 return m_busDevices
[m_logicalAddresses
.primary
];
543 CCECBusDevice
*device
= NULL
;
544 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
546 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
548 device
= m_busDevices
[iPtr
];
556 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
558 CCECBusDevice
*device
= NULL
;
560 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
562 if (m_busDevices
[iPtr
]->m_type
== type
)
564 device
= m_busDevices
[iPtr
];
572 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
574 return m_busDevices
[iAddress
]->GetCecVersion();
577 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
579 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
582 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
583 retVal
.device
= iAddress
;
588 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
590 if (m_busDevices
[iAddress
])
592 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
593 return (strcmp(language
->language
, "???") != 0);
598 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
600 if (m_busDevices
[iAddress
])
601 return m_busDevices
[iAddress
]->GetVendorId();
605 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
607 if (m_busDevices
[iAddress
])
608 return m_busDevices
[iAddress
]->GetPowerStatus();
609 return CEC_POWER_STATUS_UNKNOWN
;
612 bool CCECProcessor::Transmit(const cec_command
&data
)
617 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
);
618 bReturn
= Transmit(output
);
624 bool CCECProcessor::Transmit(CCECAdapterMessage
*output
)
627 CLockObject
lock(&m_mutex
);
629 CLockObject
msgLock(&output
->mutex
);
630 if (!m_communication
|| !m_communication
->Write(output
))
634 output
->condition
.Wait(&output
->mutex
);
635 if (output
->state
!= ADAPTER_MESSAGE_STATE_SENT
)
637 m_controller
->AddLog(CEC_LOG_ERROR
, "command was not sent");
642 if (output
->transmit_timeout
> 0)
644 if ((bReturn
= WaitForTransmitSucceeded(output
->size(), output
->transmit_timeout
)) == false)
645 m_controller
->AddLog(CEC_LOG_DEBUG
, "did not receive ack");
654 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
656 m_controller
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
660 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
661 command
.parameters
.PushBack((uint8_t)opcode
);
662 command
.parameters
.PushBack((uint8_t)reason
);
667 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength
, uint32_t iTimeout
/* = 1000 */)
670 bool bTransmitSucceeded(false);
671 uint8_t iPacketsLeft(iLength
/ 4);
673 int64_t iNow
= GetTimeMs();
674 int64_t iTargetTime
= iNow
+ (uint64_t) iTimeout
;
676 while (!bTransmitSucceeded
&& !bError
&& (iTimeout
== 0 || iNow
< iTargetTime
))
678 CCECAdapterMessage msg
;
680 if (!m_communication
->Read(msg
, iTimeout
> 0 ? (int32_t)(iTargetTime
- iNow
) : 1000))
686 if ((bError
= msg
.is_error()) == false)
688 m_controller
->AddLog(bError
? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
690 switch(msg
.message())
692 case MSGCODE_COMMAND_ACCEPTED
:
693 if (iPacketsLeft
> 0)
696 case MSGCODE_TRANSMIT_SUCCEEDED
:
697 bTransmitSucceeded
= (iPacketsLeft
== 0);
698 bError
= !bTransmitSucceeded
;
701 if (ParseMessage(msg
))
702 m_commandBuffer
.Push(m_currentframe
);
709 return bTransmitSucceeded
&& !bError
;
712 bool CCECProcessor::ParseMessage(const CCECAdapterMessage
&msg
)
719 switch(msg
.message())
721 case MSGCODE_FRAME_START
:
723 m_currentframe
.Clear();
726 m_currentframe
.initiator
= msg
.initiator();
727 m_currentframe
.destination
= msg
.destination();
728 m_currentframe
.ack
= msg
.ack();
729 m_currentframe
.eom
= msg
.eom();
733 case MSGCODE_FRAME_DATA
:
737 m_currentframe
.PushBack(msg
[1]);
738 m_currentframe
.eom
= msg
.eom();
750 void CCECProcessor::ParseCommand(cec_command
&command
)
753 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
754 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
755 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
756 m_controller
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
758 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
759 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
762 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
764 cec_logical_addresses addresses
;
766 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
768 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
769 addresses
.Set((cec_logical_address
) iPtr
);
774 bool CCECProcessor::IsActiveDevice(cec_logical_address address
)
776 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
779 bool CCECProcessor::IsActiveDeviceType(cec_device_type type
)
781 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
783 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
790 uint16_t CCECProcessor::GetPhysicalAddress(void) const
792 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
793 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
797 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode
)
799 m_controller
->SetCurrentButton(iButtonCode
);
802 void CCECProcessor::AddCommand(const cec_command
&command
)
804 m_controller
->AddCommand(command
);
807 void CCECProcessor::AddKey(cec_keypress
&key
)
809 m_controller
->AddKey(key
);
812 void CCECProcessor::AddKey(void)
814 m_controller
->AddKey();
817 void CCECProcessor::AddLog(cec_log_level level
, const CStdString
&strMessage
)
819 m_controller
->AddLog(level
, strMessage
);
822 bool CCECProcessor::SetAckMask(uint16_t iMask
)
826 strLog
.Format("setting ackmask to %2x", iMask
);
827 m_controller
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
829 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
831 output
->push_back(MSGSTART
);
832 output
->push_escaped(MSGCODE_SET_ACK_MASK
);
833 output
->push_escaped(iMask
>> 8);
834 output
->push_escaped((uint8_t)iMask
);
835 output
->push_back(MSGEND
);
837 if ((bReturn
= Transmit(output
)) == false)
838 m_controller
->AddLog(CEC_LOG_ERROR
, "could not set the ackmask");
845 bool CCECProcessor::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = false */)
847 return m_busDevices
[iDestination
]->SendKeypress(key
, bWait
);
850 bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = false */)
852 return m_busDevices
[iDestination
]->SendKeyRelease(bWait
);
855 const char *CCECProcessor::ToString(const cec_menu_state state
)
859 case CEC_MENU_STATE_ACTIVATED
:
861 case CEC_MENU_STATE_DEACTIVATED
:
862 return "deactivated";
868 const char *CCECProcessor::ToString(const cec_version version
)
872 case CEC_VERSION_1_2
:
874 case CEC_VERSION_1_2A
:
876 case CEC_VERSION_1_3
:
878 case CEC_VERSION_1_3A
:
880 case CEC_VERSION_1_4
:
887 const char *CCECProcessor::ToString(const cec_power_status status
)
891 case CEC_POWER_STATUS_ON
:
893 case CEC_POWER_STATUS_STANDBY
:
895 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY
:
896 return "in transition from on to standby";
897 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON
:
898 return "in transition from standby to on";
904 const char *CCECProcessor::ToString(const cec_logical_address address
)
908 case CECDEVICE_AUDIOSYSTEM
:
910 case CECDEVICE_BROADCAST
:
912 case CECDEVICE_FREEUSE
:
914 case CECDEVICE_PLAYBACKDEVICE1
:
916 case CECDEVICE_PLAYBACKDEVICE2
:
918 case CECDEVICE_PLAYBACKDEVICE3
:
920 case CECDEVICE_RECORDINGDEVICE1
:
922 case CECDEVICE_RECORDINGDEVICE2
:
924 case CECDEVICE_RECORDINGDEVICE3
:
926 case CECDEVICE_RESERVED1
:
928 case CECDEVICE_RESERVED2
:
930 case CECDEVICE_TUNER1
:
932 case CECDEVICE_TUNER2
:
934 case CECDEVICE_TUNER3
:
936 case CECDEVICE_TUNER4
:
945 const char *CCECProcessor::ToString(const cec_deck_control_mode mode
)
949 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND
:
950 return "skip forward wind";
951 case CEC_DECK_CONTROL_MODE_EJECT
:
953 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND
:
954 return "reverse rewind";
955 case CEC_DECK_CONTROL_MODE_STOP
:
962 const char *CCECProcessor::ToString(const cec_deck_info status
)
966 case CEC_DECK_INFO_PLAY
:
968 case CEC_DECK_INFO_RECORD
:
970 case CEC_DECK_INFO_PLAY_REVERSE
:
971 return "play reverse";
972 case CEC_DECK_INFO_STILL
:
974 case CEC_DECK_INFO_SLOW
:
976 case CEC_DECK_INFO_SLOW_REVERSE
:
977 return "slow reverse";
978 case CEC_DECK_INFO_FAST_FORWARD
:
979 return "fast forward";
980 case CEC_DECK_INFO_FAST_REVERSE
:
981 return "fast reverse";
982 case CEC_DECK_INFO_NO_MEDIA
:
984 case CEC_DECK_INFO_STOP
:
986 case CEC_DECK_INFO_SKIP_FORWARD_WIND
:
987 return "info skip forward wind";
988 case CEC_DECK_INFO_SKIP_REVERSE_REWIND
:
989 return "info skip reverse rewind";
990 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD
:
991 return "info index search forward";
992 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE
:
993 return "info index search reverse";
994 case CEC_DECK_INFO_OTHER_STATUS
:
1001 const char *CCECProcessor::ToString(const cec_opcode opcode
)
1005 case CEC_OPCODE_ACTIVE_SOURCE
:
1006 return "active source";
1007 case CEC_OPCODE_IMAGE_VIEW_ON
:
1008 return "image view on";
1009 case CEC_OPCODE_TEXT_VIEW_ON
:
1010 return "text view on";
1011 case CEC_OPCODE_INACTIVE_SOURCE
:
1012 return "inactive source";
1013 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE
:
1014 return "request active source";
1015 case CEC_OPCODE_ROUTING_CHANGE
:
1016 return "routing change";
1017 case CEC_OPCODE_ROUTING_INFORMATION
:
1018 return "routing information";
1019 case CEC_OPCODE_SET_STREAM_PATH
:
1020 return "set stream path";
1021 case CEC_OPCODE_STANDBY
:
1023 case CEC_OPCODE_RECORD_OFF
:
1024 return "record off";
1025 case CEC_OPCODE_RECORD_ON
:
1027 case CEC_OPCODE_RECORD_STATUS
:
1028 return "record status";
1029 case CEC_OPCODE_RECORD_TV_SCREEN
:
1030 return "record tv screen";
1031 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER
:
1032 return "clear analogue timer";
1033 case CEC_OPCODE_CLEAR_DIGITAL_TIMER
:
1034 return "clear digital timer";
1035 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER
:
1036 return "clear external timer";
1037 case CEC_OPCODE_SET_ANALOGUE_TIMER
:
1038 return "set analogue timer";
1039 case CEC_OPCODE_SET_DIGITAL_TIMER
:
1040 return "set digital timer";
1041 case CEC_OPCODE_SET_EXTERNAL_TIMER
:
1042 return "set external timer";
1043 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE
:
1044 return "set timer program title";
1045 case CEC_OPCODE_TIMER_CLEARED_STATUS
:
1046 return "timer cleared status";
1047 case CEC_OPCODE_TIMER_STATUS
:
1048 return "timer status";
1049 case CEC_OPCODE_CEC_VERSION
:
1050 return "cec version";
1051 case CEC_OPCODE_GET_CEC_VERSION
:
1052 return "get cec version";
1053 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS
:
1054 return "give physical address";
1055 case CEC_OPCODE_GET_MENU_LANGUAGE
:
1056 return "get menu language";
1057 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS
:
1058 return "report physical address";
1059 case CEC_OPCODE_SET_MENU_LANGUAGE
:
1060 return "set menu language";
1061 case CEC_OPCODE_DECK_CONTROL
:
1062 return "deck control";
1063 case CEC_OPCODE_DECK_STATUS
:
1064 return "deck status";
1065 case CEC_OPCODE_GIVE_DECK_STATUS
:
1066 return "give deck status";
1067 case CEC_OPCODE_PLAY
:
1069 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS
:
1070 return "give tuner status";
1071 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE
:
1072 return "select analogue service";
1073 case CEC_OPCODE_SELECT_DIGITAL_SERVICE
:
1074 return "set digital service";
1075 case CEC_OPCODE_TUNER_DEVICE_STATUS
:
1076 return "tuner device status";
1077 case CEC_OPCODE_TUNER_STEP_DECREMENT
:
1078 return "tuner step decrement";
1079 case CEC_OPCODE_TUNER_STEP_INCREMENT
:
1080 return "tuner step increment";
1081 case CEC_OPCODE_DEVICE_VENDOR_ID
:
1082 return "device vendor id";
1083 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID
:
1084 return "give device vendor id";
1085 case CEC_OPCODE_VENDOR_COMMAND
:
1086 return "vendor command";
1087 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID
:
1088 return "vendor command with id";
1089 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN
:
1090 return "vendor remote button down";
1091 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP
:
1092 return "vendor remote button up";
1093 case CEC_OPCODE_SET_OSD_STRING
:
1094 return "set osd string";
1095 case CEC_OPCODE_GIVE_OSD_NAME
:
1096 return "give osd name";
1097 case CEC_OPCODE_SET_OSD_NAME
:
1098 return "set osd name";
1099 case CEC_OPCODE_MENU_REQUEST
:
1100 return "menu request";
1101 case CEC_OPCODE_MENU_STATUS
:
1102 return "menu status";
1103 case CEC_OPCODE_USER_CONTROL_PRESSED
:
1104 return "user control pressed";
1105 case CEC_OPCODE_USER_CONTROL_RELEASE
:
1106 return "user control release";
1107 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS
:
1108 return "give device power status";
1109 case CEC_OPCODE_REPORT_POWER_STATUS
:
1110 return "report power status";
1111 case CEC_OPCODE_FEATURE_ABORT
:
1112 return "feature abort";
1113 case CEC_OPCODE_ABORT
:
1115 case CEC_OPCODE_GIVE_AUDIO_STATUS
:
1116 return "give audio status";
1117 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS
:
1118 return "give audio mode status";
1119 case CEC_OPCODE_REPORT_AUDIO_STATUS
:
1120 return "report audio status";
1121 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE
:
1122 return "set system audio mode";
1123 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST
:
1124 return "system audio mode request";
1125 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS
:
1126 return "system audio mode status";
1127 case CEC_OPCODE_SET_AUDIO_RATE
:
1128 return "set audio rate";
1134 const char *CCECProcessor::ToString(const cec_system_audio_status mode
)
1138 case CEC_SYSTEM_AUDIO_STATUS_ON
:
1140 case CEC_SYSTEM_AUDIO_STATUS_OFF
:
1147 const char *CCECProcessor::ToString(const cec_audio_status status
)
1149 // TODO this is a mask
1153 const char *CCECProcessor::ToString(const cec_vendor_id vendor
)
1157 case CEC_VENDOR_SAMSUNG
:
1161 case CEC_VENDOR_PANASONIC
:
1163 case CEC_VENDOR_PIONEER
:
1165 case CEC_VENDOR_ONKYO
:
1167 case CEC_VENDOR_YAMAHA
:
1169 case CEC_VENDOR_PHILIPS
:
1176 void *CCECBusScan::Process(void)
1178 CCECBusDevice
*device(NULL
);
1179 while (!IsStopped())
1181 for (unsigned int iPtr
= 0; iPtr
< 15 && !IsStopped(); iPtr
++)
1183 device
= m_processor
->m_busDevices
[iPtr
];
1184 if (device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
1187 device
->GetPhysicalAddress(false);
1191 device
->GetCecVersion();
1195 device
->GetVendorId();