BMediaEventLooper: Use enqueue_time in a different shape
* This is the only solution that allowed to use the best of both ways to do this calculus. I've also tested it with a modified sound player that snoozed every time the buffer should be handled, and found that neither of the lateness calculus I tested (including enqueue_time) really solve all problems. That's why I've tried to find an average solution. There's still room for improvements eventually.
This commit is contained in:
@@ -38,8 +38,9 @@ struct media_timed_event {
|
|||||||
int32 data;
|
int32 data;
|
||||||
int64 bigdata;
|
int64 bigdata;
|
||||||
char user_data[64];
|
char user_data[64];
|
||||||
|
bigtime_t enqueue_time;
|
||||||
|
|
||||||
uint32 _reserved_media_timed_event_[8];
|
uint32 _reserved_media_timed_event_[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -242,11 +242,24 @@ BMediaEventLooper::ControlLoop()
|
|||||||
err = fRealTimeQueue.RemoveFirstEvent(&event);
|
err = fRealTimeQueue.RemoveFirstEvent(&event);
|
||||||
|
|
||||||
if (err == B_OK) {
|
if (err == B_OK) {
|
||||||
// We are going to do this calculus in real time
|
// The general idea of lateness is to allow
|
||||||
// because otherwise we could get erroneous values.
|
// the client code to detect when the buffer
|
||||||
// This calculus allow us to detect both early and late
|
// is handled late or early. What we add is
|
||||||
// buffers, this is the meaning of the lateness concept.
|
// that the code log the time at which the
|
||||||
bigtime_t lateness = waitUntil - TimeSource()->RealTime();
|
// current event is added to the queue. This
|
||||||
|
// allow us to detect cyclic/stagnant latency
|
||||||
|
// in the meantime, so that the client can
|
||||||
|
// notify to the producer only the portion
|
||||||
|
// that might be attributable.
|
||||||
|
bigtime_t lateness = 0;
|
||||||
|
if (waitUntil > 0) {
|
||||||
|
lateness = waitUntil - TimeSource()->RealTime();
|
||||||
|
if (lateness > 0) {
|
||||||
|
bigtime_t enqueueLatency = event.enqueue_time - waitUntil;
|
||||||
|
if (enqueueLatency > 0)
|
||||||
|
lateness += enqueueLatency;
|
||||||
|
}
|
||||||
|
}
|
||||||
DispatchEvent(&event, -lateness, hasRealtime);
|
DispatchEvent(&event, -lateness, hasRealtime);
|
||||||
}
|
}
|
||||||
} else if (err != B_OK)
|
} else if (err != B_OK)
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ _event_queue_imp::AddEvent(const media_timed_event &event)
|
|||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_cast<media_timed_event&>(event).enqueue_time =
|
||||||
|
BTimeSource::RealTime();
|
||||||
|
|
||||||
//create a new queue
|
//create a new queue
|
||||||
if (fFirstEntry == NULL) {
|
if (fFirstEntry == NULL) {
|
||||||
ASSERT(fEventCount == 0);
|
ASSERT(fEventCount == 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user