trainman419 / python-cec

Other
170 stars 42 forks source link

Audio Status #63

Open mtullo27 opened 1 year ago

mtullo27 commented 1 year ago

Has there been any progress on implementing the get audio status functionality?

trainman419 commented 1 year ago

No, I haven't had anyone asking for audio status, so I haven't looked into it. If you can explain briefly what you're trying to do, I might be able to help.

utdream commented 9 months ago

Audio status is only loosely implemented in the HDMI-CEC specification itself. It rarely (never?) works on TV's and only works on things like sound bars. We need better implementation in the HDMI spec itself before it can really be implemented in an API like this IMHO.

r1ckdu commented 6 months ago

I know this is an old thread but I'd love to get an absolute volume reading. From what I have gathered the code that i need to evaluate is 15:71 (recorder to audio): "Give Audio Status" Returns 51:8e e.g. indicating that the volume is 14 and its muted -> hex sum of 80 + an integer of 0..127.

This would be amazing to have because for my application I need an absolute volume scale.

@trainman419 I have been able to do this using cec-client but I am not able to drive this from python...so this is where your python package came in ;)

nderr commented 2 months ago

I poked around a little bit on this issue. You can add a wrapper for the libcec "GetAudioStatus" function without too much trouble, but as discussed here, libcec caches the first result and keeps returning it forever.

The path of least resistance is probably to ask the audio system for the audio status directly, add a handler to grab the response, and cast the resulting parameter from bytes to int. For example, when I run the following...

# audio_status_test.py

import time
import cec

audio     = cec.CECDEVICE_AUDIOSYSTEM
op_give   = cec.CEC_OPCODE_GIVE_AUDIO_STATUS
op_report = cec.CEC_OPCODE_REPORT_AUDIO_STATUS

recvd = False
def cb(event, *args):

    print('event: ', event, ', data: ', args)

    par = args[0]
    init = par['initiator']
    comm = par['opcode']

    if init == audio and comm == op_report:

        byte_result = par['parameters']
        print(f'\n\nAudio Status: {int.from_bytes(byte_result,"big")}')

        global recvd
        recvd = True

cec.add_callback(cb, cec.EVENT_COMMAND)
cec.init()
cec.transmit(audio,op_give)

while not recvd:
    time.sleep(0.1)

...I get the following output.

event:  4 , data:  ({'initiator': 0, 'destination': 15, 'ack': False, 'eom': False, 'opcode': 135, 'parameters': b'\x00\x009', 'opcode_set': True, 'transmit_timeout': 1000},)
event:  4 , data:  ({'initiator': 0, 'destination': 1, 'ack': False, 'eom': False, 'opcode': 144, 'parameters': b'\x00', 'opcode_set': True, 'transmit_timeout': 1000},)
event:  4 , data:  ({'initiator': 5, 'destination': 1, 'ack': False, 'eom': False, 'opcode': 122, 'parameters': b'$', 'opcode_set': True, 'transmit_timeout': 1000},)

Audio Status: 36
utdream commented 2 months ago

Yuk. That really sucks that libcec does that. I like your implementation of asking the device directly. Thank you!