diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-04-25 17:20:38 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-04-27 08:50:01 +0000 |
commit | e98afe5808176efb60298a2f764e8e11efaf580b (patch) | |
tree | cb53aebb0bacd93ca77a21ae9152502a6ebf7692 /src/osmux.c | |
parent | a67c47cab412b631c19e3f32167b9f5a0edc39ba (diff) |
osmux: Add RTP marker bit support
According to RFC4867 (RTP payload format for AMR):
"The RTP header marker bit (M) SHALL be set to 1 if the first frameblock
carried in the packet contains a speech frame which is the first in a
talkspurt. For all other packets the marker bit SHALL be set to zero (M=0)."
This information bit provides a way for the receiver to better
synchronize the delay with ther sender.
This is specially useful if AMR DTX features are supported and
enabled on the sender.
Change-Id: I0315658159429603f1d80a168718b026015060e9
Diffstat (limited to 'src/osmux.c')
-rw-r--r-- | src/osmux.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/osmux.c b/src/osmux.c index 1dcd04f..4d12427 100644 --- a/src/osmux.c +++ b/src/osmux.c @@ -105,8 +105,8 @@ next: } static struct msgb * -osmux_rebuild_rtp(struct osmux_out_handle *h, - struct osmux_hdr *osmuxh, void *payload, int payload_len) +osmux_rebuild_rtp(struct osmux_out_handle *h, struct osmux_hdr *osmuxh, + void *payload, int payload_len, bool first_pkt) { struct msgb *out_msg; struct rtp_hdr *rtph; @@ -129,6 +129,8 @@ osmux_rebuild_rtp(struct osmux_out_handle *h, rtph->timestamp = htonl(h->rtp_timestamp); rtph->sequence = htons(h->rtp_seq); rtph->ssrc = htonl(h->rtp_ssrc); + /* rtp packet with the marker bit is always warranted to be the first one */ + rtph->marker = first_pkt && osmuxh->rtp_m; msgb_put(out_msg, sizeof(struct rtp_hdr)); @@ -166,7 +168,7 @@ int osmux_xfrm_output(struct osmux_hdr *osmuxh, struct osmux_out_handle *h, msg = osmux_rebuild_rtp(h, osmuxh, osmux_get_payload(osmuxh) + i * osmo_amr_bytes(osmuxh->amr_ft), - osmo_amr_bytes(osmuxh->amr_ft)); + osmo_amr_bytes(osmuxh->amr_ft), !i); if (msg == NULL) continue; @@ -264,6 +266,7 @@ static int osmux_batch_put(struct osmux_batch *batch, osmuxh = (struct osmux_hdr *)state->out_msg->tail; osmuxh->ft = OSMUX_FT_VOICE_AMR; osmuxh->ctr = 0; + osmuxh->rtp_m = osmuxh->rtp_m || state->rtph->marker; osmuxh->amr_f = state->amrh->f; osmuxh->amr_q= state->amrh->q; osmuxh->seq = batch->seq++; @@ -593,6 +596,13 @@ osmux_batch_add(struct osmux_batch *batch, uint32_t batch_factor, struct msgb *m if (bytes > batch->remaining_bytes) return 1; + /* Init of talkspurt (RTP M marker bit) needs to be in the first AMR slot + * of the OSMUX packet, enforce sending previous batch if required: + */ + if (rtph->marker && circuit->nmsgs != 0) + return 1; + + /* Extra validation: check if this message already exists, should not * happen but make sure we don't propagate duplicated messages. */ |