Pulse-Eight / libcec

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

CEC Control with Audio Support + Reporting status/volume to TV for display #594

Closed DigitalBites closed 2 years ago

DigitalBites commented 2 years ago

I'm working on controlling an amp that is not directly connected to a Sony tv. I've been able to compile the latest versions of libcec and tweak the pyCecClient.py included example with some success but have hit a few roadblocks. The only 'significant' change I've made to it was to tell the CEC Bus/tv it is an audio device by changing the following line:

    -self.cecconfig.deviceTypes.Add(cec.CEC_DEVICE_TYPE_RECORDING_DEVICE)
    +self.cecconfig.deviceTypes.Add(cec.CEC_DEVICE_TYPE_AUDIO_SYSTEM)

I've been able to successfully capture key presses, however, if the tv thinks the volume is zero, it stops transmitting CEC button presses for volume down, similarly volume up. I can supply the correct volume to the TV with tx commands but they don't work. I think this is because libcec seems to report to the tv on initial handshake 50:7a:7f 7a - CEC_OPCODE_REPORT_AUDIO_STATUS and 7f mapping to CEC_AUDIO_VOLUME_STATUS_UNKNOWN.

In addition, it seems that libcec responds back during CEC_OPCODE_REQUEST_ARC_START negotiation with feature unsupported and the response from the library doesn't allow me to intercept this and respond with a CEC_OPCODE_REPORT_ARC_STARTED status potentially also contributing to my problem.

I have gone through some of the code and do find references to AudioStatus and other function calls, but I have yet figured out how to influence the configuration to allow correct responses to audio status request messages as well as the ARC init sequence.

Any help would be greatly appreciated.

HDMI Hardware is as follows:

  1. Sony TV
  2. RPI 4 with HDMI cable.
  3. Apple TV

Initial handshake:

root@dmx-0:~# python3 ./cec-audio-test.py
<module 'cec' from '/usr/local/lib/python3.7/dist-packages/cec.py'>
DEBUG:   [2]     << Broadcast (F) -> Audio (5): POLL
libCEC version 6.0.2 loaded: git revision: libcec-6.0.2+1-76551ea, compiled on 2022-01-20 14:57:50 by root@dmx-0 on Linux 5.10.17-v7l+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
DEBUG:   [2]     >> POLL not sent
DEBUG:   [2]     Audio (5): device status changed into 'not present'
DEBUG:   [2]     not sending command 'system audio mode request': destination device 'Audio' marked as not present
DEBUG:   [40]     Audio (5): device status changed into 'unknown'
DEBUG:   [40]     Broadcast (F): osd name set to 'Broadcast'
NOTICE:  [40]     connection opened
DEBUG:   [40]     unregistering all CEC clients
found a CEC adapter:
port:     RPI
vendor:   0x2708
product:  0x1001
DEBUG:   [40]     Open - vc_cec initialised
DEBUG:   [40]     logical address changed to Free use (e)
NOTICE:  [41]     connection opened
DEBUG:   [41]     << Broadcast (F) -> TV (0): POLL
DEBUG:   [41]     initiator 'Broadcast' is not supported by the CEC adapter. using 'Free use' instead
TRAFFIC: [41]     << e0
DEBUG:   [41]     processor thread started
DEBUG:   [71]     >> POLL sent
DEBUG:   [71]     TV (0): device status changed into 'present'
DEBUG:   [71]     << requesting vendor ID of 'TV' (0)
TRAFFIC: [71]     << e0:8c
TRAFFIC: [288]     >> 0f:87:08:00:46
[command received] >> 0f:87:08:00:46
DEBUG:   [288]     TV (0): vendor = Sony (080046)
DEBUG:   [288]     expected response received (87: device vendor id)
DEBUG:   [288]     >> TV (0) -> Broadcast (F): device vendor id (87)
DEBUG:   [288]     registering new CEC client - v6.0.2
DEBUG:   [288]     SetClientVersion - using client version '6.0.2'
NOTICE:  [288]     setting HDMI port to 1 on device TV (0)
DEBUG:   [288]     SetConfiguration: double tap timeout = 200ms, repeat rate = 0ms, release delay = 500ms
DEBUG:   [288]     detecting logical address for type 'audiosystem'
DEBUG:   [288]     trying logical address 'Audio'
DEBUG:   [289]     << Audio (5) -> Audio (5): POLL
TRAFFIC: [289]     << 55
TRAFFIC: [559]     << 55
DEBUG:   [830]     >> POLL not sent
DEBUG:   [830]     using logical address 'Audio'
DEBUG:   [830]     Audio (5): device status changed into 'handled by libCEC'
DEBUG:   [830]     Audio (5): power status changed from 'unknown' to 'on'
DEBUG:   [830]     Audio (5): vendor = Pulse Eight (001582)
DEBUG:   [830]     Audio (5): CEC version 1.4
DEBUG:   [830]     AllocateLogicalAddresses - device '0', type 'audio system', LA '5'
DEBUG:   [831]     Audio (5): osd name set to 'pyLibCec'
DEBUG:   [832]     Audio (5): menu language set to 'eng'
DEBUG:   [831]     logical address changed to Audio (5)
DEBUG:   [832]     GetPhysicalAddress - physical address = 3000
DEBUG:   [832]     using auto-detected physical address 3000
DEBUG:   [832]     Audio (5): physical address changed from ffff to 3000
DEBUG:   [832]     << Audio (5) -> broadcast (F): physical address 3000
TRAFFIC: [832]     << 5f:84:30:00:05
NOTICE:  [983]     CEC client registered: libCEC version = 6.0.2, client version = 6.0.2, firmware version = 1, logical address(es) = Audio (5) , physical address: 3.0.0.0, git revision: libcec-6.0.2+1-76551ea, compiled on 2022-01-20 14:57:50 by root@dmx-0 on Linux 5.10.17-v7l+ (armv7l), features: P8_USB, DRM, P8_detect, randr, RPi
DEBUG:   [983]     << Audio (5) -> TV (0): OSD name 'pyLibCec'
TRAFFIC: [983]     << 50:47:70:79:4c:69:62:43:65:63
DEBUG:   [1314]     << requesting power status of 'TV' (0)
TRAFFIC: [1314]     << 50:8f
TRAFFIC: [1314]     >> 05:46
[command received] >> 05:46
DEBUG:   [1314]     >> TV (0) -> Audio (5): give osd name (46)
DEBUG:   [1374]     << Audio (5) -> TV (0): OSD name 'pyLibCec'
TRAFFIC: [1374]     << 50:47:70:79:4c:69:62:43:65:63
TRAFFIC: [1705]     >> 05:8c
[command received] >> 05:8c
DEBUG:   [1705]     << Audio (5) -> TV (0): vendor id Pulse Eight (1582)
TRAFFIC: [1705]     << 5f:87:00:15:82
DEBUG:   [1705]     >> TV (0) -> Audio (5): give device vendor id (8C)
TRAFFIC: [1945]     >> 05:90:00
[command received] >> 05:90:00
DEBUG:   [1945]     TV (0): power status changed from 'unknown' to 'on'
DEBUG:   [1946]     >> TV (0) -> Audio (5): report power status (90)
DEBUG:   [1946]     expected response received (90: report power status)
connection opened
Enter command:TRAFFIC: [2164]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [2164]     << Audio (5) -> TV (0): on
TRAFFIC: [2164]     << 50:90:00
DEBUG:   [2164]     >> TV (0) -> Audio (5): give device power status (8F)

