blob: 525da8e651079a0ce6a32ffbf6535f57f8af9765 [file] [log] [blame]
Pau Espin Pedrol1158cc62024-03-21 17:21:35 +01001module SDP_Templates {
2
3/* SDP Templates, building on top of SDP_Types from Ericsson.
4 *
5 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 */
11
12import from SDP_Types all;
13
14/* SDP Templates */
15template SDP_Origin ts_SDP_origin(charstring addr, charstring session_id,
16 charstring session_version := "1",
17 charstring addr_type := "IP4",
18 charstring user_name := "-") := {
19 user_name := user_name,
20 session_id := session_id,
21 session_version := session_version,
22 net_type := "IN",
23 addr_type := addr_type,
24 addr := addr
25}
26
27template SDP_connection ts_SDP_connection_IP(charstring addr, charstring addr_type := "IP4",
28 template integer ttl := omit,
29 template integer num_of_addr := omit) :={
30 net_type := "IN",
31 addr_type := addr_type,
32 conn_addr := {
33 addr := addr,
34 ttl := ttl,
35 num_of_addr := num_of_addr
36 }
37}
38
39template SDP_connection tr_SDP_connection_IP(template charstring addr, template charstring addr_type := ?,
40 template integer ttl := *,
41 template integer num_of_addr := *) := {
42 net_type := "IN",
43 addr_type := addr_type,
44 conn_addr := {
45 addr := addr,
46 ttl := ttl,
47 num_of_addr := num_of_addr
48 }
49}
50
51template SDP_time ts_SDP_time(charstring beg, charstring end) := {
52 time_field := {
53 start_time := beg,
54 stop_time := end
55 },
56 time_repeat := omit
57}
58
59template SDP_media_desc ts_SDP_media_desc(integer port_number, SDP_fmt_list fmts,
60 SDP_attribute_list attributes) := {
61 media_field := {
62 media := "audio",
63 ports := {
64 port_number := port_number,
65 num_of_ports := omit
66 },
67 transport := "RTP/AVP",
68 fmts := fmts
69 },
70 information := omit,
71 connections := omit,
72 bandwidth := omit,
73 key := omit,
74 attributes := attributes
75}
76
77template SDP_media_desc tr_SDP_media_desc(template integer port_number := ?,
78 template SDP_fmt_list fmts := ?,
79 template SDP_attribute_list attributes := ?) := {
80 media_field := {
81 media := "audio",
82 ports := {
83 port_number := port_number,
84 num_of_ports := omit
85 },
86 transport := "RTP/AVP",
87 fmts := fmts
88 },
89 information := *,
90 connections := *,
91 bandwidth := *,
92 key := *,
93 attributes := attributes
94}
95
96/* master template for generating SDP based in template arguments */
97template SDP_Message ts_SDP(charstring local_addr, charstring remote_addr,
98 charstring session_id, charstring session_version,
99 integer rtp_port, SDP_fmt_list fmts,
100 SDP_attribute_list attributes) := {
101 protocol_version := 0,
102 origin := ts_SDP_origin(local_addr, session_id, session_version, f_sdp_addr2addrtype(local_addr)),
103 session_name := "-",
104 information := omit,
105 uri := omit,
106 emails := omit,
107 phone_numbers := omit,
108 connection := ts_SDP_connection_IP(remote_addr, f_sdp_addr2addrtype(remote_addr)),
109 bandwidth := omit,
110 times := { ts_SDP_time("0","0") },
111 timezone_adjustments := omit,
112 key := omit,
113 attributes := omit,
114 media_list := { ts_SDP_media_desc(rtp_port, fmts, attributes) }
115}
116
117template SDP_Message tr_SDP(template charstring remote_addr := ?, template integer rtp_port := ?) := {
118 protocol_version := 0,
119 origin := ?,
120 session_name := ?,
121 information := *,
122 uri := *,
123 emails := *,
124 phone_numbers := *,
125 connection := tr_SDP_connection_IP(remote_addr, ?),
126 bandwidth := *,
127 times := ?,
128 timezone_adjustments := *,
129 key := *,
130 attributes := *,
131 media_list := { tr_SDP_media_desc(rtp_port) }
132}
133
134template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := {
135 rtpmap := {
136 attr_value := int2str(fmt) & " " & val
137 }
138}
139template SDP_attribute ts_SDP_ptime(integer p) := {
140 ptime := {
141 attr_value := int2str(p)
142 }
143}
144template SDP_attribute ts_SDP_fmtp(integer fmt, charstring val) := {
145 fmtp := {
146 attr_value := int2str(fmt) & " " & val
147 }
148}
149
150function f_sdp_addr2addrtype(charstring addr) return charstring {
151 for (var integer i := 0; i < lengthof(addr); i := i + 1) {
152 if (addr[i] == ":") {
153 return "IP6";
154 }
155 }
156 return "IP4";
157}
158
159}