Revert "- libarmbox: try to fix cec"

This reverts commit bff0e71e31.


Origin commit data
------------------
Branch: master
Commit: 9408178607
Author: vanhofen <vanhofen@gmx.de>
Date: 2020-05-29 (Fri, 29 May 2020)



------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2020-05-29 16:20:16 +02:00
parent cd7578f499
commit d8aa4545ed
2 changed files with 117 additions and 188 deletions

View File

@@ -60,7 +60,6 @@
}) })
#define CEC_DEVICE "/dev/cec0" #define CEC_DEVICE "/dev/cec0"
#define CEC_HDMIDEV "/dev/hdmi_cec"
#define RC_DEVICE "/dev/input/event1" #define RC_DEVICE "/dev/input/event1"
hdmi_cec * hdmi_cec::hdmi_cec_instance = NULL; hdmi_cec * hdmi_cec::hdmi_cec_instance = NULL;
@@ -73,7 +72,6 @@ hdmi_cec::hdmi_cec()
standby_cec_activ = autoview_cec_activ = standby = muted = false; standby_cec_activ = autoview_cec_activ = standby = muted = false;
hdmiFd = -1; hdmiFd = -1;
volume = 0; volume = 0;
fallback = false;
} }
hdmi_cec::~hdmi_cec() hdmi_cec::~hdmi_cec()
@@ -115,91 +113,77 @@ bool hdmi_cec::SetCECMode(VIDEO_HDMI_CEC_MODE _deviceType)
if (hdmiFd == -1) if (hdmiFd == -1)
{ {
hdmiFd = open(CEC_DEVICE, O_RDWR | O_CLOEXEC); hdmiFd = open(CEC_DEVICE, O_RDWR | O_CLOEXEC);
if (hdmiFd >= 0)
{
__u32 monitor = CEC_MODE_INITIATOR | CEC_MODE_FOLLOWER;
struct cec_caps caps = {};
if (ioctl(hdmiFd, CEC_ADAP_G_CAPS, &caps) < 0)
hal_debug("[CEC] %s: get caps failed (%m)\n", __func__);
if (caps.capabilities & CEC_CAP_LOG_ADDRS)
{
struct cec_log_addrs laddrs = {};
if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0)
hal_debug("[CEC] %s: reset log addr failed (%m)\n", __func__);
memset(&laddrs, 0, sizeof(laddrs));
/*
* NOTE: cec_version, osd_name and deviceType should be made configurable,
* CEC_ADAP_S_LOG_ADDRS delayed till the desired values are available
* (saves us some startup speed as well, polling for a free logical address
* takes some time)
*/
laddrs.cec_version = CEC_OP_CEC_VERSION_2_0;
strcpy(laddrs.osd_name, "neutrino");
laddrs.vendor_id = CEC_VENDOR_ID_NONE;
switch (deviceType)
{
case CEC_LOG_ADDR_TV:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TV;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TV;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TV;
break;
case CEC_LOG_ADDR_RECORD_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_RECORD;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_RECORD;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_RECORD;
break;
case CEC_LOG_ADDR_TUNER_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TUNER;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TUNER;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TUNER;
break;
case CEC_LOG_ADDR_PLAYBACK_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_PLAYBACK;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_PLAYBACK;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_PLAYBACK;
break;
case CEC_LOG_ADDR_AUDIOSYSTEM:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
break;
default:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_UNREGISTERED;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_SWITCH;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_SWITCH;
break;
}
laddrs.num_log_addrs++;
if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0)
hal_debug("[CEC] %s: et log addr failed (%m)\n", __func__);
}
if (ioctl(hdmiFd, CEC_S_MODE, &monitor) < 0)
hal_debug("[CEC] %s: monitor failed (%m)\n", __func__);
}
}
if (hdmiFd == -1)
{
hdmiFd = ::open(CEC_HDMIDEV, O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (hdmiFd >= 0)
{
::ioctl(hdmiFd, 0); /* flush old messages */
fallback = true;
}
} }
if (hdmiFd >= 0) if (hdmiFd >= 0)
{ {
__u32 monitor = CEC_MODE_INITIATOR | CEC_MODE_FOLLOWER;
struct cec_caps caps = {};
if (ioctl(hdmiFd, CEC_ADAP_G_CAPS, &caps) < 0)
hal_debug("[CEC] %s: get caps failed (%m)\n", __func__);
if (caps.capabilities & CEC_CAP_LOG_ADDRS)
{
struct cec_log_addrs laddrs = {};
if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0)
hal_debug("[CEC] %s: reset log addr failed (%m)\n", __func__);
memset(&laddrs, 0, sizeof(laddrs));
/*
* NOTE: cec_version, osd_name and deviceType should be made configurable,
* CEC_ADAP_S_LOG_ADDRS delayed till the desired values are available
* (saves us some startup speed as well, polling for a free logical address
* takes some time)
*/
laddrs.cec_version = CEC_OP_CEC_VERSION_2_0;
strcpy(laddrs.osd_name, "neutrino");
laddrs.vendor_id = CEC_VENDOR_ID_NONE;
switch (deviceType)
{
case CEC_LOG_ADDR_TV:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TV;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TV;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TV;
break;
case CEC_LOG_ADDR_RECORD_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_RECORD;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_RECORD;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_RECORD;
break;
case CEC_LOG_ADDR_TUNER_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_TUNER;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_TUNER;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_TUNER;
break;
case CEC_LOG_ADDR_PLAYBACK_1:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_PLAYBACK;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_PLAYBACK;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_PLAYBACK;
break;
case CEC_LOG_ADDR_AUDIOSYSTEM:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_AUDIOSYSTEM;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_AUDIOSYSTEM;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_AUDIOSYSTEM;
break;
default:
laddrs.log_addr_type[laddrs.num_log_addrs] = CEC_LOG_ADDR_TYPE_UNREGISTERED;
laddrs.all_device_types[laddrs.num_log_addrs] = CEC_OP_ALL_DEVTYPE_SWITCH;
laddrs.primary_device_type[laddrs.num_log_addrs] = CEC_OP_PRIM_DEVTYPE_SWITCH;
break;
}
laddrs.num_log_addrs++;
if (ioctl(hdmiFd, CEC_ADAP_S_LOG_ADDRS, &laddrs) < 0)
hal_debug("[CEC] %s: et log addr failed (%m)\n", __func__);
}
if (ioctl(hdmiFd, CEC_S_MODE, &monitor) < 0)
hal_debug("[CEC] %s: monitor failed (%m)\n", __func__);
GetCECAddressInfo(); GetCECAddressInfo();
if(autoview_cec_activ) if(autoview_cec_activ)
@@ -216,63 +200,48 @@ void hdmi_cec::GetCECAddressInfo()
{ {
if (hdmiFd >= 0) if (hdmiFd >= 0)
{ {
bool hasdata = false;
struct addressinfo addressinfo; struct addressinfo addressinfo;
if (fallback) __u16 phys_addr;
struct cec_log_addrs laddrs = {};
::ioctl(hdmiFd, CEC_ADAP_G_PHYS_ADDR, &phys_addr);
addressinfo.physical[0] = (phys_addr >> 8) & 0xff;
addressinfo.physical[1] = phys_addr & 0xff;
::ioctl(hdmiFd, CEC_ADAP_G_LOG_ADDRS, &laddrs);
addressinfo.logical = laddrs.log_addr[0];
switch (laddrs.log_addr_type[0])
{ {
if (::ioctl(hdmiFd, 1, &addressinfo) >= 0) case CEC_LOG_ADDR_TYPE_TV:
{ addressinfo.type = CEC_LOG_ADDR_TV;
hasdata = true; break;
} case CEC_LOG_ADDR_TYPE_RECORD:
} addressinfo.type = CEC_LOG_ADDR_RECORD_1;
else break;
{ case CEC_LOG_ADDR_TYPE_TUNER:
__u16 phys_addr; addressinfo.type = CEC_LOG_ADDR_TUNER_1;
struct cec_log_addrs laddrs = {}; break;
case CEC_LOG_ADDR_TYPE_PLAYBACK:
::ioctl(hdmiFd, CEC_ADAP_G_PHYS_ADDR, &phys_addr); addressinfo.type = CEC_LOG_ADDR_PLAYBACK_1;
addressinfo.physical[0] = (phys_addr >> 8) & 0xff; break;
addressinfo.physical[1] = phys_addr & 0xff; case CEC_LOG_ADDR_TYPE_AUDIOSYSTEM:
addressinfo.type = CEC_LOG_ADDR_AUDIOSYSTEM;
::ioctl(hdmiFd, CEC_ADAP_G_LOG_ADDRS, &laddrs); break;
addressinfo.logical = laddrs.log_addr[0]; case CEC_LOG_ADDR_TYPE_UNREGISTERED:
default:
switch (laddrs.log_addr_type[0]) addressinfo.type = CEC_LOG_ADDR_UNREGISTERED;
{ break;
case CEC_LOG_ADDR_TYPE_TV:
addressinfo.type = CEC_LOG_ADDR_TV;
break;
case CEC_LOG_ADDR_TYPE_RECORD:
addressinfo.type = CEC_LOG_ADDR_RECORD_1;
break;
case CEC_LOG_ADDR_TYPE_TUNER:
addressinfo.type = CEC_LOG_ADDR_TUNER_1;
break;
case CEC_LOG_ADDR_TYPE_PLAYBACK:
addressinfo.type = CEC_LOG_ADDR_PLAYBACK_1;
break;
case CEC_LOG_ADDR_TYPE_AUDIOSYSTEM:
addressinfo.type = CEC_LOG_ADDR_AUDIOSYSTEM;
break;
case CEC_LOG_ADDR_TYPE_UNREGISTERED:
default:
addressinfo.type = CEC_LOG_ADDR_UNREGISTERED;
break;
}
hasdata = true;
} }
if (hasdata) deviceType = addressinfo.type;
logicalAddress = addressinfo.logical;
if (memcmp(physicalAddress, addressinfo.physical, sizeof(physicalAddress)))
{ {
deviceType = addressinfo.type; hal_info("[CEC] %s: detected physical address change: %02X%02X --> %02X%02X\n", __func__, physicalAddress[0], physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]);
logicalAddress = addressinfo.logical; memcpy(physicalAddress, addressinfo.physical, sizeof(physicalAddress));
if (memcmp(physicalAddress, addressinfo.physical, sizeof(physicalAddress))) ReportPhysicalAddress();
{
hal_info("[CEC] %s: detected physical address change: %02X%02X --> %02X%02X\n", __func__, physicalAddress[0], physicalAddress[1], addressinfo.physical[0], addressinfo.physical[1]);
memcpy(physicalAddress, addressinfo.physical, sizeof(physicalAddress));
ReportPhysicalAddress();
}
} }
} }
} }
@@ -294,30 +263,17 @@ void hdmi_cec::SendCECMessage(struct cec_message &txmessage)
{ {
if (hdmiFd >= 0) if (hdmiFd >= 0)
{ {
char str[txmessage.length*6]; char str[txmessage.length*6];
for (int i = 0; i < txmessage.length; i++) for (int i = 0; i < txmessage.length; i++)
{ {
sprintf(str+(i*6),"[0x%02X]", txmessage.data[i]); sprintf(str+(i*6),"[0x%02X]", txmessage.data[i]);
} }
hal_info("[CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n",ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str); hal_info("[CEC] send message %s to %s (0x%02X>>0x%02X) '%s' (%s)\n",ToString((cec_logical_address)txmessage.initiator), txmessage.destination == 0xf ? "all" : ToString((cec_logical_address)txmessage.destination), txmessage.initiator, txmessage.destination, ToString((cec_opcode)txmessage.data[0]), str);
struct cec_msg msg;
if (fallback) cec_msg_init(&msg, txmessage.initiator, txmessage.destination);
{ memcpy(&msg.msg[1], txmessage.data, txmessage.length);
struct cec_message_fb message; msg.len = txmessage.length + 1;
message.address = txmessage.destination; ioctl(hdmiFd, CEC_TRANSMIT, &msg);
message.length = txmessage.length;
memcpy(&message.data, txmessage.data, txmessage.length);
::write(hdmiFd, &message, 2 + message.length);
}
else
{
struct cec_msg msg;
cec_msg_init(&msg, txmessage.initiator, txmessage.destination);
memcpy(&msg.msg[1], txmessage.data, txmessage.length);
msg.len = txmessage.length + 1;
ioctl(hdmiFd, CEC_TRANSMIT, &msg);
}
} }
} }
@@ -511,7 +467,7 @@ bool hdmi_cec::Stop()
return false; return false;
running = false; running = false;
OpenThreads::Thread::cancel(); OpenThreads::Thread::cancel();
if (hdmiFd >= 0) if (hdmiFd >= 0)
@@ -544,34 +500,15 @@ void hdmi_cec::Receive()
struct cec_message rxmessage; struct cec_message rxmessage;
struct cec_message txmessage; struct cec_message txmessage;
if (fallback) struct cec_msg msg;
if (::ioctl(hdmiFd, CEC_RECEIVE, &msg) >= 0)
{ {
struct cec_message_fb rx_message; rxmessage.length = msg.len - 1;
if (::read(hdmiFd, &rx_message, 2) == 2) rxmessage.initiator = cec_msg_initiator(&msg);
{ rxmessage.destination = cec_msg_destination(&msg);
if (::read(hdmiFd, &rx_message.data, rx_message.length) == rx_message.length) rxmessage.opcode = cec_msg_opcode(&msg);
{ memcpy(&rxmessage.data, &msg.msg[1], rxmessage.length);
rxmessage.length = rx_message.length; hasdata = true;
rxmessage.initiator = rx_message.address;
rxmessage.destination = logicalAddress;
rxmessage.opcode = rx_message.data[0];
memcpy(&rxmessage.data, rx_message.data, rx_message.length);
hasdata = true;
}
}
}
else
{
struct cec_msg msg;
if (::ioctl(hdmiFd, CEC_RECEIVE, &msg) >= 0)
{
rxmessage.length = msg.len - 1;
rxmessage.initiator = cec_msg_initiator(&msg);
rxmessage.destination = cec_msg_destination(&msg);
rxmessage.opcode = cec_msg_opcode(&msg);
memcpy(&rxmessage.data, &msg.msg[1], rxmessage.length);
hasdata = true;
}
} }
if (hasdata) if (hasdata)

View File

@@ -34,13 +34,6 @@ struct cec_message
unsigned char length; unsigned char length;
} __attribute__((packed)); } __attribute__((packed));
struct cec_message_fb
{
unsigned char address;
unsigned char length;
unsigned char data[256];
}__attribute__((packed));
struct addressinfo struct addressinfo
{ {
unsigned char logical; unsigned char logical;
@@ -77,7 +70,6 @@ private:
void request_audio_status(); void request_audio_status();
bool muted; bool muted;
int volume; int volume;
bool fallback;
protected: protected:
bool running; bool running;
public: public: