latency calculation is now done in realtime
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4543 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -33,9 +33,6 @@
|
|||||||
#include <Buffer.h>
|
#include <Buffer.h>
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
// XXX The bebook says that the latency is always calculated in realtime
|
|
||||||
// XXX This is not currently done in this code
|
|
||||||
|
|
||||||
/*************************************************************
|
/*************************************************************
|
||||||
* protected BMediaEventLooper
|
* protected BMediaEventLooper
|
||||||
*************************************************************/
|
*************************************************************/
|
||||||
@@ -74,7 +71,11 @@ BMediaEventLooper::BMediaEventLooper(uint32 apiVersion) :
|
|||||||
BMediaEventLooper::NodeRegistered()
|
BMediaEventLooper::NodeRegistered()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
// don't call Run(); here, must be done by the derived class (yes, that's stupid)
|
// Calling Run() should be done by the derived class,
|
||||||
|
// at least that's how it is documented by the BeBook.
|
||||||
|
// It appears that BeOS R5 called it here. Calling Run()
|
||||||
|
// twice doesn't hurt, and some nodes need it to be called here.
|
||||||
|
Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -219,7 +220,7 @@ BMediaEventLooper::ControlLoop()
|
|||||||
// BMediaEventLooper compensates your performance time by adding the event latency
|
// BMediaEventLooper compensates your performance time by adding the event latency
|
||||||
// (see SetEventLatency()) and the scheduling latency (or, for real-time events,
|
// (see SetEventLatency()) and the scheduling latency (or, for real-time events,
|
||||||
// only the scheduling latency).
|
// only the scheduling latency).
|
||||||
// XXX well, fix this later
|
|
||||||
latency = fEventLatency + fSchedulingLatency;
|
latency = fEventLatency + fSchedulingLatency;
|
||||||
// printf("node %02d, latency %Ld\n", ID(), latency);
|
// printf("node %02d, latency %Ld\n", ID(), latency);
|
||||||
|
|
||||||
@@ -229,6 +230,7 @@ BMediaEventLooper::ControlLoop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fRealTimeQueue.HasEvents() && (TimeSource()->RealTimeFor(TimeSource()->Now(),fSchedulingLatency)) >= fRealTimeQueue.FirstEventTime()) {
|
if (fRealTimeQueue.HasEvents() && (TimeSource()->RealTimeFor(TimeSource()->Now(),fSchedulingLatency)) >= fRealTimeQueue.FirstEventTime()) {
|
||||||
|
latency = fSchedulingLatency;
|
||||||
is_realtime = true;
|
is_realtime = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -240,10 +242,11 @@ BMediaEventLooper::ControlLoop()
|
|||||||
}
|
}
|
||||||
if (fRealTimeQueue.HasEvents()) {
|
if (fRealTimeQueue.HasEvents()) {
|
||||||
bigtime_t temp;
|
bigtime_t temp;
|
||||||
temp = TimeSource()->RealTimeFor(TimeSource()->PerformanceTimeFor(fRealTimeQueue.FirstEventTime()), fSchedulingLatency);
|
temp = fRealTimeQueue.FirstEventTime() - fSchedulingLatency;
|
||||||
if (temp < waituntil) {
|
if (temp < waituntil) {
|
||||||
waituntil = temp;
|
waituntil = temp;
|
||||||
is_realtime = true;
|
is_realtime = true;
|
||||||
|
latency = fSchedulingLatency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = WaitForMessage(waituntil);
|
err = WaitForMessage(waituntil);
|
||||||
@@ -264,7 +267,7 @@ BMediaEventLooper::ControlLoop()
|
|||||||
if (is_realtime)
|
if (is_realtime)
|
||||||
lateness = TimeSource()->RealTime() - event.event_time;
|
lateness = TimeSource()->RealTime() - event.event_time;
|
||||||
else
|
else
|
||||||
lateness = TimeSource()->Now() + fEventLatency - event.event_time;
|
lateness = TimeSource()->RealTime() - TimeSource()->RealTimeFor(event.event_time, 0) + fEventLatency;
|
||||||
DispatchEvent(&event, lateness, is_realtime);
|
DispatchEvent(&event, lateness, is_realtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -414,6 +417,9 @@ BMediaEventLooper::Run()
|
|||||||
if (fControlThread != -1)
|
if (fControlThread != -1)
|
||||||
return; // thread already running
|
return; // thread already running
|
||||||
|
|
||||||
|
// until now, the run state is B_UNREGISTERED, but we need to start in B_STOPPED state.
|
||||||
|
SetRunState(B_STOPPED);
|
||||||
|
|
||||||
char threadName[32];
|
char threadName[32];
|
||||||
sprintf(threadName, "%.20s control", Name());
|
sprintf(threadName, "%.20s control", Name());
|
||||||
fControlThread = spawn_thread(_ControlThreadStart, threadName, fCurrentPriority, this);
|
fControlThread = spawn_thread(_ControlThreadStart, threadName, fCurrentPriority, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user