Index: libs/libmythtv/NuppelVideoPlayer.cpp
===================================================================
--- libs/libmythtv/NuppelVideoPlayer.cpp	(revision 11605)
+++ libs/libmythtv/NuppelVideoPlayer.cpp	(working copy)
@@ -254,7 +254,7 @@
       isDummy(false),               
       // DVD stuff
       indvdstillframe(false), hidedvdbutton(true),
-      need_change_dvd_track(0),
+      need_change_dvd_track(0), dvd_video_codec_changing(false),
       // Debugging variables
       output_jmeter(NULL)
 {
@@ -596,6 +596,7 @@
     vidExitLock.lock();
     videofiltersLock.lock();
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME in ReinitVideo"));
     float aspect = (forced_video_aspect > 0) ? forced_video_aspect : video_aspect;
     videoOutput->InputChanged(video_width, video_height, aspect, 
                               GetDecoder()->GetVideoCodecID());
@@ -848,14 +849,18 @@
 
 void NuppelVideoPlayer::SetVideoParams(int width, int height, double fps,
                                        int keyframedistance, float aspect,
-                                       FrameScanType scan)
+                                       FrameScanType scan, bool video_codec_changed)
 {
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME entered SetVideoParams"));
     if (width == 0 || height == 0 || isnan(aspect) || isnan(fps))
         return;
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME passed step 1 in SetVideoParams"));
+            
     if ((video_width  == width ) && (video_height     == height) && 
         (video_aspect == aspect) && (video_frame_rate == fps   ) &&
-        ((keyframedistance <= 0) || (keyframedistance == keyframedist)))
+        ((keyframedistance <= 0) || (keyframedistance == keyframedist)) &&
+        !video_codec_changed)
     {
         return;
     }
@@ -874,6 +879,7 @@
         frame_interval = (int)(1000000.0f / video_frame_rate / temp_speed);
     }
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME in SetVideoParam about to reinitvideo"));
     if (videoOutput)
         ReinitVideo();
 
@@ -2592,6 +2598,9 @@
 
         if (ringBuffer->isDVD())
         {
+            if (dvd_video_codec_changing)
+                continue;
+            
             int nbframes = videoOutput->ValidVideoFrames();
             if (nbframes < 2) 
             {
Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
--- libs/libmythtv/avformatdecoder.cpp	(revision 11605)
+++ libs/libmythtv/avformatdecoder.cpp	(working copy)
@@ -278,6 +278,7 @@
       lastccptsu(0),
       using_null_videoout(use_null_videoout),
       video_codec_id(kCodec_NONE),
+      video_codec_changed(false),
       maxkeyframedist(-1), 
       // Closed Caption & Teletext decoders
       ccd608(new CC608Decoder(parent)),
@@ -292,7 +293,8 @@
       disable_passthru(false),
       // DVD
       lastdvdtitle(-1), lastcellstart(0),
-      dvdmenupktseen(false), dvdvideopause(false)
+      dvdmenupktseen(false), dvdvideopause(false),
+      xvmc_enabled(false)
 {
     bzero(&params, sizeof(AVFormatParameters));
     bzero(prvpkt, 3 * sizeof(char));
@@ -803,6 +805,9 @@
         av_free_packet(&pkt1);
         ringBuffer->Seek(0,SEEK_SET);
         ringBuffer->DVD()->IgnoreStillOrWait(false);
+        QString dec = gContext->GetSetting("PreferredMPEG2Decoder", "ffmpeg");
+        if (dec.contains("xvmc"))
+            xvmc_enabled = true;
     }
     else
     {
@@ -944,6 +949,8 @@
 {
     float aspect_ratio;
 
+    directrendering = false;
+
     if (selectedStream)
     {
         fps = normalized_fps(stream, enc);
@@ -986,9 +993,12 @@
         SetLowBuffers(false);
     }
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME in initvideocodec codec %1 codec name %2").arg(codec->id).
+            arg(codec->name));
     if (codec && (codec->id == CODEC_ID_MPEG2VIDEO_XVMC ||
                   codec->id == CODEC_ID_MPEG2VIDEO_XVMC_VLD))
     {
+        VERBOSE(VB_PLAYBACK, QString("DELETE ME in initvideocodec codec %1..IS XVMC").arg(codec->id));
         enc->flags |= CODEC_FLAG_EMU_EDGE;
         enc->get_buffer = get_avf_buffer_xvmc;
         enc->release_buffer = release_avf_buffer_xvmc;
@@ -1027,7 +1037,8 @@
         }
 
         GetNVP()->SetVideoParams(align_width, align_height, fps,
-                                 keyframedist, aspect_ratio, kScan_Detect);
+                                 keyframedist, aspect_ratio, kScan_Detect, video_codec_changed);
+        video_codec_changed = false;
     }
 }
 
