From: Lars Op den Kamp Date: Fri, 25 Nov 2011 16:43:23 +0000 (+0100) Subject: cec: added VolumeUp()/cec_volume_up(), VolumeDown()/cec_volume_down(), MuteAudio... X-Git-Tag: upstream/2.2.0~1^2~44^2~93 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=04e637f9e37a0bcbd6aacc51746bb548293007ef;p=deb_libcec.git cec: added VolumeUp()/cec_volume_up(), VolumeDown()/cec_volume_down(), MuteAudio()/cec_mute_audio() --- diff --git a/include/cec.h b/include/cec.h index 5edbe18..7ac25fd 100644 --- a/include/cec.h +++ b/include/cec.h @@ -269,6 +269,24 @@ namespace CEC * @return True when changed, false otherwise. */ virtual bool SetHDMIPort(uint8_t iPort) = 0; + + /*! + * @brief Sends a volume up keypress to an audiosystem if it's present. + * @return The new audio status. + */ + virtual uint8_t VolumeUp(void) = 0; + + /*! + * @brief Sends a volume down keypress to an audiosystem if it's present. + * @return The new audio status. + */ + virtual uint8_t VolumeDown(void) = 0; + + /*! + * @brief Sends a mute keypress to an audiosystem if it's present. + * @return The new audio status. + */ + virtual uint8_t MuteAudio(void) = 0; }; }; diff --git a/include/cecc.h b/include/cecc.h index 409f03a..c7e5ad4 100644 --- a/include/cecc.h +++ b/include/cecc.h @@ -187,6 +187,12 @@ extern DECLSPEC int cec_is_active_device_type(cec_device_type type); extern DECLSPEC int cec_set_hdmi_port(uint8_t iPort); +extern DECLSPEC int cec_volume_up(void); + +extern DECLSPEC int cec_volume_down(void); + +extern DECLSPEC int cec_mute_audio(void); + #ifdef __cplusplus }; #endif diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 8315cd2..8f2ea98 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -492,6 +492,33 @@ bool CCECProcessor::PollDevice(cec_logical_address iAddress) return false; } +uint8_t CCECProcessor::VolumeUp(void) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(); + + return status; +} + +uint8_t CCECProcessor::VolumeDown(void) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(); + + return status; +} + +uint8_t CCECProcessor::MuteAudio(void) +{ + uint8_t status = 0; + if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM)) + status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(); + + return status; +} + CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const { if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress) diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index cf9980c..178978e 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -85,6 +85,9 @@ namespace CEC virtual bool SetStreamPath(uint16_t iStreamPath); virtual bool SwitchMonitoring(bool bEnable); virtual bool PollDevice(cec_logical_address iAddress); + virtual uint8_t VolumeUp(void); + virtual uint8_t VolumeDown(void); + virtual uint8_t MuteAudio(void); virtual bool Transmit(const cec_command &data); virtual bool Transmit(CCECAdapterMessage *output); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 50ab94f..2e9dac0 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -280,6 +280,28 @@ bool CLibCEC::IsActiveDeviceType(cec_device_type type) return false; } +uint8_t CLibCEC::VolumeUp(void) +{ + if (m_cec) + return m_cec->VolumeUp(); + return 0; +} + +uint8_t CLibCEC::VolumeDown(void) +{ + if (m_cec) + return m_cec->VolumeDown(); + return 0; +} + + +uint8_t CLibCEC::MuteAudio(void) +{ + if (m_cec) + return m_cec->MuteAudio(); + return 0; +} + void CLibCEC::AddLog(cec_log_level level, const string &strMessage) { if (m_cec) diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index 66f1b75..5c9196b 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -88,6 +88,9 @@ namespace CEC virtual bool IsActiveDevice(cec_logical_address iAddress); virtual bool IsActiveDeviceType(cec_device_type type); virtual bool SetHDMIPort(uint8_t iPort = CEC_DEFAULT_HDMI_PORT); + virtual uint8_t VolumeUp(void); + virtual uint8_t VolumeDown(void); + virtual uint8_t MuteAudio(void); //@} virtual void AddLog(cec_log_level level, const std::string &strMessage); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 76f2992..08e6987 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -271,4 +271,25 @@ int cec_set_hdmi_port(uint8_t iPort) return -1; } +int cec_volume_up(void) +{ + if (cec_parser) + return cec_parser->VolumeUp(); + return -1; +} + +int cec_volume_down(void) +{ + if (cec_parser) + return cec_parser->VolumeDown(); + return -1; +} + +int cec_mute_audio(void) +{ + if (cec_parser) + return cec_parser->MuteAudio(); + return -1; +} + //@} diff --git a/src/lib/devices/CECAudioSystem.cpp b/src/lib/devices/CECAudioSystem.cpp index 1196544..4a4f11f 100644 --- a/src/lib/devices/CECAudioSystem.cpp +++ b/src/lib/devices/CECAudioSystem.cpp @@ -108,3 +108,36 @@ bool CCECAudioSystem::TransmitSystemAudioModeStatus(cec_logical_address dest) return m_processor->Transmit(command); } + +uint8_t CCECAudioSystem::VolumeUp(void) +{ + return SendKey(CEC_USER_CONTROL_CODE_VOLUME_UP); +} + +uint8_t CCECAudioSystem::VolumeDown(void) +{ + return SendKey(CEC_USER_CONTROL_CODE_VOLUME_DOWN); +} + +uint8_t CCECAudioSystem::MuteAudio(void) +{ + return SendKey(CEC_USER_CONTROL_CODE_MUTE); +} + +uint8_t CCECAudioSystem::SendKey(cec_user_control_code key) +{ + { + CLockObject lock(&m_transmitMutex); + cec_command command; + cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED); + command.parameters.PushBack(key); + m_processor->Transmit(command); + + cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_RELEASE); + if (m_processor->Transmit(command)) + m_condition.Wait(&m_transmitMutex, 1000); + } + + CLockObject lock(&m_mutex); + return m_audioStatus; +} diff --git a/src/lib/devices/CECAudioSystem.h b/src/lib/devices/CECAudioSystem.h index 9a9603e..5602931 100644 --- a/src/lib/devices/CECAudioSystem.h +++ b/src/lib/devices/CECAudioSystem.h @@ -47,6 +47,11 @@ namespace CEC virtual bool TransmitAudioStatus(cec_logical_address dest); virtual bool TransmitSystemAudioModeStatus(cec_logical_address dest); + virtual uint8_t VolumeUp(void); + virtual uint8_t VolumeDown(void); + virtual uint8_t MuteAudio(void); + virtual uint8_t SendKey(cec_user_control_code key); + virtual bool TransmitActiveSource(void) { return false; } protected: diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 7a60eb2..e293f80 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -594,6 +594,18 @@ int main (int argc, char *argv[]) { parser->PingAdapter(); } + else if (command == "volup") + { + parser->VolumeUp(); + } + else if (command == "voldown") + { + parser->VolumeDown(); + } + else if (command == "mute") + { + parser->MuteAudio(); + } else if (command == "mon") { CStdString strEnable;