Initial handshake completed, change tv setting to external speakers, output is next

TRAFFIC: [12436]     >> 05:70:40:00
[command received] >> 05:70:40:00
DEBUG:   [12436]     << 5 -> 0: set system audio mode '7f'
TRAFFIC: [12436]     << 50:72:01
DEBUG:   [12436]     >> TV (0) -> Audio (5): system audio mode request (70)
TRAFFIC: [12925]     >> 05:c3
[command received] >> 05:c3
DEBUG:   [12925]     sending abort with opcode c3 and reason 'unrecognised opcode' to TV
DEBUG:   [12925]     << transmitting abort message
TRAFFIC: [12925]     << 50:00:c3:00
DEBUG:   [12925]     >> TV (0) -> Audio (5): request ARC start (C3)
TRAFFIC: [13104]     >> 05:71
[command received] >> 05:71
DEBUG:   [13104]     << 5 -> 0: audio status '7f'
TRAFFIC: [13104]     << 50:7a:7f
DEBUG:   [13104]     >> TV (0) -> Audio (5): give audio status (71)

Enter command:
Enter command:
Enter command:
Enter command:TRAFFIC: [28521]     >> 05:44:41
[command received] >> 05:44:41
DEBUG:   [28521]     SetCurrentButton volume up (41) D:0ms cur:41
DEBUG:   [28521]     key pressed: volume up (41) current(ff) duration(0)
DEBUG:   [28521]     Changed key volume up (41) D:0ms cur:ff
DEBUG:   [28521]     key pressed: volume up (41, 0)
[key pressed] 65
volume up
DEBUG:   [28521]     CheckKeypressTimeout T:176985.377
DEBUG:   [28521]     Key volume up: idle (duration:0) (41) timeout:-1236223524ms (rel:500,rep:0,prs:500,rel:0)
DEBUG:   [28521]     >> TV (0) -> Audio (5): user control pressed (44)
TRAFFIC: [28673]     >> 05:8b:41
[command received] >> 05:8b:41
DEBUG:   [28673]     key released: volume up (41) D:152ms
[key pressed] 65
volume up - released
DEBUG:   [28673]     >> TV (0) -> Audio (5): vendor remote button up (8B)
TRAFFIC: [31297]     >> 05:44:42
[command received] >> 05:44:42
DEBUG:   [31297]     SetCurrentButton volume down (42) D:0ms cur:42
DEBUG:   [31297]     key pressed: volume down (42) current(ff) duration(0)
DEBUG:   [31297]     Changed key volume down (42) D:0ms cur:ff
DEBUG:   [31297]     key pressed: volume down (42, 0)
[key pressed] 66
volume down
DEBUG:   [31297]     CheckKeypressTimeout T:176988.153
DEBUG:   [31297]     Key volume down: idle (duration:0) (42) timeout:-1236223524ms (rel:500,rep:0,prs:500,rel:0)
DEBUG:   [31297]     >> TV (0) -> Audio (5): user control pressed (44)
TRAFFIC: [31447]     >> 05:8b:42
[command received] >> 05:8b:42
DEBUG:   [31447]     key released: volume down (42) D:150ms
[key pressed] 66
DEBUG:   [31447]     >> TV (0) -> Audio (5): vendor remote button up (8B)
TRAFFIC: [62164]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [62164]     << Audio (5) -> TV (0): on
TRAFFIC: [62164]     << 50:90:00
DEBUG:   [62164]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [122169]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [122169]     << Audio (5) -> TV (0): on
TRAFFIC: [122169]     << 50:90:00
DEBUG:   [122169]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [182170]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [182170]     << Audio (5) -> TV (0): on
TRAFFIC: [182170]     << 50:90:00
DEBUG:   [182170]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [242175]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [242175]     << Audio (5) -> TV (0): on
TRAFFIC: [242175]     << 50:90:00
DEBUG:   [242175]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [302180]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [302180]     << Audio (5) -> TV (0): on
TRAFFIC: [302180]     << 50:90:00
DEBUG:   [302180]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [362180]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [362180]     << Audio (5) -> TV (0): on
TRAFFIC: [362180]     << 50:90:00
DEBUG:   [362180]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [422185]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [422185]     >> TV (0) -> Audio (5): give device power status (8F)
DEBUG:   [422186]     << Audio (5) -> TV (0): on
TRAFFIC: [422186]     << 50:90:00
TRAFFIC: [482186]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [482186]     << Audio (5) -> TV (0): on
TRAFFIC: [482186]     << 50:90:00
DEBUG:   [482186]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [542191]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [542191]     << Audio (5) -> TV (0): on
TRAFFIC: [542191]     << 50:90:00
DEBUG:   [542191]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [602191]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [602191]     << Audio (5) -> TV (0): on
TRAFFIC: [602191]     << 50:90:00
DEBUG:   [602192]     >> TV (0) -> Audio (5): give device power status (8F)
TRAFFIC: [662191]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [662191]     << Audio (5) -> TV (0): on
TRAFFIC: [662191]     << 50:90:00
DEBUG:   [662192]     >> TV (0) -> Audio (5): give device power status (8F)