@@ -1354,6 +1365,8 @@
                 d->DestroyMPEG2();
                 h264_kf_seq->Reset();
 #ifdef USING_XVMC
+                VERBOSE(VB_PLAYBACK, QString("DELETE ME ScanStreams using null %1 stream type %2")
+                        .arg(using_null_videoout).arg(xvmc_stream_type(enc->codec_id)));
                 if (!using_null_videoout && xvmc_stream_type(enc->codec_id))
                 {
                     // HACK -- begin
@@ -1365,17 +1378,29 @@
                         enc->codec_id = CODEC_ID_MPEG2VIDEO;
                     // HACK -- end
 
+                    bool force_xv = false;
+                    if (ringBuffer->InDVDMenuOrStillFrame() &&
+                        xvmc_enabled)
+                    {
+                        force_xv = true;
+                        enc->pix_fmt = PIX_FMT_YUV420P;
+                    }
+                    
                     MythCodecID mcid;
                     mcid = VideoOutputXv::GetBestSupportedCodec(
                         /* disp dim     */ enc->width, enc->height,
                         /* osd dim      */ /*enc->width*/ 0, /*enc->height*/ 0,
                         /* mpeg type    */ xvmc_stream_type(enc->codec_id),
                         /* xvmc pix fmt */ xvmc_pixel_format(enc->pix_fmt),
-                        /* test surface */ kCodec_NORMAL_END > video_codec_id);
+                        /* test surface */ kCodec_NORMAL_END > video_codec_id,
+                        /* force_xv     */ force_xv);
                     bool vcd, idct, mc;
                     enc->codec_id = myth2av_codecid(mcid, vcd, idct, mc);
+                    if (mcid != video_codec_id)
+                        video_codec_changed = true;
+                    VERBOSE(VB_PLAYBACK, QString("DELETE ME ScanStreams video_codec_changed %1 mcid %2 force_xv %3 xvmc_enabled %4 in dvdmenuOrStillFrame %5").arg(video_codec_changed).arg(mcid).arg(force_xv).arg(xvmc_enabled).arg(ringBuffer->InDVDMenuOrStillFrame()));
                     video_codec_id = mcid;
-                    if (kCodec_NORMAL_END < mcid && kCodec_STD_XVMC_END > mcid)
+                    if (!force_xv && kCodec_NORMAL_END < mcid && kCodec_STD_XVMC_END > mcid)
                     {
                         enc->pix_fmt = (idct) ?
                             PIX_FMT_XVMC_MPEG2_IDCT : PIX_FMT_XVMC_MPEG2_MC;
@@ -2830,8 +2855,24 @@
             {
                 int current_width = curstream->codec->width;
                 int video_width = GetNVP()->GetVideoWidth();
-                if (video_width > 0 && video_width != current_width)
+                bool switch_to_xv = false;
+                bool switch_to_xvmc = false;
+                if (xvmc_enabled && GetNVP() && GetNVP()->getVideoOutput())
                 {
+                    bool xvmc_active = GetNVP()->getVideoOutput()->hasMCAcceleration();
+                    bool indvdmenu   = ringBuffer->InDVDMenuOrStillFrame();
+                    VERBOSE(VB_PLAYBACK, QString("DELETE ME xvmc_active %1 indvdmenuorstillframe %2").arg(xvmc_active).arg(indvdmenu));
+                    if (indvdmenu && xvmc_active)
+                        switch_to_xv = true;
+                    else if (!indvdmenu && !xvmc_active)
+                        switch_to_xvmc = true;
+                    VERBOSE(VB_PLAYBACK, QString("DELETE ME switch_to_xv %1 switch_to_xvmc %2").arg(switch_to_xv).arg(switch_to_xvmc));
+                }
+                
+                if ((video_width > 0 && video_width != current_width) ||
+                    switch_to_xv || switch_to_xvmc)
+                {
+                    GetNVP()->DVDVideoCodecChanging(true);
                     av_free_packet(pkt);
                     CloseCodecs();
                     ScanStreams(false);
@@ -2841,6 +2882,7 @@
                         long long cellstartpos = ringBuffer->DVD()->GetCellStartPos();
                         ringBuffer->DVD()->Seek(cellstartpos, SEEK_SET);
                     }
+                    GetNVP()->DVDVideoCodecChanging(false);
                     continue;
                 }
             }
@@ -3140,6 +3182,8 @@
                                                   &gotpicture, ptr, len);
                     else
                     {
+                        VERBOSE(VB_PLAYBACK, QString("DELETE ME context codec %1 pixfmt %2")
+                                .arg(context->codec_id).arg(context->pix_fmt));
                         ret = avcodec_decode_video(context, &mpa_pic,
                                                    &gotpicture, ptr, len);
                         // Reparse it to not drop the DVD still frame
Index: libs/libmythtv/NuppelVideoPlayer.h
===================================================================
--- libs/libmythtv/NuppelVideoPlayer.h	(revision 11605)
+++ libs/libmythtv/NuppelVideoPlayer.h	(working copy)
@@ -151,7 +151,7 @@
     void SetBookmark(void);
     void SetKeyframeDistance(int keyframedistance);
     void SetVideoParams(int w, int h, double fps, int keydist,
-                        float a = 1.33333, FrameScanType scan = kScan_Ignore);
+                        float a = 1.33333, FrameScanType scan = kScan_Ignore, bool video_codec_changed = false);
     void SetFileLength(int total, int frames);
     void Zoom(int direction);
     void ClearBookmark(void);
@@ -387,7 +387,8 @@
     { 
         hidedvdbutton = hide;
     }
-
+    void DVDVideoCodecChanging(bool setting) { dvd_video_codec_changing = setting; }
+    
   protected:
     void DisplayPauseFrame(void);
     void DisplayNormalFrame(void);
@@ -769,6 +770,7 @@
     bool indvdstillframe;
     bool hidedvdbutton;
     int need_change_dvd_track;
+    bool dvd_video_codec_changing; ///< true if switching from Xv <-->XVMC
 
     // Debugging variables
     Jitterometer *output_jmeter;
