FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rtpproto.c
Go to the documentation of this file.
1 /*
2  * RTP network protocol
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
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
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * RTP protocol
25  */
26 
27 #include "libavutil/parseutils.h"
28 #include "libavutil/avstring.h"
29 #include "libavutil/opt.h"
30 #include "avformat.h"
31 #include "avio_internal.h"
32 #include "rtp.h"
33 #include "rtpproto.h"
34 #include "url.h"
35 
36 #include <stdarg.h>
37 #include "internal.h"
38 #include "network.h"
39 #include "os_support.h"
40 #include <fcntl.h>
41 #if HAVE_POLL_H
42 #include <sys/poll.h>
43 #endif
44 
45 typedef struct RTPContext {
46  const AVClass *class;
51  struct sockaddr_storage last_rtp_source, last_rtcp_source;
53  int ttl;
56  int connect;
57  int pkt_size;
58  int dscp;
59  char *sources;
60  char *block;
61 } RTPContext;
62 
63 #define OFFSET(x) offsetof(RTPContext, x)
64 #define D AV_OPT_FLAG_DECODING_PARAM
65 #define E AV_OPT_FLAG_ENCODING_PARAM
66 static const AVOption options[] = {
67  { "ttl", "Time to live (in milliseconds, multicast only)", OFFSET(ttl), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
68  { "buffer_size", "Send/Receive buffer size (in bytes)", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
69  { "rtcp_port", "Custom rtcp port", OFFSET(rtcp_port), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
70  { "local_rtpport", "Local rtp port", OFFSET(local_rtpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
71  { "local_rtcpport", "Local rtcp port", OFFSET(local_rtcpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
72  { "connect", "Connect socket", OFFSET(connect), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
73  { "write_to_source", "Send packets to the source address of the latest received packet", OFFSET(write_to_source), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
74  { "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
75  { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
76  { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
77  { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
78  { NULL }
79 };
80 
81 static const AVClass rtp_class = {
82  .class_name = "rtp",
83  .item_name = av_default_item_name,
84  .option = options,
85  .version = LIBAVUTIL_VERSION_INT,
86 };
87 
88 /**
89  * If no filename is given to av_open_input_file because you want to
90  * get the local port first, then you must call this function to set
91  * the remote server address.
92  *
93  * @param h media file context
94  * @param uri of the remote server
95  * @return zero if no error.
96  */
97 
98 int ff_rtp_set_remote_url(URLContext *h, const char *uri)
99 {
100  RTPContext *s = h->priv_data;
101  char hostname[256];
102  int port, rtcp_port;
103  const char *p;
104 
105  char buf[1024];
106  char path[1024];
107 
108  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
109  path, sizeof(path), uri);
110  rtcp_port = port + 1;
111 
112  p = strchr(uri, '?');
113  if (p) {
114  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
115  rtcp_port = strtol(buf, NULL, 10);
116  }
117  }
118 
119  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path);
120  ff_udp_set_remote_url(s->rtp_hd, buf);
121 
122  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, rtcp_port, "%s", path);
124  return 0;
125 }
126 
127 static struct addrinfo* rtp_resolve_host(const char *hostname, int port,
128  int type, int family, int flags)
129 {
130  struct addrinfo hints = { 0 }, *res = 0;
131  int error;
132  char service[16];
133 
134  snprintf(service, sizeof(service), "%d", port);
135  hints.ai_socktype = type;
136  hints.ai_family = family;
137  hints.ai_flags = flags;
138  if ((error = getaddrinfo(hostname, service, &hints, &res))) {
139  res = NULL;
140  av_log(NULL, AV_LOG_ERROR, "rtp_resolve_host: %s\n", gai_strerror(error));
141  }
142 
143  return res;
144 }
145 
146 static int compare_addr(const struct sockaddr_storage *a,
147  const struct sockaddr_storage *b)
148 {
149  if (a->ss_family != b->ss_family)
150  return 1;
151  if (a->ss_family == AF_INET) {
152  return (((const struct sockaddr_in *)a)->sin_addr.s_addr !=
153  ((const struct sockaddr_in *)b)->sin_addr.s_addr);
154  }
155 
156 #if HAVE_STRUCT_SOCKADDR_IN6
157  if (a->ss_family == AF_INET6) {
158  const uint8_t *s6_addr_a = ((const struct sockaddr_in6 *)a)->sin6_addr.s6_addr;
159  const uint8_t *s6_addr_b = ((const struct sockaddr_in6 *)b)->sin6_addr.s6_addr;
160  return memcmp(s6_addr_a, s6_addr_b, 16);
161  }
162 #endif
163  return 1;
164 }
165 
166 static int get_port(const struct sockaddr_storage *ss)
167 {
168  if (ss->ss_family == AF_INET)
169  return ntohs(((const struct sockaddr_in *)ss)->sin_port);
170 #if HAVE_STRUCT_SOCKADDR_IN6
171  if (ss->ss_family == AF_INET6)
172  return ntohs(((const struct sockaddr_in6 *)ss)->sin6_port);
173 #endif
174  return 0;
175 }
176 
177 static void set_port(struct sockaddr_storage *ss, int port)
178 {
179  if (ss->ss_family == AF_INET)
180  ((struct sockaddr_in *)ss)->sin_port = htons(port);
181 #if HAVE_STRUCT_SOCKADDR_IN6
182  else if (ss->ss_family == AF_INET6)
183  ((struct sockaddr_in6 *)ss)->sin6_port = htons(port);
184 #endif
185 }
186 
187 static int rtp_check_source_lists(RTPContext *s, struct sockaddr_storage *source_addr_ptr)
188 {
189  int i;
190  if (s->nb_ssm_exclude_addrs) {
191  for (i = 0; i < s->nb_ssm_exclude_addrs; i++) {
192  if (!compare_addr(source_addr_ptr, s->ssm_exclude_addrs[i]))
193  return 1;
194  }
195  }
196  if (s->nb_ssm_include_addrs) {
197  for (i = 0; i < s->nb_ssm_include_addrs; i++) {
198  if (!compare_addr(source_addr_ptr, s->ssm_include_addrs[i]))
199  return 0;
200  }
201  return 1;
202  }
203  return 0;
204 }
205 
206 /**
207  * add option to url of the form:
208  * "http://host:port/path?option1=val1&option2=val2...
209  */
210 
211 static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)
212 {
213  char buf1[1024];
214  va_list ap;
215 
216  va_start(ap, fmt);
217  if (strchr(buf, '?'))
218  av_strlcat(buf, "&", buf_size);
219  else
220  av_strlcat(buf, "?", buf_size);
221  vsnprintf(buf1, sizeof(buf1), fmt, ap);
222  av_strlcat(buf, buf1, buf_size);
223  va_end(ap);
224 }
225 
227  char *buf, int buf_size,
228  const char *hostname,
229  int port, int local_port,
230  const char *include_sources,
231  const char *exclude_sources)
232 {
233  ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
234  if (local_port >= 0)
235  url_add_option(buf, buf_size, "localport=%d", local_port);
236  if (s->ttl >= 0)
237  url_add_option(buf, buf_size, "ttl=%d", s->ttl);
238  if (s->buffer_size >= 0)
239  url_add_option(buf, buf_size, "buffer_size=%d", s->buffer_size);
240  if (s->pkt_size >= 0)
241  url_add_option(buf, buf_size, "pkt_size=%d", s->pkt_size);
242  if (s->connect)
243  url_add_option(buf, buf_size, "connect=1");
244  if (s->dscp >= 0)
245  url_add_option(buf, buf_size, "dscp=%d", s->dscp);
246  url_add_option(buf, buf_size, "fifo_size=0");
247  if (include_sources && include_sources[0])
248  url_add_option(buf, buf_size, "sources=%s", include_sources);
249  if (exclude_sources && exclude_sources[0])
250  url_add_option(buf, buf_size, "block=%s", exclude_sources);
251 }
252 
253 static void rtp_parse_addr_list(URLContext *h, char *buf,
254  struct sockaddr_storage ***address_list_ptr,
255  int *address_list_size_ptr)
256 {
257  struct addrinfo *ai = NULL;
258  struct sockaddr_storage *source_addr;
259  char tmp = '\0', *p = buf, *next;
260 
261  /* Resolve all of the IPs */
262 
263  while (p && p[0]) {
264  next = strchr(p, ',');
265 
266  if (next) {
267  tmp = *next;
268  *next = '\0';
269  }
270 
271  ai = rtp_resolve_host(p, 0, SOCK_DGRAM, AF_UNSPEC, 0);
272  if (ai) {
273  source_addr = av_mallocz(sizeof(struct sockaddr_storage));
274  if (!source_addr) {
275  freeaddrinfo(ai);
276  break;
277  }
278 
279  memcpy(source_addr, ai->ai_addr, ai->ai_addrlen);
280  freeaddrinfo(ai);
281  dynarray_add(address_list_ptr, address_list_size_ptr, source_addr);
282  } else {
283  av_log(h, AV_LOG_WARNING, "Unable to resolve %s\n", p);
284  }
285 
286  if (next) {
287  *next = tmp;
288  p = next + 1;
289  } else {
290  p = NULL;
291  }
292  }
293 }
294 
295 /**
296  * url syntax: rtp://host:port[?option=val...]
297  * option: 'ttl=n' : set the ttl value (for multicast only)
298  * 'rtcpport=n' : set the remote rtcp port to n
299  * 'localrtpport=n' : set the local rtp port to n
300  * 'localrtcpport=n' : set the local rtcp port to n
301  * 'pkt_size=n' : set max packet size
302  * 'connect=0/1' : do a connect() on the UDP socket
303  * 'sources=ip[,ip]' : list allowed source IP addresses
304  * 'block=ip[,ip]' : list disallowed source IP addresses
305  * 'write_to_source=0/1' : send packets to the source address of the latest received packet
306  * 'dscp=n' : set DSCP value to n (QoS)
307  * deprecated option:
308  * 'localport=n' : set the local port to n
309  *
310  * if rtcpport isn't set the rtcp port will be the rtp port + 1
311  * if local rtp port isn't set any available port will be used for the local
312  * rtp and rtcp ports
313  * if the local rtcp port is not set it will be the local rtp port + 1
314  */
315 
316 static int rtp_open(URLContext *h, const char *uri, int flags)
317 {
318  RTPContext *s = h->priv_data;
319  int rtp_port;
320  char hostname[256], include_sources[1024] = "", exclude_sources[1024] = "";
321  char *sources = include_sources, *block = exclude_sources;
322  char buf[1024];
323  char path[1024];
324  const char *p;
325  int i, max_retry_count = 3;
326  int rtcpflags;
327 
328  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
329  path, sizeof(path), uri);
330  /* extract parameters */
331  if (s->rtcp_port < 0)
332  s->rtcp_port = rtp_port + 1;
333 
334  p = strchr(uri, '?');
335  if (p) {
336  if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
337  s->ttl = strtol(buf, NULL, 10);
338  }
339  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
340  s->rtcp_port = strtol(buf, NULL, 10);
341  }
342  if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
343  s->local_rtpport = strtol(buf, NULL, 10);
344  }
345  if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
346  s->local_rtpport = strtol(buf, NULL, 10);
347  }
348  if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
349  s->local_rtcpport = strtol(buf, NULL, 10);
350  }
351  if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
352  s->pkt_size = strtol(buf, NULL, 10);
353  }
354  if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
355  s->connect = strtol(buf, NULL, 10);
356  }
357  if (av_find_info_tag(buf, sizeof(buf), "write_to_source", p)) {
358  s->write_to_source = strtol(buf, NULL, 10);
359  }
360  if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) {
361  s->dscp = strtol(buf, NULL, 10);
362  }
363  if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
364  av_strlcpy(include_sources, buf, sizeof(include_sources));
365 
367  } else {
369  sources = s->sources;
370  }
371  if (av_find_info_tag(buf, sizeof(buf), "block", p)) {
372  av_strlcpy(exclude_sources, buf, sizeof(exclude_sources));
374  } else {
376  block = s->block;
377  }
378  }
379 
380  for (i = 0; i < max_retry_count; i++) {
381  build_udp_url(s, buf, sizeof(buf),
382  hostname, rtp_port, s->local_rtpport,
383  sources, block);
384  if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback,
386  goto fail;
388  if(s->local_rtpport == 65535) {
389  s->local_rtpport = -1;
390  continue;
391  }
392  rtcpflags = flags | AVIO_FLAG_WRITE;
393  if (s->local_rtcpport < 0) {
394  s->local_rtcpport = s->local_rtpport + 1;
395  build_udp_url(s, buf, sizeof(buf),
396  hostname, s->rtcp_port, s->local_rtcpport,
397  sources, block);
398  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags,
400  h->protocol_whitelist, h->protocol_blacklist, h) < 0) {
401  s->local_rtpport = s->local_rtcpport = -1;
402  continue;
403  }
404  break;
405  }
406  build_udp_url(s, buf, sizeof(buf),
407  hostname, s->rtcp_port, s->local_rtcpport,
408  sources, block);
409  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback,
411  goto fail;
412  break;
413  }
414 
415  /* just to ease handle access. XXX: need to suppress direct handle
416  access */
419 
421  h->is_streamed = 1;
422  return 0;
423 
424  fail:
425  if (s->rtp_hd)
426  ffurl_close(s->rtp_hd);
427  if (s->rtcp_hd)
428  ffurl_close(s->rtcp_hd);
429  return AVERROR(EIO);
430 }
431 
432 static int rtp_read(URLContext *h, uint8_t *buf, int size)
433 {
434  RTPContext *s = h->priv_data;
435  int len, n, i;
436  struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
437  int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
438  struct sockaddr_storage *addrs[2] = { &s->last_rtp_source, &s->last_rtcp_source };
439  socklen_t *addr_lens[2] = { &s->last_rtp_source_len, &s->last_rtcp_source_len };
440 
441  for(;;) {
443  return AVERROR_EXIT;
444  n = poll(p, 2, poll_delay);
445  if (n > 0) {
446  /* first try RTCP, then RTP */
447  for (i = 1; i >= 0; i--) {
448  if (!(p[i].revents & POLLIN))
449  continue;
450  *addr_lens[i] = sizeof(*addrs[i]);
451  len = recvfrom(p[i].fd, buf, size, 0,
452  (struct sockaddr *)addrs[i], addr_lens[i]);
453  if (len < 0) {
454  if (ff_neterrno() == AVERROR(EAGAIN) ||
455  ff_neterrno() == AVERROR(EINTR))
456  continue;
457  return AVERROR(EIO);
458  }
459  if (rtp_check_source_lists(s, addrs[i]))
460  continue;
461  return len;
462  }
463  } else if (n < 0) {
464  if (ff_neterrno() == AVERROR(EINTR))
465  continue;
466  return AVERROR(EIO);
467  }
468  if (h->flags & AVIO_FLAG_NONBLOCK)
469  return AVERROR(EAGAIN);
470  }
471  return len;
472 }
473 
474 static int rtp_write(URLContext *h, const uint8_t *buf, int size)
475 {
476  RTPContext *s = h->priv_data;
477  int ret;
478  URLContext *hd;
479 
480  if (size < 2)
481  return AVERROR(EINVAL);
482 
483  if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
484  av_log(h, AV_LOG_WARNING, "Data doesn't look like RTP packets, "
485  "make sure the RTP muxer is used\n");
486 
487  if (s->write_to_source) {
488  int fd;
489  struct sockaddr_storage *source, temp_source;
490  socklen_t *source_len, temp_len;
491  if (!s->last_rtp_source.ss_family && !s->last_rtcp_source.ss_family) {
492  av_log(h, AV_LOG_ERROR,
493  "Unable to send packet to source, no packets received yet\n");
494  // Intentionally not returning an error here
495  return size;
496  }
497 
498  if (RTP_PT_IS_RTCP(buf[1])) {
499  fd = s->rtcp_fd;
500  source = &s->last_rtcp_source;
501  source_len = &s->last_rtcp_source_len;
502  } else {
503  fd = s->rtp_fd;
504  source = &s->last_rtp_source;
505  source_len = &s->last_rtp_source_len;
506  }
507  if (!source->ss_family) {
508  source = &temp_source;
509  source_len = &temp_len;
510  if (RTP_PT_IS_RTCP(buf[1])) {
511  temp_source = s->last_rtp_source;
512  temp_len = s->last_rtp_source_len;
513  set_port(source, get_port(source) + 1);
514  av_log(h, AV_LOG_INFO,
515  "Not received any RTCP packets yet, inferring peer port "
516  "from the RTP port\n");
517  } else {
518  temp_source = s->last_rtcp_source;
519  temp_len = s->last_rtcp_source_len;
520  set_port(source, get_port(source) - 1);
521  av_log(h, AV_LOG_INFO,
522  "Not received any RTP packets yet, inferring peer port "
523  "from the RTCP port\n");
524  }
525  }
526 
527  if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
528  ret = ff_network_wait_fd(fd, 1);
529  if (ret < 0)
530  return ret;
531  }
532  ret = sendto(fd, buf, size, 0, (struct sockaddr *) source,
533  *source_len);
534 
535  return ret < 0 ? ff_neterrno() : ret;
536  }
537 
538  if (RTP_PT_IS_RTCP(buf[1])) {
539  /* RTCP payload type */
540  hd = s->rtcp_hd;
541  } else {
542  /* RTP payload type */
543  hd = s->rtp_hd;
544  }
545 
546  ret = ffurl_write(hd, buf, size);
547  return ret;
548 }
549 
550 static int rtp_close(URLContext *h)
551 {
552  RTPContext *s = h->priv_data;
553  int i;
554 
555  for (i = 0; i < s->nb_ssm_include_addrs; i++)
556  av_freep(&s->ssm_include_addrs[i]);
558  for (i = 0; i < s->nb_ssm_exclude_addrs; i++)
559  av_freep(&s->ssm_exclude_addrs[i]);
561 
562  ffurl_close(s->rtp_hd);
563  ffurl_close(s->rtcp_hd);
564  return 0;
565 }
566 
567 /**
568  * Return the local rtp port used by the RTP connection
569  * @param h media file context
570  * @return the local port number
571  */
572 
574 {
575  RTPContext *s = h->priv_data;
576  return ff_udp_get_local_port(s->rtp_hd);
577 }
578 
579 /**
580  * Return the local rtcp port used by the RTP connection
581  * @param h media file context
582  * @return the local port number
583  */
584 
586 {
587  RTPContext *s = h->priv_data;
588  return ff_udp_get_local_port(s->rtcp_hd);
589 }
590 
592 {
593  RTPContext *s = h->priv_data;
594  return s->rtp_fd;
595 }
596 
597 static int rtp_get_multi_file_handle(URLContext *h, int **handles,
598  int *numhandles)
599 {
600  RTPContext *s = h->priv_data;
601  int *hs = *handles = av_malloc(sizeof(**handles) * 2);
602  if (!hs)
603  return AVERROR(ENOMEM);
604  hs[0] = s->rtp_fd;
605  hs[1] = s->rtcp_fd;
606  *numhandles = 2;
607  return 0;
608 }
609 
611  .name = "rtp",
612  .url_open = rtp_open,
613  .url_read = rtp_read,
614  .url_write = rtp_write,
615  .url_close = rtp_close,
616  .url_get_file_handle = rtp_get_file_handle,
617  .url_get_multi_file_handle = rtp_get_multi_file_handle,
618  .priv_data_size = sizeof(RTPContext),
620  .priv_data_class = &rtp_class,
621 };
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
Definition: utils.c:4387
#define NULL
Definition: coverity.c:32
int rtcp_port
Definition: rtpproto.c:55
int buffer_size
Definition: rtpproto.c:54
const char * s
Definition: avisynth_c.h:768
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
Definition: rtpproto.c:573
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
Definition: avio.c:309
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
AVOption.
Definition: opt.h:245
const char * fmt
Definition: avisynth_c.h:769
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:421
int is_streamed
true if streamed (no seek possible), default = false
Definition: url.h:45
AVIOInterruptCB interrupt_callback
Definition: url.h:47
#define RTP_VERSION
Definition: rtp.h:78
#define vsnprintf
Definition: snprintf.h:36
static int rtp_check_source_lists(RTPContext *s, struct sockaddr_storage *source_addr_ptr)
Definition: rtpproto.c:187
const char * b
Definition: vf_curves.c:113
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:607
static void rtp_parse_addr_list(URLContext *h, char *buf, struct sockaddr_storage ***address_list_ptr, int *address_list_size_ptr)
Definition: rtpproto.c:253
char * block
Definition: rtpproto.c:60
int flags
Definition: url.h:43
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:252
#define freeaddrinfo
Definition: network.h:208
const URLProtocol ff_rtp_protocol
Definition: rtpproto.c:610
URLContext * rtcp_hd
Definition: rtpproto.c:47
static int compare_addr(const struct sockaddr_storage *a, const struct sockaddr_storage *b)
Definition: rtpproto.c:146
static int16_t block[64]
Definition: dct.c:113
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
Definition: rtpproto.c:474
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
static int rtp_close(URLContext *h)
Definition: rtpproto.c:550
uint8_t
#define av_malloc(s)
AVOptions.
#define D
Definition: rtpproto.c:64
miscellaneous OS support macros and functions.
socklen_t last_rtp_source_len
Definition: rtpproto.c:52
static int get_port(const struct sockaddr_storage *ss)
Definition: rtpproto.c:166
int ff_udp_get_local_port(URLContext *h)
Return the local port used by the UDP connection.
Definition: udp.c:477
uint16_t ss_family
Definition: network.h:106
int pkt_size
Definition: rtpproto.c:57
struct sockaddr_storage ** ssm_include_addrs
Definition: rtpproto.c:49
int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
Definition: parseutils.c:705
ptrdiff_t size
Definition: opengl_enc.c:101
#define av_log(a,...)
URLContext * rtp_hd
Definition: rtpproto.c:47
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_udp_set_remote_url(URLContext *h, const char *uri)
If no filename is given to av_open_input_file because you want to get the local port first...
Definition: udp.c:438
const char * protocol_whitelist
Definition: url.h:49
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
static int rtp_read(URLContext *h, uint8_t *buf, int size)
Definition: rtpproto.c:432
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
#define fail()
Definition: checkasm.h:82
int ai_addrlen
Definition: network.h:132
#define dynarray_add(tab, nb_ptr, elem)
Definition: internal.h:168
static const AVClass rtp_class
Definition: rtpproto.c:81
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
struct sockaddr_storage last_rtp_source last_rtcp_source
Definition: rtpproto.c:51
#define ff_neterrno()
Definition: network.h:64
static int rtp_open(URLContext *h, const char *uri, int flags)
url syntax: rtp://host:port[?option=val...] option: 'ttl=n' : set the ttl value (for multicast only) ...
Definition: rtpproto.c:316
static const AVOption options[]
Definition: rtpproto.c:66
int n
Definition: avisynth_c.h:684
int rtcp_fd
Definition: rtpproto.c:48
static int rtp_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Definition: rtpproto.c:597
int rtp_fd
Definition: rtpproto.c:48
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:626
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
int local_rtcpport
Definition: rtpproto.c:55
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
Definition: url.c:36
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
const char * protocol_blacklist
Definition: url.h:50
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:655
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:625
#define ss
socklen_t last_rtcp_source_len
Definition: rtpproto.c:52
void * buf
Definition: avisynth_c.h:690
Definition: url.h:38
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
static av_printf_format(3, 4)
add option to url of the form: "http://host:port/path?option1=val1&option2=val2...
Definition: rtpproto.c:211
void * priv_data
Definition: url.h:41
#define gai_strerror
Definition: network.h:215
#define snprintf
Definition: snprintf.h:34
misc parsing utilities
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:93
const char * name
Definition: url.h:54
int ai_socktype
Definition: network.h:130
#define RTP_PT_IS_RTCP(x)
Definition: rtp.h:110
static void set_port(struct sockaddr_storage *ss, int port)
Definition: rtpproto.c:177
int dscp
Definition: rtpproto.c:58
static int flags
Definition: cpu.c:47
int ffurl_close(URLContext *h)
Definition: avio.c:467
char * sources
Definition: rtpproto.c:59
static struct addrinfo * rtp_resolve_host(const char *hostname, int port, int type, int family, int flags)
Definition: rtpproto.c:127
int nb_ssm_include_addrs
Definition: rtpproto.c:48
#define getaddrinfo
Definition: network.h:207
Main libavformat public API header.
struct sockaddr_storage ** ssm_exclude_addrs
Definition: rtpproto.c:49
static int rtp_get_file_handle(URLContext *h)
Definition: rtpproto.c:591
static void build_udp_url(RTPContext *s, char *buf, int buf_size, const char *hostname, int port, int local_port, const char *include_sources, const char *exclude_sources)
Definition: rtpproto.c:226
int ff_rtp_get_local_rtcp_port(URLContext *h)
Return the local rtcp port used by the RTP connection.
Definition: rtpproto.c:585
int write_to_source
Definition: rtpproto.c:50
int len
int nb_ssm_exclude_addrs
Definition: rtpproto.c:48
int local_rtpport
Definition: rtpproto.c:55
static uint8_t tmp[8]
Definition: des.c:38
int ttl
Definition: rtpproto.c:53
#define OFFSET(x)
Definition: rtpproto.c:63
int ai_flags
Definition: network.h:128
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
#define av_freep(p)
int ff_network_wait_fd(int fd, int write)
Definition: network.c:73
unbuffered private I/O API
struct sockaddr * ai_addr
Definition: network.h:133
int ff_rtp_set_remote_url(URLContext *h, const char *uri)
If no filename is given to av_open_input_file because you want to get the local port first...
Definition: rtpproto.c:98
int connect
Definition: rtpproto.c:56
#define E
Definition: rtpproto.c:65
int ai_family
Definition: network.h:129