Merge "Fix issue 3457629 FIle loads but does not play"
diff --git a/libvideoeditor/lvpp/PreviewPlayer.cpp b/libvideoeditor/lvpp/PreviewPlayer.cpp
index d0b84d8..7d08a9f 100644
--- a/libvideoeditor/lvpp/PreviewPlayer.cpp
+++ b/libvideoeditor/lvpp/PreviewPlayer.cpp
@@ -27,7 +27,6 @@
 #include "DummyAudioSource.h"
 #include "DummyVideoSource.h"
 #include "VideoEditorSRC.h"
-#include "include/LiveSession.h"
 #include "include/NuCachedSource2.h"
 #include "include/ThrottledSource.h"
 
@@ -452,18 +451,6 @@
     }
 }
 
-void PreviewPlayer::partial_reset_l() {
-
-    if (mLastVideoBuffer) {
-        mLastVideoBuffer->release();
-        mLastVideoBuffer = NULL;
-    }
-
-    /* call base struct */
-    AwesomePlayer::partial_reset_l();
-
-}
-
 status_t PreviewPlayer::play() {
     Mutex::Autolock autoLock(mLock);
 
diff --git a/libvideoeditor/lvpp/PreviewPlayer.h b/libvideoeditor/lvpp/PreviewPlayer.h
index e06836e..dceffab 100644
--- a/libvideoeditor/lvpp/PreviewPlayer.h
+++ b/libvideoeditor/lvpp/PreviewPlayer.h
@@ -118,7 +118,6 @@
     status_t setDataSource_l(
         const char *uri, const KeyedVector<String8, String8> *headers);
     void reset_l();
-    void partial_reset_l();
     status_t play_l();
     status_t initRenderer_l();
     status_t initAudioDecoder();
diff --git a/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h b/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
index 069b84d..bc29b2a 100755
--- a/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
+++ b/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
@@ -610,6 +610,7 @@
     M4OSA_UInt8              nbActiveEffects1;  /**< Numbers of active effects RC */
     M4OSA_Bool               m_bClipExternalHasStarted;  /**< Flag to indicate that an
                                                               external effect is active */
+    M4OSA_Int32              iInOutTimeOffset;
 } M4VSS3GPP_InternalEditContext;
 
 
diff --git a/libvideoeditor/vss/src/M4VSS3GPP_Edit.c b/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
index d495186..acdbfdc 100755
--- a/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
+++ b/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
@@ -229,6 +229,8 @@
 
     pC->bIsMMS = M4OSA_FALSE;
 
+    pC->iInOutTimeOffset = 0;
+
     /**
     * Return with no error */
     M4OSA_TRACE3_0("M4VSS3GPP_editInit(): returning M4NO_ERROR");
