Skip to content
Snippets Groups Projects
Commit c8f07a68 authored by Grzegorz Sluja's avatar Grzegorz Sluja
Browse files

fixup! Fix RTP packet's timestamp based on the real incoming packet's lenght

Use the rtp timestamp received from pjsip and send it to DSP.
For some cases like playing audio file (howler tone, feature codes)
frame->len and frame->ts are 0 so we need to use the old way of
generating timestamp.
Also make sure the sequence number is always correct.
parent 9ded366b
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,7 @@
#include "asterisk/bridge.h"
#include "asterisk/stasis_system.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/rtp_engine.h"
#include <libubus.h>
#include <libpicoevent.h>
......@@ -76,7 +77,7 @@ static int brcm_in_conference(const struct brcm_pvt *p);
static int cwtimeout_cb(const void *data);
static int cwbeep_cb(const void *data);
static int r4hanguptimeout_cb(const void *data);
static void brcm_generate_rtp_packet(struct brcm_subchannel *p, uint8_t *packet_buf, int type, int marker, int dtmf_timestamp, int seqno, int len);
static void brcm_generate_rtp_packet(struct brcm_subchannel *p, uint8_t *packet_buf, int type, int seqno, unsigned int rtp_timestamp);
static void brcm_process_rtcp_packet(struct brcm_subchannel *p, uint8_t *rtcp_frame, uint32_t rtcp_size);
static int brcm_mute_connection(struct brcm_subchannel *p);
static int brcm_unmute_connection(struct brcm_subchannel *p);
......@@ -1600,6 +1601,7 @@ static int brcm_write(struct ast_channel *ast, struct ast_frame *frame)
struct brcm_subchannel *sub = ast_channel_tech_pvt(ast);
int packet_size;
audio_packet_t *ap;
unsigned int rtp_timestamp = frame->ts * (ast_rtp_get_rate(frame->subclass.format)/1000);
if (ast_channel_state(ast) != AST_STATE_UP && ast_channel_state(ast) != AST_STATE_RING) {
/* Silently ignore packets until channel is up */
......@@ -1633,7 +1635,7 @@ static int brcm_write(struct ast_channel *ast, struct ast_frame *frame)
pvt_lock(sub->parent, "TELCHAN write frame");
/* generate the rtp header */
brcm_generate_rtp_packet(sub, ap->rtp, CN, 0, 0, frame->seqno, frame->len);
brcm_generate_rtp_packet(sub, ap->rtp, CN, frame->seqno, rtp_timestamp);
/* set rtp payload_type sent to endpoint */
sub->codec = CN;
......@@ -1663,7 +1665,7 @@ static int brcm_write(struct ast_channel *ast, struct ast_frame *frame)
pvt_lock(sub->parent, "TELCHAN write frame");
/* generate the rtp header */
brcm_generate_rtp_packet(sub, ap->rtp, map_ast_codec_id_to_rtp(frame->subclass.format), 0, 0, frame->seqno, frame->len);
brcm_generate_rtp_packet(sub, ap->rtp, map_ast_codec_id_to_rtp(frame->subclass.format), frame->seqno, rtp_timestamp);
/* set rtp payload_type sent to endpoint */
sub->codec = map_ast_codec_id_to_rtp(frame->subclass.format);
......@@ -3490,6 +3492,7 @@ static struct brcm_pvt *brcm_allocate_pvt(void)
sub->connection_init = 0;
sub->channel_state = ONHOOK;
sub->time_stamp = 0;
sub->sequence_number = 0;
sub->ssrc = 0;
sub->codec = -1;
sub->parent = tmp;
......@@ -3754,6 +3757,7 @@ static void brcm_show_subchannels(struct ast_cli_args *a, struct brcm_pvt *p)
ast_cli(a->fd, " Channel state : %s\n", state2str(sub->channel_state));
ast_cli(a->fd, " Connection init : %d\n", sub->connection_init);
ast_cli(a->fd, " Codec used : %s\n", brcm_get_codec_string(sub->codec));
ast_cli(a->fd, " RTP sequence number : %d\n", sub->sequence_number);
ast_cli(a->fd, " RTP SSRC : %d\n", sub->ssrc);
ast_cli(a->fd, " RTP timestamp : %d\n", sub->time_stamp);
ast_cli(a->fd, " CW Timer id : %d\n", sub->cw_timer_id);
......@@ -5296,7 +5300,7 @@ static int brcm_close_connection(struct brcm_subchannel *sub)
/* Generate rtp payload, 12 bytes of header and 160 bytes of ulaw payload */
static void brcm_generate_rtp_packet(struct brcm_subchannel *sub, uint8_t *packet_buf, int type, int marker, int dtmf_timestamp, int seqno, int len) {
static void brcm_generate_rtp_packet(struct brcm_subchannel *sub, uint8_t *packet_buf, int type, int seqno, unsigned int rtp_timestamp) {
unsigned short* packet_buf16 = (unsigned short*)packet_buf;
unsigned int* packet_buf32 = (unsigned int*)packet_buf;
......@@ -5306,10 +5310,9 @@ static void brcm_generate_rtp_packet(struct brcm_subchannel *sub, uint8_t *packe
//Extension 0
//CSRC count 0
packet_buf[1] = type;
packet_buf[1] |= marker?0x80:0x00;
packet_buf16[1] = htons(seqno); //Add sequence number
packet_buf32[1] = htonl(sub->time_stamp); //Add timestamp
sub->time_stamp += len*8;
packet_buf16[1] = htons(seqno ? seqno : sub->sequence_number++); //Add sequence number
packet_buf32[1] = htonl(rtp_timestamp ? rtp_timestamp : sub->time_stamp); //Add timestamp
sub->time_stamp += sub->period*8;
packet_buf32[2] = sub->ssrc;
}
......
......@@ -141,6 +141,7 @@ struct brcm_subchannel {
enum CALL_DIRECTION call_direction; // Direction of call for the subchannel : 0 = incoming, 1 = outgoing
unsigned int connection_init; /* State for endpoint id connection initialization */
struct ast_frame fr; /* Frame */
uint16_t sequence_number; /* Endpoint RTP sequence number state */
unsigned int time_stamp; /* Endpoint RTP time stamp state */
unsigned int period; /* Endpoint RTP period */
unsigned int ssrc; /* Endpoint RTP synchronization source */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment