Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MythTV/mythtv
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Harrison committed Jun 5, 2011
2 parents a4c8189 + e0122d8 commit b63b46c
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 105 deletions.
20 changes: 18 additions & 2 deletions mythtv/libs/libmythbase/msocketdevice.cpp
Expand Up @@ -189,7 +189,11 @@ MSocketDevice::MSocketDevice( Type type )
this, type );
#endif
init();
//setSocket( createNewSocket(), type );

// For the time being, if it's of type Datagram create the socket now
// rather than later during connect (since there wont be one with udp)
if (type == Datagram)
setSocket( createNewSocket(), type );
}

/*!
Expand Down Expand Up @@ -549,7 +553,19 @@ quint16 MSocketDevice::port() const
*/
QHostAddress MSocketDevice::address() const
{
return a;

QString ipaddress;
if (a.toString().startsWith("0:0:0:0:0:FFFF:"))
{
Q_IPV6ADDR addr = a.toIPv6Address();
// addr contains 16 unsigned characters

ipaddress = QString("%1.%2.%3.%4").arg(addr[12]).arg(addr[13]).arg(addr[14]).arg(addr[15]);
}
else
ipaddress = a.toString();

return QHostAddress(ipaddress);
}


Expand Down
30 changes: 29 additions & 1 deletion mythtv/libs/libmythtv/dbcheck.cpp
Expand Up @@ -21,7 +21,7 @@ using namespace std;
mythtv/bindings/perl/MythTV.pm
*/
/// This is the DB schema version expected by the running MythTV instance.
const QString currentDatabaseVersion = "1276";
const QString currentDatabaseVersion = "1277";

static bool UpdateDBVersionNumber(const QString &newnumber, QString &dbver);
static bool performActualUpdate(
Expand Down Expand Up @@ -5717,6 +5717,34 @@ NULL
return false;
}

if (dbver == "1276")
{
const char *updates[] = {
"ALTER TABLE record ADD COLUMN filter INT UNSIGNED NOT NULL DEFAULT 0;",
"CREATE TABLE IF NOT EXISTS recordfilter ("
" filterid INT UNSIGNED NOT NULL PRIMARY KEY,"
" description VARCHAR(64) DEFAULT NULL,"
" clause VARCHAR(256) DEFAULT NULL,"
" newruledefault TINYINT(1) DEFAULT 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (0, 'New episode', 'program.previouslyshown = 0', 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (1, 'Identifiable episode', 'program.generic = 0', 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (2, 'First showing', 'program.first > 0', 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (3, 'Primetime', 'HOUR(program.starttime) >= 19 AND HOUR(program.starttime) < 23', 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (4, 'Commercial free', 'channel.commmethod = -2', 0);",
"INSERT INTO recordfilter (filterid, description, clause, newruledefault) "
" VALUES (5, 'High definition', 'program.hdtv > 0', 0);",
NULL
};

if (!performActualUpdate(updates, "1277", dbver))
return false;
}

return true;
}

Expand Down
83 changes: 36 additions & 47 deletions mythtv/libs/libmythtv/jitterometer.cpp
Expand Up @@ -7,8 +7,8 @@

#include "jitterometer.h"

Jitterometer::Jitterometer(const char *nname, int ncycles) :
count(0), num_cycles(ncycles), starttime_valid(0)
Jitterometer::Jitterometer(const char *nname, int ncycles)
: count(0), num_cycles(ncycles), starttime_valid(0)
{
times = (unsigned*) malloc(ncycles * sizeof(unsigned));
memset(&starttime, 0, sizeof(struct timeval));
Expand All @@ -21,76 +21,65 @@ Jitterometer::Jitterometer(const char *nname, int ncycles) :

Jitterometer::~Jitterometer()
{
free(times);
free(name);
free(times);
free(name);
}

bool Jitterometer::RecordCycleTime()
{
bool ret = RecordEndTime();
RecordStartTime();

return ret;
bool ret = RecordEndTime();
RecordStartTime();
return ret;
}

bool Jitterometer::RecordEndTime()
{
struct timeval timenow;

gettimeofday(&timenow, NULL);
struct timeval timenow;
gettimeofday(&timenow, NULL);

if (starttime_valid)
if (starttime_valid)
{
times[count] =
(timenow.tv_sec - starttime.tv_sec ) * 1000000 +
(timenow.tv_usec - starttime.tv_usec) ;

//printf("recorded timediff '%d'\n", times[count]);

count++;
times[count] = (timenow.tv_sec - starttime.tv_sec ) * 1000000 +
(timenow.tv_usec - starttime.tv_usec) ;
count++;
}

starttime_valid = 0;
starttime_valid = 0;

if (count==num_cycles)
if (count == num_cycles)
{
/* compute and display stuff, reset count to -1 */

double mean = 0, sum_of_squared_deviations=0;
double standard_deviation;
double fps = 0, tottime = 0;
int i;
/* compute and display stuff, reset count to -1 */
double mean = 0, sum_of_squared_deviations=0;
double standard_deviation;
double fps = 0, tottime = 0;
int i;

/* compute the mean */
for(i=0; i<num_cycles; i++)
{
mean += times[i];
}
tottime = mean;
mean /= num_cycles;
/* compute the mean */
for(i = 0; i < num_cycles; i++)
mean += times[i];

fps = num_cycles / tottime * 1000000;
tottime = mean;
mean /= num_cycles;

/* compute the sum of the squares of each deviation from the mean */
for(i=0; i<num_cycles;i++)
{
sum_of_squared_deviations += (mean - times[i]) * (mean - times[i]);
}
fps = num_cycles / tottime * 1000000;

/* compute standard deviation */
standard_deviation = sqrt(sum_of_squared_deviations / (num_cycles - 1));
/* compute the sum of the squares of each deviation from the mean */
for(i = 0; i < num_cycles; i++)
sum_of_squared_deviations += (mean - times[i]) * (mean - times[i]);

printf("'%s' mean = '%.2f', std. dev. = '%.2f', fps = '%.2f'\n", name, mean, standard_deviation, fps);
/* compute standard deviation */
standard_deviation = sqrt(sum_of_squared_deviations / (num_cycles - 1));

count = 0;
printf("'%s' mean = '%.2f', std. dev. = '%.2f', fps = '%.2f'\n", name, mean, standard_deviation, fps);

return true;
count = 0;
return true;
}
return false;
}

void Jitterometer::RecordStartTime()
{
gettimeofday(&starttime, NULL);
starttime_valid = 1;
gettimeofday(&starttime, NULL);
starttime_valid = 1;
}
88 changes: 40 additions & 48 deletions mythtv/libs/libmythtv/jitterometer.h
@@ -1,60 +1,52 @@
#ifndef JITTEROMETER_H
#define JITTEROMETER_H

/* Jitterometer usage. There are 2 ways to use this:
------------------------------------------------------------------
1. Every 100 iterations of the for loop, RecordCycleTime() will
print a report about the mean time to execute the loop, and
the jitter in the recorded times.
my_jmeter = new Jitterometer("forloop", 100);
for ( ) {
... some stuff ...
my_jmeter->RecordCycleTime();
}
-------------------------------------------------------------------
2. Every 42 times Weird_Operation() is run, RecordEndTime() will
print a report about the mean time to do a Weird_Operation(), and
the jitter in the recorded times.
beer = new Jitterometer("weird operation", 42);
for( ) {
...
beer->RecordStartTime();
Weird_Operation();
beer->RecordEndTime();
...
}
*/

class Jitterometer
{
public:
Jitterometer(const char *name, int num_cycles);
~Jitterometer();
public:
Jitterometer(const char *name, int num_cycles);
~Jitterometer();


/* Jitterometer usage. There are 2 ways to use this:
------------------------------------------------------------------
1. Every 100 iterations of the for loop, RecordCycleTime() will
print a report about the mean time to execute the loop, and
the jitter in the recorded times.
my_jmeter = new Jitterometer("forloop", 100);
for ( ) {
... some stuff ...
my_jmeter->RecordCycleTime();
}
-------------------------------------------------------------------
2. Every 42 times Weird_Operation() is run, RecordEndTime() will
print a report about the mean time to do a Weird_Operation(), and
the jitter in the recorded times.
beer = new Jitterometer("weird operation", 42);
for( ) {
...
beer->RecordStartTime();
Weird_Operation();
beer->RecordEndTime();
...
}
*/

bool RecordCycleTime();

void RecordStartTime();
bool RecordEndTime();
bool RecordCycleTime();
void RecordStartTime();
bool RecordEndTime();

private:
int count;
int num_cycles;

struct timeval starttime;
int starttime_valid;
unsigned *times; // array of cycle lengths, in uS

char *name;
int count;
int num_cycles;
struct timeval starttime;
int starttime_valid;
unsigned *times; // array of cycle lengths, in uS
char *name;
};

#endif // JITTEROMETER_H
Expand Down
7 changes: 3 additions & 4 deletions mythtv/libs/libmythupnp/upnpdevice.cpp
Expand Up @@ -357,14 +357,13 @@ void UPnpDeviceDesc::GetValidXML(
QString BaseAddr;
QHostAddress addr(sBaseAddress);

BaseAddr = sBaseAddress;

#if !defined(QT_NO_IPV6)
// Basically if it appears to be an IPv6 IP surround the IP with [] otherwise don't bother
if (( addr.protocol() == QAbstractSocket::IPv6Protocol ) || (sBaseAddress.contains(":")))
if (sBaseAddress.contains(":"))
BaseAddr = "[" + sBaseAddress + "]";
else
#endif
if ( addr.protocol() == QAbstractSocket::IPv4Protocol )
BaseAddr = sBaseAddress;

os << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\" xmlns:mythtv=\"mythtv.org\">\n"
Expand Down
10 changes: 8 additions & 2 deletions mythtv/libs/libmythupnp/upnptasksearch.cpp
Expand Up @@ -108,9 +108,15 @@ void UPnpSearchTask::SendMsg( MSocketDevice *pSocket,
it != m_addressList.end();
++it )
{
QString ipaddress = *it;

// If this looks like an IPv6 address, then enclose it in []'s
if (ipaddress.contains(":"))
ipaddress = "[" + ipaddress + "]";

QString sHeader = QString ( "HTTP/1.1 200 OK\r\n"
"LOCATION: http://[%1]:%2/getDeviceDesc\r\n" )
.arg( *it )
"LOCATION: http://%1:%2/getDeviceDesc\r\n" )
.arg( ipaddress )
.arg( m_nServicePort);


Expand Down
19 changes: 18 additions & 1 deletion mythtv/programs/mythbackend/scheduler.cpp
Expand Up @@ -3224,6 +3224,21 @@ void Scheduler::UpdateMatches(int recordid) {
return;
}

QString filterClause;
query.prepare("SELECT filterid, clause FROM recordfilter "
"WHERE filterid >= 0 AND filterid < 12 AND "
" TRIM(clause) <> ''");
if (!query.exec())
{
MythDB::DBError("UpdateMatches", query);
return;
}
while (query.next())
{
filterClause += QString(" AND (((RECTABLE.filter & %1) = 0) OR (%2))")
.arg(1 << query.value(0).toInt()).arg(query.value(1).toString());
}

// Make sure all FindOne rules have a valid findid before scheduling.
query.prepare("SELECT NULL from record "
"WHERE type = :FINDONE AND findid <= 0;");
Expand Down Expand Up @@ -3275,7 +3290,9 @@ void Scheduler::UpdateMatches(int recordid) {
" AND (NOT ((RECTABLE.dupin & %3) AND (program.previouslyshown "
" OR program.first = 0))) ")
.arg(kDupsExRepeats).arg(kDupsExGeneric).arg(kDupsFirstNew) +
QString(" AND channel.visible = 1 AND "
QString(" AND channel.visible = 1 ") +
filterClause + QString(" AND "

"((RECTABLE.type = %1 " // allrecord
"OR RECTABLE.type = %2 " // findonerecord
"OR RECTABLE.type = %3 " // finddailyrecord
Expand Down

0 comments on commit b63b46c

Please sign in to comment.