diff --git a/common/ca_ci.cpp b/common/ca_ci.cpp index d50ced0..c344f08 100644 --- a/common/ca_ci.cpp +++ b/common/ca_ci.cpp @@ -190,7 +190,7 @@ eData waitData(int fd, unsigned char* buffer, int* len) else if (retval == 0) { #if wd_debug - //printf("**** wd DataTimeout\n"); + printf("**** wd DataTimeout\n"); #endif return eDataTimeout; } @@ -214,7 +214,7 @@ eData waitData(int fd, unsigned char* buffer, int* len) else if (fds.revents & POLLOUT) { #if wd_debug - //printf("**** wd DataWrite\n"); + printf("**** wd DataWrite\n"); #endif return eDataWrite; } @@ -1343,12 +1343,11 @@ void cCA::slot_pollthread(void *c) { unsigned char data[1024 * 4]; eDVBCISlot* slot = (eDVBCISlot*) c; + bool wait = false; while (1) { #if HAVE_ARM_HARDWARE /* Armbox */ - if (slot->init && !slot->mmiOpened) - sleep(1); int len = 1024 *4; eData status; @@ -1381,6 +1380,9 @@ void cCA::slot_pollthread(void *c) goto FROM_FIRST; } } + /* slow down the loop, if no CI cam present */ + printf("***sleep\n"); + sleep(1); } /* case statusnone */ break; case eStatusWait: @@ -1389,6 +1391,7 @@ void cCA::slot_pollthread(void *c) FROM_FIRST: if (status == eDataReady) { + wait = false; slot->pollConnection = false; if (len) { @@ -1398,6 +1401,7 @@ FROM_FIRST: } /*if data ready */ else if (status == eDataWrite) { + wait = true; /* only writing any data here while status = eDataWrite */ if (!slot->sendqueue.empty()) { @@ -1619,6 +1623,9 @@ FROM_FIRST: if (slot->ccmgr_ready && slot->hasCCManager && slot->scrambled && !slot->SidBlackListed) slot->ccmgrSession->resendKey(slot); } + /* slow down for hd51 to avoid high cpu load */ + if (wait && slot->init) + usleep(300000); } } diff --git a/libdvbci/descrambler.cpp b/libdvbci/descrambler.cpp index 502ef1d..2d18585 100644 --- a/libdvbci/descrambler.cpp +++ b/libdvbci/descrambler.cpp @@ -20,8 +20,6 @@ static int desc_user_count = 0; #if HAVE_ARM_HARDWARE -//static const char *descrambler_filename = "/dev/dvb/adapter0/ca0"; -//static const char *descrambler_filename = "/dev/dvb/adapter0/ca1"; static const char *descrambler_filename = "/dev/ciplus_ca0"; enum ca_descr_data_type { @@ -43,19 +41,18 @@ struct ca_descr_data { }; #define CA_SET_DESCR_DATA _IOW('o', 137, struct ca_descr_data) -//#define CA_SET_DESCR_DATA _IOW('o', 10, struct ca_descr_data) int descrambler_set_key(int index, int parity, unsigned char *data) { struct ca_descr_data d; int ret; - printf("%s -> %s %s\n", FILENAME, __FUNCTION__, descrambler_filename); + printf("%s -> %s\n", FILENAME, __FUNCTION__); if (descrambler_open()) { - printf("Complete Data-> Index: (%d) Parity: (%d) -> ", index, parity); - hexdump(data, 32); + //printf("Complete Data-> Index: (%d) Parity: (%d) -> ", index, parity); + //hexdump(data, 32); d.index = index; d.parity = (ca_descr_parity)parity; @@ -78,7 +75,7 @@ int descrambler_set_key(int index, int parity, unsigned char *data) d.length = 16; d.data = data + 16; - printf("IV Index: (%d) Parity: (%d) -> ", d.index, d.parity); + printf("IV Index: (%d) Parity: (%d) -> ", d.index, d.parity); hexdump(d.data, 16); ret = ioctl(desc_fd, CA_SET_DESCR_DATA, &d); @@ -87,7 +84,6 @@ int descrambler_set_key(int index, int parity, unsigned char *data) printf("CA_SET_DESCR_DATA (IV) index=%d parity=%d (errno=%d %s)\n", index, parity, errno, strerror(errno)); } - descrambler_close(); } return 0; } @@ -102,7 +98,7 @@ int descrambler_set_key(int index, int parity, unsigned char *data) { struct ca_descr_data d; - printf("%s -> %s %s\n", FILENAME, __FUNCTION__, descrambler_filename); + printf("%s -> %s\n", FILENAME, __FUNCTION__); index |= 0x100; @@ -125,7 +121,6 @@ int descrambler_set_key(int index, int parity, unsigned char *data) printf("Index: %d Parity: (%d) -> ", d.index, d.parity); hexdump(d.data, 32); - descrambler_close(); } return 0; } @@ -165,6 +160,8 @@ int descrambler_set_pid(int index, int enable, int pid) bool descrambler_open(void) { + if (desc_fd > 0) + return true; desc_fd = open(descrambler_filename, O_RDWR | O_NONBLOCK ); if (desc_fd <= 0) { printf("cannot open %s\n", descrambler_filename); @@ -176,6 +173,7 @@ bool descrambler_open(void) int descrambler_init(void) { desc_user_count++; + descrambler_open(); printf("%s -> %s %d\n", FILENAME, __FUNCTION__, desc_user_count); return 0; } diff --git a/libdvbci/dvbci_ccmgr.cpp b/libdvbci/dvbci_ccmgr.cpp index 3011d64..53f3658 100644 --- a/libdvbci/dvbci_ccmgr.cpp +++ b/libdvbci/dvbci_ccmgr.cpp @@ -1357,7 +1357,6 @@ void eDVBCIContentControlManagerSession::resendKey(eDVBCISlot *tslot) { for (unsigned int i = 0; i < slot->pids.size(); i++) descrambler_set_pid((int)tslot->slot, 1, (int) slot->pids[i]); - descrambler_close(); } } slot->newPids = false; @@ -1372,7 +1371,6 @@ void eDVBCIContentControlManagerSession::resendKey(eDVBCISlot *tslot) { for (unsigned int i = 0; i < slot->pids.size(); i++) descrambler_set_pid((int)tslot->slot, 1, (int) slot->pids[i]); - descrambler_close(); } } slot->newPids = false;