diff --git a/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c b/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
index 9870426..2dfd07b 100755
--- a/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
+++ b/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
@@ -93,12 +93,18 @@
     M4OSA_UInt16 offset;
 
     /**
-    * Check if we reached end cut */
-    // Decorrelate input and output encoding timestamp to handle encoder prefetch
-    if ( ((M4OSA_Int32)(pC->ewc.dInputVidCts) - pC->pC1->iVoffset) >= pC->pC1->iEndTime )
+     * Check if we reached end cut. Decorrelate input and output encoding
+     * timestamp to handle encoder prefetch
+     */
+    if ( ((M4OSA_Int32)(pC->ewc.dInputVidCts) - pC->pC1->iVoffset
+        + pC->iInOutTimeOffset) >= pC->pC1->iEndTime )
     {
         /* Re-adjust video to precise cut time */
-        // Decorrelate input and output encoding timestamp to handle encoder prefetch
+        pC->iInOutTimeOffset = ((M4OSA_Int32)(pC->ewc.dInputVidCts))
+            - pC->pC1->iVoffset + pC->iInOutTimeOffset - pC->pC1->iEndTime;
+        if ( pC->iInOutTimeOffset < 0 ) {
+            pC->iInOutTimeOffset = 0;
+        }
 
         /**
         * Video is done for this clip */
@@ -1974,9 +1980,11 @@
 
              if(uiClipNumber ==1)
              {
-                if ((t >= (M4OSA_Int32)(pFx->uiStartTime)) &&                  /**< Are we after the start time of the effect? */
-                    (t <  (M4OSA_Int32)(pFx->uiStartTime + pFx->uiDuration)) ) /**< Are we into the effect duration? */
-                {
+                /**< Are we after the start time of the effect?
+                 * or Are we into the effect duration?
+                 */
+                if ( (t >= (M4OSA_Int32)(pFx->uiStartTime)) &&
+                    (t <= (M4OSA_Int32)(pFx->uiStartTime + pFx->uiDuration)) ) {
                     /**
                      * Set the active effect(s) */
                     pC->pActiveEffectsList[i] = pC->nbEffects-1-uiFxIndex;
@@ -1993,17 +2001,19 @@
                     }
 
                     /**
-                     * The third effect has the highest priority, then the second one, then the first one.
-                     * Hence, as soon as we found an active effect, we can get out of this loop */
-
+                     * The third effect has the highest priority, then the
+                     * second one, then the first one. Hence, as soon as we
+                     * found an active effect, we can get out of this loop.
+                     */
                 }
             }
             else
             {
-                if ((t + pC->pTransitionList[uiClipIndex].uiTransitionDuration >=
-                   (M4OSA_Int32)(pFx->uiStartTime)) && (t + pC->pTransitionList[uiClipIndex].uiTransitionDuration
-                    <  (M4OSA_Int32)(pFx->uiStartTime + pFx->uiDuration)) ) /**< Are we into the effect duration? */
-                 {
+                /**< Are we into the effect duration? */
+                if ( (t + pC->pTransitionList[uiClipIndex].uiTransitionDuration
+                    >= (M4OSA_Int32)(pFx->uiStartTime))
+                    && (t + pC->pTransitionList[uiClipIndex].uiTransitionDuration
+                    <= (M4OSA_Int32)(pFx->uiStartTime + pFx->uiDuration)) ) {
                     /**
                      * Set the active effect(s) */
                     pC->pActiveEffectsList1[i] = pC->nbEffects-1-uiFxIndex;
diff --git a/libvideoeditor/vss/src/M4xVSS_internal.c b/libvideoeditor/vss/src/M4xVSS_internal.c
index 71a8929..b56d524 100755
--- a/libvideoeditor/vss/src/M4xVSS_internal.c
+++ b/libvideoeditor/vss/src/M4xVSS_internal.c
@@ -4135,11 +4135,15 @@
                     if(pProgress->uiProgress >= 0 && pProgress->uiProgress \
                     < (M4OSA_UInt32)(alphaBlendingStruct->m_fadeInTime*10))
                     {
-                        alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle\
-                         - alphaBlendingStruct->m_start)\
-                            *pProgress->uiProgress/(alphaBlendingStruct->m_fadeInTime*10));
-                        alphaBlending += alphaBlendingStruct->m_start;
-                        alphaBlending /= 100;
+                        if(alphaBlendingStruct->m_fadeInTime == 0) {
+                            alphaBlending = alphaBlendingStruct->m_start / 100;
+                        } else {
+                            alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle\
+                             - alphaBlendingStruct->m_start)\
+                                *pProgress->uiProgress/(alphaBlendingStruct->m_fadeInTime*10));
+                            alphaBlending += alphaBlendingStruct->m_start;
+                            alphaBlending /= 100;
+                        }
                     }
                     else if(pProgress->uiProgress >= (M4OSA_UInt32)(alphaBlendingStruct->\
                     m_fadeInTime*10) && pProgress->uiProgress < 1000\
@@ -4151,11 +4155,15 @@
                     else if(pProgress->uiProgress >= 1000 - (M4OSA_UInt32)\
                     (alphaBlendingStruct->m_fadeOutTime*10))
                     {
-                        alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle \
-                        - alphaBlendingStruct->m_end))*(1000 - pProgress->uiProgress)\
-                        /(alphaBlendingStruct->m_fadeOutTime*10);
-                        alphaBlending += alphaBlendingStruct->m_end;
-                        alphaBlending /= 100;
+                        if(alphaBlendingStruct->m_fadeOutTime == 0) {
+                            alphaBlending = alphaBlendingStruct->m_end / 100;
+                        } else {
+                            alphaBlending = ((M4OSA_Float)(alphaBlendingStruct->m_middle \
+                            - alphaBlendingStruct->m_end))*(1000 - pProgress->uiProgress)\
+                            /(alphaBlendingStruct->m_fadeOutTime*10);
+                            alphaBlending += alphaBlendingStruct->m_end;
+                            alphaBlending /= 100;
+                        }
                     }
                 }
                 /**/