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

120 lines
3.8 KiB
C
Raw Normal View History

2007-10-05 21:00:44 +02:00
/*
* statistics.c: IPTV plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
* $Id: statistics.c,v 1.4 2007/10/06 22:15:02 rahrenbe Exp $
2007-10-05 21:00:44 +02:00
*/
#include "common.h"
#include "statistics.h"
// Section statistic class
cIptvSectionStatistics::cIptvSectionStatistics()
: filteredData(0),
numberOfCalls(0)
2007-10-05 21:00:44 +02:00
{
2007-10-06 00:23:56 +02:00
//debug("cIptvSectionStatistics::cIptvSectionStatistics()\n");
2007-10-05 21:00:44 +02:00
}
cIptvSectionStatistics::~cIptvSectionStatistics()
{
2007-10-06 00:23:56 +02:00
//debug("cIptvSectionStatistics::~cIptvSectionStatistics()\n");
2007-10-05 21:00:44 +02:00
}
cString cIptvSectionStatistics::GetStatistic()
2007-10-05 21:00:44 +02:00
{
debug("cIptvSectionStatistics::GetStatistic()\n");
long tmpFilteredData = filteredData;
long tmpNumberOfCalls = numberOfCalls;
2007-10-05 21:00:44 +02:00
filteredData = numberOfCalls = 0;
return cString::sprintf("Filtered data: %ld\nData packets passed: %ld\n", tmpFilteredData, tmpNumberOfCalls);
2007-10-05 21:00:44 +02:00
}
// --- cIptvDeviceStatistics -------------------------------------------------
2007-10-05 21:00:44 +02:00
// Device statistic class
cIptvDeviceStatistics::cIptvDeviceStatistics()
: dataBytes(0)
2007-10-05 21:00:44 +02:00
{
debug("cIptvDeviceStatistics::cIptvDeviceStatistics()\n");
memset(mostActivePids, '\0', sizeof(mostActivePids));
}
cIptvDeviceStatistics::~cIptvDeviceStatistics()
{
debug("cIptvDeviceStatistics::~cIptvDeviceStatistics()\n");
}
cString cIptvDeviceStatistics::GetStatistic(void)
2007-10-05 21:00:44 +02:00
{
debug("cIptvDeviceStatistics::GetStatistic()\n");
pidStruct tmpMostActivePids[10];
long tmpDataBytes = dataBytes;
2007-10-05 21:00:44 +02:00
dataBytes = 0;
memcpy(&tmpMostActivePids, &mostActivePids, sizeof(tmpMostActivePids));
2007-10-05 21:00:44 +02:00
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",
tmpDataBytes,
tmpMostActivePids[0].pid, tmpMostActivePids[0].DataAmount,
tmpMostActivePids[1].pid, tmpMostActivePids[1].DataAmount,
tmpMostActivePids[2].pid, tmpMostActivePids[2].DataAmount);
2007-10-05 21:00:44 +02:00
}
int SortFunc(const void* data1, const void* data2)
{
2007-10-06 00:23:56 +02:00
//debug("cIptvDeviceStatistics::SortFunc()\n");
2007-10-05 21:00:44 +02:00
pidStruct *comp1 = (pidStruct*)data1;
pidStruct *comp2 = (pidStruct*)data2;
if (comp1->DataAmount > comp2->DataAmount)
return 1;
if (comp1->DataAmount < comp2->DataAmount)
return -1;
return 0;
}
void cIptvDeviceStatistics::UpdateActivePids(u_short pid, long payload)
{
2007-10-06 00:23:56 +02:00
//debug("cIptvDeviceStatistics::UpdateActivePids()\n");
2007-10-05 21:00:44 +02:00
const int numberOfElements = sizeof(mostActivePids) / sizeof(pidStruct);
// If our statistic already is in the array, update it and quit
for (int i = 0; i < numberOfElements; ++i) {
if (mostActivePids[i].pid == pid) {
mostActivePids[i].DataAmount += payload;
// Now re-sort the array and quit
qsort(&mostActivePids, numberOfElements, sizeof(pidStruct), SortFunc);
return;
}
}
2007-10-05 21:00:44 +02:00
// Apparently our pid isn't in the array. Replace the last element with this
// one if new payload is greater
if (mostActivePids[numberOfElements - 1].DataAmount < payload) {
mostActivePids[numberOfElements - 1].pid = pid;
mostActivePids[numberOfElements - 1].DataAmount = payload;
// Re-sort
qsort(&mostActivePids, numberOfElements, sizeof(pidStruct), SortFunc);
}
2007-10-05 21:00:44 +02:00
}
// --- cIptvStreamerStatistics -----------------------------------------------
2007-10-05 21:00:44 +02:00
// Streamer statistic class
cIptvStreamerStatistics::cIptvStreamerStatistics()
: dataBytes(0)
2007-10-05 21:00:44 +02:00
{
debug("cIptvStreamerStatistics::cIptvStreamerStatistics()\n");
}
cIptvStreamerStatistics::~cIptvStreamerStatistics()
{
debug("cIptvStreamerStatistics::~cIptvStreamerStatistics()\n");
}
cString cIptvStreamerStatistics::GetStatistic(void)
2007-10-05 21:00:44 +02:00
{
debug("cIptvStreamerStatistics::GetStatistic()\n");
long tmpDataBytes = dataBytes;
2007-10-05 21:00:44 +02:00
dataBytes = 0;
return cString::sprintf("Stream data bytes: %ld\n", tmpDataBytes);
2007-10-05 21:00:44 +02:00
}