manually entering some of the tx commands to initiate ARC handshake and libcec squashes it.

Enter command:tx 50:C0
transmit 50:c0
TRAFFIC: [701662]     << 50:c0
command sent
Enter command:TRAFFIC: [701815]     >> 05:a4:0a
[command received] >> 05:a4:0a
DEBUG:   [701815]     sending abort with opcode a4 and reason 'unrecognised opcode' to TV
DEBUG:   [701815]     << transmitting abort message
TRAFFIC: [701815]     << 50:00:a4:00
DEBUG:   [701815]     >> TV (0) -> Audio (5): UNKNOWN (A4)
TRAFFIC: [701993]     >> 05:c1
[command received] >> 05:c1
DEBUG:   [701994]     sending abort with opcode c1 and reason 'unrecognised opcode' to TV
DEBUG:   [701994]     << transmitting abort message
TRAFFIC: [701994]     << 50:00:c1:00
DEBUG:   [701994]     >> TV (0) -> Audio (5): report ARC started (C1)
TRAFFIC: [702196]     >> 05:a4:0f
[command received] >> 05:a4:0f
DEBUG:   [702196]     sending abort with opcode a4 and reason 'unrecognised opcode' to TV
DEBUG:   [702196]     << transmitting abort message
TRAFFIC: [702196]     << 50:00:a4:00
DEBUG:   [702196]     >> TV (0) -> Audio (5): UNKNOWN (A4)
TRAFFIC: [702375]     >> 05:c2
[command received] >> 05:c2
DEBUG:   [702375]     sending abort with opcode c2 and reason 'unrecognised opcode' to TV
DEBUG:   [702375]     << transmitting abort message
TRAFFIC: [702375]     << 50:00:c2:00
DEBUG:   [702375]     >> TV (0) -> Audio (5): report ARC ended (C2)
TRAFFIC: [722199]     >> 05:8f
[command received] >> 05:8f
DEBUG:   [722199]     << Audio (5) -> TV (0): on
TRAFFIC: [722199]     << 50:90:00
DEBUG:   [722199]     >> TV (0) -> Audio (5): give device power status (8F)

Edit: updated output formatting for readability.

DigitalBites commented 2 years ago

Hello @malard, is the above question something you can point me in a direction on?

drolevar commented 1 year ago

@DigitalBites How did you manage to resolve the issue?