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/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 #include "ip.h"
36 
37 #include <stdarg.h>
38 #include "internal.h"
39 #include "network.h"
40 #include "os_support.h"
41 #include <fcntl.h>
42 #if HAVE_POLL_H
43 #include <poll.h>
44 #endif
45 
46 typedef struct RTPContext {
47  const AVClass *class;
52  struct sockaddr_storage last_rtp_source, last_rtcp_source;
54  int ttl;
57  int connect;
58  int pkt_size;
59  int dscp;
60  char *sources;
61  char *block;
63 } RTPContext;
64 
65 #define OFFSET(x) offsetof(RTPContext, x)
66 #define D AV_OPT_FLAG_DECODING_PARAM
67 #define E AV_OPT_FLAG_ENCODING_PARAM
68 static const AVOption options[] = {
69  { "ttl", "Time to live (in milliseconds, multicast only)", OFFSET(ttl), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
70  { "buffer_size", "Send/Receive buffer size (in bytes)", OFFSET(buffer_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
71  { "rtcp_port", "Custom rtcp port", OFFSET(rtcp_port), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
72  { "local_rtpport", "Local rtp port", OFFSET(local_rtpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
73  { "local_rtcpport", "Local rtcp port", OFFSET(local_rtcpport), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
74  { "connect", "Connect socket", OFFSET(connect), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, .flags = D|E },
75  { "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 },
76  { "pkt_size", "Maximum packet size", OFFSET(pkt_size), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
77  { "dscp", "DSCP class", OFFSET(dscp), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags = D|E },
78  { "sources", "Source list", OFFSET(sources), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
79  { "block", "Block list", OFFSET(block), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = D|E },
80  { "fec", "FEC", OFFSET(fec_options_str), AV_OPT_TYPE_STRING, { .str = NULL }, .flags = E },
81  { NULL }
82 };
83 
84 static const AVClass rtp_class = {
85  .class_name = "rtp",
86  .item_name = av_default_item_name,
87  .option = options,
88  .version = LIBAVUTIL_VERSION_INT,
89 };
90 
91 /**
92  * If no filename is given to av_open_input_file because you want to
93  * get the local port first, then you must call this function to set
94  * the remote server address.
95  *
96  * @param h media file context
97  * @param uri of the remote server
98  * @return zero if no error.
99  */
100 
101 int ff_rtp_set_remote_url(URLContext *h, const char *uri)
102 {
103  RTPContext *s = h->priv_data;
104  char hostname[256];
105  int port, rtcp_port;
106  const char *p;
107 
108  char buf[1024];
109  char path[1024];
110 
111  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &port,
112  path, sizeof(path), uri);
113  rtcp_port = port + 1;
114 
115  p = strchr(uri, '?');
116  if (p) {
117  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
118  rtcp_port = strtol(buf, NULL, 10);
119  }
120  }
121 
122  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path);
123  ff_udp_set_remote_url(s->rtp_hd, buf);
124 
125  ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, rtcp_port, "%s", path);
127  return 0;
128 }
129 
130 static int get_port(const struct sockaddr_storage *ss)
131 {
132  if (ss->ss_family == AF_INET)
133  return ntohs(((const struct sockaddr_in *)ss)->sin_port);
134 #if HAVE_STRUCT_SOCKADDR_IN6
135  if (ss->ss_family == AF_INET6)
136  return ntohs(((const struct sockaddr_in6 *)ss)->sin6_port);
137 #endif
138  return 0;
139 }
140 
141 static void set_port(struct sockaddr_storage *ss, int port)
142 {
143  if (ss->ss_family == AF_INET)
144  ((struct sockaddr_in *)ss)->sin_port = htons(port);
145 #if HAVE_STRUCT_SOCKADDR_IN6
146  else if (ss->ss_family == AF_INET6)
147  ((struct sockaddr_in6 *)ss)->sin6_port = htons(port);
148 #endif
149 }
150 
151 /**
152  * add option to url of the form:
153  * "http://host:port/path?option1=val1&option2=val2...
154  */
155 
156 static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...)
157 {
158  char buf1[1024];
159  va_list ap;
160 
161  va_start(ap, fmt);
162  if (strchr(buf, '?'))
163  av_strlcat(buf, "&", buf_size);
164  else
165  av_strlcat(buf, "?", buf_size);
166  vsnprintf(buf1, sizeof(buf1), fmt, ap);
167  av_strlcat(buf, buf1, buf_size);
168  va_end(ap);
169 }
170 
172  char *buf, int buf_size,
173  const char *hostname,
174  int port, int local_port,
175  const char *include_sources,
176  const char *exclude_sources)
177 {
178  ff_url_join(buf, buf_size, "udp", NULL, hostname, port, NULL);
179  if (local_port >= 0)
180  url_add_option(buf, buf_size, "localport=%d", local_port);
181  if (s->ttl >= 0)
182  url_add_option(buf, buf_size, "ttl=%d", s->ttl);
183  if (s->buffer_size >= 0)
184  url_add_option(buf, buf_size, "buffer_size=%d", s->buffer_size);
185  if (s->pkt_size >= 0)
186  url_add_option(buf, buf_size, "pkt_size=%d", s->pkt_size);
187  if (s->connect)
188  url_add_option(buf, buf_size, "connect=1");
189  if (s->dscp >= 0)
190  url_add_option(buf, buf_size, "dscp=%d", s->dscp);
191  url_add_option(buf, buf_size, "fifo_size=0");
192  if (include_sources && include_sources[0])
193  url_add_option(buf, buf_size, "sources=%s", include_sources);
194  if (exclude_sources && exclude_sources[0])
195  url_add_option(buf, buf_size, "block=%s", exclude_sources);
196 }
197 
198 /**
199  * url syntax: rtp://host:port[?option=val...]
200  * option: 'ttl=n' : set the ttl value (for multicast only)
201  * 'rtcpport=n' : set the remote rtcp port to n
202  * 'localrtpport=n' : set the local rtp port to n
203  * 'localrtcpport=n' : set the local rtcp port to n
204  * 'pkt_size=n' : set max packet size
205  * 'connect=0/1' : do a connect() on the UDP socket
206  * 'sources=ip[,ip]' : list allowed source IP addresses
207  * 'block=ip[,ip]' : list disallowed source IP addresses
208  * 'write_to_source=0/1' : send packets to the source address of the latest received packet
209  * 'dscp=n' : set DSCP value to n (QoS)
210  * deprecated option:
211  * 'localport=n' : set the local port to n
212  *
213  * if rtcpport isn't set the rtcp port will be the rtp port + 1
214  * if local rtp port isn't set any available port will be used for the local
215  * rtp and rtcp ports
216  * if the local rtcp port is not set it will be the local rtp port + 1
217  */
218 
219 static int rtp_open(URLContext *h, const char *uri, int flags)
220 {
221  RTPContext *s = h->priv_data;
222  AVDictionary *fec_opts = NULL;
223  int rtp_port;
224  char hostname[256], include_sources[1024] = "", exclude_sources[1024] = "";
225  char *sources = include_sources, *block = exclude_sources;
226  char *fec_protocol = NULL;
227  char buf[1024];
228  char path[1024];
229  const char *p;
230  int i, max_retry_count = 3;
231  int rtcpflags;
232 
233  av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port,
234  path, sizeof(path), uri);
235  /* extract parameters */
236  if (s->rtcp_port < 0)
237  s->rtcp_port = rtp_port + 1;
238 
239  p = strchr(uri, '?');
240  if (p) {
241  if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) {
242  s->ttl = strtol(buf, NULL, 10);
243  }
244  if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) {
245  s->rtcp_port = strtol(buf, NULL, 10);
246  }
247  if (av_find_info_tag(buf, sizeof(buf), "localport", p)) {
248  s->local_rtpport = strtol(buf, NULL, 10);
249  }
250  if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) {
251  s->local_rtpport = strtol(buf, NULL, 10);
252  }
253  if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) {
254  s->local_rtcpport = strtol(buf, NULL, 10);
255  }
256  if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) {
257  s->pkt_size = strtol(buf, NULL, 10);
258  }
259  if (av_find_info_tag(buf, sizeof(buf), "connect", p)) {
260  s->connect = strtol(buf, NULL, 10);
261  }
262  if (av_find_info_tag(buf, sizeof(buf), "write_to_source", p)) {
263  s->write_to_source = strtol(buf, NULL, 10);
264  }
265  if (av_find_info_tag(buf, sizeof(buf), "dscp", p)) {
266  s->dscp = strtol(buf, NULL, 10);
267  }
268  if (av_find_info_tag(buf, sizeof(buf), "sources", p)) {
269  av_strlcpy(include_sources, buf, sizeof(include_sources));
270  ff_ip_parse_sources(h, buf, &s->filters);
271  } else {
272  ff_ip_parse_sources(h, s->sources, &s->filters);
273  sources = s->sources;
274  }
275  if (av_find_info_tag(buf, sizeof(buf), "block", p)) {
276  av_strlcpy(exclude_sources, buf, sizeof(exclude_sources));
277  ff_ip_parse_blocks(h, buf, &s->filters);
278  } else {
279  ff_ip_parse_blocks(h, s->block, &s->filters);
280  block = s->block;
281  }
282  }
283 
284  if (s->fec_options_str) {
285  p = s->fec_options_str;
286 
287  if (!(fec_protocol = av_get_token(&p, "="))) {
288  av_log(h, AV_LOG_ERROR, "Failed to parse the FEC protocol value\n");
289  goto fail;
290  }
291  if (strcmp(fec_protocol, "prompeg")) {
292  av_log(h, AV_LOG_ERROR, "Unsupported FEC protocol %s\n", fec_protocol);
293  goto fail;
294  }
295 
296  p = s->fec_options_str + strlen(fec_protocol);
297  while (*p && *p == '=') p++;
298 
299  if (av_dict_parse_string(&fec_opts, p, "=", ":", 0) < 0) {
300  av_log(h, AV_LOG_ERROR, "Failed to parse the FEC options\n");
301  goto fail;
302  }
303  if (s->ttl > 0) {
304  av_dict_set_int(&fec_opts, "ttl", s->ttl, 0);
305  }
306  }
307 
308  for (i = 0; i < max_retry_count; i++) {
309  build_udp_url(s, buf, sizeof(buf),
310  hostname, rtp_port, s->local_rtpport,
311  sources, block);
312  if (ffurl_open_whitelist(&s->rtp_hd, buf, flags, &h->interrupt_callback,
314  goto fail;
316  if(s->local_rtpport == 65535) {
317  s->local_rtpport = -1;
318  continue;
319  }
320  rtcpflags = flags | AVIO_FLAG_WRITE;
321  if (s->local_rtcpport < 0) {
322  s->local_rtcpport = s->local_rtpport + 1;
323  build_udp_url(s, buf, sizeof(buf),
324  hostname, s->rtcp_port, s->local_rtcpport,
325  sources, block);
326  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags,
328  h->protocol_whitelist, h->protocol_blacklist, h) < 0) {
329  s->local_rtpport = s->local_rtcpport = -1;
330  continue;
331  }
332  break;
333  }
334  build_udp_url(s, buf, sizeof(buf),
335  hostname, s->rtcp_port, s->local_rtcpport,
336  sources, block);
337  if (ffurl_open_whitelist(&s->rtcp_hd, buf, rtcpflags, &h->interrupt_callback,
339  goto fail;
340  break;
341  }
342 
343  s->fec_hd = NULL;
344  if (fec_protocol) {
345  ff_url_join(buf, sizeof(buf), fec_protocol, NULL, hostname, rtp_port, NULL);
346  if (ffurl_open_whitelist(&s->fec_hd, buf, flags, &h->interrupt_callback,
347  &fec_opts, h->protocol_whitelist, h->protocol_blacklist, h) < 0)
348  goto fail;
349  }
350 
351  /* just to ease handle access. XXX: need to suppress direct handle
352  access */
355 
357  h->is_streamed = 1;
358 
359  av_free(fec_protocol);
360  av_dict_free(&fec_opts);
361 
362  return 0;
363 
364  fail:
365  ffurl_closep(&s->rtp_hd);
366  ffurl_closep(&s->rtcp_hd);
367  ffurl_closep(&s->fec_hd);
368  av_free(fec_protocol);
369  av_dict_free(&fec_opts);
370  return AVERROR(EIO);
371 }
372 
373 static int rtp_read(URLContext *h, uint8_t *buf, int size)
374 {
375  RTPContext *s = h->priv_data;
376  int len, n, i;
377  struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}};
378  int poll_delay = h->flags & AVIO_FLAG_NONBLOCK ? 0 : 100;
379  struct sockaddr_storage *addrs[2] = { &s->last_rtp_source, &s->last_rtcp_source };
380  socklen_t *addr_lens[2] = { &s->last_rtp_source_len, &s->last_rtcp_source_len };
381 
382  for(;;) {
384  return AVERROR_EXIT;
385  n = poll(p, 2, poll_delay);
386  if (n > 0) {
387  /* first try RTCP, then RTP */
388  for (i = 1; i >= 0; i--) {
389  if (!(p[i].revents & POLLIN))
390  continue;
391  *addr_lens[i] = sizeof(*addrs[i]);
392  len = recvfrom(p[i].fd, buf, size, 0,
393  (struct sockaddr *)addrs[i], addr_lens[i]);
394  if (len < 0) {
395  if (ff_neterrno() == AVERROR(EAGAIN) ||
396  ff_neterrno() == AVERROR(EINTR))
397  continue;
398  return AVERROR(EIO);
399  }
400  if (ff_ip_check_source_lists(addrs[i], &s->filters))
401  continue;
402  return len;
403  }
404  } else if (n < 0) {
405  if (ff_neterrno() == AVERROR(EINTR))
406  continue;
407  return AVERROR(EIO);
408  }
409  if (h->flags & AVIO_FLAG_NONBLOCK)
410  return AVERROR(EAGAIN);
411  }
412 }
413 
414 static int rtp_write(URLContext *h, const uint8_t *buf, int size)
415 {
416  RTPContext *s = h->priv_data;
417  int ret, ret_fec;
418  URLContext *hd;
419 
420  if (size < 2)
421  return AVERROR(EINVAL);
422 
423  if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
424  av_log(h, AV_LOG_WARNING, "Data doesn't look like RTP packets, "
425  "make sure the RTP muxer is used\n");
426 
427  if (s->write_to_source) {
428  int fd;
429  struct sockaddr_storage *source, temp_source;
430  socklen_t *source_len, temp_len;
431  if (!s->last_rtp_source.ss_family && !s->last_rtcp_source.ss_family) {
432  av_log(h, AV_LOG_ERROR,
433  "Unable to send packet to source, no packets received yet\n");
434  // Intentionally not returning an error here
435  return size;
436  }
437 
438  if (RTP_PT_IS_RTCP(buf[1])) {
439  fd = s->rtcp_fd;
440  source = &s->last_rtcp_source;
441  source_len = &s->last_rtcp_source_len;
442  } else {
443  fd = s->rtp_fd;
444  source = &s->last_rtp_source;
445  source_len = &s->last_rtp_source_len;
446  }
447  if (!source->ss_family) {
448  source = &temp_source;
449  source_len = &temp_len;
450  if (RTP_PT_IS_RTCP(buf[1])) {
451  temp_source = s->last_rtp_source;
452  temp_len = s->last_rtp_source_len;
453  set_port(source, get_port(source) + 1);
454  av_log(h, AV_LOG_INFO,
455  "Not received any RTCP packets yet, inferring peer port "
456  "from the RTP port\n");
457  } else {
458  temp_source = s->last_rtcp_source;
459  temp_len = s->last_rtcp_source_len;
460  set_port(source, get_port(source) - 1);
461  av_log(h, AV_LOG_INFO,
462  "Not received any RTP packets yet, inferring peer port "
463  "from the RTCP port\n");
464  }
465  }
466 
467  if (!(h->flags & AVIO_FLAG_NONBLOCK)) {
468  ret = ff_network_wait_fd(fd, 1);
469  if (ret < 0)
470  return ret;
471  }
472  ret = sendto(fd, buf, size, 0, (struct sockaddr *) source,
473  *source_len);
474 
475  return ret < 0 ? ff_neterrno() : ret;
476  }
477 
478  if (RTP_PT_IS_RTCP(buf[1])) {
479  /* RTCP payload type */
480  hd = s->rtcp_hd;
481  } else {
482  /* RTP payload type */
483  hd = s->rtp_hd;
484  }
485 
486  if ((ret = ffurl_write(hd, buf, size)) < 0) {
487  return ret;
488  }
489 
490  if (s->fec_hd && !RTP_PT_IS_RTCP(buf[1])) {
491  if ((ret_fec = ffurl_write(s->fec_hd, buf, size)) < 0) {
492  av_log(h, AV_LOG_ERROR, "Failed to send FEC\n");
493  return ret_fec;
494  }
495  }
496 
497  return ret;
498 }
499 
500 static int rtp_close(URLContext *h)
501 {
502  RTPContext *s = h->priv_data;
503 
505 
506  ffurl_closep(&s->rtp_hd);
507  ffurl_closep(&s->rtcp_hd);
508  ffurl_closep(&s->fec_hd);
509  return 0;
510 }
511 
512 /**
513  * Return the local rtp port used by the RTP connection
514  * @param h media file context
515  * @return the local port number
516  */
517 
519 {
520  RTPContext *s = h->priv_data;
521  return ff_udp_get_local_port(s->rtp_hd);
522 }
523 
524 /**
525  * Return the local rtcp port used by the RTP connection
526  * @param h media file context
527  * @return the local port number
528  */
529 
531 {
532  RTPContext *s = h->priv_data;
533  return s->rtp_fd;
534 }
535 
536 static int rtp_get_multi_file_handle(URLContext *h, int **handles,
537  int *numhandles)
538 {
539  RTPContext *s = h->priv_data;
540  int *hs = *handles = av_malloc(sizeof(**handles) * 2);
541  if (!hs)
542  return AVERROR(ENOMEM);
543  hs[0] = s->rtp_fd;
544  hs[1] = s->rtcp_fd;
545  *numhandles = 2;
546  return 0;
547 }
548 
550  .name = "rtp",
551  .url_open = rtp_open,
552  .url_read = rtp_read,
553  .url_write = rtp_write,
554  .url_close = rtp_close,
555  .url_get_file_handle = rtp_get_file_handle,
556  .url_get_multi_file_handle = rtp_get_multi_file_handle,
557  .priv_data_size = sizeof(RTPContext),
559  .priv_data_class = &rtp_class,
560 };
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:4792
#define NULL
Definition: coverity.c:32
int rtcp_port
Definition: rtpproto.c:56
int buffer_size
Definition: rtpproto.c:55
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
Definition: rtpproto.c:518
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:310
#define URL_PROTOCOL_FLAG_NETWORK
Definition: url.h:34
AVOption.
Definition: opt.h:248
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#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:423
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
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
#define AVIO_FLAG_WRITE
write-only
Definition: avio.h:675
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:148
char * block
Definition: rtpproto.c:61
int flags
Definition: url.h:43
const URLProtocol ff_rtp_protocol
Definition: rtpproto.c:549
URLContext * rtcp_hd
Definition: rtpproto.c:48
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
Definition: rtpproto.c:414
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:143
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:500
uint8_t
#define av_malloc(s)
IPSourceFilters filters
Definition: rtpproto.c:50
AVOptions.
#define D
Definition: rtpproto.c:66
miscellaneous OS support macros and functions.
socklen_t last_rtp_source_len
Definition: rtpproto.c:53
static int get_port(const struct sockaddr_storage *ss)
Definition: rtpproto.c:130
int ff_udp_get_local_port(URLContext *h)
Return the local port used by the UDP connection.
Definition: udp.c:445
uint16_t ss_family
Definition: network.h:116
int pkt_size
Definition: rtpproto.c:58
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:749
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
ptrdiff_t size
Definition: opengl_enc.c:100
#define av_log(a,...)
URLContext * rtp_hd
Definition: rtpproto.c:48
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
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:406
const char * protocol_whitelist
Definition: url.h:49
static int rtp_read(URLContext *h, uint8_t *buf, int size)
Definition: rtpproto.c:373
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:203
void ff_ip_reset_filters(IPSourceFilters *filters)
Resets the IP filter list and frees the internal fields of an IPSourceFilters structure.
Definition: ip.c:153
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:123
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:149
#define ss(width, name, subs,...)
Definition: cbs_vp9.c:261
char * fec_options_str
Definition: rtpproto.c:62
static const AVClass rtp_class
Definition: rtpproto.c:84
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
struct sockaddr_storage last_rtp_source last_rtcp_source
Definition: rtpproto.c:52
#define ff_neterrno()
Definition: network.h:68
static int rtp_open(URLContext *h, const char *uri, int flags)
url syntax: rtp://host:port[?option=val...] option: &#39;ttl=n&#39; : set the ttl value (for multicast only) ...
Definition: rtpproto.c:219
#define s(width, name)
Definition: cbs_vp9.c:257
static const AVOption options[]
Definition: rtpproto.c:68
int rtcp_fd
Definition: rtpproto.c:49
static int rtp_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
Definition: rtpproto.c:536
int rtp_fd
Definition: rtpproto.c:49
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
Definition: avio.c:628
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
Definition: error.h:56
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
Definition: avio.c:446
int local_rtcpport
Definition: rtpproto.c:56
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:37
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:180
#define AV_LOG_INFO
Standard information.
Definition: log.h:205
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:666
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
Definition: avio.h:693
socklen_t last_rtcp_source_len
Definition: rtpproto.c:53
Definition: url.h:38
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:44
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:156
void * priv_data
Definition: url.h:41
misc parsing utilities
URLContext * fec_hd
Definition: rtpproto.c:48
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:55
#define RTP_PT_IS_RTCP(x)
Definition: rtp.h:110
static void set_port(struct sockaddr_storage *ss, int port)
Definition: rtpproto.c:141
int dscp
Definition: rtpproto.c:59
#define flags(name, subs,...)
Definition: cbs_av1.c:560
char * sources
Definition: rtpproto.c:60
Main libavformat public API header.
static int rtp_get_file_handle(URLContext *h)
Return the local rtcp port used by the RTP connection.
Definition: rtpproto.c:530
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:171
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:147
int write_to_source
Definition: rtpproto.c:51
#define av_free(p)
int len
int local_rtpport
Definition: rtpproto.c:56
int ttl
Definition: rtpproto.c:54
#define OFFSET(x)
Definition: rtpproto.c:65
int max_packet_size
if non zero, the stream is packetized with this max packet size
Definition: url.h:44
int ff_network_wait_fd(int fd, int write)
Definition: network.c:69
unbuffered private I/O API
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
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:101
Structure for storing IP (UDP) source filters or block lists.
Definition: ip.h:29
int i
Definition: input.c:406
int connect
Definition: rtpproto.c:57
#define E
Definition: rtpproto.c:67