changeset 6962:7944afc1542c

RT-35984: MediaPlayer: playback doesn't resume after long pause and sound restarts Reviewed-by: ddehaven
author almatvee
date Thu, 01 May 2014 20:53:20 -0700
parents ae3e1b4c7dec
children 077a84d87eb4
files modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.h modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.mm
diffstat 2 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.h	Thu May 01 14:58:35 2014 -0700
+++ b/modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.h	Thu May 01 20:53:20 2014 -0700
@@ -50,6 +50,7 @@
 
     uint64_t hostTimeBase; // Host time for media time 0.0, updated every time we get a time changed notification
     double hostTimeFreq;   // frequency of the host clock, for conversion to seconds
+    BOOL updateHostTimeBase;
 
     double currentTime;
 
--- a/modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.mm	Thu May 01 14:58:35 2014 -0700
+++ b/modules/media/src/main/native/jfxmedia/platform/osx/QTKMediaPlayer.mm	Thu May 01 20:53:20 2014 -0700
@@ -146,6 +146,7 @@
         
         audioSyncDelay = 0;
         requestedRate = 1.0;
+        updateHostTimeBase = NO;
         currentTime = 0.0;
         suppressDurationEvents = NO;
         mute = NO;
@@ -637,6 +638,9 @@
 - (void) setPlayerState:(int)newState
 {
     if (newState != previousPlayerState) {
+        if (newState == kPlayerState_PLAYING) {
+            updateHostTimeBase = YES;
+        }
         // For now just send up to client
         eventHandler->SendPlayerStateEvent(newState, 0.0);
         previousPlayerState = newState;
@@ -921,8 +925,16 @@
     // TODO: send off to a work queue for processing on a separate thread to avoid deadlock issues during shutdown
     
     if (movie && movieReady && eventHandler) {
+        if (updateHostTimeBase) {
+            double now = currentTime;
+            uint64_t hostTime = CVGetCurrentHostTime();
+            hostTimeFreq = CVGetHostClockFrequency();
+            uint64_t nowDelta = (uint64_t)(now * hostTimeFreq); // current time in host frequency units
+            hostTimeBase = hostTime - nowDelta; // Host time at movie time zero
+            updateHostTimeBase = NO;
+        }
         double frameTime = (double)(hostTime - hostTimeBase) / hostTimeFreq;
-        
+
         CVVideoFrame *frame = NULL;
         try {
             frame = new CVVideoFrame(buf, frameTime, hostTime, 0);