1
0
mirror of https://github.com/rofafor/vdr-plugin-iptv.git synced 2023-10-10 13:37:03 +02:00

Statistic improvements. Supports unit calculations and appending of pre-specified unit string to the result.

This commit is contained in:
Antti Seppälä 2007-10-07 10:13:45 +00:00
parent 9ee8c7f4e7
commit 953da1fc50
7 changed files with 54 additions and 34 deletions

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.c,v 1.54 2007/10/06 22:25:49 rahrenbe Exp $ * $Id: device.c,v 1.55 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#include "common.h" #include "common.h"
@ -96,11 +96,11 @@ cIptvDevice *cIptvDevice::GetIptvDevice(int CardIndex)
return NULL; return NULL;
} }
cString cIptvDevice::GetInformation(void) cString cIptvDevice::GetInformation(uint64_t elapsed, const char* unit, const int unitdivider)
{ {
return cString::sprintf("Device:\n%s\nStreamer:\n%s\nSection Filter 0:\n%s", *GetStatistic(), return cString::sprintf("Device:\n%s\nStreamer:\n%s\nSection Filter 0:\n%s", *GetStatistic(elapsed, unit, unitdivider),
pIptvStreamer ? *pIptvStreamer->GetStatistic() : "", pIptvStreamer ? *pIptvStreamer->GetStatistic(elapsed, unit, unitdivider) : "",
secfilters[0] ? *secfilters[0]->GetStatistic() : ""); secfilters[0] ? *secfilters[0]->GetStatistic(elapsed, unit, unitdivider) : "");
} }
cString cIptvDevice::GetChannelSettings(const char *Param, int *IpPort, cIptvProtocolIf* *Protocol) cString cIptvDevice::GetChannelSettings(const char *Param, int *IpPort, cIptvProtocolIf* *Protocol)

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: device.h,v 1.25 2007/10/06 20:57:53 rahrenbe Exp $ * $Id: device.h,v 1.26 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#ifndef __IPTV_DEVICE_H #ifndef __IPTV_DEVICE_H
@ -48,7 +48,7 @@ private:
public: public:
cIptvDevice(unsigned int DeviceIndex); cIptvDevice(unsigned int DeviceIndex);
virtual ~cIptvDevice(); virtual ~cIptvDevice();
cString GetInformation(void); cString GetInformation(uint64_t, const char* unit, const int unitdivider);
// for channel parsing & buffering // for channel parsing & buffering
private: private:

4
iptv.c
View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: iptv.c,v 1.11 2007/10/06 20:57:53 rahrenbe Exp $ * $Id: iptv.c,v 1.12 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#include <getopt.h> #include <getopt.h>
@ -210,7 +210,7 @@ cString cPluginIptv::SVDRPCommand(const char *Command, const char *Option, int &
if (strcasecmp(Command, "INFO") == 0) { if (strcasecmp(Command, "INFO") == 0) {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex()); cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device) if (device)
return device->GetInformation(); return device->GetInformation(0, "", 0);
else { else {
ReplyCode = 550; // Requested action not taken ReplyCode = 550; // Requested action not taken
return cString("IPTV information not available!"); return cString("IPTV information not available!");

15
setup.c
View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: setup.c,v 1.22 2007/10/06 22:15:02 rahrenbe Exp $ * $Id: setup.c,v 1.23 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#include <string.h> #include <string.h>
@ -479,7 +479,7 @@ private:
}; };
cString text; cString text;
cTimeMs timeout; cTimeMs timeout;
void UpdateInfo(); void UpdateInfo(uint64_t elapsed, const char* unit, const int unitdivider);
public: public:
cIptvMenuInfo(); cIptvMenuInfo();
@ -491,18 +491,18 @@ public:
cIptvMenuInfo::cIptvMenuInfo() cIptvMenuInfo::cIptvMenuInfo()
:cOsdMenu(tr("IPTV Information")), text(""), timeout(INFO_TIMEOUT) :cOsdMenu(tr("IPTV Information")), text(""), timeout(INFO_TIMEOUT)
{ {
UpdateInfo(); UpdateInfo(0, "kbytes", 1024);
} }
cIptvMenuInfo::~cIptvMenuInfo() cIptvMenuInfo::~cIptvMenuInfo()
{ {
} }
void cIptvMenuInfo::UpdateInfo(void) void cIptvMenuInfo::UpdateInfo(uint64_t elapsed, const char* unit, const int unitdivider)
{ {
cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex()); cIptvDevice *device = cIptvDevice::GetIptvDevice(cDevice::ActualDevice()->CardIndex());
if (device) if (device)
text = device->GetInformation(); text = device->GetInformation(elapsed, unit, unitdivider);
else else
text = cString(tr("IPTV information not available!")); text = cString(tr("IPTV information not available!"));
Display(); Display();
@ -539,11 +539,12 @@ eOSState cIptvMenuInfo::ProcessKey(eKeys Key)
if (state == osUnknown) { if (state == osUnknown) {
switch (Key) { switch (Key) {
case kOk: return osBack; case kOk: return osBack;
default: if (timeout.TimedOut()) default: if (timeout.TimedOut()) {
UpdateInfo(); UpdateInfo(INFO_TIMEOUT, "kb/s", 1024);
return osContinue; return osContinue;
} }
} }
}
return state; return state;
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: statisticif.h,v 1.2 2007/10/06 22:15:02 rahrenbe Exp $ * $Id: statisticif.h,v 1.3 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#ifndef __IPTV_STATISTICIF_H #ifndef __IPTV_STATISTICIF_H
@ -15,7 +15,7 @@ class cIptvStatisticIf {
public: public:
cIptvStatisticIf() {} cIptvStatisticIf() {}
virtual ~cIptvStatisticIf() {} virtual ~cIptvStatisticIf() {}
virtual cString GetStatistic() = 0; virtual cString GetStatistic(uint64_t elapsed, const char* unit, const int unitdivider) = 0;
private: private:
cIptvStatisticIf(const cIptvStatisticIf&); cIptvStatisticIf(const cIptvStatisticIf&);

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: statistics.c,v 1.5 2007/10/07 08:46:34 ajhseppa Exp $ * $Id: statistics.c,v 1.6 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#include "common.h" #include "common.h"
@ -22,13 +22,17 @@ cIptvSectionStatistics::~cIptvSectionStatistics()
//debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n"); //debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n");
} }
cString cIptvSectionStatistics::GetStatistic() cString cIptvSectionStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
{ {
debug("cIptvSectionStatistics::GetStatistic()\n"); debug("cIptvSectionStatistics::GetStatistic()\n");
// Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
long tmpFilteredData = filteredData; long tmpFilteredData = filteredData;
long tmpNumberOfCalls = numberOfCalls; long tmpNumberOfCalls = numberOfCalls;
float divider = unitdivider * elapsed / 1000;
filteredData = numberOfCalls = 0; filteredData = numberOfCalls = 0;
return cString::sprintf("Filtered data: %ld\nData packets passed: %ld\n", tmpFilteredData, tmpNumberOfCalls); return cString::sprintf("Filtered data: %ld %s\nData packets passed: %ld\n", (long)(tmpFilteredData / divider), unit, tmpNumberOfCalls);
} }
// --- cIptvDeviceStatistics ------------------------------------------------- // --- cIptvDeviceStatistics -------------------------------------------------
@ -46,19 +50,30 @@ cIptvDeviceStatistics::~cIptvDeviceStatistics()
debug("cIptvDeviceStatistics::~cIptvDeviceStatistics()\n"); debug("cIptvDeviceStatistics::~cIptvDeviceStatistics()\n");
} }
cString cIptvDeviceStatistics::GetStatistic(void) cString cIptvDeviceStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
{ {
debug("cIptvDeviceStatistics::GetStatistic()\n"); debug("cIptvDeviceStatistics::GetStatistic()\n");
pidStruct tmpMostActivePids[10]; pidStruct tmpMostActivePids[10];
long tmpDataBytes = dataBytes; long tmpDataBytes = dataBytes;
// Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
float divider = unitdivider * elapsed / 1000;
dataBytes = 0; dataBytes = 0;
memcpy(&tmpMostActivePids, &mostActivePids, sizeof(tmpMostActivePids)); memcpy(&tmpMostActivePids, &mostActivePids, sizeof(tmpMostActivePids));
memset(&mostActivePids, '\0', sizeof(mostActivePids)); memset(&mostActivePids, '\0', sizeof(mostActivePids));
return cString::sprintf("Stream data bytes: %ld\n1. Active Pid: %d %ld\n2. Active Pid: %d %ld\n3. Active Pid: %d %ld\n", return cString::sprintf("Stream data bytes: %ld %s\n"
tmpDataBytes, " 1. Active Pid: %d %ld %s\n"
tmpMostActivePids[0].pid, tmpMostActivePids[0].DataAmount, " 2. Active Pid: %d %ld %s\n"
tmpMostActivePids[1].pid, tmpMostActivePids[1].DataAmount, " 3. Active Pid: %d %ld %s\n"
tmpMostActivePids[2].pid, tmpMostActivePids[2].DataAmount); " 4. Active Pid: %d %ld %s\n"
" 5. Active Pid: %d %ld %s\n",
(long)(tmpDataBytes / divider), unit,
tmpMostActivePids[0].pid, (long)(tmpMostActivePids[0].DataAmount / divider), unit,
tmpMostActivePids[1].pid, (long)(tmpMostActivePids[1].DataAmount / divider), unit,
tmpMostActivePids[2].pid, (long)(tmpMostActivePids[2].DataAmount / divider), unit,
tmpMostActivePids[3].pid, (long)(tmpMostActivePids[3].DataAmount / divider), unit,
tmpMostActivePids[4].pid, (long)(tmpMostActivePids[4].DataAmount / divider), unit);
} }
int SortFunc(const void* data1, const void* data2) int SortFunc(const void* data1, const void* data2)
@ -110,10 +125,14 @@ cIptvStreamerStatistics::~cIptvStreamerStatistics()
debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n"); debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n");
} }
cString cIptvStreamerStatistics::GetStatistic(void) cString cIptvStreamerStatistics::GetStatistic(uint64_t elapsed, const char* unit, int unitdivider)
{ {
debug("cIptvStreamerStatistics::GetStatistic()\n"); debug("cIptvStreamerStatistics::GetStatistic()\n");
long tmpDataBytes = dataBytes; // Prevent a divide-by-zero error
elapsed ? : elapsed = 1;
unitdivider ? : unitdivider = 1;
float divider = unitdivider * elapsed / 1000;
long tmpDataBytes = (long)(dataBytes / divider);
dataBytes = 0; dataBytes = 0;
return cString::sprintf("Stream data bytes: %ld\n", tmpDataBytes); return cString::sprintf("Stream data bytes: %ld %s\n", tmpDataBytes, unit);
} }

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: statistics.h,v 1.2 2007/10/06 22:15:02 rahrenbe Exp $ * $Id: statistics.h,v 1.3 2007/10/07 10:13:45 ajhseppa Exp $
*/ */
#ifndef __IPTV_STATISTICS_H #ifndef __IPTV_STATISTICS_H
@ -26,7 +26,7 @@ public:
cIptvSectionStatistics(); cIptvSectionStatistics();
virtual ~cIptvSectionStatistics(); virtual ~cIptvSectionStatistics();
cString GetStatistic(); cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
}; };
// Device statistics // Device statistics
@ -38,7 +38,7 @@ public:
cIptvDeviceStatistics(); cIptvDeviceStatistics();
virtual ~cIptvDeviceStatistics(); virtual ~cIptvDeviceStatistics();
cString GetStatistic(); cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
protected: protected:
void UpdateActivePids(u_short pid, long payload); void UpdateActivePids(u_short pid, long payload);
@ -56,7 +56,7 @@ public:
cIptvStreamerStatistics(); cIptvStreamerStatistics();
virtual ~cIptvStreamerStatistics(); virtual ~cIptvStreamerStatistics();
cString GetStatistic(); cString GetStatistic(uint64_t elapsed, const char* unit, int unitdivider);
}; };
#endif // __IPTV_STATISTICS_H #endif // __IPTV_STATISTICS_H