64 #define OFFSET(x) offsetof(RTPContext, x) 65 #define D AV_OPT_FLAG_DECODING_PARAM 66 #define E AV_OPT_FLAG_ENCODING_PARAM 68 {
"ttl",
"Time to live (in milliseconds, multicast only)",
OFFSET(
ttl),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, .flags =
D|
E },
111 path,
sizeof(path), uri);
112 rtcp_port = port + 1;
114 p = strchr(uri,
'?');
117 rtcp_port = strtol(buf,
NULL, 10);
121 ff_url_join(buf,
sizeof(buf),
"udp",
NULL, hostname, port,
"%s", path);
124 ff_url_join(buf,
sizeof(buf),
"udp",
NULL, hostname, rtcp_port,
"%s", path);
132 struct addrinfo hints = { 0 }, *res = 0;
136 snprintf(service,
sizeof(service),
"%d", port);
140 if ((error =
getaddrinfo(hostname, service, &hints, &res))) {
154 return (((
const struct sockaddr_in *)a)->sin_addr.s_addr !=
155 ((
const struct sockaddr_in *)b)->sin_addr.s_addr);
158 #if HAVE_STRUCT_SOCKADDR_IN6 160 const uint8_t *s6_addr_a = ((
const struct sockaddr_in6 *)a)->sin6_addr.s6_addr;
161 const uint8_t *s6_addr_b = ((
const struct sockaddr_in6 *)b)->sin6_addr.s6_addr;
162 return memcmp(s6_addr_a, s6_addr_b, 16);
171 return ntohs(((
const struct sockaddr_in *)ss)->sin_port);
172 #if HAVE_STRUCT_SOCKADDR_IN6 173 if (ss->ss_family == AF_INET6)
174 return ntohs(((
const struct sockaddr_in6 *)ss)->sin6_port);
182 ((
struct sockaddr_in *)ss)->sin_port = htons(port);
183 #if HAVE_STRUCT_SOCKADDR_IN6 184 else if (ss->ss_family == AF_INET6)
185 ((
struct sockaddr_in6 *)ss)->sin6_port = htons(port);
219 if (strchr(buf,
'?'))
229 char *
buf,
int buf_size,
230 const char *hostname,
231 int port,
int local_port,
232 const char *include_sources,
233 const char *exclude_sources)
237 url_add_option(buf, buf_size,
"localport=%d", local_port);
239 url_add_option(buf, buf_size,
"ttl=%d", s->
ttl);
241 url_add_option(buf, buf_size,
"buffer_size=%d", s->
buffer_size);
243 url_add_option(buf, buf_size,
"pkt_size=%d", s->
pkt_size);
245 url_add_option(buf, buf_size,
"connect=1");
247 url_add_option(buf, buf_size,
"dscp=%d", s->
dscp);
248 url_add_option(buf, buf_size,
"fifo_size=0");
249 if (include_sources && include_sources[0])
250 url_add_option(buf, buf_size,
"sources=%s", include_sources);
251 if (exclude_sources && exclude_sources[0])
252 url_add_option(buf, buf_size,
"block=%s", exclude_sources);
257 int *address_list_size_ptr)
261 char tmp =
'\0', *p =
buf, *next;
266 next = strchr(p,
',');
283 dynarray_add(address_list_ptr, address_list_size_ptr, source_addr);
323 char hostname[256], include_sources[1024] =
"", exclude_sources[1024] =
"";
324 char *
sources = include_sources, *
block = exclude_sources;
325 char *fec_protocol =
NULL;
329 int i, max_retry_count = 3;
333 path,
sizeof(path), uri);
338 p = strchr(uri,
'?');
341 s->
ttl = strtol(buf,
NULL, 10);
368 av_strlcpy(include_sources, buf,
sizeof(include_sources));
376 av_strlcpy(exclude_sources, buf,
sizeof(exclude_sources));
391 if (strcmp(fec_protocol,
"prompeg")) {
397 while (*p && *p ==
'=') p++;
409 for (i = 0; i < max_retry_count; i++) {
480 struct pollfd p[2] = {{s->
rtp_fd, POLLIN, 0}, {s->
rtcp_fd, POLLIN, 0}};
488 n = poll(p, 2, poll_delay);
491 for (i = 1; i >= 0; i--) {
492 if (!(p[i].revents & POLLIN))
494 *addr_lens[i] =
sizeof(*addrs[i]);
495 len = recvfrom(p[i].fd, buf, size, 0,
496 (
struct sockaddr *)addrs[i], addr_lens[i]);
528 "make sure the RTP muxer is used\n");
533 socklen_t *source_len, temp_len;
536 "Unable to send packet to source, no packets received yet\n");
547 source = &s->last_rtp_source;
551 source = &temp_source;
552 source_len = &temp_len;
554 temp_source = s->last_rtp_source;
558 "Not received any RTCP packets yet, inferring peer port " 559 "from the RTP port\n");
565 "Not received any RTP packets yet, inferring peer port " 566 "from the RTCP port\n");
575 ret = sendto(fd, buf, size, 0, (
struct sockaddr *) source,
649 int *hs = *handles =
av_malloc(
sizeof(**handles) * 2);
668 .priv_data_class = &rtp_class,
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 ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
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. ...
#define URL_PROTOCOL_FLAG_NETWORK
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
int is_streamed
true if streamed (no seek possible), default = false
AVIOInterruptCB interrupt_callback
static int rtp_check_source_lists(RTPContext *s, struct sockaddr_storage *source_addr_ptr)
const char * av_default_item_name(void *ptr)
Return the context name.
#define AVIO_FLAG_WRITE
write-only
static void rtp_parse_addr_list(URLContext *h, char *buf, struct sockaddr_storage ***address_list_ptr, int *address_list_size_ptr)
const URLProtocol ff_rtp_protocol
static int compare_addr(const struct sockaddr_storage *a, const struct sockaddr_storage *b)
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int rtp_close(URLContext *h)
miscellaneous OS support macros and functions.
socklen_t last_rtp_source_len
static int get_port(const struct sockaddr_storage *ss)
int ff_udp_get_local_port(URLContext *h)
Return the local port used by the UDP connection.
struct sockaddr_storage ** ssm_include_addrs
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
const char * protocol_whitelist
static int rtp_read(URLContext *h, uint8_t *buf, int size)
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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.
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 const AVClass rtp_class
struct sockaddr_storage last_rtp_source last_rtcp_source
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[]
static int rtp_get_multi_file_handle(URLContext *h, int **handles, int *numhandles)
int ffurl_get_file_handle(URLContext *h)
Return the file descriptor associated with this URL.
#define AVERROR_EXIT
Immediate exit was requested; the called function should not be restarted.
static void error(const char *err)
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
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.
#define AV_LOG_INFO
Standard information.
const char * protocol_blacklist
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrupt a blocking function associated with cb.
typedef void(RENAME(mix_any_func_type))
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
socklen_t last_rtcp_source_len
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Describe the class of an AVClass context structure.
static av_printf_format(3, 4)
add option to url of the form: "http://host:port/path?option1=val1&option2=val2...
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...
#define RTP_PT_IS_RTCP(x)
static void set_port(struct sockaddr_storage *ss, int port)
int ffurl_close(URLContext *h)
static struct addrinfo * rtp_resolve_host(const char *hostname, int port, int type, int family, int flags)
struct sockaddr_storage ** ssm_exclude_addrs
static int rtp_get_file_handle(URLContext *h)
Return the local rtcp port used by the RTP connection.
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)
int max_packet_size
if non zero, the stream is packetized with this max packet size
int ff_network_wait_fd(int fd, int write)
unbuffered private I/O API
struct sockaddr * ai_addr
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...