From 72abc768e9bc8f95ff5fa7289898087fff3156a2 Mon Sep 17 00:00:00 2001 From: Catalin Toda Date: Tue, 30 May 2023 20:56:57 -0700 Subject: [PATCH] Fix high cpu usage when CAM not plugged in for enigma #1096 --- src/ca.c | 19 +++++++++++++++---- src/pmt.c | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/ca.c b/src/ca.c index f2d70abdf3..86e7116622 100644 --- a/src/ca.c +++ b/src/ca.c @@ -1728,10 +1728,10 @@ static int CIPLUS_APP_LANG_handler(ca_session_t *session, int tag, // if (data_length) // hexdump(data, data_length); - uint8_t data_reply_lang[3]; // ISO 639 Part 2 - data_reply_lang[0] = 0x65; /* e */ - data_reply_lang[1] = 0x6e; /* n */ - data_reply_lang[2] = 0x67; /* g */ + uint8_t data_reply_lang[3]; // ISO 639 Part 2 + data_reply_lang[0] = 0x65; /* e */ + data_reply_lang[1] = 0x6e; /* n */ + data_reply_lang[2] = 0x67; /* g */ uint8_t data_reply_country[3]; // ISO 3166-1 alpha 3 data_reply_country[0] = 0x55; /* U */ @@ -2700,6 +2700,17 @@ int ca_read_enigma(int socket, void *buf, int len, sockets *ss, int *rb) { *rb = 0; if (rl > 0) { *rb = rl; + if (ss->events & ~POLLPRI) { + ss->events |= POLLPRI; + } + return 1; + } + if (ss->revents == POLLPRI) { + ca_device_t *d = ca_devices[ss->sid]; + if (d->state != CA_STATE_INACTIVE) { + d->state = CA_STATE_INACTIVE; + } + ss->events = POLLIN; } return 1; } diff --git a/src/pmt.c b/src/pmt.c index 5648e31543..d4ccbfe858 100644 --- a/src/pmt.c +++ b/src/pmt.c @@ -2076,7 +2076,7 @@ int process_sdt(int filter, unsigned char *sdt, int len, void *opaque) { sdt_len = (sdt[1] & 0xF) * 256 + sdt[2]; i = 11; - LOGM("Processing SDT for transponder %d (%x) with length %d, sdt[5] " + DEBUGM("Processing SDT for transponder %d (%x) with length %d, sdt[5] " "%02X", tsid, tsid, sdt_len, sdt[5]); @@ -2087,7 +2087,7 @@ int process_sdt(int filter, unsigned char *sdt, int len, void *opaque) { desc_loop_len = (b[3] & 0xF) * 256 + b[4]; desc_loop_len += 5; pmt = get_all_pmt_for_sid(ad->id, sid); - LOGM("Detected service ID %d (%X) status:%d CA:%d, pos %d len %d", sid, + DEBUGM("Detected service ID %d (%X) status:%d CA:%d, pos %d len %d", sid, sid, (status >> 1), (status & 0x1), i, desc_loop_len); if (!pmt) { DEBUGM("%s: no PMT found for sid %d (%X)", __FUNCTION__, sid, sid);