Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
--- libs/libmythtv/avformatdecoder.cpp	(revision 18581)
+++ libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -439,6 +439,8 @@
 {
     while (storedPackets.count() > 0)
     {
+        VERBOSE(VB_PLAYBACK, QString("AFD::~AvFormatDecoder: flushing %1 stored video pkts")
+                .arg(storedPackets.count()));
         AVPacket *pkt = storedPackets.first();
         storedPackets.removeFirst();
         av_free_packet(pkt);
@@ -639,6 +641,8 @@
     if (doflush)
     {
         lastapts = 0;
+        VERBOSE(VB_PLAYBACK,
+                QString("lastapts = %1 in SeekReset").arg(lastapts));
         lastvpts = 0;
         lastccptsu = 0;
         av_read_frame_flush(ic);
@@ -673,6 +677,8 @@
         // Free up the stored up packets
         while (storedPackets.count() > 0)
         {
+            VERBOSE(VB_PLAYBACK, QString("AFD::SeekReset: flushing %1 stored video pkts")
+                    .arg(storedPackets.count()));
             AVPacket *pkt = storedPackets.first();
             storedPackets.removeFirst();
             av_free_packet(pkt);
@@ -2350,6 +2356,15 @@
 
             if (changed)
             {
+// Heisenbug and/or race condition?
+#if 1
+                VERBOSE(VB_PLAYBACK,
+                        QString("seqFPS = %1, fps = %2 in MpegPreProcessPkt").arg(seqFPS).arg(fps));
+                VERBOSE(VB_PLAYBACK,
+                        QString("width = %1, cur.width = %2 in MpegPreProcessPkt").arg(width).arg((uint)current_width));
+                VERBOSE(VB_PLAYBACK,
+                        QString("height = %1, cur.height = %2 in MpegPreProcessPkt").arg(height).arg((uint)current_height));
+#endif
                 GetNVP()->SetVideoParams(width, height, seqFPS,
                                          keyframedist, aspect, 
                                          kScan_Detect);
@@ -2364,6 +2379,8 @@
                 gopset = false;
                 prevgoppos = 0;
                 lastapts = lastvpts = lastccptsu = 0;
+                VERBOSE(VB_PLAYBACK,
+                        QString("lastapts = %1 in MpegPreProcessPkt").arg(lastapts));
 
                 // fps debugging info
                 float avFPS = normalized_fps(stream, context);
@@ -2439,6 +2456,8 @@
             gopset = false;
             prevgoppos = 0;
             lastapts = lastvpts = lastccptsu = 0;
+            VERBOSE(VB_PLAYBACK,
+                    QString("lastapts = %1 in H264PreProcessPkt").arg(lastapts));
 
             // fps debugging info
             float avFPS = normalized_fps(stream, context);
@@ -3086,14 +3105,18 @@
             }
         }
 
+        VERBOSE(VB_PLAYBACK, QString("gotvideo: %1, pts diff: %2, lastvpts: "
+                                     "%3, lastapts: %4").arg(gotvideo)
+                .arg(lastvpts-lastapts).arg(lastvpts).arg(lastapts));
         if (gotvideo)
         {
-            if (lowbuffers && onlyvideo == 0 && 
-                lastapts < lastvpts + 100 &&
+            if (!onlyvideo &&
+                lastapts < lastvpts + 200 &&
                 lastapts > lastvpts - 10000 && 
                 !ringBuffer->InDVDMenuOrStillFrame())
             {
-                //cout << "behind: " << lastapts << " " << lastvpts << endl;
+                VERBOSE(VB_PLAYBACK, QString("Audio is %1 ms behind, queuing video pkts (%2)")
+                        .arg(lastvpts-lastapts).arg(storedPackets.count()));
                 storevideoframes = true;
             }
             else if (onlyvideo >= 0)
@@ -3105,6 +3128,8 @@
 
         if (!storevideoframes && storedPackets.count() > 0)
         {
+            VERBOSE(VB_PLAYBACK, QString("AFD::GetFrame: taking one stored video pkt (%1)")
+                    .arg(storedPackets.count()));
             if (pkt)
             {
                 av_free_packet(pkt);
@@ -3228,6 +3253,8 @@
         {
             av_dup_packet(pkt);
             storedPackets.append(pkt);
+            VERBOSE(VB_PLAYBACK, QString("AFD::GetFrame: storing video pkt (%1)")
+                    .arg(storedPackets.count()));
             pkt = NULL;
             continue;
         }
@@ -3441,8 +3468,12 @@
                     }
 
                     if (firstloop && pkt->pts != (int64_t)AV_NOPTS_VALUE)
+                    {
                         lastapts = (long long)(av_q2d(curstream->time_base) *
                                                pkt->pts * 1000);
+                        VERBOSE(VB_PLAYBACK,
+                                QString("lastapts = %1 in GetFrame1").arg(lastapts));
+                    }
 
                     if ((onlyvideo > 0) || (pkt->stream_index != audIdx))
                     {
@@ -3522,6 +3553,8 @@
                     lastapts += (long long)((double)(data_size * 1000) /
                                 (curstream->codec->channels * 2) / 
                                 curstream->codec->sample_rate);
+                    VERBOSE(VB_PLAYBACK,
+                            QString("lastapts = %1 in GetFrame2").arg(lastapts));
 
                     VERBOSE(VB_PLAYBACK|VB_TIMESTAMP,
                             LOC + QString("audio timecode %1 %2 %3 %4") 
