- if (m_busDevices[address]->TryLogicalAddress())
- {
- m_configuration.logicalAddresses.Set(address);
- return true;
- }
-
- return false;
-}
-
-bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
-{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
- return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
- TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
- TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
-}
-
-bool CCECProcessor::FindLogicalAddressTuner(void)
-{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
- return TryLogicalAddress(CECDEVICE_TUNER1) ||
- TryLogicalAddress(CECDEVICE_TUNER2) ||
- TryLogicalAddress(CECDEVICE_TUNER3) ||
- TryLogicalAddress(CECDEVICE_TUNER4);
-}
-
-bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
-{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
- return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
- TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
- TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
-}
-
-bool CCECProcessor::FindLogicalAddressAudioSystem(void)
-{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
- return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
-}
-
-bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
-{
- bool bChanged(false);
-
- CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to));
-
- CLockObject lock(m_mutex);
- CCECBusDevice *previousDevice = GetDeviceByType(from);
- m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
-
- for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
- {
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
- continue;
-
- if (m_configuration.deviceTypes.types[iPtr] == from)
- {
- bChanged = true;
- m_configuration.deviceTypes.types[iPtr] = to;
- }
- else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged)
- {
- m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
- }
- }
-
- if (bChanged)
- {
- FindLogicalAddresses();
-
- CCECBusDevice *newDevice = GetDeviceByType(to);
- if (previousDevice && newDevice)
- {
- newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
- previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
-
- newDevice->SetCecVersion(previousDevice->GetCecVersion(false));
- previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
-
- newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false));
-
- newDevice->SetMenuState(previousDevice->GetMenuState());
- previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
-
- newDevice->SetOSDName(previousDevice->GetOSDName(false));
- previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress()));
-
- newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false));
- previousDevice->SetPhysicalAddress(0xFFFF);
-
- newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false));
- previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN);
-
- newDevice->SetVendorId(previousDevice->GetVendorId(false));
- previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN);
-
- if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
- (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE))
- {
- ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode());
- ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP);
-
- ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus());
- ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP);
- }
- }
- }
-
- return true;
-}
-
-bool CCECProcessor::FindLogicalAddresses(void)
-{
- bool bReturn(true);
- m_configuration.logicalAddresses.Clear();
-
- if (m_configuration.deviceTypes.IsEmpty())
- {
- CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set");
- return false;
- }
-
- for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
- {
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
- continue;
-
- CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]);
-
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
- bReturn &= FindLogicalAddressRecordingDevice();
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
- bReturn &= FindLogicalAddressTuner();
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
- bReturn &= FindLogicalAddressPlaybackDevice();
- if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
- bReturn &= FindLogicalAddressAudioSystem();
- }
-
- if (bReturn)
- SetAckMask(m_configuration.logicalAddresses.AckMask());
-
- return bReturn;
-}
-
-void CCECProcessor::ReplaceHandlers(void)
-{
- if (!IsInitialised())
- return;
- for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
- m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
-}
-
-bool CCECProcessor::OnCommandReceived(const cec_command &command)
-{
- return m_inBuffer.Push(command);
-}
-
-void *CCECProcessor::Process(void)
-{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
-
- cec_command command;
- command.Clear();
-
- while (!IsStopped() && m_communication->IsOpen())
- {
- if (m_inBuffer.Pop(command, 500))
- ParseCommand(command);
-
- if (IsInitialised())
- {
- ReplaceHandlers();
-
- m_controller->CheckKeypressTimeout();
- }
- }
-
- return NULL;
-}
-
-bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
-{
- bool bReturn(false);
-
- if (!IsRunning())
- return bReturn;
-
- cec_logical_address addr = m_configuration.logicalAddresses.primary;
-
- if (type != CEC_DEVICE_TYPE_RESERVED)
- {
- for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
- {
- if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
- {
- addr = (cec_logical_address) iPtr;
- break;
- }
- }
- }
-
- m_busDevices[addr]->SetActiveSource();
- if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
- bReturn = m_busDevices[addr]->ActivateSource();
-
- return bReturn;
-}
-
-bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
-{
- bool bReturn(false);
-
- // suppress polls when searching for a device
- CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath, false, true);