diff --git a/tuner.c b/tuner.c index fe5a832..b25308a 100644 --- a/tuner.c +++ b/tuner.c @@ -474,50 +474,15 @@ bool cSatipTuner::SetPid(int pidP, int typeP, bool onP) { //debug("cSatipTuner::%s(%d, %d, %d) [device %d]", __FUNCTION__, pidP, typeP, onP, deviceM->GetId()); cMutexLock MutexLock(&mutexM); - bool found = false; - for (int i = 0; i < pidsM.Size(); ++i) { - if (pidsM[i] == pidP) { - found = true; - if (!onP) - pidsM.Remove(i); - break; - } - } - if (onP && !found) - pidsM.Append(pidP); - // Generate deltas - found = false; if (onP) { - for (int i = 0; i < addPidsM.Size(); ++i) { - if (addPidsM[i] == pidP) { - found = true; - break; - } - } - if (!found) - addPidsM.Append(pidP); - for (int i = 0; i < delPidsM.Size(); ++i) { - if (delPidsM[i] == pidP) { - delPidsM.Remove(i); - break; - } - } + pidsM.AddPid(pidP); + addPidsM.AddPid(pidP); + delPidsM.RemovePid(pidP); } else { - for (int i = 0; i < delPidsM.Size(); ++i) { - if (delPidsM[i] == pidP) { - found = true; - break; - } - } - if (!found) - delPidsM.Append(pidP); - for (int i = 0; i < addPidsM.Size(); ++i) { - if (addPidsM[i] == pidP) { - addPidsM.Remove(i); - break; - } - } + pidsM.RemovePid(pidP); + delPidsM.AddPid(pidP); + addPidsM.RemovePid(pidP); } pidUpdateCacheM.Set(ePidUpdateIntervalMs); return true; diff --git a/tuner.h b/tuner.h index 444e855..5c36b82 100644 --- a/tuner.h +++ b/tuner.h @@ -23,6 +23,32 @@ #include "statistics.h" #include "socket.h" +class cSatipPid : public cVector { +private: + int PidIndex(const int &pidP) + { + for (int i = 0; i < this->Size(); ++i) { + if (pidP == this->At(i)) + return i; + } + return -1; + } + +public: + void RemovePid(const int &pidP) + { + int i = PidIndex(pidP); + if (i >= 0) + this->Remove(i); + } + + void AddPid(int pidP) + { + if (PidIndex(pidP) < 0) + this->Append(pidP); + } +}; + class cSatipTuner : public cThread, public cSatipTunerStatistics { private: enum { @@ -65,9 +91,9 @@ private: int signalStrengthM; int signalQualityM; int streamIdM; - cVector addPidsM; - cVector delPidsM; - cVector pidsM; + cSatipPid addPidsM; + cSatipPid delPidsM; + cSatipPid pidsM; bool Connect(void); bool Disconnect(void);