osmux: Early return on error or batch full during osmux_replay_lost_packets()
If there's an error while replaying lost packets, return the error to the caller. If the batch is found full, early return indicating so, there's no need to continue flow calling osmux_batch_enqueue() in osmux_batch_add() again. Change-Id: I62f494d2b2e7903a6683f6dea00781bb721a3d41
This commit is contained in:
parent
d6e8765faf
commit
a50895f7eb
20
src/osmux.c
20
src/osmux.c
|
@ -560,23 +560,24 @@ static int osmux_rtp_amr_payload_len(struct msgb *msg, struct rtp_hdr *rtph)
|
||||||
return amr_payload_len;
|
return amr_payload_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void osmux_replay_lost_packets(struct osmux_circuit *circuit,
|
/* returns: 1 if batch is full, 0 if batch still not full, negative on error. */
|
||||||
|
static int osmux_replay_lost_packets(struct osmux_circuit *circuit,
|
||||||
struct rtp_hdr *cur_rtph, int batch_factor)
|
struct rtp_hdr *cur_rtph, int batch_factor)
|
||||||
{
|
{
|
||||||
int16_t diff;
|
int16_t diff;
|
||||||
struct msgb *last;
|
struct msgb *last;
|
||||||
struct rtp_hdr *rtph;
|
struct rtp_hdr *rtph;
|
||||||
int i;
|
int i, rc;
|
||||||
|
|
||||||
/* Have we seen any RTP packet in this batch before? */
|
/* Have we seen any RTP packet in this batch before? */
|
||||||
if (llist_empty(&circuit->msg_list))
|
if (llist_empty(&circuit->msg_list))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
/* Get last RTP packet seen in this batch */
|
/* Get last RTP packet seen in this batch */
|
||||||
last = llist_entry(circuit->msg_list.prev, struct msgb, list);
|
last = llist_entry(circuit->msg_list.prev, struct msgb, list);
|
||||||
rtph = osmo_rtp_get_hdr(last);
|
rtph = osmo_rtp_get_hdr(last);
|
||||||
if (rtph == NULL)
|
if (rtph == NULL)
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
diff = ntohs(cur_rtph->sequence) - ntohs(rtph->sequence);
|
diff = ntohs(cur_rtph->sequence) - ntohs(rtph->sequence);
|
||||||
|
|
||||||
|
@ -584,6 +585,7 @@ static void osmux_replay_lost_packets(struct osmux_circuit *circuit,
|
||||||
if (diff > 16)
|
if (diff > 16)
|
||||||
diff = 16;
|
diff = 16;
|
||||||
|
|
||||||
|
rc = 0;
|
||||||
/* If diff between last RTP packet seen and this one is > 1,
|
/* If diff between last RTP packet seen and this one is > 1,
|
||||||
* then we lost several RTP packets, let's replay them.
|
* then we lost several RTP packets, let's replay them.
|
||||||
*/
|
*/
|
||||||
|
@ -607,13 +609,15 @@ static void osmux_replay_lost_packets(struct osmux_circuit *circuit,
|
||||||
DELTA_RTP_TIMESTAMP);
|
DELTA_RTP_TIMESTAMP);
|
||||||
|
|
||||||
/* No more room in this batch, skip padding with more clones */
|
/* No more room in this batch, skip padding with more clones */
|
||||||
if (osmux_batch_enqueue(clone, circuit, batch_factor) != 0) {
|
rc = osmux_batch_enqueue(clone, circuit, batch_factor);
|
||||||
|
if (rc != 0) {
|
||||||
msgb_free(clone);
|
msgb_free(clone);
|
||||||
break;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGP(DLMUX, LOGL_ERROR, "adding cloned RTP\n");
|
LOGP(DLMUX, LOGL_ERROR, "adding cloned RTP\n");
|
||||||
}
|
}
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct osmux_circuit *
|
static struct osmux_circuit *
|
||||||
|
@ -727,7 +731,9 @@ osmux_batch_add(struct osmux_batch *batch, uint32_t batch_factor, struct msgb *m
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Handle RTP packet loss scenario */
|
/* Handle RTP packet loss scenario */
|
||||||
osmux_replay_lost_packets(circuit, rtph, batch_factor);
|
rc = osmux_replay_lost_packets(circuit, rtph, batch_factor);
|
||||||
|
if (rc != 0)
|
||||||
|
return rc;
|
||||||
|
|
||||||
/* This batch is full, force batch delivery */
|
/* This batch is full, force batch delivery */
|
||||||
rc = osmux_batch_enqueue(msg, circuit, batch_factor);
|
rc = osmux_batch_enqueue(msg, circuit, batch_factor);
|
||||||
|
|
Loading…
Reference in New Issue