Index: libs/libmythtv/NuppelVideoPlayer.cpp
===================================================================
--- libs/libmythtv/NuppelVideoPlayer.cpp	(revision 11820)
+++ libs/libmythtv/NuppelVideoPlayer.cpp	(working copy)
@@ -502,24 +502,27 @@
 
     PIPType piptype = kPIPOff;
 
+    if (ispip)
+    {
+        if (m_tv)
+        {
+            VideoOutput *vid = m_tv->GetVideoOutput();
+            if (vid && !vid->IsResolutionSupported(video_width, video_height))
+                return false;
+            if (livetv)
+                piptype = kPIPOnLiveTV;
+            else
+                piptype = kPIPOnTV;
+        }
+        else
+            piptype = kPIPOn;
+    }
+
     if (using_null_videoout)
     {
         videoOutput = new VideoOutputNull();
         if (ispip)
-        {
-            if (m_tv)
-            {
-                if (livetv)
-                    piptype = kPIPOnLiveTV;
-                else
-                    piptype = kPIPOnTV;
-            }
-            else
-                piptype = kPIPOn;
-
             videoOutput->SetAsPIP(piptype);
-        }
-    
            
         if (!videoOutput->Init(video_width, video_height, video_aspect,
                                0, 0, 0, 0, 0, 0))
@@ -565,17 +568,21 @@
         }
 
         if (ispip)
+            videoOutput->SetAsPIP(piptype);
+
+        int xpos = 0;
+        int ypos = 0;
+        int widgetID = widget->winId();
+        if (piptype >= kPIPOnTV && !softwareScalingPIP)
         {
+            xpos = widget->x();
+            ypos = widget->y();
             if (m_tv)
-                piptype = kPIPOnTV;
-            else
-                piptype = kPIPOn;
-            
-            videoOutput->SetAsPIP(piptype);
+                widgetID = m_tv->GetWidgetID();
         }
