74 path,
sizeof(path), uri);
80 rtcp_port = strtol(buf,
NULL, 10);
87 ff_url_join(buf,
sizeof(buf),
"udp",
NULL, hostname, rtcp_port,
"%s", path);
93 int type,
int family,
int flags)
95 struct addrinfo hints = { 0 }, *res = 0;
99 snprintf(service,
sizeof(service),
"%d", port);
103 if ((error =
getaddrinfo(hostname, service, &hints, &res))) {
117 return (((
const struct sockaddr_in *)a)->sin_addr.s_addr !=
118 ((
const struct sockaddr_in *)b)->sin_addr.s_addr);
121 #if HAVE_STRUCT_SOCKADDR_IN6
123 const uint8_t *s6_addr_a = ((
const struct sockaddr_in6 *)a)->sin6_addr.s6_addr;
124 const uint8_t *s6_addr_b = ((
const struct sockaddr_in6 *)b)->sin6_addr.s6_addr;
125 return memcmp(s6_addr_a, s6_addr_b, 16);
134 return ntohs(((
const struct sockaddr_in *)ss)->sin_port);
135 #if HAVE_STRUCT_SOCKADDR_IN6
137 return ntohs(((
const struct sockaddr_in6 *)ss)->sin6_port);
145 ((
struct sockaddr_in *)ss)->sin_port = htons(port);
146 #if HAVE_STRUCT_SOCKADDR_IN6
147 else if (ss->ss_family == AF_INET6)
148 ((
struct sockaddr_in6 *)ss)->sin6_port = htons(port);
182 if (strchr(buf,
'?'))
186 vsnprintf(buf1,
sizeof(buf1), fmt, ap);
192 const char *hostname,
int port,
193 int local_port,
int ttl,
194 int max_packet_size,
int connect,
195 const char *include_sources,
196 const char *exclude_sources)
200 url_add_option(buf, buf_size,
"localport=%d", local_port);
202 url_add_option(buf, buf_size,
"ttl=%d", ttl);
203 if (max_packet_size >=0)
204 url_add_option(buf, buf_size,
"pkt_size=%d", max_packet_size);
206 url_add_option(buf, buf_size,
"connect=1");
207 if (include_sources && include_sources[0])
208 url_add_option(buf, buf_size,
"sources=%s", include_sources);
209 if (exclude_sources && exclude_sources[0])
210 url_add_option(buf, buf_size,
"block=%s", exclude_sources);
215 int *address_list_size_ptr)
219 char tmp =
'\0', *p = buf, *next;
224 next = strchr(p,
',');
239 dynarray_add(address_list_ptr, address_list_size_ptr, source_addr);
276 int rtp_port, rtcp_port,
278 local_rtp_port, local_rtcp_port, max_packet_size;
279 char hostname[256], include_sources[1024] =
"", exclude_sources[1024] =
"";
285 path,
sizeof(path), uri);
288 rtcp_port = rtp_port+1;
290 local_rtcp_port = -1;
291 max_packet_size = -1;
294 p = strchr(uri,
'?');
297 ttl = strtol(buf,
NULL, 10);
300 rtcp_port = strtol(buf,
NULL, 10);
303 local_rtp_port = strtol(buf,
NULL, 10);
306 local_rtp_port = strtol(buf,
NULL, 10);
309 local_rtcp_port = strtol(buf,
NULL, 10);
312 max_packet_size = strtol(buf,
NULL, 10);
315 connect = strtol(buf,
NULL, 10);
321 av_strlcpy(include_sources, buf,
sizeof(include_sources));
325 av_strlcpy(exclude_sources, buf,
sizeof(exclude_sources));
331 hostname, rtp_port, local_rtp_port, ttl, max_packet_size,
332 connect, include_sources, exclude_sources);
335 if (local_rtp_port>=0 && local_rtcp_port<0)
339 hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size,
340 connect, include_sources, exclude_sources);
365 struct pollfd p[2] = {{s->
rtp_fd, POLLIN, 0}, {s->
rtcp_fd, POLLIN, 0}};
373 n = poll(p, 2, poll_delay);
376 for (i = 1; i >= 0; i--) {
377 if (!(p[i].revents & POLLIN))
379 *addr_lens[i] =
sizeof(*addrs[i]);
380 len = recvfrom(p[i].fd, buf, size, 0,
381 (
struct sockaddr *)addrs[i], addr_lens[i]);
415 socklen_t *source_len, temp_len;
418 "Unable to send packet to source, no packets received yet\n");
429 source = &s->last_rtp_source;
433 source = &temp_source;
434 source_len = &temp_len;
436 temp_source = s->last_rtp_source;
440 "Not received any RTCP packets yet, inferring peer port "
441 "from the RTP port\n");
447 "Not received any RTP packets yet, inferring peer port "
448 "from the RTCP port\n");
457 ret = sendto(fd, buf, size, 0, (
struct sockaddr *) source,
526 int *hs = *handles =
av_malloc(
sizeof(**handles) * 2);
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.
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
#define URL_PROTOCOL_FLAG_NETWORK
#define AV_LOG_WARNING
Something somehow does not look correct.
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)
static void rtp_parse_addr_list(URLContext *h, char *buf, struct sockaddr_storage ***address_list_ptr, int *address_list_size_ptr)
static int compare_addr(const struct sockaddr_storage *a, const struct sockaddr_storage *b)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
static int rtp_write(URLContext *h, const uint8_t *buf, int size)
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.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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...
static int rtp_read(URLContext *h, uint8_t *buf, int size)
void av_log(void *avcl, int level, const char *fmt,...)
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.
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 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.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
#define AV_LOG_INFO
Standard information.
int ff_check_interrupt(AVIOInterruptCB *cb)
Check if the user has requested to interrup a blocking function associated with cb.
#define AVIO_FLAG_NONBLOCK
Use non-blocking mode.
static void(WINAPI *cond_broadcast)(pthread_cond_t *cond)
socklen_t last_rtcp_source_len
static av_printf_format(3, 4)
add option to url of the form: "http://host:port/path?option1=val1&option2=val2...
static void build_udp_url(char *buf, int buf_size, const char *hostname, int port, int local_port, int ttl, int max_packet_size, int connect, const char *include_sources, const char *exclude_sources)
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)
Close the resource accessed by the URLContext h, and free the memory used by it.
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)
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
int ff_rtp_get_local_rtcp_port(URLContext *h)
Return the local rtcp port used by the RTP connection.
URLProtocol ff_rtp_protocol
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...
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...