Pulse-Eight / libcec

USB CEC Adapter communication Library http://libcec.pulse-eight.com/
Other
724 stars 291 forks source link

Implementation of mute audio differs between C & C++ library #663

Open kira-bruneau opened 1 month ago

kira-bruneau commented 1 month ago

Hi! I noticed that when trying to run libcec_mute_audio through the C library, it wouldn't work on my TV (I don't have an audio system).

It looks like SendMuteAudio is designed to send key presses if there isn't an audio system, but the C library doesn't use it:

C: src/libcec/LibCECC.cpp:

#if CEC_LIB_VERSION_MAJOR >= 5
int libcec_mute_audio(libcec_connection_t connection, int UNUSED(bSendRelease))
{
  ICECAdapter* adapter = static_cast<ICECAdapter*>(connection);
  return adapter ?
      adapter->AudioToggleMute() :
      -1;
}
#endif

C++: src/libcec/LibCEC.cpp:

#if CEC_LIB_VERSION_MAJOR >= 5
uint8_t CLibCEC::MuteAudio(void)
{
  return !!m_client ?
    m_client->SendMuteAudio() :
    (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
}
#endif

I'm working around this, by just sending key presses manually (I'm using https://github.com/ssalonen/cec-rs in Rust, which internally uses the C library):

fn mute(cec: &CecConnection) -> CecConnectionResult<()> {
    cec.send_keypress(CecLogicalAddress::Tv, CecUserControlCode::Mute, true)?;
    cec.send_key_release(CecLogicalAddress::Tv, true)?;
    Ok(())
}