OLD | NEW |
1 /* | 1 /* |
2 * RTP network protocol | 2 * RTP network protocol |
3 * Copyright (c) 2002 Fabrice Bellard | 3 * Copyright (c) 2002 Fabrice Bellard |
4 * | 4 * |
5 * This file is part of FFmpeg. | 5 * This file is part of FFmpeg. |
6 * | 6 * |
7 * FFmpeg is free software; you can redistribute it and/or | 7 * FFmpeg is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2.1 of the License, or (at your option) any later version. | 10 * version 2.1 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * FFmpeg is distributed in the hope that it will be useful, | 12 * FFmpeg is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | 15 * Lesser General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Lesser General Public | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with FFmpeg; if not, write to the Free Software | 18 * License along with FFmpeg; if not, write to the Free Software |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 */ | 20 */ |
21 | 21 |
22 /** | 22 /** |
23 * @file libavformat/rtpproto.c | 23 * @file libavformat/rtpproto.c |
24 * RTP protocol | 24 * RTP protocol |
25 */ | 25 */ |
26 | 26 |
27 #include "libavutil/avstring.h" | 27 #include "libavutil/avstring.h" |
28 #include "avformat.h" | 28 #include "avformat.h" |
| 29 #include "rtpdec.h" |
29 | 30 |
30 #include <unistd.h> | 31 #include <unistd.h> |
31 #include <stdarg.h> | 32 #include <stdarg.h> |
32 #include "network.h" | 33 #include "network.h" |
33 #include "os_support.h" | 34 #include "os_support.h" |
34 #include <fcntl.h> | 35 #include <fcntl.h> |
35 #if HAVE_SYS_SELECT_H | 36 #if HAVE_SYS_SELECT_H |
36 #include <sys/select.h> | 37 #include <sys/select.h> |
37 #endif | 38 #endif |
38 | 39 |
(...skipping 17 matching lines...) Expand all Loading... |
56 | 57 |
57 int rtp_set_remote_url(URLContext *h, const char *uri) | 58 int rtp_set_remote_url(URLContext *h, const char *uri) |
58 { | 59 { |
59 RTPContext *s = h->priv_data; | 60 RTPContext *s = h->priv_data; |
60 char hostname[256]; | 61 char hostname[256]; |
61 int port; | 62 int port; |
62 | 63 |
63 char buf[1024]; | 64 char buf[1024]; |
64 char path[1024]; | 65 char path[1024]; |
65 | 66 |
66 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, | 67 ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, |
67 path, sizeof(path), uri); | 68 path, sizeof(path), uri); |
68 | 69 |
69 snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port, path); | 70 ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path); |
70 udp_set_remote_url(s->rtp_hd, buf); | 71 udp_set_remote_url(s->rtp_hd, buf); |
71 | 72 |
72 snprintf(buf, sizeof(buf), "udp://%s:%d%s", hostname, port + 1, path); | 73 ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path); |
73 udp_set_remote_url(s->rtcp_hd, buf); | 74 udp_set_remote_url(s->rtcp_hd, buf); |
74 return 0; | 75 return 0; |
75 } | 76 } |
76 | 77 |
77 | 78 |
78 /** | 79 /** |
79 * add option to url of the form: | 80 * add option to url of the form: |
80 * "http://host:port/path?option1=val1&option2=val2... | 81 * "http://host:port/path?option1=val1&option2=val2... |
81 */ | 82 */ |
82 | 83 |
(...skipping 10 matching lines...) Expand all Loading... |
93 vsnprintf(buf1, sizeof(buf1), fmt, ap); | 94 vsnprintf(buf1, sizeof(buf1), fmt, ap); |
94 av_strlcat(buf, buf1, buf_size); | 95 av_strlcat(buf, buf1, buf_size); |
95 va_end(ap); | 96 va_end(ap); |
96 } | 97 } |
97 | 98 |
98 static void build_udp_url(char *buf, int buf_size, | 99 static void build_udp_url(char *buf, int buf_size, |
99 const char *hostname, int port, | 100 const char *hostname, int port, |
100 int local_port, int ttl, | 101 int local_port, int ttl, |
101 int max_packet_size) | 102 int max_packet_size) |
102 { | 103 { |
103 snprintf(buf, buf_size, "udp://%s:%d", hostname, port); | 104 ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL); |
104 if (local_port >= 0) | 105 if (local_port >= 0) |
105 url_add_option(buf, buf_size, "localport=%d", local_port); | 106 url_add_option(buf, buf_size, "localport=%d", local_port); |
106 if (ttl >= 0) | 107 if (ttl >= 0) |
107 url_add_option(buf, buf_size, "ttl=%d", ttl); | 108 url_add_option(buf, buf_size, "ttl=%d", ttl); |
108 if (max_packet_size >=0) | 109 if (max_packet_size >=0) |
109 url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); | 110 url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); |
110 } | 111 } |
111 | 112 |
112 /** | 113 /** |
113 * url syntax: rtp://host:port[?option=val...] | 114 * url syntax: rtp://host:port[?option=val...] |
(...skipping 12 matching lines...) Expand all Loading... |
126 char path[1024]; | 127 char path[1024]; |
127 const char *p; | 128 const char *p; |
128 | 129 |
129 is_output = (flags & URL_WRONLY); | 130 is_output = (flags & URL_WRONLY); |
130 | 131 |
131 s = av_mallocz(sizeof(RTPContext)); | 132 s = av_mallocz(sizeof(RTPContext)); |
132 if (!s) | 133 if (!s) |
133 return AVERROR(ENOMEM); | 134 return AVERROR(ENOMEM); |
134 h->priv_data = s; | 135 h->priv_data = s; |
135 | 136 |
136 url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, | 137 ff_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port, |
137 path, sizeof(path), uri); | 138 path, sizeof(path), uri); |
138 /* extract parameters */ | 139 /* extract parameters */ |
139 ttl = -1; | 140 ttl = -1; |
140 local_port = -1; | 141 local_port = -1; |
141 max_packet_size = -1; | 142 max_packet_size = -1; |
142 | 143 |
143 p = strchr(uri, '?'); | 144 p = strchr(uri, '?'); |
144 if (p) { | 145 if (p) { |
145 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { | 146 if (find_info_tag(buf, sizeof(buf), "ttl", p)) { |
146 ttl = strtol(buf, NULL, 10); | 147 ttl = strtol(buf, NULL, 10); |
147 } | 148 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return AVERROR(EIO); | 186 return AVERROR(EIO); |
186 } | 187 } |
187 | 188 |
188 static int rtp_read(URLContext *h, uint8_t *buf, int size) | 189 static int rtp_read(URLContext *h, uint8_t *buf, int size) |
189 { | 190 { |
190 RTPContext *s = h->priv_data; | 191 RTPContext *s = h->priv_data; |
191 struct sockaddr_in from; | 192 struct sockaddr_in from; |
192 socklen_t from_len; | 193 socklen_t from_len; |
193 int len, fd_max, n; | 194 int len, fd_max, n; |
194 fd_set rfds; | 195 fd_set rfds; |
| 196 struct timeval tv; |
195 #if 0 | 197 #if 0 |
196 for(;;) { | 198 for(;;) { |
197 from_len = sizeof(from); | 199 from_len = sizeof(from); |
198 len = recvfrom (s->rtp_fd, buf, size, 0, | 200 len = recvfrom (s->rtp_fd, buf, size, 0, |
199 (struct sockaddr *)&from, &from_len); | 201 (struct sockaddr *)&from, &from_len); |
200 if (len < 0) { | 202 if (len < 0) { |
201 if (ff_neterrno() == FF_NETERROR(EAGAIN) || | 203 if (ff_neterrno() == FF_NETERROR(EAGAIN) || |
202 ff_neterrno() == FF_NETERROR(EINTR)) | 204 ff_neterrno() == FF_NETERROR(EINTR)) |
203 continue; | 205 continue; |
204 return AVERROR(EIO); | 206 return AVERROR(EIO); |
205 } | 207 } |
206 break; | 208 break; |
207 } | 209 } |
208 #else | 210 #else |
209 for(;;) { | 211 for(;;) { |
| 212 if (url_interrupt_cb()) |
| 213 return AVERROR(EINTR); |
210 /* build fdset to listen to RTP and RTCP packets */ | 214 /* build fdset to listen to RTP and RTCP packets */ |
211 FD_ZERO(&rfds); | 215 FD_ZERO(&rfds); |
212 fd_max = s->rtp_fd; | 216 fd_max = s->rtp_fd; |
213 FD_SET(s->rtp_fd, &rfds); | 217 FD_SET(s->rtp_fd, &rfds); |
214 if (s->rtcp_fd > fd_max) | 218 if (s->rtcp_fd > fd_max) |
215 fd_max = s->rtcp_fd; | 219 fd_max = s->rtcp_fd; |
216 FD_SET(s->rtcp_fd, &rfds); | 220 FD_SET(s->rtcp_fd, &rfds); |
217 n = select(fd_max + 1, &rfds, NULL, NULL, NULL); | 221 tv.tv_sec = 0; |
| 222 tv.tv_usec = 100 * 1000; |
| 223 n = select(fd_max + 1, &rfds, NULL, NULL, &tv); |
218 if (n > 0) { | 224 if (n > 0) { |
219 /* first try RTCP */ | 225 /* first try RTCP */ |
220 if (FD_ISSET(s->rtcp_fd, &rfds)) { | 226 if (FD_ISSET(s->rtcp_fd, &rfds)) { |
221 from_len = sizeof(from); | 227 from_len = sizeof(from); |
222 len = recvfrom (s->rtcp_fd, buf, size, 0, | 228 len = recvfrom (s->rtcp_fd, buf, size, 0, |
223 (struct sockaddr *)&from, &from_len); | 229 (struct sockaddr *)&from, &from_len); |
224 if (len < 0) { | 230 if (len < 0) { |
225 if (ff_neterrno() == FF_NETERROR(EAGAIN) || | 231 if (ff_neterrno() == FF_NETERROR(EAGAIN) || |
226 ff_neterrno() == FF_NETERROR(EINTR)) | 232 ff_neterrno() == FF_NETERROR(EINTR)) |
227 continue; | 233 continue; |
228 return AVERROR(EIO); | 234 return AVERROR(EIO); |
229 } | 235 } |
230 break; | 236 break; |
231 } | 237 } |
232 /* then RTP */ | 238 /* then RTP */ |
233 if (FD_ISSET(s->rtp_fd, &rfds)) { | 239 if (FD_ISSET(s->rtp_fd, &rfds)) { |
234 from_len = sizeof(from); | 240 from_len = sizeof(from); |
235 len = recvfrom (s->rtp_fd, buf, size, 0, | 241 len = recvfrom (s->rtp_fd, buf, size, 0, |
236 (struct sockaddr *)&from, &from_len); | 242 (struct sockaddr *)&from, &from_len); |
237 if (len < 0) { | 243 if (len < 0) { |
238 if (ff_neterrno() == FF_NETERROR(EAGAIN) || | 244 if (ff_neterrno() == FF_NETERROR(EAGAIN) || |
239 ff_neterrno() == FF_NETERROR(EINTR)) | 245 ff_neterrno() == FF_NETERROR(EINTR)) |
240 continue; | 246 continue; |
241 return AVERROR(EIO); | 247 return AVERROR(EIO); |
242 } | 248 } |
243 break; | 249 break; |
244 } | 250 } |
| 251 } else if (n < 0) { |
| 252 return AVERROR(EIO); |
245 } | 253 } |
246 } | 254 } |
247 #endif | 255 #endif |
248 return len; | 256 return len; |
249 } | 257 } |
250 | 258 |
251 static int rtp_write(URLContext *h, uint8_t *buf, int size) | 259 static int rtp_write(URLContext *h, uint8_t *buf, int size) |
252 { | 260 { |
253 RTPContext *s = h->priv_data; | 261 RTPContext *s = h->priv_data; |
254 int ret; | 262 int ret; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 328 |
321 URLProtocol rtp_protocol = { | 329 URLProtocol rtp_protocol = { |
322 "rtp", | 330 "rtp", |
323 rtp_open, | 331 rtp_open, |
324 rtp_read, | 332 rtp_read, |
325 rtp_write, | 333 rtp_write, |
326 NULL, /* seek */ | 334 NULL, /* seek */ |
327 rtp_close, | 335 rtp_close, |
328 .url_get_file_handle = rtp_get_file_handle, | 336 .url_get_file_handle = rtp_get_file_handle, |
329 }; | 337 }; |
OLD | NEW |