Ticket #762: Fixed jitter buffer in handling DTX with relative short period of 'keep alive', e.g: Speex DTX seems to periodically send a keep alive frame every 20 silence frames.

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@2672 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjmedia/build/Jbtest.dat b/pjmedia/build/Jbtest.dat
index 6c836f0..3e2169c 100644
--- a/pjmedia/build/Jbtest.dat
+++ b/pjmedia/build/Jbtest.dat
@@ -184,14 +184,18 @@
 %adaptive 0 0 10
 !burst	    1
 !discard    0
-!lost	    3
-!empty	    1
+!lost	    7
+!empty	    3
 !delay	    3
 PGPGPGPGPGPGPGPGPGPG PGPGPGPGPGPGPGPGPGPG
 # Some losts
 LGPGPGLGPGPGPGLGPGPG
 # Normal
 PGPGPGPGPGPGPGPGPGPG PGPGPGPGPGPGPGPGPGPG
+# More losts
+PLPGGGPPPGGGPLPGGGPG PLPGGGPPPGGGPLPGGGPG
+# Normal
+PGPGPGPGPGPGPGPGPGPG PGPGPGPGPGPGPGPGPGPG
 .
 
 = Sequence restart
diff --git a/pjmedia/src/pjmedia/jbuf.c b/pjmedia/src/pjmedia/jbuf.c
index 1149503..1df68a5 100644
--- a/pjmedia/src/pjmedia/jbuf.c
+++ b/pjmedia/src/pjmedia/jbuf.c
@@ -315,10 +315,6 @@
 
     assert(frame_size <= framelist->frame_size);
 
-    /* the first ever frame since inited/resetted. */
-    if (framelist->origin == INVALID_OFFSET)
-	framelist->origin = index;
-
     /* too late or duplicated or sequence restart */
     if (index < framelist->origin) {
 	if (framelist->origin - index < MAX_MISORDER) {
@@ -330,6 +326,11 @@
 	}
     }
 
+    /* if jbuf is empty, just reset the origin */
+    if (framelist->size == 0) {
+	framelist->origin = index;
+    }
+
     /* get distance of this frame to the first frame in the buffer */
     distance = index - framelist->origin;
 
@@ -341,14 +342,8 @@
 	    framelist->origin = index;
 	    distance = 0;
 	} else {
-	    if (framelist->size == 0) {
-		/* if jbuf is empty, process the frame */
-		framelist->origin = index;
-		distance = 0;
-	    } else {
-		/* otherwise, reject the frame */
-		return PJ_ETOOMANY;
-	    }
+	    /* otherwise, reject the frame */
+	    return PJ_ETOOMANY;
 	}
     }