diff --git a/device.c b/device.c index 0ba53cc..5185c39 100644 --- a/device.c +++ b/device.c @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: device.c,v 1.62 2007/10/09 16:37:16 rahrenbe Exp $ + * $Id: device.c,v 1.63 2007/10/09 17:58:17 ajhseppa Exp $ */ #include "config.h" @@ -97,19 +97,19 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex) cString cIptvDevice::GetGeneralInformation(void) { //debug("cIptvDevice::GetGeneralInformation(%d)\n", deviceIndex); - return cString::sprintf("IPTV device #%d (CardIndex: %d)\n%s\n%s\nTS buffer usage: %d%%\n", + return cString::sprintf("IPTV device #%d (CardIndex: %d)\n%s\n%s\nTSBuffer: %s\nStreamBuffer: %s\n", deviceIndex, CardIndex(), pIptvStreamer ? *pIptvStreamer->GetInformation() : "", - pIptvStreamer ? *pIptvStreamer->GetStatistic() : "", - ((MEGABYTE(IptvConfig.GetTsBufferSize()) - tsBuffer->Free()) / - MEGABYTE(IptvConfig.GetTsBufferSize()))); + pIptvStreamer ? *pIptvStreamer->cIptvStreamerStatistics::GetStatistic() : "", + *cIptvBufferStatistics::GetStatistic(), + pIptvStreamer ? *pIptvStreamer->cIptvBufferStatistics::GetStatistic() : ""); } cString cIptvDevice::GetPidsInformation(void) { //debug("cIptvDevice::GetPidsInformation(%d)\n", deviceIndex); cString info("Most active pids:\n"); - info = cString::sprintf("%s%s", *info, *GetStatistic()); + info = cString::sprintf("%s%s", *info, *cIptvDeviceStatistics::GetStatistic()); return info; } @@ -365,7 +365,8 @@ bool cIptvDevice::GetTSPacket(uchar *&Data) isPacketDelivered = true; Data = p; // Update statistics - AddStatistic(Count, ts_pid(p), payload(p)); + cIptvDeviceStatistics::AddStatistic(TS_SIZE, ts_pid(p), payload(p)); + cIptvBufferStatistics::AddStatistic(tsBuffer->Available(), tsBuffer->Free()); // Run the data through all filters for (unsigned int i = 0; i < eMaxSecFilterCount; ++i) { if (secfilters[i]) diff --git a/device.h b/device.h index 79cbea7..588b8cc 100644 --- a/device.h +++ b/device.h @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: device.h,v 1.29 2007/10/09 16:37:16 rahrenbe Exp $ + * $Id: device.h,v 1.30 2007/10/09 17:58:17 ajhseppa Exp $ */ #ifndef __IPTV_DEVICE_H @@ -19,7 +19,7 @@ #include "sidscanner.h" #include "statistics.h" -class cIptvDevice : public cDevice, public cIptvDeviceStatistics { +class cIptvDevice : public cDevice, public cIptvDeviceStatistics, public cIptvBufferStatistics { // static ones public: static unsigned int deviceCount; diff --git a/statistics.c b/statistics.c index 2fc034e..ec4705a 100644 --- a/statistics.c +++ b/statistics.c @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: statistics.c,v 1.15 2007/10/08 23:51:58 rahrenbe Exp $ + * $Id: statistics.c,v 1.16 2007/10/09 17:58:17 ajhseppa Exp $ */ #include @@ -173,3 +173,42 @@ void cIptvStreamerStatistics::AddStatistic(long Bytes) cMutexLock MutexLock(&mutex); dataBytes += Bytes; } + + +// Buffer statistic class +cIptvBufferStatistics::cIptvBufferStatistics() +: freeSpace(0), + usedSpace(0), + timer(), + mutex() +{ + debug("cIptvBufferStatistics::cIptvBufferStatistics()\n"); +} + +cIptvBufferStatistics::~cIptvBufferStatistics() +{ + debug("cIptvBufferStatistics::~cIptvBufferStatistics()\n"); +} + +cString cIptvBufferStatistics::GetStatistic() +{ + //debug("cIptvBufferStatistics::GetStatistic()\n"); + cMutexLock MutexLock(&mutex); + float percentage = (float)((1-(float)freeSpace / (float)(usedSpace + freeSpace)) * 100); + long usedKilos = (long)(usedSpace / KILOBYTE(1)); + long freeKilos = (long)(freeSpace / KILOBYTE(1)); + if (!IptvConfig.GetUseBytes()) { + freeKilos *= 8; + usedKilos *= 8; + } + cString info = cString::sprintf("%ld/%ld k%s (%2.1f%%)", usedKilos, freeKilos, IptvConfig.GetUseBytes() ? "B" : "bit", percentage); + return info; +} + +void cIptvBufferStatistics::AddStatistic(long used, long free) +{ + //debug("cIptvBufferStatistics::AddStatistic(Bytes=%ld)\n", Bytes); + cMutexLock MutexLock(&mutex); + freeSpace = free; + usedSpace = used; +} diff --git a/statistics.h b/statistics.h index d54c67f..4b08c05 100644 --- a/statistics.h +++ b/statistics.h @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: statistics.h,v 1.7 2007/10/08 16:24:48 rahrenbe Exp $ + * $Id: statistics.h,v 1.8 2007/10/09 17:58:17 ajhseppa Exp $ */ #ifndef __IPTV_STATISTICS_H @@ -70,5 +70,22 @@ private: cMutex mutex; }; +// Buffer statistics +class cIptvBufferStatistics : public cIptvStatisticIf { +public: + cIptvBufferStatistics(); + virtual ~cIptvBufferStatistics(); + cString GetStatistic(); + +protected: + void AddStatistic(long used, long free); + +private: + long freeSpace; + long usedSpace; + cTimeMs timer; + cMutex mutex; +}; + #endif // __IPTV_STATISTICS_H diff --git a/streamer.c b/streamer.c index d5ce5f3..84be665 100644 --- a/streamer.c +++ b/streamer.c @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: streamer.c,v 1.19 2007/10/08 16:24:49 rahrenbe Exp $ + * $Id: streamer.c,v 1.20 2007/10/09 17:58:17 ajhseppa Exp $ */ #include @@ -37,12 +37,14 @@ void cIptvStreamer::Action(void) unsigned char *buffer = NULL; int length = protocol->Read(&buffer); if (length >= 0) { - AddStatistic(length); + cIptvStreamerStatistics::AddStatistic(length); mutex->Lock(); int p = ringBuffer->Put(buffer, length); if (p != length && Running()) ringBuffer->ReportOverflow(length - p); mutex->Unlock(); + cIptvBufferStatistics::AddStatistic(ringBuffer->Available(), + ringBuffer->Free()); } else cCondWait::SleepMs(100); // to reduce cpu load diff --git a/streamer.h b/streamer.h index a2f8cad..1571e92 100644 --- a/streamer.h +++ b/streamer.h @@ -3,7 +3,7 @@ * * See the README file for copyright information and how to reach the author. * - * $Id: streamer.h,v 1.9 2007/10/07 22:54:09 rahrenbe Exp $ + * $Id: streamer.h,v 1.10 2007/10/09 17:58:17 ajhseppa Exp $ */ #ifndef __IPTV_STREAMER_H @@ -17,7 +17,7 @@ #include "protocolif.h" #include "statistics.h" -class cIptvStreamer : public cThread, public cIptvStreamerStatistics { +class cIptvStreamer : public cThread, public cIptvStreamerStatistics, public cIptvBufferStatistics { private: cRingBufferLinear* ringBuffer; cMutex* mutex;