-
+        
         if (!videoOutput->Init(video_width, video_height, video_aspect,
-                               widget->winId(), 0, 0, widget->width(),
+                               widgetID, xpos, ypos, widget->width(),
                                widget->height(), 0))
         {
             errored = true;
Index: libs/libmythtv/tv_play.h
===================================================================
--- libs/libmythtv/tv_play.h	(revision 11820)
+++ libs/libmythtv/tv_play.h	(working copy)
@@ -34,6 +34,7 @@
 class OSDGenericTree;
 class LiveTVChain;
 class PIPPlayer;
+class VideoOutput;
 
 typedef QValueVector<QString>    str_vec_t;
 typedef QMap<QString,QString>    InfoMap;
@@ -172,6 +173,8 @@
 
     // Non-const queries
     OSD *GetOSD(void);
+    int GetWidgetID(void); 
+    VideoOutput *GetVideoOutput(void);
 
     void SetCurrentlyPlaying(ProgramInfo *pginfo);
 
Index: libs/libmythtv/pipplayer.h
===================================================================
--- libs/libmythtv/pipplayer.h	(revision 11820)
+++ libs/libmythtv/pipplayer.h	(working copy)
@@ -18,10 +18,8 @@
 class PIPPlayer
 {
     public:
-        PIPPlayer(void);
+        PIPPlayer(const QRect &rect, int location = -1);
         ~PIPPlayer(void);
-        static PIPPlayer *Create(const QRect &rect);
-        static PIPPlayer * Create(NuppelVideoPlayer *parentnvp, int location);
         bool StartPlaying(ProgramInfo *rec = NULL, 
                             bool piptype = false,
                             bool nullvideo = false,
@@ -45,8 +43,6 @@
         void Show(void);
         bool UsingNullVideo(void) { return using_nullvideo; }
         void GetARGBFrame(void);
-        QSize GetVideoDimensions(void) 
-                { return QSize(video_width, video_height); }
         bool IsPaused(void) { return paused; }
         void Pause(void);
         void Play(float speed = 1.0);
@@ -55,7 +51,6 @@
     private:
         bool StartRecorder(RemoteEncoder *rec, int maxWait);
         void Reinitialize(void);
-        void Init(QRect rect, QString name);
 
     private:
         RemoteEncoder *piprecorder;
@@ -69,8 +64,6 @@
         bool islivetv;
         bool reinit;
         bool using_nullvideo;
-        int video_width;
-        int video_height;
         bool paused;
 };
 
Index: libs/libmythtv/tv_play.cpp
===================================================================
--- libs/libmythtv/tv_play.cpp	(revision 11820)
+++ libs/libmythtv/tv_play.cpp	(working copy)
@@ -3157,13 +3157,11 @@
 
 void TV::TogglePIPView(void)
 {
-    if (!pipplayer) 
+    if (!pipplayer && nvp) 
     {
         int pip_location = gContext->GetNumSetting("PIPLocation", 0);
-        QRect rect = activenvp->getVideoOutput()->GetPIPRect(pip_location, NULL);
-        pipplayer = PIPPlayer::Create(rect);
-        if (!pipplayer)
-            return;
+        QRect rect = nvp->getVideoOutput()->GetPIPRect(pip_location, NULL);
+        pipplayer = new PIPPlayer(rect, pip_location);
         pipplayer->StartPlaying(NULL, true, false, this);
         if (pipplayer->IsPlaying())
         {
@@ -3173,25 +3171,20 @@
         }
         else
         {
-            QSize pipdim = pipplayer->GetVideoDimensions();
-            VideoOutput *vid = nvp->getVideoOutput();
-            if (vid && 
-                vid->IsResolutionSupported(pipdim.width(), pipdim.height()))
+            if (pipplayer->GetNVP() &&
+                pipplayer->GetNVP()->PIPSoftwareScaling() &&
+                nvp->getVideoOutput() &&
+                nvp->getVideoOutput()->hasXVAcceleration())
             {
-                if (pipplayer->GetNVP() &&
-                    pipplayer->GetNVP()->PIPSoftwareScaling() &&
-                    nvp->getVideoOutput() &&
-                    nvp->getVideoOutput()->hasXVAcceleration())
+                VERBOSE(VB_PLAYBACK, LOC + "Attempting to start Software Scaled PIP");
+                pipplayer->StartPlaying(NULL, true, true, this);
+                if (pipplayer->IsPlaying())
                 {
-                    pipplayer->StartPlaying(NULL, true, true, this);
-                    if (pipplayer->IsPlaying())
-                    {
-                        pipplayer->Hide();
-                        activenvp->SetPIPPlayer(pipplayer->GetNVP());
-                        pipplayerCond.wait();
-                        pipplayer->GetNVP()->DiscardVideoFrames(true);
-                        return;
-                    }
+                    pipplayer->Hide();
+                    nvp->SetPIPPlayer(pipplayer->GetNVP());
+                    pipplayerCond.wait();
+                    pipplayer->GetNVP()->DiscardVideoFrames(true);
+                    return;
                 } 
             }
         }
@@ -5905,6 +5898,13 @@
     return NULL;
 }
 
+VideoOutput *TV::GetVideoOutput(void)
+{
+    if (nvp)
+        return nvp->getVideoOutput();
+    return NULL;
+}
+
 void TV::TreeMenuEntered(OSDListTreeType *tree, OSDGenericTree *item)
 {
     // show help text somewhere, perhaps?
@@ -7535,4 +7535,10 @@
     return true;
 }
 
+int TV::GetWidgetID(void)
+{
+    if (myWindow)
+        return myWindow->winId();
+    return -1;
+}
 /* vim: set expandtab tabstop=4 shiftwidth=4: */
Index: libs/libmythtv/videooutbase.cpp
===================================================================
--- libs/libmythtv/videooutbase.cpp	(revision 11820)
+++ libs/libmythtv/videooutbase.cpp	(working copy)
@@ -248,7 +248,7 @@
                 .arg(db_move.x()).arg(db_move.y()));
     }
 
-    display_visible_rect = QRect(0, 0, winw, winh);
+    display_visible_rect = QRect(winx, winy, winw, winh);
     video_dim            = QSize(width, height);
     video_rect           = QRect(QPoint(winx, winy), fix_1080i(video_dim));
 
Index: libs/libmythtv/pipplayer.cpp
===================================================================
--- libs/libmythtv/pipplayer.cpp	(revision 11820)
+++ libs/libmythtv/pipplayer.cpp	(working copy)
@@ -13,15 +13,32 @@
     return NULL;
 }
  
-PIPPlayer::PIPPlayer(void)
+PIPPlayer::PIPPlayer(const QRect &rect, int location)
     :   piprecorder(NULL), piprbuffer(NULL),
         piptvchain(NULL), piprecinfo(NULL),
         pipnvp(NULL), pipWindow(NULL),
         islivetv(false), 
         reinit(true), using_nullvideo(false),
-        video_width(0), video_height(0),
         paused(false)
 {
+    QString name;
+    if (location > -1)
+        name = QString("pip player %1").arg((int)location);
+    else
+        name = "pip player";
+    
+    QRect piprect = QRect(rect);
+    MythMainWindow *mainWindow = gContext->GetMainWindow();
+    QWidget *parentWidget = mainWindow->currentWidget();
+    MythDialog *window = new MythDialog(gContext->GetMainWindow(), name);
+    window->setNoErase();
+    window->setGeometry(piprect);
+    window->setFixedSize(piprect.size());
+    window->show();
+    mainWindow->detach(window);
+    pipWindow = window;
+    if (parentWidget && location > -1)
+        pipWindow->stackUnder(parentWidget); 
 };
 
 PIPPlayer::~PIPPlayer(void)
