[haiku-bugs] Re: [Haiku] #7285: BSoundPlayer sends buffers late, with ever-increasing latency

  • From: "bonefish" <trac@xxxxxxxxxxxx>
  • Date: Thu, 10 Mar 2011 10:14:59 -0000

#7285: BSoundPlayer sends buffers late, with ever-increasing latency
------------------------------+-----------------------
   Reporter:  Pete            |      Owner:  axeld
       Type:  bug             |     Status:  new
   Priority:  normal          |  Milestone:  R1
  Component:  Kits/Media Kit  |    Version:  R1/alpha2
 Resolution:                  |   Keywords:
 Blocked By:                  |   Blocking:
Has a Patch:  0               |   Platform:  All
------------------------------+-----------------------

Comment (by bonefish):

 Replying to [comment:2 Pete]:
 > What I find completely mysterious, though, is -- what may be the root of
 the whole problem -- that the read_port_etc in WaitForMessage (called in
 MediaEventLooper's ControlLoop) sometimes times out 4-8 msec late! (About
 the same amount the latency keeps increasing by.)
 [...]
 > Note that the time of return is 8 msec later than requested!
 > I don't imagine this is expected behaviour in a B_URGENT_PRIORITY task?

 Unless some other thread with even higher priority is very busy, this
 shouldn't happen. If there isn't, disregarding kernel bugs, those
 latencies can only occur when interrupts are disabled for too long, for
 which there are two usual reasons: 1. Handling an interrupt takes too long
 -- which really is a bug too (likely in a driver). 2. You have serial
 debug output enabled. The latter could explain all the behavior you have
 reported. Since interrupts are disabled while writing to the serial port
 and writing even only a few characters takes a rather long time, this can
 easily cause the `read_port_etc()` latencies you encounter. It might also
 explain that the latency increases over time, since late buffers cause the
 mixer to print to the serial debug output, which in turn worsens the
 issue. At some point the adjusted downstream latency should be high enough
 to compensate for all of that, but the excessive serial debug output might
 affect the system enough to cause drivers to become unhappy and complain
 (to the serial debug output). The general system sluggishness would
 support such an assumption.

 So, long story short, if you have serial debug output enabled (the default
 for nightlies and self-built images), try to disable it and see how things
 go.

 Just in case serial debug output isn't the underlying cause, another
 common reason for ever-increasing/decreasing latencies is a mix-
 up/incorrect use of real time and performance time in computations, since
 the two usually drift apart slowly.

 Oh, and since you mentioned a perceivable latency, IIRC the last time I
 looked the multi-audio add-on played buffers a full buffer late. This
 isn't noticeable when just playing audio, but might be when watching a
 video or doing MIDI.

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/7285#comment:4>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: