[mythtv] [PATCH] live TV audio underrun/stutter bug workaround

Klaus Weidner kw at w-m-p.com
Mon Feb 14 08:46:40 UTC 2005


On Mon, Feb 14, 2005 at 01:57:44AM -0500, Isaac Richards wrote:
> On Sunday 13 February 2005 07:59 pm, Klaus Weidner wrote:
> > I've upgraded to 0.17 and now have the problem that some others have also
> > reported - switching channels when watching live TV almost always causes
> > the video to run at half speed, with the audio stuttering badly. The same
> > effect happens occasionally during recording playback as well.
> 
> Could you put a couple debug statements in the GetAudiotime() function to see 
> what's making it negative?  That'd help me figure out what's causing the 
> problem.

I think I got it, the variable "delay" in the ALSA getBufferedOnSoundcard
method didn't get initialized and the function occasionally returned
garbage data when the sound card was in an unexpected state. Shouldn't
there be a compiler warning for something like that?

  2005-02-14 02:30:49.536 Broadcasting free space avail
   soundcard_buffer=21472 totalbuffer=23520 audiotime=20275 audbuf_timecode=20397 audio_bytes_per_sample=4 audio_stretchfactor=1
  2005-02-14 02:30:49.552 audio waiting for buffer to fill: have 2048 want 4096
  2005-02-14 02:30:49.552 Broadcasting free space avail
  2005-02-14 02:30:49.569 prebuffering pause
  2005-02-14 02:30:49.569 waiting for prebuffer...
  2005-02-14 02:30:49.571 OutputAudioLoop: audio paused
  2005-02-14 02:30:49.571 47712 bytes free on soundcard
  [...]
  2005-02-14 02:30:50.092 61760 bytes free on soundcard
  2005-02-14 02:30:50.092 WriteAudio: Preparing 4096 bytes (1024 frames)
  2005-02-14 02:30:50.111 61280 bytes free on soundcard
  2005-02-14 02:30:50.122 _AddSamples bytes=4608, used=75777, free=436223, timecode=20781
  2005-02-14 02:30:50.125 _AddSamples bytes=4608, used=80385, free=431615, timecode=20805
  2005-02-14 02:30:50.128 _AddSamples bytes=4608, used=84993, free=427007, timecode=20829
  2005-02-14 02:30:50.131 OutputAudioLoop: Play Event
  FIXME: getBufferedOnSoundcard unexpected state 4, returning uninitialized delay 1097729063
   soundcard_buffer=95948956 totalbuffer=96038556 audiotime=-479347 audbuf_timecode=20853 audio_bytes_per_sample=4 audio_stretchfactor=1
  [...]
  2005-02-14 02:31:06.131 57344 bytes free on soundcard
  2005-02-14 02:31:06.171 OutputAudioLoop: Play Event
  2005-02-14 02:31:06.171 Broadcasting free space avail
  2005-02-14 02:31:06.171 WriteAudio: Preparing 4096 bytes (1024 frames)
  FIXME: getBufferedOnSoundcard unexpected state 2, returning uninitialized delay 1097729063
   soundcard_buffer=95948956 totalbuffer=95949468 audiotime=-499379 audbuf_timecode=357 audio_bytes_per_sample=4 audio_stretchfactor=1
  2005-02-14 02:31:06.171 audio waiting for buffer to fill: have 512 want 4096
  2005-02-14 02:31:06.171 Broadcasting free space avail
  FIXME: getBufferedOnSoundcard unexpected state 2, returning uninitialized delay 1097729063
   soundcard_buffer=95948956 totalbuffer=95949468 audiotime=-499379 audbuf_timecode=357 audio_bytes_per_sample=4 audio_stretchfactor=1
  2005-02-14 02:31:06.191 audio waiting for buffer to fill: have 512 want 4096
  2005-02-14 02:31:06.191 Broadcasting free space avail
  FIXME: got bogus value -499366 from getAudiotime()

A workaround patch is below - I haven't checked what the unexpected
status value means.

mythfrontend still crashes on me very frequently, but I'll let someone
else take a shot at that, I need sleep ;-)

-Klaus

--- mythtv-0.17/libs/libmyth/audiooutputalsa.cpp.orig	2005-02-14 02:23:45.000000000 -0600
+++ mythtv-0.17/libs/libmyth/audiooutputalsa.cpp	2005-02-14 02:32:48.000000000 -0600
@@ -222,6 +222,9 @@ inline int AudioOutputALSA::getBufferedO
         state == SND_PCM_STATE_DRAINING)
     {
         snd_pcm_delay(pcm_handle, &delay);
+    } else {
+	cerr << "FIXME: getBufferedOnSoundcard unexpected state " << state << ", returning uninitialized delay " << delay << endl;
+	return 0;
     }
 
     if (delay < 0)


More information about the mythtv-dev mailing list