@@ -31,39 +48,6 @@
         pipWindow->deleteLater();
 };
 
-PIPPlayer * PIPPlayer::Create(NuppelVideoPlayer *parentnvp, int location)
-{
-    PIPPlayer *tmppip = new PIPPlayer();
-    if (parentnvp)
-    {
-        QRect rect = parentnvp->getVideoOutput()->GetPIPRect(location, NULL);
-        tmppip->Init(rect, QString("pip player %1").arg((int)location));
-        return tmppip;
-    }
-    delete tmppip;
-    return NULL;
-}
-
-PIPPlayer * PIPPlayer::Create(const QRect &rect)
-{
-    PIPPlayer *tmppip = new PIPPlayer();
-    tmppip->Init(rect, "pip player");
-    return tmppip;
-}
-
-void PIPPlayer::Init(QRect rect, QString name)
-{
-    QRect piprect = QRect(rect);
-    MythDialog *window = new MythDialog(gContext->GetMainWindow(), name);
-    window->setNoErase();
-    window->setGeometry(piprect);
-    window->setFixedSize(piprect.size());
-    window->show();
-    window->setBackgroundColor(Qt::black);
-    gContext->GetMainWindow()->detach(window);
-    pipWindow = window;
-}
-
 void PIPPlayer::Reinitialize(void)
 {
     if (pipnvp)
@@ -213,9 +197,6 @@
         usleep(5000);
     }
    
-    video_width = pipnvp->GetVideoWidth();
-    video_height = pipnvp->GetVideoHeight();
-    
     if (!pipnvp->IsPlaying())
     {
         VERBOSE(VB_PLAYBACK, LOC_ERR + "PIP NVP Failed to Start");
Index: libs/libmythtv/videoout_xv.h
===================================================================
--- libs/libmythtv/videoout_xv.h	(revision 11820)
+++ libs/libmythtv/videoout_xv.h	(working copy)
@@ -229,6 +229,10 @@
 
     // Chromakey OSD info
     ChromaKeyOSD        *chroma_osd;
+
+    //PIP Stuff
+    /// \brief disable X11 setforeground on PIP when ChromakeyOSD is showing.
+    static bool pip_disable_setForeground; 
 };
 
 CodecID myth2av_codecid(MythCodecID codec_id,
Index: libs/libmythtv/videoout_xv.cpp
===================================================================
--- libs/libmythtv/videoout_xv.cpp	(revision 11820)
+++ libs/libmythtv/videoout_xv.cpp	(working copy)
@@ -85,6 +85,8 @@
     "unknown", "xlib", "xshm", "xv-blit", "xvmc", "xvmc", "xvmc", 
 };
 
