Go to the documentation of this file.
67 #define OFFSET(x) offsetof(RTPContext, x)
68 #define D AV_OPT_FLAG_DECODING_PARAM
69 #define E AV_OPT_FLAG_ENCODING_PARAM
71 {
"ttl",
"Time to live (in milliseconds, multicast only)",
OFFSET(ttl),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
72 {
"buffer_size",
"Send/Receive buffer size (in bytes)",
OFFSET(buffer_size),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
73 {
"rtcp_port",
"Custom rtcp port",
OFFSET(rtcp_port),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
74 {
"local_rtpport",
"Local rtp port",
OFFSET(local_rtpport),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
75 {
"local_rtcpport",
"Local rtcp port",
OFFSET(local_rtcpport),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
77 {
"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 },
78 {
"pkt_size",
"Maximum packet size",
OFFSET(pkt_size),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
80 {
"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 },
116 path,
sizeof(path), uri);
117 rtcp_port = port + 1;
119 p = strchr(uri,
'?');
122 rtcp_port = strtol(buf,
NULL, 10);
126 ff_url_join(buf,
sizeof(buf),
"udp",
NULL, hostname, port,
"%s", path);
129 ff_url_join(buf,
sizeof(buf),
"udp",
NULL, hostname, rtcp_port,
"%s", path);
136 if (
ss->ss_family == AF_INET)
137 return ntohs(((
const struct sockaddr_in *)
ss)->sin_port);
138 #if HAVE_STRUCT_SOCKADDR_IN6
139 if (
ss->ss_family == AF_INET6)
140 return ntohs(((
const struct sockaddr_in6 *)
ss)->sin6_port);
147 if (
ss->ss_family == AF_INET)
148 ((
struct sockaddr_in *)
ss)->sin_port = htons(port);
149 #if HAVE_STRUCT_SOCKADDR_IN6
150 else if (
ss->ss_family == AF_INET6)
151 ((
struct sockaddr_in6 *)
ss)->sin6_port = htons(port);
160 static av_printf_format(3, 4) void url_add_option(
char *buf,
int buf_size, const
char *fmt, ...)
166 if (strchr(buf,
'?'))
176 char *buf,
int buf_size,
177 const char *hostname,
178 const char *localaddr,
179 int port,
int local_port,
180 const char *include_sources,
181 const char *exclude_sources)
185 url_add_option(buf, buf_size,
"localport=%d", local_port);
187 url_add_option(buf, buf_size,
"ttl=%d",
s->ttl);
188 if (
s->buffer_size >= 0)
189 url_add_option(buf, buf_size,
"buffer_size=%d",
s->buffer_size);
190 if (
s->pkt_size >= 0)
191 url_add_option(buf, buf_size,
"pkt_size=%d",
s->pkt_size);
193 url_add_option(buf, buf_size,
"connect=1");
195 url_add_option(buf, buf_size,
"dscp=%d",
s->dscp);
196 url_add_option(buf, buf_size,
"fifo_size=0");
197 if (include_sources && include_sources[0])
198 url_add_option(buf, buf_size,
"sources=%s", include_sources);
199 if (exclude_sources && exclude_sources[0])
200 url_add_option(buf, buf_size,
"block=%s", exclude_sources);
201 if (localaddr && localaddr[0])
202 url_add_option(buf, buf_size,
"localaddr=%s", localaddr);
231 char hostname[256], include_sources[1024] =
"", exclude_sources[1024] =
"";
232 char *
sources = include_sources, *
block = exclude_sources;
233 char *fec_protocol =
NULL;
237 int i, max_retry_count = 3;
241 path,
sizeof(path), uri);
243 if (
s->rtcp_port < 0)
244 s->rtcp_port = rtp_port + 1;
246 p = strchr(uri,
'?');
249 s->ttl = strtol(buf,
NULL, 10);
252 s->rtcp_port = strtol(buf,
NULL, 10);
255 s->local_rtpport = strtol(buf,
NULL, 10);
258 s->local_rtpport = strtol(buf,
NULL, 10);
261 s->local_rtcpport = strtol(buf,
NULL, 10);
264 s->pkt_size = strtol(buf,
NULL, 10);
267 s->connect = strtol(buf,
NULL, 10);
270 s->write_to_source = strtol(buf,
NULL, 10);
273 s->dscp = strtol(buf,
NULL, 10);
276 s->rw_timeout = strtol(buf,
NULL, 10);
279 av_strlcpy(include_sources, buf,
sizeof(include_sources));
286 av_strlcpy(exclude_sources, buf,
sizeof(exclude_sources));
299 if (
s->rw_timeout >= 0)
300 h->rw_timeout =
s->rw_timeout;
302 if (
s->fec_options_str) {
303 p =
s->fec_options_str;
309 if (strcmp(fec_protocol,
"prompeg")) {
314 p =
s->fec_options_str + strlen(fec_protocol);
315 while (*p && *p ==
'=') p++;
326 for (
i = 0;
i < max_retry_count;
i++) {
328 hostname,
s->localaddr, rtp_port,
s->local_rtpport,
331 NULL,
h->protocol_whitelist,
h->protocol_blacklist,
h) < 0)
334 if(
s->local_rtpport == 65535) {
335 s->local_rtpport = -1;
339 if (
s->local_rtcpport < 0) {
340 s->local_rtcpport =
s->local_rtpport + 1;
342 hostname,
s->localaddr,
s->rtcp_port,
s->local_rtcpport,
345 &
h->interrupt_callback,
NULL,
346 h->protocol_whitelist,
h->protocol_blacklist,
h) < 0) {
347 s->local_rtpport =
s->local_rtcpport = -1;
353 hostname,
s->localaddr,
s->rtcp_port,
s->local_rtcpport,
356 NULL,
h->protocol_whitelist,
h->protocol_blacklist,
h) < 0)
365 &fec_opts,
h->protocol_whitelist,
h->protocol_blacklist,
h) < 0)
374 h->max_packet_size =
s->rtp_hd->max_packet_size;
395 struct pollfd p[2] = {{
s->rtp_fd, POLLIN, 0}, {
s->rtcp_fd, POLLIN, 0}};
398 socklen_t *addr_lens[2] = { &
s->last_rtp_source_len, &
s->last_rtcp_source_len };
404 n = poll(p, 2, poll_delay);
407 for (
i = 1;
i >= 0;
i--) {
408 if (!(p[
i].revents & POLLIN))
410 *addr_lens[
i] =
sizeof(*addrs[
i]);
411 len = recvfrom(p[
i].fd, buf,
size, 0,
412 (
struct sockaddr *)addrs[
i], addr_lens[
i]);
423 }
else if (n == 0 &&
h->rw_timeout > 0 && --runs <= 0) {
446 "make sure the RTP muxer is used\n");
448 if (
s->write_to_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");
462 source_len = &
s->last_rtcp_source_len;
466 source_len = &
s->last_rtp_source_len;
470 source_len = &temp_len;
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");
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");
561 int *hs = *handles =
av_malloc(
sizeof(**handles) * 2);
int ff_udp_get_local_port(URLContext *h)
Return the local port used by the UDP connection.
#define AV_LOG_WARNING
Something somehow does not look correct.
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 av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info)
Attempt to find a specific tag in a URL.
#define URL_PROTOCOL_FLAG_NETWORK
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...
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...
static av_printf_format(3, 4)
add option to url of the form: "http://host:port/path?option1=val1&option2=val2...
static int rtp_close(URLContext *h)
Note except for filters that can have queued frames and sources
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,...
socklen_t last_rtp_source_len
const URLProtocol ff_rtp_protocol
void ff_ip_reset_filters(IPSourceFilters *filters)
Resets the IP filter list and frees the internal fields of an IPSourceFilters structure.
static const AVClass rtp_class
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
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,...
#define ss(width, name, subs,...)
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
#define AVIO_FLAG_WRITE
write-only
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
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...
const char * av_default_item_name(void *ptr)
Return the context name.
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
#define RTP_PT_IS_RTCP(x)
static int rtp_read(URLContext *h, uint8_t *buf, int size)
static void set_port(struct sockaddr_storage *ss, int port)
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)
struct sockaddr_storage last_rtp_source last_rtcp_source
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
#define AV_LOG_INFO
Standard information.
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) ...
static const AVOption options[]
#define i(width, name, range_min, range_max)
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.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
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,...
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
Structure for storing IP (UDP) source filters or block lists.
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.
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int ff_ip_check_source_lists(struct sockaddr_storage *source_addr_ptr, IPSourceFilters *s)
Checks the source address against a given IP source filter.
static int rtp_get_file_handle(URLContext *h)
Return the local rtcp port used by the RTP connection.
static int rtp_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
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.
char * av_strdup(const char *s)
Duplicate a string.
static int get_port(const struct sockaddr_storage *ss)
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
#define flags(name, subs,...)
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.
The exact code depends on how similar the blocks are and how related they are to the block
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
socklen_t last_rtcp_source_len
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
int ff_network_wait_fd(int fd, int write)