From: Lars Op den Kamp Date: Tue, 29 Nov 2011 20:34:29 +0000 (+0100) Subject: cec: handle audio opcodes correctly X-Git-Tag: upstream/2.2.0~1^2~44^2~75 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aa517a0d7e95d3941b12f36e242abcc8ab06f80a;p=deb_libcec.git cec: handle audio opcodes correctly --- diff --git a/src/lib/devices/CECAudioSystem.cpp b/src/lib/devices/CECAudioSystem.cpp index 46824fc..1028a1f 100644 --- a/src/lib/devices/CECAudioSystem.cpp +++ b/src/lib/devices/CECAudioSystem.cpp @@ -62,13 +62,13 @@ bool CCECAudioSystem::SetAudioStatus(uint8_t status) return false; } -bool CCECAudioSystem::SetSystemAudioMode(const cec_system_audio_status mode) +bool CCECAudioSystem::SetSystemAudioModeStatus(const cec_system_audio_status mode) { CLockObject lock(&m_writeMutex); if (m_systemAudioStatus != mode) { CStdString strLog; - strLog.Format(">> %s (%X): system audio mode changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_systemAudioStatus), ToString(mode)); + strLog.Format(">> %s (%X): system audio mode status changed from %s to %s", GetLogicalAddressName(), m_iLogicalAddress, ToString(m_systemAudioStatus), ToString(mode)); AddLog(CEC_LOG_DEBUG, strLog.c_str()); m_systemAudioStatus = mode; @@ -78,17 +78,6 @@ bool CCECAudioSystem::SetSystemAudioMode(const cec_system_audio_status mode) return false; } -bool CCECAudioSystem::SetSystemAudioMode(const cec_command &command) -{ - SetSystemAudioMode((command.parameters.size == 0) ? - CEC_SYSTEM_AUDIO_STATUS_OFF : - CEC_SYSTEM_AUDIO_STATUS_ON); - - if (MyLogicalAddressContains(m_iLogicalAddress)) - return TransmitAudioStatus(command.initiator); - return true; -} - bool CCECAudioSystem::TransmitAudioStatus(cec_logical_address dest) { CLockObject lock(&m_writeMutex); @@ -103,6 +92,20 @@ bool CCECAudioSystem::TransmitAudioStatus(cec_logical_address dest) return m_processor->Transmit(command); } +bool CCECAudioSystem::TransmitSetSystemAudioMode(cec_logical_address dest) +{ + CLockObject lock(&m_writeMutex); + CStdString strLog; + strLog.Format("<< %x -> %x: set system audio mode '%2x'", m_iLogicalAddress, dest, m_audioStatus); + AddLog(CEC_LOG_NOTICE, strLog); + + cec_command command; + cec_command::Format(command, m_iLogicalAddress, dest, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE); + command.parameters.PushBack(m_systemAudioStatus); + + return m_processor->Transmit(command); +} + bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest) { CLockObject lock(&m_writeMutex); diff --git a/src/lib/devices/CECAudioSystem.h b/src/lib/devices/CECAudioSystem.h index 7a7a16e..7f22549 100644 --- a/src/lib/devices/CECAudioSystem.h +++ b/src/lib/devices/CECAudioSystem.h @@ -42,9 +42,9 @@ namespace CEC virtual ~CCECAudioSystem(void) {}; virtual bool SetAudioStatus(uint8_t status); - virtual bool SetSystemAudioMode(const cec_system_audio_status mode); - virtual bool SetSystemAudioMode(const cec_command &command); + virtual bool SetSystemAudioModeStatus(const cec_system_audio_status mode); virtual bool TransmitAudioStatus(cec_logical_address dest); + virtual bool TransmitSetSystemAudioMode(cec_logical_address dest); virtual bool TransmitSystemAudioModeStatus(cec_logical_address dest); virtual uint8_t VolumeUp(bool bWait = true); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index f0a2e64..f53a5e8 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -106,7 +106,16 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) HandleGiveSystemAudioModeStatus(command); break; case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - HandleSetSystemAudioModeRequest(command); + HandleSystemAudioModeRequest(command); + break; + case CEC_OPCODE_REPORT_AUDIO_STATUS: + HandleReportAudioStatus(command);//YYY + break; + case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: + HandleSystemAudioModeStatus(command);//YYY + break; + case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: + HandleSetSystemAudioMode(command);//YYY break; case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: HandleRequestActiveSource(command); @@ -129,12 +138,6 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: HandleReportPhysicalAddress(command); break; - case CEC_OPCODE_REPORT_AUDIO_STATUS: - HandleReportAudioStatus(command); - break; - case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: - HandleSystemAudioStatus(command); - break; case CEC_OPCODE_SET_OSD_NAME: HandleSetOSDName(command); break; @@ -455,13 +458,29 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) return false; } -bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command) +bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) { - if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1) + if (m_busDevice->MyLogicalAddressContains(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) - return ((CCECAudioSystem *) device)->SetSystemAudioMode(command); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + { + if (command.parameters.size >= 2) + { + device->SetPowerStatus(CEC_POWER_STATUS_ON); + ((CCECAudioSystem *) 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) + m_busDevice->GetProcessor()->SetActiveSource(newActiveDevice->GetLogicalAddress()); + return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + } + else + { + ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); + return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); + } + } } return false; } @@ -475,13 +494,31 @@ bool CCECCommandHandler::HandleStandby(const cec_command &command) return true; } -bool CCECCommandHandler::HandleSystemAudioStatus(const cec_command &command) +bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) { - CCECBusDevice *device = GetDevice(command.initiator); - if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + if (command.parameters.size == 1) { - ((CCECAudioSystem *)device)->SetSystemAudioMode(command); - return true; + CCECBusDevice *device = GetDevice(command.initiator); + if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) + { + ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + return true; + } + } + + return false; +} + +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)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); + return true; + } } return false; diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 7db7514..4d9a021 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -72,9 +72,10 @@ namespace CEC virtual bool HandleSetMenuLanguage(const cec_command &command); virtual bool HandleSetOSDName(const cec_command &command); virtual bool HandleSetStreamPath(const cec_command &command); - virtual bool HandleSetSystemAudioModeRequest(const cec_command &command); + virtual bool HandleSystemAudioModeRequest(const cec_command &command); virtual bool HandleStandby(const cec_command &command); - virtual bool HandleSystemAudioStatus(const cec_command &command); + virtual bool HandleSystemAudioModeStatus(const cec_command &command); + virtual bool HandleSetSystemAudioMode(const cec_command &command); virtual bool HandleTextViewOn(const cec_command &command); virtual bool HandleUserControlPressed(const cec_command &command); virtual bool HandleUserControlRelease(const cec_command &command);