Changeset 60db87243c9426e59557d0f0f2e30276cc2f9c94
- Timestamp:
- 01/05/07 19:14:14
(1 year ago)
- Author:
- Rémi Denis-Courmont <rem@videolan.org>
- git-committer:
- Rémi Denis-Courmont <rem@videolan.org> 1178039654 +0000
- git-parent:
[7681a9b5d1df0cbcaa5914cc33bb40fee8276a36]
- git-author:
- Rémi Denis-Courmont <rem@videolan.org> 1178039654 +0000
- Message:
Add helper for SDP media description formatting
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| re8ff31e |
r60db872 |
|
| 25 | 25 | |
|---|
| 26 | 26 | #include <string.h> |
|---|
| | 27 | #include <stdarg.h> |
|---|
| | 28 | #include <stdio.h> |
|---|
| | 29 | #include <assert.h> |
|---|
| 27 | 30 | #include <vlc_network.h> |
|---|
| 28 | 31 | #include <vlc_charset.h> |
|---|
| … | … | |
| 109 | 112 | if (!IsSDPString (name) || !IsSDPString (description) |
|---|
| 110 | 113 | || !IsSDPString (url) || !IsSDPString (email) || !IsSDPString (phone) |
|---|
| 111 | | || (AddressToSDP ((struct sockaddr *)orig, origlen, machine) == NULL) |
|---|
| 112 | | || (AddressToSDP ((struct sockaddr *)addr, addrlen, conn) == NULL)) |
|---|
| | 114 | || (AddressToSDP (orig, origlen, machine) == NULL) |
|---|
| | 115 | || (AddressToSDP (addr, addrlen, conn) == NULL)) |
|---|
| 113 | 116 | return NULL; |
|---|
| 114 | 117 | |
|---|
| … | … | |
| 150 | 153 | } |
|---|
| 151 | 154 | |
|---|
| | 155 | |
|---|
| | 156 | char *MakeSDPMedia (const char *type, int dport, const char *protocol, |
|---|
| | 157 | unsigned pt, const char *rtpmap, const char *fmtpfmt, ...) |
|---|
| | 158 | { |
|---|
| | 159 | char *sdp_media = NULL; |
|---|
| | 160 | |
|---|
| | 161 | /* Some default values */ |
|---|
| | 162 | if (type == NULL) |
|---|
| | 163 | type = "video"; |
|---|
| | 164 | if (dport == 0) |
|---|
| | 165 | dport = 9; |
|---|
| | 166 | if (protocol == NULL) |
|---|
| | 167 | protocol = "RTP/AVP"; |
|---|
| | 168 | assert (pt < 128u); |
|---|
| | 169 | |
|---|
| | 170 | /* RTP payload type map */ |
|---|
| | 171 | char sdp_rtpmap[rtpmap ? (sizeof ("a=rtpmap:123 *\r\n") + strlen (rtpmap)) : 1]; |
|---|
| | 172 | if (rtpmap != NULL) |
|---|
| | 173 | sprintf (sdp_rtpmap, "a=rtpmap:%u %s\r\n", pt, rtpmap); |
|---|
| | 174 | else |
|---|
| | 175 | *sdp_rtpmap = '\0'; |
|---|
| | 176 | |
|---|
| | 177 | /* Format parameters */ |
|---|
| | 178 | char *fmtp = NULL; |
|---|
| | 179 | if (fmtpfmt != NULL) |
|---|
| | 180 | { |
|---|
| | 181 | va_list ap; |
|---|
| | 182 | |
|---|
| | 183 | va_start (ap, fmtpfmt); |
|---|
| | 184 | if (vasprintf (&fmtp, fmtpfmt, ap) == -1) |
|---|
| | 185 | fmtpfmt = NULL; |
|---|
| | 186 | va_end (ap); |
|---|
| | 187 | |
|---|
| | 188 | if (fmtp == NULL) |
|---|
| | 189 | return NULL; |
|---|
| | 190 | } |
|---|
| | 191 | |
|---|
| | 192 | char sdp_fmtp[fmtp ? (sizeof ("a=fmtp:123 *\r\n") + strlen (fmtp)) : 1]; |
|---|
| | 193 | if (fmtp != NULL) |
|---|
| | 194 | { |
|---|
| | 195 | sprintf (sdp_fmtp, "a=fmtp:%u %s\r\n", pt, fmtp); |
|---|
| | 196 | free (fmtp); |
|---|
| | 197 | } |
|---|
| | 198 | else |
|---|
| | 199 | *sdp_fmtp = '\0'; |
|---|
| | 200 | |
|---|
| | 201 | if (asprintf (&sdp_media, "m=%s %u %s %d\r\n" "%s" "%s", |
|---|
| | 202 | type, dport, protocol, pt, |
|---|
| | 203 | sdp_rtpmap, sdp_fmtp) == -1) |
|---|
| | 204 | return NULL; |
|---|
| | 205 | |
|---|
| | 206 | return sdp_media; |
|---|
| | 207 | } |
|---|
| r7681a9b |
r60db872 |
|
| 117 | 117 | const struct sockaddr *orig, socklen_t origlen, |
|---|
| 118 | 118 | const struct sockaddr *addr, socklen_t addrlen); |
|---|
| | 119 | char *MakeSDPMedia (const char *type, int dport, const char *protocol, |
|---|
| | 120 | unsigned pt, const char *rtpmap, const char *fmtp, ...); |
|---|
| 119 | 121 | |
|---|