+bool VideoOutputXv::pip_disable_setForeground = false;
+
 /** \class  VideoOutputXv
  *  \brief Supports common video output methods used with %X11 Servers.
  *
@@ -176,6 +178,9 @@
 
     if (xvmc_tex)
         delete xvmc_tex;
+
+    if (piptype == kPIPOff)
+        pip_disable_setForeground = false;
 }
 
 // this is documented in videooutbase.cpp
@@ -730,6 +735,9 @@
     if (!done && use_xv)
         done = InitXVideo();
 
+    if (!done && piptype > kPIPOff)
+        return done;
+
     // Fall back to shared memory, if we are allowed to use it
     if (!done && use_shm)
         done = InitXShm();
@@ -1098,6 +1106,7 @@
 
     return ret;
 #else // if !USING_XVMC
+    (void)ispip;
     return (MythCodecID)(kCodec_MPEG1 + (stream_type-1));
 #endif // !USING_XVMC
 }
@@ -2575,6 +2584,8 @@
     if (chroma_osd && chroma_osd->GetImage() && xv_need_bobdeint_repaint)
     {
         X11L;
+        if (piptype == kPIPOff)
+            pip_disable_setForeground = true;
         XShmPutImage(XJ_disp, XJ_curwin, XJ_gc, chroma_osd->GetImage(),
                      0, 0, 0, 0,
                      display_visible_rect.width(),
@@ -2590,6 +2601,14 @@
 
     X11L;
 
+    if (piptype == kPIPOff)
+        pip_disable_setForeground = false;
+    else if (pip_disable_setForeground && piptype >= kPIPOnTV)
+    {
+        needrepaint = false;
+        return;
+    }
+    
     if (xv_draw_colorkey && needrepaint)
     {
         XSetForeground(XJ_disp, XJ_gc, xv_colorkey);
@@ -3298,6 +3317,39 @@
     if (width == 0 || height == 0)
         return false;
 
+    if (!xv_chroma)
+    {
+        int ids[] = { GUID_I420_PLANAR, GUID_IYUV_PLANAR, GUID_YV12_PLANAR };
+        int format_cnt = 0;
+        XvImageFormatValues *formats;
+        X11S(formats = XvListImageFormats(XJ_disp, xv_port, &format_cnt));
+
+        for (int i = 0; i < format_cnt; i++)
+        {
+            char *chr = (char*) &(formats[i].id);
+            VERBOSE(VB_PLAYBACK, LOC + QString("IsResolutionSupported() PIP XVideo Format #%1 is '%2%3%4%5'")
+            .arg(i).arg(chr[0]).arg(chr[1]).arg(chr[2]).arg(chr[3]));
+        }
+
+#ifdef USE_HACK_FOR_BROKEN_I420_SUPPORT_IN_DRIVER
+        swap(ids[0], ids[2]);
+#endif // USE_HACK_FOR_BROKEN_I420_SUPPORT_IN_DRIVER
+
+        for (uint i = 0; i < sizeof(ids)/sizeof(int); i++)
+        {
+            if (has_format(formats, format_cnt, ids[i]))
+            {
+                xv_chroma = ids[i];
+                break;
+            }
+        }
+                
+        // IYUV is bit identical to I420, just pretend we saw I420
+        xv_chroma = (GUID_IYUV_PLANAR == xv_chroma) ? GUID_I420_PLANAR : xv_chroma;
+        if (formats)
+            X11S(XFree(formats));
+    }
+    
     if (xv_port >= 0 && xv_chroma)
     {
         int size = 0;
@@ -3317,9 +3369,10 @@
             delete info;
             return false;
         }
-
         return true;
     }
+  
+    VERBOSE(VB_IMPORTANT, LOC_ERR + "IsResolutionSupported(): No free XV Ports or XV Chroma");
     return false;
 }
         
Index: programs/mythfrontend/playbackbox.cpp
===================================================================
--- programs/mythfrontend/playbackbox.cpp	(revision 11820)
+++ programs/mythfrontend/playbackbox.cpp	(working copy)
@@ -521,7 +521,7 @@
 
     if (previewVideoEnabled)
     {
-        previewPlayer = PIPPlayer::Create(drawVideoBounds);
+        previewPlayer = new PIPPlayer(drawVideoBounds);
         if (previewPlayer)
             previewPlayer->Hide();
         previewPixmapEnabled = true;
@@ -2162,7 +2162,7 @@
 
     if (previewVideoEnabled && !previewPlayer)
     {
-        previewPlayer = PIPPlayer::Create(drawVideoBounds);
+        previewPlayer = new PIPPlayer(drawVideoBounds);
         if (previewPlayer)
             previewPlayer->Hide();
     }
Index: programs/mythfrontend/globalsettings.cpp
===================================================================
--- programs/mythfrontend/globalsettings.cpp	(revision 11820)
+++ programs/mythfrontend/globalsettings.cpp	(working copy)
@@ -1779,7 +1779,7 @@
 
 static HostCheckBox *EndOfRecordingExitPrompt()
 {
-    HostCheckBox *gc = new HostCheckBox("EndOfRecordingExitPrompt");
+    HostCheckBox *gc = new HostCheckBox("EndofRecordingExitPrompt");
     gc->setLabel(QObject::tr("Prompt at end of recording"));
     gc->setValue(false);
     gc->setHelpText(QObject::tr("If set, a menu will be displayed allowing "
@@ -1849,16 +1849,6 @@
     return gc;
 }
 
-static HostCheckBox *PlaybackPreviewLowCPU()
-{
-    HostCheckBox *gc = new HostCheckBox("PlaybackPreviewLowCPU");
-    gc->setLabel(QObject::tr("CPU friendly preview of recordings"));
-    gc->setValue(false);
-    gc->setHelpText(QObject::tr("When enabled, recording previews "
-                    "will play with reduced FPS to save CPU."));
-    return gc;
-}
-
 static HostCheckBox *PlayBoxTransparency()
 {
     HostCheckBox *gc = new HostCheckBox("PlayBoxTransparency");
@@ -4160,6 +4150,7 @@
     general->addChild(oscan);
     general->addChild(columns2);
     general->addChild(PlaybackExitPrompt());
+    general->addChild(EndOfRecordingExitPrompt());
     addChild(general);
 
     QString tmp = QString(" (%1/%2)").arg(++i).arg(total);
