X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FCECCommandHandler.cpp;h=40d7ec37425a26ded517d2c96f3829c2a62ccb8b;hb=65108638b4d86198e03bc709a8a51a4658aef160;hp=ad4349efb608141e6df52aac04216daac46e3fff;hpb=004b83822a351e1fb6e982a9183a12a430b0b769;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index ad4349e..40d7ec3 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -221,10 +221,10 @@ bool CCECCommandHandler::HandleActiveSource(const cec_command &command) bool CCECCommandHandler::HandleDeckControl(const cec_command &command) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0) + CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); + if (device && command.parameters.size > 0) { - ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); + device->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); return true; } @@ -245,8 +245,8 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) - m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) + m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); return true; } @@ -267,7 +267,7 @@ bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -279,11 +279,11 @@ bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) - return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator); + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); + if (device) + return device->TransmitAudioStatus(command.initiator); } return false; @@ -291,11 +291,11 @@ bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) - return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); + CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); + if (device) + return device->TransmitDeckStatus(command.initiator); } return false; @@ -303,7 +303,7 @@ bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -315,7 +315,7 @@ bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -327,7 +327,7 @@ bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -339,7 +339,7 @@ bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -351,7 +351,7 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -363,11 +363,11 @@ bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) - return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator); + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); + if (device) + return device->TransmitSystemAudioModeStatus(command.initiator); } return false; @@ -381,7 +381,7 @@ bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); if (device) @@ -417,10 +417,10 @@ bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) { if (command.parameters.size == 1) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); + if (device) { - ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]); + device->SetAudioStatus(command.parameters[0]); return true; } } @@ -450,7 +450,7 @@ bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) { - if (m_processor->IsRunning()) + if (m_processor->CECInitialised()) { LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator); m_processor->GetDevice(command.initiator)->SetPowerStatus(CEC_POWER_STATUS_ON); @@ -533,7 +533,7 @@ bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) { - if (m_processor->IsRunning() && command.parameters.size >= 2) + if (m_processor->CECInitialised() && command.parameters.size >= 2) { uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); @@ -548,25 +548,25 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); + if (device) { if (command.parameters.size >= 2) { device->SetPowerStatus(CEC_POWER_STATUS_ON); - ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); + device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); if (newActiveDevice) newActiveDevice->MarkAsActiveSource(); - return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + return device->TransmitSetSystemAudioMode(command.initiator); } else { - ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); - return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); + return device->TransmitSetSystemAudioMode(command.initiator); } } } @@ -586,10 +586,10 @@ bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) { if (command.parameters.size == 1) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); + if (device) { - ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); return true; } } @@ -601,10 +601,10 @@ bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) { if (command.parameters.size == 1) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); + if (device) { - ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); return true; } } @@ -620,7 +620,7 @@ bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { - if (m_processor->IsRunning() && + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination) && command.parameters.size > 0) { @@ -684,7 +684,7 @@ void CCECCommandHandler::UnhandledCommand(const cec_command &command) { LIB_CEC->AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); } @@ -738,21 +738,24 @@ void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16 { if (!m_processor->IsHandledByLibCEC(iAddress)) { - CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); - bool bOurAddress(device && device->GetLogicalAddress() != m_busDevice->GetLogicalAddress() && - device->IsHandledByLibCEC()); - - GetDevice(iAddress)->SetPhysicalAddress(iNewAddress); + CCECBusDevice *otherDevice = m_processor->GetDeviceByPhysicalAddress(iNewAddress); + CCECClient *client = otherDevice ? otherDevice->GetClient() : NULL; - if (bOurAddress) + CCECBusDevice *device = m_processor->GetDevice(iAddress); + if (device) + device->SetPhysicalAddress(iNewAddress); + else { - /* another device reported the same physical address as ours - * since we don't have physical address detection yet, we'll just use the - * given address, increased by 0x100 for now */ - CCECClient *client = device->GetClient(); - if (client) - client->SetPhysicalAddress(iNewAddress + 0x100); + LIB_CEC->AddLog(CEC_LOG_DEBUG, "device with logical address %X not found", iAddress); } + + /* another device reported the same physical address as ours */ + if (client) + client->ResetPhysicalAddress(); + } + else + { + 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); } } @@ -1057,10 +1060,10 @@ bool CCECCommandHandler::ActivateSource(void) m_busDevice->TransmitImageViewOn(); m_busDevice->TransmitActiveSource(); m_busDevice->TransmitMenuState(CECDEVICE_TV); - if ((m_busDevice->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || - m_busDevice->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && - SendDeckStatusUpdateOnActiveSource()) - ((CCECPlaybackDevice *)m_busDevice)->TransmitDeckStatus(CECDEVICE_TV); + + CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice(); + if (playbackDevice && SendDeckStatusUpdateOnActiveSource()) + playbackDevice->TransmitDeckStatus(CECDEVICE_TV); m_bHandlerInited = true; } return true;