FFmpeg
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/mem.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/avstring.h"
30 #include "libavutil/opt.h"
31 #include "avformat.h"
32 #include "rtp.h"
33 #include "rtpproto.h"
34 #include "url.h"
35 #include "ip.h"
36 
37 #include <stdarg.h>
38 #include "network.h"
39 #include "os_support.h"
40 #include <fcntl.h>
41 #if HAVE_POLL_H
42 #include <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;
63  char *localaddr;
64 } RTPContext;
65 
66 #define OFFSET(x) offsetof(RTPContext, x)
67 #define D AV_OPT_FLAG_DECODING_PARAM
68 #define E AV_OPT_FLAG_ENCODING_PARAM
69 static const AVOption options[] = {
70  { "ttl", "Time to live (multicast only)", OFFSET(ttl), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, .flags = D|E },
71  { "buffer_size", "Send/Receive buffer size (in bytes)", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
72  { "rtcp_port", "Custom rtcp port", OFFSET(rtcp_port), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
73  { "local_rtpport", "Local rtp port", OFFSET(local_rtpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
74  { "local_rtcpport", "Local rtcp port", OFFSET(local_rtcpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
75  { "connect", "Connect socket", OFFSET(connect), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
76  { "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 },
77  { "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
78  { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
79  { "timeout", "set timeout (in microseconds) of socket I/O operations", OFFSET(rw_timeout), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, .flags = D|E },
80  { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
81  { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
82  { "fec", "FEC", OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = E },
83  { "localaddr", "Local address", OFFSET(localaddr), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
84  { NULL }
85 };
86 
87 static const AVClass rtp_class = {
88  .class_name = "rtp",
89  .item_name = av_default_item_name,
90  .option = options,
91  .version = LIBAVUTIL_VERSION_INT,
92 };
93 
94 /**
95  * If no filename is given to av_open_input_file because you want to
96  * get the local port first, then you must call this function to set
97  * the remote server address.
98  *
99  * @param h media file context
100  * @param uri of the remote server
101  * @return zero if no error.
102  */
103 
104 int ff_rtp_set_remote_url(URLContext *h, const char *uri)
105 {
106  RTPContext *s = h->priv_data;
107  char hostname[256];
108  int port, rtcp_port;
109  const char *p;
110 
111  char buf[1024];
112  char path[1024];
113 
114  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
115  path, sizeof(path), uri);
116  rtcp_port = port + 1;
117 
118  p = strchr(uri, '?');
119  if (p) {
120  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
121  rtcp_port = strtol(buf, NULL, 10);
122  }
123  }
124 
125  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path);
126  ff_udp_set_remote_url(s->rtp_hd, buf);
127 
128  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, rtcp_port, "%s", path);
129  ff_udp_set_remote_url(s->rtcp_hd, buf);
130  return 0;
131 }
132 
133 static int get_port(const struct sockaddr_storage *ss)
134 {
135  if (ss->ss_family == AF_INET)
136  return ntohs(((const struct sockaddr_in *)ss)->sin_port);
137 #if HAVE_STRUCT_SOCKADDR_IN6
138  if (ss->ss_family == AF_INET6)
139  return ntohs(((const struct sockaddr_in6 *)ss)->sin6_port);
140 #endif
141  return 0;
142 }
143 
144 static void set_port(struct sockaddr_storage *ss, int port)
145 {
146  if (ss->ss_family == AF_INET)
147  ((struct sockaddr_in *)ss)->sin_port = htons(port);
148 #if HAVE_STRUCT_SOCKADDR_IN6
149  else if (ss->ss_family == AF_INET6)
150  ((struct sockaddr_in6 *)ss)->sin6_port = htons(port);
151 #endif
152 }
153 
154 /**
155  * add option to url of the form:
156  * "http://host:port/path?option1=val1&option2=val2...
157  */
158 
159 static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)
160 {
161  char buf1[1024];
162  va_list ap;
163 
164  va_start(ap, fmt);
165  if (strchr(buf, '?'))
166  av_strlcat(buf, "&", buf_size);
167  else
168  av_strlcat(buf, "?", buf_size);
169  vsnprintf(buf1, sizeof(buf1), fmt, ap);
170  av_strlcat(buf, buf1, buf_size);
171  va_end(ap);
172 }
173 
175  char *buf, int buf_size,
176  const char *hostname,
177  const char *localaddr,
178  int port, int local_port,
179  const char *include_sources,
180  const char *exclude_sources)
181 {
182  ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
183  if (local_port >= 0)
184  url_add_option(buf, buf_size, "localport=%d", local_port);
185  if (s->ttl >= 0)
186  url_add_option(buf, buf_size, "ttl=%d", s->ttl);
187  if (s->buffer_size >= 0)
188  url_add_option(buf, buf_size, "buffer_size=%d", s->buffer_size);
189  if (s->pkt_size >= 0)
190  url_add_option(buf, buf_size, "pkt_size=%d", s->pkt_size);
191  if (s->connect)
192  url_add_option(buf, buf_size, "connect=1");
193  if (s->dscp >= 0)
194  url_add_option(buf, buf_size, "dscp=%d", s->dscp);
195  url_add_option(buf, buf_size, "fifo_size=0");
196  if (include_sources && include_sources[0])
197  url_add_option(buf, buf_size, "sources=%s", include_sources);
198  if (exclude_sources && exclude_sources[0])
199  url_add_option(buf, buf_size, "block=%s", exclude_sources);
200  if (localaddr && localaddr[0])
201  url_add_option(buf, buf_size, "localaddr=%s", localaddr);
202 }
203 
204 /**
205  * url syntax: rtp://host:port[?option=val...]
206  * option: 'ttl=n' : set the ttl value (for multicast only)
207  * 'rtcpport=n' : set the remote rtcp port to n
208  * 'localrtpport=n' : set the local rtp port to n
209  * 'localrtcpport=n' : set the local rtcp port to n
210  * 'pkt_size=n' : set max packet size
211  * 'connect=0/1' : do a connect() on the UDP socket
212  * 'sources=ip[,ip]' : list allowed source IP addresses
213  * 'block=ip[,ip]' : list disallowed source IP addresses
214  * 'write_to_source=0/1' : send packets to the source address of the latest received packet
215  * 'dscp=n' : set DSCP value to n (QoS)
216  * deprecated option:
217  * 'localport=n' : set the local port to n
218  *
219  * if rtcpport isn't set the rtcp port will be the rtp port + 1
220  * if local rtp port isn't set any available port will be used for the local
221  * rtp and rtcp ports
222  * if the local rtcp port is not set it will be the local rtp port + 1
223  */
224 
225 static int rtp_open(URLContext *h, const char *uri, int flags)
226 {
227  RTPContext *s = h->priv_data;
228  AVDictionary *fec_opts = NULL;
229  int rtp_port;
230  char hostname[256], include_sources[1024] = "", exclude_sources[1024] = "";
231  char *sources = include_sources, *block = exclude_sources;
232  char *fec_protocol = NULL;
233  char buf[1024];
234  char path[1024];
235  const char *p;
236  int i, max_retry_count = 3;
237  int rtcpflags;
238 
239  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
240  path, sizeof(path), uri);
241  /* extract parameters */
242  if (s->rtcp_port < 0)
243  s->rtcp_port = rtp_port + 1;
244 
245  p = strchr(uri, '?');
246  if (p) {
247  if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
248  s->ttl = strtol(buf, NULL, 10);
249  }
250  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
251  s->rtcp_port = strtol(buf, NULL, 10);
252  }
253  if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
254  s->local_rtpport = strtol(buf, NULL, 10);
255  }
256  if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
257  s->local_rtpport = strtol(buf, NULL, 10);
258  }
259  if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
260  s->local_rtcpport = strtol(buf, NULL, 10);
261  }
262  if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
263  s->pkt_size = strtol(buf, NULL, 10);
264  }
265  if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
266  s->connect = strtol(buf, NULL, 10);
267  }
268  if (av_find_info_tag(buf, sizeof(buf), "write_to_source", p)) {
269  s->write_to_source = strtol(buf, NULL, 10);
270  }
271  if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) {
272  s->dscp = strtol(buf, NULL, 10);
273  }
274  if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
275  s->rw_timeout = strtol(buf, NULL, 10);
276  }
277  if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
278  av_strlcpy(include_sources, buf, sizeof(include_sources));
279  ff_ip_parse_sources(h, buf, &s->filters);
280  } else {
281  ff_ip_parse_sources(h, s->sources, &s->filters);
282  sources = s->sources;
283  }
284  if (av_find_info_tag(buf, sizeof(buf), "block", p)) {
285  av_strlcpy(exclude_sources, buf, sizeof(exclude_sources));
286  ff_ip_parse_blocks(h, buf, &s->filters);
287  } else {
288  ff_ip_parse_blocks(h, s->block, &s->filters);
289  block = s->block;
290  }
291  if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) {
292  av_freep(&s->localaddr);
293  s->localaddr = av_strdup(buf);
294  if (!s->localaddr)
295  goto fail;
296  }
297  }
298  if (s->rw_timeout >= 0)
299  h->rw_timeout = s->rw_timeout;
300 
301  if (s->fec_options_str) {
302  p = s->fec_options_str;
303 
304  if (!(fec_protocol = av_get_token(&p, "="))) {
305  av_log(h, AV_LOG_ERROR, "Failed to parse the FEC protocol value\n");
306  goto fail;
307  }
308  if (strcmp(fec_protocol, "prompeg")) {
309  av_log(h, AV_LOG_ERROR, "Unsupported FEC protocol %s\n", fec_protocol);
310  goto fail;
311  }
312 
313  p = s->fec_options_str + strlen(fec_protocol);
314  while (*p && *p == '=') p++;
315 
316  if (av_dict_parse_string(&fec_opts, p, "=", ":", 0) < 0) {
317  av_log(h, AV_LOG_ERROR, "Failed to parse the FEC options\n");
318  goto fail;
319  }
320  if (s->ttl > 0) {
321  av_dict_set_int(&fec_opts, "ttl", s->ttl, 0);
322  }
323  }
324 
325  for (i = 0; i < max_retry_count; i++) {
326  build_udp_url(s, buf, sizeof(buf),
327  hostname, s->localaddr, rtp_port, s->local_rtpport,
328  sources, block);
329  if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback,
330  NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
331  goto fail;
332  s->local_rtpport = ff_udp_get_local_port(s->rtp_hd);
333  if(s->local_rtpport == 65535) {
334  s->local_rtpport = -1;
335  continue;
336  }
337  rtcpflags = flags | AVIO_FLAG_WRITE;
338  if (s->local_rtcpport < 0) {
339  s->local_rtcpport = s->local_rtpport + 1;
340  build_udp_url(s, buf, sizeof(buf),
341  hostname, s->localaddr, s->rtcp_port, s->local_rtcpport,
342  sources, block);
343  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags,
344  &h->interrupt_callback, NULL,
345  h->protocol_whitelist, h->protocol_blacklist, h) < 0) {
346  s->local_rtpport = s->local_rtcpport = -1;
347  continue;
348  }
349  break;
350  }
351  build_udp_url(s, buf, sizeof(buf),
352  hostname, s->localaddr, s->rtcp_port, s->local_rtcpport,
353  sources, block);
354  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback,
355  NULL, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
356  goto fail;
357  break;
358  }
359 
360  s->fec_hd = NULL;
361  if (fec_protocol) {
362  ff_url_join(buf, sizeof(buf), fec_protocol, NULL, hostname, rtp_port, NULL);
363  if (ffurl_open_whitelist(&s->fec_hd, buf, flags, &h->interrupt_callback,
364  &fec_opts, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
365  goto fail;
366  }
367 
368  /* just to ease handle access. XXX: need to suppress direct handle
369  access */
370  s->rtp_fd = ffurl_get_file_handle(s->rtp_hd);
371  s->rtcp_fd = ffurl_get_file_handle(s->rtcp_hd);
372 
373  h->max_packet_size = s->rtp_hd->max_packet_size;
374  h->is_streamed = 1;
375 
376  av_free(fec_protocol);
377  av_dict_free(&fec_opts);
378 
379  return 0;
380 
381  fail:
382  ff_ip_reset_filters(&s->filters);
383  ffurl_closep(&s->rtp_hd);
384  ffurl_closep(&s->rtcp_hd);
385  ffurl_closep(&s->fec_hd);
386  av_free(fec_protocol);
387  av_dict_free(&fec_opts);
388  return AVERROR(EIO);
389 }
390 
391 static int rtp_read(URLContext *h, uint8_t *buf, int size)
392 {
393  RTPContext *s = h->priv_data;
394  int len, n, i;
395  struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
396  int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : POLLING_TIME;
397  struct sockaddr_storage *addrs[2] = { &s->last_rtp_source, &s->last_rtcp_source };
398  socklen_t *addr_lens[2] = { &s->last_rtp_source_len, &s->last_rtcp_source_len };
399  int runs = h->rw_timeout / 1000 / POLLING_TIME;
400 
401  for(;;) {
402  if (ff_check_interrupt(&h->interrupt_callback))
403  return AVERROR_EXIT;
404  n = poll(p, 2, poll_delay);
405  if (n > 0) {
406  /* first try RTCP, then RTP */
407  for (i = 1; i >= 0; i--) {
408  if (!(p[i].revents & POLLIN))
409  continue;
410  *addr_lens[i] = sizeof(*addrs[i]);
411  len = recvfrom(p[i].fd, buf, size, 0,
412  (struct sockaddr *)addrs[i], addr_lens[i]);
413  if (len < 0) {
414  if (ff_neterrno() == AVERROR(EAGAIN) ||
415  ff_neterrno() == AVERROR(EINTR))
416  continue;
417  return AVERROR(EIO);
418  }
419  if (ff_ip_check_source_lists(addrs[i], &s->filters))
420  continue;
421  return len;
422  }
423  } else if (n == 0 && h->rw_timeout > 0 && --runs <= 0) {
424  return AVERROR(ETIMEDOUT);
425  } else if (n < 0) {
426  if (ff_neterrno() == AVERROR(EINTR))
427  continue;
428  return AVERROR(EIO);
429  }
430  if (h->flags & AVIO_FLAG_NONBLOCK)
431  return AVERROR(EAGAIN);
432  }
433 }
434 
435 static int rtp_write(URLContext *h, const uint8_t *buf, int size)
436 {
437  RTPContext *s = h->priv_data;
438  int ret, ret_fec;
439  URLContext *hd;
440 
441  if (size < 2)
442  return AVERROR(EINVAL);
443 
444  if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
445  av_log(h, AV_LOG_WARNING, "Data doesn't look like RTP packets, "
446  "make sure the RTP muxer is used\n");
447 
448  if (s->write_to_source) {
449  int fd;
450  struct sockaddr_storage *source, temp_source;
451  socklen_t *source_len, temp_len;
452  if (!s->last_rtp_source.ss_family && !s->last_rtcp_source.ss_family) {
454  "Unable to send packet to source, no packets received yet\n");
455  // Intentionally not returning an error here
456  return size;
457  }
458 
459  if (RTP_PT_IS_RTCP(buf[1])) {
460  fd = s->rtcp_fd;
461  source = &s->last_rtcp_source;
462  source_len = &s->last_rtcp_source_len;
463  } else {
464  fd = s->rtp_fd;
465  source = &s->last_rtp_source;
466  source_len = &s->last_rtp_source_len;
467  }
468  if (!source->ss_family) {
469  source = &temp_source;
470  source_len = &temp_len;
471  if (RTP_PT_IS_RTCP(buf[1])) {
472  temp_source = s->last_rtp_source;
473  temp_len = s->last_rtp_source_len;
476  "Not received any RTCP packets yet, inferring peer port "
477  "from the RTP port\n");
478  } else {
479  temp_source = s->last_rtcp_source;
480  temp_len = s->last_rtcp_source_len;
483  "Not received any RTP packets yet, inferring peer port "
484  "from the RTCP port\n");
485  }
486  }
487 
488  if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
489  ret = ff_network_wait_fd(fd, 1);
490  if (ret < 0)
491  return ret;
492  }
493  ret = sendto(fd, buf, size, 0, (struct sockaddr *) source,
494  *source_len);
495 
496  return ret < 0 ? ff_neterrno() : ret;
497  }
498 
499  if (RTP_PT_IS_RTCP(buf[1])) {
500  /* RTCP payload type */
501  hd = s->rtcp_hd;
502  } else {
503  /* RTP payload type */
504  hd = s->rtp_hd;
505  }
506 
507  if ((ret = ffurl_write(hd, buf, size)) < 0) {
508  return ret;
509  }
510 
511  if (s->fec_hd && !RTP_PT_IS_RTCP(buf[1])) {
512  if ((ret_fec = ffurl_write(s->fec_hd, buf, size)) < 0) {
513  av_log(h, AV_LOG_ERROR, "Failed to send FEC\n");
514  return ret_fec;
515  }
516  }
517 
518  return ret;
519 }
520 
521 static int rtp_close(URLContext *h)
522 {
523  RTPContext *s = h->priv_data;
524 
525  ff_ip_reset_filters(&s->filters);
526 
527  ffurl_closep(&s->rtp_hd);
528  ffurl_closep(&s->rtcp_hd);
529  ffurl_closep(&s->fec_hd);
530  return 0;
531 }
532 
533 /**
534  * Return the local rtp port used by the RTP connection
535  * @param h media file context
536  * @return the local port number
537  */
538 
540 {
541  RTPContext *s = h->priv_data;
542  return ff_udp_get_local_port(s->rtp_hd);
543 }
544 
545 /**
546  * Return the local rtcp port used by the RTP connection
547  * @param h media file context
548  * @return the local port number
549  */
550 
552 {
553  RTPContext *s = h->priv_data;
554  return s->rtp_fd;
555 }
556 
557 static int rtp_get_multi_file_handle(URLContext *h, int **handles,
558  int *numhandles)
559 {
560  RTPContext *s = h->priv_data;
561  int *hs = *handles = av_malloc(sizeof(**handles) * 2);
562  if (!hs)
563  return AVERROR(ENOMEM);
564  hs[0] = s->rtp_fd;
565  hs[1] = s->rtcp_fd;
566  *numhandles = 2;
567  return 0;
568 }
569 
571  .name = "rtp",
572  .url_open = rtp_open,
573  .url_read = rtp_read,
574  .url_write = rtp_write,
575  .url_close = rtp_close,
576  .url_get_file_handle = rtp_get_file_handle,
577  .url_get_multi_file_handle = rtp_get_multi_file_handle,
578  .priv_data_size = sizeof(RTPContext),
580  .priv_data_class = &rtp_class,
581 };
ff_udp_get_local_port
int ff_udp_get_local_port(URLContext *h)
Return the local port used by the UDP connection.
Definition: udp.c:464
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
RTPContext::rtcp_fd
int rtcp_fd
Definition: rtpproto.c:48
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
RTPContext::connect
int connect
Definition: rtpproto.c:56
opt.h
av_find_info_tag
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:756
URL_PROTOCOL_FLAG_NETWORK
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:33
ff_ip_parse_sources
int ff_ip_parse_sources(void *log_ctx, const char *buf, IPSourceFilters *filters)
Parses the address[,address] source list in buf and adds it to the filters in the IPSourceFilters str...
Definition: ip.c:145
av_printf_format
static av_printf_format(3, 4)
add option to url of the form: "http://host:port/path?option1=val1&option2=val2...
Definition: rtpproto.c:159
RTP_VERSION
#define RTP_VERSION
Definition: rtp.h:80
RTPContext::local_rtcpport
int local_rtcpport
Definition: rtpproto.c:55
int64_t
long long int64_t
Definition: coverity.c:34
ffurl_write
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: url.h:202
rtp_close
static int rtp_close(URLContext *h)
Definition: rtpproto.c:521
sources
Note except for filters that can have queued frames and sources
Definition: filter_design.txt:285
AVOption
AVOption.
Definition: opt.h:429
OFFSET
#define OFFSET(x)
Definition: rtpproto.c:66
ff_udp_set_remote_url
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:425
AVDictionary
Definition: dict.c:34
URLProtocol
Definition: url.h:51
os_support.h
RTPContext::last_rtp_source_len
socklen_t last_rtp_source_len
Definition: rtpproto.c:52
sockaddr_storage
Definition: network.h:111
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
ff_rtp_protocol
const URLProtocol ff_rtp_protocol
Definition: rtpproto.c:570
ff_ip_reset_filters
void ff_ip_reset_filters(IPSourceFilters *filters)
Resets the IP filter list and frees the internal fields of an IPSourceFilters structure.
Definition: ip.c:155
rtp_class
static const AVClass rtp_class
Definition: rtpproto.c:87
fail
#define fail()
Definition: checkasm.h:189
ff_rtp_get_local_rtp_port
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
Definition: rtpproto.c:539
ff_rtp_set_remote_url
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:104
RTPContext::fec_options_str
char * fec_options_str
Definition: rtpproto.c:61
ss
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:202
ff_check_interrupt
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
Definition: avio.c:854
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
ffurl_open_whitelist
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:362
s
#define s(width, name)
Definition: cbs_vp9.c:198
RTPContext::ttl
int ttl
Definition: rtpproto.c:53
ff_url_join
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:40
AV_OPT_TYPE_INT64
@ AV_OPT_TYPE_INT64
Underlying C type is int64_t.
Definition: opt.h:263
AVIO_FLAG_WRITE
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:618
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
RTPContext::block
char * block
Definition: rtpproto.c:60
NULL
#define NULL
Definition: coverity.c:32
ff_ip_parse_blocks
int ff_ip_parse_blocks(void *log_ctx, const char *buf, IPSourceFilters *filters)
Parses the address[,address] source block list in buf and adds it to the filters in the IPSourceFilte...
Definition: ip.c:150
RTPContext::rtcp_hd
URLContext * rtcp_hd
Definition: rtpproto.c:47
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
RTPContext::buffer_size
int buffer_size
Definition: rtpproto.c:54
parseutils.h
ff_neterrno
#define ff_neterrno()
Definition: network.h:68
source
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a source
Definition: filter_design.txt:255
RTP_PT_IS_RTCP
#define RTP_PT_IS_RTCP(x)
Definition: rtp.h:112
RTPContext::pkt_size
int pkt_size
Definition: rtpproto.c:57
RTPContext::dscp
int dscp
Definition: rtpproto.c:58
rtp_read
static int rtp_read(URLContext *h, uint8_t *buf, int size)
Definition: rtpproto.c:391
RTPContext::rtp_hd
URLContext * rtp_hd
Definition: rtpproto.c:47
size
int size
Definition: twinvq_data.h:10344
URLProtocol::name
const char * name
Definition: url.h:52
set_port
static void set_port(struct sockaddr_storage *ss, int port)
Definition: rtpproto.c:144
RTPContext::localaddr
char * localaddr
Definition: rtpproto.c:63
build_udp_url
static void build_udp_url(RTPContext *s, char *buf, int buf_size, const char *hostname, const char *localaddr, int port, int local_port, const char *include_sources, const char *exclude_sources)
Definition: rtpproto.c:174
RTPContext::last_rtcp_source
struct sockaddr_storage last_rtp_source last_rtcp_source
Definition: rtpproto.c:51
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:223
rtp.h
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
rtp_open
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:225
options
static const AVOption options[]
Definition: rtpproto.c:69
URLContext
Definition: url.h:35
RTPContext::sources
char * sources
Definition: rtpproto.c:59
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ip.h
RTPContext::rw_timeout
int64_t rw_timeout
Definition: rtpproto.c:62
vsnprintf
#define vsnprintf
Definition: snprintf.h:36
rtpproto.h
av_url_split
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:351
url.h
len
int len
Definition: vorbis_enc_data.h:426
ffurl_closep
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:588
ret
ret
Definition: filter_design.txt:187
AVClass::class_name
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:80
av_strlcat
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:95
E
#define E
Definition: rtpproto.c:68
avformat.h
rtp_write
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
Definition: rtpproto.c:435
network.h
RTPContext::local_rtpport
int local_rtpport
Definition: rtpproto.c:55
RTPContext::fec_hd
URLContext * fec_hd
Definition: rtpproto.c:47
IPSourceFilters
Structure for storing IP (UDP) source filters or block lists.
Definition: ip.h:29
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
av_get_token
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
Definition: avstring.c:143
av_dict_parse_string
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
Definition: dict.c:200
RTPContext::rtcp_port
int rtcp_port
Definition: rtpproto.c:55
ff_ip_check_source_lists
int ff_ip_check_source_lists(struct sockaddr_storage *source_addr_ptr, IPSourceFilters *s)
Checks the source address against a given IP source filter.
Definition: ip.c:46
RTPContext
Definition: rtpproto.c:45
rtp_get_file_handle
static int rtp_get_file_handle(URLContext *h)
Return the local rtcp port used by the RTP connection.
Definition: rtpproto.c:551
rtp_get_multi_file_handle
static int rtp_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Definition: rtpproto.c:557
av_dict_set_int
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
Definition: dict.c:167
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:272
mem.h
get_port
static int get_port(const struct sockaddr_storage *ss)
Definition: rtpproto.c:133
D
#define D
Definition: rtpproto.c:67
RTPContext::write_to_source
int write_to_source
Definition: rtpproto.c:50
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition: opt.h:327
AVIO_FLAG_NONBLOCK
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:636
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
POLLING_TIME
#define POLLING_TIME
Definition: network.h:249
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
av_strlcpy
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:85
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
AVERROR_EXIT
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:58
RTPContext::rtp_fd
int rtp_fd
Definition: rtpproto.c:48
RTPContext::filters
IPSourceFilters filters
Definition: rtpproto.c:49
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
Definition: opt.h:276
RTPContext::last_rtcp_source_len
socklen_t last_rtcp_source_len
Definition: rtpproto.c:52
ffurl_get_file_handle
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:814
ff_network_wait_fd
int ff_network_wait_fd(int fd, int write)
Definition: network.c:74