Pau Espin Pedrol | 1158cc6 | 2024-03-21 17:21:35 +0100 | [diff] [blame] | 1 | module 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 | |
| 12 | import from SDP_Types all; |
| 13 | |
| 14 | /* SDP Templates */ |
| 15 | template 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 | |
| 27 | template 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 | |
| 39 | template 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 | |
| 51 | template 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 | |
| 59 | template 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 | |
| 77 | template 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 */ |
| 97 | template 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 | |
| 117 | template 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 | |
| 134 | template SDP_attribute ts_SDP_rtpmap(integer fmt, charstring val) := { |
| 135 | rtpmap := { |
| 136 | attr_value := int2str(fmt) & " " & val |
| 137 | } |
| 138 | } |
| 139 | template SDP_attribute ts_SDP_ptime(integer p) := { |
| 140 | ptime := { |
| 141 | attr_value := int2str(p) |
| 142 | } |
| 143 | } |
| 144 | template SDP_attribute ts_SDP_fmtp(integer fmt, charstring val) := { |
| 145 | fmtp := { |
| 146 | attr_value := int2str(fmt) & " " & val |
| 147 | } |
| 148 | } |
| 149 | |
Pau Espin Pedrol | 4713138 | 2024-06-20 13:51:18 +0200 | [diff] [blame] | 150 | /* rfc3312 */ |
| 151 | const charstring c_SDP_PRECON_TYPE_qos := "qos"; |
| 152 | const charstring c_SDP_PRECON_STRENGTH_TAG_mandatory := "mandatory"; |
| 153 | const charstring c_SDP_PRECON_STRENGTH_TAG_optional := "optional"; |
| 154 | const charstring c_SDP_PRECON_STRENGTH_TAG_none := "none"; |
| 155 | const charstring c_SDP_PRECON_STRENGTH_TAG_failure := "failure"; |
| 156 | const charstring c_SDP_PRECON_STRENGTH_TAG_unknown := "unknown"; |
| 157 | const charstring c_SDP_PRECON_STATUS_TYPE_e2e := "e2e"; |
| 158 | const charstring c_SDP_PRECON_STATUS_TYPE_local := "local"; |
| 159 | const charstring c_SDP_PRECON_STATUS_TYPE_remote := "remote"; |
| 160 | const charstring c_SDP_PRECON_DIR_TAG_none := "none"; |
| 161 | const charstring c_SDP_PRECON_DIR_TAG_send := "send"; |
| 162 | const charstring c_SDP_PRECON_DIR_TAG_recv := "recv"; |
| 163 | const charstring c_SDP_PRECON_DIR_TAG_sendrecv := "sendrecv"; |
| 164 | |
| 165 | template (present) SDP_attribute tr_SDP_curr(charstring status_type, |
| 166 | charstring dir_tag, |
| 167 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 168 | curr := { |
| 169 | attr_value := precondition_type & " " & status_type & " " & dir_tag |
| 170 | } |
| 171 | } |
| 172 | template (present) SDP_attribute tr_SDP_curr_present := { |
| 173 | curr := { |
| 174 | attr_value := ? |
| 175 | } |
| 176 | } |
| 177 | template (value) SDP_attribute ts_SDP_curr(charstring status_type, |
| 178 | charstring dir_tag, |
| 179 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 180 | curr := { |
| 181 | attr_value := precondition_type & " " & status_type & " " & dir_tag |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | template (present) SDP_attribute tr_SDP_des(charstring status_type, |
| 186 | charstring strength_tag, |
| 187 | charstring dir_tag, |
| 188 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 189 | curr := { |
| 190 | attr_value := precondition_type & " " & strength_tag & " " & status_type & " " & dir_tag |
| 191 | } |
| 192 | } |
| 193 | template (present) SDP_attribute tr_SDP_des_present := { |
| 194 | des := { |
| 195 | attr_value := ? |
| 196 | } |
| 197 | } |
| 198 | template (value) SDP_attribute ts_SDP_des(charstring status_type, |
| 199 | charstring strength_tag, |
| 200 | charstring dir_tag, |
| 201 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 202 | des := { |
| 203 | attr_value := precondition_type & " " & strength_tag & " " & status_type & " " & dir_tag |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | template (present) SDP_attribute tr_SDP_conf(charstring status_type, |
| 208 | charstring dir_tag, |
| 209 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 210 | conf := { |
| 211 | attr_value := precondition_type & " " & status_type & " " & dir_tag |
| 212 | } |
| 213 | } |
| 214 | template (present) SDP_attribute tr_SDP_conf_present := { |
| 215 | conf := { |
| 216 | attr_value := ? |
| 217 | } |
| 218 | } |
| 219 | template (value) SDP_attribute ts_SDP_conf(charstring status_type, |
| 220 | charstring dir_tag, |
| 221 | charstring precondition_type := c_SDP_PRECON_TYPE_qos) := { |
| 222 | conf := { |
| 223 | attr_value := precondition_type & " " & status_type & " " & dir_tag |
| 224 | } |
| 225 | } |
| 226 | |
Pau Espin Pedrol | 1158cc6 | 2024-03-21 17:21:35 +0100 | [diff] [blame] | 227 | function f_sdp_addr2addrtype(charstring addr) return charstring { |
| 228 | for (var integer i := 0; i < lengthof(addr); i := i + 1) { |
| 229 | if (addr[i] == ":") { |
| 230 | return "IP6"; |
| 231 | } |
| 232 | } |
| 233 | return "IP4"; |
| 234 | } |
| 235 | |
| 236 | } |