X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=src%2Flib%2Fimplementations%2FCECCommandHandler.cpp;h=122c4be1c51e2eaedbc681b9c5b2a163992e67c2;hb=181b347542a6ed9dc1f9ea7bca2051c72b49a9df;hp=2324c2011d9664a04d361e3210398fcf00baaf16;hpb=29912296089b5266f2c7e49e621c135b9f023313;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 2324c20..122c4be 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -32,6 +32,7 @@ #include "CECCommandHandler.h" #include "../devices/CECBusDevice.h" +#include "../devices/CECAudioSystem.h" #include "../CECProcessor.h" using namespace CEC; @@ -92,6 +93,15 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) case CEC_OPCODE_USER_CONTROL_RELEASE: HandleUserControlRelease(command); break; + case CEC_OPCODE_GIVE_AUDIO_STATUS: + HandleGiveAudioStatus(command); + break; + case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: + HandleGiveSystemAudioModeStatus(command); + break; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: + HandleSetSystemAudioModeRequest(command); + break; default: UnhandledCommand(command); m_busDevice->GetProcessor()->AddCommand(command); @@ -157,19 +167,13 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device) - device->SetVendorId(command.parameters); - + SetVendorId(command); return true; } bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device) - device->SetVendorId(command.parameters); - + SetVendorId(command); return true; } @@ -182,6 +186,15 @@ bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) return false; } +bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) +{ + CCECBusDevice *device = GetDevice(command.destination); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator); + + return false; +} + bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) { CCECBusDevice *device = GetDevice(command.destination); @@ -269,7 +282,7 @@ bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) CCECBusDevice *device = GetDevice(command.initiator); if (device) - device->SetPhysicalAddress(iNewAddress, iOldAddress); + device->SetStreamPath(iNewAddress, iOldAddress); } return true; } @@ -300,17 +313,33 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) CStdString strLog; strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr); m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); - if (streamaddr == m_busDevice->GetMyPhysicalAddress()) - { - CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitActiveSource(); - return false; - } + CCECBusDevice *device = GetDeviceByPhysicalAddress(streamaddr); + if (device) + return device->TransmitActiveSource(); + } + return true; +} + +bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command) +{ + if (command.parameters.size >= 1) + { + CCECBusDevice *device = GetDevice(command.destination); + if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + return ((CCECAudioSystem *) device)->SetSystemAudioMode(command); } return true; } +bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) +{ + CCECBusDevice *device = GetDevice(command.destination); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator); + + return false; +} + bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { if (command.parameters.size > 0) @@ -351,3 +380,37 @@ CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress return device; } + +CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const +{ + CCECBusDevice *device = NULL; + + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + { + if (m_busDevice->GetProcessor()->m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress) + { + device = m_busDevice->GetProcessor()->m_busDevices[iPtr]; + break; + } + } + + return device; +} + + +void CCECCommandHandler::SetVendorId(const cec_command &command) +{ + if (command.parameters.size < 3) + { + m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); + return; + } + + uint64_t iVendorId = ((uint64_t)command.parameters[0] << 3) + + ((uint64_t)command.parameters[1] << 2) + + (uint64_t)command.parameters[2]; + + CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); + if (device) + device->SetVendorId(iVendorId, iVendorId); +}