From 0195b902c7b9b8c9a9ae891f2f2d4d1dc0c57584 Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Wed, 4 Jul 2012 16:39:13 +0200
Subject: [PATCH] mythplayer: Don't call DoneDisplayingFrame for PiP until next frame is ready

When displaying 'pictute in picture' (PiP), VideoOutput::ShowPIP
composites the PiP windows onto the main video frame.  To do so, it uses
the player's GetCurrentFrame method to obtain the most recently displayed
PiP frame.  However, MythPlayer::DisplayNormalFrames immediately releases
the last frame displayed back to the decoding queue.  Consequently when
GetCurrentFrame calls GetLastShownFrame to obtain that frame it may have been
overwritten by the decoder thread.

This patch defers calling DoneDisplayingFrame if the player is a PiP
player so that future calls to GetLastShownFrame return an intact frame.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
 mythtv/libs/libmythtv/mythplayer.cpp |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
index 5a637f7..5c92280 100644
--- a/mythtv/libs/libmythtv/mythplayer.cpp
+++ b/mythtv/libs/libmythtv/mythplayer.cpp
@@ -2155,6 +2155,10 @@ void MythPlayer::DisplayNormalFrame(bool check_prebuffer)
     // clear the buffering state
     SetBuffering(false);
 
+    // If PiP then release the last shown frame to the decoding queue
+    if (player_ctx->IsPIP())
+        videoOutput->DoneDisplayingFrame(videoOutput->GetLastShownFrame());
+
     // retrieve the next frame
     videoOutput->StartDisplayingFrame();
     VideoFrame *frame = videoOutput->GetLastShownFrame();
@@ -2180,7 +2184,9 @@ void MythPlayer::DisplayNormalFrame(bool check_prebuffer)
     osdLock.unlock();
 
     AVSync(frame, 0);
-    videoOutput->DoneDisplayingFrame(frame);
+    // If PiP then keep this frame for MythPlayer::GetCurrentFrame
+    if (!player_ctx->IsPIP())
+        videoOutput->DoneDisplayingFrame(frame);
 }
 
 void MythPlayer::PreProcessNormalFrame(void)
-- 
1.7.4.1

