# Fixed handling shared CA pids. # --- ci.c 2018/09/23 10:17:20 5.1 +++ ci.c 2019/03/19 14:58:06 @@ -2505,8 +2505,10 @@ if (GetCaPids(source, transponder, p->programNumber, CaSystemIds, MAXRECEIVEPIDS + 1, CaPids) > 0) { if (Active) caPidReceiver->AddPids(CaPids); - else + else { + KeepSharedCaPids(p->programNumber, CaSystemIds, CaPids); caPidReceiver->DelPids(CaPids); + } } } if (RepliesToQuery()) @@ -2522,6 +2524,43 @@ } } +void cCamSlot::KeepSharedCaPids(int ProgramNumber, const int *CaSystemIds, int *CaPids) +{ + int numPids = 0; + int *pCaPids = CaPids; + while (*pCaPids) { + numPids++; + pCaPids++; + } + if (numPids <= 0) + return; + int CaPids2[MAXRECEIVEPIDS + 1]; + for (cCiCaProgramData *p = caProgramList.First(); p; p = caProgramList.Next(p)) { + if (p->programNumber != ProgramNumber) { + if (GetCaPids(source, transponder, p->programNumber, CaSystemIds, MAXRECEIVEPIDS + 1, CaPids2) > 0) { + int *pCaPids2 = CaPids2; + while (*pCaPids2) { + pCaPids = CaPids; + while (*pCaPids) { + if (*pCaPids == *pCaPids2) { + dsyslog("CAM %d: keeping shared CA pid %d", SlotNumber(), *pCaPids); + // To remove *pCaPids from CaPids we overwrite it with the last valie in the list, and then strip the last value: + *pCaPids = CaPids[numPids - 1]; + numPids--; + CaPids[numPids] = 0; + if (numPids <= 0) + return; + } + else + pCaPids++; + } + pCaPids2++; + } + } + } + } +} + void cCamSlot::SendCaPmts(cCiCaPmtList &CaPmtList) { cMutexLock MutexLock(&mutex); --- ci.h 2018/03/17 12:17:37 5.0 +++ ci.h 2019/03/17 17:41:17 @@ -254,6 +254,7 @@ cList caProgramList; bool mtdAvailable; cMtdHandler *mtdHandler; + void KeepSharedCaPids(int ProgramNumber, const int *CaSystemIds, int *CaPids); void NewConnection(void); void DeleteAllConnections(void); void Process(cTPDU *TPDU = NULL);