comparison src/set_sdes.c @ 31:284fcb5868e2

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