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

Klaus Weidner kw at w-m-p.com
Mon Feb 14 00:59:33 UTC 2005


Hello,

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.

After a bit of digging around, I've noticed a very weird effect in that
the "lastaudiotime" value returned by audioOutput->GetAudiotime() is
occasionally a large negative number, which completely screws up the
avsync calculations. The patch below is a band aid that works around the
problem, but maybe someone with a better understanding of the code can
fix the real underlying problem.

Here are a couple of log extracts from running the frontend with "-v
playback,audio" (plus some additional debug statements I added):

  2005-02-12 23:22:52.251 _AddSamples bytes=4448, used=38781, free=473219, timecode=765
  lastaudiotime=-495406 buffer->timecode=367 delay=0 avsync_delay=495739
  avsync_adjustment=0 avsync_avg=123934 avsync_oldavg=123934750
  diverge=3714.4 frame_interval=33366 refreshrate=16665, warpfactor: 1.03544, warpfactor_avg: 1.03492
  2005-02-12 23:22:52.261 Changing from None to WatchingLiveTV
  2005-02-12 23:22:52.262 A/V diverged by 30 frames, extending frame to keep audio in sync
  [...]
  2005-02-12 23:22:52.324 audio waiting for space on soundcard: have 1536 need 4096
  lastaudiotime=352 buffer->timecode=400 delay=0 avsync_delay=15
  avsync_adjustment=0 avsync_avg=92954 avsync_oldavg=92954812
  diverge=2785.91 frame_interval=33366 refreshrate=16665, warpfactor: 1.03595, warpfactor_avg: 1.03492
  2005-02-12 23:22:52.326 A/V diverged by 30 frames, extending frame to keep audio in sync
  [...]
  2005-02-12 23:22:53.342 WriteAudio: buffer underrun
  [...]
  2005-02-12 23:22:53.387 Broadcasting free space avail
  lastaudiotime=-494494 buffer->timecode=934 delay=0 avsync_delay=495394
  avsync_adjustment=0 avsync_avg=217451 avsync_oldavg=217451552
  diverge=6517.16 frame_interval=33366 refreshrate=16665, warpfactor: 1.04427, warpfactor_avg: 1.03492

-Klaus

--- /home/mythtv/NuppelVideoPlayer-3.cpp	2005-02-12 23:33:09.000000000 -0600
+++ mythtv-0.17/libs/libmythtv/NuppelVideoPlayer.cpp	2005-02-13 00:03:08.000000000 -0600
@@ -1408,6 +1408,15 @@ void NuppelVideoPlayer::AVSync(void)
     {
         // ms, same scale as timecodes
         lastaudiotime = audioOutput->GetAudiotime();
+
+	// sanity check, GetAudiotime returns large negative values
+	// after audio buffer overrun ?!
+	if (lastaudiotime < 0) {
+		cerr << "FIXME: got bogus value " << lastaudiotime
+		     << " from getAudiotime()" << endl;
+		lastaudiotime = buffer->timecode;
+	}
+
         if (lastaudiotime != 0 && buffer->timecode != 0)
         { // lastaudiotime = 0 after a seek
             // The time at the start of this frame (ie, now) is given by


More information about the mythtv-dev mailing list