[haiku-commits] haiku: hrev49662 - src/kits/media

  • From: b.vitruvio@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 26 Sep 2015 13:29:29 +0200 (CEST)

hrev49662 adds 2 changesets to branch 'master'
old head: 7e26adffc0b3cb9bde04c5b188448cda368ccdff
new head: 5e726ed44299f243b5bf4e07a449cca861e4504c
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=5e726ed44299+%5E7e26adffc0b3

----------------------------------------------------------------------------

8bffda1633c2: media_kit: Allow to set a NULL buffer group. Fixes #12305.

5e726ed44299: BMediaEventLooper: Finally fix some lateness problems

* For the moment i still remain with the classic lateness calculus.
My code wasn't perfect, but this commit fix the remaining
problems from my perspective.
* The first reason is that if we have a patologic latency
such as adding for experimental reasons a snooze() before a SendBuffer or
in the BufferReceived callback, we still can't do anything about it.
If we use enqueue_time and don't send a LateProducer notice, this latency
will never be detected by the API client. We can't do anything about it,
and it's even better that systems with such problems are recognized as
soon as possible IMO.
* The second reason is that the lateness calculus described in the BeBook
is done this way because the media_kit want us to adjust our timing in both
early and late situations.
* Realtime expect that things are always delivered under a certain time
limit, if the software at the bottom doesn't meet with this requirement,
it's just not realtime and things can't work in realtime.
* enqueue_time has nothing to do with the performance_time. But we can
still add this to the media_timed_event struct so that applications can
make use of it.
* Lateness was probably not used a lot in BeOS programs as it looks like
a relatively new feature but i have the concern to complete our API
implementation to be close to what i see was reasonably the designers aim.

[ Dario Casalinuovo <b.vitruvio@xxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 15 insertions(+), 9 deletions(-)
src/kits/media/BufferGroup.cpp | 4 ++--
src/kits/media/BufferProducer.cpp | 4 ++--
src/kits/media/MediaEventLooper.cpp | 16 +++++++++++-----

############################################################################

Commit: 8bffda1633c2ada9ae685b6ec0066834d317e2bb
URL: http://cgit.haiku-os.org/haiku/commit/?id=8bffda1633c2
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Mon Sep 21 12:49:39 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/12305

media_kit: Allow to set a NULL buffer group. Fixes #12305.

----------------------------------------------------------------------------

diff --git a/src/kits/media/BufferGroup.cpp b/src/kits/media/BufferGroup.cpp
index b196793..e589aa3 100644
--- a/src/kits/media/BufferGroup.cpp
+++ b/src/kits/media/BufferGroup.cpp
@@ -284,9 +284,9 @@ BBufferGroup::ReclaimAllBuffers()
// this has happened when the "fReclaimSem" can be aquired
"fBufferCount"
// times

- status_t status;
+ status_t status = B_ERROR;
do {
- status = acquire_sem_etc(fReclaimSem, count, 0, 0);
+ status = acquire_sem_etc(fReclaimSem, count,
B_RELATIVE_TIMEOUT, 0);
} while (status == B_INTERRUPTED);

if (status != B_OK)
diff --git a/src/kits/media/BufferProducer.cpp
b/src/kits/media/BufferProducer.cpp
index 3358a7b..101bc81 100644
--- a/src/kits/media/BufferProducer.cpp
+++ b/src/kits/media/BufferProducer.cpp
@@ -271,11 +271,11 @@ BBufferProducer::HandleMessage(int32 message, const void*
data, size_t size)
? new BBufferGroup(command->buffer_count,
command->buffers)
: NULL;

- if (group == NULL || group->InitCheck() != B_OK) {
+ if (group != NULL && group->InitCheck() != B_OK) {
ERROR("BBufferProducer::HandleMessage
PRODUCER_SET_BUFFER_GROUP"
" group InitCheck() failed.\n");
delete group;
- return B_OK;
+ group = NULL;
}
status_t status = SetBufferGroup(command->source,
group);
if (command->destination == media_destination::null)

############################################################################

Revision: hrev49662
Commit: 5e726ed44299f243b5bf4e07a449cca861e4504c
URL: http://cgit.haiku-os.org/haiku/commit/?id=5e726ed44299
Author: Dario Casalinuovo <b.vitruvio@xxxxxxxxx>
Date: Mon Sep 21 12:50:50 2015 UTC

BMediaEventLooper: Finally fix some lateness problems

* For the moment i still remain with the classic lateness calculus.
My code wasn't perfect, but this commit fix the remaining
problems from my perspective.
* The first reason is that if we have a patologic latency
such as adding for experimental reasons a snooze() before a SendBuffer or
in the BufferReceived callback, we still can't do anything about it.
If we use enqueue_time and don't send a LateProducer notice, this latency
will never be detected by the API client. We can't do anything about it,
and it's even better that systems with such problems are recognized as
soon as possible IMO.
* The second reason is that the lateness calculus described in the BeBook
is done this way because the media_kit want us to adjust our timing in both
early and late situations.
* Realtime expect that things are always delivered under a certain time
limit, if the software at the bottom doesn't meet with this requirement,
it's just not realtime and things can't work in realtime.
* enqueue_time has nothing to do with the performance_time. But we can
still add this to the media_timed_event struct so that applications can
make use of it.
* Lateness was probably not used a lot in BeOS programs as it looks like
a relatively new feature but i have the concern to complete our API
implementation to be close to what i see was reasonably the designers aim.

----------------------------------------------------------------------------

diff --git a/src/kits/media/MediaEventLooper.cpp
b/src/kits/media/MediaEventLooper.cpp
index c9c006d..5110b24 100644
--- a/src/kits/media/MediaEventLooper.cpp
+++ b/src/kits/media/MediaEventLooper.cpp
@@ -230,6 +230,10 @@ BMediaEventLooper::ControlLoop()
err = WaitForMessage(waitUntil);
if (err == B_TIMED_OUT
|| err == B_WOULD_BLOCK) {
+ // NOTE: The reference for doing the lateness calculus
this way can
+ // be found in the BeBook article "A BMediaEventLooper
Example".
+ // The value which we are going to calculate, is
referred there as
+ // 'lateness'.
media_timed_event event;
if (hasEvent)
err = fEventQueue.RemoveFirstEvent(&event);
@@ -237,11 +241,13 @@ BMediaEventLooper::ControlLoop()
err = fRealTimeQueue.RemoveFirstEvent(&event);

if (err == B_OK) {
- bigtime_t lateness = waitUntil -
TimeSource()->RealTime();
- if (lateness < 0)
- lateness = 0;
-
- DispatchEvent(&event, lateness, hasRealtime);
+ // We are going to do this calculus in
performance time
+ // because otherwise we could get erroneous
values.
+ // This calculus allow us to detect both early
and late
+ // buffers, this is the meaning of the lateness
concept.
+ bigtime_t lateness = event.event_time -
fEventLatency
+ - fSchedulingLatency -
TimeSource()->Now();
+ DispatchEvent(&event, -lateness, hasRealtime);
}
} else if (err != B_OK)
return;


Other related posts:

  • » [haiku-commits] haiku: hrev49662 - src/kits/media - b . vitruvio