Fix for issue 3404624 - The overlay in exported video is blurry

Change-Id: I52bd474c85589bd75e58c675045a7c7fe058a228
diff --git a/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h b/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
index 55513bc..069b84d 100755
--- a/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
+++ b/libvideoeditor/vss/inc/M4VSS3GPP_InternalTypes.h
@@ -608,6 +608,8 @@
     M4OSA_Bool               bIssecondClip;
     M4OSA_UInt8              *pActiveEffectsList1;  /**< List of the active effects settings. Array of nbEffects RC */
     M4OSA_UInt8              nbActiveEffects1;  /**< Numbers of active effects RC */
+    M4OSA_Bool               m_bClipExternalHasStarted;  /**< Flag to indicate that an
+                                                              external effect is active */
 } M4VSS3GPP_InternalEditContext;
 
 
diff --git a/libvideoeditor/vss/src/M4VSS3GPP_Edit.c b/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
index 722bfe9..d495186 100755
--- a/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
+++ b/libvideoeditor/vss/src/M4VSS3GPP_Edit.c
@@ -224,6 +224,8 @@
     pC->State = M4VSS3GPP_kEditState_CREATED;
     pC->Vstate = M4VSS3GPP_kEditVideoState_READ_WRITE;
     pC->Astate = M4VSS3GPP_kEditAudioState_READ_WRITE;
+    /* The flag is set to false at the beginning of every clip */
+    pC->m_bClipExternalHasStarted = M4OSA_FALSE;
 
     pC->bIsMMS = M4OSA_FALSE;
 
@@ -3287,6 +3289,8 @@
             }
         }
     }
+    /* The flag is set to false at the beginning of every clip */
+    pC->m_bClipExternalHasStarted = M4OSA_FALSE;
 
     /**
     * Return with no error */
diff --git a/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c b/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
index ff9f120..f0a3a01 100755
--- a/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
+++ b/libvideoeditor/vss/src/M4VSS3GPP_EditVideo.c
@@ -770,8 +770,15 @@
                     pC->Vstate = M4VSS3GPP_kEditVideoState_READ_WRITE;
                 }
             }
-            else
+            else if(!((pC->m_bClipExternalHasStarted == M4OSA_TRUE) &&
+                    (pC->Vstate == M4VSS3GPP_kEditVideoState_DECODE_ENCODE)))
             {
+                /**
+                 * Test if we go into copy/paste mode or into decode/encode mode
+                 * If an external effect has been applied on the current clip
+                 * then continue to be in decode/encode mode till end of
+                 * clip to avoid H.264 distortion.
+                 */
                 pC->Vstate = M4VSS3GPP_kEditVideoState_READ_WRITE;
             }
         }
@@ -1969,18 +1976,25 @@
              {
                 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? */
-                    {
-                /**
-                 * Set the active effect(s) */
+                {
+                    /**
+                     * Set the active effect(s) */
                     pC->pActiveEffectsList[i] = pC->nbEffects-1-uiFxIndex;
 
-                /**
-                 * Update counter of active effects */
+                    /**
+                     * Update counter of active effects */
                     i++;
 
-                /**
-                 * 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 */
+                    /**
+                     * For all external effects set this flag to true. */
+                    if(pFx->VideoEffectType > M4VSS3GPP_kVideoEffectType_External)
+                    {
+                        pC->m_bClipExternalHasStarted = M4OSA_TRUE;
+                    }
+
+                    /**
+                     * 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 */
 
                 }
             }
@@ -1990,22 +2004,26 @@
                    (M4OSA_Int32)(pFx->uiStartTime)) && (t + pC->pTransitionList[uiClipIndex].uiTransitionDuration
                     <  (M4OSA_Int32)(pFx->uiStartTime + pFx->uiDuration)) ) /**< Are we into the effect duration? */
                  {
-                /**
-                 * Set the active effect(s) */
+                    /**
+                     * Set the active effect(s) */
                     pC->pActiveEffectsList1[i] = pC->nbEffects-1-uiFxIndex;
 
-                /**
-                 * Update counter of active effects */
+                    /**
+                     * Update counter of active effects */
                     i++;
 
-                /**
-                 * 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 */
+                    /**
+                     * For all external effects set this flag to true. */
+                    if(pFx->VideoEffectType > M4VSS3GPP_kVideoEffectType_External)
+                    {
+                        pC->m_bClipExternalHasStarted = M4OSA_TRUE;
+                    }
+
+                    /**
+                     * 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 */
                 }
-
-
             }
-
         }
     }
 
diff --git a/libvideoeditor/vss/src/M4xVSS_API.c b/libvideoeditor/vss/src/M4xVSS_API.c
index 67d168d..a5371e7 100755
--- a/libvideoeditor/vss/src/M4xVSS_API.c
+++ b/libvideoeditor/vss/src/M4xVSS_API.c
@@ -2248,8 +2248,8 @@
                 i]->ClipProperties.uiStillPicHeight; //ARGB_Height;
                 pParams->width = pSettings->pClipList[
                     i]->ClipProperties.uiStillPicWidth; //ARGB_Width;
-                    M4OSA_TRACE1_1("CLIP M4xVSS_SendCommand  is %d", pParams->height);
-                    M4OSA_TRACE1_1("CLIP M4xVSS_SendCommand  is %d", pParams->height);
+                    M4OSA_TRACE3_1("CLIP M4xVSS_SendCommand ARGB8888 H = %d", pParams->height);
+                    M4OSA_TRACE3_1("CLIP M4xVSS_SendCommand ARGB8888 W = %d", pParams->width);
 
                     if( xVSS_context->pPTo3GPPparamsList
                         == M4OSA_NULL ) /* Means it is the first element of the list */
@@ -3892,9 +3892,9 @@
                         xVSS_context,
                         &(xVSS_context->pSettings->Effects[j]),
                         framingCtx->aFramingCtx,xVSS_context->pSettings->xVSS.outputVideoSize);
-                    M4OSA_TRACE1_1("FRAMMING AFTER M4xVSS_SendCommand  %d",
+                    M4OSA_TRACE3_1("FRAMING WIDTH BEFORE M4xVSS_SendCommand  %d",
                         framingCtx->aFramingCtx->width);
-                    M4OSA_TRACE1_1("FRAMMING AFTER M4xVSS_SendCommand  %d",
+                    M4OSA_TRACE3_1("FRAMING HEIGHT BEFORE M4xVSS_SendCommand  %d",
                         framingCtx->aFramingCtx->height);
 
                     if( err != M4NO_ERROR )