Index: libs/libmythtv/videoout_xv.h
===================================================================
--- libs/libmythtv/videoout_xv.h	(revision 11605)
+++ libs/libmythtv/videoout_xv.h	(working copy)
@@ -94,7 +94,7 @@
     static MythCodecID GetBestSupportedCodec(uint width, uint height,
                                              uint osd_width, uint osd_height,
                                              uint stream_type, int xvmc_chroma,
-                                             bool test_surface);
+                                             bool test_surface, bool force_xv);
 
     static int GrabSuitableXvPort(Display* disp, Window root,
                                   MythCodecID type,
@@ -144,7 +144,7 @@
     bool CreateBuffers(VOSType subtype);
     vector<void*> CreateXvMCSurfaces(uint num, bool create_xvmc_blocks);
     vector<unsigned char*> CreateShmImages(uint num, bool use_xv);
-    void CreatePauseFrame(void);
+    void CreatePauseFrame(VOSType subtype);
     void CopyFrame(VideoFrame *to, const VideoFrame *from);
 
     void DeleteBuffers(VOSType subtype, bool delete_pause_frame);
Index: libs/libmythtv/videoout_xv.cpp
===================================================================
--- libs/libmythtv/videoout_xv.cpp	(revision 11605)
+++ libs/libmythtv/videoout_xv.cpp	(working copy)
@@ -207,6 +207,8 @@
 
     VideoOutput::InputChanged(width, height, aspect, av_codec_id);
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME InputChanged cid_changed %1 res_changed %2")
+            .arg(cid_changed).arg(res_changed));
     if (!res_changed && !cid_changed)
     {
         if (VideoOutputSubType() == XVideo)
@@ -649,11 +651,13 @@
  *
  * \sideeffect sets av_pause_frame.
  */
-void VideoOutputXv::CreatePauseFrame(void)
+void VideoOutputXv::CreatePauseFrame(VOSType subtype)
 {
     // All methods but XvMC use a pause frame, create it if needed
-    if (VideoOutputSubType() <= XVideo)
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME CreatePauseFrame Now Video Type %1").arg(subtype);
+    if (subtype <= XVideo)
     {
+        VERBOSE(VB_PLAYBACK, QString("DELETE ME CreatePauseFrame Now "));
         vbuffers.LockFrame(&av_pause_frame, "CreatePauseFrame");
 
         if (av_pause_frame.buf)
@@ -992,11 +996,14 @@
 MythCodecID VideoOutputXv::GetBestSupportedCodec(
     uint width,       uint height,
     uint osd_width,   uint osd_height,
-    uint stream_type, int xvmc_chroma,    bool test_surface)
+    uint stream_type, int xvmc_chroma,    
+    bool test_surface, bool force_xv)
 {
     (void)width, (void)height, (void)osd_width, (void)osd_height;
     (void)stream_type, (void)xvmc_chroma, (void)test_surface;
 
+    if (force_xv)
+        return (MythCodecID)(kCodec_MPEG1 + (stream_type-1));
 #ifdef USING_XVMC
     Display *disp = MythXOpenDisplay();
 
@@ -1718,8 +1725,9 @@
 
     }
 
+    VERBOSE(VB_PLAYBACK, QString("DELETE ME In CreateBuffers..ok %1 about to CreatePauseFrame").arg(ok));
     if (ok)
-        CreatePauseFrame();
+        CreatePauseFrame(subtype);
 
     return ok;
 }
@@ -1772,6 +1780,7 @@
 
     if (delete_pause_frame)
     {
+        VERBOSE(VB_PLAYBACK, QString("DELETE ME deleting pause frame DeleteBuffers"));
         if (av_pause_frame.buf)
         {
             delete [] av_pause_frame.buf;
Index: libs/libmythtv/avformatdecoder.h
===================================================================
--- libs/libmythtv/avformatdecoder.h	(revision 11605)
+++ libs/libmythtv/avformatdecoder.h	(working copy)
@@ -228,6 +228,7 @@
 
     bool using_null_videoout;
     MythCodecID video_codec_id;
+    bool video_codec_changed;
 
     int maxkeyframedist;
 
@@ -255,6 +256,8 @@
     uint lastcellstart;
     bool dvdmenupktseen;
     bool dvdvideopause;
+    bool xvmc_enabled;
+    bool xvmc_active;
 
 };
 
Index: libs/libavcodec/mpeg12.c
===================================================================
--- libs/libavcodec/mpeg12.c	(revision 11605)
+++ libs/libavcodec/mpeg12.c	(working copy)
@@ -2078,6 +2078,8 @@
     s->mpeg_enc_ctx.picture_number = 0;
     s->repeat_field = 0;
     s->mpeg_enc_ctx.codec_id= avctx->codec->id;
+    avctx->xvmc_acceleration = 0;
+    avctx->xvmc_vld_hwslice  = 0;
     return 0;
 }
 
