[mythtv-users] Audio Video Sync on v31 and Alsa Buffer Size

Stephen Worthington stephen_agent at jsw.gen.nz
Sun Jun 7 10:23:50 UTC 2020


On Thu, 04 Jun 2020 05:19:24 +1200, you wrote:

It looks like this problem is a bit more complicated than I thought.
While MythTV is playing a file, even root is unable to change the
prealloc buffer setting.  So if you run my audio-prealloc.sh file from
the LiveTVStarted or PlayStarted events, mythfrontend has already got
the audio device open and the setting does not get changed.  If you
pause playback, the audio device remains under mythfrontend's control
and the prealloc buffer setting still can not be changed.  So the best
fix I can come up with is to run audio-prealloc.sh at boot and then
from the LiveTVStopped and PlayStopped events.  That means that if you
get symptoms of the buffer being too small during playback, such as
some sorts of juddering, if you stop and restart playback, the audio
prealloc buffer setting will have been fixed and it should work on the
second try.

During testing this, I have also noticed that the setting that
mythfrontend recommends changes depending on what recording you are
playing.  For my main MythTV system, I have seen values from 168 to
32768 (the maximum possible value) recommended.  So having the setting
correct for one recording does not necessarily fix it for a subsequent
recording which might want a larger value.  So I am now wondering if
it would not be best to just set the audio prealloc to 32768 and leave
it at that.  Does anyone know if there are any bad consequences from
setting the prealloc that high?

To further complicate things, if you change the audio device that
MythTV is using (say you plug in a TV with audio over HDMI and you
switch to using that, instead of the motherboard audio device(s)),
then the prealloc will need to be set for the new device.

To run audio-prealloc.sh at boot and from the *Stopped events, the
following commands should work on Ubuntu.  If you do not already have
these files installed, the rm commands will cause error messages -
just ignore them.  If you already have some of the files, they will be
removed and the new versions installed.  The new versions are
compatible with the old versions - they just have support for
audio-prealloc.sh added.

sudo su
cd /etc/sudoers.d
rm mythtv-systemctl-helper
wget http://www.jsw.gen.nz/mythtv/mythtv-systemctl-helper
chown root:root mythtv-systemctl-helper
chmod u,g=r mythtv-systemctl-helper
cd /usr/local/bin
rm mythtv-systemctl-helper.sh
wget http://www.jsw.gen.nz/mythtv/mythtv-systemctl-helper.sh
chown root:mythtv
chmod ug=rx,o= mythtv-systemctl-helper.sh
rm audio-prealloc.sh
wget http://www.jsw.gen.nz/mythtv/audio-prealloc.sh
chown root:root audio-prealloc.sh
chmod ug=rwx,o=r audio-prealloc.sh
cd /etc/systemd/system
rm audio-prealloc.service
wget http://www.jsw.gen.nz/mythtv/audio-prealloc.service
chown root:root audio-prealloc.service
chmod u=rw,go=r audio-prealloc.service
systemctl enable audio-prealloc.service
systemctl start audio-prealloc.service

Then you have to set up the events in mythfrontend:

Setup > System Event Handlers > Live TV ended
Setup > System Event Handlers > Playback stopped

For each of those events, set the command to be:

sudo systemctl start audio-prealloc

If (like me) you are already using those events, you will need to
create a script file run from each event which does the "sudo
systemctl start audio-prealloc" command and also whatever else you
want to happen on that event.

To see what the audio-prealloc service has done, look at its journal:

sudo journalctl -eu audio-prealloc

If there are any error messages they should show up there, and you
will be able to see when the service was run.  If you want to manually
run audio-prealloc, start it with systemctl:

sudo systemctl start audio-prealloc


More information about the mythtv-users mailing list