History log of /haiku/src/kits/media/MediaEventLooper.cpp
Revision Date Author Comments
# b84955d4 23-Oct-2018 Barrett17 <b.vitruvio@gmail.com>

media: Remove debug.h, finalize MediaDebug.h

* Funny rust from 0 AD.


# b8d4709e 08-Dec-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

MediaEventLooper: Remove soft real time lateness bounding

* The media_kit isn't an hard real time beast. Bounding lateness
looked like the perfect way to enable reasonable soft real time
performance and thus limiting port writes and reads between producers
and consumers. It seems to don't work very well so I just remove it.
* The result of the recent code simplification makes it equal to my
first version, before any discussion on it happened.
* Thanks to AlienSoldier for testing such issues.
* Fixes #13069.


# 3588e74a 19-Oct-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Return to simple lateness computation

* Remove enqueue_time again.
* Lateness seems generally useless. No way to get something useful
experimentally. The commit noise however was useful, the port wait is
behaving more in accordance with the lateness calculus.
* Fixes #12817 and possibly #12594.


# 51c8ec34 16-May-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

MediaKit and MediaPlayer Style Fixes

* Suggested by korli, thanks!


# b18c4449 07-May-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper::SetBufferDuration: Clamp if negative

* For the sake of making the code more backward compatible,
and safer eventually.


# f2bb946b 07-May-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Handle events in past differently

* When the loop didn't handle an event in performance time, we will
attempt at reading the port only if there are messages using a null
timeout.


# e042d9eb 07-May-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

MediaEventLooper: Calculate lateness from the nearest value

* When the event is late there are two major situations, the first
is when the enqueue time is in past compared to the performance time.
The second happen when the performance time is in past compared to the
enqueue time. The purpose of this change is to calculate the lateness
considering always the nearest of the two values. This way the exceding
latency is trimmed out from the calculus depending on what the actual
source of delay is.
* There is a lot more that could be done by looking at the previous
lateness value.


# 4666afbf 11-Feb-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Revert recent timeout rework

* While on my system it looked like to run well, it introduced
a regression on some hardware. I'm reverting it as I don't have
a better solution, with the difference that we will do that only
for perfomance time events.
* Fixes #12624.


# 801b3e3b 07-Feb-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

MediaEventLooper: Add more safeness on exit

* The WaitForMessage is moved at the end of the loop, and
the check for quitting the loop is moved as it's condition,
this makes us to be sure that once a Quit() request is performed
we will not handle events anymore.
* Other minor style and initialization fixes.


# 138a8026 02-Feb-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

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.


# bb1f15aa 01-Feb-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Better solution for negative timestamp

* This problem happens only at the startup, so that it's
preferred that we deal with it in the BMediaEventLooper side.
* This solve some audio stability problems I had with slow systems.


# ffeb987d 30-Jan-2016 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Make lateness calculus in real time

* After having this patch applied locally for some time,
I'm going to be sure that we have to deal only with real_time values.
* Since RealTime() is just a system_time() wrapper, the code
will be slightly improved in performances too.
* Additionally it performs very well when the thread is
externally stopped (such as debugging it), so that the audio
recover almost immediately.


# 5e726ed4 21-Sep-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

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.


# be7d9d3f 27-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: With B_WOULD_BLOCK we may still handle an event


# dfe056fd 25-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Continue code improvements.


# b0ed3239 03-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper::ControlLoop: Review style/logic, no functional change

* The code is just reversed to be better organized.
* Since the first event will be handled after a port write, at thread
spawn we just wait with infinite timeout for new messages.
* Remove goto which then become a continue.
* This permitted to remove the double waitUntil assignment which
was in different braces.
* lateness var become tempLateness, so it become more obvious than
before that it's a cached value and we are doing this to avoid
double calculus.


# 7771139c 02-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Rewrite ControlLoop()

* The first problem was the O(n^2) complexity of the algorithm, it's
now linear and try to act in a circular way by dispatching
events and reading the port in a balanced way. This exclude
a certain degree of possible deadlocks.
* Add detection and escape when the system try to kill the
thread. This solve some blocking issues on exit et similia
that i had with libjackcompat.
* The algorithm choose soon which event to focus on.
* Lateness is calculated just before the event is dispatched
as it is the more appropriate place, otherwise we would be
calculating something imprecise/guessed.
* Remove timed_event_queue::queued_time. It's more precise to
just use the RealTime() before to Dispatch the event.
* It should solve the BSoundPlayer lateness problems.
* With those improvements the media_kit is not going to lock
completely under stress conditions, instead it try to work
in a best effort shape.
* There's still room for improvements, for example i'm considering some
strategies in lateness situations such as update scheduling latency,
try to decrease waiting time and detect when we are too early on
the other hand to recover when the load go down.
* Thanks to Julian Harnath for sharing his WIP patch which helped
with some controls such as avoiding negative lateness.
* Comments are welcome!


# 75486484 09-Apr-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

Implement BMediaRoster::SyncToNode


# 179c6ec2 23-Apr-2014 Adrien Destugues <pulkomandy@pulkomandy.tk>

Remove some traces sent to application stdout.

* This may be fine in media server where it lands in logs, but certainly
not when the code is run in applications.
* Helps with all media-related webkit tests.


# 332cc6bc 30-Nov-2012 Axel Dörfler <axeld@pinc-software.de>

64 bit fixes for libmedia.so, ActivityMonitor, and Sudoku.

* Alex, I feel your pain :-)


# ba5e652d 03-Nov-2011 Adrien Destugues <pulkomandy@pulkomandy.ath.cx>

Set of patches by Pete Goodeve to imrpove the handling of audio latency.
Closes #7285.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43164 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a74d9260 26-Apr-2008 Jérôme Duval <korli@users.berlios.de>

style cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25173 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7dc1efb 09-Mar-2006 Marcus Overhagen <marcusoverhagen@gmail.com>

removed port unblock workaround, as port API should work now similar to BeOS R5


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16671 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3bb81a42 07-Mar-2006 Marcus Overhagen <marcusoverhagen@gmail.com>

Fixed deadlock that occured when quitting media applications.
I don't know why this never happened on R5. Haiku close_port()
works as documented in BeBook, but might possibly different in R5.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16629 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 51e7b01f 01-Oct-2003 beveloper <beveloper@nowhere.fake>

changed timeout calculation


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4918 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 71c77b48 07-Sep-2003 beveloper <beveloper@nowhere.fake>

latency calculation is now done in realtime


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4543 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d91580cd 30-Aug-2003 beveloper <beveloper@nowhere.fake>

removed/fixed warnings


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4418 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5ac4fbd7 19-Jun-2003 beveloper <beveloper@nowhere.fake>

clean up of debugging functions
FATAL is now replaced by ERROR and active at DEBUG=1 or above
TRACE is active at 2 or above
PRINT(level, ...) can be used for DEBUG= level or abode
INFO is removed


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3578 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0703a47 03-Jun-2003 beveloper <beveloper@nowhere.fake>

fixed BSoundPlayer::Stop() bugs exposed by CL-Amp


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3413 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5917dd5b 01-Jun-2003 beveloper <beveloper@nowhere.fake>

various timing related bugfixes


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3395 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1ab3e018 30-May-2003 beveloper <beveloper@nowhere.fake>

bugfixes and debug information


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3390 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9bedd42c 29-May-2003 beveloper <beveloper@nowhere.fake>

many fixes to improve timing


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3386 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 255a01c7 14-Apr-2003 beveloper <beveloper@nowhere.fake>

Added a new license to this file, as I'm the author.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3068 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cf4e2277 14-Mar-2003 beveloper <beveloper@nowhere.fake>

fixing BMediaRoster::ReleaseNode()


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2915 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d2ecd5a9 14-Mar-2003 beveloper <beveloper@nowhere.fake>

code style cleanup


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b6de9d11 12-Jul-2002 beveloper <beveloper@nowhere.fake>

removed compiler warnings


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@138 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a38012 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5e726ed44299f243b5bf4e07a449cca861e4504c 21-Sep-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

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.


# be7d9d3f5d23570f02de6853c781a9a56b13397b 27-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: With B_WOULD_BLOCK we may still handle an event


# dfe056fd6a5218b77449842bdb8c8b9099b836f7 25-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Continue code improvements.


# b0ed3239243cf00692f5982482f0ddaa181356fa 03-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper::ControlLoop: Review style/logic, no functional change

* The code is just reversed to be better organized.
* Since the first event will be handled after a port write, at thread
spawn we just wait with infinite timeout for new messages.
* Remove goto which then become a continue.
* This permitted to remove the double waitUntil assignment which
was in different braces.
* lateness var become tempLateness, so it become more obvious than
before that it's a cached value and we are doing this to avoid
double calculus.


# 7771139cdf652d3712c0b96b8e9e2dda6db6191e 02-Aug-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

BMediaEventLooper: Rewrite ControlLoop()

* The first problem was the O(n^2) complexity of the algorithm, it's
now linear and try to act in a circular way by dispatching
events and reading the port in a balanced way. This exclude
a certain degree of possible deadlocks.
* Add detection and escape when the system try to kill the
thread. This solve some blocking issues on exit et similia
that i had with libjackcompat.
* The algorithm choose soon which event to focus on.
* Lateness is calculated just before the event is dispatched
as it is the more appropriate place, otherwise we would be
calculating something imprecise/guessed.
* Remove timed_event_queue::queued_time. It's more precise to
just use the RealTime() before to Dispatch the event.
* It should solve the BSoundPlayer lateness problems.
* With those improvements the media_kit is not going to lock
completely under stress conditions, instead it try to work
in a best effort shape.
* There's still room for improvements, for example i'm considering some
strategies in lateness situations such as update scheduling latency,
try to decrease waiting time and detect when we are too early on
the other hand to recover when the load go down.
* Thanks to Julian Harnath for sharing his WIP patch which helped
with some controls such as avoiding negative lateness.
* Comments are welcome!


# 75486484201a2b4ebbffc34d868679d270b0f170 09-Apr-2015 Dario Casalinuovo <b.vitruvio@gmail.com>

Implement BMediaRoster::SyncToNode


# 179c6ec2fd0886dc6560f6c79f77e109e2ce13d7 23-Apr-2014 Adrien Destugues <pulkomandy@pulkomandy.tk>

Remove some traces sent to application stdout.

* This may be fine in media server where it lands in logs, but certainly
not when the code is run in applications.
* Helps with all media-related webkit tests.


# 332cc6bc3b696473169bb9e43340b69a0a3fc4f1 30-Nov-2012 Axel Dörfler <axeld@pinc-software.de>

64 bit fixes for libmedia.so, ActivityMonitor, and Sudoku.

* Alex, I feel your pain :-)


# ba5e652d79a41a15230b0940003e7dc352b41974 03-Nov-2011 Adrien Destugues <pulkomandy@pulkomandy.ath.cx>

Set of patches by Pete Goodeve to imrpove the handling of audio latency.
Closes #7285.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43164 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a74d92608dde5b000f147cbd14a59b75488c5267 26-Apr-2008 Jérôme Duval <korli@users.berlios.de>

style cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25173 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a7dc1efbac42dc3e0de63867b89db26b044218f2 09-Mar-2006 Marcus Overhagen <marcusoverhagen@gmail.com>

removed port unblock workaround, as port API should work now similar to BeOS R5


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16671 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3bb81a42394316b1c88bb7ce4ee51c1740fca9b2 07-Mar-2006 Marcus Overhagen <marcusoverhagen@gmail.com>

Fixed deadlock that occured when quitting media applications.
I don't know why this never happened on R5. Haiku close_port()
works as documented in BeBook, but might possibly different in R5.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16629 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 51e7b01fac9470ce8ff17de65e4dc615c9d33dd1 01-Oct-2003 beveloper <beveloper@nowhere.fake>

changed timeout calculation


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4918 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 71c77b48dd8c50a8015e64877e73451554992401 07-Sep-2003 beveloper <beveloper@nowhere.fake>

latency calculation is now done in realtime


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4543 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d91580cd9a9f39e74f086d5ca31d997a56c111a9 30-Aug-2003 beveloper <beveloper@nowhere.fake>

removed/fixed warnings


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4418 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5ac4fbd70dc5b5387cc80965de796deb820d4f05 19-Jun-2003 beveloper <beveloper@nowhere.fake>

clean up of debugging functions
FATAL is now replaced by ERROR and active at DEBUG=1 or above
TRACE is active at 2 or above
PRINT(level, ...) can be used for DEBUG= level or abode
INFO is removed


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3578 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a0703a47ce03792b3981bb6c2f4b8af443dec619 03-Jun-2003 beveloper <beveloper@nowhere.fake>

fixed BSoundPlayer::Stop() bugs exposed by CL-Amp


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3413 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5917dd5b85eed661e5d9297c8eb8979bf304b6dc 01-Jun-2003 beveloper <beveloper@nowhere.fake>

various timing related bugfixes


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3395 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1ab3e018978a65e71ffe20141d51ae4e591f67de 30-May-2003 beveloper <beveloper@nowhere.fake>

bugfixes and debug information


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3390 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9bedd42cd1e0fdb44e39be7ef4f3c76786d59b50 29-May-2003 beveloper <beveloper@nowhere.fake>

many fixes to improve timing


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3386 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 255a01c76a3ddc38d2c6cae806c4148b9bf022d4 14-Apr-2003 beveloper <beveloper@nowhere.fake>

Added a new license to this file, as I'm the author.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3068 a95241bf-73f2-0310-859d-f6bbb57e9c96


# cf4e22778668a91fead7c7573d531d5d1fac8a12 14-Mar-2003 beveloper <beveloper@nowhere.fake>

fixing BMediaRoster::ReleaseNode()


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2915 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d2ecd5a91c08b5d2ef2daab2a3ac8dba2e5abd9d 14-Mar-2003 beveloper <beveloper@nowhere.fake>

code style cleanup


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2914 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b6de9d11ff1c98de319f0c4f93ae3ceb9a33556f 12-Jul-2002 beveloper <beveloper@nowhere.fake>

removed compiler warnings


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@138 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a380120846174213ccce9c4aab0dda17c72083 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96