summaryrefslogtreecommitdiffstats
path: root/PICA_client.c
diff options
context:
space:
mode:
Diffstat (limited to 'PICA_client.c')
-rw-r--r--PICA_client.c98
1 files changed, 96 insertions, 2 deletions
diff --git a/PICA_client.c b/PICA_client.c
index 7609150..0339ef7 100644
--- a/PICA_client.c
+++ b/PICA_client.c
@@ -86,6 +86,7 @@ static unsigned int procmsg_CALL_AUDIOPARAM(unsigned char*, unsigned int, void*)
static unsigned int procmsg_CALL_VIDEOPARAM(unsigned char*, unsigned int, void*);
static unsigned int procmsg_CALL_AUDIO_PACKET(unsigned char*, unsigned int, void*);
static unsigned int procmsg_CALL_VIDEO_PACKET(unsigned char*, unsigned int, void*);
+static unsigned int procmsg_CALL_RECEPTION_REPORT(unsigned char*, unsigned int, void*);
static unsigned int procmsg_MEDIA_PINGREQ(unsigned char*, unsigned int, void*);
static unsigned int procmsg_MEDIA_PINGREP(unsigned char*, unsigned int, void*);
static unsigned int procmsg_MYTCPADDR(unsigned char*, unsigned int, void*);
@@ -135,6 +136,7 @@ const struct PICA_msginfo c2c_messages[] =
{PICA_PROTO_CALL_VIDEOPARAM, PICA_MSG_FIXED_SIZE, PICA_PROTO_CALL_VIDEOPARAM_SIZE, procmsg_CALL_VIDEOPARAM},
{PICA_PROTO_CALL_AUDIO_PACKET, PICA_MSG_VAR_SIZE, PICA_MSG_VARSIZE_INT16, procmsg_CALL_AUDIO_PACKET},
{PICA_PROTO_CALL_VIDEO_PACKET, PICA_MSG_VAR_SIZE, PICA_MSG_VARSIZE_INT16, procmsg_CALL_VIDEO_PACKET},
+ {PICA_PROTO_CALL_RECEPTION_REPORT, PICA_MSG_FIXED_SIZE, PICA_PROTO_CALL_RECEPTION_REPORT_SIZE, procmsg_CALL_RECEPTION_REPORT},
{PICA_PROTO_SENDFILEREQUEST, PICA_MSG_VAR_SIZE, PICA_MSG_VARSIZE_INT16, procmsg_SENDFILEREQUEST},
{PICA_PROTO_ACCEPTEDFILE, PICA_MSG_FIXED_SIZE, PICA_PROTO_ACCEPTEDFILE_SIZE, procmsg_ACCEPTEDFILE},
{PICA_PROTO_DENIEDFILE, PICA_MSG_FIXED_SIZE, PICA_PROTO_DENIEDFILE_SIZE, procmsg_DENIEDFILE},
@@ -2500,8 +2502,11 @@ static int call_answered(struct PICA_c2c *chn)
return PICA_OK;
}
+static void call_send_reception_report(struct PICA_c2c *chn);
+
/* Sends 0x70 and 0x71 that were waiting for the address of the call socket
- * once it is known, or once waiting for it is over.
+ * once it is known, or once waiting for it is over, and the 0x79 reports of
+ * active calls.
*/
static void process_calls(struct PICA_c2n *c2n)
{
@@ -2511,7 +2516,13 @@ static void process_calls(struct PICA_c2n *c2n)
{
struct PICA_media_call *mc = c2c->media_call;
- if (!mc || !mc->pending_msg || !PICA_media_call_ready(c2c))
+ if (!mc)
+ continue;
+
+ if (c2c->call_state == PICA_CALL_STATE_ACTIVE)
+ call_send_reception_report(c2c);
+
+ if (!mc->pending_msg || !PICA_media_call_ready(c2c))
continue;
if (mc->pending_msg == PICA_PROTO_CALLREQ && c2c->call_state == PICA_CALL_STATE_CALLING)
@@ -2708,6 +2719,8 @@ static unsigned int procmsg_CALL_AUDIO_PACKET(unsigned char *buf, unsigned int n
uint32_t timestamp = *(uint32_t*)(buf + 4 + PICA_PROTO_CALL_PACKET_SEQNUM_SIZE);
uint16_t pkt_size = tail_size - PICA_PROTO_CALL_PACKET_HDRSIZE;
+ PICA_media_rx_packet(chan, 0, seq_num, timestamp, pkt_size);
+
callbacks.call_audio_packet_cb(chan->peer_id, seq_num, timestamp, pkt_size, buf + 4 + PICA_PROTO_CALL_PACKET_HDRSIZE);
return 1;
@@ -2746,11 +2759,92 @@ static unsigned int procmsg_CALL_VIDEO_PACKET(unsigned char *buf, unsigned int n
uint32_t timestamp = *(uint32_t*)(buf + 4 + PICA_PROTO_CALL_PACKET_SEQNUM_SIZE);
uint16_t pkt_size = tail_size - PICA_PROTO_CALL_PACKET_HDRSIZE;
+ PICA_media_rx_packet(chan, 1, seq_num, timestamp, pkt_size);
+
callbacks.call_video_packet_cb(chan->peer_id, seq_num, timestamp, pkt_size, buf + 4 + PICA_PROTO_CALL_PACKET_HDRSIZE);
return 1;
}
+static uint16_t get_le16(const unsigned char *p)
+{
+ return (uint16_t)(p[0] | (p[1] << 8));
+}
+
+static uint32_t get_le32(const unsigned char *p)
+{
+ return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
+}
+
+static void put_le16(unsigned char *p, uint16_t v)
+{
+ p[0] = v & 0xFF;
+ p[1] = (v >> 8) & 0xFF;
+}
+
+static void put_le32(unsigned char *p, uint32_t v)
+{
+ p[0] = v & 0xFF;
+ p[1] = (v >> 8) & 0xFF;
+ p[2] = (v >> 16) & 0xFF;
+ p[3] = (v >> 24) & 0xFF;
+}
+
+/* Ignored rather than a protocol error outside of an active call: one sent
+ * just before the peer learnt that the call is over is still on its way when
+ * the hangup has already been processed here.
+ */
+static unsigned int procmsg_CALL_RECEPTION_REPORT(unsigned char *buf, unsigned int nb, void *p)
+{
+ struct PICA_c2c *chan = (struct PICA_c2c *)p;
+ struct PICA_call_reception_report r;
+
+ if (chan->call_state != PICA_CALL_STATE_ACTIVE)
+ return 1;
+
+ r.period = get_le16(buf + 2);
+ r.audio_received = get_le16(buf + 4);
+ r.audio_lost = get_le16(buf + 6);
+ r.video_received = get_le16(buf + 8);
+ r.video_lost = get_le16(buf + 10);
+ r.audio_octets = get_le32(buf + 12);
+ r.video_octets = get_le32(buf + 16);
+ r.queuing_delay = get_le16(buf + 20);
+
+ if (callbacks.call_reception_report_cb)
+ callbacks.call_reception_report_cb(chan->peer_id, &r);
+
+ return 1;
+}
+
+/* Sends 0x79 when a report period of the call is over. */
+static void call_send_reception_report(struct PICA_c2c *chn)
+{
+ struct PICA_call_reception_report r;
+ struct PICA_proto_msg *mp;
+
+ if (!PICA_media_rx_report(chn, &r))
+ return;
+
+ /* Over the c2c connection, or the directc2c one once it has taken over,
+ * whatever carries the media: the report has to arrive even when the
+ * media connection is losing most of what it carries.
+ */
+ mp = c2c_writebuf_push(chn, PICA_PROTO_CALL_RECEPTION_REPORT, PICA_PROTO_CALL_RECEPTION_REPORT_SIZE);
+
+ if (!mp)
+ return;
+
+ put_le16(mp->tail + 0, r.period);
+ put_le16(mp->tail + 2, r.audio_received);
+ put_le16(mp->tail + 4, r.audio_lost);
+ put_le16(mp->tail + 6, r.video_received);
+ put_le16(mp->tail + 8, r.video_lost);
+ put_le32(mp->tail + 10, r.audio_octets);
+ put_le32(mp->tail + 14, r.video_octets);
+ put_le16(mp->tail + 18, r.queuing_delay);
+}
+
static int c2n_optstage7_multilogin(struct PICA_c2n *c2n)
{
struct PICA_proto_msg *mp;