Index: translate.c =================================================================== RCS file: /usr/cvsroot/asterisk/translate.c,v retrieving revision 1.40 diff -u -p -r1.40 translate.c --- translate.c 15 Jul 2005 23:00:46 -0000 1.40 +++ translate.c 22 Jul 2005 10:11:54 -0000 @@ -149,10 +149,12 @@ struct ast_frame *ast_translate(struct a /* Make sure this is in line with what we were expecting */ if (!ast_tveq(path->nextin, f->delivery)) { /* The time has changed between what we expected and this - most recent time on the new packet. Adjust our output - time appropriately */ - path->nextout = ast_tvadd(path->nextout, - ast_tvsub(f->delivery, path->nextin)); + most recent time on the new packet. If we have a + valid prediction adjust our output time appropriately */ + if(!ast_tvzero(path->nextout)) { + path->nextout = ast_tvadd(path->nextout, + ast_tvsub(f->delivery, path->nextin)); + } path->nextin = f->delivery; } } else { @@ -177,15 +179,22 @@ struct ast_frame *ast_translate(struct a p->next->step->framein(p->next->state, out); else { if (!ast_tvzero(delivery)) { + /* Regenerate prediction after a discontinuity */ + if(ast_tvzero(path->nextout)) + path->nextout = ast_tvnow(); + /* Use next predicted outgoing timestamp */ out->delivery = path->nextout; /* Predict next outgoing timestamp from samples in this frame. */ path->nextout = ast_tvadd(path->nextout, ast_samp2tv( out->samples, 8000)); } else { out->delivery = ast_tv(0, 0); } + /* Invalidate prediction if we're entering a silence period */ + if(out->frametype == AST_FRAME_CNG) + path->nextout = ast_tv(0, 0); return out; } p = p->next;