FreeCalypso > hg > themwi-rtp-lib
annotate src/set_sdes.c @ 33:e70e7b266f89
hook in RTCP output
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 08 Jul 2024 07:25:19 +0000 |
parents | 284fcb5868e2 |
children |
rev | line source |
---|---|
31
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement the function that prepares the SDES subpacket |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * for subsequent RTCP output. |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdbool.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <errno.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <arpa/inet.h> /* for network byte order functions */ |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/talloc.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <themwi/rtp/endp.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <themwi/rtp/rtcp_defs.h> |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int twrtp_endp_set_sdes(struct twrtp_endp *endp, const char *cname, |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 const char *name, const char *email, const char *phone, |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 const char *loc, const char *tool, const char *note) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint16_t len_str, len_padded, len_with_hdr, len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 struct rtcp_sr_rr_hdr *hdr; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 uint8_t *dp; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (!cname) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return -EINVAL; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 len_str = strlen(cname) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (name) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 len_str += strlen(name) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (email) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 len_str += strlen(email) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (phone) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 len_str += strlen(phone) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 if (loc) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 len_str += strlen(loc) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (tool) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 len_str += strlen(tool) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (note) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 len_str += strlen(note) + 2; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 len_padded = (len_str + 4) & ~3; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 len_with_hdr = len_padded + sizeof(struct rtcp_sr_rr_hdr); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (endp->sdes_buf) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 talloc_free(endp->sdes_buf); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 endp->sdes_buf = talloc_size(endp, len_with_hdr); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (!endp->sdes_buf) |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return -ENOMEM; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 hdr = (struct rtcp_sr_rr_hdr *) endp->sdes_buf; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 hdr->v_p_rc = 0x81; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 hdr->pt = RTCP_PT_SDES; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 hdr->len = htons(len_with_hdr / 4 - 1); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 hdr->ssrc = htonl(endp->tx.ssrc); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 dp = endp->sdes_buf + sizeof(struct rtcp_sr_rr_hdr); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 *dp++ = SDES_ITEM_CNAME; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 *dp++ = len = strlen(cname); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 memcpy(dp, cname, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (name) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 *dp++ = SDES_ITEM_NAME; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 *dp++ = len = strlen(name); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 memcpy(dp, name, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (email) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 *dp++ = SDES_ITEM_EMAIL; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 *dp++ = len = strlen(email); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 memcpy(dp, email, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (phone) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 *dp++ = SDES_ITEM_PHONE; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 *dp++ = len = strlen(phone); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 memcpy(dp, phone, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (loc) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 *dp++ = SDES_ITEM_LOC; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 *dp++ = len = strlen(loc); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 memcpy(dp, loc, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (tool) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 *dp++ = SDES_ITEM_TOOL; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 *dp++ = len = strlen(tool); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 memcpy(dp, tool, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (note) { |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *dp++ = SDES_ITEM_NOTE; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 *dp++ = len = strlen(note); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 memcpy(dp, note, len); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 dp += len; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 memset(dp, 0, len_padded - len_str); |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 endp->sdes_len = len_with_hdr; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 return 0; |
284fcb5868e2
implement SDES setting
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |