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:
beveloper
2003-09-07 22:36:21 +00:00
parent 1df08d394c
commit 71c77b48dd
+14 -8
View File
@@ -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);
} }
} }
@@ -413,6 +416,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());
@@ -452,7 +458,7 @@ BMediaEventLooper::DispatchEvent(const media_timed_event *event,
{ {
PRINT(6, "CALLED BMediaEventLooper::DispatchEvent()\n"); PRINT(6, "CALLED BMediaEventLooper::DispatchEvent()\n");
HandleEvent(event,lateness,realTimeEvent); HandleEvent(event, lateness, realTimeEvent);
switch (event->type) { switch (event->type) {
case BTimedEventQueue::B_START: case BTimedEventQueue::B_START: