avsync-lib: pattern check limited in one frame room [1/1]

PD#SWPL-47065

Problem:
AV Sync 60Hz video on 59.94 display will cause longer
than expected AV-sync diff range. NTS failed.
reason is the pattern check did not have an up pts limit
to keep the pattern, cause diff accumulated to bigger number
then reset.

Solution:
*set upper limit to one v-sync inverval room for the pattern
adjustment, that is the common pull down/up method
*Added env setting AML_AVSYNC_DEBUG_LEVEL option to overwrite
the default settings from other module for convinient debug

Verify:
AH212

Change-Id: I386c092efd493f55e48d351644ca177e4a0a85d9
Signed-off-by: yongchun.li <yongchun.li@amlogic.com>
diff --git a/src/pattern.c b/src/pattern.c
index 231b399..8210c08 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -144,9 +144,11 @@
             /* check if next frame will toggle after 3 vsyncs */
             /* 22222...22222 -> 222..2213(2)22...22 */
             /* check if next frame will toggle after 3 vsyncs */
-
+            /* shall only allow one extra interval space to play around */
             if (((int)(systime + (expected_prev_interval + 1) *
-                        vsync_interval - npts) >= 0)) {
+                        vsync_interval - npts) >= 0) &&
+                ((int)(systime + (expected_prev_interval + 2) *
+                        vsync_interval - npts) < 0)) {
                 *expire = false;
                 log_debug("hold frame for pattern: %d", pd->detected);
             }