[Asterisk-code-review] translate: Re-enables native Packet-Loss Concealment (PLC) f... (asterisk[master])

Alexander Traud asteriskteam at digium.com
Tue Dec 15 14:06:00 CST 2015


Alexander Traud has uploaded a new change for review.

  https://gerrit.asterisk.org/1820

Change subject: translate: Re-enables native Packet-Loss Concealment (PLC) for ilBC and Speex.
......................................................................

translate: Re-enables native Packet-Loss Concealment (PLC) for ilBC and Speex.

ASTERISK-25629 #close

Change-Id: Ibfcf0670e094e9718d82fd9920f1fb2dae122006
---
M main/translate.c
1 file changed, 66 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/20/1820/2

diff --git a/main/translate.c b/main/translate.c
index 8d37e37..77eb92a 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -524,13 +524,14 @@
 /*! \brief do the actual translation */
 struct ast_frame *ast_translate(struct ast_trans_pvt *path, struct ast_frame *f, int consume)
 {
-	struct ast_trans_pvt *p = path;
-	struct ast_frame *out;
+	struct ast_trans_pvt *p;
+	struct ast_frame *list, *out = NULL;
 	struct timeval delivery;
 	int has_timing_info;
 	long ts;
 	long len;
 	int seqno;
+	unsigned int frames_missing = 0;
 
 	has_timing_info = ast_test_flag(f, AST_FRFLAG_HAS_TIMING_INFO);
 	ts = f->ts;
@@ -541,6 +542,27 @@
 		if (!ast_tvzero(path->nextin)) {
 			/* Make sure this is in line with what we were expecting */
 			if (!ast_tveq(path->nextin, f->delivery)) {
+				/* For native PLC, determine the amout of lost packets */
+				if (path->t->native_plc && path->f.seqno) { /* not at start 0 */
+					if (seqno < path->f.seqno) { /* seqno overrun situation */
+						frames_missing = 0xffff + seqno - path->f.seqno - 1;
+					} else {
+						frames_missing = seqno - path->f.seqno - 1;
+					}
+					/* Out-of-order packet - more precise: late packet */
+					if (0x7fff < frames_missing) {
+						if (consume) {
+							ast_frfree(f);
+						}
+						/*
+						 * Do not pass a late packet to transcoding module,
+						 * because that confuses the internal state of the
+						 * library (packets inter-depent). With the next valid
+						 * packet, this is going to be threated as lost packet.
+						 */
+						return NULL;
+					}
+				}
 				/* The time has changed between what we expected and this
 				   most recent time on the new packet.  If we have a
 				   valid prediction adjust our output time appropriately */
@@ -560,18 +582,51 @@
 			 f->samples, ast_format_get_sample_rate(f->subclass.format)));
 	}
 	delivery = f->delivery;
-	for (out = f; out && p ; p = p->next) {
-		struct ast_frame *current = out;
 
-		do {
-			framein(p, current);
-			current = AST_LIST_NEXT(current, frame_list);
-		} while (current);
-		if (out != f) {
-			ast_frfree(out);
+	while (0 < frames_missing) { /* lost packet(s) */
+		struct ast_frame *missed = ast_malloc(sizeof(*missed));
+
+		if (missed) {
+			*missed = ast_null_frame;
+			missed->samples = f->samples;
+			missed->subclass.format = ao2_bump(f->subclass.format);
+			missed->seqno = seqno - frames_missing;
+			AST_LIST_NEXT(missed, frame_list) = f;
+			f = missed; /* f is head because of if (consume) then ast_free(f) */
 		}
-		out = p->t->frameout(p);
+
+		frames_missing--;
 	}
+
+	for (list = f; list; list = AST_LIST_NEXT(list, frame_list)) {
+		struct ast_frame *inner;
+
+		for (inner = list, p = path; inner && p; p = p->next) {
+			framein(p, inner);
+			if (inner != list) {
+				ast_frfree(inner);
+			}
+			inner = p->t->frameout(p);
+		}
+		if (out && inner) {
+			struct ast_frame *current = out;
+
+			while (current != inner && AST_LIST_NEXT(current, frame_list)) {
+				current = AST_LIST_NEXT(current, frame_list);
+			}
+			/*
+			 * Now, 'current' points to the
+			 * A) last element in the list of 'out' (inner is new), or
+			 * B) is the same as 'inner' (exists already in list).
+			 */
+			if (current != inner) {
+				AST_LIST_NEXT(current, frame_list) = inner;
+			}
+		} else if (inner) {
+			out = inner;
+		}
+	}
+
 	if (out) {
 		/* we have a frame, play with times */
 		if (!ast_tvzero(delivery)) {

-- 
To view, visit https://gerrit.asterisk.org/1820
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibfcf0670e094e9718d82fd9920f1fb2dae122006
Gerrit-PatchSet: 2
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Alexander Traud <pabstraud at compuserve.com>
Gerrit-Reviewer: Alexander Traud <pabstraud at compuserve.com>



More information about the asterisk-code-review mailing list